/* * Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. *
*/
void Dependencies::assert_evol_method(ciMethod* m) {
assert_common_1(evol_method, m);
}
void Dependencies::assert_leaf_type(ciKlass* ctxk) { if (ctxk->is_array_klass()) { // As a special case, support this assertion on an array type, // which reduces to an assertion on its element type. // Note that this cannot be done with assertions that // relate to concreteness or abstractness.
ciType* elemt = ctxk->as_array_klass()->base_element_type(); if (!elemt->is_instance_klass()) return; // Ex: int[][]
ctxk = elemt->as_instance_klass(); //if (ctxk->is_final()) return; // Ex: String[][]
}
check_ctxk(ctxk);
assert_common_1(leaf_type, ctxk);
}
void Dependencies::assert_leaf_type(Klass* ctxk) { if (ctxk->is_array_klass()) { // As a special case, support this assertion on an array type, // which reduces to an assertion on its element type. // Note that this cannot be done with assertions that // relate to concreteness or abstractness.
BasicType elemt = ArrayKlass::cast(ctxk)->element_type(); if (is_java_primitive(elemt)) return; // Ex: int[][]
ctxk = ObjArrayKlass::cast(ctxk)->bottom_klass(); //if (ctxk->is_final()) return; // Ex: String[][]
}
check_ctxk(ctxk);
assert_common_1(leaf_type, DepValue(_oop_recorder, ctxk));
}
// Helper function. If we are adding a new dep. under ctxk2, // try to find an old dep. under a broader* ctxk1. If there is // bool Dependencies::maybe_merge_ctxk(GrowableArray<ciBaseObject*>* deps, int ctxk_i, ciKlass* ctxk2) {
ciKlass* ctxk1 = deps->at(ctxk_i)->as_metadata()->as_klass(); if (ctxk2->is_subtype_of(ctxk1)) { returntrue; // success, and no need to change
} elseif (ctxk1->is_subtype_of(ctxk2)) { // new context class fully subsumes previous one
deps->at_put(ctxk_i, ctxk2); returntrue;
} else { returnfalse;
}
}
// see if the same (or a similar) dep is already recorded if (note_dep_seen(dept, x)) {
assert(deps->find(x) >= 0, "sanity");
} else {
deps->append(x);
}
}
// see if the same (or a similar) dep is already recorded bool has_ctxk = has_explicit_context_arg(dept); if (has_ctxk) {
assert(dep_context_arg(dept) == 0, "sanity"); if (note_dep_seen(dept, x1)) { // look in this bucket for redundant assertions constint stride = 2; for (int i = deps->length(); (i -= stride) >= 0; ) {
ciBaseObject* y1 = deps->at(i+1); if (x1 == y1) { // same subject; check the context if (maybe_merge_ctxk(deps, i+0, x0->as_metadata()->as_klass())) { return;
}
}
}
}
} else { bool dep_seen_x0 = note_dep_seen(dept, x0); // records x0 for future queries bool dep_seen_x1 = note_dep_seen(dept, x1); // records x1 for future queries if (dep_seen_x0 && dep_seen_x1) { // look in this bucket for redundant assertions constint stride = 2; for (int i = deps->length(); (i -= stride) >= 0; ) {
ciBaseObject* y0 = deps->at(i+0);
ciBaseObject* y1 = deps->at(i+1); if (x0 == y0 && x1 == y1) { return;
}
}
}
}
// append the assertion in the correct bucket:
deps->append(x0);
deps->append(x1);
}
// see if the same (or a similar) dep is already recorded bool dep_seen_x1 = note_dep_seen(dept, x1); // records x1 for future queries bool dep_seen_x2 = note_dep_seen(dept, x2); // records x2 for future queries bool dep_seen_x3 = note_dep_seen(dept, x3); // records x3 for future queries if (dep_seen_x1 && dep_seen_x2 && dep_seen_x3) { // look in this bucket for redundant assertions constint stride = 4; for (int i = deps->length(); (i -= stride) >= 0; ) {
ciBaseObject* y1 = deps->at(i+1);
ciBaseObject* y2 = deps->at(i+2);
ciBaseObject* y3 = deps->at(i+3); if (x1 == y1 && x2 == y2 && x3 == y3) { // same subjects; check the context if (maybe_merge_ctxk(deps, i+0, ctxk)) { return;
}
}
}
} // append the assertion in the correct bucket:
deps->append(ctxk);
deps->append(x1);
deps->append(x2);
deps->append(x3);
}
#if INCLUDE_JVMCI bool Dependencies::maybe_merge_ctxk(GrowableArray<DepValue>* deps, int ctxk_i, DepValue ctxk2_dv) {
Klass* ctxk1 = deps->at(ctxk_i).as_klass(_oop_recorder);
Klass* ctxk2 = ctxk2_dv.as_klass(_oop_recorder); if (ctxk2->is_subtype_of(ctxk1)) { returntrue; // success, and no need to change
} elseif (ctxk1->is_subtype_of(ctxk2)) { // new context class fully subsumes previous one
deps->at_put(ctxk_i, ctxk2_dv); returntrue;
} else { returnfalse;
}
}
// see if the same (or a similar) dep is already recorded if (note_dep_seen(dept, x)) {
assert(deps->find(x) >= 0, "sanity");
} else {
deps->append(x);
}
}
// see if the same (or a similar) dep is already recorded bool has_ctxk = has_explicit_context_arg(dept); if (has_ctxk) {
assert(dep_context_arg(dept) == 0, "sanity"); if (note_dep_seen(dept, x1)) { // look in this bucket for redundant assertions constint stride = 2; for (int i = deps->length(); (i -= stride) >= 0; ) {
DepValue y1 = deps->at(i+1); if (x1 == y1) { // same subject; check the context if (maybe_merge_ctxk(deps, i+0, x0)) { return;
}
}
}
}
} else { bool dep_seen_x0 = note_dep_seen(dept, x0); // records x0 for future queries bool dep_seen_x1 = note_dep_seen(dept, x1); // records x1 for future queries if (dep_seen_x0 && dep_seen_x1) { // look in this bucket for redundant assertions constint stride = 2; for (int i = deps->length(); (i -= stride) >= 0; ) {
DepValue y0 = deps->at(i+0);
DepValue y1 = deps->at(i+1); if (x0 == y0 && x1 == y1) { return;
}
}
}
}
// append the assertion in the correct bucket:
deps->append(x0);
deps->append(x1);
} #endif// INCLUDE_JVMCI
/// Support for encoding dependencies into an nmethod:
void Dependencies::copy_to(nmethod* nm) {
address beg = nm->dependencies_begin();
address end = nm->dependencies_end();
guarantee(end - beg >= (ptrdiff_t) size_in_bytes(), "bad sizing");
Copy::disjoint_words((HeapWord*) content_bytes(),
(HeapWord*) beg,
size_in_bytes() / sizeof(HeapWord));
assert(size_in_bytes() % sizeof(HeapWord) == 0, "copy by words");
}
Dependencies::DepType Dependencies::validate_dependencies(CompileTask* task, char** failure_detail) { int klass_violations = 0;
DepType result = end_marker; for (Dependencies::DepStream deps(this); deps.next(); ) {
Klass* witness = deps.check_dependency(); if (witness != NULL) { if (klass_violations == 0) {
result = deps.type(); if (failure_detail != NULL && klass_violations == 0) { // Use a fixed size buffer to prevent the string stream from // resizing in the context of an inner resource mark. char* buffer = NEW_RESOURCE_ARRAY(char, O_BUFLEN);
stringStream st(buffer, O_BUFLEN);
deps.print_dependency(witness, true, &st);
*failure_detail = st.as_string();
}
}
klass_violations++; if (xtty == NULL) { // If we're not logging then a single violation is sufficient, // otherwise we want to log all the dependences which were // violated. break;
}
}
}
return result;
}
// for the sake of the compiler log, print out current dependencies: void Dependencies::log_all_dependencies() { if (log() == NULL) return;
ResourceMark rm; for (int deptv = (int)FIRST_TYPE; deptv < (int)TYPE_LIMIT; deptv++) {
DepType dept = (DepType)deptv;
GrowableArray<ciBaseObject*>* deps = _deps[dept]; int deplen = deps->length(); if (deplen == 0) { continue;
} int stride = dep_args(dept);
GrowableArray<ciBaseObject*>* ciargs = new GrowableArray<ciBaseObject*>(stride); for (int i = 0; i < deps->length(); i += stride) { for (int j = 0; j < stride; j++) { // flush out the identities before printing
ciargs->push(deps->at(i+j));
}
write_dependency_to(log(), dept, ciargs);
ciargs->clear();
}
guarantee(deplen == deps->length(), "deps array cannot grow inside nested ResoureMark scope");
}
}
Metadata* Dependencies::DepStream::argument(int i) {
Metadata* result = recorded_metadata_at(argument_index(i));
if (result == NULL) { // Explicit context argument can be compressed int ctxkj = dep_context_arg(type()); // -1 if no explicit context arg if (ctxkj >= 0 && i == ctxkj && ctxkj+1 < argument_count()) {
result = ctxk_encoded_as_null(type(), argument(ctxkj+1));
}
}
// Most dependencies have an explicit context type argument.
{ int ctxkj = dep_context_arg(type()); // -1 if no explicit context arg if (ctxkj >= 0) {
Metadata* k = argument(ctxkj);
assert(k != NULL && k->is_klass(), "type check"); return InstanceKlass::cast((Klass*)k);
}
}
// Some dependencies are using the klass of the first object // argument as implicit context type.
{ int ctxkj = dep_implicit_context_arg(type()); if (ctxkj >= 0) {
Klass* k = argument_oop(ctxkj)->klass();
assert(k != NULL, "type check"); return InstanceKlass::cast(k);
}
}
// And some dependencies don't have a context type at all, // e.g. evol_method. return NULL;
}
for (int i = 0; i < s1.args_count(); i++) { if (s1.arg(i) != s2.arg(i)) { returnfalse;
}
} returntrue;
}
/// Checking dependencies
// This hierarchy walker inspects subtypes of a given type, trying to find a "bad" class which breaks a dependency. // Such a class is called a "witness" to the broken dependency. // While searching around, we ignore "participants", which are already known to the dependency. class AbstractClassHierarchyWalker { public: enum { PARTICIPANT_LIMIT = 3 };
private: // if non-zero, tells how many witnesses to convert to participants
uint _record_witnesses;
// special classes which are not allowed to be witnesses:
Klass* _participants[PARTICIPANT_LIMIT+1];
uint _num_participants;
Klass* AbstractClassHierarchyWalker::find_witness(InstanceKlass* context_type, KlassDepChange* changes) { // Current thread must be in VM (not native mode, as in CI):
assert(must_be_in_vm(), "raw oops here"); // Must not move the class hierarchy during this check:
assert_locked_or_safepoint(Compile_lock);
assert(_nof_requests++ == 0, "repeated requests are not supported");
// (Note: Interfaces do not have subclasses.) // If it is an interface, search its direct implementors. // (Their subclasses are additional indirect implementors. See InstanceKlass::add_implementor().) if (context_type->is_interface()) { int nof_impls = context_type->nof_implementors(); if (nof_impls == 0) { return NULL; // no implementors
} elseif (nof_impls == 1) { // unique implementor
assert(context_type != context_type->implementor(), "not unique");
context_type = InstanceKlass::cast(context_type->implementor());
} else { // nof_impls >= 2 // Avoid this case: *I.m > { A.m, C }; B.m > C // Here, I.m has 2 concrete implementations, but m appears unique // as A.m, because the search misses B.m when checking C. // The inherited method B.m was getting missed by the walker // when interface 'I' was the starting point. // %%% Until this is fixed more systematically, bail out. return context_type;
}
}
assert(!context_type->is_interface(), "no interfaces allowed");
if (changes != NULL) { if (UsePerfData) {
_perf_find_witness_in_calls_count->inc();
} return find_witness_in(*changes);
} else { if (UsePerfData) {
_perf_find_witness_anywhere_calls_count->inc();
} return find_witness_anywhere(context_type);
}
}
class ConcreteSubtypeFinder : public AbstractClassHierarchyWalker { private: bool is_witness(Klass* k);
bool ConcreteSubtypeFinder::is_witness(Klass* k) { if (Dependencies::is_concrete_klass(k)) { return record_witness(k); // concrete subtype
} else { returnfalse; // not a concrete class
}
}
Klass* ConcreteSubtypeFinder::find_witness_in(KlassDepChange& changes) { // When looking for unexpected concrete types, do not look beneath expected ones: // * CX > CC > C' is OK, even if C' is new. // * CX > { CC, C' } is not OK if C' is new, and C' is the witness.
Klass* new_type = changes.as_new_klass_change()->new_type();
assert(!is_participant(new_type), "only old classes are participants"); // If the new type is a subtype of a participant, we are done. for (uint i = 0; i < num_participants(); i++) { if (changes.involves_context(participant(i))) { // new guy is protected from this check by previous participant return NULL;
}
} if (is_witness(new_type)) { return new_type;
} // No witness found. The dependency remains unbroken. return NULL;
}
Klass* ConcreteSubtypeFinder::find_witness_anywhere(InstanceKlass* context_type) { for (CountingClassHierarchyIterator iter(context_type); !iter.done(); iter.next()) {
Klass* sub = iter.klass(); // Do not report participant types. if (is_participant(sub)) { // Don't walk beneath a participant since it hides witnesses.
iter.skip_subclasses();
} elseif (is_witness(sub)) { return sub; // found a witness
}
} // No witness found. The dependency remains unbroken. return NULL;
}
class ConcreteMethodFinder : public AbstractClassHierarchyWalker { private:
Symbol* _name;
Symbol* _signature;
// cache of method lookups
Method* _found_methods[PARTICIPANT_LIMIT+1];
for (int i = 0; i < PARTICIPANT_LIMIT+1; i++) {
_found_methods[i] = NULL;
}
}
// Note: If n==num_participants, returns NULL.
Method* found_method(uint n) {
assert(n <= num_participants(), "oob");
Method* fm = _found_methods[n];
assert(n == num_participants() || fm != NULL, "proper usage"); if (fm != NULL && fm->method_holder() != participant(n)) { // Default methods from interfaces can be added to classes. In // that case the holder of the method is not the class but the // interface where it's defined.
assert(fm->is_default_method(), "sanity"); return NULL;
} return fm;
}
bool ConcreteMethodFinder::is_witness(Klass* k) { if (is_participant(k)) { returnfalse; // do not report participant types
} if (k->is_instance_klass()) {
InstanceKlass* ik = InstanceKlass::cast(k); // Search class hierarchy first, skipping private implementations // as they never override any inherited methods
Method* m = ik->find_instance_method(_name, _signature, Klass::PrivateLookupMode::skip); if (Dependencies::is_concrete_method(m, ik)) { return record_witness(k, m); // concrete method found
} else { // Check for re-abstraction of method if (!ik->is_interface() && m != NULL && m->is_abstract()) { // Found a matching abstract method 'm' in the class hierarchy. // This is fine iff 'k' is an abstract class and all concrete subtypes // of 'k' override 'm' and are participates of the current search.
ConcreteSubtypeFinder wf; for (uint i = 0; i < num_participants(); i++) {
Klass* p = participant(i);
wf.add_participant(p);
}
Klass* w = wf.find_witness(ik); if (w != NULL) {
Method* wm = InstanceKlass::cast(w)->find_instance_method(_name, _signature, Klass::PrivateLookupMode::skip); if (!Dependencies::is_concrete_method(wm, w)) { // Found a concrete subtype 'w' which does not override abstract method 'm'. // Bail out because 'm' could be called with 'w' as receiver (leading to an // AbstractMethodError) and thus the method we are looking for is not unique. return record_witness(k, m);
}
}
} // Check interface defaults also, if any exist.
Array<Method*>* default_methods = ik->default_methods(); if (default_methods != NULL) {
Method* dm = ik->find_method(default_methods, _name, _signature); if (Dependencies::is_concrete_method(dm, NULL)) { return record_witness(k, dm); // default method found
}
} returnfalse; // no concrete method found
}
} else { returnfalse; // no methods to find in an array type
}
}
Klass* ConcreteMethodFinder::find_witness_in(KlassDepChange& changes) { // When looking for unexpected concrete methods, look beneath expected ones, to see if there are overrides. // * CX.m > CC.m > C'.m is not OK, if C'.m is new, and C' is the witness.
Klass* new_type = changes.as_new_klass_change()->new_type();
assert(!is_participant(new_type), "only old classes are participants"); if (is_witness(new_type)) { return new_type;
} else { // No witness found, but is_witness() doesn't detect method re-abstraction in case of spot-checking. if (witnessed_reabstraction_in_supers(new_type)) { return new_type;
}
} // No witness found. The dependency remains unbroken. return NULL;
}
bool ConcreteMethodFinder::witnessed_reabstraction_in_supers(Klass* k) { if (!k->is_instance_klass()) { returnfalse; // no methods to find in an array type
} else { // Looking for a case when an abstract method is inherited into a concrete class. if (Dependencies::is_concrete_klass(k) && !k->is_interface()) {
Method* m = InstanceKlass::cast(k)->find_instance_method(_name, _signature, Klass::PrivateLookupMode::skip); if (m != NULL) { returnfalse; // no reabstraction possible: local method found
} for (InstanceKlass* super = k->java_super(); super != NULL; super = super->java_super()) {
m = super->find_instance_method(_name, _signature, Klass::PrivateLookupMode::skip); if (m != NULL) { // inherited method found if (m->is_abstract() || m->is_overpass()) { return record_witness(super, m); // abstract method found
} returnfalse;
}
} // Miranda. returntrue;
} returnfalse;
}
}
Klass* ConcreteMethodFinder::find_witness_anywhere(InstanceKlass* context_type) { // Walk hierarchy under a context type, looking for unexpected types. for (CountingClassHierarchyIterator iter(context_type); !iter.done(); iter.next()) {
Klass* sub = iter.klass(); if (is_witness(sub)) { return sub; // found a witness
}
} // No witness found. The dependency remains unbroken. return NULL;
}
// For some method m and some class ctxk (subclass of method holder), // enumerate all distinct overrides of m in concrete subclasses of ctxk. // It relies on vtable/itable information to perform method selection on each linked subclass // and ignores all non yet linked ones (speculatively treat them as "effectively abstract"). class LinkedConcreteMethodFinder : public AbstractClassHierarchyWalker { private:
InstanceKlass* _resolved_klass; // resolved class (JVMS-5.4.3.1)
InstanceKlass* _declaring_klass; // the holder of resolved method (JVMS-5.4.3.3) int _vtable_index; // vtable/itable index of the resolved method bool _do_itable_lookup; // choose between itable and vtable lookup logic
// cache of method lookups
Method* _found_methods[PARTICIPANT_LIMIT+1];
void add_participant(Method* m, Klass* participant) {
uint np = num_participants();
AbstractClassHierarchyWalker::add_participant(participant);
assert(np + 1 == num_participants(), "sanity");
_found_methods[np] = m; // record the method for the participant
}
bool record_witness(Klass* witness, Method* m) { for (uint i = 0; i < num_participants(); i++) { if (found_method(i) == m) { returnfalse; // already recorded
}
} // Record not yet seen method.
_found_methods[num_participants()] = m; return AbstractClassHierarchyWalker::record_witness(witness);
}
void initialize(Method* participant) { for (uint i = 0; i < PARTICIPANT_LIMIT+1; i++) {
_found_methods[i] = NULL;
} if (participant != NULL) {
add_participant(participant, participant->method_holder());
}
}
public: // In order to perform method selection, the following info is needed: // (1) interface or virtual call; // (2) vtable/itable index; // (3) declaring class (in case of interface call). // // It is prepared based on the results of method resolution: resolved class and resolved method (as specified in JVMS-5.4.3.3). // Optionally, a method which was previously determined as a unique target (uniqm) is added as a participant // to enable dependency spot-checking and speed up the search.
LinkedConcreteMethodFinder(InstanceKlass* resolved_klass, Method* resolved_method, Method* uniqm = NULL) : AbstractClassHierarchyWalker(NULL) {
assert(UseVtableBasedCHA, "required");
assert(resolved_klass->is_linked(), "required");
assert(resolved_method->method_holder()->is_linked(), "required");
assert(!resolved_method->can_be_statically_bound(), "no vtable index available");
Klass* LinkedConcreteMethodFinder::find_witness_in(KlassDepChange& changes) {
Klass* type = changes.type();
assert(!is_participant(type), "only old classes are participants");
if (is_witness(type)) { return type;
} return NULL; // No witness found. The dependency remains unbroken.
}
Klass* LinkedConcreteMethodFinder::find_witness_anywhere(InstanceKlass* context_type) { for (CountingClassHierarchyIterator iter(context_type); !iter.done(); iter.next()) {
Klass* sub = iter.klass(); if (is_witness(sub)) { return sub;
} if (sub->is_instance_klass() && !InstanceKlass::cast(sub)->is_linked()) {
iter.skip_subclasses(); // ignore not yet linked classes
}
} return NULL; // No witness found. The dependency remains unbroken.
}
bool LinkedConcreteMethodFinder::is_witness(Klass* k) { if (is_participant(k)) { returnfalse; // do not report participant types
} elseif (k->is_instance_klass()) {
InstanceKlass* ik = InstanceKlass::cast(k); if (is_concrete_klass(ik)) {
Method* m = select_method(ik); return record_witness(ik, m);
} else { returnfalse; // ignore non-concrete holder class
}
} else { returnfalse; // no methods to find in an array type
}
}
Method* LinkedConcreteMethodFinder::select_method(InstanceKlass* recv_klass) {
Method* selected_method = NULL; if (_do_itable_lookup) {
assert(_declaring_klass->is_interface(), "sanity"); bool implements_interface; // initialized by method_at_itable_or_null()
selected_method = recv_klass->method_at_itable_or_null(_declaring_klass, _vtable_index,
implements_interface); // out parameter
assert(implements_interface, "not implemented");
} else {
selected_method = recv_klass->method_at_vtable(_vtable_index);
} return selected_method; // NULL when corresponding slot is empty (AbstractMethodError case)
}
int LinkedConcreteMethodFinder::compute_vtable_index(InstanceKlass* resolved_klass, Method* resolved_method, // out parameter bool& is_itable_index) { if (resolved_klass->is_interface() && resolved_method->has_itable_index()) {
is_itable_index = true; return resolved_method->itable_index();
} // Check for default or miranda method first.
InstanceKlass* declaring_klass = resolved_method->method_holder(); if (!resolved_klass->is_interface() && declaring_klass->is_interface()) {
is_itable_index = false; return resolved_klass->vtable_index_of_interface_method(resolved_method);
} // At this point we are sure that resolved_method is virtual and not // a default or miranda method; therefore, it must have a valid vtable index.
assert(resolved_method->has_vtable_index(), "");
is_itable_index = false; return resolved_method->vtable_index();
}
bool LinkedConcreteMethodFinder::is_concrete_klass(InstanceKlass* ik) { if (!Dependencies::is_concrete_klass(ik)) { returnfalse; // not concrete
} if (ik->is_interface()) { returnfalse; // interfaces aren't concrete
} if (!ik->is_linked()) { returnfalse; // not yet linked classes don't have instances
} returntrue;
}
#ifdef ASSERT // Assert that m is inherited into ctxk, without intervening overrides. // (May return true even if this is not true, in corner cases where we punt.) bool Dependencies::verify_method_context(InstanceKlass* ctxk, Method* m) { if (m->is_private()) { returnfalse; // Quick lose. Should not happen.
} if (m->method_holder() == ctxk) { returntrue; // Quick win.
} if (!(m->is_public() || m->is_protected())) { // The override story is complex when packages get involved. returntrue; // Must punt the assertion to true.
}
Method* lm = ctxk->lookup_method(m->name(), m->signature()); if (lm == NULL && ctxk->is_instance_klass()) { // It might be an interface method
lm = InstanceKlass::cast(ctxk)->lookup_method_in_ordered_interfaces(m->name(),
m->signature());
} if (lm == m) { // Method m is inherited into ctxk. returntrue;
} if (lm != NULL) { if (!(lm->is_public() || lm->is_protected())) { // Method is [package-]private, so the override story is complex. returntrue; // Must punt the assertion to true.
} if (lm->is_static()) { // Static methods don't override non-static so punt returntrue;
} if (!Dependencies::is_concrete_method(lm, ctxk) &&
!Dependencies::is_concrete_method(m, ctxk)) { // They are both non-concrete if (lm->method_holder()->is_subtype_of(m->method_holder())) { // Method m is overridden by lm, but both are non-concrete. returntrue;
} if (lm->method_holder()->is_interface() && m->method_holder()->is_interface() &&
ctxk->is_subtype_of(m->method_holder()) && ctxk->is_subtype_of(lm->method_holder())) { // Interface method defined in multiple super interfaces returntrue;
}
}
}
ResourceMark rm;
tty->print_cr("Dependency method not found in the associated context:");
tty->print_cr(" context = %s", ctxk->external_name());
tty->print( " method = "); m->print_short_name(tty); tty->cr(); if (lm != NULL) {
tty->print( " found = "); lm->print_short_name(tty); tty->cr();
} returnfalse;
} #endif// ASSERT
bool Dependencies::is_concrete_klass(Klass* k) { if (k->is_abstract()) returnfalse; // %%% We could treat classes which are concrete but // have not yet been instantiated as virtually abstract. // This would require a deoptimization barrier on first instantiation. //if (k->is_not_instantiated()) return false; returntrue;
}
bool Dependencies::is_concrete_method(Method* m, Klass* k) { // NULL is not a concrete method. if (m == NULL) { returnfalse;
} // Statics are irrelevant to virtual call sites. if (m->is_static()) { returnfalse;
} // Abstract methods are not concrete. if (m->is_abstract()) { returnfalse;
} // Overpass (error) methods are not concrete if k is abstract. if (m->is_overpass() && k != NULL) { return !k->is_abstract();
} // Note "true" is conservative answer: overpass clause is false if k == NULL, // implies return true if answer depends on overpass clause. returntrue;
}
Klass* Dependencies::find_finalizable_subclass(InstanceKlass* ik) { for (ClassHierarchyIterator iter(ik); !iter.done(); iter.next()) {
Klass* sub = iter.klass(); if (sub->has_finalizer() && !sub->is_interface()) { return sub;
}
} return NULL; // not found
}
bool Dependencies::is_concrete_klass(ciInstanceKlass* k) { if (k->is_abstract()) returnfalse; // We could also return false if k does not yet appear to be // instantiated, if the VM version supports this distinction also. //if (k->is_not_instantiated()) return false; returntrue;
}
// Any use of the contents (bytecodes) of a method must be // marked by an "evol_method" dependency, if those contents // can change. (Note: A method is always dependent on itself.)
Klass* Dependencies::check_evol_method(Method* m) {
assert(must_be_in_vm(), "raw oops here"); // Did somebody do a JVMTI RedefineClasses while our backs were turned? // Or is there a now a breakpoint? // (Assumes compiled code cannot handle bkpts; change if UseFastBreakpoints.) if (m->is_old()
|| m->number_of_breakpoints() > 0) { return m->method_holder();
} else { return NULL;
}
}
// This is a strong assertion: It is that the given type // has no subtypes whatever. It is most useful for // optimizing checks on reflected types or on array types. // (Checks on types which are derived from real instances // can be optimized more strongly than this, because we // know that the checked type comes from a concrete type, // and therefore we can disregard abstract types.)
Klass* Dependencies::check_leaf_type(InstanceKlass* ctxk) {
assert(must_be_in_vm(), "raw oops here");
assert_locked_or_safepoint(Compile_lock);
Klass* sub = ctxk->subklass(); if (sub != NULL) { return sub;
} elseif (ctxk->nof_implementors() != 0) { // if it is an interface, it must be unimplemented // (if it is not an interface, nof_implementors is always zero)
InstanceKlass* impl = ctxk->implementor();
assert(impl != NULL, "must be set"); return impl;
} else { return NULL;
}
}
// Test the assertion that conck is the only concrete subtype* of ctxk. // The type conck itself is allowed to have have further concrete subtypes. // This allows the compiler to narrow occurrences of ctxk by conck, // when dealing with the types of actual instances.
Klass* Dependencies::check_abstract_with_unique_concrete_subtype(InstanceKlass* ctxk,
Klass* conck,
NewKlassDepChange* changes) {
ConcreteSubtypeFinder wf(conck);
Klass* k = wf.find_witness(ctxk, changes); return k;
}
// Find the unique concrete proper subtype of ctxk, or NULL if there // is more than one concrete proper subtype. If there are no concrete // proper subtypes, return ctxk itself, whether it is concrete or not. // The returned subtype is allowed to have have further concrete subtypes. // That is, return CC1 for CX > CC1 > CC2, but NULL for CX > { CC1, CC2 }.
Klass* Dependencies::find_unique_concrete_subtype(InstanceKlass* ctxk) {
ConcreteSubtypeFinder wf(ctxk); // Ignore ctxk when walking.
wf.record_witnesses(1); // Record one other witness when walking.
Klass* wit = wf.find_witness(ctxk); if (wit != NULL) return NULL; // Too many witnesses.
Klass* conck = wf.participant(0); if (conck == NULL) { return ctxk; // Return ctxk as a flag for "no subtypes".
} else { #ifndef PRODUCT // Make sure the dependency mechanism will pass this discovery: if (VerifyDependencies) { // Turn off dependency tracing while actually testing deps.
FlagSetting fs(TraceDependencies, false); if (!Dependencies::is_concrete_klass(ctxk)) {
guarantee(NULL == (void *)
check_abstract_with_unique_concrete_subtype(ctxk, conck), "verify dep.");
}
} #endif//PRODUCT return conck;
}
}
// Try to determine whether root method in some context is concrete or not based on the information about the unique method // in that context. It exploits the fact that concrete root method is always inherited into the context when there's a unique method. // Hence, unique method holder is always a supertype of the context class when root method is concrete. // Examples for concrete_root_method // C (C.m uniqm) // | // CX (ctxk) uniqm is inherited into context. // // CX (ctxk) (CX.m uniqm) here uniqm is defined in ctxk. // Examples for !concrete_root_method // CX (ctxk) // | // C (C.m uniqm) uniqm is in subtype of ctxk. bool Dependencies::is_concrete_root_method(Method* uniqm, InstanceKlass* ctxk) { if (uniqm == NULL) { returnfalse; // match Dependencies::is_concrete_method() behavior
} // Theoretically, the "direction" of subtype check matters here. // On one hand, in case of interface context with a single implementor, uniqm can be in a superclass of the implementor which // is not related to context class. // On another hand, uniqm could come from an interface unrelated to the context class, but right now it is not possible: // it is required that uniqm->method_holder() is the participant (uniqm->method_holder() <: ctxk), hence a default method // can't be used as unique. if (ctxk->is_interface()) {
InstanceKlass* implementor = ctxk->implementor();
assert(implementor != ctxk, "single implementor only"); // should have been invalidated earlier
ctxk = implementor;
}
InstanceKlass* holder = uniqm->method_holder();
assert(!holder->is_interface(), "no default methods allowed");
assert(ctxk->is_subclass_of(holder) || holder->is_subclass_of(ctxk), "not related"); return ctxk->is_subclass_of(holder);
}
// If a class (or interface) has a unique concrete method uniqm, return NULL. // Otherwise, return a class that contains an interfering method.
Klass* Dependencies::check_unique_concrete_method(InstanceKlass* ctxk,
Method* uniqm,
NewKlassDepChange* changes) {
ConcreteMethodFinder wf(uniqm, uniqm->method_holder());
Klass* k = wf.find_witness(ctxk, changes); if (k != NULL) { return k;
} if (!Dependencies::is_concrete_root_method(uniqm, ctxk) || changes != NULL) {
Klass* conck = find_witness_AME(ctxk, uniqm, changes); if (conck != NULL) { // Found a concrete subtype 'conck' which does not override abstract root method. return conck;
}
} return NULL;
}
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.65Bemerkung:
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.