255 deps->append(x0);
256 deps->append(x1);
257 }
258
259 void Dependencies::assert_common_3(DepType dept,
260 ciKlass* ctxk, ciBaseObject* x, ciBaseObject* x2) {
261 assert(dep_context_arg(dept) == 0, "sanity");
262 assert(dep_args(dept) == 3, "sanity");
263 log_dependency(dept, ctxk, x, x2);
264 GrowableArray<ciBaseObject*>* deps = _deps[dept];
265
266 // try to normalize an unordered pair:
267 bool swap = false;
268 switch (dept) {
269 case abstract_with_exclusive_concrete_subtypes_2:
270 swap = (x->ident() > x2->ident() && x->as_metadata()->as_klass() != ctxk);
271 break;
272 case exclusive_concrete_methods_2:
273 swap = (x->ident() > x2->ident() && x->as_metadata()->as_method()->holder() != ctxk);
274 break;
275 }
276 if (swap) { ciBaseObject* t = x; x = x2; x2 = t; }
277
278 // see if the same (or a similar) dep is already recorded
279 if (note_dep_seen(dept, x) && note_dep_seen(dept, x2)) {
280 // look in this bucket for redundant assertions
281 const int stride = 3;
282 for (int i = deps->length(); (i -= stride) >= 0; ) {
283 ciBaseObject* y = deps->at(i+1);
284 ciBaseObject* y2 = deps->at(i+2);
285 if (x == y && x2 == y2) { // same subjects; check the context
286 if (maybe_merge_ctxk(deps, i+0, ctxk)) {
287 return;
288 }
289 }
290 }
291 }
292 // append the assertion in the correct bucket:
293 deps->append(ctxk);
294 deps->append(x);
403 }
404 static int sort_dep_value_arg_1(Dependencies::DepValue* p1, Dependencies::DepValue* p2)
405 { return sort_dep_value(p1, p2, 1); }
406 static int sort_dep_value_arg_2(Dependencies::DepValue* p1, Dependencies::DepValue* p2)
407 { return sort_dep_value(p1, p2, 2); }
408 static int sort_dep_value_arg_3(Dependencies::DepValue* p1, Dependencies::DepValue* p2)
409 { return sort_dep_value(p1, p2, 3); }
410 #endif // INCLUDE_JVMCI
411
412 void Dependencies::sort_all_deps() {
413 #if INCLUDE_JVMCI
414 if (_using_dep_values) {
415 for (int deptv = (int)FIRST_TYPE; deptv < (int)TYPE_LIMIT; deptv++) {
416 DepType dept = (DepType)deptv;
417 GrowableArray<DepValue>* deps = _dep_values[dept];
418 if (deps->length() <= 1) continue;
419 switch (dep_args(dept)) {
420 case 1: deps->sort(sort_dep_value_arg_1, 1); break;
421 case 2: deps->sort(sort_dep_value_arg_2, 2); break;
422 case 3: deps->sort(sort_dep_value_arg_3, 3); break;
423 default: ShouldNotReachHere();
424 }
425 }
426 return;
427 }
428 #endif // INCLUDE_JVMCI
429 for (int deptv = (int)FIRST_TYPE; deptv < (int)TYPE_LIMIT; deptv++) {
430 DepType dept = (DepType)deptv;
431 GrowableArray<ciBaseObject*>* deps = _deps[dept];
432 if (deps->length() <= 1) continue;
433 switch (dep_args(dept)) {
434 case 1: deps->sort(sort_dep_arg_1, 1); break;
435 case 2: deps->sort(sort_dep_arg_2, 2); break;
436 case 3: deps->sort(sort_dep_arg_3, 3); break;
437 default: ShouldNotReachHere();
438 }
439 }
440 }
441
442 size_t Dependencies::estimate_size_in_bytes() {
443 size_t est_size = 100;
444 #if INCLUDE_JVMCI
445 if (_using_dep_values) {
446 for (int deptv = (int)FIRST_TYPE; deptv < (int)TYPE_LIMIT; deptv++) {
447 DepType dept = (DepType)deptv;
448 GrowableArray<DepValue>* deps = _dep_values[dept];
449 est_size += deps->length() * 2; // tags and argument(s)
450 }
451 return est_size;
452 }
453 #endif // INCLUDE_JVMCI
454 for (int deptv = (int)FIRST_TYPE; deptv < (int)TYPE_LIMIT; deptv++) {
455 DepType dept = (DepType)deptv;
456 GrowableArray<ciBaseObject*>* deps = _deps[dept];
457 est_size += deps->length()*2; // tags and argument(s)
458 }
459 return est_size;
460 }
461
462 ciKlass* Dependencies::ctxk_encoded_as_null(DepType dept, ciBaseObject* x) {
463 switch (dept) {
464 case abstract_with_exclusive_concrete_subtypes_2:
465 return x->as_metadata()->as_klass();
466 case unique_concrete_method:
467 case exclusive_concrete_methods_2:
468 return x->as_metadata()->as_method()->holder();
469 }
470 return NULL; // let NULL be NULL
471 }
472
473 Klass* Dependencies::ctxk_encoded_as_null(DepType dept, Metadata* x) {
474 assert(must_be_in_vm(), "raw oops here");
475 switch (dept) {
476 case abstract_with_exclusive_concrete_subtypes_2:
477 assert(x->is_klass(), "sanity");
478 return (Klass*) x;
479 case unique_concrete_method:
480 case exclusive_concrete_methods_2:
481 assert(x->is_method(), "sanity");
482 return ((Method*)x)->method_holder();
483 }
484 return NULL; // let NULL be NULL
485 }
486
487 void Dependencies::encode_content_bytes() {
488 sort_all_deps();
489
490 // cast is safe, no deps can overflow INT_MAX
491 CompressedWriteStream bytes((int)estimate_size_in_bytes());
492
493 #if INCLUDE_JVMCI
494 if (_using_dep_values) {
495 for (int deptv = (int)FIRST_TYPE; deptv < (int)TYPE_LIMIT; deptv++) {
496 DepType dept = (DepType)deptv;
497 GrowableArray<DepValue>* deps = _dep_values[dept];
498 if (deps->length() == 0) continue;
499 int stride = dep_args(dept);
500 int ctxkj = dep_context_arg(dept); // -1 if no context arg
501 assert(stride > 0, "sanity");
502 for (int i = 0; i < deps->length(); i += stride) {
503 jbyte code_byte = (jbyte)dept;
504 int skipj = -1;
1442
1443 bool Dependencies::is_concrete_klass(Klass* k) {
1444 if (k->is_abstract()) return false;
1445 // %%% We could treat classes which are concrete but
1446 // have not yet been instantiated as virtually abstract.
1447 // This would require a deoptimization barrier on first instantiation.
1448 //if (k->is_not_instantiated()) return false;
1449 return true;
1450 }
1451
1452 bool Dependencies::is_concrete_method(Method* m, Klass * k) {
1453 // NULL is not a concrete method,
1454 // statics are irrelevant to virtual call sites,
1455 // abstract methods are not concrete,
1456 // overpass (error) methods are not concrete if k is abstract
1457 //
1458 // note "true" is conservative answer --
1459 // overpass clause is false if k == NULL, implies return true if
1460 // answer depends on overpass clause.
1461 return ! ( m == NULL || m -> is_static() || m -> is_abstract() ||
1462 m->is_overpass() && k != NULL && k -> is_abstract() );
1463 }
1464
1465
1466 Klass* Dependencies::find_finalizable_subclass(Klass* k) {
1467 if (k->is_interface()) return NULL;
1468 if (k->has_finalizer()) return k;
1469 k = k->subklass();
1470 while (k != NULL) {
1471 Klass* result = find_finalizable_subclass(k);
1472 if (result != NULL) return result;
1473 k = k->next_sibling();
1474 }
1475 return NULL;
1476 }
1477
1478
1479 bool Dependencies::is_concrete_klass(ciInstanceKlass* k) {
1480 if (k->is_abstract()) return false;
1481 // We could also return false if k does not yet appear to be
1482 // instantiated, if the VM version supports this distinction also.
1847 for (ContextStream str(*this); str.next(); ) {
1848 Klass* k = str.klass();
1849 switch (str.change_type()) {
1850 case Change_new_type:
1851 tty->print_cr(" dependee = %s", k->external_name());
1852 break;
1853 case Change_new_sub:
1854 if (!WizardMode) {
1855 ++nsup;
1856 } else {
1857 tty->print_cr(" context super = %s", k->external_name());
1858 }
1859 break;
1860 case Change_new_impl:
1861 if (!WizardMode) {
1862 ++nint;
1863 } else {
1864 tty->print_cr(" context interface = %s", k->external_name());
1865 }
1866 break;
1867 }
1868 }
1869 if (nsup + nint != 0) {
1870 tty->print_cr(" context supers = %d, interfaces = %d", nsup, nint);
1871 }
1872 }
1873
1874 void DepChange::ContextStream::start() {
1875 Klass* new_type = _changes.is_klass_change() ? _changes.as_klass_change()->new_type() : (Klass*) NULL;
1876 _change_type = (new_type == NULL ? NO_CHANGE : Start_Klass);
1877 _klass = new_type;
1878 _ti_base = NULL;
1879 _ti_index = 0;
1880 _ti_limit = 0;
1881 }
1882
1883 bool DepChange::ContextStream::next() {
1884 switch (_change_type) {
1885 case Start_Klass: // initial state; _klass is the new type
1886 _ti_base = InstanceKlass::cast(_klass)->transitive_interfaces();
|
255 deps->append(x0);
256 deps->append(x1);
257 }
258
259 void Dependencies::assert_common_3(DepType dept,
260 ciKlass* ctxk, ciBaseObject* x, ciBaseObject* x2) {
261 assert(dep_context_arg(dept) == 0, "sanity");
262 assert(dep_args(dept) == 3, "sanity");
263 log_dependency(dept, ctxk, x, x2);
264 GrowableArray<ciBaseObject*>* deps = _deps[dept];
265
266 // try to normalize an unordered pair:
267 bool swap = false;
268 switch (dept) {
269 case abstract_with_exclusive_concrete_subtypes_2:
270 swap = (x->ident() > x2->ident() && x->as_metadata()->as_klass() != ctxk);
271 break;
272 case exclusive_concrete_methods_2:
273 swap = (x->ident() > x2->ident() && x->as_metadata()->as_method()->holder() != ctxk);
274 break;
275 default:
276 break;
277 }
278 if (swap) { ciBaseObject* t = x; x = x2; x2 = t; }
279
280 // see if the same (or a similar) dep is already recorded
281 if (note_dep_seen(dept, x) && note_dep_seen(dept, x2)) {
282 // look in this bucket for redundant assertions
283 const int stride = 3;
284 for (int i = deps->length(); (i -= stride) >= 0; ) {
285 ciBaseObject* y = deps->at(i+1);
286 ciBaseObject* y2 = deps->at(i+2);
287 if (x == y && x2 == y2) { // same subjects; check the context
288 if (maybe_merge_ctxk(deps, i+0, ctxk)) {
289 return;
290 }
291 }
292 }
293 }
294 // append the assertion in the correct bucket:
295 deps->append(ctxk);
296 deps->append(x);
405 }
406 static int sort_dep_value_arg_1(Dependencies::DepValue* p1, Dependencies::DepValue* p2)
407 { return sort_dep_value(p1, p2, 1); }
408 static int sort_dep_value_arg_2(Dependencies::DepValue* p1, Dependencies::DepValue* p2)
409 { return sort_dep_value(p1, p2, 2); }
410 static int sort_dep_value_arg_3(Dependencies::DepValue* p1, Dependencies::DepValue* p2)
411 { return sort_dep_value(p1, p2, 3); }
412 #endif // INCLUDE_JVMCI
413
414 void Dependencies::sort_all_deps() {
415 #if INCLUDE_JVMCI
416 if (_using_dep_values) {
417 for (int deptv = (int)FIRST_TYPE; deptv < (int)TYPE_LIMIT; deptv++) {
418 DepType dept = (DepType)deptv;
419 GrowableArray<DepValue>* deps = _dep_values[dept];
420 if (deps->length() <= 1) continue;
421 switch (dep_args(dept)) {
422 case 1: deps->sort(sort_dep_value_arg_1, 1); break;
423 case 2: deps->sort(sort_dep_value_arg_2, 2); break;
424 case 3: deps->sort(sort_dep_value_arg_3, 3); break;
425 default: ShouldNotReachHere(); break;
426 }
427 }
428 return;
429 }
430 #endif // INCLUDE_JVMCI
431 for (int deptv = (int)FIRST_TYPE; deptv < (int)TYPE_LIMIT; deptv++) {
432 DepType dept = (DepType)deptv;
433 GrowableArray<ciBaseObject*>* deps = _deps[dept];
434 if (deps->length() <= 1) continue;
435 switch (dep_args(dept)) {
436 case 1: deps->sort(sort_dep_arg_1, 1); break;
437 case 2: deps->sort(sort_dep_arg_2, 2); break;
438 case 3: deps->sort(sort_dep_arg_3, 3); break;
439 default: ShouldNotReachHere(); break;
440 }
441 }
442 }
443
444 size_t Dependencies::estimate_size_in_bytes() {
445 size_t est_size = 100;
446 #if INCLUDE_JVMCI
447 if (_using_dep_values) {
448 for (int deptv = (int)FIRST_TYPE; deptv < (int)TYPE_LIMIT; deptv++) {
449 DepType dept = (DepType)deptv;
450 GrowableArray<DepValue>* deps = _dep_values[dept];
451 est_size += deps->length() * 2; // tags and argument(s)
452 }
453 return est_size;
454 }
455 #endif // INCLUDE_JVMCI
456 for (int deptv = (int)FIRST_TYPE; deptv < (int)TYPE_LIMIT; deptv++) {
457 DepType dept = (DepType)deptv;
458 GrowableArray<ciBaseObject*>* deps = _deps[dept];
459 est_size += deps->length()*2; // tags and argument(s)
460 }
461 return est_size;
462 }
463
464 ciKlass* Dependencies::ctxk_encoded_as_null(DepType dept, ciBaseObject* x) {
465 switch (dept) {
466 case abstract_with_exclusive_concrete_subtypes_2:
467 return x->as_metadata()->as_klass();
468 case unique_concrete_method:
469 case exclusive_concrete_methods_2:
470 return x->as_metadata()->as_method()->holder();
471 default:
472 return NULL; // let NULL be NULL
473 }
474 }
475
476 Klass* Dependencies::ctxk_encoded_as_null(DepType dept, Metadata* x) {
477 assert(must_be_in_vm(), "raw oops here");
478 switch (dept) {
479 case abstract_with_exclusive_concrete_subtypes_2:
480 assert(x->is_klass(), "sanity");
481 return (Klass*) x;
482 case unique_concrete_method:
483 case exclusive_concrete_methods_2:
484 assert(x->is_method(), "sanity");
485 return ((Method*)x)->method_holder();
486 default:
487 return NULL; // let NULL be NULL
488 }
489 }
490
491 void Dependencies::encode_content_bytes() {
492 sort_all_deps();
493
494 // cast is safe, no deps can overflow INT_MAX
495 CompressedWriteStream bytes((int)estimate_size_in_bytes());
496
497 #if INCLUDE_JVMCI
498 if (_using_dep_values) {
499 for (int deptv = (int)FIRST_TYPE; deptv < (int)TYPE_LIMIT; deptv++) {
500 DepType dept = (DepType)deptv;
501 GrowableArray<DepValue>* deps = _dep_values[dept];
502 if (deps->length() == 0) continue;
503 int stride = dep_args(dept);
504 int ctxkj = dep_context_arg(dept); // -1 if no context arg
505 assert(stride > 0, "sanity");
506 for (int i = 0; i < deps->length(); i += stride) {
507 jbyte code_byte = (jbyte)dept;
508 int skipj = -1;
1446
1447 bool Dependencies::is_concrete_klass(Klass* k) {
1448 if (k->is_abstract()) return false;
1449 // %%% We could treat classes which are concrete but
1450 // have not yet been instantiated as virtually abstract.
1451 // This would require a deoptimization barrier on first instantiation.
1452 //if (k->is_not_instantiated()) return false;
1453 return true;
1454 }
1455
1456 bool Dependencies::is_concrete_method(Method* m, Klass * k) {
1457 // NULL is not a concrete method,
1458 // statics are irrelevant to virtual call sites,
1459 // abstract methods are not concrete,
1460 // overpass (error) methods are not concrete if k is abstract
1461 //
1462 // note "true" is conservative answer --
1463 // overpass clause is false if k == NULL, implies return true if
1464 // answer depends on overpass clause.
1465 return ! ( m == NULL || m -> is_static() || m -> is_abstract() ||
1466 (m->is_overpass() && k != NULL && k -> is_abstract()) );
1467 }
1468
1469
1470 Klass* Dependencies::find_finalizable_subclass(Klass* k) {
1471 if (k->is_interface()) return NULL;
1472 if (k->has_finalizer()) return k;
1473 k = k->subklass();
1474 while (k != NULL) {
1475 Klass* result = find_finalizable_subclass(k);
1476 if (result != NULL) return result;
1477 k = k->next_sibling();
1478 }
1479 return NULL;
1480 }
1481
1482
1483 bool Dependencies::is_concrete_klass(ciInstanceKlass* k) {
1484 if (k->is_abstract()) return false;
1485 // We could also return false if k does not yet appear to be
1486 // instantiated, if the VM version supports this distinction also.
1851 for (ContextStream str(*this); str.next(); ) {
1852 Klass* k = str.klass();
1853 switch (str.change_type()) {
1854 case Change_new_type:
1855 tty->print_cr(" dependee = %s", k->external_name());
1856 break;
1857 case Change_new_sub:
1858 if (!WizardMode) {
1859 ++nsup;
1860 } else {
1861 tty->print_cr(" context super = %s", k->external_name());
1862 }
1863 break;
1864 case Change_new_impl:
1865 if (!WizardMode) {
1866 ++nint;
1867 } else {
1868 tty->print_cr(" context interface = %s", k->external_name());
1869 }
1870 break;
1871 default:
1872 break;
1873 }
1874 }
1875 if (nsup + nint != 0) {
1876 tty->print_cr(" context supers = %d, interfaces = %d", nsup, nint);
1877 }
1878 }
1879
1880 void DepChange::ContextStream::start() {
1881 Klass* new_type = _changes.is_klass_change() ? _changes.as_klass_change()->new_type() : (Klass*) NULL;
1882 _change_type = (new_type == NULL ? NO_CHANGE : Start_Klass);
1883 _klass = new_type;
1884 _ti_base = NULL;
1885 _ti_index = 0;
1886 _ti_limit = 0;
1887 }
1888
1889 bool DepChange::ContextStream::next() {
1890 switch (_change_type) {
1891 case Start_Klass: // initial state; _klass is the new type
1892 _ti_base = InstanceKlass::cast(_klass)->transitive_interfaces();
|