< prev index next >

src/share/vm/code/dependencies.cpp

Print this page




 100   check_ctxk(ctxk);
 101   assert_common_2(unique_concrete_method, ctxk, uniqm);
 102 }
 103 
 104 void Dependencies::assert_abstract_with_exclusive_concrete_subtypes(ciKlass* ctxk, ciKlass* k1, ciKlass* k2) {
 105   check_ctxk(ctxk);
 106   assert_common_3(abstract_with_exclusive_concrete_subtypes_2, ctxk, k1, k2);
 107 }
 108 
 109 void Dependencies::assert_exclusive_concrete_methods(ciKlass* ctxk, ciMethod* m1, ciMethod* m2) {
 110   check_ctxk(ctxk);
 111   assert_common_3(exclusive_concrete_methods_2, ctxk, m1, m2);
 112 }
 113 
 114 void Dependencies::assert_has_no_finalizable_subclasses(ciKlass* ctxk) {
 115   check_ctxk(ctxk);
 116   assert_common_1(no_finalizable_subclasses, ctxk);
 117 }
 118 
 119 void Dependencies::assert_call_site_target_value(ciCallSite* call_site, ciMethodHandle* method_handle) {
 120   ciKlass* ctxk = call_site->get_context();
 121   check_ctxk(ctxk);
 122   assert_common_3(call_site_target_value, ctxk, call_site, method_handle);
 123 }
 124 
 125 // Helper function.  If we are adding a new dep. under ctxk2,
 126 // try to find an old dep. under a broader* ctxk1.  If there is
 127 //
 128 bool Dependencies::maybe_merge_ctxk(GrowableArray<ciBaseObject*>* deps,
 129                                     int ctxk_i, ciKlass* ctxk2) {
 130   ciKlass* ctxk1 = deps->at(ctxk_i)->as_metadata()->as_klass();
 131   if (ctxk2->is_subtype_of(ctxk1)) {
 132     return true;  // success, and no need to change
 133   } else if (ctxk1->is_subtype_of(ctxk2)) {
 134     // new context class fully subsumes previous one
 135     deps->at_put(ctxk_i, ctxk2);
 136     return true;
 137   } else {
 138     return false;
 139   }
 140 }
 141 
 142 void Dependencies::assert_common_1(DepType dept, ciBaseObject* x) {


 158   log_dependency(dept, x0, x1);
 159   GrowableArray<ciBaseObject*>* deps = _deps[dept];
 160 
 161   // see if the same (or a similar) dep is already recorded
 162   bool has_ctxk = has_explicit_context_arg(dept);
 163   if (has_ctxk) {
 164     assert(dep_context_arg(dept) == 0, "sanity");
 165     if (note_dep_seen(dept, x1)) {
 166       // look in this bucket for redundant assertions
 167       const int stride = 2;
 168       for (int i = deps->length(); (i -= stride) >= 0; ) {
 169         ciBaseObject* y1 = deps->at(i+1);
 170         if (x1 == y1) {  // same subject; check the context
 171           if (maybe_merge_ctxk(deps, i+0, x0->as_metadata()->as_klass())) {
 172             return;
 173           }
 174         }
 175       }
 176     }
 177   } else {
 178     assert(dep_implicit_context_arg(dept) == 0, "sanity");
 179     if (note_dep_seen(dept, x0) && note_dep_seen(dept, x1)) {
 180       // look in this bucket for redundant assertions
 181       const int stride = 2;
 182       for (int i = deps->length(); (i -= stride) >= 0; ) {
 183         ciBaseObject* y0 = deps->at(i+0);
 184         ciBaseObject* y1 = deps->at(i+1);
 185         if (x0 == y0 && x1 == y1) {
 186           return;
 187         }
 188       }
 189     }
 190   }
 191 
 192   // append the assertion in the correct bucket:
 193   deps->append(x0);
 194   deps->append(x1);
 195 }
 196 
 197 void Dependencies::assert_common_3(DepType dept,
 198                                    ciKlass* ctxk, ciBaseObject* x, ciBaseObject* x2) {


 372   "abstract_with_no_concrete_subtype",
 373   "concrete_with_no_concrete_subtype",
 374   "unique_concrete_method",
 375   "abstract_with_exclusive_concrete_subtypes_2",
 376   "exclusive_concrete_methods_2",
 377   "no_finalizable_subclasses",
 378   "call_site_target_value"
 379 };
 380 
 381 int Dependencies::_dep_args[TYPE_LIMIT] = {
 382   -1,// end_marker
 383   1, // evol_method m
 384   1, // leaf_type ctxk
 385   2, // abstract_with_unique_concrete_subtype ctxk, k
 386   1, // abstract_with_no_concrete_subtype ctxk
 387   1, // concrete_with_no_concrete_subtype ctxk
 388   2, // unique_concrete_method ctxk, m
 389   3, // unique_concrete_subtypes_2 ctxk, k1, k2
 390   3, // unique_concrete_methods_2 ctxk, m1, m2
 391   1, // no_finalizable_subclasses ctxk
 392   3  // call_site_target_value ctxk, call_site, method_handle
 393 };
 394 
 395 const char* Dependencies::dep_name(Dependencies::DepType dept) {
 396   if (!dept_in_mask(dept, all_types))  return "?bad-dep?";
 397   return _dep_name[dept];
 398 }
 399 
 400 int Dependencies::dep_args(Dependencies::DepType dept) {
 401   if (!dept_in_mask(dept, all_types))  return -1;
 402   return _dep_args[dept];
 403 }
 404 
 405 void Dependencies::check_valid_dependency_type(DepType dept) {
 406   guarantee(FIRST_TYPE <= dept && dept < TYPE_LIMIT, err_msg("invalid dependency type: %d", (int) dept));
 407 }
 408 
 409 // for the sake of the compiler log, print out current dependencies:
 410 void Dependencies::log_all_dependencies() {
 411   if (log() == NULL)  return;
 412   ResourceMark rm;


1498   return fm;
1499 }
1500 
1501 Klass* Dependencies::check_exclusive_concrete_methods(Klass* ctxk,
1502                                                         Method* m1,
1503                                                         Method* m2,
1504                                                         KlassDepChange* changes) {
1505   ClassHierarchyWalker wf(m1);
1506   wf.add_participant(m1->method_holder());
1507   wf.add_participant(m2->method_holder());
1508   return wf.find_witness_definer(ctxk, changes);
1509 }
1510 
1511 Klass* Dependencies::check_has_no_finalizable_subclasses(Klass* ctxk, KlassDepChange* changes) {
1512   Klass* search_at = ctxk;
1513   if (changes != NULL)
1514     search_at = changes->new_type(); // just look at the new bit
1515   return find_finalizable_subclass(search_at);
1516 }
1517 
1518 Klass* Dependencies::check_call_site_target_value(Klass* recorded_ctxk, oop call_site, oop method_handle, CallSiteDepChange* changes) {
1519   assert(call_site->is_a(SystemDictionary::CallSite_klass()),     "sanity");

1520   assert(!oopDesc::is_null(method_handle), "sanity");
1521 
1522   Klass* call_site_ctxk = MethodHandles::get_call_site_context(call_site);
1523   assert(!Klass::is_null(call_site_ctxk), "call site context should be initialized already");
1524   if (recorded_ctxk != call_site_ctxk) {
1525     // Stale context
1526     return recorded_ctxk;
1527   }
1528   if (changes == NULL) {
1529     // Validate all CallSites
1530     if (java_lang_invoke_CallSite::target(call_site) != method_handle)
1531       return call_site->klass();  // assertion failed
1532   } else {
1533     // Validate the given CallSite
1534     if (call_site == changes->call_site() && java_lang_invoke_CallSite::target(call_site) != changes->method_handle()) {
1535       assert(method_handle != changes->method_handle(), "must be");
1536       return call_site->klass();  // assertion failed
1537     }
1538   }
1539   return NULL;  // assertion still valid
1540 }
1541 
1542 void Dependencies::DepStream::trace_and_log_witness(Klass* witness) {
1543   if (witness != NULL) {
1544     if (TraceDependencies) {
1545       print_dependency(witness, /*verbose=*/ true);
1546     }
1547     // The following is a no-op unless logging is enabled:


1582     break;
1583   case no_finalizable_subclasses:
1584     witness = check_has_no_finalizable_subclasses(context_type(), changes);
1585     break;
1586   default:
1587     witness = NULL;
1588     break;
1589   }
1590   trace_and_log_witness(witness);
1591   return witness;
1592 }
1593 
1594 
1595 Klass* Dependencies::DepStream::check_call_site_dependency(CallSiteDepChange* changes) {
1596   assert_locked_or_safepoint(Compile_lock);
1597   Dependencies::check_valid_dependency_type(type());
1598 
1599   Klass* witness = NULL;
1600   switch (type()) {
1601   case call_site_target_value:
1602     witness = check_call_site_target_value(context_type(), argument_oop(1), argument_oop(2), changes);
1603     break;
1604   default:
1605     witness = NULL;
1606     break;
1607   }
1608   trace_and_log_witness(witness);
1609   return witness;
1610 }
1611 
1612 
1613 Klass* Dependencies::DepStream::spot_check_dependency_at(DepChange& changes) {
1614   // Handle klass dependency
1615   if (changes.is_klass_change() && changes.as_klass_change()->involves_context(context_type()))
1616     return check_klass_dependency(changes.as_klass_change());
1617 
1618   // Handle CallSite dependency
1619   if (changes.is_call_site_change())
1620     return check_call_site_dependency(changes.as_call_site_change());
1621 
1622   // irrelevant dependency; skip it




 100   check_ctxk(ctxk);
 101   assert_common_2(unique_concrete_method, ctxk, uniqm);
 102 }
 103 
 104 void Dependencies::assert_abstract_with_exclusive_concrete_subtypes(ciKlass* ctxk, ciKlass* k1, ciKlass* k2) {
 105   check_ctxk(ctxk);
 106   assert_common_3(abstract_with_exclusive_concrete_subtypes_2, ctxk, k1, k2);
 107 }
 108 
 109 void Dependencies::assert_exclusive_concrete_methods(ciKlass* ctxk, ciMethod* m1, ciMethod* m2) {
 110   check_ctxk(ctxk);
 111   assert_common_3(exclusive_concrete_methods_2, ctxk, m1, m2);
 112 }
 113 
 114 void Dependencies::assert_has_no_finalizable_subclasses(ciKlass* ctxk) {
 115   check_ctxk(ctxk);
 116   assert_common_1(no_finalizable_subclasses, ctxk);
 117 }
 118 
 119 void Dependencies::assert_call_site_target_value(ciCallSite* call_site, ciMethodHandle* method_handle) {
 120   assert_common_2(call_site_target_value, call_site, method_handle);


 121 }
 122 
 123 // Helper function.  If we are adding a new dep. under ctxk2,
 124 // try to find an old dep. under a broader* ctxk1.  If there is
 125 //
 126 bool Dependencies::maybe_merge_ctxk(GrowableArray<ciBaseObject*>* deps,
 127                                     int ctxk_i, ciKlass* ctxk2) {
 128   ciKlass* ctxk1 = deps->at(ctxk_i)->as_metadata()->as_klass();
 129   if (ctxk2->is_subtype_of(ctxk1)) {
 130     return true;  // success, and no need to change
 131   } else if (ctxk1->is_subtype_of(ctxk2)) {
 132     // new context class fully subsumes previous one
 133     deps->at_put(ctxk_i, ctxk2);
 134     return true;
 135   } else {
 136     return false;
 137   }
 138 }
 139 
 140 void Dependencies::assert_common_1(DepType dept, ciBaseObject* x) {


 156   log_dependency(dept, x0, x1);
 157   GrowableArray<ciBaseObject*>* deps = _deps[dept];
 158 
 159   // see if the same (or a similar) dep is already recorded
 160   bool has_ctxk = has_explicit_context_arg(dept);
 161   if (has_ctxk) {
 162     assert(dep_context_arg(dept) == 0, "sanity");
 163     if (note_dep_seen(dept, x1)) {
 164       // look in this bucket for redundant assertions
 165       const int stride = 2;
 166       for (int i = deps->length(); (i -= stride) >= 0; ) {
 167         ciBaseObject* y1 = deps->at(i+1);
 168         if (x1 == y1) {  // same subject; check the context
 169           if (maybe_merge_ctxk(deps, i+0, x0->as_metadata()->as_klass())) {
 170             return;
 171           }
 172         }
 173       }
 174     }
 175   } else {

 176     if (note_dep_seen(dept, x0) && note_dep_seen(dept, x1)) {
 177       // look in this bucket for redundant assertions
 178       const int stride = 2;
 179       for (int i = deps->length(); (i -= stride) >= 0; ) {
 180         ciBaseObject* y0 = deps->at(i+0);
 181         ciBaseObject* y1 = deps->at(i+1);
 182         if (x0 == y0 && x1 == y1) {
 183           return;
 184         }
 185       }
 186     }
 187   }
 188 
 189   // append the assertion in the correct bucket:
 190   deps->append(x0);
 191   deps->append(x1);
 192 }
 193 
 194 void Dependencies::assert_common_3(DepType dept,
 195                                    ciKlass* ctxk, ciBaseObject* x, ciBaseObject* x2) {


 369   "abstract_with_no_concrete_subtype",
 370   "concrete_with_no_concrete_subtype",
 371   "unique_concrete_method",
 372   "abstract_with_exclusive_concrete_subtypes_2",
 373   "exclusive_concrete_methods_2",
 374   "no_finalizable_subclasses",
 375   "call_site_target_value"
 376 };
 377 
 378 int Dependencies::_dep_args[TYPE_LIMIT] = {
 379   -1,// end_marker
 380   1, // evol_method m
 381   1, // leaf_type ctxk
 382   2, // abstract_with_unique_concrete_subtype ctxk, k
 383   1, // abstract_with_no_concrete_subtype ctxk
 384   1, // concrete_with_no_concrete_subtype ctxk
 385   2, // unique_concrete_method ctxk, m
 386   3, // unique_concrete_subtypes_2 ctxk, k1, k2
 387   3, // unique_concrete_methods_2 ctxk, m1, m2
 388   1, // no_finalizable_subclasses ctxk
 389   2  // call_site_target_value call_site, method_handle
 390 };
 391 
 392 const char* Dependencies::dep_name(Dependencies::DepType dept) {
 393   if (!dept_in_mask(dept, all_types))  return "?bad-dep?";
 394   return _dep_name[dept];
 395 }
 396 
 397 int Dependencies::dep_args(Dependencies::DepType dept) {
 398   if (!dept_in_mask(dept, all_types))  return -1;
 399   return _dep_args[dept];
 400 }
 401 
 402 void Dependencies::check_valid_dependency_type(DepType dept) {
 403   guarantee(FIRST_TYPE <= dept && dept < TYPE_LIMIT, err_msg("invalid dependency type: %d", (int) dept));
 404 }
 405 
 406 // for the sake of the compiler log, print out current dependencies:
 407 void Dependencies::log_all_dependencies() {
 408   if (log() == NULL)  return;
 409   ResourceMark rm;


1495   return fm;
1496 }
1497 
1498 Klass* Dependencies::check_exclusive_concrete_methods(Klass* ctxk,
1499                                                         Method* m1,
1500                                                         Method* m2,
1501                                                         KlassDepChange* changes) {
1502   ClassHierarchyWalker wf(m1);
1503   wf.add_participant(m1->method_holder());
1504   wf.add_participant(m2->method_holder());
1505   return wf.find_witness_definer(ctxk, changes);
1506 }
1507 
1508 Klass* Dependencies::check_has_no_finalizable_subclasses(Klass* ctxk, KlassDepChange* changes) {
1509   Klass* search_at = ctxk;
1510   if (changes != NULL)
1511     search_at = changes->new_type(); // just look at the new bit
1512   return find_finalizable_subclass(search_at);
1513 }
1514 
1515 Klass* Dependencies::check_call_site_target_value(oop call_site, oop method_handle, CallSiteDepChange* changes) {
1516   assert(call_site->is_a(SystemDictionary::CallSite_klass()),     "sanity");
1517   assert(!oopDesc::is_null(call_site), "sanity");
1518   assert(!oopDesc::is_null(method_handle), "sanity");
1519 






1520   if (changes == NULL) {
1521     // Validate all CallSites
1522     if (java_lang_invoke_CallSite::target(call_site) != method_handle)
1523       return call_site->klass();  // assertion failed
1524   } else {
1525     // Validate the given CallSite
1526     if (call_site == changes->call_site() && java_lang_invoke_CallSite::target(call_site) != changes->method_handle()) {
1527       assert(method_handle != changes->method_handle(), "must be");
1528       return call_site->klass();  // assertion failed
1529     }
1530   }
1531   return NULL;  // assertion still valid
1532 }
1533 
1534 void Dependencies::DepStream::trace_and_log_witness(Klass* witness) {
1535   if (witness != NULL) {
1536     if (TraceDependencies) {
1537       print_dependency(witness, /*verbose=*/ true);
1538     }
1539     // The following is a no-op unless logging is enabled:


1574     break;
1575   case no_finalizable_subclasses:
1576     witness = check_has_no_finalizable_subclasses(context_type(), changes);
1577     break;
1578   default:
1579     witness = NULL;
1580     break;
1581   }
1582   trace_and_log_witness(witness);
1583   return witness;
1584 }
1585 
1586 
1587 Klass* Dependencies::DepStream::check_call_site_dependency(CallSiteDepChange* changes) {
1588   assert_locked_or_safepoint(Compile_lock);
1589   Dependencies::check_valid_dependency_type(type());
1590 
1591   Klass* witness = NULL;
1592   switch (type()) {
1593   case call_site_target_value:
1594     witness = check_call_site_target_value(argument_oop(0), argument_oop(1), changes);
1595     break;
1596   default:
1597     witness = NULL;
1598     break;
1599   }
1600   trace_and_log_witness(witness);
1601   return witness;
1602 }
1603 
1604 
1605 Klass* Dependencies::DepStream::spot_check_dependency_at(DepChange& changes) {
1606   // Handle klass dependency
1607   if (changes.is_klass_change() && changes.as_klass_change()->involves_context(context_type()))
1608     return check_klass_dependency(changes.as_klass_change());
1609 
1610   // Handle CallSite dependency
1611   if (changes.is_call_site_change())
1612     return check_call_site_dependency(changes.as_call_site_change());
1613 
1614   // irrelevant dependency; skip it


< prev index next >