62
63 void Dependencies::initialize(ciEnv* env) {
64 Arena* arena = env->arena();
65 _oop_recorder = env->oop_recorder();
66 _log = env->log();
67 _dep_seen = new(arena) GrowableArray<int>(arena, 500, 0, 0);
68 DEBUG_ONLY(_deps[end_marker] = nullptr);
69 for (int i = (int)FIRST_TYPE; i < (int)TYPE_LIMIT; i++) {
70 _deps[i] = new(arena) GrowableArray<ciBaseObject*>(arena, 10, 0, nullptr);
71 }
72 _content_bytes = nullptr;
73 _size_in_bytes = (size_t)-1;
74
75 assert(TYPE_LIMIT <= (1<<LG2_TYPE_LIMIT), "sanity");
76 }
77
78 void Dependencies::assert_evol_method(ciMethod* m) {
79 assert_common_1(evol_method, m);
80 }
81
82 void Dependencies::assert_leaf_type(ciKlass* ctxk) {
83 if (ctxk->is_array_klass()) {
84 // As a special case, support this assertion on an array type,
85 // which reduces to an assertion on its element type.
86 // Note that this cannot be done with assertions that
87 // relate to concreteness or abstractness.
88 ciType* elemt = ctxk->as_array_klass()->base_element_type();
89 if (!elemt->is_instance_klass()) return; // Ex: int[][]
90 ctxk = elemt->as_instance_klass();
91 //if (ctxk->is_final()) return; // Ex: String[][]
92 }
93 check_ctxk(ctxk);
94 assert_common_1(leaf_type, ctxk);
95 }
96
97 void Dependencies::assert_abstract_with_unique_concrete_subtype(ciKlass* ctxk, ciKlass* conck) {
98 check_ctxk_abstract(ctxk);
99 assert_common_2(abstract_with_unique_concrete_subtype, ctxk, conck);
100 }
101
339
340 // write a sentinel byte to mark the end
341 bytes.write_byte(end_marker);
342
343 // round it out to a word boundary
344 while (bytes.position() % sizeof(HeapWord) != 0) {
345 bytes.write_byte(end_marker);
346 }
347
348 // check whether the dept byte encoding really works
349 assert((jbyte)default_context_type_bit != 0, "byte overflow");
350
351 _content_bytes = bytes.buffer();
352 _size_in_bytes = bytes.position();
353 }
354
355
356 const char* Dependencies::_dep_name[TYPE_LIMIT] = {
357 "end_marker",
358 "evol_method",
359 "leaf_type",
360 "abstract_with_unique_concrete_subtype",
361 "unique_concrete_method",
362 "unique_implementor",
363 "no_finalizable_subclasses",
364 "call_site_target_value"
365 };
366
367 int Dependencies::_dep_args[TYPE_LIMIT] = {
368 -1,// end_marker
369 1, // evol_method m
370 1, // leaf_type ctxk
371 2, // abstract_with_unique_concrete_subtype ctxk, k
372 4, // unique_concrete_method ctxk, m, resolved_klass, resolved_method
373 2, // unique_implementor ctxk, implementor
374 1, // no_finalizable_subclasses ctxk
375 2 // call_site_target_value call_site, method_handle
376 };
377
378 const char* Dependencies::dep_name(Dependencies::DepType dept) {
379 if (!dept_in_mask(dept, all_types)) return "?bad-dep?";
380 return _dep_name[dept];
381 }
382
383 int Dependencies::dep_args(Dependencies::DepType dept) {
384 if (!dept_in_mask(dept, all_types)) return -1;
385 return _dep_args[dept];
386 }
387
388 void Dependencies::check_valid_dependency_type(DepType dept) {
389 guarantee(FIRST_TYPE <= dept && dept < TYPE_LIMIT, "invalid dependency type: %d", (int) dept);
1280 bool Dependencies::is_concrete_klass(ciInstanceKlass* k) {
1281 if (k->is_abstract()) return false;
1282 // We could also return false if k does not yet appear to be
1283 // instantiated, if the VM version supports this distinction also.
1284 //if (k->is_not_instantiated()) return false;
1285 return true;
1286 }
1287
1288 bool Dependencies::has_finalizable_subclass(ciInstanceKlass* k) {
1289 return k->has_finalizable_subclass();
1290 }
1291
1292 // Any use of the contents (bytecodes) of a method must be
1293 // marked by an "evol_method" dependency, if those contents
1294 // can change. (Note: A method is always dependent on itself.)
1295 Klass* Dependencies::check_evol_method(Method* m) {
1296 assert(must_be_in_vm(), "raw oops here");
1297 // Did somebody do a JVMTI RedefineClasses while our backs were turned?
1298 // Or is there a now a breakpoint?
1299 // (Assumes compiled code cannot handle bkpts; change if UseFastBreakpoints.)
1300 if (m->is_old()
1301 || m->number_of_breakpoints() > 0) {
1302 return m->method_holder();
1303 } else {
1304 return nullptr;
1305 }
1306 }
1307
1308 // This is a strong assertion: It is that the given type
1309 // has no subtypes whatever. It is most useful for
1310 // optimizing checks on reflected types or on array types.
1311 // (Checks on types which are derived from real instances
1312 // can be optimized more strongly than this, because we
1313 // know that the checked type comes from a concrete type,
1314 // and therefore we can disregard abstract types.)
1315 Klass* Dependencies::check_leaf_type(InstanceKlass* ctxk) {
1316 assert(must_be_in_vm(), "raw oops here");
1317 assert_locked_or_safepoint(Compile_lock);
1318 Klass* sub = ctxk->subklass();
1319 if (sub != nullptr) {
1320 return sub;
1321 } else if (ctxk->nof_implementors() != 0) {
1491 if (witness != nullptr) {
1492 LogTarget(Debug, dependencies) lt;
1493 if (lt.is_enabled()) {
1494 LogStream ls(<);
1495 print_dependency(&ls, witness, /*verbose=*/ true);
1496 }
1497 // The following is a no-op unless logging is enabled:
1498 log_dependency(witness);
1499 }
1500 }
1501
1502 Klass* Dependencies::DepStream::check_new_klass_dependency(NewKlassDepChange* changes) {
1503 assert_locked_or_safepoint(Compile_lock);
1504 Dependencies::check_valid_dependency_type(type());
1505
1506 Klass* witness = nullptr;
1507 switch (type()) {
1508 case evol_method:
1509 witness = check_evol_method(method_argument(0));
1510 break;
1511 case leaf_type:
1512 witness = check_leaf_type(context_type());
1513 break;
1514 case abstract_with_unique_concrete_subtype:
1515 witness = check_abstract_with_unique_concrete_subtype(context_type(), type_argument(1), changes);
1516 break;
1517 case unique_concrete_method:
1518 witness = check_unique_concrete_method(context_type(), method_argument(1), type_argument(2), method_argument(3), changes);
1519 break;
1520 case unique_implementor:
1521 witness = check_unique_implementor(context_type(), type_argument(1), changes);
1522 break;
1523 case no_finalizable_subclasses:
1524 witness = check_has_no_finalizable_subclasses(context_type(), changes);
1525 break;
1526 default:
1527 witness = nullptr;
1528 break;
1529 }
1530 trace_and_log_witness(witness);
|
62
63 void Dependencies::initialize(ciEnv* env) {
64 Arena* arena = env->arena();
65 _oop_recorder = env->oop_recorder();
66 _log = env->log();
67 _dep_seen = new(arena) GrowableArray<int>(arena, 500, 0, 0);
68 DEBUG_ONLY(_deps[end_marker] = nullptr);
69 for (int i = (int)FIRST_TYPE; i < (int)TYPE_LIMIT; i++) {
70 _deps[i] = new(arena) GrowableArray<ciBaseObject*>(arena, 10, 0, nullptr);
71 }
72 _content_bytes = nullptr;
73 _size_in_bytes = (size_t)-1;
74
75 assert(TYPE_LIMIT <= (1<<LG2_TYPE_LIMIT), "sanity");
76 }
77
78 void Dependencies::assert_evol_method(ciMethod* m) {
79 assert_common_1(evol_method, m);
80 }
81
82 void Dependencies::assert_mismatch_calling_convention(ciMethod* m) {
83 assert_common_1(mismatch_calling_convention, m);
84 }
85
86 void Dependencies::assert_leaf_type(ciKlass* ctxk) {
87 if (ctxk->is_array_klass()) {
88 // As a special case, support this assertion on an array type,
89 // which reduces to an assertion on its element type.
90 // Note that this cannot be done with assertions that
91 // relate to concreteness or abstractness.
92 ciType* elemt = ctxk->as_array_klass()->base_element_type();
93 if (!elemt->is_instance_klass()) return; // Ex: int[][]
94 ctxk = elemt->as_instance_klass();
95 //if (ctxk->is_final()) return; // Ex: String[][]
96 }
97 check_ctxk(ctxk);
98 assert_common_1(leaf_type, ctxk);
99 }
100
101 void Dependencies::assert_abstract_with_unique_concrete_subtype(ciKlass* ctxk, ciKlass* conck) {
102 check_ctxk_abstract(ctxk);
103 assert_common_2(abstract_with_unique_concrete_subtype, ctxk, conck);
104 }
105
343
344 // write a sentinel byte to mark the end
345 bytes.write_byte(end_marker);
346
347 // round it out to a word boundary
348 while (bytes.position() % sizeof(HeapWord) != 0) {
349 bytes.write_byte(end_marker);
350 }
351
352 // check whether the dept byte encoding really works
353 assert((jbyte)default_context_type_bit != 0, "byte overflow");
354
355 _content_bytes = bytes.buffer();
356 _size_in_bytes = bytes.position();
357 }
358
359
360 const char* Dependencies::_dep_name[TYPE_LIMIT] = {
361 "end_marker",
362 "evol_method",
363 "mismatch_calling_convention",
364 "leaf_type",
365 "abstract_with_unique_concrete_subtype",
366 "unique_concrete_method",
367 "unique_implementor",
368 "no_finalizable_subclasses",
369 "call_site_target_value"
370 };
371
372 int Dependencies::_dep_args[TYPE_LIMIT] = {
373 -1,// end_marker
374 1, // evol_method m
375 1, // mismatch_calling_convention m
376 1, // leaf_type ctxk
377 2, // abstract_with_unique_concrete_subtype ctxk, k
378 4, // unique_concrete_method ctxk, m, resolved_klass, resolved_method
379 2, // unique_implementor ctxk, implementor
380 1, // no_finalizable_subclasses ctxk
381 2 // call_site_target_value call_site, method_handle
382 };
383
384 const char* Dependencies::dep_name(Dependencies::DepType dept) {
385 if (!dept_in_mask(dept, all_types)) return "?bad-dep?";
386 return _dep_name[dept];
387 }
388
389 int Dependencies::dep_args(Dependencies::DepType dept) {
390 if (!dept_in_mask(dept, all_types)) return -1;
391 return _dep_args[dept];
392 }
393
394 void Dependencies::check_valid_dependency_type(DepType dept) {
395 guarantee(FIRST_TYPE <= dept && dept < TYPE_LIMIT, "invalid dependency type: %d", (int) dept);
1286 bool Dependencies::is_concrete_klass(ciInstanceKlass* k) {
1287 if (k->is_abstract()) return false;
1288 // We could also return false if k does not yet appear to be
1289 // instantiated, if the VM version supports this distinction also.
1290 //if (k->is_not_instantiated()) return false;
1291 return true;
1292 }
1293
1294 bool Dependencies::has_finalizable_subclass(ciInstanceKlass* k) {
1295 return k->has_finalizable_subclass();
1296 }
1297
1298 // Any use of the contents (bytecodes) of a method must be
1299 // marked by an "evol_method" dependency, if those contents
1300 // can change. (Note: A method is always dependent on itself.)
1301 Klass* Dependencies::check_evol_method(Method* m) {
1302 assert(must_be_in_vm(), "raw oops here");
1303 // Did somebody do a JVMTI RedefineClasses while our backs were turned?
1304 // Or is there a now a breakpoint?
1305 // (Assumes compiled code cannot handle bkpts; change if UseFastBreakpoints.)
1306 if (m->is_old() || m->number_of_breakpoints() > 0) {
1307 return m->method_holder();
1308 } else {
1309 return nullptr;
1310 }
1311 }
1312
1313 Klass* Dependencies::check_mismatch_calling_convention(Method* m) {
1314 assert(must_be_in_vm(), "raw oops here");
1315 if (m->mismatch()) {
1316 return m->method_holder();
1317 } else {
1318 return nullptr;
1319 }
1320 }
1321
1322 // This is a strong assertion: It is that the given type
1323 // has no subtypes whatever. It is most useful for
1324 // optimizing checks on reflected types or on array types.
1325 // (Checks on types which are derived from real instances
1326 // can be optimized more strongly than this, because we
1327 // know that the checked type comes from a concrete type,
1328 // and therefore we can disregard abstract types.)
1329 Klass* Dependencies::check_leaf_type(InstanceKlass* ctxk) {
1330 assert(must_be_in_vm(), "raw oops here");
1331 assert_locked_or_safepoint(Compile_lock);
1332 Klass* sub = ctxk->subklass();
1333 if (sub != nullptr) {
1334 return sub;
1335 } else if (ctxk->nof_implementors() != 0) {
1505 if (witness != nullptr) {
1506 LogTarget(Debug, dependencies) lt;
1507 if (lt.is_enabled()) {
1508 LogStream ls(<);
1509 print_dependency(&ls, witness, /*verbose=*/ true);
1510 }
1511 // The following is a no-op unless logging is enabled:
1512 log_dependency(witness);
1513 }
1514 }
1515
1516 Klass* Dependencies::DepStream::check_new_klass_dependency(NewKlassDepChange* changes) {
1517 assert_locked_or_safepoint(Compile_lock);
1518 Dependencies::check_valid_dependency_type(type());
1519
1520 Klass* witness = nullptr;
1521 switch (type()) {
1522 case evol_method:
1523 witness = check_evol_method(method_argument(0));
1524 break;
1525 case mismatch_calling_convention:
1526 witness = check_mismatch_calling_convention(method_argument(0));
1527 break;
1528 case leaf_type:
1529 witness = check_leaf_type(context_type());
1530 break;
1531 case abstract_with_unique_concrete_subtype:
1532 witness = check_abstract_with_unique_concrete_subtype(context_type(), type_argument(1), changes);
1533 break;
1534 case unique_concrete_method:
1535 witness = check_unique_concrete_method(context_type(), method_argument(1), type_argument(2), method_argument(3), changes);
1536 break;
1537 case unique_implementor:
1538 witness = check_unique_implementor(context_type(), type_argument(1), changes);
1539 break;
1540 case no_finalizable_subclasses:
1541 witness = check_has_no_finalizable_subclasses(context_type(), changes);
1542 break;
1543 default:
1544 witness = nullptr;
1545 break;
1546 }
1547 trace_and_log_witness(witness);
|