1.1 --- a/src/share/vm/oops/methodData.cpp Tue Mar 25 12:54:21 2014 -0700 1.2 +++ b/src/share/vm/oops/methodData.cpp Tue Mar 25 17:07:36 2014 -0700 1.3 @@ -24,6 +24,7 @@ 1.4 1.5 #include "precompiled.hpp" 1.6 #include "classfile/systemDictionary.hpp" 1.7 +#include "compiler/compilerOracle.hpp" 1.8 #include "interpreter/bytecode.hpp" 1.9 #include "interpreter/bytecodeStream.hpp" 1.10 #include "interpreter/linkResolver.hpp" 1.11 @@ -80,8 +81,42 @@ 1.12 _data = NULL; 1.13 } 1.14 1.15 +char* ProfileData::print_data_on_helper(const MethodData* md) const { 1.16 + DataLayout* dp = md->extra_data_base(); 1.17 + DataLayout* end = md->extra_data_limit(); 1.18 + stringStream ss; 1.19 + for (;; dp = MethodData::next_extra(dp)) { 1.20 + assert(dp < end, "moved past end of extra data"); 1.21 + switch(dp->tag()) { 1.22 + case DataLayout::speculative_trap_data_tag: 1.23 + if (dp->bci() == bci()) { 1.24 + SpeculativeTrapData* data = new SpeculativeTrapData(dp); 1.25 + int trap = data->trap_state(); 1.26 + char buf[100]; 1.27 + ss.print("trap/"); 1.28 + data->method()->print_short_name(&ss); 1.29 + ss.print("(%s) ", Deoptimization::format_trap_state(buf, sizeof(buf), trap)); 1.30 + } 1.31 + break; 1.32 + case DataLayout::bit_data_tag: 1.33 + break; 1.34 + case DataLayout::no_tag: 1.35 + case DataLayout::arg_info_data_tag: 1.36 + return ss.as_string(); 1.37 + break; 1.38 + default: 1.39 + fatal(err_msg("unexpected tag %d", dp->tag())); 1.40 + } 1.41 + } 1.42 + return NULL; 1.43 +} 1.44 + 1.45 +void ProfileData::print_data_on(outputStream* st, const MethodData* md) const { 1.46 + print_data_on(st, print_data_on_helper(md)); 1.47 +} 1.48 + 1.49 #ifndef PRODUCT 1.50 -void ProfileData::print_shared(outputStream* st, const char* name) const { 1.51 +void ProfileData::print_shared(outputStream* st, const char* name, const char* extra) const { 1.52 st->print("bci: %d", bci()); 1.53 st->fill_to(tab_width_one); 1.54 st->print("%s", name); 1.55 @@ -91,9 +126,13 @@ 1.56 char buf[100]; 1.57 st->print("trap(%s) ", Deoptimization::format_trap_state(buf, sizeof(buf), trap)); 1.58 } 1.59 + if (extra != NULL) { 1.60 + st->print(extra); 1.61 + } 1.62 int flags = data()->flags(); 1.63 - if (flags != 0) 1.64 + if (flags != 0) { 1.65 st->print("flags(%d) ", flags); 1.66 + } 1.67 } 1.68 1.69 void ProfileData::tab(outputStream* st, bool first) const { 1.70 @@ -109,8 +148,8 @@ 1.71 1.72 1.73 #ifndef PRODUCT 1.74 -void BitData::print_data_on(outputStream* st) const { 1.75 - print_shared(st, "BitData"); 1.76 +void BitData::print_data_on(outputStream* st, const char* extra) const { 1.77 + print_shared(st, "BitData", extra); 1.78 } 1.79 #endif // !PRODUCT 1.80 1.81 @@ -120,8 +159,8 @@ 1.82 // A CounterData corresponds to a simple counter. 1.83 1.84 #ifndef PRODUCT 1.85 -void CounterData::print_data_on(outputStream* st) const { 1.86 - print_shared(st, "CounterData"); 1.87 +void CounterData::print_data_on(outputStream* st, const char* extra) const { 1.88 + print_shared(st, "CounterData", extra); 1.89 st->print_cr("count(%u)", count()); 1.90 } 1.91 #endif // !PRODUCT 1.92 @@ -150,8 +189,8 @@ 1.93 } 1.94 1.95 #ifndef PRODUCT 1.96 -void JumpData::print_data_on(outputStream* st) const { 1.97 - print_shared(st, "JumpData"); 1.98 +void JumpData::print_data_on(outputStream* st, const char* extra) const { 1.99 + print_shared(st, "JumpData", extra); 1.100 st->print_cr("taken(%u) displacement(%d)", taken(), displacement()); 1.101 } 1.102 #endif // !PRODUCT 1.103 @@ -332,8 +371,8 @@ 1.104 st->cr(); 1.105 } 1.106 1.107 -void CallTypeData::print_data_on(outputStream* st) const { 1.108 - CounterData::print_data_on(st); 1.109 +void CallTypeData::print_data_on(outputStream* st, const char* extra) const { 1.110 + CounterData::print_data_on(st, extra); 1.111 if (has_arguments()) { 1.112 tab(st, true); 1.113 st->print("argument types"); 1.114 @@ -346,8 +385,8 @@ 1.115 } 1.116 } 1.117 1.118 -void VirtualCallTypeData::print_data_on(outputStream* st) const { 1.119 - VirtualCallData::print_data_on(st); 1.120 +void VirtualCallTypeData::print_data_on(outputStream* st, const char* extra) const { 1.121 + VirtualCallData::print_data_on(st, extra); 1.122 if (has_arguments()) { 1.123 tab(st, true); 1.124 st->print("argument types"); 1.125 @@ -400,12 +439,12 @@ 1.126 } 1.127 } 1.128 } 1.129 -void ReceiverTypeData::print_data_on(outputStream* st) const { 1.130 - print_shared(st, "ReceiverTypeData"); 1.131 +void ReceiverTypeData::print_data_on(outputStream* st, const char* extra) const { 1.132 + print_shared(st, "ReceiverTypeData", extra); 1.133 print_receiver_data_on(st); 1.134 } 1.135 -void VirtualCallData::print_data_on(outputStream* st) const { 1.136 - print_shared(st, "VirtualCallData"); 1.137 +void VirtualCallData::print_data_on(outputStream* st, const char* extra) const { 1.138 + print_shared(st, "VirtualCallData", extra); 1.139 print_receiver_data_on(st); 1.140 } 1.141 #endif // !PRODUCT 1.142 @@ -461,8 +500,8 @@ 1.143 #endif // CC_INTERP 1.144 1.145 #ifndef PRODUCT 1.146 -void RetData::print_data_on(outputStream* st) const { 1.147 - print_shared(st, "RetData"); 1.148 +void RetData::print_data_on(outputStream* st, const char* extra) const { 1.149 + print_shared(st, "RetData", extra); 1.150 uint row; 1.151 int entries = 0; 1.152 for (row = 0; row < row_limit(); row++) { 1.153 @@ -496,8 +535,8 @@ 1.154 } 1.155 1.156 #ifndef PRODUCT 1.157 -void BranchData::print_data_on(outputStream* st) const { 1.158 - print_shared(st, "BranchData"); 1.159 +void BranchData::print_data_on(outputStream* st, const char* extra) const { 1.160 + print_shared(st, "BranchData", extra); 1.161 st->print_cr("taken(%u) displacement(%d)", 1.162 taken(), displacement()); 1.163 tab(st); 1.164 @@ -570,8 +609,8 @@ 1.165 } 1.166 1.167 #ifndef PRODUCT 1.168 -void MultiBranchData::print_data_on(outputStream* st) const { 1.169 - print_shared(st, "MultiBranchData"); 1.170 +void MultiBranchData::print_data_on(outputStream* st, const char* extra) const { 1.171 + print_shared(st, "MultiBranchData", extra); 1.172 st->print_cr("default_count(%u) displacement(%d)", 1.173 default_count(), default_displacement()); 1.174 int cases = number_of_cases(); 1.175 @@ -584,8 +623,8 @@ 1.176 #endif 1.177 1.178 #ifndef PRODUCT 1.179 -void ArgInfoData::print_data_on(outputStream* st) const { 1.180 - print_shared(st, "ArgInfoData"); 1.181 +void ArgInfoData::print_data_on(outputStream* st, const char* extra) const { 1.182 + print_shared(st, "ArgInfoData", extra); 1.183 int nargs = number_of_args(); 1.184 for (int i = 0; i < nargs; i++) { 1.185 st->print(" 0x%x", arg_modified(i)); 1.186 @@ -616,10 +655,17 @@ 1.187 } 1.188 1.189 #ifndef PRODUCT 1.190 -void ParametersTypeData::print_data_on(outputStream* st) const { 1.191 - st->print("parameter types"); 1.192 +void ParametersTypeData::print_data_on(outputStream* st, const char* extra) const { 1.193 + st->print("parameter types", extra); 1.194 _parameters.print_data_on(st); 1.195 } 1.196 + 1.197 +void SpeculativeTrapData::print_data_on(outputStream* st, const char* extra) const { 1.198 + print_shared(st, "SpeculativeTrapData", extra); 1.199 + tab(st); 1.200 + method()->print_short_name(st); 1.201 + st->cr(); 1.202 +} 1.203 #endif 1.204 1.205 // ================================================================== 1.206 @@ -745,7 +791,27 @@ 1.207 return DataLayout::compute_size_in_bytes(cell_count); 1.208 } 1.209 1.210 -int MethodData::compute_extra_data_count(int data_size, int empty_bc_count) { 1.211 +bool MethodData::is_speculative_trap_bytecode(Bytecodes::Code code) { 1.212 + // Bytecodes for which we may use speculation 1.213 + switch (code) { 1.214 + case Bytecodes::_checkcast: 1.215 + case Bytecodes::_instanceof: 1.216 + case Bytecodes::_aastore: 1.217 + case Bytecodes::_invokevirtual: 1.218 + case Bytecodes::_invokeinterface: 1.219 + case Bytecodes::_if_acmpeq: 1.220 + case Bytecodes::_if_acmpne: 1.221 + case Bytecodes::_invokestatic: 1.222 +#ifdef COMPILER2 1.223 + return UseTypeSpeculation; 1.224 +#endif 1.225 + default: 1.226 + return false; 1.227 + } 1.228 + return false; 1.229 +} 1.230 + 1.231 +int MethodData::compute_extra_data_count(int data_size, int empty_bc_count, bool needs_speculative_traps) { 1.232 if (ProfileTraps) { 1.233 // Assume that up to 3% of BCIs with no MDP will need to allocate one. 1.234 int extra_data_count = (uint)(empty_bc_count * 3) / 128 + 1; 1.235 @@ -756,7 +822,18 @@ 1.236 extra_data_count = one_percent_of_data; 1.237 if (extra_data_count > empty_bc_count) 1.238 extra_data_count = empty_bc_count; // no need for more 1.239 - return extra_data_count; 1.240 + 1.241 + // Make sure we have a minimum number of extra data slots to 1.242 + // allocate SpeculativeTrapData entries. We would want to have one 1.243 + // entry per compilation that inlines this method and for which 1.244 + // some type speculation assumption fails. So the room we need for 1.245 + // the SpeculativeTrapData entries doesn't directly depend on the 1.246 + // size of the method. Because it's hard to estimate, we reserve 1.247 + // space for an arbitrary number of entries. 1.248 + int spec_data_count = (needs_speculative_traps ? SpecTrapLimitExtraEntries : 0) * 1.249 + (SpeculativeTrapData::static_cell_count() + DataLayout::header_size_in_cells()); 1.250 + 1.251 + return MAX2(extra_data_count, spec_data_count); 1.252 } else { 1.253 return 0; 1.254 } 1.255 @@ -769,15 +846,17 @@ 1.256 BytecodeStream stream(method); 1.257 Bytecodes::Code c; 1.258 int empty_bc_count = 0; // number of bytecodes lacking data 1.259 + bool needs_speculative_traps = false; 1.260 while ((c = stream.next()) >= 0) { 1.261 int size_in_bytes = compute_data_size(&stream); 1.262 data_size += size_in_bytes; 1.263 if (size_in_bytes == 0) empty_bc_count += 1; 1.264 + needs_speculative_traps = needs_speculative_traps || is_speculative_trap_bytecode(c); 1.265 } 1.266 int object_size = in_bytes(data_offset()) + data_size; 1.267 1.268 // Add some extra DataLayout cells (at least one) to track stray traps. 1.269 - int extra_data_count = compute_extra_data_count(data_size, empty_bc_count); 1.270 + int extra_data_count = compute_extra_data_count(data_size, empty_bc_count, needs_speculative_traps); 1.271 object_size += extra_data_count * DataLayout::compute_size_in_bytes(0); 1.272 1.273 // Add a cell to record information about modified arguments. 1.274 @@ -993,7 +1072,8 @@ 1.275 } 1.276 1.277 // Initialize the MethodData* corresponding to a given method. 1.278 -MethodData::MethodData(methodHandle method, int size, TRAPS) { 1.279 +MethodData::MethodData(methodHandle method, int size, TRAPS) 1.280 + : _extra_data_lock(Monitor::leaf, "MDO extra data lock") { 1.281 No_Safepoint_Verifier no_safepoint; // init function atomic wrt GC 1.282 ResourceMark rm; 1.283 // Set the method back-pointer. 1.284 @@ -1009,18 +1089,23 @@ 1.285 _data[0] = 0; // apparently not set below. 1.286 BytecodeStream stream(method); 1.287 Bytecodes::Code c; 1.288 + bool needs_speculative_traps = false; 1.289 while ((c = stream.next()) >= 0) { 1.290 int size_in_bytes = initialize_data(&stream, data_size); 1.291 data_size += size_in_bytes; 1.292 if (size_in_bytes == 0) empty_bc_count += 1; 1.293 + needs_speculative_traps = needs_speculative_traps || is_speculative_trap_bytecode(c); 1.294 } 1.295 _data_size = data_size; 1.296 int object_size = in_bytes(data_offset()) + data_size; 1.297 1.298 // Add some extra DataLayout cells (at least one) to track stray traps. 1.299 - int extra_data_count = compute_extra_data_count(data_size, empty_bc_count); 1.300 + int extra_data_count = compute_extra_data_count(data_size, empty_bc_count, needs_speculative_traps); 1.301 int extra_size = extra_data_count * DataLayout::compute_size_in_bytes(0); 1.302 1.303 + // Let's zero the space for the extra data 1.304 + Copy::zero_to_bytes(((address)_data) + data_size, extra_size); 1.305 + 1.306 // Add a cell to record information about modified arguments. 1.307 // Set up _args_modified array after traps cells so that 1.308 // the code for traps cells works. 1.309 @@ -1032,17 +1117,17 @@ 1.310 int arg_data_size = DataLayout::compute_size_in_bytes(arg_size+1); 1.311 object_size += extra_size + arg_data_size; 1.312 1.313 - int args_cell = ParametersTypeData::compute_cell_count(method()); 1.314 + int parms_cell = ParametersTypeData::compute_cell_count(method()); 1.315 // If we are profiling parameters, we reserver an area near the end 1.316 // of the MDO after the slots for bytecodes (because there's no bci 1.317 // for method entry so they don't fit with the framework for the 1.318 // profiling of bytecodes). We store the offset within the MDO of 1.319 // this area (or -1 if no parameter is profiled) 1.320 - if (args_cell > 0) { 1.321 - object_size += DataLayout::compute_size_in_bytes(args_cell); 1.322 + if (parms_cell > 0) { 1.323 + object_size += DataLayout::compute_size_in_bytes(parms_cell); 1.324 _parameters_type_data_di = data_size + extra_size + arg_data_size; 1.325 DataLayout *dp = data_layout_at(data_size + extra_size + arg_data_size); 1.326 - dp->initialize(DataLayout::parameters_type_data_tag, 0, args_cell); 1.327 + dp->initialize(DataLayout::parameters_type_data_tag, 0, parms_cell); 1.328 } else { 1.329 _parameters_type_data_di = -1; 1.330 } 1.331 @@ -1069,6 +1154,21 @@ 1.332 _highest_osr_comp_level = 0; 1.333 _would_profile = true; 1.334 1.335 +#if INCLUDE_RTM_OPT 1.336 + _rtm_state = NoRTM; // No RTM lock eliding by default 1.337 + if (UseRTMLocking && 1.338 + !CompilerOracle::has_option_string(_method, "NoRTMLockEliding")) { 1.339 + if (CompilerOracle::has_option_string(_method, "UseRTMLockEliding") || !UseRTMDeopt) { 1.340 + // Generate RTM lock eliding code without abort ratio calculation code. 1.341 + _rtm_state = UseRTM; 1.342 + } else if (UseRTMDeopt) { 1.343 + // Generate RTM lock eliding code and include abort ratio calculation 1.344 + // code if UseRTMDeopt is on. 1.345 + _rtm_state = ProfileRTM; 1.346 + } 1.347 + } 1.348 +#endif 1.349 + 1.350 // Initialize flags and trap history. 1.351 _nof_decompiles = 0; 1.352 _nof_overflow_recompiles = 0; 1.353 @@ -1133,39 +1233,114 @@ 1.354 break; 1.355 } 1.356 } 1.357 - return bci_to_extra_data(bci, false); 1.358 + return bci_to_extra_data(bci, NULL, false); 1.359 } 1.360 1.361 -// Translate a bci to its corresponding extra data, or NULL. 1.362 -ProfileData* MethodData::bci_to_extra_data(int bci, bool create_if_missing) { 1.363 - DataLayout* dp = extra_data_base(); 1.364 - DataLayout* end = extra_data_limit(); 1.365 - DataLayout* avail = NULL; 1.366 - for (; dp < end; dp = next_extra(dp)) { 1.367 +DataLayout* MethodData::next_extra(DataLayout* dp) { 1.368 + int nb_cells = 0; 1.369 + switch(dp->tag()) { 1.370 + case DataLayout::bit_data_tag: 1.371 + case DataLayout::no_tag: 1.372 + nb_cells = BitData::static_cell_count(); 1.373 + break; 1.374 + case DataLayout::speculative_trap_data_tag: 1.375 + nb_cells = SpeculativeTrapData::static_cell_count(); 1.376 + break; 1.377 + default: 1.378 + fatal(err_msg("unexpected tag %d", dp->tag())); 1.379 + } 1.380 + return (DataLayout*)((address)dp + DataLayout::compute_size_in_bytes(nb_cells)); 1.381 +} 1.382 + 1.383 +ProfileData* MethodData::bci_to_extra_data_helper(int bci, Method* m, DataLayout*& dp, bool concurrent) { 1.384 + DataLayout* end = extra_data_limit(); 1.385 + 1.386 + for (;; dp = next_extra(dp)) { 1.387 + assert(dp < end, "moved past end of extra data"); 1.388 // No need for "OrderAccess::load_acquire" ops, 1.389 // since the data structure is monotonic. 1.390 - if (dp->tag() == DataLayout::no_tag) break; 1.391 - if (dp->tag() == DataLayout::arg_info_data_tag) { 1.392 - dp = end; // ArgInfoData is at the end of extra data section. 1.393 + switch(dp->tag()) { 1.394 + case DataLayout::no_tag: 1.395 + return NULL; 1.396 + case DataLayout::arg_info_data_tag: 1.397 + dp = end; 1.398 + return NULL; // ArgInfoData is at the end of extra data section. 1.399 + case DataLayout::bit_data_tag: 1.400 + if (m == NULL && dp->bci() == bci) { 1.401 + return new BitData(dp); 1.402 + } 1.403 break; 1.404 - } 1.405 - if (dp->bci() == bci) { 1.406 - assert(dp->tag() == DataLayout::bit_data_tag, "sane"); 1.407 - return new BitData(dp); 1.408 + case DataLayout::speculative_trap_data_tag: 1.409 + if (m != NULL) { 1.410 + SpeculativeTrapData* data = new SpeculativeTrapData(dp); 1.411 + // data->method() may be null in case of a concurrent 1.412 + // allocation. Maybe it's for the same method. Try to use that 1.413 + // entry in that case. 1.414 + if (dp->bci() == bci) { 1.415 + if (data->method() == NULL) { 1.416 + assert(concurrent, "impossible because no concurrent allocation"); 1.417 + return NULL; 1.418 + } else if (data->method() == m) { 1.419 + return data; 1.420 + } 1.421 + } 1.422 + } 1.423 + break; 1.424 + default: 1.425 + fatal(err_msg("unexpected tag %d", dp->tag())); 1.426 } 1.427 } 1.428 + return NULL; 1.429 +} 1.430 + 1.431 + 1.432 +// Translate a bci to its corresponding extra data, or NULL. 1.433 +ProfileData* MethodData::bci_to_extra_data(int bci, Method* m, bool create_if_missing) { 1.434 + // This code assumes an entry for a SpeculativeTrapData is 2 cells 1.435 + assert(2*DataLayout::compute_size_in_bytes(BitData::static_cell_count()) == 1.436 + DataLayout::compute_size_in_bytes(SpeculativeTrapData::static_cell_count()), 1.437 + "code needs to be adjusted"); 1.438 + 1.439 + DataLayout* dp = extra_data_base(); 1.440 + DataLayout* end = extra_data_limit(); 1.441 + 1.442 + // Allocation in the extra data space has to be atomic because not 1.443 + // all entries have the same size and non atomic concurrent 1.444 + // allocation would result in a corrupted extra data space. 1.445 + ProfileData* result = bci_to_extra_data_helper(bci, m, dp, true); 1.446 + if (result != NULL) { 1.447 + return result; 1.448 + } 1.449 + 1.450 if (create_if_missing && dp < end) { 1.451 - // Allocate this one. There is no mutual exclusion, 1.452 - // so two threads could allocate different BCIs to the 1.453 - // same data layout. This means these extra data 1.454 - // records, like most other MDO contents, must not be 1.455 - // trusted too much. 1.456 + MutexLocker ml(&_extra_data_lock); 1.457 + // Check again now that we have the lock. Another thread may 1.458 + // have added extra data entries. 1.459 + ProfileData* result = bci_to_extra_data_helper(bci, m, dp, false); 1.460 + if (result != NULL || dp >= end) { 1.461 + return result; 1.462 + } 1.463 + 1.464 + assert(dp->tag() == DataLayout::no_tag || (dp->tag() == DataLayout::speculative_trap_data_tag && m != NULL), "should be free"); 1.465 + assert(next_extra(dp)->tag() == DataLayout::no_tag || next_extra(dp)->tag() == DataLayout::arg_info_data_tag, "should be free or arg info"); 1.466 + u1 tag = m == NULL ? DataLayout::bit_data_tag : DataLayout::speculative_trap_data_tag; 1.467 + // SpeculativeTrapData is 2 slots. Make sure we have room. 1.468 + if (m != NULL && next_extra(dp)->tag() != DataLayout::no_tag) { 1.469 + return NULL; 1.470 + } 1.471 DataLayout temp; 1.472 - temp.initialize(DataLayout::bit_data_tag, bci, 0); 1.473 - dp->release_set_header(temp.header()); 1.474 - assert(dp->tag() == DataLayout::bit_data_tag, "sane"); 1.475 - //NO: assert(dp->bci() == bci, "no concurrent allocation"); 1.476 - return new BitData(dp); 1.477 + temp.initialize(tag, bci, 0); 1.478 + 1.479 + dp->set_header(temp.header()); 1.480 + assert(dp->tag() == tag, "sane"); 1.481 + assert(dp->bci() == bci, "no concurrent allocation"); 1.482 + if (tag == DataLayout::bit_data_tag) { 1.483 + return new BitData(dp); 1.484 + } else { 1.485 + SpeculativeTrapData* data = new SpeculativeTrapData(dp); 1.486 + data->set_method(m); 1.487 + return data; 1.488 + } 1.489 } 1.490 return NULL; 1.491 } 1.492 @@ -1210,25 +1385,35 @@ 1.493 for ( ; is_valid(data); data = next_data(data)) { 1.494 st->print("%d", dp_to_di(data->dp())); 1.495 st->fill_to(6); 1.496 - data->print_data_on(st); 1.497 + data->print_data_on(st, this); 1.498 } 1.499 st->print_cr("--- Extra data:"); 1.500 DataLayout* dp = extra_data_base(); 1.501 DataLayout* end = extra_data_limit(); 1.502 - for (; dp < end; dp = next_extra(dp)) { 1.503 + for (;; dp = next_extra(dp)) { 1.504 + assert(dp < end, "moved past end of extra data"); 1.505 // No need for "OrderAccess::load_acquire" ops, 1.506 // since the data structure is monotonic. 1.507 - if (dp->tag() == DataLayout::no_tag) continue; 1.508 - if (dp->tag() == DataLayout::bit_data_tag) { 1.509 + switch(dp->tag()) { 1.510 + case DataLayout::no_tag: 1.511 + continue; 1.512 + case DataLayout::bit_data_tag: 1.513 data = new BitData(dp); 1.514 - } else { 1.515 - assert(dp->tag() == DataLayout::arg_info_data_tag, "must be BitData or ArgInfo"); 1.516 + break; 1.517 + case DataLayout::speculative_trap_data_tag: 1.518 + data = new SpeculativeTrapData(dp); 1.519 + break; 1.520 + case DataLayout::arg_info_data_tag: 1.521 data = new ArgInfoData(dp); 1.522 dp = end; // ArgInfoData is at the end of extra data section. 1.523 + break; 1.524 + default: 1.525 + fatal(err_msg("unexpected tag %d", dp->tag())); 1.526 } 1.527 st->print("%d", dp_to_di(data->dp())); 1.528 st->fill_to(6); 1.529 data->print_data_on(st); 1.530 + if (dp >= end) return; 1.531 } 1.532 } 1.533 #endif 1.534 @@ -1351,3 +1536,110 @@ 1.535 assert(profile_parameters_jsr292_only(), "inconsistent"); 1.536 return m->is_compiled_lambda_form(); 1.537 } 1.538 + 1.539 +void MethodData::clean_extra_data_helper(DataLayout* dp, int shift, bool reset) { 1.540 + if (shift == 0) { 1.541 + return; 1.542 + } 1.543 + if (!reset) { 1.544 + // Move all cells of trap entry at dp left by "shift" cells 1.545 + intptr_t* start = (intptr_t*)dp; 1.546 + intptr_t* end = (intptr_t*)next_extra(dp); 1.547 + for (intptr_t* ptr = start; ptr < end; ptr++) { 1.548 + *(ptr-shift) = *ptr; 1.549 + } 1.550 + } else { 1.551 + // Reset "shift" cells stopping at dp 1.552 + intptr_t* start = ((intptr_t*)dp) - shift; 1.553 + intptr_t* end = (intptr_t*)dp; 1.554 + for (intptr_t* ptr = start; ptr < end; ptr++) { 1.555 + *ptr = 0; 1.556 + } 1.557 + } 1.558 +} 1.559 + 1.560 +// Remove SpeculativeTrapData entries that reference an unloaded 1.561 +// method 1.562 +void MethodData::clean_extra_data(BoolObjectClosure* is_alive) { 1.563 + DataLayout* dp = extra_data_base(); 1.564 + DataLayout* end = extra_data_limit(); 1.565 + 1.566 + int shift = 0; 1.567 + for (; dp < end; dp = next_extra(dp)) { 1.568 + switch(dp->tag()) { 1.569 + case DataLayout::speculative_trap_data_tag: { 1.570 + SpeculativeTrapData* data = new SpeculativeTrapData(dp); 1.571 + Method* m = data->method(); 1.572 + assert(m != NULL, "should have a method"); 1.573 + if (!m->method_holder()->is_loader_alive(is_alive)) { 1.574 + // "shift" accumulates the number of cells for dead 1.575 + // SpeculativeTrapData entries that have been seen so 1.576 + // far. Following entries must be shifted left by that many 1.577 + // cells to remove the dead SpeculativeTrapData entries. 1.578 + shift += (int)((intptr_t*)next_extra(dp) - (intptr_t*)dp); 1.579 + } else { 1.580 + // Shift this entry left if it follows dead 1.581 + // SpeculativeTrapData entries 1.582 + clean_extra_data_helper(dp, shift); 1.583 + } 1.584 + break; 1.585 + } 1.586 + case DataLayout::bit_data_tag: 1.587 + // Shift this entry left if it follows dead SpeculativeTrapData 1.588 + // entries 1.589 + clean_extra_data_helper(dp, shift); 1.590 + continue; 1.591 + case DataLayout::no_tag: 1.592 + case DataLayout::arg_info_data_tag: 1.593 + // We are at end of the live trap entries. The previous "shift" 1.594 + // cells contain entries that are either dead or were shifted 1.595 + // left. They need to be reset to no_tag 1.596 + clean_extra_data_helper(dp, shift, true); 1.597 + return; 1.598 + default: 1.599 + fatal(err_msg("unexpected tag %d", dp->tag())); 1.600 + } 1.601 + } 1.602 +} 1.603 + 1.604 +// Verify there's no unloaded method referenced by a 1.605 +// SpeculativeTrapData entry 1.606 +void MethodData::verify_extra_data_clean(BoolObjectClosure* is_alive) { 1.607 +#ifdef ASSERT 1.608 + DataLayout* dp = extra_data_base(); 1.609 + DataLayout* end = extra_data_limit(); 1.610 + 1.611 + for (; dp < end; dp = next_extra(dp)) { 1.612 + switch(dp->tag()) { 1.613 + case DataLayout::speculative_trap_data_tag: { 1.614 + SpeculativeTrapData* data = new SpeculativeTrapData(dp); 1.615 + Method* m = data->method(); 1.616 + assert(m != NULL && m->method_holder()->is_loader_alive(is_alive), "Method should exist"); 1.617 + break; 1.618 + } 1.619 + case DataLayout::bit_data_tag: 1.620 + continue; 1.621 + case DataLayout::no_tag: 1.622 + case DataLayout::arg_info_data_tag: 1.623 + return; 1.624 + default: 1.625 + fatal(err_msg("unexpected tag %d", dp->tag())); 1.626 + } 1.627 + } 1.628 +#endif 1.629 +} 1.630 + 1.631 +void MethodData::clean_method_data(BoolObjectClosure* is_alive) { 1.632 + for (ProfileData* data = first_data(); 1.633 + is_valid(data); 1.634 + data = next_data(data)) { 1.635 + data->clean_weak_klass_links(is_alive); 1.636 + } 1.637 + ParametersTypeData* parameters = parameters_type_data(); 1.638 + if (parameters != NULL) { 1.639 + parameters->clean_weak_klass_links(is_alive); 1.640 + } 1.641 + 1.642 + clean_extra_data(is_alive); 1.643 + verify_extra_data_clean(is_alive); 1.644 +}