duke@435: /* acorn@5848: * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #include "precompiled.hpp" stefank@2314: #include "ci/ciArrayKlass.hpp" stefank@2314: #include "ci/ciEnv.hpp" stefank@2314: #include "ci/ciKlass.hpp" stefank@2314: #include "ci/ciMethod.hpp" stefank@2314: #include "code/dependencies.hpp" stefank@2314: #include "compiler/compileLog.hpp" stefank@2314: #include "oops/oop.inline.hpp" coleenp@4037: #include "runtime/handles.hpp" stefank@2314: #include "runtime/handles.inline.hpp" stefank@2314: #include "utilities/copy.hpp" duke@435: duke@435: duke@435: #ifdef ASSERT duke@435: static bool must_be_in_vm() { duke@435: Thread* thread = Thread::current(); duke@435: if (thread->is_Java_thread()) duke@435: return ((JavaThread*)thread)->thread_state() == _thread_in_vm; duke@435: else duke@435: return true; //something like this: thread->is_VM_thread(); duke@435: } duke@435: #endif //ASSERT duke@435: duke@435: void Dependencies::initialize(ciEnv* env) { duke@435: Arena* arena = env->arena(); duke@435: _oop_recorder = env->oop_recorder(); duke@435: _log = env->log(); duke@435: _dep_seen = new(arena) GrowableArray(arena, 500, 0, 0); duke@435: DEBUG_ONLY(_deps[end_marker] = NULL); duke@435: for (int i = (int)FIRST_TYPE; i < (int)TYPE_LIMIT; i++) { coleenp@4037: _deps[i] = new(arena) GrowableArray(arena, 10, 0, 0); duke@435: } duke@435: _content_bytes = NULL; duke@435: _size_in_bytes = (size_t)-1; duke@435: duke@435: assert(TYPE_LIMIT <= (1<is_array_klass()) { duke@435: // As a special case, support this assertion on an array type, duke@435: // which reduces to an assertion on its element type. duke@435: // Note that this cannot be done with assertions that duke@435: // relate to concreteness or abstractness. duke@435: ciType* elemt = ctxk->as_array_klass()->base_element_type(); duke@435: if (!elemt->is_instance_klass()) return; // Ex: int[][] duke@435: ctxk = elemt->as_instance_klass(); duke@435: //if (ctxk->is_final()) return; // Ex: String[][] duke@435: } duke@435: check_ctxk(ctxk); duke@435: assert_common_1(leaf_type, ctxk); duke@435: } duke@435: duke@435: void Dependencies::assert_abstract_with_unique_concrete_subtype(ciKlass* ctxk, ciKlass* conck) { duke@435: check_ctxk_abstract(ctxk); duke@435: assert_common_2(abstract_with_unique_concrete_subtype, ctxk, conck); duke@435: } duke@435: duke@435: void Dependencies::assert_abstract_with_no_concrete_subtype(ciKlass* ctxk) { duke@435: check_ctxk_abstract(ctxk); duke@435: assert_common_1(abstract_with_no_concrete_subtype, ctxk); duke@435: } duke@435: duke@435: void Dependencies::assert_concrete_with_no_concrete_subtype(ciKlass* ctxk) { duke@435: check_ctxk_concrete(ctxk); duke@435: assert_common_1(concrete_with_no_concrete_subtype, ctxk); duke@435: } duke@435: duke@435: void Dependencies::assert_unique_concrete_method(ciKlass* ctxk, ciMethod* uniqm) { duke@435: check_ctxk(ctxk); duke@435: assert_common_2(unique_concrete_method, ctxk, uniqm); duke@435: } duke@435: duke@435: void Dependencies::assert_abstract_with_exclusive_concrete_subtypes(ciKlass* ctxk, ciKlass* k1, ciKlass* k2) { duke@435: check_ctxk(ctxk); duke@435: assert_common_3(abstract_with_exclusive_concrete_subtypes_2, ctxk, k1, k2); duke@435: } duke@435: duke@435: void Dependencies::assert_exclusive_concrete_methods(ciKlass* ctxk, ciMethod* m1, ciMethod* m2) { duke@435: check_ctxk(ctxk); duke@435: assert_common_3(exclusive_concrete_methods_2, ctxk, m1, m2); duke@435: } duke@435: duke@435: void Dependencies::assert_has_no_finalizable_subclasses(ciKlass* ctxk) { duke@435: check_ctxk(ctxk); duke@435: assert_common_1(no_finalizable_subclasses, ctxk); duke@435: } duke@435: twisti@3094: void Dependencies::assert_call_site_target_value(ciCallSite* call_site, ciMethodHandle* method_handle) { twisti@3094: check_ctxk(call_site->klass()); twisti@3094: assert_common_2(call_site_target_value, call_site, method_handle); twisti@3050: } twisti@3050: duke@435: // Helper function. If we are adding a new dep. under ctxk2, duke@435: // try to find an old dep. under a broader* ctxk1. If there is duke@435: // coleenp@4037: bool Dependencies::maybe_merge_ctxk(GrowableArray* deps, duke@435: int ctxk_i, ciKlass* ctxk2) { coleenp@4037: ciKlass* ctxk1 = deps->at(ctxk_i)->as_metadata()->as_klass(); duke@435: if (ctxk2->is_subtype_of(ctxk1)) { duke@435: return true; // success, and no need to change duke@435: } else if (ctxk1->is_subtype_of(ctxk2)) { duke@435: // new context class fully subsumes previous one duke@435: deps->at_put(ctxk_i, ctxk2); duke@435: return true; duke@435: } else { duke@435: return false; duke@435: } duke@435: } duke@435: coleenp@4037: void Dependencies::assert_common_1(DepType dept, ciBaseObject* x) { duke@435: assert(dep_args(dept) == 1, "sanity"); duke@435: log_dependency(dept, x); coleenp@4037: GrowableArray* deps = _deps[dept]; duke@435: duke@435: // see if the same (or a similar) dep is already recorded duke@435: if (note_dep_seen(dept, x)) { duke@435: assert(deps->find(x) >= 0, "sanity"); duke@435: } else { duke@435: deps->append(x); duke@435: } duke@435: } duke@435: twisti@3094: void Dependencies::assert_common_2(DepType dept, coleenp@4037: ciBaseObject* x0, ciBaseObject* x1) { duke@435: assert(dep_args(dept) == 2, "sanity"); twisti@3094: log_dependency(dept, x0, x1); coleenp@4037: GrowableArray* deps = _deps[dept]; duke@435: duke@435: // see if the same (or a similar) dep is already recorded twisti@3094: bool has_ctxk = has_explicit_context_arg(dept); twisti@3094: if (has_ctxk) { twisti@3094: assert(dep_context_arg(dept) == 0, "sanity"); twisti@3094: if (note_dep_seen(dept, x1)) { twisti@3094: // look in this bucket for redundant assertions twisti@3094: const int stride = 2; twisti@3094: for (int i = deps->length(); (i -= stride) >= 0; ) { coleenp@4037: ciBaseObject* y1 = deps->at(i+1); twisti@3094: if (x1 == y1) { // same subject; check the context coleenp@4037: if (maybe_merge_ctxk(deps, i+0, x0->as_metadata()->as_klass())) { twisti@3094: return; twisti@3094: } twisti@3094: } twisti@3094: } twisti@3094: } twisti@3094: } else { twisti@3094: assert(dep_implicit_context_arg(dept) == 0, "sanity"); twisti@3094: if (note_dep_seen(dept, x0) && note_dep_seen(dept, x1)) { twisti@3094: // look in this bucket for redundant assertions twisti@3094: const int stride = 2; twisti@3094: for (int i = deps->length(); (i -= stride) >= 0; ) { coleenp@4037: ciBaseObject* y0 = deps->at(i+0); coleenp@4037: ciBaseObject* y1 = deps->at(i+1); twisti@3094: if (x0 == y0 && x1 == y1) { duke@435: return; duke@435: } duke@435: } duke@435: } duke@435: } duke@435: duke@435: // append the assertion in the correct bucket: twisti@3094: deps->append(x0); twisti@3094: deps->append(x1); duke@435: } duke@435: twisti@3094: void Dependencies::assert_common_3(DepType dept, coleenp@4037: ciKlass* ctxk, ciBaseObject* x, ciBaseObject* x2) { duke@435: assert(dep_context_arg(dept) == 0, "sanity"); duke@435: assert(dep_args(dept) == 3, "sanity"); duke@435: log_dependency(dept, ctxk, x, x2); coleenp@4037: GrowableArray* deps = _deps[dept]; duke@435: duke@435: // try to normalize an unordered pair: duke@435: bool swap = false; duke@435: switch (dept) { duke@435: case abstract_with_exclusive_concrete_subtypes_2: coleenp@4037: swap = (x->ident() > x2->ident() && x->as_metadata()->as_klass() != ctxk); duke@435: break; duke@435: case exclusive_concrete_methods_2: coleenp@4037: swap = (x->ident() > x2->ident() && x->as_metadata()->as_method()->holder() != ctxk); duke@435: break; duke@435: } coleenp@4037: if (swap) { ciBaseObject* t = x; x = x2; x2 = t; } duke@435: duke@435: // see if the same (or a similar) dep is already recorded duke@435: if (note_dep_seen(dept, x) && note_dep_seen(dept, x2)) { duke@435: // look in this bucket for redundant assertions duke@435: const int stride = 3; duke@435: for (int i = deps->length(); (i -= stride) >= 0; ) { coleenp@4037: ciBaseObject* y = deps->at(i+1); coleenp@4037: ciBaseObject* y2 = deps->at(i+2); duke@435: if (x == y && x2 == y2) { // same subjects; check the context duke@435: if (maybe_merge_ctxk(deps, i+0, ctxk)) { duke@435: return; duke@435: } duke@435: } duke@435: } duke@435: } duke@435: // append the assertion in the correct bucket: duke@435: deps->append(ctxk); duke@435: deps->append(x); duke@435: deps->append(x2); duke@435: } duke@435: duke@435: /// Support for encoding dependencies into an nmethod: duke@435: duke@435: void Dependencies::copy_to(nmethod* nm) { duke@435: address beg = nm->dependencies_begin(); duke@435: address end = nm->dependencies_end(); duke@435: guarantee(end - beg >= (ptrdiff_t) size_in_bytes(), "bad sizing"); duke@435: Copy::disjoint_words((HeapWord*) content_bytes(), duke@435: (HeapWord*) beg, duke@435: size_in_bytes() / sizeof(HeapWord)); duke@435: assert(size_in_bytes() % sizeof(HeapWord) == 0, "copy by words"); duke@435: } duke@435: coleenp@4037: static int sort_dep(ciBaseObject** p1, ciBaseObject** p2, int narg) { duke@435: for (int i = 0; i < narg; i++) { duke@435: int diff = p1[i]->ident() - p2[i]->ident(); duke@435: if (diff != 0) return diff; duke@435: } duke@435: return 0; duke@435: } coleenp@4037: static int sort_dep_arg_1(ciBaseObject** p1, ciBaseObject** p2) duke@435: { return sort_dep(p1, p2, 1); } coleenp@4037: static int sort_dep_arg_2(ciBaseObject** p1, ciBaseObject** p2) duke@435: { return sort_dep(p1, p2, 2); } coleenp@4037: static int sort_dep_arg_3(ciBaseObject** p1, ciBaseObject** p2) duke@435: { return sort_dep(p1, p2, 3); } duke@435: duke@435: void Dependencies::sort_all_deps() { duke@435: for (int deptv = (int)FIRST_TYPE; deptv < (int)TYPE_LIMIT; deptv++) { duke@435: DepType dept = (DepType)deptv; coleenp@4037: GrowableArray* deps = _deps[dept]; duke@435: if (deps->length() <= 1) continue; duke@435: switch (dep_args(dept)) { duke@435: case 1: deps->sort(sort_dep_arg_1, 1); break; duke@435: case 2: deps->sort(sort_dep_arg_2, 2); break; duke@435: case 3: deps->sort(sort_dep_arg_3, 3); break; duke@435: default: ShouldNotReachHere(); duke@435: } duke@435: } duke@435: } duke@435: duke@435: size_t Dependencies::estimate_size_in_bytes() { duke@435: size_t est_size = 100; duke@435: for (int deptv = (int)FIRST_TYPE; deptv < (int)TYPE_LIMIT; deptv++) { duke@435: DepType dept = (DepType)deptv; coleenp@4037: GrowableArray* deps = _deps[dept]; duke@435: est_size += deps->length()*2; // tags and argument(s) duke@435: } duke@435: return est_size; duke@435: } duke@435: coleenp@4037: ciKlass* Dependencies::ctxk_encoded_as_null(DepType dept, ciBaseObject* x) { duke@435: switch (dept) { duke@435: case abstract_with_exclusive_concrete_subtypes_2: coleenp@4037: return x->as_metadata()->as_klass(); duke@435: case unique_concrete_method: duke@435: case exclusive_concrete_methods_2: coleenp@4037: return x->as_metadata()->as_method()->holder(); duke@435: } duke@435: return NULL; // let NULL be NULL duke@435: } duke@435: coleenp@4037: Klass* Dependencies::ctxk_encoded_as_null(DepType dept, Metadata* x) { duke@435: assert(must_be_in_vm(), "raw oops here"); duke@435: switch (dept) { duke@435: case abstract_with_exclusive_concrete_subtypes_2: duke@435: assert(x->is_klass(), "sanity"); coleenp@4037: return (Klass*) x; duke@435: case unique_concrete_method: duke@435: case exclusive_concrete_methods_2: duke@435: assert(x->is_method(), "sanity"); coleenp@4037: return ((Method*)x)->method_holder(); duke@435: } duke@435: return NULL; // let NULL be NULL duke@435: } duke@435: duke@435: void Dependencies::encode_content_bytes() { duke@435: sort_all_deps(); duke@435: duke@435: // cast is safe, no deps can overflow INT_MAX duke@435: CompressedWriteStream bytes((int)estimate_size_in_bytes()); duke@435: duke@435: for (int deptv = (int)FIRST_TYPE; deptv < (int)TYPE_LIMIT; deptv++) { duke@435: DepType dept = (DepType)deptv; coleenp@4037: GrowableArray* deps = _deps[dept]; duke@435: if (deps->length() == 0) continue; duke@435: int stride = dep_args(dept); duke@435: int ctxkj = dep_context_arg(dept); // -1 if no context arg duke@435: assert(stride > 0, "sanity"); duke@435: for (int i = 0; i < deps->length(); i += stride) { duke@435: jbyte code_byte = (jbyte)dept; duke@435: int skipj = -1; duke@435: if (ctxkj >= 0 && ctxkj+1 < stride) { coleenp@4037: ciKlass* ctxk = deps->at(i+ctxkj+0)->as_metadata()->as_klass(); coleenp@4037: ciBaseObject* x = deps->at(i+ctxkj+1); // following argument duke@435: if (ctxk == ctxk_encoded_as_null(dept, x)) { duke@435: skipj = ctxkj; // we win: maybe one less oop to keep track of duke@435: code_byte |= default_context_type_bit; duke@435: } duke@435: } duke@435: bytes.write_byte(code_byte); duke@435: for (int j = 0; j < stride; j++) { duke@435: if (j == skipj) continue; coleenp@4037: ciBaseObject* v = deps->at(i+j); vlivanov@4155: int idx; coleenp@4037: if (v->is_object()) { vlivanov@4155: idx = _oop_recorder->find_index(v->as_object()->constant_encoding()); coleenp@4037: } else { coleenp@4037: ciMetadata* meta = v->as_metadata(); vlivanov@4155: idx = _oop_recorder->find_index(meta->constant_encoding()); coleenp@4037: } vlivanov@4155: bytes.write_int(idx); duke@435: } duke@435: } duke@435: } duke@435: duke@435: // write a sentinel byte to mark the end duke@435: bytes.write_byte(end_marker); duke@435: duke@435: // round it out to a word boundary duke@435: while (bytes.position() % sizeof(HeapWord) != 0) { duke@435: bytes.write_byte(end_marker); duke@435: } duke@435: duke@435: // check whether the dept byte encoding really works duke@435: assert((jbyte)default_context_type_bit != 0, "byte overflow"); duke@435: duke@435: _content_bytes = bytes.buffer(); duke@435: _size_in_bytes = bytes.position(); duke@435: } duke@435: duke@435: duke@435: const char* Dependencies::_dep_name[TYPE_LIMIT] = { duke@435: "end_marker", duke@435: "evol_method", duke@435: "leaf_type", duke@435: "abstract_with_unique_concrete_subtype", duke@435: "abstract_with_no_concrete_subtype", duke@435: "concrete_with_no_concrete_subtype", duke@435: "unique_concrete_method", duke@435: "abstract_with_exclusive_concrete_subtypes_2", duke@435: "exclusive_concrete_methods_2", twisti@3050: "no_finalizable_subclasses", twisti@3050: "call_site_target_value" duke@435: }; duke@435: duke@435: int Dependencies::_dep_args[TYPE_LIMIT] = { duke@435: -1,// end_marker duke@435: 1, // evol_method m duke@435: 1, // leaf_type ctxk duke@435: 2, // abstract_with_unique_concrete_subtype ctxk, k duke@435: 1, // abstract_with_no_concrete_subtype ctxk duke@435: 1, // concrete_with_no_concrete_subtype ctxk duke@435: 2, // unique_concrete_method ctxk, m duke@435: 3, // unique_concrete_subtypes_2 ctxk, k1, k2 duke@435: 3, // unique_concrete_methods_2 ctxk, m1, m2 twisti@3050: 1, // no_finalizable_subclasses ctxk twisti@3094: 2 // call_site_target_value call_site, method_handle duke@435: }; duke@435: duke@435: const char* Dependencies::dep_name(Dependencies::DepType dept) { duke@435: if (!dept_in_mask(dept, all_types)) return "?bad-dep?"; duke@435: return _dep_name[dept]; duke@435: } duke@435: duke@435: int Dependencies::dep_args(Dependencies::DepType dept) { duke@435: if (!dept_in_mask(dept, all_types)) return -1; duke@435: return _dep_args[dept]; duke@435: } duke@435: twisti@3050: void Dependencies::check_valid_dependency_type(DepType dept) { twisti@3094: guarantee(FIRST_TYPE <= dept && dept < TYPE_LIMIT, err_msg("invalid dependency type: %d", (int) dept)); twisti@3050: } twisti@3050: duke@435: // for the sake of the compiler log, print out current dependencies: duke@435: void Dependencies::log_all_dependencies() { duke@435: if (log() == NULL) return; coleenp@4037: ciBaseObject* args[max_arg_count]; duke@435: for (int deptv = (int)FIRST_TYPE; deptv < (int)TYPE_LIMIT; deptv++) { duke@435: DepType dept = (DepType)deptv; coleenp@4037: GrowableArray* deps = _deps[dept]; duke@435: if (deps->length() == 0) continue; duke@435: int stride = dep_args(dept); duke@435: for (int i = 0; i < deps->length(); i += stride) { duke@435: for (int j = 0; j < stride; j++) { duke@435: // flush out the identities before printing duke@435: args[j] = deps->at(i+j); duke@435: } duke@435: write_dependency_to(log(), dept, stride, args); duke@435: } duke@435: } duke@435: } duke@435: duke@435: void Dependencies::write_dependency_to(CompileLog* log, duke@435: DepType dept, coleenp@4037: int nargs, DepArgument args[], coleenp@4037: Klass* witness) { duke@435: if (log == NULL) { duke@435: return; duke@435: } duke@435: ciEnv* env = ciEnv::current(); coleenp@4037: ciBaseObject* ciargs[max_arg_count]; duke@435: assert(nargs <= max_arg_count, "oob"); duke@435: for (int j = 0; j < nargs; j++) { coleenp@4037: if (args[j].is_oop()) { coleenp@4037: ciargs[j] = env->get_object(args[j].oop_value()); coleenp@4037: } else { coleenp@4037: ciargs[j] = env->get_metadata(args[j].metadata_value()); coleenp@4037: } duke@435: } duke@435: Dependencies::write_dependency_to(log, dept, nargs, ciargs, witness); duke@435: } duke@435: duke@435: void Dependencies::write_dependency_to(CompileLog* log, duke@435: DepType dept, coleenp@4037: int nargs, ciBaseObject* args[], coleenp@4037: Klass* witness) { duke@435: if (log == NULL) return; duke@435: assert(nargs <= max_arg_count, "oob"); duke@435: int argids[max_arg_count]; duke@435: int ctxkj = dep_context_arg(dept); // -1 if no context arg duke@435: int j; duke@435: for (j = 0; j < nargs; j++) { coleenp@4037: if (args[j]->is_object()) { coleenp@4037: argids[j] = log->identify(args[j]->as_object()); coleenp@4037: } else { coleenp@4037: argids[j] = log->identify(args[j]->as_metadata()); coleenp@4037: } duke@435: } duke@435: if (witness != NULL) { duke@435: log->begin_elem("dependency_failed"); duke@435: } else { duke@435: log->begin_elem("dependency"); duke@435: } duke@435: log->print(" type='%s'", dep_name(dept)); duke@435: if (ctxkj >= 0) { duke@435: log->print(" ctxk='%d'", argids[ctxkj]); duke@435: } duke@435: // write remaining arguments, if any. duke@435: for (j = 0; j < nargs; j++) { duke@435: if (j == ctxkj) continue; // already logged duke@435: if (j == 1) { duke@435: log->print( " x='%d'", argids[j]); duke@435: } else { duke@435: log->print(" x%d='%d'", j, argids[j]); duke@435: } duke@435: } duke@435: if (witness != NULL) { duke@435: log->object("witness", witness); duke@435: log->stamp(); duke@435: } duke@435: log->end_elem(); duke@435: } duke@435: duke@435: void Dependencies::write_dependency_to(xmlStream* xtty, duke@435: DepType dept, coleenp@4037: int nargs, DepArgument args[], coleenp@4037: Klass* witness) { duke@435: if (xtty == NULL) return; duke@435: ttyLocker ttyl; duke@435: int ctxkj = dep_context_arg(dept); // -1 if no context arg duke@435: if (witness != NULL) { duke@435: xtty->begin_elem("dependency_failed"); duke@435: } else { duke@435: xtty->begin_elem("dependency"); duke@435: } duke@435: xtty->print(" type='%s'", dep_name(dept)); duke@435: if (ctxkj >= 0) { coleenp@4037: xtty->object("ctxk", args[ctxkj].metadata_value()); duke@435: } duke@435: // write remaining arguments, if any. duke@435: for (int j = 0; j < nargs; j++) { duke@435: if (j == ctxkj) continue; // already logged duke@435: if (j == 1) { coleenp@4037: if (args[j].is_oop()) { coleenp@4037: xtty->object("x", args[j].oop_value()); coleenp@4037: } else { coleenp@4037: xtty->object("x", args[j].metadata_value()); coleenp@4037: } duke@435: } else { duke@435: char xn[10]; sprintf(xn, "x%d", j); coleenp@4037: if (args[j].is_oop()) { coleenp@4037: xtty->object(xn, args[j].oop_value()); coleenp@4037: } else { coleenp@4037: xtty->object(xn, args[j].metadata_value()); coleenp@4037: } duke@435: } duke@435: } duke@435: if (witness != NULL) { duke@435: xtty->object("witness", witness); duke@435: xtty->stamp(); duke@435: } duke@435: xtty->end_elem(); duke@435: } duke@435: coleenp@4037: void Dependencies::print_dependency(DepType dept, int nargs, DepArgument args[], coleenp@4037: Klass* witness) { duke@435: ResourceMark rm; duke@435: ttyLocker ttyl; // keep the following output all in one block duke@435: tty->print_cr("%s of type %s", duke@435: (witness == NULL)? "Dependency": "Failed dependency", duke@435: dep_name(dept)); duke@435: // print arguments duke@435: int ctxkj = dep_context_arg(dept); // -1 if no context arg duke@435: for (int j = 0; j < nargs; j++) { coleenp@4037: DepArgument arg = args[j]; duke@435: bool put_star = false; coleenp@4037: if (arg.is_null()) continue; duke@435: const char* what; duke@435: if (j == ctxkj) { coleenp@4037: assert(arg.is_metadata(), "must be"); duke@435: what = "context"; coleenp@4037: put_star = !Dependencies::is_concrete_klass((Klass*)arg.metadata_value()); coleenp@4037: } else if (arg.is_method()) { duke@435: what = "method "; coleenp@4037: put_star = !Dependencies::is_concrete_method((Method*)arg.metadata_value()); coleenp@4037: } else if (arg.is_klass()) { duke@435: what = "class "; duke@435: } else { duke@435: what = "object "; duke@435: } duke@435: tty->print(" %s = %s", what, (put_star? "*": "")); coleenp@4037: if (arg.is_klass()) hseigel@4278: tty->print("%s", ((Klass*)arg.metadata_value())->external_name()); coleenp@4037: else if (arg.is_method()) coleenp@4037: ((Method*)arg.metadata_value())->print_value(); duke@435: else coleenp@4037: ShouldNotReachHere(); // Provide impl for this type. duke@435: tty->cr(); duke@435: } duke@435: if (witness != NULL) { duke@435: bool put_star = !Dependencies::is_concrete_klass(witness); duke@435: tty->print_cr(" witness = %s%s", duke@435: (put_star? "*": ""), hseigel@4278: witness->external_name()); duke@435: } duke@435: } duke@435: coleenp@4037: void Dependencies::DepStream::log_dependency(Klass* witness) { duke@435: if (_deps == NULL && xtty == NULL) return; // fast cutout for runtime minqi@4267: ResourceMark rm; duke@435: int nargs = argument_count(); coleenp@4037: DepArgument args[max_arg_count]; duke@435: for (int j = 0; j < nargs; j++) { coleenp@4037: if (type() == call_site_target_value) { coleenp@4037: args[j] = argument_oop(j); coleenp@4037: } else { vlivanov@4155: args[j] = argument(j); vlivanov@4155: } coleenp@4037: } duke@435: if (_deps != NULL && _deps->log() != NULL) { duke@435: Dependencies::write_dependency_to(_deps->log(), duke@435: type(), nargs, args, witness); duke@435: } else { duke@435: Dependencies::write_dependency_to(xtty, duke@435: type(), nargs, args, witness); duke@435: } duke@435: } duke@435: coleenp@4037: void Dependencies::DepStream::print_dependency(Klass* witness, bool verbose) { duke@435: int nargs = argument_count(); coleenp@4037: DepArgument args[max_arg_count]; duke@435: for (int j = 0; j < nargs; j++) { duke@435: args[j] = argument(j); duke@435: } duke@435: Dependencies::print_dependency(type(), nargs, args, witness); duke@435: if (verbose) { duke@435: if (_code != NULL) { duke@435: tty->print(" code: "); duke@435: _code->print_value_on(tty); duke@435: tty->cr(); duke@435: } duke@435: } duke@435: } duke@435: duke@435: duke@435: /// Dependency stream support (decodes dependencies from an nmethod): duke@435: duke@435: #ifdef ASSERT duke@435: void Dependencies::DepStream::initial_asserts(size_t byte_limit) { duke@435: assert(must_be_in_vm(), "raw oops here"); duke@435: _byte_limit = byte_limit; duke@435: _type = (DepType)(end_marker-1); // defeat "already at end" assert duke@435: assert((_code!=NULL) + (_deps!=NULL) == 1, "one or t'other"); duke@435: } duke@435: #endif //ASSERT duke@435: duke@435: bool Dependencies::DepStream::next() { duke@435: assert(_type != end_marker, "already at end"); duke@435: if (_bytes.position() == 0 && _code != NULL duke@435: && _code->dependencies_size() == 0) { duke@435: // Method has no dependencies at all. duke@435: return false; duke@435: } duke@435: int code_byte = (_bytes.read_byte() & 0xFF); duke@435: if (code_byte == end_marker) { duke@435: DEBUG_ONLY(_type = end_marker); duke@435: return false; duke@435: } else { duke@435: int ctxk_bit = (code_byte & Dependencies::default_context_type_bit); duke@435: code_byte -= ctxk_bit; duke@435: DepType dept = (DepType)code_byte; duke@435: _type = dept; twisti@3094: Dependencies::check_valid_dependency_type(dept); duke@435: int stride = _dep_args[dept]; duke@435: assert(stride == dep_args(dept), "sanity"); duke@435: int skipj = -1; duke@435: if (ctxk_bit != 0) { duke@435: skipj = 0; // currently the only context argument is at zero duke@435: assert(skipj == dep_context_arg(dept), "zero arg always ctxk"); duke@435: } duke@435: for (int j = 0; j < stride; j++) { duke@435: _xi[j] = (j == skipj)? 0: _bytes.read_int(); duke@435: } duke@435: DEBUG_ONLY(_xi[stride] = -1); // help detect overruns duke@435: return true; duke@435: } duke@435: } duke@435: coleenp@4037: inline Metadata* Dependencies::DepStream::recorded_metadata_at(int i) { coleenp@4037: Metadata* o = NULL; coleenp@4037: if (_code != NULL) { coleenp@4037: o = _code->metadata_at(i); coleenp@4037: } else { coleenp@4037: o = _deps->oop_recorder()->metadata_at(i); coleenp@4037: } coleenp@5307: assert(o == NULL || o->is_metaspace_object(), coleenp@5307: err_msg("Should be metadata " PTR_FORMAT, o)); coleenp@4037: return o; coleenp@4037: } coleenp@4037: duke@435: inline oop Dependencies::DepStream::recorded_oop_at(int i) { duke@435: return (_code != NULL) duke@435: ? _code->oop_at(i) coleenp@4037: : JNIHandles::resolve(_deps->oop_recorder()->oop_at(i)); duke@435: } duke@435: coleenp@4037: Metadata* Dependencies::DepStream::argument(int i) { coleenp@4037: Metadata* result = recorded_metadata_at(argument_index(i)); vlivanov@4155: vlivanov@4155: if (result == NULL) { // Explicit context argument can be compressed vlivanov@4155: int ctxkj = dep_context_arg(type()); // -1 if no explicit context arg vlivanov@4155: if (ctxkj >= 0 && i == ctxkj && ctxkj+1 < argument_count()) { vlivanov@4155: result = ctxk_encoded_as_null(type(), argument(ctxkj+1)); vlivanov@4155: } vlivanov@4155: } vlivanov@4155: coleenp@4037: assert(result == NULL || result->is_klass() || result->is_method(), "must be"); coleenp@4037: return result; duke@435: } duke@435: coleenp@4037: oop Dependencies::DepStream::argument_oop(int i) { coleenp@4037: oop result = recorded_oop_at(argument_index(i)); coleenp@4037: assert(result == NULL || result->is_oop(), "must be"); coleenp@4037: return result; coleenp@4037: } coleenp@4037: coleenp@4037: Klass* Dependencies::DepStream::context_type() { duke@435: assert(must_be_in_vm(), "raw oops here"); twisti@3094: twisti@3094: // Most dependencies have an explicit context type argument. twisti@3094: { vlivanov@4155: int ctxkj = dep_context_arg(type()); // -1 if no explicit context arg twisti@3094: if (ctxkj >= 0) { coleenp@4037: Metadata* k = argument(ctxkj); vlivanov@4155: assert(k != NULL && k->is_klass(), "type check"); vlivanov@4155: return (Klass*)k; twisti@3094: } twisti@3094: } twisti@3094: twisti@3094: // Some dependencies are using the klass of the first object twisti@3094: // argument as implicit context type (e.g. call_site_target_value). twisti@3094: { vlivanov@4155: int ctxkj = dep_implicit_context_arg(type()); twisti@3094: if (ctxkj >= 0) { coleenp@4037: Klass* k = argument_oop(ctxkj)->klass(); vlivanov@4155: assert(k != NULL && k->is_klass(), "type check"); coleenp@4037: return (Klass*) k; duke@435: } duke@435: } twisti@3094: twisti@3094: // And some dependencies don't have a context type at all, twisti@3094: // e.g. evol_method. twisti@3094: return NULL; duke@435: } duke@435: duke@435: /// Checking dependencies: duke@435: duke@435: // This hierarchy walker inspects subtypes of a given type, duke@435: // trying to find a "bad" class which breaks a dependency. duke@435: // Such a class is called a "witness" to the broken dependency. duke@435: // While searching around, we ignore "participants", which duke@435: // are already known to the dependency. duke@435: class ClassHierarchyWalker { duke@435: public: duke@435: enum { PARTICIPANT_LIMIT = 3 }; duke@435: duke@435: private: duke@435: // optional method descriptor to check for: coleenp@2497: Symbol* _name; coleenp@2497: Symbol* _signature; duke@435: duke@435: // special classes which are not allowed to be witnesses: coleenp@4037: Klass* _participants[PARTICIPANT_LIMIT+1]; duke@435: int _num_participants; duke@435: duke@435: // cache of method lookups coleenp@4037: Method* _found_methods[PARTICIPANT_LIMIT+1]; duke@435: duke@435: // if non-zero, tells how many witnesses to convert to participants duke@435: int _record_witnesses; duke@435: coleenp@4037: void initialize(Klass* participant) { duke@435: _record_witnesses = 0; duke@435: _participants[0] = participant; duke@435: _found_methods[0] = NULL; duke@435: _num_participants = 0; duke@435: if (participant != NULL) { duke@435: // Terminating NULL. duke@435: _participants[1] = NULL; duke@435: _found_methods[1] = NULL; duke@435: _num_participants = 1; duke@435: } duke@435: } duke@435: coleenp@4037: void initialize_from_method(Method* m) { duke@435: assert(m != NULL && m->is_method(), "sanity"); duke@435: _name = m->name(); duke@435: _signature = m->signature(); duke@435: } duke@435: duke@435: public: duke@435: // The walker is initialized to recognize certain methods and/or types duke@435: // as friendly participants. coleenp@4037: ClassHierarchyWalker(Klass* participant, Method* m) { duke@435: initialize_from_method(m); duke@435: initialize(participant); duke@435: } coleenp@4037: ClassHierarchyWalker(Method* m) { duke@435: initialize_from_method(m); duke@435: initialize(NULL); duke@435: } coleenp@4037: ClassHierarchyWalker(Klass* participant = NULL) { duke@435: _name = NULL; duke@435: _signature = NULL; duke@435: initialize(participant); duke@435: } duke@435: duke@435: // This is common code for two searches: One for concrete subtypes, duke@435: // the other for concrete method implementations and overrides. duke@435: bool doing_subtype_search() { duke@435: return _name == NULL; duke@435: } duke@435: duke@435: int num_participants() { return _num_participants; } coleenp@4037: Klass* participant(int n) { duke@435: assert((uint)n <= (uint)_num_participants, "oob"); duke@435: return _participants[n]; duke@435: } duke@435: duke@435: // Note: If n==num_participants, returns NULL. coleenp@4037: Method* found_method(int n) { duke@435: assert((uint)n <= (uint)_num_participants, "oob"); coleenp@4037: Method* fm = _found_methods[n]; duke@435: assert(n == _num_participants || fm != NULL, "proper usage"); duke@435: assert(fm == NULL || fm->method_holder() == _participants[n], "sanity"); duke@435: return fm; duke@435: } duke@435: duke@435: #ifdef ASSERT duke@435: // Assert that m is inherited into ctxk, without intervening overrides. duke@435: // (May return true even if this is not true, in corner cases where we punt.) coleenp@4037: bool check_method_context(Klass* ctxk, Method* m) { duke@435: if (m->method_holder() == ctxk) duke@435: return true; // Quick win. duke@435: if (m->is_private()) duke@435: return false; // Quick lose. Should not happen. duke@435: if (!(m->is_public() || m->is_protected())) duke@435: // The override story is complex when packages get involved. duke@435: return true; // Must punt the assertion to true. hseigel@4278: Klass* k = ctxk; coleenp@4037: Method* lm = k->lookup_method(m->name(), m->signature()); duke@435: if (lm == NULL && k->oop_is_instance()) { acorn@5848: // It might be an interface method acorn@5848: lm = ((InstanceKlass*)k)->lookup_method_in_ordered_interfaces(m->name(), duke@435: m->signature()); duke@435: } duke@435: if (lm == m) duke@435: // Method m is inherited into ctxk. duke@435: return true; duke@435: if (lm != NULL) { never@3256: if (!(lm->is_public() || lm->is_protected())) { duke@435: // Method is [package-]private, so the override story is complex. duke@435: return true; // Must punt the assertion to true. never@3256: } never@3256: if (lm->is_static()) { never@3256: // Static methods don't override non-static so punt never@3256: return true; never@3256: } duke@435: if ( !Dependencies::is_concrete_method(lm) duke@435: && !Dependencies::is_concrete_method(m) coleenp@4251: && lm->method_holder()->is_subtype_of(m->method_holder())) duke@435: // Method m is overridden by lm, but both are non-concrete. duke@435: return true; duke@435: } duke@435: ResourceMark rm; duke@435: tty->print_cr("Dependency method not found in the associated context:"); hseigel@4278: tty->print_cr(" context = %s", ctxk->external_name()); duke@435: tty->print( " method = "); m->print_short_name(tty); tty->cr(); duke@435: if (lm != NULL) { duke@435: tty->print( " found = "); lm->print_short_name(tty); tty->cr(); duke@435: } duke@435: return false; duke@435: } duke@435: #endif duke@435: coleenp@4037: void add_participant(Klass* participant) { duke@435: assert(_num_participants + _record_witnesses < PARTICIPANT_LIMIT, "oob"); duke@435: int np = _num_participants++; duke@435: _participants[np] = participant; duke@435: _participants[np+1] = NULL; duke@435: _found_methods[np+1] = NULL; duke@435: } duke@435: duke@435: void record_witnesses(int add) { duke@435: if (add > PARTICIPANT_LIMIT) add = PARTICIPANT_LIMIT; duke@435: assert(_num_participants + add < PARTICIPANT_LIMIT, "oob"); duke@435: _record_witnesses = add; duke@435: } duke@435: coleenp@4037: bool is_witness(Klass* k) { duke@435: if (doing_subtype_search()) { duke@435: return Dependencies::is_concrete_klass(k); duke@435: } else { coleenp@4037: Method* m = InstanceKlass::cast(k)->find_method(_name, _signature); duke@435: if (m == NULL || !Dependencies::is_concrete_method(m)) return false; duke@435: _found_methods[_num_participants] = m; duke@435: // Note: If add_participant(k) is called, duke@435: // the method m will already be memoized for it. duke@435: return true; duke@435: } duke@435: } duke@435: coleenp@4037: bool is_participant(Klass* k) { duke@435: if (k == _participants[0]) { duke@435: return true; duke@435: } else if (_num_participants <= 1) { duke@435: return false; duke@435: } else { duke@435: return in_list(k, &_participants[1]); duke@435: } duke@435: } coleenp@4037: bool ignore_witness(Klass* witness) { duke@435: if (_record_witnesses == 0) { duke@435: return false; duke@435: } else { duke@435: --_record_witnesses; duke@435: add_participant(witness); duke@435: return true; duke@435: } duke@435: } coleenp@4037: static bool in_list(Klass* x, Klass** list) { duke@435: for (int i = 0; ; i++) { coleenp@4037: Klass* y = list[i]; duke@435: if (y == NULL) break; duke@435: if (y == x) return true; duke@435: } duke@435: return false; // not in list duke@435: } duke@435: duke@435: private: duke@435: // the actual search method: coleenp@4037: Klass* find_witness_anywhere(Klass* context_type, duke@435: bool participants_hide_witnesses, duke@435: bool top_level_call = true); duke@435: // the spot-checking version: coleenp@4037: Klass* find_witness_in(KlassDepChange& changes, coleenp@4037: Klass* context_type, duke@435: bool participants_hide_witnesses); duke@435: public: coleenp@4037: Klass* find_witness_subtype(Klass* context_type, KlassDepChange* changes = NULL) { duke@435: assert(doing_subtype_search(), "must set up a subtype search"); duke@435: // When looking for unexpected concrete types, duke@435: // do not look beneath expected ones. duke@435: const bool participants_hide_witnesses = true; duke@435: // CX > CC > C' is OK, even if C' is new. duke@435: // CX > { CC, C' } is not OK if C' is new, and C' is the witness. duke@435: if (changes != NULL) { duke@435: return find_witness_in(*changes, context_type, participants_hide_witnesses); duke@435: } else { duke@435: return find_witness_anywhere(context_type, participants_hide_witnesses); duke@435: } duke@435: } coleenp@4037: Klass* find_witness_definer(Klass* context_type, KlassDepChange* changes = NULL) { duke@435: assert(!doing_subtype_search(), "must set up a method definer search"); duke@435: // When looking for unexpected concrete methods, duke@435: // look beneath expected ones, to see if there are overrides. duke@435: const bool participants_hide_witnesses = true; duke@435: // CX.m > CC.m > C'.m is not OK, if C'.m is new, and C' is the witness. duke@435: if (changes != NULL) { duke@435: return find_witness_in(*changes, context_type, !participants_hide_witnesses); duke@435: } else { duke@435: return find_witness_anywhere(context_type, !participants_hide_witnesses); duke@435: } duke@435: } duke@435: }; duke@435: duke@435: #ifndef PRODUCT duke@435: static int deps_find_witness_calls = 0; duke@435: static int deps_find_witness_steps = 0; duke@435: static int deps_find_witness_recursions = 0; duke@435: static int deps_find_witness_singles = 0; duke@435: static int deps_find_witness_print = 0; // set to -1 to force a final print duke@435: static bool count_find_witness_calls() { duke@435: if (TraceDependencies || LogCompilation) { duke@435: int pcount = deps_find_witness_print + 1; duke@435: bool final_stats = (pcount == 0); duke@435: bool initial_call = (pcount == 1); duke@435: bool occasional_print = ((pcount & ((1<<10) - 1)) == 0); duke@435: if (pcount < 0) pcount = 1; // crude overflow protection duke@435: deps_find_witness_print = pcount; duke@435: if (VerifyDependencies && initial_call) { duke@435: tty->print_cr("Warning: TraceDependencies results may be inflated by VerifyDependencies"); duke@435: } duke@435: if (occasional_print || final_stats) { duke@435: // Every now and then dump a little info about dependency searching. duke@435: if (xtty != NULL) { kvn@1641: ttyLocker ttyl; kvn@1641: xtty->elem("deps_find_witness calls='%d' steps='%d' recursions='%d' singles='%d'", duke@435: deps_find_witness_calls, duke@435: deps_find_witness_steps, duke@435: deps_find_witness_recursions, duke@435: deps_find_witness_singles); duke@435: } duke@435: if (final_stats || (TraceDependencies && WizardMode)) { kvn@1641: ttyLocker ttyl; duke@435: tty->print_cr("Dependency check (find_witness) " duke@435: "calls=%d, steps=%d (avg=%.1f), recursions=%d, singles=%d", duke@435: deps_find_witness_calls, duke@435: deps_find_witness_steps, duke@435: (double)deps_find_witness_steps / deps_find_witness_calls, duke@435: deps_find_witness_recursions, duke@435: deps_find_witness_singles); duke@435: } duke@435: } duke@435: return true; duke@435: } duke@435: return false; duke@435: } duke@435: #else duke@435: #define count_find_witness_calls() (0) duke@435: #endif //PRODUCT duke@435: duke@435: coleenp@4037: Klass* ClassHierarchyWalker::find_witness_in(KlassDepChange& changes, coleenp@4037: Klass* context_type, duke@435: bool participants_hide_witnesses) { duke@435: assert(changes.involves_context(context_type), "irrelevant dependency"); coleenp@4037: Klass* new_type = changes.new_type(); duke@435: ccheung@5259: (void)count_find_witness_calls(); duke@435: NOT_PRODUCT(deps_find_witness_singles++); duke@435: duke@435: // Current thread must be in VM (not native mode, as in CI): duke@435: assert(must_be_in_vm(), "raw oops here"); duke@435: // Must not move the class hierarchy during this check: duke@435: assert_locked_or_safepoint(Compile_lock); duke@435: coleenp@4037: int nof_impls = InstanceKlass::cast(context_type)->nof_implementors(); jrose@465: if (nof_impls > 1) { jrose@465: // Avoid this case: *I.m > { A.m, C }; B.m > C jrose@465: // %%% Until this is fixed more systematically, bail out. jrose@465: // See corresponding comment in find_witness_anywhere. jrose@465: return context_type; jrose@465: } jrose@465: duke@435: assert(!is_participant(new_type), "only old classes are participants"); duke@435: if (participants_hide_witnesses) { duke@435: // If the new type is a subtype of a participant, we are done. duke@435: for (int i = 0; i < num_participants(); i++) { coleenp@4037: Klass* part = participant(i); duke@435: if (part == NULL) continue; hseigel@4278: assert(changes.involves_context(part) == new_type->is_subtype_of(part), duke@435: "correct marking of participants, b/c new_type is unique"); duke@435: if (changes.involves_context(part)) { duke@435: // new guy is protected from this check by previous participant duke@435: return NULL; duke@435: } duke@435: } duke@435: } duke@435: duke@435: if (is_witness(new_type) && duke@435: !ignore_witness(new_type)) { duke@435: return new_type; duke@435: } duke@435: duke@435: return NULL; duke@435: } duke@435: duke@435: duke@435: // Walk hierarchy under a context type, looking for unexpected types. duke@435: // Do not report participant types, and recursively walk beneath duke@435: // them only if participants_hide_witnesses is false. duke@435: // If top_level_call is false, skip testing the context type, duke@435: // because the caller has already considered it. coleenp@4037: Klass* ClassHierarchyWalker::find_witness_anywhere(Klass* context_type, duke@435: bool participants_hide_witnesses, duke@435: bool top_level_call) { duke@435: // Current thread must be in VM (not native mode, as in CI): duke@435: assert(must_be_in_vm(), "raw oops here"); duke@435: // Must not move the class hierarchy during this check: duke@435: assert_locked_or_safepoint(Compile_lock); duke@435: duke@435: bool do_counts = count_find_witness_calls(); duke@435: duke@435: // Check the root of the sub-hierarchy first. duke@435: if (top_level_call) { duke@435: if (do_counts) { duke@435: NOT_PRODUCT(deps_find_witness_calls++); duke@435: NOT_PRODUCT(deps_find_witness_steps++); duke@435: } duke@435: if (is_participant(context_type)) { duke@435: if (participants_hide_witnesses) return NULL; duke@435: // else fall through to search loop... duke@435: } else if (is_witness(context_type) && !ignore_witness(context_type)) { duke@435: // The context is an abstract class or interface, to start with. duke@435: return context_type; duke@435: } duke@435: } duke@435: duke@435: // Now we must check each implementor and each subclass. duke@435: // Use a short worklist to avoid blowing the stack. duke@435: // Each worklist entry is a *chain* of subklass siblings to process. coleenp@4037: const int CHAINMAX = 100; // >= 1 + InstanceKlass::implementors_limit duke@435: Klass* chains[CHAINMAX]; duke@435: int chaini = 0; // index into worklist duke@435: Klass* chain; // scratch variable duke@435: #define ADD_SUBCLASS_CHAIN(k) { \ duke@435: assert(chaini < CHAINMAX, "oob"); \ coleenp@4037: chain = InstanceKlass::cast(k)->subklass(); \ duke@435: if (chain != NULL) chains[chaini++] = chain; } duke@435: duke@435: // Look for non-abstract subclasses. duke@435: // (Note: Interfaces do not have subclasses.) duke@435: ADD_SUBCLASS_CHAIN(context_type); duke@435: duke@435: // If it is an interface, search its direct implementors. duke@435: // (Their subclasses are additional indirect implementors. coleenp@4037: // See InstanceKlass::add_implementor.) duke@435: // (Note: nof_implementors is always zero for non-interfaces.) coleenp@4037: int nof_impls = InstanceKlass::cast(context_type)->nof_implementors(); duke@435: if (nof_impls > 1) { duke@435: // Avoid this case: *I.m > { A.m, C }; B.m > C duke@435: // Here, I.m has 2 concrete implementations, but m appears unique duke@435: // as A.m, because the search misses B.m when checking C. duke@435: // The inherited method B.m was getting missed by the walker duke@435: // when interface 'I' was the starting point. duke@435: // %%% Until this is fixed more systematically, bail out. duke@435: // (Old CHA had the same limitation.) duke@435: return context_type; duke@435: } jiangli@3701: if (nof_impls > 0) { coleenp@4037: Klass* impl = InstanceKlass::cast(context_type)->implementor(); jiangli@3701: assert(impl != NULL, "just checking"); jiangli@3701: // If impl is the same as the context_type, then more than one jiangli@3701: // implementor has seen. No exact info in this case. jiangli@3701: if (impl == context_type) { duke@435: return context_type; // report an inexact witness to this sad affair duke@435: } duke@435: if (do_counts) duke@435: { NOT_PRODUCT(deps_find_witness_steps++); } duke@435: if (is_participant(impl)) { jiangli@3701: if (!participants_hide_witnesses) { jiangli@3701: ADD_SUBCLASS_CHAIN(impl); jiangli@3701: } duke@435: } else if (is_witness(impl) && !ignore_witness(impl)) { duke@435: return impl; jiangli@3701: } else { jiangli@3701: ADD_SUBCLASS_CHAIN(impl); duke@435: } duke@435: } duke@435: duke@435: // Recursively process each non-trivial sibling chain. duke@435: while (chaini > 0) { duke@435: Klass* chain = chains[--chaini]; coleenp@4037: for (Klass* sub = chain; sub != NULL; sub = sub->next_sibling()) { duke@435: if (do_counts) { NOT_PRODUCT(deps_find_witness_steps++); } duke@435: if (is_participant(sub)) { duke@435: if (participants_hide_witnesses) continue; duke@435: // else fall through to process this guy's subclasses duke@435: } else if (is_witness(sub) && !ignore_witness(sub)) { duke@435: return sub; duke@435: } duke@435: if (chaini < (VerifyDependencies? 2: CHAINMAX)) { duke@435: // Fast path. (Partially disabled if VerifyDependencies.) duke@435: ADD_SUBCLASS_CHAIN(sub); duke@435: } else { duke@435: // Worklist overflow. Do a recursive call. Should be rare. duke@435: // The recursive call will have its own worklist, of course. duke@435: // (Note that sub has already been tested, so that there is duke@435: // no need for the recursive call to re-test. That's handy, duke@435: // since the recursive call sees sub as the context_type.) duke@435: if (do_counts) { NOT_PRODUCT(deps_find_witness_recursions++); } coleenp@4037: Klass* witness = find_witness_anywhere(sub, duke@435: participants_hide_witnesses, duke@435: /*top_level_call=*/ false); duke@435: if (witness != NULL) return witness; duke@435: } duke@435: } duke@435: } duke@435: duke@435: // No witness found. The dependency remains unbroken. duke@435: return NULL; duke@435: #undef ADD_SUBCLASS_CHAIN duke@435: } duke@435: duke@435: coleenp@4037: bool Dependencies::is_concrete_klass(Klass* k) { hseigel@4278: if (k->is_abstract()) return false; duke@435: // %%% We could treat classes which are concrete but duke@435: // have not yet been instantiated as virtually abstract. duke@435: // This would require a deoptimization barrier on first instantiation. duke@435: //if (k->is_not_instantiated()) return false; duke@435: return true; duke@435: } duke@435: coleenp@4037: bool Dependencies::is_concrete_method(Method* m) { never@3256: // Statics are irrelevant to virtual call sites. never@3256: if (m->is_static()) return false; never@3256: never@3256: // We could also return false if m does not yet appear to be never@3256: // executed, if the VM version supports this distinction also. kamg@4245: return !m->is_abstract() && kamg@4245: !InstanceKlass::cast(m->method_holder())->is_interface(); kamg@4245: // TODO: investigate whether default methods should be kamg@4245: // considered as "concrete" in this situation. For now they kamg@4245: // are not. duke@435: } duke@435: duke@435: duke@435: Klass* Dependencies::find_finalizable_subclass(Klass* k) { duke@435: if (k->is_interface()) return NULL; duke@435: if (k->has_finalizer()) return k; duke@435: k = k->subklass(); duke@435: while (k != NULL) { duke@435: Klass* result = find_finalizable_subclass(k); duke@435: if (result != NULL) return result; duke@435: k = k->next_sibling(); duke@435: } duke@435: return NULL; duke@435: } duke@435: duke@435: duke@435: bool Dependencies::is_concrete_klass(ciInstanceKlass* k) { duke@435: if (k->is_abstract()) return false; never@3256: // We could also return false if k does not yet appear to be duke@435: // instantiated, if the VM version supports this distinction also. duke@435: //if (k->is_not_instantiated()) return false; duke@435: return true; duke@435: } duke@435: duke@435: bool Dependencies::is_concrete_method(ciMethod* m) { duke@435: // Statics are irrelevant to virtual call sites. duke@435: if (m->is_static()) return false; duke@435: never@3256: // We could also return false if m does not yet appear to be duke@435: // executed, if the VM version supports this distinction also. duke@435: return !m->is_abstract(); duke@435: } duke@435: duke@435: duke@435: bool Dependencies::has_finalizable_subclass(ciInstanceKlass* k) { duke@435: return k->has_finalizable_subclass(); duke@435: } duke@435: duke@435: duke@435: // Any use of the contents (bytecodes) of a method must be duke@435: // marked by an "evol_method" dependency, if those contents duke@435: // can change. (Note: A method is always dependent on itself.) coleenp@4037: Klass* Dependencies::check_evol_method(Method* m) { duke@435: assert(must_be_in_vm(), "raw oops here"); duke@435: // Did somebody do a JVMTI RedefineClasses while our backs were turned? duke@435: // Or is there a now a breakpoint? duke@435: // (Assumes compiled code cannot handle bkpts; change if UseFastBreakpoints.) duke@435: if (m->is_old() duke@435: || m->number_of_breakpoints() > 0) { duke@435: return m->method_holder(); duke@435: } else { duke@435: return NULL; duke@435: } duke@435: } duke@435: duke@435: // This is a strong assertion: It is that the given type duke@435: // has no subtypes whatever. It is most useful for duke@435: // optimizing checks on reflected types or on array types. duke@435: // (Checks on types which are derived from real instances duke@435: // can be optimized more strongly than this, because we duke@435: // know that the checked type comes from a concrete type, duke@435: // and therefore we can disregard abstract types.) coleenp@4037: Klass* Dependencies::check_leaf_type(Klass* ctxk) { duke@435: assert(must_be_in_vm(), "raw oops here"); duke@435: assert_locked_or_safepoint(Compile_lock); coleenp@4037: InstanceKlass* ctx = InstanceKlass::cast(ctxk); duke@435: Klass* sub = ctx->subklass(); duke@435: if (sub != NULL) { coleenp@4037: return sub; duke@435: } else if (ctx->nof_implementors() != 0) { duke@435: // if it is an interface, it must be unimplemented duke@435: // (if it is not an interface, nof_implementors is always zero) coleenp@4037: Klass* impl = ctx->implementor(); jiangli@3701: assert(impl != NULL, "must be set"); jiangli@3701: return impl; duke@435: } else { duke@435: return NULL; duke@435: } duke@435: } duke@435: duke@435: // Test the assertion that conck is the only concrete subtype* of ctxk. duke@435: // The type conck itself is allowed to have have further concrete subtypes. duke@435: // This allows the compiler to narrow occurrences of ctxk by conck, duke@435: // when dealing with the types of actual instances. coleenp@4037: Klass* Dependencies::check_abstract_with_unique_concrete_subtype(Klass* ctxk, coleenp@4037: Klass* conck, twisti@3050: KlassDepChange* changes) { duke@435: ClassHierarchyWalker wf(conck); duke@435: return wf.find_witness_subtype(ctxk, changes); duke@435: } duke@435: duke@435: // If a non-concrete class has no concrete subtypes, it is not (yet) duke@435: // instantiatable. This can allow the compiler to make some paths go duke@435: // dead, if they are gated by a test of the type. coleenp@4037: Klass* Dependencies::check_abstract_with_no_concrete_subtype(Klass* ctxk, twisti@3050: KlassDepChange* changes) { duke@435: // Find any concrete subtype, with no participants: duke@435: ClassHierarchyWalker wf; duke@435: return wf.find_witness_subtype(ctxk, changes); duke@435: } duke@435: duke@435: duke@435: // If a concrete class has no concrete subtypes, it can always be duke@435: // exactly typed. This allows the use of a cheaper type test. coleenp@4037: Klass* Dependencies::check_concrete_with_no_concrete_subtype(Klass* ctxk, twisti@3050: KlassDepChange* changes) { duke@435: // Find any concrete subtype, with only the ctxk as participant: duke@435: ClassHierarchyWalker wf(ctxk); duke@435: return wf.find_witness_subtype(ctxk, changes); duke@435: } duke@435: duke@435: duke@435: // Find the unique concrete proper subtype of ctxk, or NULL if there duke@435: // is more than one concrete proper subtype. If there are no concrete duke@435: // proper subtypes, return ctxk itself, whether it is concrete or not. duke@435: // The returned subtype is allowed to have have further concrete subtypes. duke@435: // That is, return CC1 for CX > CC1 > CC2, but NULL for CX > { CC1, CC2 }. coleenp@4037: Klass* Dependencies::find_unique_concrete_subtype(Klass* ctxk) { duke@435: ClassHierarchyWalker wf(ctxk); // Ignore ctxk when walking. duke@435: wf.record_witnesses(1); // Record one other witness when walking. coleenp@4037: Klass* wit = wf.find_witness_subtype(ctxk); duke@435: if (wit != NULL) return NULL; // Too many witnesses. coleenp@4037: Klass* conck = wf.participant(0); duke@435: if (conck == NULL) { duke@435: #ifndef PRODUCT duke@435: // Make sure the dependency mechanism will pass this discovery: duke@435: if (VerifyDependencies) { duke@435: // Turn off dependency tracing while actually testing deps. duke@435: FlagSetting fs(TraceDependencies, false); duke@435: if (!Dependencies::is_concrete_klass(ctxk)) { duke@435: guarantee(NULL == duke@435: (void *)check_abstract_with_no_concrete_subtype(ctxk), duke@435: "verify dep."); duke@435: } else { duke@435: guarantee(NULL == duke@435: (void *)check_concrete_with_no_concrete_subtype(ctxk), duke@435: "verify dep."); duke@435: } duke@435: } duke@435: #endif //PRODUCT duke@435: return ctxk; // Return ctxk as a flag for "no subtypes". duke@435: } else { duke@435: #ifndef PRODUCT duke@435: // Make sure the dependency mechanism will pass this discovery: duke@435: if (VerifyDependencies) { duke@435: // Turn off dependency tracing while actually testing deps. duke@435: FlagSetting fs(TraceDependencies, false); duke@435: if (!Dependencies::is_concrete_klass(ctxk)) { duke@435: guarantee(NULL == (void *) duke@435: check_abstract_with_unique_concrete_subtype(ctxk, conck), duke@435: "verify dep."); duke@435: } duke@435: } duke@435: #endif //PRODUCT duke@435: return conck; duke@435: } duke@435: } duke@435: duke@435: // Test the assertion that the k[12] are the only concrete subtypes of ctxk, duke@435: // except possibly for further subtypes of k[12] themselves. duke@435: // The context type must be abstract. The types k1 and k2 are themselves duke@435: // allowed to have further concrete subtypes. coleenp@4037: Klass* Dependencies::check_abstract_with_exclusive_concrete_subtypes( coleenp@4037: Klass* ctxk, coleenp@4037: Klass* k1, coleenp@4037: Klass* k2, twisti@3050: KlassDepChange* changes) { duke@435: ClassHierarchyWalker wf; duke@435: wf.add_participant(k1); duke@435: wf.add_participant(k2); duke@435: return wf.find_witness_subtype(ctxk, changes); duke@435: } duke@435: duke@435: // Search ctxk for concrete implementations. If there are klen or fewer, duke@435: // pack them into the given array and return the number. duke@435: // Otherwise, return -1, meaning the given array would overflow. duke@435: // (Note that a return of 0 means there are exactly no concrete subtypes.) duke@435: // In this search, if ctxk is concrete, it will be reported alone. duke@435: // For any type CC reported, no proper subtypes of CC will be reported. coleenp@4037: int Dependencies::find_exclusive_concrete_subtypes(Klass* ctxk, duke@435: int klen, coleenp@4037: Klass* karray[]) { duke@435: ClassHierarchyWalker wf; duke@435: wf.record_witnesses(klen); coleenp@4037: Klass* wit = wf.find_witness_subtype(ctxk); duke@435: if (wit != NULL) return -1; // Too many witnesses. duke@435: int num = wf.num_participants(); duke@435: assert(num <= klen, "oob"); duke@435: // Pack the result array with the good news. duke@435: for (int i = 0; i < num; i++) duke@435: karray[i] = wf.participant(i); duke@435: #ifndef PRODUCT duke@435: // Make sure the dependency mechanism will pass this discovery: duke@435: if (VerifyDependencies) { duke@435: // Turn off dependency tracing while actually testing deps. duke@435: FlagSetting fs(TraceDependencies, false); duke@435: switch (Dependencies::is_concrete_klass(ctxk)? -1: num) { duke@435: case -1: // ctxk was itself concrete duke@435: guarantee(num == 1 && karray[0] == ctxk, "verify dep."); duke@435: break; duke@435: case 0: duke@435: guarantee(NULL == (void *)check_abstract_with_no_concrete_subtype(ctxk), duke@435: "verify dep."); duke@435: break; duke@435: case 1: duke@435: guarantee(NULL == (void *) duke@435: check_abstract_with_unique_concrete_subtype(ctxk, karray[0]), duke@435: "verify dep."); duke@435: break; duke@435: case 2: duke@435: guarantee(NULL == (void *) duke@435: check_abstract_with_exclusive_concrete_subtypes(ctxk, duke@435: karray[0], duke@435: karray[1]), duke@435: "verify dep."); duke@435: break; duke@435: default: duke@435: ShouldNotReachHere(); // klen > 2 yet supported duke@435: } duke@435: } duke@435: #endif //PRODUCT duke@435: return num; duke@435: } duke@435: duke@435: // If a class (or interface) has a unique concrete method uniqm, return NULL. duke@435: // Otherwise, return a class that contains an interfering method. coleenp@4037: Klass* Dependencies::check_unique_concrete_method(Klass* ctxk, Method* uniqm, twisti@3050: KlassDepChange* changes) { duke@435: // Here is a missing optimization: If uniqm->is_final(), duke@435: // we don't really need to search beneath it for overrides. duke@435: // This is probably not important, since we don't use dependencies duke@435: // to track final methods. (They can't be "definalized".) duke@435: ClassHierarchyWalker wf(uniqm->method_holder(), uniqm); duke@435: return wf.find_witness_definer(ctxk, changes); duke@435: } duke@435: duke@435: // Find the set of all non-abstract methods under ctxk that match m. duke@435: // (The method m must be defined or inherited in ctxk.) duke@435: // Include m itself in the set, unless it is abstract. duke@435: // If this set has exactly one element, return that element. coleenp@4037: Method* Dependencies::find_unique_concrete_method(Klass* ctxk, Method* m) { duke@435: ClassHierarchyWalker wf(m); duke@435: assert(wf.check_method_context(ctxk, m), "proper context"); duke@435: wf.record_witnesses(1); coleenp@4037: Klass* wit = wf.find_witness_definer(ctxk); duke@435: if (wit != NULL) return NULL; // Too many witnesses. coleenp@4037: Method* fm = wf.found_method(0); // Will be NULL if num_parts == 0. duke@435: if (Dependencies::is_concrete_method(m)) { duke@435: if (fm == NULL) { duke@435: // It turns out that m was always the only implementation. duke@435: fm = m; duke@435: } else if (fm != m) { duke@435: // Two conflicting implementations after all. duke@435: // (This can happen if m is inherited into ctxk and fm overrides it.) duke@435: return NULL; duke@435: } duke@435: } duke@435: #ifndef PRODUCT duke@435: // Make sure the dependency mechanism will pass this discovery: duke@435: if (VerifyDependencies && fm != NULL) { duke@435: guarantee(NULL == (void *)check_unique_concrete_method(ctxk, fm), duke@435: "verify dep."); duke@435: } duke@435: #endif //PRODUCT duke@435: return fm; duke@435: } duke@435: coleenp@4037: Klass* Dependencies::check_exclusive_concrete_methods(Klass* ctxk, coleenp@4037: Method* m1, coleenp@4037: Method* m2, twisti@3050: KlassDepChange* changes) { duke@435: ClassHierarchyWalker wf(m1); duke@435: wf.add_participant(m1->method_holder()); duke@435: wf.add_participant(m2->method_holder()); duke@435: return wf.find_witness_definer(ctxk, changes); duke@435: } duke@435: duke@435: // Find the set of all non-abstract methods under ctxk that match m[0]. duke@435: // (The method m[0] must be defined or inherited in ctxk.) duke@435: // Include m itself in the set, unless it is abstract. duke@435: // Fill the given array m[0..(mlen-1)] with this set, and return the length. duke@435: // (The length may be zero if no concrete methods are found anywhere.) duke@435: // If there are too many concrete methods to fit in marray, return -1. coleenp@4037: int Dependencies::find_exclusive_concrete_methods(Klass* ctxk, duke@435: int mlen, coleenp@4037: Method* marray[]) { coleenp@4037: Method* m0 = marray[0]; duke@435: ClassHierarchyWalker wf(m0); duke@435: assert(wf.check_method_context(ctxk, m0), "proper context"); duke@435: wf.record_witnesses(mlen); duke@435: bool participants_hide_witnesses = true; coleenp@4037: Klass* wit = wf.find_witness_definer(ctxk); duke@435: if (wit != NULL) return -1; // Too many witnesses. duke@435: int num = wf.num_participants(); duke@435: assert(num <= mlen, "oob"); duke@435: // Keep track of whether m is also part of the result set. duke@435: int mfill = 0; duke@435: assert(marray[mfill] == m0, "sanity"); duke@435: if (Dependencies::is_concrete_method(m0)) duke@435: mfill++; // keep m0 as marray[0], the first result duke@435: for (int i = 0; i < num; i++) { coleenp@4037: Method* fm = wf.found_method(i); duke@435: if (fm == m0) continue; // Already put this guy in the list. duke@435: if (mfill == mlen) { duke@435: return -1; // Oops. Too many methods after all! duke@435: } duke@435: marray[mfill++] = fm; duke@435: } duke@435: #ifndef PRODUCT duke@435: // Make sure the dependency mechanism will pass this discovery: duke@435: if (VerifyDependencies) { duke@435: // Turn off dependency tracing while actually testing deps. duke@435: FlagSetting fs(TraceDependencies, false); duke@435: switch (mfill) { duke@435: case 1: duke@435: guarantee(NULL == (void *)check_unique_concrete_method(ctxk, marray[0]), duke@435: "verify dep."); duke@435: break; duke@435: case 2: duke@435: guarantee(NULL == (void *) duke@435: check_exclusive_concrete_methods(ctxk, marray[0], marray[1]), duke@435: "verify dep."); duke@435: break; duke@435: default: duke@435: ShouldNotReachHere(); // mlen > 2 yet supported duke@435: } duke@435: } duke@435: #endif //PRODUCT duke@435: return mfill; duke@435: } duke@435: duke@435: coleenp@4037: Klass* Dependencies::check_has_no_finalizable_subclasses(Klass* ctxk, KlassDepChange* changes) { coleenp@4037: Klass* search_at = ctxk; duke@435: if (changes != NULL) coleenp@4037: search_at = changes->new_type(); // just look at the new bit coleenp@4037: return find_finalizable_subclass(search_at); duke@435: } duke@435: duke@435: coleenp@4037: Klass* Dependencies::check_call_site_target_value(oop call_site, oop method_handle, CallSiteDepChange* changes) { twisti@3050: assert(call_site ->is_a(SystemDictionary::CallSite_klass()), "sanity"); twisti@3050: assert(method_handle->is_a(SystemDictionary::MethodHandle_klass()), "sanity"); twisti@3050: if (changes == NULL) { twisti@3050: // Validate all CallSites twisti@3050: if (java_lang_invoke_CallSite::target(call_site) != method_handle) twisti@3094: return call_site->klass(); // assertion failed twisti@3050: } else { twisti@3050: // Validate the given CallSite twisti@3050: if (call_site == changes->call_site() && java_lang_invoke_CallSite::target(call_site) != changes->method_handle()) { twisti@3050: assert(method_handle != changes->method_handle(), "must be"); twisti@3094: return call_site->klass(); // assertion failed twisti@3050: } twisti@3050: } twisti@3050: return NULL; // assertion still valid twisti@3050: } twisti@3050: twisti@3050: coleenp@4037: void Dependencies::DepStream::trace_and_log_witness(Klass* witness) { twisti@3050: if (witness != NULL) { twisti@3050: if (TraceDependencies) { twisti@3050: print_dependency(witness, /*verbose=*/ true); twisti@3050: } twisti@3050: // The following is a no-op unless logging is enabled: twisti@3050: log_dependency(witness); twisti@3050: } twisti@3050: } twisti@3050: twisti@3050: coleenp@4037: Klass* Dependencies::DepStream::check_klass_dependency(KlassDepChange* changes) { duke@435: assert_locked_or_safepoint(Compile_lock); twisti@3050: Dependencies::check_valid_dependency_type(type()); duke@435: coleenp@4037: Klass* witness = NULL; duke@435: switch (type()) { duke@435: case evol_method: duke@435: witness = check_evol_method(method_argument(0)); duke@435: break; duke@435: case leaf_type: duke@435: witness = check_leaf_type(context_type()); duke@435: break; duke@435: case abstract_with_unique_concrete_subtype: twisti@3050: witness = check_abstract_with_unique_concrete_subtype(context_type(), type_argument(1), changes); duke@435: break; duke@435: case abstract_with_no_concrete_subtype: twisti@3050: witness = check_abstract_with_no_concrete_subtype(context_type(), changes); duke@435: break; duke@435: case concrete_with_no_concrete_subtype: twisti@3050: witness = check_concrete_with_no_concrete_subtype(context_type(), changes); duke@435: break; duke@435: case unique_concrete_method: twisti@3050: witness = check_unique_concrete_method(context_type(), method_argument(1), changes); duke@435: break; duke@435: case abstract_with_exclusive_concrete_subtypes_2: twisti@3050: witness = check_abstract_with_exclusive_concrete_subtypes(context_type(), type_argument(1), type_argument(2), changes); duke@435: break; duke@435: case exclusive_concrete_methods_2: twisti@3050: witness = check_exclusive_concrete_methods(context_type(), method_argument(1), method_argument(2), changes); duke@435: break; duke@435: case no_finalizable_subclasses: twisti@3050: witness = check_has_no_finalizable_subclasses(context_type(), changes); duke@435: break; twisti@3050: default: duke@435: witness = NULL; duke@435: break; duke@435: } twisti@3050: trace_and_log_witness(witness); duke@435: return witness; duke@435: } duke@435: duke@435: coleenp@4037: Klass* Dependencies::DepStream::check_call_site_dependency(CallSiteDepChange* changes) { twisti@3050: assert_locked_or_safepoint(Compile_lock); twisti@3050: Dependencies::check_valid_dependency_type(type()); duke@435: coleenp@4037: Klass* witness = NULL; twisti@3050: switch (type()) { twisti@3050: case call_site_target_value: coleenp@4037: witness = check_call_site_target_value(argument_oop(0), argument_oop(1), changes); twisti@3050: break; twisti@3050: default: twisti@3050: witness = NULL; twisti@3050: break; twisti@3050: } twisti@3050: trace_and_log_witness(witness); twisti@3050: return witness; duke@435: } duke@435: duke@435: coleenp@4037: Klass* Dependencies::DepStream::spot_check_dependency_at(DepChange& changes) { twisti@3050: // Handle klass dependency twisti@3050: if (changes.is_klass_change() && changes.as_klass_change()->involves_context(context_type())) twisti@3050: return check_klass_dependency(changes.as_klass_change()); duke@435: twisti@3050: // Handle CallSite dependency twisti@3050: if (changes.is_call_site_change()) twisti@3050: return check_call_site_dependency(changes.as_call_site_change()); twisti@3050: twisti@3050: // irrelevant dependency; skip it twisti@3050: return NULL; twisti@3050: } twisti@3050: twisti@3050: twisti@3050: void DepChange::print() { twisti@3050: int nsup = 0, nint = 0; duke@435: for (ContextStream str(*this); str.next(); ) { coleenp@4037: Klass* k = str.klass(); twisti@3050: switch (str.change_type()) { twisti@3050: case Change_new_type: coleenp@4037: tty->print_cr(" dependee = %s", InstanceKlass::cast(k)->external_name()); twisti@3050: break; twisti@3050: case Change_new_sub: twisti@3050: if (!WizardMode) { twisti@3050: ++nsup; twisti@3050: } else { coleenp@4037: tty->print_cr(" context super = %s", InstanceKlass::cast(k)->external_name()); twisti@3050: } twisti@3050: break; twisti@3050: case Change_new_impl: twisti@3050: if (!WizardMode) { twisti@3050: ++nint; twisti@3050: } else { coleenp@4037: tty->print_cr(" context interface = %s", InstanceKlass::cast(k)->external_name()); twisti@3050: } twisti@3050: break; twisti@3050: } twisti@3050: } twisti@3050: if (nsup + nint != 0) { twisti@3050: tty->print_cr(" context supers = %d, interfaces = %d", nsup, nint); duke@435: } duke@435: } duke@435: twisti@3050: void DepChange::ContextStream::start() { coleenp@4037: Klass* new_type = _changes.is_klass_change() ? _changes.as_klass_change()->new_type() : (Klass*) NULL; twisti@3050: _change_type = (new_type == NULL ? NO_CHANGE : Start_Klass); twisti@3050: _klass = new_type; twisti@3050: _ti_base = NULL; twisti@3050: _ti_index = 0; twisti@3050: _ti_limit = 0; duke@435: } duke@435: duke@435: bool DepChange::ContextStream::next() { duke@435: switch (_change_type) { duke@435: case Start_Klass: // initial state; _klass is the new type coleenp@4037: _ti_base = InstanceKlass::cast(_klass)->transitive_interfaces(); duke@435: _ti_index = 0; duke@435: _change_type = Change_new_type; duke@435: return true; duke@435: case Change_new_type: duke@435: // fall through: duke@435: _change_type = Change_new_sub; duke@435: case Change_new_sub: sbohne@489: // 6598190: brackets workaround Sun Studio C++ compiler bug 6629277 sbohne@489: { coleenp@4037: _klass = InstanceKlass::cast(_klass)->super(); sbohne@489: if (_klass != NULL) { sbohne@489: return true; sbohne@489: } duke@435: } duke@435: // else set up _ti_limit and fall through: duke@435: _ti_limit = (_ti_base == NULL) ? 0 : _ti_base->length(); duke@435: _change_type = Change_new_impl; duke@435: case Change_new_impl: duke@435: if (_ti_index < _ti_limit) { coleenp@4037: _klass = _ti_base->at(_ti_index++); duke@435: return true; duke@435: } duke@435: // fall through: duke@435: _change_type = NO_CHANGE; // iterator is exhausted duke@435: case NO_CHANGE: duke@435: break; duke@435: default: duke@435: ShouldNotReachHere(); duke@435: } duke@435: return false; duke@435: } duke@435: twisti@3050: void KlassDepChange::initialize() { twisti@3050: // entire transaction must be under this lock: twisti@3050: assert_lock_strong(Compile_lock); twisti@3050: twisti@3050: // Mark all dependee and all its superclasses twisti@3050: // Mark transitive interfaces duke@435: for (ContextStream str(*this); str.next(); ) { coleenp@4037: Klass* d = str.klass(); coleenp@4037: assert(!InstanceKlass::cast(d)->is_marked_dependent(), "checking"); coleenp@4037: InstanceKlass::cast(d)->set_is_marked_dependent(true); duke@435: } twisti@3050: } twisti@3050: twisti@3050: KlassDepChange::~KlassDepChange() { twisti@3050: // Unmark all dependee and all its superclasses twisti@3050: // Unmark transitive interfaces twisti@3050: for (ContextStream str(*this); str.next(); ) { coleenp@4037: Klass* d = str.klass(); coleenp@4037: InstanceKlass::cast(d)->set_is_marked_dependent(false); duke@435: } duke@435: } duke@435: coleenp@4037: bool KlassDepChange::involves_context(Klass* k) { hseigel@4278: if (k == NULL || !k->oop_is_instance()) { twisti@3050: return false; twisti@3050: } coleenp@4037: InstanceKlass* ik = InstanceKlass::cast(k); twisti@3050: bool is_contained = ik->is_marked_dependent(); hseigel@4278: assert(is_contained == new_type()->is_subtype_of(k), twisti@3050: "correct marking of potential context types"); twisti@3050: return is_contained; twisti@3050: } twisti@3050: duke@435: #ifndef PRODUCT duke@435: void Dependencies::print_statistics() { duke@435: if (deps_find_witness_print != 0) { duke@435: // Call one final time, to flush out the data. duke@435: deps_find_witness_print = -1; duke@435: count_find_witness_calls(); duke@435: } duke@435: } duke@435: #endif