annotate src/share/vm/code/dependencies.cpp @ 975:83c29a26f67c

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