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