annotate src/share/vm/code/dependencies.cpp @ 2297:fe8ab1affd14

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