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;
1052 }
1053
1054 // Iteration over data.
1055 ProfileData* MethodData::next_data(ProfileData* current) const {
1056 int current_index = dp_to_di(current->dp());
1057 int next_index = current_index + current->size_in_bytes();
1058 ProfileData* next = data_at(next_index);
1059 return next;
1060 }
1061
1062 // Give each of the data entries a chance to perform specific
1063 // data initialization.
1064 void MethodData::post_initialize(BytecodeStream* stream) {
1065 ResourceMark rm;
1066 ProfileData* data;
1067 for (data = first_data(); is_valid(data); data = next_data(data)) {
1068 stream->set_start(data->bci());
1069 stream->next();
1070 data->post_initialize(stream, this);
1071 }
1072 if (_parameters_type_data_di != -1) {
1073 parameters_type_data()->post_initialize(NULL, this);
1074 }
1075 }
1076
1077 // Initialize the MethodData* corresponding to a given method.
1078 MethodData::MethodData(methodHandle method, int size, TRAPS)
1079 : _extra_data_lock(Monitor::leaf, "MDO extra data lock") {
1080 No_Safepoint_Verifier no_safepoint; // init function atomic wrt GC
1081 ResourceMark rm;
1082 // Set the method back-pointer.
1083 _method = method();
1084
1085 init();
1086 set_creation_mileage(mileage_of(method()));
1087
1088 // Go through the bytecodes and allocate and initialize the
1089 // corresponding data cells.
1090 int data_size = 0;
1091 int empty_bc_count = 0; // number of bytecodes lacking data
1092 _data[0] = 0; // apparently not set below.
1093 BytecodeStream stream(method);
1094 Bytecodes::Code c;
1095 bool needs_speculative_traps = false;
1096 while ((c = stream.next()) >= 0) {
1097 int size_in_bytes = initialize_data(&stream, data_size);
1098 data_size += size_in_bytes;
1099 if (size_in_bytes == 0) empty_bc_count += 1;
1115 DataLayout *dp = data_layout_at(data_size + extra_size);
1116
1117 int arg_size = method->size_of_parameters();
1118 dp->initialize(DataLayout::arg_info_data_tag, 0, arg_size+1);
1119
1120 int arg_data_size = DataLayout::compute_size_in_bytes(arg_size+1);
1121 object_size += extra_size + arg_data_size;
1122
1123 int parms_cell = ParametersTypeData::compute_cell_count(method());
1124 // If we are profiling parameters, we reserver an area near the end
1125 // of the MDO after the slots for bytecodes (because there's no bci
1126 // for method entry so they don't fit with the framework for the
1127 // profiling of bytecodes). We store the offset within the MDO of
1128 // this area (or -1 if no parameter is profiled)
1129 if (parms_cell > 0) {
1130 object_size += DataLayout::compute_size_in_bytes(parms_cell);
1131 _parameters_type_data_di = data_size + extra_size + arg_data_size;
1132 DataLayout *dp = data_layout_at(data_size + extra_size + arg_data_size);
1133 dp->initialize(DataLayout::parameters_type_data_tag, 0, parms_cell);
1134 } else {
1135 _parameters_type_data_di = -1;
1136 }
1137
1138 // Set an initial hint. Don't use set_hint_di() because
1139 // first_di() may be out of bounds if data_size is 0.
1140 // In that situation, _hint_di is never used, but at
1141 // least well-defined.
1142 _hint_di = first_di();
1143
1144 post_initialize(&stream);
1145
1146 set_size(object_size);
1147 }
1148
1149 void MethodData::init() {
1150 _invocation_counter.init();
1151 _backedge_counter.init();
1152 _invocation_counter_start = 0;
1153 _backedge_counter_start = 0;
1154 _num_loops = 0;
1155 _num_blocks = 0;
1237 return bci_to_extra_data(bci, NULL, false);
1238 }
1239
1240 DataLayout* MethodData::next_extra(DataLayout* dp) {
1241 int nb_cells = 0;
1242 switch(dp->tag()) {
1243 case DataLayout::bit_data_tag:
1244 case DataLayout::no_tag:
1245 nb_cells = BitData::static_cell_count();
1246 break;
1247 case DataLayout::speculative_trap_data_tag:
1248 nb_cells = SpeculativeTrapData::static_cell_count();
1249 break;
1250 default:
1251 fatal(err_msg("unexpected tag %d", dp->tag()));
1252 }
1253 return (DataLayout*)((address)dp + DataLayout::compute_size_in_bytes(nb_cells));
1254 }
1255
1256 ProfileData* MethodData::bci_to_extra_data_helper(int bci, Method* m, DataLayout*& dp, bool concurrent) {
1257 DataLayout* end = extra_data_limit();
1258
1259 for (;; dp = next_extra(dp)) {
1260 assert(dp < end, "moved past end of extra data");
1261 // No need for "OrderAccess::load_acquire" ops,
1262 // since the data structure is monotonic.
1263 switch(dp->tag()) {
1264 case DataLayout::no_tag:
1265 return NULL;
1266 case DataLayout::arg_info_data_tag:
1267 dp = end;
1268 return NULL; // ArgInfoData is at the end of extra data section.
1269 case DataLayout::bit_data_tag:
1270 if (m == NULL && dp->bci() == bci) {
1271 return new BitData(dp);
1272 }
1273 break;
1274 case DataLayout::speculative_trap_data_tag:
1275 if (m != NULL) {
1276 SpeculativeTrapData* data = new SpeculativeTrapData(dp);
1277 // data->method() may be null in case of a concurrent
1286 }
1287 }
1288 }
1289 break;
1290 default:
1291 fatal(err_msg("unexpected tag %d", dp->tag()));
1292 }
1293 }
1294 return NULL;
1295 }
1296
1297
1298 // Translate a bci to its corresponding extra data, or NULL.
1299 ProfileData* MethodData::bci_to_extra_data(int bci, Method* m, bool create_if_missing) {
1300 // This code assumes an entry for a SpeculativeTrapData is 2 cells
1301 assert(2*DataLayout::compute_size_in_bytes(BitData::static_cell_count()) ==
1302 DataLayout::compute_size_in_bytes(SpeculativeTrapData::static_cell_count()),
1303 "code needs to be adjusted");
1304
1305 DataLayout* dp = extra_data_base();
1306 DataLayout* end = extra_data_limit();
1307
1308 // Allocation in the extra data space has to be atomic because not
1309 // all entries have the same size and non atomic concurrent
1310 // allocation would result in a corrupted extra data space.
1311 ProfileData* result = bci_to_extra_data_helper(bci, m, dp, true);
1312 if (result != NULL) {
1313 return result;
1314 }
1315
1316 if (create_if_missing && dp < end) {
1317 MutexLocker ml(&_extra_data_lock);
1318 // Check again now that we have the lock. Another thread may
1319 // have added extra data entries.
1320 ProfileData* result = bci_to_extra_data_helper(bci, m, dp, false);
1321 if (result != NULL || dp >= end) {
1322 return result;
1323 }
1324
1325 assert(dp->tag() == DataLayout::no_tag || (dp->tag() == DataLayout::speculative_trap_data_tag && m != NULL), "should be free");
1326 assert(next_extra(dp)->tag() == DataLayout::no_tag || next_extra(dp)->tag() == DataLayout::arg_info_data_tag, "should be free or arg info");
1331 }
1332 DataLayout temp;
1333 temp.initialize(tag, bci, 0);
1334
1335 dp->set_header(temp.header());
1336 assert(dp->tag() == tag, "sane");
1337 assert(dp->bci() == bci, "no concurrent allocation");
1338 if (tag == DataLayout::bit_data_tag) {
1339 return new BitData(dp);
1340 } else {
1341 SpeculativeTrapData* data = new SpeculativeTrapData(dp);
1342 data->set_method(m);
1343 return data;
1344 }
1345 }
1346 return NULL;
1347 }
1348
1349 ArgInfoData *MethodData::arg_info() {
1350 DataLayout* dp = extra_data_base();
1351 DataLayout* end = extra_data_limit();
1352 for (; dp < end; dp = next_extra(dp)) {
1353 if (dp->tag() == DataLayout::arg_info_data_tag)
1354 return new ArgInfoData(dp);
1355 }
1356 return NULL;
1357 }
1358
1359 // Printing
1360
1361 #ifndef PRODUCT
1362
1363 void MethodData::print_on(outputStream* st) const {
1364 assert(is_methodData(), "should be method data");
1365 st->print("method data for ");
1366 method()->print_value_on(st);
1367 st->cr();
1368 print_data_on(st);
1369 }
1370
1371 #endif //PRODUCT
1372
1373 void MethodData::print_value_on(outputStream* st) const {
1374 assert(is_methodData(), "should be method data");
1375 st->print("method data for ");
1376 method()->print_value_on(st);
1377 }
1378
1379 #ifndef PRODUCT
1380 void MethodData::print_data_on(outputStream* st) const {
1381 ResourceMark rm;
1382 ProfileData* data = first_data();
1383 if (_parameters_type_data_di != -1) {
1384 parameters_type_data()->print_data_on(st);
1385 }
1386 for ( ; is_valid(data); data = next_data(data)) {
1387 st->print("%d", dp_to_di(data->dp()));
1388 st->fill_to(6);
1389 data->print_data_on(st, this);
1390 }
1391 st->print_cr("--- Extra data:");
1392 DataLayout* dp = extra_data_base();
1393 DataLayout* end = extra_data_limit();
1394 for (;; dp = next_extra(dp)) {
1395 assert(dp < end, "moved past end of extra data");
1396 // No need for "OrderAccess::load_acquire" ops,
1397 // since the data structure is monotonic.
1398 switch(dp->tag()) {
1399 case DataLayout::no_tag:
1400 continue;
1401 case DataLayout::bit_data_tag:
1402 data = new BitData(dp);
1403 break;
1404 case DataLayout::speculative_trap_data_tag:
1405 data = new SpeculativeTrapData(dp);
1406 break;
1407 case DataLayout::arg_info_data_tag:
1408 data = new ArgInfoData(dp);
1409 dp = end; // ArgInfoData is at the end of extra data section.
1410 break;
1411 default:
1412 fatal(err_msg("unexpected tag %d", dp->tag()));
1413 }
1572 CleanExtraDataKlassClosure(BoolObjectClosure* is_alive) : _is_alive(is_alive) {}
1573 bool is_live(Method* m) {
1574 return m->method_holder()->is_loader_alive(_is_alive);
1575 }
1576 };
1577
1578 // Check for entries that reference a redefined method
1579 class CleanExtraDataMethodClosure : public CleanExtraDataClosure {
1580 public:
1581 CleanExtraDataMethodClosure() {}
1582 bool is_live(Method* m) {
1583 return m->on_stack();
1584 }
1585 };
1586
1587
1588 // Remove SpeculativeTrapData entries that reference an unloaded or
1589 // redefined method
1590 void MethodData::clean_extra_data(CleanExtraDataClosure* cl) {
1591 DataLayout* dp = extra_data_base();
1592 DataLayout* end = extra_data_limit();
1593
1594 int shift = 0;
1595 for (; dp < end; dp = next_extra(dp)) {
1596 switch(dp->tag()) {
1597 case DataLayout::speculative_trap_data_tag: {
1598 SpeculativeTrapData* data = new SpeculativeTrapData(dp);
1599 Method* m = data->method();
1600 assert(m != NULL, "should have a method");
1601 if (!cl->is_live(m)) {
1602 // "shift" accumulates the number of cells for dead
1603 // SpeculativeTrapData entries that have been seen so
1604 // far. Following entries must be shifted left by that many
1605 // cells to remove the dead SpeculativeTrapData entries.
1606 shift += (int)((intptr_t*)next_extra(dp) - (intptr_t*)dp);
1607 } else {
1608 // Shift this entry left if it follows dead
1609 // SpeculativeTrapData entries
1610 clean_extra_data_helper(dp, shift);
1611 }
1612 break;
1617 clean_extra_data_helper(dp, shift);
1618 continue;
1619 case DataLayout::no_tag:
1620 case DataLayout::arg_info_data_tag:
1621 // We are at end of the live trap entries. The previous "shift"
1622 // cells contain entries that are either dead or were shifted
1623 // left. They need to be reset to no_tag
1624 clean_extra_data_helper(dp, shift, true);
1625 return;
1626 default:
1627 fatal(err_msg("unexpected tag %d", dp->tag()));
1628 }
1629 }
1630 }
1631
1632 // Verify there's no unloaded or redefined method referenced by a
1633 // SpeculativeTrapData entry
1634 void MethodData::verify_extra_data_clean(CleanExtraDataClosure* cl) {
1635 #ifdef ASSERT
1636 DataLayout* dp = extra_data_base();
1637 DataLayout* end = extra_data_limit();
1638
1639 for (; dp < end; dp = next_extra(dp)) {
1640 switch(dp->tag()) {
1641 case DataLayout::speculative_trap_data_tag: {
1642 SpeculativeTrapData* data = new SpeculativeTrapData(dp);
1643 Method* m = data->method();
1644 assert(m != NULL && cl->is_live(m), "Method should exist");
1645 break;
1646 }
1647 case DataLayout::bit_data_tag:
1648 continue;
1649 case DataLayout::no_tag:
1650 case DataLayout::arg_info_data_tag:
1651 return;
1652 default:
1653 fatal(err_msg("unexpected tag %d", dp->tag()));
1654 }
1655 }
1656 #endif
1657 }
|
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;
1052 }
1053
1054 // Iteration over data.
1055 ProfileData* MethodData::next_data(ProfileData* current) const {
1056 int current_index = dp_to_di(current->dp());
1057 int next_index = current_index + current->size_in_bytes();
1058 ProfileData* next = data_at(next_index);
1059 return next;
1060 }
1061
1062 // Give each of the data entries a chance to perform specific
1063 // data initialization.
1064 void MethodData::post_initialize(BytecodeStream* stream) {
1065 ResourceMark rm;
1066 ProfileData* data;
1067 for (data = first_data(); is_valid(data); data = next_data(data)) {
1068 stream->set_start(data->bci());
1069 stream->next();
1070 data->post_initialize(stream, this);
1071 }
1072 if (_parameters_type_data_di != no_parameters) {
1073 parameters_type_data()->post_initialize(NULL, this);
1074 }
1075 }
1076
1077 // Initialize the MethodData* corresponding to a given method.
1078 MethodData::MethodData(methodHandle method, int size, TRAPS)
1079 : _extra_data_lock(Monitor::leaf, "MDO extra data lock"),
1080 _parameters_type_data_di(parameters_uninitialized) {
1081 No_Safepoint_Verifier no_safepoint; // init function atomic wrt GC
1082 ResourceMark rm;
1083 // Set the method back-pointer.
1084 _method = method();
1085
1086 init();
1087 set_creation_mileage(mileage_of(method()));
1088
1089 // Go through the bytecodes and allocate and initialize the
1090 // corresponding data cells.
1091 int data_size = 0;
1092 int empty_bc_count = 0; // number of bytecodes lacking data
1093 _data[0] = 0; // apparently not set below.
1094 BytecodeStream stream(method);
1095 Bytecodes::Code c;
1096 bool needs_speculative_traps = false;
1097 while ((c = stream.next()) >= 0) {
1098 int size_in_bytes = initialize_data(&stream, data_size);
1099 data_size += size_in_bytes;
1100 if (size_in_bytes == 0) empty_bc_count += 1;
1116 DataLayout *dp = data_layout_at(data_size + extra_size);
1117
1118 int arg_size = method->size_of_parameters();
1119 dp->initialize(DataLayout::arg_info_data_tag, 0, arg_size+1);
1120
1121 int arg_data_size = DataLayout::compute_size_in_bytes(arg_size+1);
1122 object_size += extra_size + arg_data_size;
1123
1124 int parms_cell = ParametersTypeData::compute_cell_count(method());
1125 // If we are profiling parameters, we reserver an area near the end
1126 // of the MDO after the slots for bytecodes (because there's no bci
1127 // for method entry so they don't fit with the framework for the
1128 // profiling of bytecodes). We store the offset within the MDO of
1129 // this area (or -1 if no parameter is profiled)
1130 if (parms_cell > 0) {
1131 object_size += DataLayout::compute_size_in_bytes(parms_cell);
1132 _parameters_type_data_di = data_size + extra_size + arg_data_size;
1133 DataLayout *dp = data_layout_at(data_size + extra_size + arg_data_size);
1134 dp->initialize(DataLayout::parameters_type_data_tag, 0, parms_cell);
1135 } else {
1136 _parameters_type_data_di = no_parameters;
1137 }
1138
1139 // Set an initial hint. Don't use set_hint_di() because
1140 // first_di() may be out of bounds if data_size is 0.
1141 // In that situation, _hint_di is never used, but at
1142 // least well-defined.
1143 _hint_di = first_di();
1144
1145 post_initialize(&stream);
1146
1147 set_size(object_size);
1148 }
1149
1150 void MethodData::init() {
1151 _invocation_counter.init();
1152 _backedge_counter.init();
1153 _invocation_counter_start = 0;
1154 _backedge_counter_start = 0;
1155 _num_loops = 0;
1156 _num_blocks = 0;
1238 return bci_to_extra_data(bci, NULL, false);
1239 }
1240
1241 DataLayout* MethodData::next_extra(DataLayout* dp) {
1242 int nb_cells = 0;
1243 switch(dp->tag()) {
1244 case DataLayout::bit_data_tag:
1245 case DataLayout::no_tag:
1246 nb_cells = BitData::static_cell_count();
1247 break;
1248 case DataLayout::speculative_trap_data_tag:
1249 nb_cells = SpeculativeTrapData::static_cell_count();
1250 break;
1251 default:
1252 fatal(err_msg("unexpected tag %d", dp->tag()));
1253 }
1254 return (DataLayout*)((address)dp + DataLayout::compute_size_in_bytes(nb_cells));
1255 }
1256
1257 ProfileData* MethodData::bci_to_extra_data_helper(int bci, Method* m, DataLayout*& dp, bool concurrent) {
1258 DataLayout* end = args_data_limit();
1259
1260 for (;; dp = next_extra(dp)) {
1261 assert(dp < end, "moved past end of extra data");
1262 // No need for "OrderAccess::load_acquire" ops,
1263 // since the data structure is monotonic.
1264 switch(dp->tag()) {
1265 case DataLayout::no_tag:
1266 return NULL;
1267 case DataLayout::arg_info_data_tag:
1268 dp = end;
1269 return NULL; // ArgInfoData is at the end of extra data section.
1270 case DataLayout::bit_data_tag:
1271 if (m == NULL && dp->bci() == bci) {
1272 return new BitData(dp);
1273 }
1274 break;
1275 case DataLayout::speculative_trap_data_tag:
1276 if (m != NULL) {
1277 SpeculativeTrapData* data = new SpeculativeTrapData(dp);
1278 // data->method() may be null in case of a concurrent
1287 }
1288 }
1289 }
1290 break;
1291 default:
1292 fatal(err_msg("unexpected tag %d", dp->tag()));
1293 }
1294 }
1295 return NULL;
1296 }
1297
1298
1299 // Translate a bci to its corresponding extra data, or NULL.
1300 ProfileData* MethodData::bci_to_extra_data(int bci, Method* m, bool create_if_missing) {
1301 // This code assumes an entry for a SpeculativeTrapData is 2 cells
1302 assert(2*DataLayout::compute_size_in_bytes(BitData::static_cell_count()) ==
1303 DataLayout::compute_size_in_bytes(SpeculativeTrapData::static_cell_count()),
1304 "code needs to be adjusted");
1305
1306 DataLayout* dp = extra_data_base();
1307 DataLayout* end = args_data_limit();
1308
1309 // Allocation in the extra data space has to be atomic because not
1310 // all entries have the same size and non atomic concurrent
1311 // allocation would result in a corrupted extra data space.
1312 ProfileData* result = bci_to_extra_data_helper(bci, m, dp, true);
1313 if (result != NULL) {
1314 return result;
1315 }
1316
1317 if (create_if_missing && dp < end) {
1318 MutexLocker ml(&_extra_data_lock);
1319 // Check again now that we have the lock. Another thread may
1320 // have added extra data entries.
1321 ProfileData* result = bci_to_extra_data_helper(bci, m, dp, false);
1322 if (result != NULL || dp >= end) {
1323 return result;
1324 }
1325
1326 assert(dp->tag() == DataLayout::no_tag || (dp->tag() == DataLayout::speculative_trap_data_tag && m != NULL), "should be free");
1327 assert(next_extra(dp)->tag() == DataLayout::no_tag || next_extra(dp)->tag() == DataLayout::arg_info_data_tag, "should be free or arg info");
1332 }
1333 DataLayout temp;
1334 temp.initialize(tag, bci, 0);
1335
1336 dp->set_header(temp.header());
1337 assert(dp->tag() == tag, "sane");
1338 assert(dp->bci() == bci, "no concurrent allocation");
1339 if (tag == DataLayout::bit_data_tag) {
1340 return new BitData(dp);
1341 } else {
1342 SpeculativeTrapData* data = new SpeculativeTrapData(dp);
1343 data->set_method(m);
1344 return data;
1345 }
1346 }
1347 return NULL;
1348 }
1349
1350 ArgInfoData *MethodData::arg_info() {
1351 DataLayout* dp = extra_data_base();
1352 DataLayout* end = args_data_limit();
1353 for (; dp < end; dp = next_extra(dp)) {
1354 if (dp->tag() == DataLayout::arg_info_data_tag)
1355 return new ArgInfoData(dp);
1356 }
1357 return NULL;
1358 }
1359
1360 // Printing
1361
1362 #ifndef PRODUCT
1363
1364 void MethodData::print_on(outputStream* st) const {
1365 assert(is_methodData(), "should be method data");
1366 st->print("method data for ");
1367 method()->print_value_on(st);
1368 st->cr();
1369 print_data_on(st);
1370 }
1371
1372 #endif //PRODUCT
1373
1374 void MethodData::print_value_on(outputStream* st) const {
1375 assert(is_methodData(), "should be method data");
1376 st->print("method data for ");
1377 method()->print_value_on(st);
1378 }
1379
1380 #ifndef PRODUCT
1381 void MethodData::print_data_on(outputStream* st) const {
1382 ResourceMark rm;
1383 ProfileData* data = first_data();
1384 if (_parameters_type_data_di != no_parameters) {
1385 parameters_type_data()->print_data_on(st);
1386 }
1387 for ( ; is_valid(data); data = next_data(data)) {
1388 st->print("%d", dp_to_di(data->dp()));
1389 st->fill_to(6);
1390 data->print_data_on(st, this);
1391 }
1392 st->print_cr("--- Extra data:");
1393 DataLayout* dp = extra_data_base();
1394 DataLayout* end = args_data_limit();
1395 for (;; dp = next_extra(dp)) {
1396 assert(dp < end, "moved past end of extra data");
1397 // No need for "OrderAccess::load_acquire" ops,
1398 // since the data structure is monotonic.
1399 switch(dp->tag()) {
1400 case DataLayout::no_tag:
1401 continue;
1402 case DataLayout::bit_data_tag:
1403 data = new BitData(dp);
1404 break;
1405 case DataLayout::speculative_trap_data_tag:
1406 data = new SpeculativeTrapData(dp);
1407 break;
1408 case DataLayout::arg_info_data_tag:
1409 data = new ArgInfoData(dp);
1410 dp = end; // ArgInfoData is at the end of extra data section.
1411 break;
1412 default:
1413 fatal(err_msg("unexpected tag %d", dp->tag()));
1414 }
1573 CleanExtraDataKlassClosure(BoolObjectClosure* is_alive) : _is_alive(is_alive) {}
1574 bool is_live(Method* m) {
1575 return m->method_holder()->is_loader_alive(_is_alive);
1576 }
1577 };
1578
1579 // Check for entries that reference a redefined method
1580 class CleanExtraDataMethodClosure : public CleanExtraDataClosure {
1581 public:
1582 CleanExtraDataMethodClosure() {}
1583 bool is_live(Method* m) {
1584 return m->on_stack();
1585 }
1586 };
1587
1588
1589 // Remove SpeculativeTrapData entries that reference an unloaded or
1590 // redefined method
1591 void MethodData::clean_extra_data(CleanExtraDataClosure* cl) {
1592 DataLayout* dp = extra_data_base();
1593 DataLayout* end = args_data_limit();
1594
1595 int shift = 0;
1596 for (; dp < end; dp = next_extra(dp)) {
1597 switch(dp->tag()) {
1598 case DataLayout::speculative_trap_data_tag: {
1599 SpeculativeTrapData* data = new SpeculativeTrapData(dp);
1600 Method* m = data->method();
1601 assert(m != NULL, "should have a method");
1602 if (!cl->is_live(m)) {
1603 // "shift" accumulates the number of cells for dead
1604 // SpeculativeTrapData entries that have been seen so
1605 // far. Following entries must be shifted left by that many
1606 // cells to remove the dead SpeculativeTrapData entries.
1607 shift += (int)((intptr_t*)next_extra(dp) - (intptr_t*)dp);
1608 } else {
1609 // Shift this entry left if it follows dead
1610 // SpeculativeTrapData entries
1611 clean_extra_data_helper(dp, shift);
1612 }
1613 break;
1618 clean_extra_data_helper(dp, shift);
1619 continue;
1620 case DataLayout::no_tag:
1621 case DataLayout::arg_info_data_tag:
1622 // We are at end of the live trap entries. The previous "shift"
1623 // cells contain entries that are either dead or were shifted
1624 // left. They need to be reset to no_tag
1625 clean_extra_data_helper(dp, shift, true);
1626 return;
1627 default:
1628 fatal(err_msg("unexpected tag %d", dp->tag()));
1629 }
1630 }
1631 }
1632
1633 // Verify there's no unloaded or redefined method referenced by a
1634 // SpeculativeTrapData entry
1635 void MethodData::verify_extra_data_clean(CleanExtraDataClosure* cl) {
1636 #ifdef ASSERT
1637 DataLayout* dp = extra_data_base();
1638 DataLayout* end = args_data_limit();
1639
1640 for (; dp < end; dp = next_extra(dp)) {
1641 switch(dp->tag()) {
1642 case DataLayout::speculative_trap_data_tag: {
1643 SpeculativeTrapData* data = new SpeculativeTrapData(dp);
1644 Method* m = data->method();
1645 assert(m != NULL && cl->is_live(m), "Method should exist");
1646 break;
1647 }
1648 case DataLayout::bit_data_tag:
1649 continue;
1650 case DataLayout::no_tag:
1651 case DataLayout::arg_info_data_tag:
1652 return;
1653 default:
1654 fatal(err_msg("unexpected tag %d", dp->tag()));
1655 }
1656 }
1657 #endif
1658 }
|