src/share/vm/oops/methodData.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot Sdiff src/share/vm/oops

src/share/vm/oops/methodData.cpp

Print this page
rev 6953 : 8057038: Speculative traps not robust when compilation and class unloading are concurrent
Summary: speculative traps can be removed from MDO while being copied by compiler
Reviewed-by:


  69 
  70 void DataLayout::clean_weak_klass_links(BoolObjectClosure* cl) {
  71   ResourceMark m;
  72   data_in()->clean_weak_klass_links(cl);
  73 }
  74 
  75 
  76 // ==================================================================
  77 // ProfileData
  78 //
  79 // A ProfileData object is created to refer to a section of profiling
  80 // data in a structured way.
  81 
  82 // Constructor for invalid ProfileData.
  83 ProfileData::ProfileData() {
  84   _data = NULL;
  85 }
  86 
  87 char* ProfileData::print_data_on_helper(const MethodData* md) const {
  88   DataLayout* dp  = md->extra_data_base();
  89   DataLayout* end = md->extra_data_limit();
  90   stringStream ss;
  91   for (;; dp = MethodData::next_extra(dp)) {
  92     assert(dp < end, "moved past end of extra data");
  93     switch(dp->tag()) {
  94     case DataLayout::speculative_trap_data_tag:
  95       if (dp->bci() == bci()) {
  96         SpeculativeTrapData* data = new SpeculativeTrapData(dp);
  97         int trap = data->trap_state();
  98         char buf[100];
  99         ss.print("trap/");
 100         data->method()->print_short_name(&ss);
 101         ss.print("(%s) ", Deoptimization::format_trap_state(buf, sizeof(buf), trap));
 102       }
 103       break;
 104     case DataLayout::bit_data_tag:
 105       break;
 106     case DataLayout::no_tag:
 107     case DataLayout::arg_info_data_tag:
 108       return ss.as_string();
 109       break;


1031 }
1032 
1033 // Iteration over data.
1034 ProfileData* MethodData::next_data(ProfileData* current) const {
1035   int current_index = dp_to_di(current->dp());
1036   int next_index = current_index + current->size_in_bytes();
1037   ProfileData* next = data_at(next_index);
1038   return next;
1039 }
1040 
1041 // Give each of the data entries a chance to perform specific
1042 // data initialization.
1043 void MethodData::post_initialize(BytecodeStream* stream) {
1044   ResourceMark rm;
1045   ProfileData* data;
1046   for (data = first_data(); is_valid(data); data = next_data(data)) {
1047     stream->set_start(data->bci());
1048     stream->next();
1049     data->post_initialize(stream, this);
1050   }
1051   if (_parameters_type_data_di != -1) {
1052     parameters_type_data()->post_initialize(NULL, this);
1053   }
1054 }
1055 
1056 // Initialize the MethodData* corresponding to a given method.
1057 MethodData::MethodData(methodHandle method, int size, TRAPS)
1058   : _extra_data_lock(Monitor::leaf, "MDO extra data lock") {

1059   No_Safepoint_Verifier no_safepoint;  // init function atomic wrt GC
1060   ResourceMark rm;
1061   // Set the method back-pointer.
1062   _method = method();
1063 
1064   init();
1065   set_creation_mileage(mileage_of(method()));
1066 
1067   // Go through the bytecodes and allocate and initialize the
1068   // corresponding data cells.
1069   int data_size = 0;
1070   int empty_bc_count = 0;  // number of bytecodes lacking data
1071   _data[0] = 0;  // apparently not set below.
1072   BytecodeStream stream(method);
1073   Bytecodes::Code c;
1074   bool needs_speculative_traps = false;
1075   while ((c = stream.next()) >= 0) {
1076     int size_in_bytes = initialize_data(&stream, data_size);
1077     data_size += size_in_bytes;
1078     if (size_in_bytes == 0)  empty_bc_count += 1;


1094   DataLayout *dp = data_layout_at(data_size + extra_size);
1095 
1096   int arg_size = method->size_of_parameters();
1097   dp->initialize(DataLayout::arg_info_data_tag, 0, arg_size+1);
1098 
1099   int arg_data_size = DataLayout::compute_size_in_bytes(arg_size+1);
1100   object_size += extra_size + arg_data_size;
1101 
1102   int parms_cell = ParametersTypeData::compute_cell_count(method());
1103   // If we are profiling parameters, we reserver an area near the end
1104   // of the MDO after the slots for bytecodes (because there's no bci
1105   // for method entry so they don't fit with the framework for the
1106   // profiling of bytecodes). We store the offset within the MDO of
1107   // this area (or -1 if no parameter is profiled)
1108   if (parms_cell > 0) {
1109     object_size += DataLayout::compute_size_in_bytes(parms_cell);
1110     _parameters_type_data_di = data_size + extra_size + arg_data_size;
1111     DataLayout *dp = data_layout_at(data_size + extra_size + arg_data_size);
1112     dp->initialize(DataLayout::parameters_type_data_tag, 0, parms_cell);
1113   } else {
1114     _parameters_type_data_di = -1;
1115   }
1116 
1117   // Set an initial hint. Don't use set_hint_di() because
1118   // first_di() may be out of bounds if data_size is 0.
1119   // In that situation, _hint_di is never used, but at
1120   // least well-defined.
1121   _hint_di = first_di();
1122 
1123   post_initialize(&stream);
1124 
1125   set_size(object_size);
1126 }
1127 
1128 void MethodData::init() {
1129   _invocation_counter.init();
1130   _backedge_counter.init();
1131   _invocation_counter_start = 0;
1132   _backedge_counter_start = 0;
1133   _tenure_traps = 0;
1134   _num_loops = 0;


1219   return bci_to_extra_data(bci, NULL, false);
1220 }
1221 
1222 DataLayout* MethodData::next_extra(DataLayout* dp) {
1223   int nb_cells = 0;
1224   switch(dp->tag()) {
1225   case DataLayout::bit_data_tag:
1226   case DataLayout::no_tag:
1227     nb_cells = BitData::static_cell_count();
1228     break;
1229   case DataLayout::speculative_trap_data_tag:
1230     nb_cells = SpeculativeTrapData::static_cell_count();
1231     break;
1232   default:
1233     fatal(err_msg("unexpected tag %d", dp->tag()));
1234   }
1235   return (DataLayout*)((address)dp + DataLayout::compute_size_in_bytes(nb_cells));
1236 }
1237 
1238 ProfileData* MethodData::bci_to_extra_data_helper(int bci, Method* m, DataLayout*& dp, bool concurrent) {
1239   DataLayout* end = extra_data_limit();
1240 
1241   for (;; dp = next_extra(dp)) {
1242     assert(dp < end, "moved past end of extra data");
1243     // No need for "OrderAccess::load_acquire" ops,
1244     // since the data structure is monotonic.
1245     switch(dp->tag()) {
1246     case DataLayout::no_tag:
1247       return NULL;
1248     case DataLayout::arg_info_data_tag:
1249       dp = end;
1250       return NULL; // ArgInfoData is at the end of extra data section.
1251     case DataLayout::bit_data_tag:
1252       if (m == NULL && dp->bci() == bci) {
1253         return new BitData(dp);
1254       }
1255       break;
1256     case DataLayout::speculative_trap_data_tag:
1257       if (m != NULL) {
1258         SpeculativeTrapData* data = new SpeculativeTrapData(dp);
1259         // data->method() may be null in case of a concurrent


1268           }
1269         }
1270       }
1271       break;
1272     default:
1273       fatal(err_msg("unexpected tag %d", dp->tag()));
1274     }
1275   }
1276   return NULL;
1277 }
1278 
1279 
1280 // Translate a bci to its corresponding extra data, or NULL.
1281 ProfileData* MethodData::bci_to_extra_data(int bci, Method* m, bool create_if_missing) {
1282   // This code assumes an entry for a SpeculativeTrapData is 2 cells
1283   assert(2*DataLayout::compute_size_in_bytes(BitData::static_cell_count()) ==
1284          DataLayout::compute_size_in_bytes(SpeculativeTrapData::static_cell_count()),
1285          "code needs to be adjusted");
1286 
1287   DataLayout* dp  = extra_data_base();
1288   DataLayout* end = extra_data_limit();
1289 
1290   // Allocation in the extra data space has to be atomic because not
1291   // all entries have the same size and non atomic concurrent
1292   // allocation would result in a corrupted extra data space.
1293   ProfileData* result = bci_to_extra_data_helper(bci, m, dp, true);
1294   if (result != NULL) {
1295     return result;
1296   }
1297 
1298   if (create_if_missing && dp < end) {
1299     MutexLocker ml(&_extra_data_lock);
1300     // Check again now that we have the lock. Another thread may
1301     // have added extra data entries.
1302     ProfileData* result = bci_to_extra_data_helper(bci, m, dp, false);
1303     if (result != NULL || dp >= end) {
1304       return result;
1305     }
1306 
1307     assert(dp->tag() == DataLayout::no_tag || (dp->tag() == DataLayout::speculative_trap_data_tag && m != NULL), "should be free");
1308     assert(next_extra(dp)->tag() == DataLayout::no_tag || next_extra(dp)->tag() == DataLayout::arg_info_data_tag, "should be free or arg info");


1313     }
1314     DataLayout temp;
1315     temp.initialize(tag, bci, 0);
1316 
1317     dp->set_header(temp.header());
1318     assert(dp->tag() == tag, "sane");
1319     assert(dp->bci() == bci, "no concurrent allocation");
1320     if (tag == DataLayout::bit_data_tag) {
1321       return new BitData(dp);
1322     } else {
1323       SpeculativeTrapData* data = new SpeculativeTrapData(dp);
1324       data->set_method(m);
1325       return data;
1326     }
1327   }
1328   return NULL;
1329 }
1330 
1331 ArgInfoData *MethodData::arg_info() {
1332   DataLayout* dp    = extra_data_base();
1333   DataLayout* end   = extra_data_limit();
1334   for (; dp < end; dp = next_extra(dp)) {
1335     if (dp->tag() == DataLayout::arg_info_data_tag)
1336       return new ArgInfoData(dp);
1337   }
1338   return NULL;
1339 }
1340 
1341 // Printing
1342 
1343 void MethodData::print_on(outputStream* st) const {
1344   assert(is_methodData(), "should be method data");
1345   st->print("method data for ");
1346   method()->print_value_on(st);
1347   st->cr();
1348   print_data_on(st);
1349 }
1350 
1351 void MethodData::print_value_on(outputStream* st) const {
1352   assert(is_methodData(), "should be method data");
1353   st->print("method data for ");
1354   method()->print_value_on(st);
1355 }
1356 
1357 void MethodData::print_data_on(outputStream* st) const {
1358   ResourceMark rm;
1359   ProfileData* data = first_data();
1360   if (_parameters_type_data_di != -1) {
1361     parameters_type_data()->print_data_on(st);
1362   }
1363   for ( ; is_valid(data); data = next_data(data)) {
1364     st->print("%d", dp_to_di(data->dp()));
1365     st->fill_to(6);
1366     data->print_data_on(st, this);
1367   }
1368   st->print_cr("--- Extra data:");
1369   DataLayout* dp    = extra_data_base();
1370   DataLayout* end   = extra_data_limit();
1371   for (;; dp = next_extra(dp)) {
1372     assert(dp < end, "moved past end of extra data");
1373     // No need for "OrderAccess::load_acquire" ops,
1374     // since the data structure is monotonic.
1375     switch(dp->tag()) {
1376     case DataLayout::no_tag:
1377       continue;
1378     case DataLayout::bit_data_tag:
1379       data = new BitData(dp);
1380       break;
1381     case DataLayout::speculative_trap_data_tag:
1382       data = new SpeculativeTrapData(dp);
1383       break;
1384     case DataLayout::arg_info_data_tag:
1385       data = new ArgInfoData(dp);
1386       dp = end; // ArgInfoData is at the end of extra data section.
1387       break;
1388     default:
1389       fatal(err_msg("unexpected tag %d", dp->tag()));
1390     }


1548   CleanExtraDataKlassClosure(BoolObjectClosure* is_alive) : _is_alive(is_alive) {}
1549   bool is_live(Method* m) {
1550     return m->method_holder()->is_loader_alive(_is_alive);
1551   }
1552 };
1553 
1554 // Check for entries that reference a redefined method
1555 class CleanExtraDataMethodClosure : public CleanExtraDataClosure {
1556 public:
1557   CleanExtraDataMethodClosure() {}
1558   bool is_live(Method* m) {
1559     return !m->is_old() || m->on_stack();
1560   }
1561 };
1562 
1563 
1564 // Remove SpeculativeTrapData entries that reference an unloaded or
1565 // redefined method
1566 void MethodData::clean_extra_data(CleanExtraDataClosure* cl) {
1567   DataLayout* dp  = extra_data_base();
1568   DataLayout* end = extra_data_limit();
1569 
1570   int shift = 0;
1571   for (; dp < end; dp = next_extra(dp)) {
1572     switch(dp->tag()) {
1573     case DataLayout::speculative_trap_data_tag: {
1574       SpeculativeTrapData* data = new SpeculativeTrapData(dp);
1575       Method* m = data->method();
1576       assert(m != NULL, "should have a method");
1577       if (!cl->is_live(m)) {
1578         // "shift" accumulates the number of cells for dead
1579         // SpeculativeTrapData entries that have been seen so
1580         // far. Following entries must be shifted left by that many
1581         // cells to remove the dead SpeculativeTrapData entries.
1582         shift += (int)((intptr_t*)next_extra(dp) - (intptr_t*)dp);
1583       } else {
1584         // Shift this entry left if it follows dead
1585         // SpeculativeTrapData entries
1586         clean_extra_data_helper(dp, shift);
1587       }
1588       break;


1593       clean_extra_data_helper(dp, shift);
1594       continue;
1595     case DataLayout::no_tag:
1596     case DataLayout::arg_info_data_tag:
1597       // We are at end of the live trap entries. The previous "shift"
1598       // cells contain entries that are either dead or were shifted
1599       // left. They need to be reset to no_tag
1600       clean_extra_data_helper(dp, shift, true);
1601       return;
1602     default:
1603       fatal(err_msg("unexpected tag %d", dp->tag()));
1604     }
1605   }
1606 }
1607 
1608 // Verify there's no unloaded or redefined method referenced by a
1609 // SpeculativeTrapData entry
1610 void MethodData::verify_extra_data_clean(CleanExtraDataClosure* cl) {
1611 #ifdef ASSERT
1612   DataLayout* dp  = extra_data_base();
1613   DataLayout* end = extra_data_limit();
1614 
1615   for (; dp < end; dp = next_extra(dp)) {
1616     switch(dp->tag()) {
1617     case DataLayout::speculative_trap_data_tag: {
1618       SpeculativeTrapData* data = new SpeculativeTrapData(dp);
1619       Method* m = data->method();
1620       assert(m != NULL && cl->is_live(m), "Method should exist");
1621       break;
1622     }
1623     case DataLayout::bit_data_tag:
1624       continue;
1625     case DataLayout::no_tag:
1626     case DataLayout::arg_info_data_tag:
1627       return;
1628     default:
1629       fatal(err_msg("unexpected tag %d", dp->tag()));
1630     }
1631   }
1632 #endif
1633 }




  69 
  70 void DataLayout::clean_weak_klass_links(BoolObjectClosure* cl) {
  71   ResourceMark m;
  72   data_in()->clean_weak_klass_links(cl);
  73 }
  74 
  75 
  76 // ==================================================================
  77 // ProfileData
  78 //
  79 // A ProfileData object is created to refer to a section of profiling
  80 // data in a structured way.
  81 
  82 // Constructor for invalid ProfileData.
  83 ProfileData::ProfileData() {
  84   _data = NULL;
  85 }
  86 
  87 char* ProfileData::print_data_on_helper(const MethodData* md) const {
  88   DataLayout* dp  = md->extra_data_base();
  89   DataLayout* end = md->args_data_limit();
  90   stringStream ss;
  91   for (;; dp = MethodData::next_extra(dp)) {
  92     assert(dp < end, "moved past end of extra data");
  93     switch(dp->tag()) {
  94     case DataLayout::speculative_trap_data_tag:
  95       if (dp->bci() == bci()) {
  96         SpeculativeTrapData* data = new SpeculativeTrapData(dp);
  97         int trap = data->trap_state();
  98         char buf[100];
  99         ss.print("trap/");
 100         data->method()->print_short_name(&ss);
 101         ss.print("(%s) ", Deoptimization::format_trap_state(buf, sizeof(buf), trap));
 102       }
 103       break;
 104     case DataLayout::bit_data_tag:
 105       break;
 106     case DataLayout::no_tag:
 107     case DataLayout::arg_info_data_tag:
 108       return ss.as_string();
 109       break;


1031 }
1032 
1033 // Iteration over data.
1034 ProfileData* MethodData::next_data(ProfileData* current) const {
1035   int current_index = dp_to_di(current->dp());
1036   int next_index = current_index + current->size_in_bytes();
1037   ProfileData* next = data_at(next_index);
1038   return next;
1039 }
1040 
1041 // Give each of the data entries a chance to perform specific
1042 // data initialization.
1043 void MethodData::post_initialize(BytecodeStream* stream) {
1044   ResourceMark rm;
1045   ProfileData* data;
1046   for (data = first_data(); is_valid(data); data = next_data(data)) {
1047     stream->set_start(data->bci());
1048     stream->next();
1049     data->post_initialize(stream, this);
1050   }
1051   if (_parameters_type_data_di != no_parameters) {
1052     parameters_type_data()->post_initialize(NULL, this);
1053   }
1054 }
1055 
1056 // Initialize the MethodData* corresponding to a given method.
1057 MethodData::MethodData(methodHandle method, int size, TRAPS)
1058   : _extra_data_lock(Monitor::leaf, "MDO extra data lock"),
1059     _parameters_type_data_di(parameters_uninitialized) {
1060   No_Safepoint_Verifier no_safepoint;  // init function atomic wrt GC
1061   ResourceMark rm;
1062   // Set the method back-pointer.
1063   _method = method();
1064 
1065   init();
1066   set_creation_mileage(mileage_of(method()));
1067 
1068   // Go through the bytecodes and allocate and initialize the
1069   // corresponding data cells.
1070   int data_size = 0;
1071   int empty_bc_count = 0;  // number of bytecodes lacking data
1072   _data[0] = 0;  // apparently not set below.
1073   BytecodeStream stream(method);
1074   Bytecodes::Code c;
1075   bool needs_speculative_traps = false;
1076   while ((c = stream.next()) >= 0) {
1077     int size_in_bytes = initialize_data(&stream, data_size);
1078     data_size += size_in_bytes;
1079     if (size_in_bytes == 0)  empty_bc_count += 1;


1095   DataLayout *dp = data_layout_at(data_size + extra_size);
1096 
1097   int arg_size = method->size_of_parameters();
1098   dp->initialize(DataLayout::arg_info_data_tag, 0, arg_size+1);
1099 
1100   int arg_data_size = DataLayout::compute_size_in_bytes(arg_size+1);
1101   object_size += extra_size + arg_data_size;
1102 
1103   int parms_cell = ParametersTypeData::compute_cell_count(method());
1104   // If we are profiling parameters, we reserver an area near the end
1105   // of the MDO after the slots for bytecodes (because there's no bci
1106   // for method entry so they don't fit with the framework for the
1107   // profiling of bytecodes). We store the offset within the MDO of
1108   // this area (or -1 if no parameter is profiled)
1109   if (parms_cell > 0) {
1110     object_size += DataLayout::compute_size_in_bytes(parms_cell);
1111     _parameters_type_data_di = data_size + extra_size + arg_data_size;
1112     DataLayout *dp = data_layout_at(data_size + extra_size + arg_data_size);
1113     dp->initialize(DataLayout::parameters_type_data_tag, 0, parms_cell);
1114   } else {
1115     _parameters_type_data_di = no_parameters;
1116   }
1117 
1118   // Set an initial hint. Don't use set_hint_di() because
1119   // first_di() may be out of bounds if data_size is 0.
1120   // In that situation, _hint_di is never used, but at
1121   // least well-defined.
1122   _hint_di = first_di();
1123 
1124   post_initialize(&stream);
1125 
1126   set_size(object_size);
1127 }
1128 
1129 void MethodData::init() {
1130   _invocation_counter.init();
1131   _backedge_counter.init();
1132   _invocation_counter_start = 0;
1133   _backedge_counter_start = 0;
1134   _tenure_traps = 0;
1135   _num_loops = 0;


1220   return bci_to_extra_data(bci, NULL, false);
1221 }
1222 
1223 DataLayout* MethodData::next_extra(DataLayout* dp) {
1224   int nb_cells = 0;
1225   switch(dp->tag()) {
1226   case DataLayout::bit_data_tag:
1227   case DataLayout::no_tag:
1228     nb_cells = BitData::static_cell_count();
1229     break;
1230   case DataLayout::speculative_trap_data_tag:
1231     nb_cells = SpeculativeTrapData::static_cell_count();
1232     break;
1233   default:
1234     fatal(err_msg("unexpected tag %d", dp->tag()));
1235   }
1236   return (DataLayout*)((address)dp + DataLayout::compute_size_in_bytes(nb_cells));
1237 }
1238 
1239 ProfileData* MethodData::bci_to_extra_data_helper(int bci, Method* m, DataLayout*& dp, bool concurrent) {
1240   DataLayout* end = args_data_limit();
1241 
1242   for (;; dp = next_extra(dp)) {
1243     assert(dp < end, "moved past end of extra data");
1244     // No need for "OrderAccess::load_acquire" ops,
1245     // since the data structure is monotonic.
1246     switch(dp->tag()) {
1247     case DataLayout::no_tag:
1248       return NULL;
1249     case DataLayout::arg_info_data_tag:
1250       dp = end;
1251       return NULL; // ArgInfoData is at the end of extra data section.
1252     case DataLayout::bit_data_tag:
1253       if (m == NULL && dp->bci() == bci) {
1254         return new BitData(dp);
1255       }
1256       break;
1257     case DataLayout::speculative_trap_data_tag:
1258       if (m != NULL) {
1259         SpeculativeTrapData* data = new SpeculativeTrapData(dp);
1260         // data->method() may be null in case of a concurrent


1269           }
1270         }
1271       }
1272       break;
1273     default:
1274       fatal(err_msg("unexpected tag %d", dp->tag()));
1275     }
1276   }
1277   return NULL;
1278 }
1279 
1280 
1281 // Translate a bci to its corresponding extra data, or NULL.
1282 ProfileData* MethodData::bci_to_extra_data(int bci, Method* m, bool create_if_missing) {
1283   // This code assumes an entry for a SpeculativeTrapData is 2 cells
1284   assert(2*DataLayout::compute_size_in_bytes(BitData::static_cell_count()) ==
1285          DataLayout::compute_size_in_bytes(SpeculativeTrapData::static_cell_count()),
1286          "code needs to be adjusted");
1287 
1288   DataLayout* dp  = extra_data_base();
1289   DataLayout* end = args_data_limit();
1290 
1291   // Allocation in the extra data space has to be atomic because not
1292   // all entries have the same size and non atomic concurrent
1293   // allocation would result in a corrupted extra data space.
1294   ProfileData* result = bci_to_extra_data_helper(bci, m, dp, true);
1295   if (result != NULL) {
1296     return result;
1297   }
1298 
1299   if (create_if_missing && dp < end) {
1300     MutexLocker ml(&_extra_data_lock);
1301     // Check again now that we have the lock. Another thread may
1302     // have added extra data entries.
1303     ProfileData* result = bci_to_extra_data_helper(bci, m, dp, false);
1304     if (result != NULL || dp >= end) {
1305       return result;
1306     }
1307 
1308     assert(dp->tag() == DataLayout::no_tag || (dp->tag() == DataLayout::speculative_trap_data_tag && m != NULL), "should be free");
1309     assert(next_extra(dp)->tag() == DataLayout::no_tag || next_extra(dp)->tag() == DataLayout::arg_info_data_tag, "should be free or arg info");


1314     }
1315     DataLayout temp;
1316     temp.initialize(tag, bci, 0);
1317 
1318     dp->set_header(temp.header());
1319     assert(dp->tag() == tag, "sane");
1320     assert(dp->bci() == bci, "no concurrent allocation");
1321     if (tag == DataLayout::bit_data_tag) {
1322       return new BitData(dp);
1323     } else {
1324       SpeculativeTrapData* data = new SpeculativeTrapData(dp);
1325       data->set_method(m);
1326       return data;
1327     }
1328   }
1329   return NULL;
1330 }
1331 
1332 ArgInfoData *MethodData::arg_info() {
1333   DataLayout* dp    = extra_data_base();
1334   DataLayout* end   = args_data_limit();
1335   for (; dp < end; dp = next_extra(dp)) {
1336     if (dp->tag() == DataLayout::arg_info_data_tag)
1337       return new ArgInfoData(dp);
1338   }
1339   return NULL;
1340 }
1341 
1342 // Printing
1343 
1344 void MethodData::print_on(outputStream* st) const {
1345   assert(is_methodData(), "should be method data");
1346   st->print("method data for ");
1347   method()->print_value_on(st);
1348   st->cr();
1349   print_data_on(st);
1350 }
1351 
1352 void MethodData::print_value_on(outputStream* st) const {
1353   assert(is_methodData(), "should be method data");
1354   st->print("method data for ");
1355   method()->print_value_on(st);
1356 }
1357 
1358 void MethodData::print_data_on(outputStream* st) const {
1359   ResourceMark rm;
1360   ProfileData* data = first_data();
1361   if (_parameters_type_data_di != no_parameters) {
1362     parameters_type_data()->print_data_on(st);
1363   }
1364   for ( ; is_valid(data); data = next_data(data)) {
1365     st->print("%d", dp_to_di(data->dp()));
1366     st->fill_to(6);
1367     data->print_data_on(st, this);
1368   }
1369   st->print_cr("--- Extra data:");
1370   DataLayout* dp    = extra_data_base();
1371   DataLayout* end   = args_data_limit();
1372   for (;; dp = next_extra(dp)) {
1373     assert(dp < end, "moved past end of extra data");
1374     // No need for "OrderAccess::load_acquire" ops,
1375     // since the data structure is monotonic.
1376     switch(dp->tag()) {
1377     case DataLayout::no_tag:
1378       continue;
1379     case DataLayout::bit_data_tag:
1380       data = new BitData(dp);
1381       break;
1382     case DataLayout::speculative_trap_data_tag:
1383       data = new SpeculativeTrapData(dp);
1384       break;
1385     case DataLayout::arg_info_data_tag:
1386       data = new ArgInfoData(dp);
1387       dp = end; // ArgInfoData is at the end of extra data section.
1388       break;
1389     default:
1390       fatal(err_msg("unexpected tag %d", dp->tag()));
1391     }


1549   CleanExtraDataKlassClosure(BoolObjectClosure* is_alive) : _is_alive(is_alive) {}
1550   bool is_live(Method* m) {
1551     return m->method_holder()->is_loader_alive(_is_alive);
1552   }
1553 };
1554 
1555 // Check for entries that reference a redefined method
1556 class CleanExtraDataMethodClosure : public CleanExtraDataClosure {
1557 public:
1558   CleanExtraDataMethodClosure() {}
1559   bool is_live(Method* m) {
1560     return !m->is_old() || m->on_stack();
1561   }
1562 };
1563 
1564 
1565 // Remove SpeculativeTrapData entries that reference an unloaded or
1566 // redefined method
1567 void MethodData::clean_extra_data(CleanExtraDataClosure* cl) {
1568   DataLayout* dp  = extra_data_base();
1569   DataLayout* end = args_data_limit();
1570 
1571   int shift = 0;
1572   for (; dp < end; dp = next_extra(dp)) {
1573     switch(dp->tag()) {
1574     case DataLayout::speculative_trap_data_tag: {
1575       SpeculativeTrapData* data = new SpeculativeTrapData(dp);
1576       Method* m = data->method();
1577       assert(m != NULL, "should have a method");
1578       if (!cl->is_live(m)) {
1579         // "shift" accumulates the number of cells for dead
1580         // SpeculativeTrapData entries that have been seen so
1581         // far. Following entries must be shifted left by that many
1582         // cells to remove the dead SpeculativeTrapData entries.
1583         shift += (int)((intptr_t*)next_extra(dp) - (intptr_t*)dp);
1584       } else {
1585         // Shift this entry left if it follows dead
1586         // SpeculativeTrapData entries
1587         clean_extra_data_helper(dp, shift);
1588       }
1589       break;


1594       clean_extra_data_helper(dp, shift);
1595       continue;
1596     case DataLayout::no_tag:
1597     case DataLayout::arg_info_data_tag:
1598       // We are at end of the live trap entries. The previous "shift"
1599       // cells contain entries that are either dead or were shifted
1600       // left. They need to be reset to no_tag
1601       clean_extra_data_helper(dp, shift, true);
1602       return;
1603     default:
1604       fatal(err_msg("unexpected tag %d", dp->tag()));
1605     }
1606   }
1607 }
1608 
1609 // Verify there's no unloaded or redefined method referenced by a
1610 // SpeculativeTrapData entry
1611 void MethodData::verify_extra_data_clean(CleanExtraDataClosure* cl) {
1612 #ifdef ASSERT
1613   DataLayout* dp  = extra_data_base();
1614   DataLayout* end = args_data_limit();
1615 
1616   for (; dp < end; dp = next_extra(dp)) {
1617     switch(dp->tag()) {
1618     case DataLayout::speculative_trap_data_tag: {
1619       SpeculativeTrapData* data = new SpeculativeTrapData(dp);
1620       Method* m = data->method();
1621       assert(m != NULL && cl->is_live(m), "Method should exist");
1622       break;
1623     }
1624     case DataLayout::bit_data_tag:
1625       continue;
1626     case DataLayout::no_tag:
1627     case DataLayout::arg_info_data_tag:
1628       return;
1629     default:
1630       fatal(err_msg("unexpected tag %d", dp->tag()));
1631     }
1632   }
1633 #endif
1634 }


src/share/vm/oops/methodData.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File