Mon, 01 Dec 2014 13:06:20 -0500
8064524: Compiler code generation improvements
Reviewed-by: jrose, acorn, vlivanov
duke@435 | 1 | /* |
drchase@7714 | 2 | * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
stefank@2314 | 25 | #include "precompiled.hpp" |
stefank@2314 | 26 | #include "ci/ciArrayKlass.hpp" |
stefank@2314 | 27 | #include "ci/ciEnv.hpp" |
stefank@2314 | 28 | #include "ci/ciKlass.hpp" |
stefank@2314 | 29 | #include "ci/ciMethod.hpp" |
stefank@2314 | 30 | #include "code/dependencies.hpp" |
stefank@2314 | 31 | #include "compiler/compileLog.hpp" |
stefank@2314 | 32 | #include "oops/oop.inline.hpp" |
coleenp@4037 | 33 | #include "runtime/handles.hpp" |
stefank@2314 | 34 | #include "runtime/handles.inline.hpp" |
goetz@6911 | 35 | #include "runtime/thread.inline.hpp" |
stefank@2314 | 36 | #include "utilities/copy.hpp" |
duke@435 | 37 | |
duke@435 | 38 | |
duke@435 | 39 | #ifdef ASSERT |
duke@435 | 40 | static bool must_be_in_vm() { |
duke@435 | 41 | Thread* thread = Thread::current(); |
duke@435 | 42 | if (thread->is_Java_thread()) |
duke@435 | 43 | return ((JavaThread*)thread)->thread_state() == _thread_in_vm; |
duke@435 | 44 | else |
duke@435 | 45 | return true; //something like this: thread->is_VM_thread(); |
duke@435 | 46 | } |
duke@435 | 47 | #endif //ASSERT |
duke@435 | 48 | |
duke@435 | 49 | void Dependencies::initialize(ciEnv* env) { |
duke@435 | 50 | Arena* arena = env->arena(); |
duke@435 | 51 | _oop_recorder = env->oop_recorder(); |
duke@435 | 52 | _log = env->log(); |
duke@435 | 53 | _dep_seen = new(arena) GrowableArray<int>(arena, 500, 0, 0); |
duke@435 | 54 | DEBUG_ONLY(_deps[end_marker] = NULL); |
duke@435 | 55 | for (int i = (int)FIRST_TYPE; i < (int)TYPE_LIMIT; i++) { |
coleenp@4037 | 56 | _deps[i] = new(arena) GrowableArray<ciBaseObject*>(arena, 10, 0, 0); |
duke@435 | 57 | } |
duke@435 | 58 | _content_bytes = NULL; |
duke@435 | 59 | _size_in_bytes = (size_t)-1; |
duke@435 | 60 | |
duke@435 | 61 | assert(TYPE_LIMIT <= (1<<LG2_TYPE_LIMIT), "sanity"); |
duke@435 | 62 | } |
duke@435 | 63 | |
duke@435 | 64 | void Dependencies::assert_evol_method(ciMethod* m) { |
duke@435 | 65 | assert_common_1(evol_method, m); |
duke@435 | 66 | } |
duke@435 | 67 | |
duke@435 | 68 | void Dependencies::assert_leaf_type(ciKlass* ctxk) { |
duke@435 | 69 | if (ctxk->is_array_klass()) { |
duke@435 | 70 | // As a special case, support this assertion on an array type, |
duke@435 | 71 | // which reduces to an assertion on its element type. |
duke@435 | 72 | // Note that this cannot be done with assertions that |
duke@435 | 73 | // relate to concreteness or abstractness. |
duke@435 | 74 | ciType* elemt = ctxk->as_array_klass()->base_element_type(); |
duke@435 | 75 | if (!elemt->is_instance_klass()) return; // Ex: int[][] |
duke@435 | 76 | ctxk = elemt->as_instance_klass(); |
duke@435 | 77 | //if (ctxk->is_final()) return; // Ex: String[][] |
duke@435 | 78 | } |
duke@435 | 79 | check_ctxk(ctxk); |
duke@435 | 80 | assert_common_1(leaf_type, ctxk); |
duke@435 | 81 | } |
duke@435 | 82 | |
duke@435 | 83 | void Dependencies::assert_abstract_with_unique_concrete_subtype(ciKlass* ctxk, ciKlass* conck) { |
duke@435 | 84 | check_ctxk_abstract(ctxk); |
duke@435 | 85 | assert_common_2(abstract_with_unique_concrete_subtype, ctxk, conck); |
duke@435 | 86 | } |
duke@435 | 87 | |
duke@435 | 88 | void Dependencies::assert_abstract_with_no_concrete_subtype(ciKlass* ctxk) { |
duke@435 | 89 | check_ctxk_abstract(ctxk); |
duke@435 | 90 | assert_common_1(abstract_with_no_concrete_subtype, ctxk); |
duke@435 | 91 | } |
duke@435 | 92 | |
duke@435 | 93 | void Dependencies::assert_concrete_with_no_concrete_subtype(ciKlass* ctxk) { |
duke@435 | 94 | check_ctxk_concrete(ctxk); |
duke@435 | 95 | assert_common_1(concrete_with_no_concrete_subtype, ctxk); |
duke@435 | 96 | } |
duke@435 | 97 | |
duke@435 | 98 | void Dependencies::assert_unique_concrete_method(ciKlass* ctxk, ciMethod* uniqm) { |
duke@435 | 99 | check_ctxk(ctxk); |
duke@435 | 100 | assert_common_2(unique_concrete_method, ctxk, uniqm); |
duke@435 | 101 | } |
duke@435 | 102 | |
duke@435 | 103 | void Dependencies::assert_abstract_with_exclusive_concrete_subtypes(ciKlass* ctxk, ciKlass* k1, ciKlass* k2) { |
duke@435 | 104 | check_ctxk(ctxk); |
duke@435 | 105 | assert_common_3(abstract_with_exclusive_concrete_subtypes_2, ctxk, k1, k2); |
duke@435 | 106 | } |
duke@435 | 107 | |
duke@435 | 108 | void Dependencies::assert_exclusive_concrete_methods(ciKlass* ctxk, ciMethod* m1, ciMethod* m2) { |
duke@435 | 109 | check_ctxk(ctxk); |
duke@435 | 110 | assert_common_3(exclusive_concrete_methods_2, ctxk, m1, m2); |
duke@435 | 111 | } |
duke@435 | 112 | |
duke@435 | 113 | void Dependencies::assert_has_no_finalizable_subclasses(ciKlass* ctxk) { |
duke@435 | 114 | check_ctxk(ctxk); |
duke@435 | 115 | assert_common_1(no_finalizable_subclasses, ctxk); |
duke@435 | 116 | } |
duke@435 | 117 | |
twisti@3094 | 118 | void Dependencies::assert_call_site_target_value(ciCallSite* call_site, ciMethodHandle* method_handle) { |
twisti@3094 | 119 | check_ctxk(call_site->klass()); |
twisti@3094 | 120 | assert_common_2(call_site_target_value, call_site, method_handle); |
twisti@3050 | 121 | } |
twisti@3050 | 122 | |
duke@435 | 123 | // Helper function. If we are adding a new dep. under ctxk2, |
duke@435 | 124 | // try to find an old dep. under a broader* ctxk1. If there is |
duke@435 | 125 | // |
coleenp@4037 | 126 | bool Dependencies::maybe_merge_ctxk(GrowableArray<ciBaseObject*>* deps, |
duke@435 | 127 | int ctxk_i, ciKlass* ctxk2) { |
coleenp@4037 | 128 | ciKlass* ctxk1 = deps->at(ctxk_i)->as_metadata()->as_klass(); |
duke@435 | 129 | if (ctxk2->is_subtype_of(ctxk1)) { |
duke@435 | 130 | return true; // success, and no need to change |
duke@435 | 131 | } else if (ctxk1->is_subtype_of(ctxk2)) { |
duke@435 | 132 | // new context class fully subsumes previous one |
duke@435 | 133 | deps->at_put(ctxk_i, ctxk2); |
duke@435 | 134 | return true; |
duke@435 | 135 | } else { |
duke@435 | 136 | return false; |
duke@435 | 137 | } |
duke@435 | 138 | } |
duke@435 | 139 | |
coleenp@4037 | 140 | void Dependencies::assert_common_1(DepType dept, ciBaseObject* x) { |
duke@435 | 141 | assert(dep_args(dept) == 1, "sanity"); |
duke@435 | 142 | log_dependency(dept, x); |
coleenp@4037 | 143 | GrowableArray<ciBaseObject*>* deps = _deps[dept]; |
duke@435 | 144 | |
duke@435 | 145 | // see if the same (or a similar) dep is already recorded |
duke@435 | 146 | if (note_dep_seen(dept, x)) { |
duke@435 | 147 | assert(deps->find(x) >= 0, "sanity"); |
duke@435 | 148 | } else { |
duke@435 | 149 | deps->append(x); |
duke@435 | 150 | } |
duke@435 | 151 | } |
duke@435 | 152 | |
twisti@3094 | 153 | void Dependencies::assert_common_2(DepType dept, |
coleenp@4037 | 154 | ciBaseObject* x0, ciBaseObject* x1) { |
duke@435 | 155 | assert(dep_args(dept) == 2, "sanity"); |
twisti@3094 | 156 | log_dependency(dept, x0, x1); |
coleenp@4037 | 157 | GrowableArray<ciBaseObject*>* deps = _deps[dept]; |
duke@435 | 158 | |
duke@435 | 159 | // see if the same (or a similar) dep is already recorded |
twisti@3094 | 160 | bool has_ctxk = has_explicit_context_arg(dept); |
twisti@3094 | 161 | if (has_ctxk) { |
twisti@3094 | 162 | assert(dep_context_arg(dept) == 0, "sanity"); |
twisti@3094 | 163 | if (note_dep_seen(dept, x1)) { |
twisti@3094 | 164 | // look in this bucket for redundant assertions |
twisti@3094 | 165 | const int stride = 2; |
twisti@3094 | 166 | for (int i = deps->length(); (i -= stride) >= 0; ) { |
coleenp@4037 | 167 | ciBaseObject* y1 = deps->at(i+1); |
twisti@3094 | 168 | if (x1 == y1) { // same subject; check the context |
coleenp@4037 | 169 | if (maybe_merge_ctxk(deps, i+0, x0->as_metadata()->as_klass())) { |
twisti@3094 | 170 | return; |
twisti@3094 | 171 | } |
twisti@3094 | 172 | } |
twisti@3094 | 173 | } |
twisti@3094 | 174 | } |
twisti@3094 | 175 | } else { |
twisti@3094 | 176 | assert(dep_implicit_context_arg(dept) == 0, "sanity"); |
twisti@3094 | 177 | if (note_dep_seen(dept, x0) && note_dep_seen(dept, x1)) { |
twisti@3094 | 178 | // look in this bucket for redundant assertions |
twisti@3094 | 179 | const int stride = 2; |
twisti@3094 | 180 | for (int i = deps->length(); (i -= stride) >= 0; ) { |
coleenp@4037 | 181 | ciBaseObject* y0 = deps->at(i+0); |
coleenp@4037 | 182 | ciBaseObject* y1 = deps->at(i+1); |
twisti@3094 | 183 | if (x0 == y0 && x1 == y1) { |
duke@435 | 184 | return; |
duke@435 | 185 | } |
duke@435 | 186 | } |
duke@435 | 187 | } |
duke@435 | 188 | } |
duke@435 | 189 | |
duke@435 | 190 | // append the assertion in the correct bucket: |
twisti@3094 | 191 | deps->append(x0); |
twisti@3094 | 192 | deps->append(x1); |
duke@435 | 193 | } |
duke@435 | 194 | |
twisti@3094 | 195 | void Dependencies::assert_common_3(DepType dept, |
coleenp@4037 | 196 | ciKlass* ctxk, ciBaseObject* x, ciBaseObject* x2) { |
duke@435 | 197 | assert(dep_context_arg(dept) == 0, "sanity"); |
duke@435 | 198 | assert(dep_args(dept) == 3, "sanity"); |
duke@435 | 199 | log_dependency(dept, ctxk, x, x2); |
coleenp@4037 | 200 | GrowableArray<ciBaseObject*>* deps = _deps[dept]; |
duke@435 | 201 | |
duke@435 | 202 | // try to normalize an unordered pair: |
duke@435 | 203 | bool swap = false; |
duke@435 | 204 | switch (dept) { |
duke@435 | 205 | case abstract_with_exclusive_concrete_subtypes_2: |
coleenp@4037 | 206 | swap = (x->ident() > x2->ident() && x->as_metadata()->as_klass() != ctxk); |
duke@435 | 207 | break; |
duke@435 | 208 | case exclusive_concrete_methods_2: |
coleenp@4037 | 209 | swap = (x->ident() > x2->ident() && x->as_metadata()->as_method()->holder() != ctxk); |
duke@435 | 210 | break; |
duke@435 | 211 | } |
coleenp@4037 | 212 | if (swap) { ciBaseObject* t = x; x = x2; x2 = t; } |
duke@435 | 213 | |
duke@435 | 214 | // see if the same (or a similar) dep is already recorded |
duke@435 | 215 | if (note_dep_seen(dept, x) && note_dep_seen(dept, x2)) { |
duke@435 | 216 | // look in this bucket for redundant assertions |
duke@435 | 217 | const int stride = 3; |
duke@435 | 218 | for (int i = deps->length(); (i -= stride) >= 0; ) { |
coleenp@4037 | 219 | ciBaseObject* y = deps->at(i+1); |
coleenp@4037 | 220 | ciBaseObject* y2 = deps->at(i+2); |
duke@435 | 221 | if (x == y && x2 == y2) { // same subjects; check the context |
duke@435 | 222 | if (maybe_merge_ctxk(deps, i+0, ctxk)) { |
duke@435 | 223 | return; |
duke@435 | 224 | } |
duke@435 | 225 | } |
duke@435 | 226 | } |
duke@435 | 227 | } |
duke@435 | 228 | // append the assertion in the correct bucket: |
duke@435 | 229 | deps->append(ctxk); |
duke@435 | 230 | deps->append(x); |
duke@435 | 231 | deps->append(x2); |
duke@435 | 232 | } |
duke@435 | 233 | |
duke@435 | 234 | /// Support for encoding dependencies into an nmethod: |
duke@435 | 235 | |
duke@435 | 236 | void Dependencies::copy_to(nmethod* nm) { |
duke@435 | 237 | address beg = nm->dependencies_begin(); |
duke@435 | 238 | address end = nm->dependencies_end(); |
duke@435 | 239 | guarantee(end - beg >= (ptrdiff_t) size_in_bytes(), "bad sizing"); |
duke@435 | 240 | Copy::disjoint_words((HeapWord*) content_bytes(), |
duke@435 | 241 | (HeapWord*) beg, |
duke@435 | 242 | size_in_bytes() / sizeof(HeapWord)); |
duke@435 | 243 | assert(size_in_bytes() % sizeof(HeapWord) == 0, "copy by words"); |
duke@435 | 244 | } |
duke@435 | 245 | |
coleenp@4037 | 246 | static int sort_dep(ciBaseObject** p1, ciBaseObject** p2, int narg) { |
duke@435 | 247 | for (int i = 0; i < narg; i++) { |
duke@435 | 248 | int diff = p1[i]->ident() - p2[i]->ident(); |
duke@435 | 249 | if (diff != 0) return diff; |
duke@435 | 250 | } |
duke@435 | 251 | return 0; |
duke@435 | 252 | } |
coleenp@4037 | 253 | static int sort_dep_arg_1(ciBaseObject** p1, ciBaseObject** p2) |
duke@435 | 254 | { return sort_dep(p1, p2, 1); } |
coleenp@4037 | 255 | static int sort_dep_arg_2(ciBaseObject** p1, ciBaseObject** p2) |
duke@435 | 256 | { return sort_dep(p1, p2, 2); } |
coleenp@4037 | 257 | static int sort_dep_arg_3(ciBaseObject** p1, ciBaseObject** p2) |
duke@435 | 258 | { return sort_dep(p1, p2, 3); } |
duke@435 | 259 | |
duke@435 | 260 | void Dependencies::sort_all_deps() { |
duke@435 | 261 | for (int deptv = (int)FIRST_TYPE; deptv < (int)TYPE_LIMIT; deptv++) { |
duke@435 | 262 | DepType dept = (DepType)deptv; |
coleenp@4037 | 263 | GrowableArray<ciBaseObject*>* deps = _deps[dept]; |
duke@435 | 264 | if (deps->length() <= 1) continue; |
duke@435 | 265 | switch (dep_args(dept)) { |
duke@435 | 266 | case 1: deps->sort(sort_dep_arg_1, 1); break; |
duke@435 | 267 | case 2: deps->sort(sort_dep_arg_2, 2); break; |
duke@435 | 268 | case 3: deps->sort(sort_dep_arg_3, 3); break; |
duke@435 | 269 | default: ShouldNotReachHere(); |
duke@435 | 270 | } |
duke@435 | 271 | } |
duke@435 | 272 | } |
duke@435 | 273 | |
duke@435 | 274 | size_t Dependencies::estimate_size_in_bytes() { |
duke@435 | 275 | size_t est_size = 100; |
duke@435 | 276 | for (int deptv = (int)FIRST_TYPE; deptv < (int)TYPE_LIMIT; deptv++) { |
duke@435 | 277 | DepType dept = (DepType)deptv; |
coleenp@4037 | 278 | GrowableArray<ciBaseObject*>* deps = _deps[dept]; |
duke@435 | 279 | est_size += deps->length()*2; // tags and argument(s) |
duke@435 | 280 | } |
duke@435 | 281 | return est_size; |
duke@435 | 282 | } |
duke@435 | 283 | |
coleenp@4037 | 284 | ciKlass* Dependencies::ctxk_encoded_as_null(DepType dept, ciBaseObject* x) { |
duke@435 | 285 | switch (dept) { |
duke@435 | 286 | case abstract_with_exclusive_concrete_subtypes_2: |
coleenp@4037 | 287 | return x->as_metadata()->as_klass(); |
duke@435 | 288 | case unique_concrete_method: |
duke@435 | 289 | case exclusive_concrete_methods_2: |
coleenp@4037 | 290 | return x->as_metadata()->as_method()->holder(); |
duke@435 | 291 | } |
duke@435 | 292 | return NULL; // let NULL be NULL |
duke@435 | 293 | } |
duke@435 | 294 | |
coleenp@4037 | 295 | Klass* Dependencies::ctxk_encoded_as_null(DepType dept, Metadata* x) { |
duke@435 | 296 | assert(must_be_in_vm(), "raw oops here"); |
duke@435 | 297 | switch (dept) { |
duke@435 | 298 | case abstract_with_exclusive_concrete_subtypes_2: |
duke@435 | 299 | assert(x->is_klass(), "sanity"); |
coleenp@4037 | 300 | return (Klass*) x; |
duke@435 | 301 | case unique_concrete_method: |
duke@435 | 302 | case exclusive_concrete_methods_2: |
duke@435 | 303 | assert(x->is_method(), "sanity"); |
coleenp@4037 | 304 | return ((Method*)x)->method_holder(); |
duke@435 | 305 | } |
duke@435 | 306 | return NULL; // let NULL be NULL |
duke@435 | 307 | } |
duke@435 | 308 | |
duke@435 | 309 | void Dependencies::encode_content_bytes() { |
duke@435 | 310 | sort_all_deps(); |
duke@435 | 311 | |
duke@435 | 312 | // cast is safe, no deps can overflow INT_MAX |
duke@435 | 313 | CompressedWriteStream bytes((int)estimate_size_in_bytes()); |
duke@435 | 314 | |
duke@435 | 315 | for (int deptv = (int)FIRST_TYPE; deptv < (int)TYPE_LIMIT; deptv++) { |
duke@435 | 316 | DepType dept = (DepType)deptv; |
coleenp@4037 | 317 | GrowableArray<ciBaseObject*>* deps = _deps[dept]; |
duke@435 | 318 | if (deps->length() == 0) continue; |
duke@435 | 319 | int stride = dep_args(dept); |
duke@435 | 320 | int ctxkj = dep_context_arg(dept); // -1 if no context arg |
duke@435 | 321 | assert(stride > 0, "sanity"); |
duke@435 | 322 | for (int i = 0; i < deps->length(); i += stride) { |
duke@435 | 323 | jbyte code_byte = (jbyte)dept; |
duke@435 | 324 | int skipj = -1; |
duke@435 | 325 | if (ctxkj >= 0 && ctxkj+1 < stride) { |
coleenp@4037 | 326 | ciKlass* ctxk = deps->at(i+ctxkj+0)->as_metadata()->as_klass(); |
coleenp@4037 | 327 | ciBaseObject* x = deps->at(i+ctxkj+1); // following argument |
duke@435 | 328 | if (ctxk == ctxk_encoded_as_null(dept, x)) { |
duke@435 | 329 | skipj = ctxkj; // we win: maybe one less oop to keep track of |
duke@435 | 330 | code_byte |= default_context_type_bit; |
duke@435 | 331 | } |
duke@435 | 332 | } |
duke@435 | 333 | bytes.write_byte(code_byte); |
duke@435 | 334 | for (int j = 0; j < stride; j++) { |
duke@435 | 335 | if (j == skipj) continue; |
coleenp@4037 | 336 | ciBaseObject* v = deps->at(i+j); |
vlivanov@4155 | 337 | int idx; |
coleenp@4037 | 338 | if (v->is_object()) { |
vlivanov@4155 | 339 | idx = _oop_recorder->find_index(v->as_object()->constant_encoding()); |
coleenp@4037 | 340 | } else { |
coleenp@4037 | 341 | ciMetadata* meta = v->as_metadata(); |
vlivanov@4155 | 342 | idx = _oop_recorder->find_index(meta->constant_encoding()); |
coleenp@4037 | 343 | } |
vlivanov@4155 | 344 | bytes.write_int(idx); |
duke@435 | 345 | } |
duke@435 | 346 | } |
duke@435 | 347 | } |
duke@435 | 348 | |
duke@435 | 349 | // write a sentinel byte to mark the end |
duke@435 | 350 | bytes.write_byte(end_marker); |
duke@435 | 351 | |
duke@435 | 352 | // round it out to a word boundary |
duke@435 | 353 | while (bytes.position() % sizeof(HeapWord) != 0) { |
duke@435 | 354 | bytes.write_byte(end_marker); |
duke@435 | 355 | } |
duke@435 | 356 | |
duke@435 | 357 | // check whether the dept byte encoding really works |
duke@435 | 358 | assert((jbyte)default_context_type_bit != 0, "byte overflow"); |
duke@435 | 359 | |
duke@435 | 360 | _content_bytes = bytes.buffer(); |
duke@435 | 361 | _size_in_bytes = bytes.position(); |
duke@435 | 362 | } |
duke@435 | 363 | |
duke@435 | 364 | |
duke@435 | 365 | const char* Dependencies::_dep_name[TYPE_LIMIT] = { |
duke@435 | 366 | "end_marker", |
duke@435 | 367 | "evol_method", |
duke@435 | 368 | "leaf_type", |
duke@435 | 369 | "abstract_with_unique_concrete_subtype", |
duke@435 | 370 | "abstract_with_no_concrete_subtype", |
duke@435 | 371 | "concrete_with_no_concrete_subtype", |
duke@435 | 372 | "unique_concrete_method", |
duke@435 | 373 | "abstract_with_exclusive_concrete_subtypes_2", |
duke@435 | 374 | "exclusive_concrete_methods_2", |
twisti@3050 | 375 | "no_finalizable_subclasses", |
twisti@3050 | 376 | "call_site_target_value" |
duke@435 | 377 | }; |
duke@435 | 378 | |
duke@435 | 379 | int Dependencies::_dep_args[TYPE_LIMIT] = { |
duke@435 | 380 | -1,// end_marker |
duke@435 | 381 | 1, // evol_method m |
duke@435 | 382 | 1, // leaf_type ctxk |
duke@435 | 383 | 2, // abstract_with_unique_concrete_subtype ctxk, k |
duke@435 | 384 | 1, // abstract_with_no_concrete_subtype ctxk |
duke@435 | 385 | 1, // concrete_with_no_concrete_subtype ctxk |
duke@435 | 386 | 2, // unique_concrete_method ctxk, m |
duke@435 | 387 | 3, // unique_concrete_subtypes_2 ctxk, k1, k2 |
duke@435 | 388 | 3, // unique_concrete_methods_2 ctxk, m1, m2 |
twisti@3050 | 389 | 1, // no_finalizable_subclasses ctxk |
twisti@3094 | 390 | 2 // call_site_target_value call_site, method_handle |
duke@435 | 391 | }; |
duke@435 | 392 | |
duke@435 | 393 | const char* Dependencies::dep_name(Dependencies::DepType dept) { |
duke@435 | 394 | if (!dept_in_mask(dept, all_types)) return "?bad-dep?"; |
duke@435 | 395 | return _dep_name[dept]; |
duke@435 | 396 | } |
duke@435 | 397 | |
duke@435 | 398 | int Dependencies::dep_args(Dependencies::DepType dept) { |
duke@435 | 399 | if (!dept_in_mask(dept, all_types)) return -1; |
duke@435 | 400 | return _dep_args[dept]; |
duke@435 | 401 | } |
duke@435 | 402 | |
twisti@3050 | 403 | void Dependencies::check_valid_dependency_type(DepType dept) { |
twisti@3094 | 404 | guarantee(FIRST_TYPE <= dept && dept < TYPE_LIMIT, err_msg("invalid dependency type: %d", (int) dept)); |
twisti@3050 | 405 | } |
twisti@3050 | 406 | |
duke@435 | 407 | // for the sake of the compiler log, print out current dependencies: |
duke@435 | 408 | void Dependencies::log_all_dependencies() { |
duke@435 | 409 | if (log() == NULL) return; |
morris@7030 | 410 | ResourceMark rm; |
duke@435 | 411 | for (int deptv = (int)FIRST_TYPE; deptv < (int)TYPE_LIMIT; deptv++) { |
duke@435 | 412 | DepType dept = (DepType)deptv; |
coleenp@4037 | 413 | GrowableArray<ciBaseObject*>* deps = _deps[dept]; |
morris@7030 | 414 | int deplen = deps->length(); |
morris@7030 | 415 | if (deplen == 0) { |
morris@7030 | 416 | continue; |
morris@7030 | 417 | } |
duke@435 | 418 | int stride = dep_args(dept); |
morris@7030 | 419 | GrowableArray<ciBaseObject*>* ciargs = new GrowableArray<ciBaseObject*>(stride); |
duke@435 | 420 | for (int i = 0; i < deps->length(); i += stride) { |
duke@435 | 421 | for (int j = 0; j < stride; j++) { |
duke@435 | 422 | // flush out the identities before printing |
morris@7030 | 423 | ciargs->push(deps->at(i+j)); |
duke@435 | 424 | } |
morris@7030 | 425 | write_dependency_to(log(), dept, ciargs); |
morris@7030 | 426 | ciargs->clear(); |
duke@435 | 427 | } |
morris@7030 | 428 | guarantee(deplen == deps->length(), "deps array cannot grow inside nested ResoureMark scope"); |
duke@435 | 429 | } |
duke@435 | 430 | } |
duke@435 | 431 | |
duke@435 | 432 | void Dependencies::write_dependency_to(CompileLog* log, |
duke@435 | 433 | DepType dept, |
morris@7030 | 434 | GrowableArray<DepArgument>* args, |
coleenp@4037 | 435 | Klass* witness) { |
duke@435 | 436 | if (log == NULL) { |
duke@435 | 437 | return; |
duke@435 | 438 | } |
morris@7030 | 439 | ResourceMark rm; |
duke@435 | 440 | ciEnv* env = ciEnv::current(); |
morris@7030 | 441 | GrowableArray<ciBaseObject*>* ciargs = new GrowableArray<ciBaseObject*>(args->length()); |
morris@7030 | 442 | for (GrowableArrayIterator<DepArgument> it = args->begin(); it != args->end(); ++it) { |
morris@7030 | 443 | DepArgument arg = *it; |
morris@7030 | 444 | if (arg.is_oop()) { |
morris@7030 | 445 | ciargs->push(env->get_object(arg.oop_value())); |
coleenp@4037 | 446 | } else { |
morris@7030 | 447 | ciargs->push(env->get_metadata(arg.metadata_value())); |
coleenp@4037 | 448 | } |
duke@435 | 449 | } |
morris@7030 | 450 | int argslen = ciargs->length(); |
morris@7030 | 451 | Dependencies::write_dependency_to(log, dept, ciargs, witness); |
morris@7030 | 452 | guarantee(argslen == ciargs->length(), "ciargs array cannot grow inside nested ResoureMark scope"); |
duke@435 | 453 | } |
duke@435 | 454 | |
duke@435 | 455 | void Dependencies::write_dependency_to(CompileLog* log, |
duke@435 | 456 | DepType dept, |
morris@7030 | 457 | GrowableArray<ciBaseObject*>* args, |
coleenp@4037 | 458 | Klass* witness) { |
morris@7030 | 459 | if (log == NULL) { |
morris@7030 | 460 | return; |
morris@7030 | 461 | } |
morris@7030 | 462 | ResourceMark rm; |
morris@7030 | 463 | GrowableArray<int>* argids = new GrowableArray<int>(args->length()); |
morris@7030 | 464 | for (GrowableArrayIterator<ciBaseObject*> it = args->begin(); it != args->end(); ++it) { |
morris@7030 | 465 | ciBaseObject* obj = *it; |
morris@7030 | 466 | if (obj->is_object()) { |
morris@7030 | 467 | argids->push(log->identify(obj->as_object())); |
coleenp@4037 | 468 | } else { |
morris@7030 | 469 | argids->push(log->identify(obj->as_metadata())); |
coleenp@4037 | 470 | } |
duke@435 | 471 | } |
duke@435 | 472 | if (witness != NULL) { |
duke@435 | 473 | log->begin_elem("dependency_failed"); |
duke@435 | 474 | } else { |
duke@435 | 475 | log->begin_elem("dependency"); |
duke@435 | 476 | } |
duke@435 | 477 | log->print(" type='%s'", dep_name(dept)); |
morris@7030 | 478 | const int ctxkj = dep_context_arg(dept); // -1 if no context arg |
morris@7030 | 479 | if (ctxkj >= 0 && ctxkj < argids->length()) { |
morris@7030 | 480 | log->print(" ctxk='%d'", argids->at(ctxkj)); |
duke@435 | 481 | } |
duke@435 | 482 | // write remaining arguments, if any. |
morris@7030 | 483 | for (int j = 0; j < argids->length(); j++) { |
duke@435 | 484 | if (j == ctxkj) continue; // already logged |
duke@435 | 485 | if (j == 1) { |
morris@7030 | 486 | log->print( " x='%d'", argids->at(j)); |
duke@435 | 487 | } else { |
morris@7030 | 488 | log->print(" x%d='%d'", j, argids->at(j)); |
duke@435 | 489 | } |
duke@435 | 490 | } |
duke@435 | 491 | if (witness != NULL) { |
duke@435 | 492 | log->object("witness", witness); |
duke@435 | 493 | log->stamp(); |
duke@435 | 494 | } |
duke@435 | 495 | log->end_elem(); |
duke@435 | 496 | } |
duke@435 | 497 | |
duke@435 | 498 | void Dependencies::write_dependency_to(xmlStream* xtty, |
duke@435 | 499 | DepType dept, |
morris@7030 | 500 | GrowableArray<DepArgument>* args, |
coleenp@4037 | 501 | Klass* witness) { |
morris@7030 | 502 | if (xtty == NULL) { |
morris@7030 | 503 | return; |
morris@7030 | 504 | } |
morris@7030 | 505 | ResourceMark rm; |
duke@435 | 506 | ttyLocker ttyl; |
duke@435 | 507 | int ctxkj = dep_context_arg(dept); // -1 if no context arg |
duke@435 | 508 | if (witness != NULL) { |
duke@435 | 509 | xtty->begin_elem("dependency_failed"); |
duke@435 | 510 | } else { |
duke@435 | 511 | xtty->begin_elem("dependency"); |
duke@435 | 512 | } |
duke@435 | 513 | xtty->print(" type='%s'", dep_name(dept)); |
duke@435 | 514 | if (ctxkj >= 0) { |
morris@7030 | 515 | xtty->object("ctxk", args->at(ctxkj).metadata_value()); |
duke@435 | 516 | } |
duke@435 | 517 | // write remaining arguments, if any. |
morris@7030 | 518 | for (int j = 0; j < args->length(); j++) { |
duke@435 | 519 | if (j == ctxkj) continue; // already logged |
morris@7030 | 520 | DepArgument arg = args->at(j); |
duke@435 | 521 | if (j == 1) { |
morris@7030 | 522 | if (arg.is_oop()) { |
morris@7030 | 523 | xtty->object("x", arg.oop_value()); |
coleenp@4037 | 524 | } else { |
morris@7030 | 525 | xtty->object("x", arg.metadata_value()); |
coleenp@4037 | 526 | } |
duke@435 | 527 | } else { |
duke@435 | 528 | char xn[10]; sprintf(xn, "x%d", j); |
morris@7030 | 529 | if (arg.is_oop()) { |
morris@7030 | 530 | xtty->object(xn, arg.oop_value()); |
coleenp@4037 | 531 | } else { |
morris@7030 | 532 | xtty->object(xn, arg.metadata_value()); |
coleenp@4037 | 533 | } |
duke@435 | 534 | } |
duke@435 | 535 | } |
duke@435 | 536 | if (witness != NULL) { |
duke@435 | 537 | xtty->object("witness", witness); |
duke@435 | 538 | xtty->stamp(); |
duke@435 | 539 | } |
duke@435 | 540 | xtty->end_elem(); |
duke@435 | 541 | } |
duke@435 | 542 | |
morris@7030 | 543 | void Dependencies::print_dependency(DepType dept, GrowableArray<DepArgument>* args, |
coleenp@4037 | 544 | Klass* witness) { |
duke@435 | 545 | ResourceMark rm; |
duke@435 | 546 | ttyLocker ttyl; // keep the following output all in one block |
duke@435 | 547 | tty->print_cr("%s of type %s", |
duke@435 | 548 | (witness == NULL)? "Dependency": "Failed dependency", |
duke@435 | 549 | dep_name(dept)); |
duke@435 | 550 | // print arguments |
duke@435 | 551 | int ctxkj = dep_context_arg(dept); // -1 if no context arg |
morris@7030 | 552 | for (int j = 0; j < args->length(); j++) { |
morris@7030 | 553 | DepArgument arg = args->at(j); |
duke@435 | 554 | bool put_star = false; |
coleenp@4037 | 555 | if (arg.is_null()) continue; |
duke@435 | 556 | const char* what; |
duke@435 | 557 | if (j == ctxkj) { |
coleenp@4037 | 558 | assert(arg.is_metadata(), "must be"); |
duke@435 | 559 | what = "context"; |
coleenp@4037 | 560 | put_star = !Dependencies::is_concrete_klass((Klass*)arg.metadata_value()); |
coleenp@4037 | 561 | } else if (arg.is_method()) { |
duke@435 | 562 | what = "method "; |
drchase@7714 | 563 | put_star = !Dependencies::is_concrete_method((Method*)arg.metadata_value(), NULL); |
coleenp@4037 | 564 | } else if (arg.is_klass()) { |
duke@435 | 565 | what = "class "; |
duke@435 | 566 | } else { |
duke@435 | 567 | what = "object "; |
duke@435 | 568 | } |
duke@435 | 569 | tty->print(" %s = %s", what, (put_star? "*": "")); |
coleenp@4037 | 570 | if (arg.is_klass()) |
hseigel@4278 | 571 | tty->print("%s", ((Klass*)arg.metadata_value())->external_name()); |
coleenp@4037 | 572 | else if (arg.is_method()) |
coleenp@4037 | 573 | ((Method*)arg.metadata_value())->print_value(); |
duke@435 | 574 | else |
coleenp@4037 | 575 | ShouldNotReachHere(); // Provide impl for this type. |
duke@435 | 576 | tty->cr(); |
duke@435 | 577 | } |
duke@435 | 578 | if (witness != NULL) { |
duke@435 | 579 | bool put_star = !Dependencies::is_concrete_klass(witness); |
duke@435 | 580 | tty->print_cr(" witness = %s%s", |
duke@435 | 581 | (put_star? "*": ""), |
hseigel@4278 | 582 | witness->external_name()); |
duke@435 | 583 | } |
duke@435 | 584 | } |
duke@435 | 585 | |
coleenp@4037 | 586 | void Dependencies::DepStream::log_dependency(Klass* witness) { |
duke@435 | 587 | if (_deps == NULL && xtty == NULL) return; // fast cutout for runtime |
minqi@4267 | 588 | ResourceMark rm; |
morris@7030 | 589 | const int nargs = argument_count(); |
morris@7030 | 590 | GrowableArray<DepArgument>* args = new GrowableArray<DepArgument>(nargs); |
duke@435 | 591 | for (int j = 0; j < nargs; j++) { |
coleenp@4037 | 592 | if (type() == call_site_target_value) { |
morris@7030 | 593 | args->push(argument_oop(j)); |
coleenp@4037 | 594 | } else { |
morris@7030 | 595 | args->push(argument(j)); |
vlivanov@4155 | 596 | } |
coleenp@4037 | 597 | } |
morris@7030 | 598 | int argslen = args->length(); |
duke@435 | 599 | if (_deps != NULL && _deps->log() != NULL) { |
morris@7030 | 600 | Dependencies::write_dependency_to(_deps->log(), type(), args, witness); |
duke@435 | 601 | } else { |
morris@7030 | 602 | Dependencies::write_dependency_to(xtty, type(), args, witness); |
duke@435 | 603 | } |
morris@7030 | 604 | guarantee(argslen == args->length(), "args array cannot grow inside nested ResoureMark scope"); |
duke@435 | 605 | } |
duke@435 | 606 | |
coleenp@4037 | 607 | void Dependencies::DepStream::print_dependency(Klass* witness, bool verbose) { |
morris@7030 | 608 | ResourceMark rm; |
duke@435 | 609 | int nargs = argument_count(); |
morris@7030 | 610 | GrowableArray<DepArgument>* args = new GrowableArray<DepArgument>(nargs); |
duke@435 | 611 | for (int j = 0; j < nargs; j++) { |
morris@7030 | 612 | args->push(argument(j)); |
duke@435 | 613 | } |
morris@7030 | 614 | int argslen = args->length(); |
morris@7030 | 615 | Dependencies::print_dependency(type(), args, witness); |
duke@435 | 616 | if (verbose) { |
duke@435 | 617 | if (_code != NULL) { |
duke@435 | 618 | tty->print(" code: "); |
duke@435 | 619 | _code->print_value_on(tty); |
duke@435 | 620 | tty->cr(); |
duke@435 | 621 | } |
duke@435 | 622 | } |
morris@7030 | 623 | guarantee(argslen == args->length(), "args array cannot grow inside nested ResoureMark scope"); |
duke@435 | 624 | } |
duke@435 | 625 | |
duke@435 | 626 | |
duke@435 | 627 | /// Dependency stream support (decodes dependencies from an nmethod): |
duke@435 | 628 | |
duke@435 | 629 | #ifdef ASSERT |
duke@435 | 630 | void Dependencies::DepStream::initial_asserts(size_t byte_limit) { |
duke@435 | 631 | assert(must_be_in_vm(), "raw oops here"); |
duke@435 | 632 | _byte_limit = byte_limit; |
duke@435 | 633 | _type = (DepType)(end_marker-1); // defeat "already at end" assert |
duke@435 | 634 | assert((_code!=NULL) + (_deps!=NULL) == 1, "one or t'other"); |
duke@435 | 635 | } |
duke@435 | 636 | #endif //ASSERT |
duke@435 | 637 | |
duke@435 | 638 | bool Dependencies::DepStream::next() { |
duke@435 | 639 | assert(_type != end_marker, "already at end"); |
duke@435 | 640 | if (_bytes.position() == 0 && _code != NULL |
duke@435 | 641 | && _code->dependencies_size() == 0) { |
duke@435 | 642 | // Method has no dependencies at all. |
duke@435 | 643 | return false; |
duke@435 | 644 | } |
duke@435 | 645 | int code_byte = (_bytes.read_byte() & 0xFF); |
duke@435 | 646 | if (code_byte == end_marker) { |
duke@435 | 647 | DEBUG_ONLY(_type = end_marker); |
duke@435 | 648 | return false; |
duke@435 | 649 | } else { |
duke@435 | 650 | int ctxk_bit = (code_byte & Dependencies::default_context_type_bit); |
duke@435 | 651 | code_byte -= ctxk_bit; |
duke@435 | 652 | DepType dept = (DepType)code_byte; |
duke@435 | 653 | _type = dept; |
twisti@3094 | 654 | Dependencies::check_valid_dependency_type(dept); |
duke@435 | 655 | int stride = _dep_args[dept]; |
duke@435 | 656 | assert(stride == dep_args(dept), "sanity"); |
duke@435 | 657 | int skipj = -1; |
duke@435 | 658 | if (ctxk_bit != 0) { |
duke@435 | 659 | skipj = 0; // currently the only context argument is at zero |
duke@435 | 660 | assert(skipj == dep_context_arg(dept), "zero arg always ctxk"); |
duke@435 | 661 | } |
duke@435 | 662 | for (int j = 0; j < stride; j++) { |
duke@435 | 663 | _xi[j] = (j == skipj)? 0: _bytes.read_int(); |
duke@435 | 664 | } |
duke@435 | 665 | DEBUG_ONLY(_xi[stride] = -1); // help detect overruns |
duke@435 | 666 | return true; |
duke@435 | 667 | } |
duke@435 | 668 | } |
duke@435 | 669 | |
coleenp@4037 | 670 | inline Metadata* Dependencies::DepStream::recorded_metadata_at(int i) { |
coleenp@4037 | 671 | Metadata* o = NULL; |
coleenp@4037 | 672 | if (_code != NULL) { |
coleenp@4037 | 673 | o = _code->metadata_at(i); |
coleenp@4037 | 674 | } else { |
coleenp@4037 | 675 | o = _deps->oop_recorder()->metadata_at(i); |
coleenp@4037 | 676 | } |
coleenp@4037 | 677 | return o; |
coleenp@4037 | 678 | } |
coleenp@4037 | 679 | |
duke@435 | 680 | inline oop Dependencies::DepStream::recorded_oop_at(int i) { |
duke@435 | 681 | return (_code != NULL) |
duke@435 | 682 | ? _code->oop_at(i) |
coleenp@4037 | 683 | : JNIHandles::resolve(_deps->oop_recorder()->oop_at(i)); |
duke@435 | 684 | } |
duke@435 | 685 | |
coleenp@4037 | 686 | Metadata* Dependencies::DepStream::argument(int i) { |
coleenp@4037 | 687 | Metadata* result = recorded_metadata_at(argument_index(i)); |
vlivanov@4155 | 688 | |
vlivanov@4155 | 689 | if (result == NULL) { // Explicit context argument can be compressed |
vlivanov@4155 | 690 | int ctxkj = dep_context_arg(type()); // -1 if no explicit context arg |
vlivanov@4155 | 691 | if (ctxkj >= 0 && i == ctxkj && ctxkj+1 < argument_count()) { |
vlivanov@4155 | 692 | result = ctxk_encoded_as_null(type(), argument(ctxkj+1)); |
vlivanov@4155 | 693 | } |
vlivanov@4155 | 694 | } |
vlivanov@4155 | 695 | |
coleenp@4037 | 696 | assert(result == NULL || result->is_klass() || result->is_method(), "must be"); |
coleenp@4037 | 697 | return result; |
duke@435 | 698 | } |
duke@435 | 699 | |
coleenp@4037 | 700 | oop Dependencies::DepStream::argument_oop(int i) { |
coleenp@4037 | 701 | oop result = recorded_oop_at(argument_index(i)); |
coleenp@4037 | 702 | assert(result == NULL || result->is_oop(), "must be"); |
coleenp@4037 | 703 | return result; |
coleenp@4037 | 704 | } |
coleenp@4037 | 705 | |
coleenp@4037 | 706 | Klass* Dependencies::DepStream::context_type() { |
duke@435 | 707 | assert(must_be_in_vm(), "raw oops here"); |
twisti@3094 | 708 | |
twisti@3094 | 709 | // Most dependencies have an explicit context type argument. |
twisti@3094 | 710 | { |
vlivanov@4155 | 711 | int ctxkj = dep_context_arg(type()); // -1 if no explicit context arg |
twisti@3094 | 712 | if (ctxkj >= 0) { |
coleenp@4037 | 713 | Metadata* k = argument(ctxkj); |
vlivanov@4155 | 714 | assert(k != NULL && k->is_klass(), "type check"); |
vlivanov@4155 | 715 | return (Klass*)k; |
twisti@3094 | 716 | } |
twisti@3094 | 717 | } |
twisti@3094 | 718 | |
twisti@3094 | 719 | // Some dependencies are using the klass of the first object |
twisti@3094 | 720 | // argument as implicit context type (e.g. call_site_target_value). |
twisti@3094 | 721 | { |
vlivanov@4155 | 722 | int ctxkj = dep_implicit_context_arg(type()); |
twisti@3094 | 723 | if (ctxkj >= 0) { |
coleenp@4037 | 724 | Klass* k = argument_oop(ctxkj)->klass(); |
vlivanov@4155 | 725 | assert(k != NULL && k->is_klass(), "type check"); |
coleenp@4037 | 726 | return (Klass*) k; |
duke@435 | 727 | } |
duke@435 | 728 | } |
twisti@3094 | 729 | |
twisti@3094 | 730 | // And some dependencies don't have a context type at all, |
twisti@3094 | 731 | // e.g. evol_method. |
twisti@3094 | 732 | return NULL; |
duke@435 | 733 | } |
duke@435 | 734 | |
duke@435 | 735 | /// Checking dependencies: |
duke@435 | 736 | |
duke@435 | 737 | // This hierarchy walker inspects subtypes of a given type, |
duke@435 | 738 | // trying to find a "bad" class which breaks a dependency. |
duke@435 | 739 | // Such a class is called a "witness" to the broken dependency. |
duke@435 | 740 | // While searching around, we ignore "participants", which |
duke@435 | 741 | // are already known to the dependency. |
duke@435 | 742 | class ClassHierarchyWalker { |
duke@435 | 743 | public: |
duke@435 | 744 | enum { PARTICIPANT_LIMIT = 3 }; |
duke@435 | 745 | |
duke@435 | 746 | private: |
duke@435 | 747 | // optional method descriptor to check for: |
coleenp@2497 | 748 | Symbol* _name; |
coleenp@2497 | 749 | Symbol* _signature; |
duke@435 | 750 | |
duke@435 | 751 | // special classes which are not allowed to be witnesses: |
coleenp@4037 | 752 | Klass* _participants[PARTICIPANT_LIMIT+1]; |
duke@435 | 753 | int _num_participants; |
duke@435 | 754 | |
duke@435 | 755 | // cache of method lookups |
coleenp@4037 | 756 | Method* _found_methods[PARTICIPANT_LIMIT+1]; |
duke@435 | 757 | |
duke@435 | 758 | // if non-zero, tells how many witnesses to convert to participants |
duke@435 | 759 | int _record_witnesses; |
duke@435 | 760 | |
coleenp@4037 | 761 | void initialize(Klass* participant) { |
duke@435 | 762 | _record_witnesses = 0; |
duke@435 | 763 | _participants[0] = participant; |
duke@435 | 764 | _found_methods[0] = NULL; |
duke@435 | 765 | _num_participants = 0; |
duke@435 | 766 | if (participant != NULL) { |
duke@435 | 767 | // Terminating NULL. |
duke@435 | 768 | _participants[1] = NULL; |
duke@435 | 769 | _found_methods[1] = NULL; |
duke@435 | 770 | _num_participants = 1; |
duke@435 | 771 | } |
duke@435 | 772 | } |
duke@435 | 773 | |
coleenp@4037 | 774 | void initialize_from_method(Method* m) { |
duke@435 | 775 | assert(m != NULL && m->is_method(), "sanity"); |
duke@435 | 776 | _name = m->name(); |
duke@435 | 777 | _signature = m->signature(); |
duke@435 | 778 | } |
duke@435 | 779 | |
duke@435 | 780 | public: |
duke@435 | 781 | // The walker is initialized to recognize certain methods and/or types |
duke@435 | 782 | // as friendly participants. |
coleenp@4037 | 783 | ClassHierarchyWalker(Klass* participant, Method* m) { |
duke@435 | 784 | initialize_from_method(m); |
duke@435 | 785 | initialize(participant); |
duke@435 | 786 | } |
coleenp@4037 | 787 | ClassHierarchyWalker(Method* m) { |
duke@435 | 788 | initialize_from_method(m); |
duke@435 | 789 | initialize(NULL); |
duke@435 | 790 | } |
coleenp@4037 | 791 | ClassHierarchyWalker(Klass* participant = NULL) { |
duke@435 | 792 | _name = NULL; |
duke@435 | 793 | _signature = NULL; |
duke@435 | 794 | initialize(participant); |
duke@435 | 795 | } |
duke@435 | 796 | |
duke@435 | 797 | // This is common code for two searches: One for concrete subtypes, |
duke@435 | 798 | // the other for concrete method implementations and overrides. |
duke@435 | 799 | bool doing_subtype_search() { |
duke@435 | 800 | return _name == NULL; |
duke@435 | 801 | } |
duke@435 | 802 | |
duke@435 | 803 | int num_participants() { return _num_participants; } |
coleenp@4037 | 804 | Klass* participant(int n) { |
duke@435 | 805 | assert((uint)n <= (uint)_num_participants, "oob"); |
duke@435 | 806 | return _participants[n]; |
duke@435 | 807 | } |
duke@435 | 808 | |
duke@435 | 809 | // Note: If n==num_participants, returns NULL. |
coleenp@4037 | 810 | Method* found_method(int n) { |
duke@435 | 811 | assert((uint)n <= (uint)_num_participants, "oob"); |
coleenp@4037 | 812 | Method* fm = _found_methods[n]; |
duke@435 | 813 | assert(n == _num_participants || fm != NULL, "proper usage"); |
duke@435 | 814 | assert(fm == NULL || fm->method_holder() == _participants[n], "sanity"); |
duke@435 | 815 | return fm; |
duke@435 | 816 | } |
duke@435 | 817 | |
duke@435 | 818 | #ifdef ASSERT |
duke@435 | 819 | // Assert that m is inherited into ctxk, without intervening overrides. |
duke@435 | 820 | // (May return true even if this is not true, in corner cases where we punt.) |
coleenp@4037 | 821 | bool check_method_context(Klass* ctxk, Method* m) { |
duke@435 | 822 | if (m->method_holder() == ctxk) |
duke@435 | 823 | return true; // Quick win. |
duke@435 | 824 | if (m->is_private()) |
duke@435 | 825 | return false; // Quick lose. Should not happen. |
duke@435 | 826 | if (!(m->is_public() || m->is_protected())) |
duke@435 | 827 | // The override story is complex when packages get involved. |
duke@435 | 828 | return true; // Must punt the assertion to true. |
hseigel@4278 | 829 | Klass* k = ctxk; |
coleenp@4037 | 830 | Method* lm = k->lookup_method(m->name(), m->signature()); |
duke@435 | 831 | if (lm == NULL && k->oop_is_instance()) { |
acorn@5848 | 832 | // It might be an interface method |
acorn@5848 | 833 | lm = ((InstanceKlass*)k)->lookup_method_in_ordered_interfaces(m->name(), |
duke@435 | 834 | m->signature()); |
duke@435 | 835 | } |
duke@435 | 836 | if (lm == m) |
duke@435 | 837 | // Method m is inherited into ctxk. |
duke@435 | 838 | return true; |
duke@435 | 839 | if (lm != NULL) { |
never@3256 | 840 | if (!(lm->is_public() || lm->is_protected())) { |
duke@435 | 841 | // Method is [package-]private, so the override story is complex. |
duke@435 | 842 | return true; // Must punt the assertion to true. |
never@3256 | 843 | } |
never@3256 | 844 | if (lm->is_static()) { |
never@3256 | 845 | // Static methods don't override non-static so punt |
never@3256 | 846 | return true; |
never@3256 | 847 | } |
drchase@7714 | 848 | if ( !Dependencies::is_concrete_method(lm, k) |
drchase@7714 | 849 | && !Dependencies::is_concrete_method(m, ctxk) |
coleenp@4251 | 850 | && lm->method_holder()->is_subtype_of(m->method_holder())) |
duke@435 | 851 | // Method m is overridden by lm, but both are non-concrete. |
duke@435 | 852 | return true; |
duke@435 | 853 | } |
duke@435 | 854 | ResourceMark rm; |
duke@435 | 855 | tty->print_cr("Dependency method not found in the associated context:"); |
hseigel@4278 | 856 | tty->print_cr(" context = %s", ctxk->external_name()); |
duke@435 | 857 | tty->print( " method = "); m->print_short_name(tty); tty->cr(); |
duke@435 | 858 | if (lm != NULL) { |
duke@435 | 859 | tty->print( " found = "); lm->print_short_name(tty); tty->cr(); |
duke@435 | 860 | } |
duke@435 | 861 | return false; |
duke@435 | 862 | } |
duke@435 | 863 | #endif |
duke@435 | 864 | |
coleenp@4037 | 865 | void add_participant(Klass* participant) { |
duke@435 | 866 | assert(_num_participants + _record_witnesses < PARTICIPANT_LIMIT, "oob"); |
duke@435 | 867 | int np = _num_participants++; |
duke@435 | 868 | _participants[np] = participant; |
duke@435 | 869 | _participants[np+1] = NULL; |
duke@435 | 870 | _found_methods[np+1] = NULL; |
duke@435 | 871 | } |
duke@435 | 872 | |
duke@435 | 873 | void record_witnesses(int add) { |
duke@435 | 874 | if (add > PARTICIPANT_LIMIT) add = PARTICIPANT_LIMIT; |
duke@435 | 875 | assert(_num_participants + add < PARTICIPANT_LIMIT, "oob"); |
duke@435 | 876 | _record_witnesses = add; |
duke@435 | 877 | } |
duke@435 | 878 | |
coleenp@4037 | 879 | bool is_witness(Klass* k) { |
duke@435 | 880 | if (doing_subtype_search()) { |
duke@435 | 881 | return Dependencies::is_concrete_klass(k); |
duke@435 | 882 | } else { |
drchase@7714 | 883 | // Search class hierarchy first. |
drchase@7714 | 884 | Method* m = InstanceKlass::cast(k)->find_instance_method(_name, _signature); |
drchase@7714 | 885 | if (!Dependencies::is_concrete_method(m, k)) { |
drchase@7714 | 886 | // Check interface defaults also, if any exist. |
drchase@7714 | 887 | Array<Method*>* default_methods = InstanceKlass::cast(k)->default_methods(); |
drchase@7714 | 888 | if (default_methods == NULL) |
drchase@7714 | 889 | return false; |
drchase@7714 | 890 | m = InstanceKlass::cast(k)->find_method(default_methods, _name, _signature); |
drchase@7714 | 891 | if (!Dependencies::is_concrete_method(m, NULL)) |
drchase@7714 | 892 | return false; |
drchase@7714 | 893 | } |
duke@435 | 894 | _found_methods[_num_participants] = m; |
duke@435 | 895 | // Note: If add_participant(k) is called, |
duke@435 | 896 | // the method m will already be memoized for it. |
duke@435 | 897 | return true; |
duke@435 | 898 | } |
duke@435 | 899 | } |
duke@435 | 900 | |
coleenp@4037 | 901 | bool is_participant(Klass* k) { |
duke@435 | 902 | if (k == _participants[0]) { |
duke@435 | 903 | return true; |
duke@435 | 904 | } else if (_num_participants <= 1) { |
duke@435 | 905 | return false; |
duke@435 | 906 | } else { |
duke@435 | 907 | return in_list(k, &_participants[1]); |
duke@435 | 908 | } |
duke@435 | 909 | } |
coleenp@4037 | 910 | bool ignore_witness(Klass* witness) { |
duke@435 | 911 | if (_record_witnesses == 0) { |
duke@435 | 912 | return false; |
duke@435 | 913 | } else { |
duke@435 | 914 | --_record_witnesses; |
duke@435 | 915 | add_participant(witness); |
duke@435 | 916 | return true; |
duke@435 | 917 | } |
duke@435 | 918 | } |
coleenp@4037 | 919 | static bool in_list(Klass* x, Klass** list) { |
duke@435 | 920 | for (int i = 0; ; i++) { |
coleenp@4037 | 921 | Klass* y = list[i]; |
duke@435 | 922 | if (y == NULL) break; |
duke@435 | 923 | if (y == x) return true; |
duke@435 | 924 | } |
duke@435 | 925 | return false; // not in list |
duke@435 | 926 | } |
duke@435 | 927 | |
duke@435 | 928 | private: |
duke@435 | 929 | // the actual search method: |
coleenp@4037 | 930 | Klass* find_witness_anywhere(Klass* context_type, |
duke@435 | 931 | bool participants_hide_witnesses, |
duke@435 | 932 | bool top_level_call = true); |
duke@435 | 933 | // the spot-checking version: |
coleenp@4037 | 934 | Klass* find_witness_in(KlassDepChange& changes, |
coleenp@4037 | 935 | Klass* context_type, |
duke@435 | 936 | bool participants_hide_witnesses); |
duke@435 | 937 | public: |
coleenp@4037 | 938 | Klass* find_witness_subtype(Klass* context_type, KlassDepChange* changes = NULL) { |
duke@435 | 939 | assert(doing_subtype_search(), "must set up a subtype search"); |
duke@435 | 940 | // When looking for unexpected concrete types, |
duke@435 | 941 | // do not look beneath expected ones. |
duke@435 | 942 | const bool participants_hide_witnesses = true; |
duke@435 | 943 | // CX > CC > C' is OK, even if C' is new. |
duke@435 | 944 | // CX > { CC, C' } is not OK if C' is new, and C' is the witness. |
duke@435 | 945 | if (changes != NULL) { |
duke@435 | 946 | return find_witness_in(*changes, context_type, participants_hide_witnesses); |
duke@435 | 947 | } else { |
duke@435 | 948 | return find_witness_anywhere(context_type, participants_hide_witnesses); |
duke@435 | 949 | } |
duke@435 | 950 | } |
coleenp@4037 | 951 | Klass* find_witness_definer(Klass* context_type, KlassDepChange* changes = NULL) { |
duke@435 | 952 | assert(!doing_subtype_search(), "must set up a method definer search"); |
duke@435 | 953 | // When looking for unexpected concrete methods, |
duke@435 | 954 | // look beneath expected ones, to see if there are overrides. |
duke@435 | 955 | const bool participants_hide_witnesses = true; |
duke@435 | 956 | // CX.m > CC.m > C'.m is not OK, if C'.m is new, and C' is the witness. |
duke@435 | 957 | if (changes != NULL) { |
duke@435 | 958 | return find_witness_in(*changes, context_type, !participants_hide_witnesses); |
duke@435 | 959 | } else { |
duke@435 | 960 | return find_witness_anywhere(context_type, !participants_hide_witnesses); |
duke@435 | 961 | } |
duke@435 | 962 | } |
duke@435 | 963 | }; |
duke@435 | 964 | |
duke@435 | 965 | #ifndef PRODUCT |
duke@435 | 966 | static int deps_find_witness_calls = 0; |
duke@435 | 967 | static int deps_find_witness_steps = 0; |
duke@435 | 968 | static int deps_find_witness_recursions = 0; |
duke@435 | 969 | static int deps_find_witness_singles = 0; |
duke@435 | 970 | static int deps_find_witness_print = 0; // set to -1 to force a final print |
duke@435 | 971 | static bool count_find_witness_calls() { |
duke@435 | 972 | if (TraceDependencies || LogCompilation) { |
duke@435 | 973 | int pcount = deps_find_witness_print + 1; |
duke@435 | 974 | bool final_stats = (pcount == 0); |
duke@435 | 975 | bool initial_call = (pcount == 1); |
duke@435 | 976 | bool occasional_print = ((pcount & ((1<<10) - 1)) == 0); |
duke@435 | 977 | if (pcount < 0) pcount = 1; // crude overflow protection |
duke@435 | 978 | deps_find_witness_print = pcount; |
duke@435 | 979 | if (VerifyDependencies && initial_call) { |
duke@435 | 980 | tty->print_cr("Warning: TraceDependencies results may be inflated by VerifyDependencies"); |
duke@435 | 981 | } |
duke@435 | 982 | if (occasional_print || final_stats) { |
duke@435 | 983 | // Every now and then dump a little info about dependency searching. |
duke@435 | 984 | if (xtty != NULL) { |
kvn@1641 | 985 | ttyLocker ttyl; |
kvn@1641 | 986 | xtty->elem("deps_find_witness calls='%d' steps='%d' recursions='%d' singles='%d'", |
duke@435 | 987 | deps_find_witness_calls, |
duke@435 | 988 | deps_find_witness_steps, |
duke@435 | 989 | deps_find_witness_recursions, |
duke@435 | 990 | deps_find_witness_singles); |
duke@435 | 991 | } |
duke@435 | 992 | if (final_stats || (TraceDependencies && WizardMode)) { |
kvn@1641 | 993 | ttyLocker ttyl; |
duke@435 | 994 | tty->print_cr("Dependency check (find_witness) " |
duke@435 | 995 | "calls=%d, steps=%d (avg=%.1f), recursions=%d, singles=%d", |
duke@435 | 996 | deps_find_witness_calls, |
duke@435 | 997 | deps_find_witness_steps, |
duke@435 | 998 | (double)deps_find_witness_steps / deps_find_witness_calls, |
duke@435 | 999 | deps_find_witness_recursions, |
duke@435 | 1000 | deps_find_witness_singles); |
duke@435 | 1001 | } |
duke@435 | 1002 | } |
duke@435 | 1003 | return true; |
duke@435 | 1004 | } |
duke@435 | 1005 | return false; |
duke@435 | 1006 | } |
duke@435 | 1007 | #else |
duke@435 | 1008 | #define count_find_witness_calls() (0) |
duke@435 | 1009 | #endif //PRODUCT |
duke@435 | 1010 | |
duke@435 | 1011 | |
coleenp@4037 | 1012 | Klass* ClassHierarchyWalker::find_witness_in(KlassDepChange& changes, |
coleenp@4037 | 1013 | Klass* context_type, |
duke@435 | 1014 | bool participants_hide_witnesses) { |
duke@435 | 1015 | assert(changes.involves_context(context_type), "irrelevant dependency"); |
coleenp@4037 | 1016 | Klass* new_type = changes.new_type(); |
duke@435 | 1017 | |
ccheung@5259 | 1018 | (void)count_find_witness_calls(); |
duke@435 | 1019 | NOT_PRODUCT(deps_find_witness_singles++); |
duke@435 | 1020 | |
duke@435 | 1021 | // Current thread must be in VM (not native mode, as in CI): |
duke@435 | 1022 | assert(must_be_in_vm(), "raw oops here"); |
duke@435 | 1023 | // Must not move the class hierarchy during this check: |
duke@435 | 1024 | assert_locked_or_safepoint(Compile_lock); |
duke@435 | 1025 | |
coleenp@4037 | 1026 | int nof_impls = InstanceKlass::cast(context_type)->nof_implementors(); |
jrose@465 | 1027 | if (nof_impls > 1) { |
jrose@465 | 1028 | // Avoid this case: *I.m > { A.m, C }; B.m > C |
jrose@465 | 1029 | // %%% Until this is fixed more systematically, bail out. |
jrose@465 | 1030 | // See corresponding comment in find_witness_anywhere. |
jrose@465 | 1031 | return context_type; |
jrose@465 | 1032 | } |
jrose@465 | 1033 | |
duke@435 | 1034 | assert(!is_participant(new_type), "only old classes are participants"); |
duke@435 | 1035 | if (participants_hide_witnesses) { |
duke@435 | 1036 | // If the new type is a subtype of a participant, we are done. |
duke@435 | 1037 | for (int i = 0; i < num_participants(); i++) { |
coleenp@4037 | 1038 | Klass* part = participant(i); |
duke@435 | 1039 | if (part == NULL) continue; |
hseigel@4278 | 1040 | assert(changes.involves_context(part) == new_type->is_subtype_of(part), |
duke@435 | 1041 | "correct marking of participants, b/c new_type is unique"); |
duke@435 | 1042 | if (changes.involves_context(part)) { |
duke@435 | 1043 | // new guy is protected from this check by previous participant |
duke@435 | 1044 | return NULL; |
duke@435 | 1045 | } |
duke@435 | 1046 | } |
duke@435 | 1047 | } |
duke@435 | 1048 | |
duke@435 | 1049 | if (is_witness(new_type) && |
duke@435 | 1050 | !ignore_witness(new_type)) { |
duke@435 | 1051 | return new_type; |
duke@435 | 1052 | } |
duke@435 | 1053 | |
duke@435 | 1054 | return NULL; |
duke@435 | 1055 | } |
duke@435 | 1056 | |
duke@435 | 1057 | |
duke@435 | 1058 | // Walk hierarchy under a context type, looking for unexpected types. |
duke@435 | 1059 | // Do not report participant types, and recursively walk beneath |
duke@435 | 1060 | // them only if participants_hide_witnesses is false. |
duke@435 | 1061 | // If top_level_call is false, skip testing the context type, |
duke@435 | 1062 | // because the caller has already considered it. |
coleenp@4037 | 1063 | Klass* ClassHierarchyWalker::find_witness_anywhere(Klass* context_type, |
duke@435 | 1064 | bool participants_hide_witnesses, |
duke@435 | 1065 | bool top_level_call) { |
duke@435 | 1066 | // Current thread must be in VM (not native mode, as in CI): |
duke@435 | 1067 | assert(must_be_in_vm(), "raw oops here"); |
duke@435 | 1068 | // Must not move the class hierarchy during this check: |
duke@435 | 1069 | assert_locked_or_safepoint(Compile_lock); |
duke@435 | 1070 | |
duke@435 | 1071 | bool do_counts = count_find_witness_calls(); |
duke@435 | 1072 | |
duke@435 | 1073 | // Check the root of the sub-hierarchy first. |
duke@435 | 1074 | if (top_level_call) { |
duke@435 | 1075 | if (do_counts) { |
duke@435 | 1076 | NOT_PRODUCT(deps_find_witness_calls++); |
duke@435 | 1077 | NOT_PRODUCT(deps_find_witness_steps++); |
duke@435 | 1078 | } |
duke@435 | 1079 | if (is_participant(context_type)) { |
duke@435 | 1080 | if (participants_hide_witnesses) return NULL; |
duke@435 | 1081 | // else fall through to search loop... |
duke@435 | 1082 | } else if (is_witness(context_type) && !ignore_witness(context_type)) { |
duke@435 | 1083 | // The context is an abstract class or interface, to start with. |
duke@435 | 1084 | return context_type; |
duke@435 | 1085 | } |
duke@435 | 1086 | } |
duke@435 | 1087 | |
duke@435 | 1088 | // Now we must check each implementor and each subclass. |
duke@435 | 1089 | // Use a short worklist to avoid blowing the stack. |
duke@435 | 1090 | // Each worklist entry is a *chain* of subklass siblings to process. |
coleenp@4037 | 1091 | const int CHAINMAX = 100; // >= 1 + InstanceKlass::implementors_limit |
duke@435 | 1092 | Klass* chains[CHAINMAX]; |
duke@435 | 1093 | int chaini = 0; // index into worklist |
duke@435 | 1094 | Klass* chain; // scratch variable |
duke@435 | 1095 | #define ADD_SUBCLASS_CHAIN(k) { \ |
duke@435 | 1096 | assert(chaini < CHAINMAX, "oob"); \ |
coleenp@4037 | 1097 | chain = InstanceKlass::cast(k)->subklass(); \ |
duke@435 | 1098 | if (chain != NULL) chains[chaini++] = chain; } |
duke@435 | 1099 | |
duke@435 | 1100 | // Look for non-abstract subclasses. |
duke@435 | 1101 | // (Note: Interfaces do not have subclasses.) |
duke@435 | 1102 | ADD_SUBCLASS_CHAIN(context_type); |
duke@435 | 1103 | |
duke@435 | 1104 | // If it is an interface, search its direct implementors. |
duke@435 | 1105 | // (Their subclasses are additional indirect implementors. |
coleenp@4037 | 1106 | // See InstanceKlass::add_implementor.) |
duke@435 | 1107 | // (Note: nof_implementors is always zero for non-interfaces.) |
coleenp@4037 | 1108 | int nof_impls = InstanceKlass::cast(context_type)->nof_implementors(); |
duke@435 | 1109 | if (nof_impls > 1) { |
duke@435 | 1110 | // Avoid this case: *I.m > { A.m, C }; B.m > C |
duke@435 | 1111 | // Here, I.m has 2 concrete implementations, but m appears unique |
duke@435 | 1112 | // as A.m, because the search misses B.m when checking C. |
duke@435 | 1113 | // The inherited method B.m was getting missed by the walker |
duke@435 | 1114 | // when interface 'I' was the starting point. |
duke@435 | 1115 | // %%% Until this is fixed more systematically, bail out. |
duke@435 | 1116 | // (Old CHA had the same limitation.) |
duke@435 | 1117 | return context_type; |
duke@435 | 1118 | } |
jiangli@3701 | 1119 | if (nof_impls > 0) { |
coleenp@4037 | 1120 | Klass* impl = InstanceKlass::cast(context_type)->implementor(); |
jiangli@3701 | 1121 | assert(impl != NULL, "just checking"); |
jiangli@3701 | 1122 | // If impl is the same as the context_type, then more than one |
jiangli@3701 | 1123 | // implementor has seen. No exact info in this case. |
jiangli@3701 | 1124 | if (impl == context_type) { |
duke@435 | 1125 | return context_type; // report an inexact witness to this sad affair |
duke@435 | 1126 | } |
duke@435 | 1127 | if (do_counts) |
duke@435 | 1128 | { NOT_PRODUCT(deps_find_witness_steps++); } |
duke@435 | 1129 | if (is_participant(impl)) { |
jiangli@3701 | 1130 | if (!participants_hide_witnesses) { |
jiangli@3701 | 1131 | ADD_SUBCLASS_CHAIN(impl); |
jiangli@3701 | 1132 | } |
duke@435 | 1133 | } else if (is_witness(impl) && !ignore_witness(impl)) { |
duke@435 | 1134 | return impl; |
jiangli@3701 | 1135 | } else { |
jiangli@3701 | 1136 | ADD_SUBCLASS_CHAIN(impl); |
duke@435 | 1137 | } |
duke@435 | 1138 | } |
duke@435 | 1139 | |
duke@435 | 1140 | // Recursively process each non-trivial sibling chain. |
duke@435 | 1141 | while (chaini > 0) { |
duke@435 | 1142 | Klass* chain = chains[--chaini]; |
coleenp@4037 | 1143 | for (Klass* sub = chain; sub != NULL; sub = sub->next_sibling()) { |
duke@435 | 1144 | if (do_counts) { NOT_PRODUCT(deps_find_witness_steps++); } |
duke@435 | 1145 | if (is_participant(sub)) { |
duke@435 | 1146 | if (participants_hide_witnesses) continue; |
duke@435 | 1147 | // else fall through to process this guy's subclasses |
duke@435 | 1148 | } else if (is_witness(sub) && !ignore_witness(sub)) { |
duke@435 | 1149 | return sub; |
duke@435 | 1150 | } |
duke@435 | 1151 | if (chaini < (VerifyDependencies? 2: CHAINMAX)) { |
duke@435 | 1152 | // Fast path. (Partially disabled if VerifyDependencies.) |
duke@435 | 1153 | ADD_SUBCLASS_CHAIN(sub); |
duke@435 | 1154 | } else { |
duke@435 | 1155 | // Worklist overflow. Do a recursive call. Should be rare. |
duke@435 | 1156 | // The recursive call will have its own worklist, of course. |
duke@435 | 1157 | // (Note that sub has already been tested, so that there is |
duke@435 | 1158 | // no need for the recursive call to re-test. That's handy, |
duke@435 | 1159 | // since the recursive call sees sub as the context_type.) |
duke@435 | 1160 | if (do_counts) { NOT_PRODUCT(deps_find_witness_recursions++); } |
coleenp@4037 | 1161 | Klass* witness = find_witness_anywhere(sub, |
duke@435 | 1162 | participants_hide_witnesses, |
duke@435 | 1163 | /*top_level_call=*/ false); |
duke@435 | 1164 | if (witness != NULL) return witness; |
duke@435 | 1165 | } |
duke@435 | 1166 | } |
duke@435 | 1167 | } |
duke@435 | 1168 | |
duke@435 | 1169 | // No witness found. The dependency remains unbroken. |
duke@435 | 1170 | return NULL; |
duke@435 | 1171 | #undef ADD_SUBCLASS_CHAIN |
duke@435 | 1172 | } |
duke@435 | 1173 | |
duke@435 | 1174 | |
coleenp@4037 | 1175 | bool Dependencies::is_concrete_klass(Klass* k) { |
hseigel@4278 | 1176 | if (k->is_abstract()) return false; |
duke@435 | 1177 | // %%% We could treat classes which are concrete but |
duke@435 | 1178 | // have not yet been instantiated as virtually abstract. |
duke@435 | 1179 | // This would require a deoptimization barrier on first instantiation. |
duke@435 | 1180 | //if (k->is_not_instantiated()) return false; |
duke@435 | 1181 | return true; |
duke@435 | 1182 | } |
duke@435 | 1183 | |
drchase@7714 | 1184 | bool Dependencies::is_concrete_method(Method* m, Klass * k) { |
drchase@7714 | 1185 | // NULL is not a concrete method, |
drchase@7714 | 1186 | // statics are irrelevant to virtual call sites, |
drchase@7714 | 1187 | // abstract methods are not concrete, |
drchase@7714 | 1188 | // overpass (error) methods are not concrete if k is abstract |
drchase@7714 | 1189 | // |
drchase@7714 | 1190 | // note "true" is conservative answer -- |
drchase@7714 | 1191 | // overpass clause is false if k == NULL, implies return true if |
drchase@7714 | 1192 | // answer depends on overpass clause. |
drchase@7714 | 1193 | return ! ( m == NULL || m -> is_static() || m -> is_abstract() || |
drchase@7714 | 1194 | m->is_overpass() && k != NULL && k -> is_abstract() ); |
duke@435 | 1195 | } |
duke@435 | 1196 | |
duke@435 | 1197 | |
duke@435 | 1198 | Klass* Dependencies::find_finalizable_subclass(Klass* k) { |
duke@435 | 1199 | if (k->is_interface()) return NULL; |
duke@435 | 1200 | if (k->has_finalizer()) return k; |
duke@435 | 1201 | k = k->subklass(); |
duke@435 | 1202 | while (k != NULL) { |
duke@435 | 1203 | Klass* result = find_finalizable_subclass(k); |
duke@435 | 1204 | if (result != NULL) return result; |
duke@435 | 1205 | k = k->next_sibling(); |
duke@435 | 1206 | } |
duke@435 | 1207 | return NULL; |
duke@435 | 1208 | } |
duke@435 | 1209 | |
duke@435 | 1210 | |
duke@435 | 1211 | bool Dependencies::is_concrete_klass(ciInstanceKlass* k) { |
duke@435 | 1212 | if (k->is_abstract()) return false; |
never@3256 | 1213 | // We could also return false if k does not yet appear to be |
duke@435 | 1214 | // instantiated, if the VM version supports this distinction also. |
duke@435 | 1215 | //if (k->is_not_instantiated()) return false; |
duke@435 | 1216 | return true; |
duke@435 | 1217 | } |
duke@435 | 1218 | |
duke@435 | 1219 | bool Dependencies::has_finalizable_subclass(ciInstanceKlass* k) { |
duke@435 | 1220 | return k->has_finalizable_subclass(); |
duke@435 | 1221 | } |
duke@435 | 1222 | |
duke@435 | 1223 | |
duke@435 | 1224 | // Any use of the contents (bytecodes) of a method must be |
duke@435 | 1225 | // marked by an "evol_method" dependency, if those contents |
duke@435 | 1226 | // can change. (Note: A method is always dependent on itself.) |
coleenp@4037 | 1227 | Klass* Dependencies::check_evol_method(Method* m) { |
duke@435 | 1228 | assert(must_be_in_vm(), "raw oops here"); |
duke@435 | 1229 | // Did somebody do a JVMTI RedefineClasses while our backs were turned? |
duke@435 | 1230 | // Or is there a now a breakpoint? |
duke@435 | 1231 | // (Assumes compiled code cannot handle bkpts; change if UseFastBreakpoints.) |
duke@435 | 1232 | if (m->is_old() |
duke@435 | 1233 | || m->number_of_breakpoints() > 0) { |
duke@435 | 1234 | return m->method_holder(); |
duke@435 | 1235 | } else { |
duke@435 | 1236 | return NULL; |
duke@435 | 1237 | } |
duke@435 | 1238 | } |
duke@435 | 1239 | |
duke@435 | 1240 | // This is a strong assertion: It is that the given type |
duke@435 | 1241 | // has no subtypes whatever. It is most useful for |
duke@435 | 1242 | // optimizing checks on reflected types or on array types. |
duke@435 | 1243 | // (Checks on types which are derived from real instances |
duke@435 | 1244 | // can be optimized more strongly than this, because we |
duke@435 | 1245 | // know that the checked type comes from a concrete type, |
duke@435 | 1246 | // and therefore we can disregard abstract types.) |
coleenp@4037 | 1247 | Klass* Dependencies::check_leaf_type(Klass* ctxk) { |
duke@435 | 1248 | assert(must_be_in_vm(), "raw oops here"); |
duke@435 | 1249 | assert_locked_or_safepoint(Compile_lock); |
coleenp@4037 | 1250 | InstanceKlass* ctx = InstanceKlass::cast(ctxk); |
duke@435 | 1251 | Klass* sub = ctx->subklass(); |
duke@435 | 1252 | if (sub != NULL) { |
coleenp@4037 | 1253 | return sub; |
duke@435 | 1254 | } else if (ctx->nof_implementors() != 0) { |
duke@435 | 1255 | // if it is an interface, it must be unimplemented |
duke@435 | 1256 | // (if it is not an interface, nof_implementors is always zero) |
coleenp@4037 | 1257 | Klass* impl = ctx->implementor(); |
jiangli@3701 | 1258 | assert(impl != NULL, "must be set"); |
jiangli@3701 | 1259 | return impl; |
duke@435 | 1260 | } else { |
duke@435 | 1261 | return NULL; |
duke@435 | 1262 | } |
duke@435 | 1263 | } |
duke@435 | 1264 | |
duke@435 | 1265 | // Test the assertion that conck is the only concrete subtype* of ctxk. |
duke@435 | 1266 | // The type conck itself is allowed to have have further concrete subtypes. |
duke@435 | 1267 | // This allows the compiler to narrow occurrences of ctxk by conck, |
duke@435 | 1268 | // when dealing with the types of actual instances. |
coleenp@4037 | 1269 | Klass* Dependencies::check_abstract_with_unique_concrete_subtype(Klass* ctxk, |
coleenp@4037 | 1270 | Klass* conck, |
twisti@3050 | 1271 | KlassDepChange* changes) { |
duke@435 | 1272 | ClassHierarchyWalker wf(conck); |
duke@435 | 1273 | return wf.find_witness_subtype(ctxk, changes); |
duke@435 | 1274 | } |
duke@435 | 1275 | |
duke@435 | 1276 | // If a non-concrete class has no concrete subtypes, it is not (yet) |
duke@435 | 1277 | // instantiatable. This can allow the compiler to make some paths go |
duke@435 | 1278 | // dead, if they are gated by a test of the type. |
coleenp@4037 | 1279 | Klass* Dependencies::check_abstract_with_no_concrete_subtype(Klass* ctxk, |
twisti@3050 | 1280 | KlassDepChange* changes) { |
duke@435 | 1281 | // Find any concrete subtype, with no participants: |
duke@435 | 1282 | ClassHierarchyWalker wf; |
duke@435 | 1283 | return wf.find_witness_subtype(ctxk, changes); |
duke@435 | 1284 | } |
duke@435 | 1285 | |
duke@435 | 1286 | |
duke@435 | 1287 | // If a concrete class has no concrete subtypes, it can always be |
duke@435 | 1288 | // exactly typed. This allows the use of a cheaper type test. |
coleenp@4037 | 1289 | Klass* Dependencies::check_concrete_with_no_concrete_subtype(Klass* ctxk, |
twisti@3050 | 1290 | KlassDepChange* changes) { |
duke@435 | 1291 | // Find any concrete subtype, with only the ctxk as participant: |
duke@435 | 1292 | ClassHierarchyWalker wf(ctxk); |
duke@435 | 1293 | return wf.find_witness_subtype(ctxk, changes); |
duke@435 | 1294 | } |
duke@435 | 1295 | |
duke@435 | 1296 | |
duke@435 | 1297 | // Find the unique concrete proper subtype of ctxk, or NULL if there |
duke@435 | 1298 | // is more than one concrete proper subtype. If there are no concrete |
duke@435 | 1299 | // proper subtypes, return ctxk itself, whether it is concrete or not. |
duke@435 | 1300 | // The returned subtype is allowed to have have further concrete subtypes. |
duke@435 | 1301 | // That is, return CC1 for CX > CC1 > CC2, but NULL for CX > { CC1, CC2 }. |
coleenp@4037 | 1302 | Klass* Dependencies::find_unique_concrete_subtype(Klass* ctxk) { |
duke@435 | 1303 | ClassHierarchyWalker wf(ctxk); // Ignore ctxk when walking. |
duke@435 | 1304 | wf.record_witnesses(1); // Record one other witness when walking. |
coleenp@4037 | 1305 | Klass* wit = wf.find_witness_subtype(ctxk); |
duke@435 | 1306 | if (wit != NULL) return NULL; // Too many witnesses. |
coleenp@4037 | 1307 | Klass* conck = wf.participant(0); |
duke@435 | 1308 | if (conck == NULL) { |
duke@435 | 1309 | #ifndef PRODUCT |
duke@435 | 1310 | // Make sure the dependency mechanism will pass this discovery: |
duke@435 | 1311 | if (VerifyDependencies) { |
duke@435 | 1312 | // Turn off dependency tracing while actually testing deps. |
duke@435 | 1313 | FlagSetting fs(TraceDependencies, false); |
duke@435 | 1314 | if (!Dependencies::is_concrete_klass(ctxk)) { |
duke@435 | 1315 | guarantee(NULL == |
duke@435 | 1316 | (void *)check_abstract_with_no_concrete_subtype(ctxk), |
duke@435 | 1317 | "verify dep."); |
duke@435 | 1318 | } else { |
duke@435 | 1319 | guarantee(NULL == |
duke@435 | 1320 | (void *)check_concrete_with_no_concrete_subtype(ctxk), |
duke@435 | 1321 | "verify dep."); |
duke@435 | 1322 | } |
duke@435 | 1323 | } |
duke@435 | 1324 | #endif //PRODUCT |
duke@435 | 1325 | return ctxk; // Return ctxk as a flag for "no subtypes". |
duke@435 | 1326 | } else { |
duke@435 | 1327 | #ifndef PRODUCT |
duke@435 | 1328 | // Make sure the dependency mechanism will pass this discovery: |
duke@435 | 1329 | if (VerifyDependencies) { |
duke@435 | 1330 | // Turn off dependency tracing while actually testing deps. |
duke@435 | 1331 | FlagSetting fs(TraceDependencies, false); |
duke@435 | 1332 | if (!Dependencies::is_concrete_klass(ctxk)) { |
duke@435 | 1333 | guarantee(NULL == (void *) |
duke@435 | 1334 | check_abstract_with_unique_concrete_subtype(ctxk, conck), |
duke@435 | 1335 | "verify dep."); |
duke@435 | 1336 | } |
duke@435 | 1337 | } |
duke@435 | 1338 | #endif //PRODUCT |
duke@435 | 1339 | return conck; |
duke@435 | 1340 | } |
duke@435 | 1341 | } |
duke@435 | 1342 | |
duke@435 | 1343 | // Test the assertion that the k[12] are the only concrete subtypes of ctxk, |
duke@435 | 1344 | // except possibly for further subtypes of k[12] themselves. |
duke@435 | 1345 | // The context type must be abstract. The types k1 and k2 are themselves |
duke@435 | 1346 | // allowed to have further concrete subtypes. |
coleenp@4037 | 1347 | Klass* Dependencies::check_abstract_with_exclusive_concrete_subtypes( |
coleenp@4037 | 1348 | Klass* ctxk, |
coleenp@4037 | 1349 | Klass* k1, |
coleenp@4037 | 1350 | Klass* k2, |
twisti@3050 | 1351 | KlassDepChange* changes) { |
duke@435 | 1352 | ClassHierarchyWalker wf; |
duke@435 | 1353 | wf.add_participant(k1); |
duke@435 | 1354 | wf.add_participant(k2); |
duke@435 | 1355 | return wf.find_witness_subtype(ctxk, changes); |
duke@435 | 1356 | } |
duke@435 | 1357 | |
duke@435 | 1358 | // Search ctxk for concrete implementations. If there are klen or fewer, |
duke@435 | 1359 | // pack them into the given array and return the number. |
duke@435 | 1360 | // Otherwise, return -1, meaning the given array would overflow. |
duke@435 | 1361 | // (Note that a return of 0 means there are exactly no concrete subtypes.) |
duke@435 | 1362 | // In this search, if ctxk is concrete, it will be reported alone. |
duke@435 | 1363 | // For any type CC reported, no proper subtypes of CC will be reported. |
coleenp@4037 | 1364 | int Dependencies::find_exclusive_concrete_subtypes(Klass* ctxk, |
duke@435 | 1365 | int klen, |
coleenp@4037 | 1366 | Klass* karray[]) { |
duke@435 | 1367 | ClassHierarchyWalker wf; |
duke@435 | 1368 | wf.record_witnesses(klen); |
coleenp@4037 | 1369 | Klass* wit = wf.find_witness_subtype(ctxk); |
duke@435 | 1370 | if (wit != NULL) return -1; // Too many witnesses. |
duke@435 | 1371 | int num = wf.num_participants(); |
duke@435 | 1372 | assert(num <= klen, "oob"); |
duke@435 | 1373 | // Pack the result array with the good news. |
duke@435 | 1374 | for (int i = 0; i < num; i++) |
duke@435 | 1375 | karray[i] = wf.participant(i); |
duke@435 | 1376 | #ifndef PRODUCT |
duke@435 | 1377 | // Make sure the dependency mechanism will pass this discovery: |
duke@435 | 1378 | if (VerifyDependencies) { |
duke@435 | 1379 | // Turn off dependency tracing while actually testing deps. |
duke@435 | 1380 | FlagSetting fs(TraceDependencies, false); |
duke@435 | 1381 | switch (Dependencies::is_concrete_klass(ctxk)? -1: num) { |
duke@435 | 1382 | case -1: // ctxk was itself concrete |
duke@435 | 1383 | guarantee(num == 1 && karray[0] == ctxk, "verify dep."); |
duke@435 | 1384 | break; |
duke@435 | 1385 | case 0: |
duke@435 | 1386 | guarantee(NULL == (void *)check_abstract_with_no_concrete_subtype(ctxk), |
duke@435 | 1387 | "verify dep."); |
duke@435 | 1388 | break; |
duke@435 | 1389 | case 1: |
duke@435 | 1390 | guarantee(NULL == (void *) |
duke@435 | 1391 | check_abstract_with_unique_concrete_subtype(ctxk, karray[0]), |
duke@435 | 1392 | "verify dep."); |
duke@435 | 1393 | break; |
duke@435 | 1394 | case 2: |
duke@435 | 1395 | guarantee(NULL == (void *) |
duke@435 | 1396 | check_abstract_with_exclusive_concrete_subtypes(ctxk, |
duke@435 | 1397 | karray[0], |
duke@435 | 1398 | karray[1]), |
duke@435 | 1399 | "verify dep."); |
duke@435 | 1400 | break; |
duke@435 | 1401 | default: |
duke@435 | 1402 | ShouldNotReachHere(); // klen > 2 yet supported |
duke@435 | 1403 | } |
duke@435 | 1404 | } |
duke@435 | 1405 | #endif //PRODUCT |
duke@435 | 1406 | return num; |
duke@435 | 1407 | } |
duke@435 | 1408 | |
duke@435 | 1409 | // If a class (or interface) has a unique concrete method uniqm, return NULL. |
duke@435 | 1410 | // Otherwise, return a class that contains an interfering method. |
coleenp@4037 | 1411 | Klass* Dependencies::check_unique_concrete_method(Klass* ctxk, Method* uniqm, |
twisti@3050 | 1412 | KlassDepChange* changes) { |
duke@435 | 1413 | // Here is a missing optimization: If uniqm->is_final(), |
duke@435 | 1414 | // we don't really need to search beneath it for overrides. |
duke@435 | 1415 | // This is probably not important, since we don't use dependencies |
duke@435 | 1416 | // to track final methods. (They can't be "definalized".) |
duke@435 | 1417 | ClassHierarchyWalker wf(uniqm->method_holder(), uniqm); |
duke@435 | 1418 | return wf.find_witness_definer(ctxk, changes); |
duke@435 | 1419 | } |
duke@435 | 1420 | |
duke@435 | 1421 | // Find the set of all non-abstract methods under ctxk that match m. |
duke@435 | 1422 | // (The method m must be defined or inherited in ctxk.) |
duke@435 | 1423 | // Include m itself in the set, unless it is abstract. |
duke@435 | 1424 | // If this set has exactly one element, return that element. |
coleenp@4037 | 1425 | Method* Dependencies::find_unique_concrete_method(Klass* ctxk, Method* m) { |
duke@435 | 1426 | ClassHierarchyWalker wf(m); |
duke@435 | 1427 | assert(wf.check_method_context(ctxk, m), "proper context"); |
duke@435 | 1428 | wf.record_witnesses(1); |
coleenp@4037 | 1429 | Klass* wit = wf.find_witness_definer(ctxk); |
duke@435 | 1430 | if (wit != NULL) return NULL; // Too many witnesses. |
coleenp@4037 | 1431 | Method* fm = wf.found_method(0); // Will be NULL if num_parts == 0. |
drchase@7714 | 1432 | if (Dependencies::is_concrete_method(m, ctxk)) { |
duke@435 | 1433 | if (fm == NULL) { |
duke@435 | 1434 | // It turns out that m was always the only implementation. |
duke@435 | 1435 | fm = m; |
duke@435 | 1436 | } else if (fm != m) { |
duke@435 | 1437 | // Two conflicting implementations after all. |
duke@435 | 1438 | // (This can happen if m is inherited into ctxk and fm overrides it.) |
duke@435 | 1439 | return NULL; |
duke@435 | 1440 | } |
duke@435 | 1441 | } |
duke@435 | 1442 | #ifndef PRODUCT |
duke@435 | 1443 | // Make sure the dependency mechanism will pass this discovery: |
duke@435 | 1444 | if (VerifyDependencies && fm != NULL) { |
duke@435 | 1445 | guarantee(NULL == (void *)check_unique_concrete_method(ctxk, fm), |
duke@435 | 1446 | "verify dep."); |
duke@435 | 1447 | } |
duke@435 | 1448 | #endif //PRODUCT |
duke@435 | 1449 | return fm; |
duke@435 | 1450 | } |
duke@435 | 1451 | |
coleenp@4037 | 1452 | Klass* Dependencies::check_exclusive_concrete_methods(Klass* ctxk, |
coleenp@4037 | 1453 | Method* m1, |
coleenp@4037 | 1454 | Method* m2, |
twisti@3050 | 1455 | KlassDepChange* changes) { |
duke@435 | 1456 | ClassHierarchyWalker wf(m1); |
duke@435 | 1457 | wf.add_participant(m1->method_holder()); |
duke@435 | 1458 | wf.add_participant(m2->method_holder()); |
duke@435 | 1459 | return wf.find_witness_definer(ctxk, changes); |
duke@435 | 1460 | } |
duke@435 | 1461 | |
coleenp@4037 | 1462 | Klass* Dependencies::check_has_no_finalizable_subclasses(Klass* ctxk, KlassDepChange* changes) { |
coleenp@4037 | 1463 | Klass* search_at = ctxk; |
duke@435 | 1464 | if (changes != NULL) |
coleenp@4037 | 1465 | search_at = changes->new_type(); // just look at the new bit |
coleenp@4037 | 1466 | return find_finalizable_subclass(search_at); |
duke@435 | 1467 | } |
duke@435 | 1468 | |
coleenp@4037 | 1469 | Klass* Dependencies::check_call_site_target_value(oop call_site, oop method_handle, CallSiteDepChange* changes) { |
twisti@3050 | 1470 | assert(call_site ->is_a(SystemDictionary::CallSite_klass()), "sanity"); |
twisti@3050 | 1471 | assert(method_handle->is_a(SystemDictionary::MethodHandle_klass()), "sanity"); |
twisti@3050 | 1472 | if (changes == NULL) { |
twisti@3050 | 1473 | // Validate all CallSites |
twisti@3050 | 1474 | if (java_lang_invoke_CallSite::target(call_site) != method_handle) |
twisti@3094 | 1475 | return call_site->klass(); // assertion failed |
twisti@3050 | 1476 | } else { |
twisti@3050 | 1477 | // Validate the given CallSite |
twisti@3050 | 1478 | if (call_site == changes->call_site() && java_lang_invoke_CallSite::target(call_site) != changes->method_handle()) { |
twisti@3050 | 1479 | assert(method_handle != changes->method_handle(), "must be"); |
twisti@3094 | 1480 | return call_site->klass(); // assertion failed |
twisti@3050 | 1481 | } |
twisti@3050 | 1482 | } |
twisti@3050 | 1483 | return NULL; // assertion still valid |
twisti@3050 | 1484 | } |
twisti@3050 | 1485 | |
twisti@3050 | 1486 | |
coleenp@4037 | 1487 | void Dependencies::DepStream::trace_and_log_witness(Klass* witness) { |
twisti@3050 | 1488 | if (witness != NULL) { |
twisti@3050 | 1489 | if (TraceDependencies) { |
twisti@3050 | 1490 | print_dependency(witness, /*verbose=*/ true); |
twisti@3050 | 1491 | } |
twisti@3050 | 1492 | // The following is a no-op unless logging is enabled: |
twisti@3050 | 1493 | log_dependency(witness); |
twisti@3050 | 1494 | } |
twisti@3050 | 1495 | } |
twisti@3050 | 1496 | |
twisti@3050 | 1497 | |
coleenp@4037 | 1498 | Klass* Dependencies::DepStream::check_klass_dependency(KlassDepChange* changes) { |
duke@435 | 1499 | assert_locked_or_safepoint(Compile_lock); |
twisti@3050 | 1500 | Dependencies::check_valid_dependency_type(type()); |
duke@435 | 1501 | |
coleenp@4037 | 1502 | Klass* witness = NULL; |
duke@435 | 1503 | switch (type()) { |
duke@435 | 1504 | case evol_method: |
duke@435 | 1505 | witness = check_evol_method(method_argument(0)); |
duke@435 | 1506 | break; |
duke@435 | 1507 | case leaf_type: |
duke@435 | 1508 | witness = check_leaf_type(context_type()); |
duke@435 | 1509 | break; |
duke@435 | 1510 | case abstract_with_unique_concrete_subtype: |
twisti@3050 | 1511 | witness = check_abstract_with_unique_concrete_subtype(context_type(), type_argument(1), changes); |
duke@435 | 1512 | break; |
duke@435 | 1513 | case abstract_with_no_concrete_subtype: |
twisti@3050 | 1514 | witness = check_abstract_with_no_concrete_subtype(context_type(), changes); |
duke@435 | 1515 | break; |
duke@435 | 1516 | case concrete_with_no_concrete_subtype: |
twisti@3050 | 1517 | witness = check_concrete_with_no_concrete_subtype(context_type(), changes); |
duke@435 | 1518 | break; |
duke@435 | 1519 | case unique_concrete_method: |
twisti@3050 | 1520 | witness = check_unique_concrete_method(context_type(), method_argument(1), changes); |
duke@435 | 1521 | break; |
duke@435 | 1522 | case abstract_with_exclusive_concrete_subtypes_2: |
twisti@3050 | 1523 | witness = check_abstract_with_exclusive_concrete_subtypes(context_type(), type_argument(1), type_argument(2), changes); |
duke@435 | 1524 | break; |
duke@435 | 1525 | case exclusive_concrete_methods_2: |
twisti@3050 | 1526 | witness = check_exclusive_concrete_methods(context_type(), method_argument(1), method_argument(2), changes); |
duke@435 | 1527 | break; |
duke@435 | 1528 | case no_finalizable_subclasses: |
twisti@3050 | 1529 | witness = check_has_no_finalizable_subclasses(context_type(), changes); |
duke@435 | 1530 | break; |
twisti@3050 | 1531 | default: |
duke@435 | 1532 | witness = NULL; |
duke@435 | 1533 | break; |
duke@435 | 1534 | } |
twisti@3050 | 1535 | trace_and_log_witness(witness); |
duke@435 | 1536 | return witness; |
duke@435 | 1537 | } |
duke@435 | 1538 | |
duke@435 | 1539 | |
coleenp@4037 | 1540 | Klass* Dependencies::DepStream::check_call_site_dependency(CallSiteDepChange* changes) { |
twisti@3050 | 1541 | assert_locked_or_safepoint(Compile_lock); |
twisti@3050 | 1542 | Dependencies::check_valid_dependency_type(type()); |
duke@435 | 1543 | |
coleenp@4037 | 1544 | Klass* witness = NULL; |
twisti@3050 | 1545 | switch (type()) { |
twisti@3050 | 1546 | case call_site_target_value: |
coleenp@4037 | 1547 | witness = check_call_site_target_value(argument_oop(0), argument_oop(1), changes); |
twisti@3050 | 1548 | break; |
twisti@3050 | 1549 | default: |
twisti@3050 | 1550 | witness = NULL; |
twisti@3050 | 1551 | break; |
twisti@3050 | 1552 | } |
twisti@3050 | 1553 | trace_and_log_witness(witness); |
twisti@3050 | 1554 | return witness; |
duke@435 | 1555 | } |
duke@435 | 1556 | |
duke@435 | 1557 | |
coleenp@4037 | 1558 | Klass* Dependencies::DepStream::spot_check_dependency_at(DepChange& changes) { |
twisti@3050 | 1559 | // Handle klass dependency |
twisti@3050 | 1560 | if (changes.is_klass_change() && changes.as_klass_change()->involves_context(context_type())) |
twisti@3050 | 1561 | return check_klass_dependency(changes.as_klass_change()); |
duke@435 | 1562 | |
twisti@3050 | 1563 | // Handle CallSite dependency |
twisti@3050 | 1564 | if (changes.is_call_site_change()) |
twisti@3050 | 1565 | return check_call_site_dependency(changes.as_call_site_change()); |
twisti@3050 | 1566 | |
twisti@3050 | 1567 | // irrelevant dependency; skip it |
twisti@3050 | 1568 | return NULL; |
twisti@3050 | 1569 | } |
twisti@3050 | 1570 | |
twisti@3050 | 1571 | |
twisti@3050 | 1572 | void DepChange::print() { |
twisti@3050 | 1573 | int nsup = 0, nint = 0; |
duke@435 | 1574 | for (ContextStream str(*this); str.next(); ) { |
coleenp@4037 | 1575 | Klass* k = str.klass(); |
twisti@3050 | 1576 | switch (str.change_type()) { |
twisti@3050 | 1577 | case Change_new_type: |
coleenp@4037 | 1578 | tty->print_cr(" dependee = %s", InstanceKlass::cast(k)->external_name()); |
twisti@3050 | 1579 | break; |
twisti@3050 | 1580 | case Change_new_sub: |
twisti@3050 | 1581 | if (!WizardMode) { |
twisti@3050 | 1582 | ++nsup; |
twisti@3050 | 1583 | } else { |
coleenp@4037 | 1584 | tty->print_cr(" context super = %s", InstanceKlass::cast(k)->external_name()); |
twisti@3050 | 1585 | } |
twisti@3050 | 1586 | break; |
twisti@3050 | 1587 | case Change_new_impl: |
twisti@3050 | 1588 | if (!WizardMode) { |
twisti@3050 | 1589 | ++nint; |
twisti@3050 | 1590 | } else { |
coleenp@4037 | 1591 | tty->print_cr(" context interface = %s", InstanceKlass::cast(k)->external_name()); |
twisti@3050 | 1592 | } |
twisti@3050 | 1593 | break; |
twisti@3050 | 1594 | } |
twisti@3050 | 1595 | } |
twisti@3050 | 1596 | if (nsup + nint != 0) { |
twisti@3050 | 1597 | tty->print_cr(" context supers = %d, interfaces = %d", nsup, nint); |
duke@435 | 1598 | } |
duke@435 | 1599 | } |
duke@435 | 1600 | |
twisti@3050 | 1601 | void DepChange::ContextStream::start() { |
coleenp@4037 | 1602 | Klass* new_type = _changes.is_klass_change() ? _changes.as_klass_change()->new_type() : (Klass*) NULL; |
twisti@3050 | 1603 | _change_type = (new_type == NULL ? NO_CHANGE : Start_Klass); |
twisti@3050 | 1604 | _klass = new_type; |
twisti@3050 | 1605 | _ti_base = NULL; |
twisti@3050 | 1606 | _ti_index = 0; |
twisti@3050 | 1607 | _ti_limit = 0; |
duke@435 | 1608 | } |
duke@435 | 1609 | |
duke@435 | 1610 | bool DepChange::ContextStream::next() { |
duke@435 | 1611 | switch (_change_type) { |
duke@435 | 1612 | case Start_Klass: // initial state; _klass is the new type |
coleenp@4037 | 1613 | _ti_base = InstanceKlass::cast(_klass)->transitive_interfaces(); |
duke@435 | 1614 | _ti_index = 0; |
duke@435 | 1615 | _change_type = Change_new_type; |
duke@435 | 1616 | return true; |
duke@435 | 1617 | case Change_new_type: |
duke@435 | 1618 | // fall through: |
duke@435 | 1619 | _change_type = Change_new_sub; |
duke@435 | 1620 | case Change_new_sub: |
sbohne@489 | 1621 | // 6598190: brackets workaround Sun Studio C++ compiler bug 6629277 |
sbohne@489 | 1622 | { |
coleenp@4037 | 1623 | _klass = InstanceKlass::cast(_klass)->super(); |
sbohne@489 | 1624 | if (_klass != NULL) { |
sbohne@489 | 1625 | return true; |
sbohne@489 | 1626 | } |
duke@435 | 1627 | } |
duke@435 | 1628 | // else set up _ti_limit and fall through: |
duke@435 | 1629 | _ti_limit = (_ti_base == NULL) ? 0 : _ti_base->length(); |
duke@435 | 1630 | _change_type = Change_new_impl; |
duke@435 | 1631 | case Change_new_impl: |
duke@435 | 1632 | if (_ti_index < _ti_limit) { |
coleenp@4037 | 1633 | _klass = _ti_base->at(_ti_index++); |
duke@435 | 1634 | return true; |
duke@435 | 1635 | } |
duke@435 | 1636 | // fall through: |
duke@435 | 1637 | _change_type = NO_CHANGE; // iterator is exhausted |
duke@435 | 1638 | case NO_CHANGE: |
duke@435 | 1639 | break; |
duke@435 | 1640 | default: |
duke@435 | 1641 | ShouldNotReachHere(); |
duke@435 | 1642 | } |
duke@435 | 1643 | return false; |
duke@435 | 1644 | } |
duke@435 | 1645 | |
twisti@3050 | 1646 | void KlassDepChange::initialize() { |
twisti@3050 | 1647 | // entire transaction must be under this lock: |
twisti@3050 | 1648 | assert_lock_strong(Compile_lock); |
twisti@3050 | 1649 | |
twisti@3050 | 1650 | // Mark all dependee and all its superclasses |
twisti@3050 | 1651 | // Mark transitive interfaces |
duke@435 | 1652 | for (ContextStream str(*this); str.next(); ) { |
coleenp@4037 | 1653 | Klass* d = str.klass(); |
coleenp@4037 | 1654 | assert(!InstanceKlass::cast(d)->is_marked_dependent(), "checking"); |
coleenp@4037 | 1655 | InstanceKlass::cast(d)->set_is_marked_dependent(true); |
duke@435 | 1656 | } |
twisti@3050 | 1657 | } |
twisti@3050 | 1658 | |
twisti@3050 | 1659 | KlassDepChange::~KlassDepChange() { |
twisti@3050 | 1660 | // Unmark all dependee and all its superclasses |
twisti@3050 | 1661 | // Unmark transitive interfaces |
twisti@3050 | 1662 | for (ContextStream str(*this); str.next(); ) { |
coleenp@4037 | 1663 | Klass* d = str.klass(); |
coleenp@4037 | 1664 | InstanceKlass::cast(d)->set_is_marked_dependent(false); |
duke@435 | 1665 | } |
duke@435 | 1666 | } |
duke@435 | 1667 | |
coleenp@4037 | 1668 | bool KlassDepChange::involves_context(Klass* k) { |
hseigel@4278 | 1669 | if (k == NULL || !k->oop_is_instance()) { |
twisti@3050 | 1670 | return false; |
twisti@3050 | 1671 | } |
coleenp@4037 | 1672 | InstanceKlass* ik = InstanceKlass::cast(k); |
twisti@3050 | 1673 | bool is_contained = ik->is_marked_dependent(); |
hseigel@4278 | 1674 | assert(is_contained == new_type()->is_subtype_of(k), |
twisti@3050 | 1675 | "correct marking of potential context types"); |
twisti@3050 | 1676 | return is_contained; |
twisti@3050 | 1677 | } |
twisti@3050 | 1678 | |
duke@435 | 1679 | #ifndef PRODUCT |
duke@435 | 1680 | void Dependencies::print_statistics() { |
duke@435 | 1681 | if (deps_find_witness_print != 0) { |
duke@435 | 1682 | // Call one final time, to flush out the data. |
duke@435 | 1683 | deps_find_witness_print = -1; |
duke@435 | 1684 | count_find_witness_calls(); |
duke@435 | 1685 | } |
duke@435 | 1686 | } |
duke@435 | 1687 | #endif |