src/share/vm/code/dependencies.cpp

Wed, 08 Apr 2009 00:12:59 -0700

author
jrose
date
Wed, 08 Apr 2009 00:12:59 -0700
changeset 1144
1d037ecd7960
parent 631
d1605aabd0a1
child 1408
ad6585fd4087
child 1424
148e5441d916
permissions
-rw-r--r--

6827505: sizing logic for vtable and itable stubs needs self-check
Summary: Asserts and comments to help maintain the correct sizing of certain stubs
Reviewed-by: kvn

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

mercurial