1 /* 2 * Copyright (c) 1998, 2023, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #include "precompiled.hpp" 26 #include "cds/metaspaceShared.hpp" 27 #include "classfile/vmClasses.hpp" 28 #include "interpreter/bytecodes.hpp" 29 #include "interpreter/bytecodeStream.hpp" 30 #include "interpreter/interpreter.hpp" 31 #include "interpreter/rewriter.hpp" 32 #include "memory/metadataFactory.hpp" 33 #include "memory/resourceArea.hpp" 34 #include "oops/generateOopMap.hpp" 35 #include "oops/resolvedFieldEntry.hpp" 36 #include "oops/resolvedIndyEntry.hpp" 37 #include "prims/methodHandles.hpp" 38 #include "runtime/arguments.hpp" 39 #include "runtime/fieldDescriptor.inline.hpp" 40 #include "runtime/handles.inline.hpp" 41 #include "utilities/checkedCast.hpp" 42 43 // Computes a CPC map (new_index -> original_index) for constant pool entries 44 // that are referred to by the interpreter at runtime via the constant pool cache. 45 // Also computes a CP map (original_index -> new_index). 46 // Marks entries in CP which require additional processing. 47 void Rewriter::compute_index_maps() { 48 const int length = _pool->length(); 49 init_maps(length); 50 bool saw_mh_symbol = false; 51 for (int i = 0; i < length; i++) { 52 int tag = _pool->tag_at(i).value(); 53 switch (tag) { 54 case JVM_CONSTANT_Fieldref : 55 _cp_map.at_put(i, _field_entry_index); 56 _field_entry_index++; 57 _initialized_field_entries.push(ResolvedFieldEntry((u2)i)); 58 break; 59 case JVM_CONSTANT_InterfaceMethodref: // fall through 60 case JVM_CONSTANT_Methodref : 61 add_cp_cache_entry(i); 62 break; 63 case JVM_CONSTANT_Dynamic: 64 assert(_pool->has_dynamic_constant(), "constant pool's _has_dynamic_constant flag not set"); 65 add_resolved_references_entry(i); 66 break; 67 case JVM_CONSTANT_String : // fall through 68 case JVM_CONSTANT_MethodHandle : // fall through 69 case JVM_CONSTANT_MethodType : // fall through 70 add_resolved_references_entry(i); 71 break; 72 case JVM_CONSTANT_Utf8: 73 if (_pool->symbol_at(i) == vmSymbols::java_lang_invoke_MethodHandle() || 74 _pool->symbol_at(i) == vmSymbols::java_lang_invoke_VarHandle()) { 75 saw_mh_symbol = true; 76 } 77 break; 78 } 79 } 80 81 // Record limits of resolved reference map for constant pool cache indices 82 record_map_limits(); 83 84 guarantee((int) _cp_cache_map.length() - 1 <= (int) ((u2)-1), 85 "all cp cache indexes fit in a u2"); 86 87 if (saw_mh_symbol) { 88 _method_handle_invokers.at_grow(length, 0); 89 } 90 } 91 92 // Unrewrite the bytecodes if an error occurs. 93 void Rewriter::restore_bytecodes(Thread* thread) { 94 int len = _methods->length(); 95 bool invokespecial_error = false; 96 97 for (int i = len-1; i >= 0; i--) { 98 Method* method = _methods->at(i); 99 scan_method(thread, method, true, &invokespecial_error); 100 assert(!invokespecial_error, "reversing should not get an invokespecial error"); 101 } 102 } 103 104 // Creates a constant pool cache given a CPC map 105 void Rewriter::make_constant_pool_cache(TRAPS) { 106 ClassLoaderData* loader_data = _pool->pool_holder()->class_loader_data(); 107 ConstantPoolCache* cache = 108 ConstantPoolCache::allocate(loader_data, _cp_cache_map, 109 _invokedynamic_references_map, _initialized_indy_entries, _initialized_field_entries, CHECK); 110 111 // initialize object cache in constant pool 112 _pool->set_cache(cache); 113 cache->set_constant_pool(_pool()); 114 115 // _resolved_references is stored in pool->cache(), so need to be done after 116 // the above lines. 117 _pool->initialize_resolved_references(loader_data, _resolved_references_map, 118 _resolved_reference_limit, 119 THREAD); 120 #if INCLUDE_CDS 121 if (!HAS_PENDING_EXCEPTION && Arguments::is_dumping_archive()) { 122 if (_pool->pool_holder()->is_shared()) { 123 assert(DynamicDumpSharedSpaces, "must be"); 124 // We are linking a shared class from the base archive. This 125 // class won't be written into the dynamic archive, so there's no 126 // need to save its CpCaches. 127 } else { 128 cache->save_for_archive(THREAD); 129 } 130 } 131 #endif 132 133 // Clean up constant pool cache if initialize_resolved_references() failed. 134 if (HAS_PENDING_EXCEPTION) { 135 MetadataFactory::free_metadata(loader_data, cache); 136 _pool->set_cache(nullptr); // so the verifier isn't confused 137 } 138 } 139 140 141 142 // The new finalization semantics says that registration of 143 // finalizable objects must be performed on successful return from the 144 // Object.<init> constructor. We could implement this trivially if 145 // <init> were never rewritten but since JVMTI allows this to occur, a 146 // more complicated solution is required. A special return bytecode 147 // is used only by Object.<init> to signal the finalization 148 // registration point. Additionally local 0 must be preserved so it's 149 // available to pass to the registration function. For simplicity we 150 // require that local 0 is never overwritten so it's available as an 151 // argument for registration. 152 153 void Rewriter::rewrite_Object_init(const methodHandle& method, TRAPS) { 154 RawBytecodeStream bcs(method); 155 while (!bcs.is_last_bytecode()) { 156 Bytecodes::Code opcode = bcs.raw_next(); 157 switch (opcode) { 158 case Bytecodes::_return: *bcs.bcp() = Bytecodes::_return_register_finalizer; break; 159 160 case Bytecodes::_istore: 161 case Bytecodes::_lstore: 162 case Bytecodes::_fstore: 163 case Bytecodes::_dstore: 164 case Bytecodes::_astore: 165 if (bcs.get_index() != 0) continue; 166 167 // fall through 168 case Bytecodes::_istore_0: 169 case Bytecodes::_lstore_0: 170 case Bytecodes::_fstore_0: 171 case Bytecodes::_dstore_0: 172 case Bytecodes::_astore_0: 173 THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), 174 "can't overwrite local 0 in Object.<init>"); 175 break; 176 177 default: 178 break; 179 } 180 } 181 } 182 183 184 void Rewriter::rewrite_field_reference(address bcp, int offset, bool reverse) { 185 address p = bcp + offset; 186 if (!reverse) { 187 int cp_index = Bytes::get_Java_u2(p); 188 int field_entry_index = _cp_map.at(cp_index); 189 Bytes::put_native_u2(p, checked_cast<u2>(field_entry_index)); 190 } else { 191 int field_entry_index = Bytes::get_native_u2(p); 192 int pool_index = _initialized_field_entries.at(field_entry_index).constant_pool_index(); 193 Bytes::put_Java_u2(p, checked_cast<u2>(pool_index)); 194 } 195 } 196 197 // Rewrite a classfile-order CP index into a native-order CPC index. 198 void Rewriter::rewrite_member_reference(address bcp, int offset, bool reverse) { 199 address p = bcp + offset; 200 if (!reverse) { 201 int cp_index = Bytes::get_Java_u2(p); 202 int cache_index = cp_entry_to_cp_cache(cp_index); 203 Bytes::put_native_u2(p, (u2)cache_index); 204 if (!_method_handle_invokers.is_empty()) 205 maybe_rewrite_invokehandle(p - 1, cp_index, cache_index, reverse); 206 } else { 207 int cache_index = Bytes::get_native_u2(p); 208 int pool_index = cp_cache_entry_pool_index(cache_index); 209 Bytes::put_Java_u2(p, (u2)pool_index); 210 if (!_method_handle_invokers.is_empty()) 211 maybe_rewrite_invokehandle(p - 1, pool_index, cache_index, reverse); 212 } 213 } 214 215 // If the constant pool entry for invokespecial is InterfaceMethodref, 216 // we need to add a separate cpCache entry for its resolution, because it is 217 // different than the resolution for invokeinterface with InterfaceMethodref. 218 // These cannot share cpCache entries. 219 void Rewriter::rewrite_invokespecial(address bcp, int offset, bool reverse, bool* invokespecial_error) { 220 address p = bcp + offset; 221 if (!reverse) { 222 int cp_index = Bytes::get_Java_u2(p); 223 if (_pool->tag_at(cp_index).is_interface_method()) { 224 int cache_index = add_invokespecial_cp_cache_entry(cp_index); 225 if (cache_index != (int)(jushort) cache_index) { 226 *invokespecial_error = true; 227 } 228 Bytes::put_native_u2(p, (u2)cache_index); 229 } else { 230 rewrite_member_reference(bcp, offset, reverse); 231 } 232 } else { 233 rewrite_member_reference(bcp, offset, reverse); 234 } 235 } 236 237 238 // Adjust the invocation bytecode for a signature-polymorphic method (MethodHandle.invoke, etc.) 239 void Rewriter::maybe_rewrite_invokehandle(address opc, int cp_index, int cache_index, bool reverse) { 240 if (!reverse) { 241 if ((*opc) == (u1)Bytecodes::_invokevirtual || 242 // allow invokespecial as an alias, although it would be very odd: 243 (*opc) == (u1)Bytecodes::_invokespecial) { 244 assert(_pool->tag_at(cp_index).is_method(), "wrong index"); 245 // Determine whether this is a signature-polymorphic method. 246 if (cp_index >= _method_handle_invokers.length()) return; 247 int status = _method_handle_invokers.at(cp_index); 248 assert(status >= -1 && status <= 1, "oob tri-state"); 249 if (status == 0) { 250 if (_pool->uncached_klass_ref_at_noresolve(cp_index) == vmSymbols::java_lang_invoke_MethodHandle() && 251 MethodHandles::is_signature_polymorphic_name(vmClasses::MethodHandle_klass(), 252 _pool->uncached_name_ref_at(cp_index))) { 253 // we may need a resolved_refs entry for the appendix 254 add_invokedynamic_resolved_references_entry(cp_index, cache_index); 255 status = +1; 256 } else if (_pool->uncached_klass_ref_at_noresolve(cp_index) == vmSymbols::java_lang_invoke_VarHandle() && 257 MethodHandles::is_signature_polymorphic_name(vmClasses::VarHandle_klass(), 258 _pool->uncached_name_ref_at(cp_index))) { 259 // we may need a resolved_refs entry for the appendix 260 add_invokedynamic_resolved_references_entry(cp_index, cache_index); 261 status = +1; 262 } else { 263 status = -1; 264 } 265 _method_handle_invokers.at(cp_index) = status; 266 } 267 // We use a special internal bytecode for such methods (if non-static). 268 // The basic reason for this is that such methods need an extra "appendix" argument 269 // to transmit the call site's intended call type. 270 if (status > 0) { 271 (*opc) = (u1)Bytecodes::_invokehandle; 272 } 273 } 274 } else { 275 // Do not need to look at cp_index. 276 if ((*opc) == (u1)Bytecodes::_invokehandle) { 277 (*opc) = (u1)Bytecodes::_invokevirtual; 278 // Ignore corner case of original _invokespecial instruction. 279 // This is safe because (a) the signature polymorphic method was final, and 280 // (b) the implementation of MethodHandle will not call invokespecial on it. 281 } 282 } 283 } 284 285 286 void Rewriter::rewrite_invokedynamic(address bcp, int offset, bool reverse) { 287 address p = bcp + offset; 288 assert(p[-1] == Bytecodes::_invokedynamic, "not invokedynamic bytecode"); 289 if (!reverse) { 290 int cp_index = Bytes::get_Java_u2(p); 291 int resolved_index = add_invokedynamic_resolved_references_entry(cp_index, -1); // Indy no longer has a CPCE 292 // Replace the trailing four bytes with an index to the array of 293 // indy resolution information in the CPC. There is one entry for 294 // each bytecode, even if they make the same call. In other words, 295 // the CPC-to-CP relation is many-to-one for invokedynamic entries. 296 // This means we must use a larger index size than u2 to address 297 // all these entries. That is the main reason invokedynamic 298 // must have a five-byte instruction format. (Of course, other JVM 299 // implementations can use the bytes for other purposes.) 300 // Note: We use native_u4 format exclusively for 4-byte indexes. 301 Bytes::put_native_u4(p, ConstantPool::encode_invokedynamic_index(_invokedynamic_index)); 302 _invokedynamic_index++; 303 304 // Collect invokedynamic information before creating ResolvedInvokeDynamicInfo array 305 _initialized_indy_entries.push(ResolvedIndyEntry((u2)resolved_index, (u2)cp_index)); 306 } else { 307 // Should do nothing since we are not patching this bytecode 308 int cache_index = ConstantPool::decode_invokedynamic_index( 309 Bytes::get_native_u4(p)); 310 int cp_index = _initialized_indy_entries.at(cache_index).constant_pool_index(); 311 assert(_pool->tag_at(cp_index).is_invoke_dynamic(), "wrong index"); 312 // zero out 4 bytes 313 Bytes::put_Java_u4(p, 0); 314 Bytes::put_Java_u2(p, (u2)cp_index); 315 } 316 } 317 318 // Rewrite some ldc bytecodes to _fast_aldc 319 void Rewriter::maybe_rewrite_ldc(address bcp, int offset, bool is_wide, 320 bool reverse) { 321 if (!reverse) { 322 assert((*bcp) == (is_wide ? Bytecodes::_ldc_w : Bytecodes::_ldc), "not ldc bytecode"); 323 address p = bcp + offset; 324 int cp_index = is_wide ? Bytes::get_Java_u2(p) : (u1)(*p); 325 constantTag tag = _pool->tag_at(cp_index).value(); 326 327 if (tag.is_method_handle() || 328 tag.is_method_type() || 329 tag.is_string() || 330 (tag.is_dynamic_constant() && 331 // keep regular ldc interpreter logic for condy primitives 332 is_reference_type(Signature::basic_type(_pool->uncached_signature_ref_at(cp_index)))) 333 ) { 334 int ref_index = cp_entry_to_resolved_references(cp_index); 335 if (is_wide) { 336 (*bcp) = Bytecodes::_fast_aldc_w; 337 assert(ref_index == (u2)ref_index, "index overflow"); 338 Bytes::put_native_u2(p, (u2)ref_index); 339 } else { 340 (*bcp) = Bytecodes::_fast_aldc; 341 assert(ref_index == (u1)ref_index, "index overflow"); 342 (*p) = (u1)ref_index; 343 } 344 } 345 } else { 346 Bytecodes::Code rewritten_bc = 347 (is_wide ? Bytecodes::_fast_aldc_w : Bytecodes::_fast_aldc); 348 if ((*bcp) == rewritten_bc) { 349 address p = bcp + offset; 350 int ref_index = is_wide ? Bytes::get_native_u2(p) : (u1)(*p); 351 int pool_index = resolved_references_entry_to_pool_index(ref_index); 352 if (is_wide) { 353 (*bcp) = Bytecodes::_ldc_w; 354 assert(pool_index == (u2)pool_index, "index overflow"); 355 Bytes::put_Java_u2(p, (u2)pool_index); 356 } else { 357 (*bcp) = Bytecodes::_ldc; 358 assert(pool_index == (u1)pool_index, "index overflow"); 359 (*p) = (u1)pool_index; 360 } 361 } 362 } 363 } 364 365 366 // Rewrites a method given the index_map information 367 void Rewriter::scan_method(Thread* thread, Method* method, bool reverse, bool* invokespecial_error) { 368 369 int nof_jsrs = 0; 370 bool has_monitor_bytecodes = false; 371 Bytecodes::Code c; 372 373 // Bytecodes and their length 374 const address code_base = method->code_base(); 375 const int code_length = method->code_size(); 376 377 int bc_length; 378 for (int bci = 0; bci < code_length; bci += bc_length) { 379 address bcp = code_base + bci; 380 int prefix_length = 0; 381 c = (Bytecodes::Code)(*bcp); 382 383 // Since we have the code, see if we can get the length 384 // directly. Some more complicated bytecodes will report 385 // a length of zero, meaning we need to make another method 386 // call to calculate the length. 387 bc_length = Bytecodes::length_for(c); 388 if (bc_length == 0) { 389 bc_length = Bytecodes::length_at(method, bcp); 390 391 // length_at will put us at the bytecode after the one modified 392 // by 'wide'. We don't currently examine any of the bytecodes 393 // modified by wide, but in case we do in the future... 394 if (c == Bytecodes::_wide) { 395 prefix_length = 1; 396 c = (Bytecodes::Code)bcp[1]; 397 } 398 } 399 400 // Continuing with an invalid bytecode will fail in the loop below. 401 // So guarantee here. 402 guarantee(bc_length > 0, "Verifier should have caught this invalid bytecode"); 403 404 switch (c) { 405 case Bytecodes::_lookupswitch : { 406 #ifndef ZERO 407 Bytecode_lookupswitch bc(method, bcp); 408 (*bcp) = ( 409 bc.number_of_pairs() < BinarySwitchThreshold 410 ? Bytecodes::_fast_linearswitch 411 : Bytecodes::_fast_binaryswitch 412 ); 413 #endif 414 break; 415 } 416 case Bytecodes::_fast_linearswitch: 417 case Bytecodes::_fast_binaryswitch: { 418 #ifndef ZERO 419 (*bcp) = Bytecodes::_lookupswitch; 420 #endif 421 break; 422 } 423 424 case Bytecodes::_invokespecial : { 425 rewrite_invokespecial(bcp, prefix_length+1, reverse, invokespecial_error); 426 break; 427 } 428 429 case Bytecodes::_putstatic : 430 case Bytecodes::_putfield : { 431 if (!reverse) { 432 // Check if any final field of the class given as parameter is modified 433 // outside of initializer methods of the class. Fields that are modified 434 // are marked with a flag. For marked fields, the compilers do not perform 435 // constant folding (as the field can be changed after initialization). 436 // 437 // The check is performed after verification and only if verification has 438 // succeeded. Therefore, the class is guaranteed to be well-formed. 439 InstanceKlass* klass = method->method_holder(); 440 u2 bc_index = Bytes::get_Java_u2(bcp + prefix_length + 1); 441 constantPoolHandle cp(thread, method->constants()); 442 Symbol* ref_class_name = cp->klass_name_at(cp->uncached_klass_ref_index_at(bc_index)); 443 444 if (klass->name() == ref_class_name) { 445 Symbol* field_name = cp->uncached_name_ref_at(bc_index); 446 Symbol* field_sig = cp->uncached_signature_ref_at(bc_index); 447 448 fieldDescriptor fd; 449 if (klass->find_field(field_name, field_sig, &fd) != nullptr) { 450 if (fd.access_flags().is_final()) { 451 if (fd.access_flags().is_static()) { 452 if (!method->is_static_initializer()) { 453 fd.set_has_initialized_final_update(true); 454 } 455 } else { 456 if (!method->is_object_initializer()) { 457 fd.set_has_initialized_final_update(true); 458 } 459 } 460 } 461 } 462 } 463 } 464 } 465 // fall through 466 case Bytecodes::_getstatic : // fall through 467 case Bytecodes::_getfield : // fall through 468 rewrite_field_reference(bcp, prefix_length+1, reverse); 469 break; 470 case Bytecodes::_invokevirtual : // fall through 471 case Bytecodes::_invokestatic : 472 case Bytecodes::_invokeinterface: 473 case Bytecodes::_invokehandle : // if reverse=true 474 rewrite_member_reference(bcp, prefix_length+1, reverse); 475 break; 476 case Bytecodes::_invokedynamic: 477 rewrite_invokedynamic(bcp, prefix_length+1, reverse); 478 break; 479 case Bytecodes::_ldc: 480 case Bytecodes::_fast_aldc: // if reverse=true 481 maybe_rewrite_ldc(bcp, prefix_length+1, false, reverse); 482 break; 483 case Bytecodes::_ldc_w: 484 case Bytecodes::_fast_aldc_w: // if reverse=true 485 maybe_rewrite_ldc(bcp, prefix_length+1, true, reverse); 486 break; 487 case Bytecodes::_jsr : // fall through 488 case Bytecodes::_jsr_w : nof_jsrs++; break; 489 case Bytecodes::_monitorenter : // fall through 490 case Bytecodes::_monitorexit : has_monitor_bytecodes = true; break; 491 492 default: break; 493 } 494 } 495 496 // Update flags 497 if (has_monitor_bytecodes) { 498 method->set_has_monitor_bytecodes(); 499 } 500 501 // The present of a jsr bytecode implies that the method might potentially 502 // have to be rewritten, so we run the oopMapGenerator on the method 503 if (nof_jsrs > 0) { 504 method->set_has_jsrs(); 505 } 506 } 507 508 // After constant pool is created, revisit methods containing jsrs. 509 methodHandle Rewriter::rewrite_jsrs(const methodHandle& method, TRAPS) { 510 ResourceMark rm(THREAD); 511 ResolveOopMapConflicts romc(method); 512 methodHandle new_method = romc.do_potential_rewrite(CHECK_(methodHandle())); 513 // Update monitor matching info. 514 if (romc.monitor_safe()) { 515 new_method->set_guaranteed_monitor_matching(); 516 } 517 518 return new_method; 519 } 520 521 void Rewriter::rewrite_bytecodes(TRAPS) { 522 assert(_pool->cache() == nullptr, "constant pool cache must not be set yet"); 523 524 // determine index maps for Method* rewriting 525 compute_index_maps(); 526 527 if (RegisterFinalizersAtInit && _klass->name() == vmSymbols::java_lang_Object()) { 528 bool did_rewrite = false; 529 int i = _methods->length(); 530 while (i-- > 0) { 531 Method* method = _methods->at(i); 532 if (method->intrinsic_id() == vmIntrinsics::_Object_init) { 533 // rewrite the return bytecodes of Object.<init> to register the 534 // object for finalization if needed. 535 methodHandle m(THREAD, method); 536 rewrite_Object_init(m, CHECK); 537 did_rewrite = true; 538 break; 539 } 540 } 541 assert(did_rewrite, "must find Object::<init> to rewrite it"); 542 } 543 544 // rewrite methods, in two passes 545 int len = _methods->length(); 546 bool invokespecial_error = false; 547 548 for (int i = len-1; i >= 0; i--) { 549 Method* method = _methods->at(i); 550 scan_method(THREAD, method, false, &invokespecial_error); 551 if (invokespecial_error) { 552 // If you get an error here, there is no reversing bytecodes 553 // This exception is stored for this class and no further attempt is 554 // made at verifying or rewriting. 555 THROW_MSG(vmSymbols::java_lang_InternalError(), 556 "This classfile overflows invokespecial for interfaces " 557 "and cannot be loaded"); 558 return; 559 } 560 } 561 } 562 563 void Rewriter::rewrite(InstanceKlass* klass, TRAPS) { 564 #if INCLUDE_CDS 565 if (klass->is_shared()) { 566 assert(!klass->is_rewritten(), "rewritten shared classes cannot be rewritten again"); 567 } 568 #endif // INCLUDE_CDS 569 ResourceMark rm(THREAD); 570 constantPoolHandle cpool(THREAD, klass->constants()); 571 Rewriter rw(klass, cpool, klass->methods(), CHECK); 572 // (That's all, folks.) 573 } 574 575 Rewriter::Rewriter(InstanceKlass* klass, const constantPoolHandle& cpool, Array<Method*>* methods, TRAPS) 576 : _klass(klass), 577 _pool(cpool), 578 _methods(methods), 579 _cp_map(cpool->length()), 580 _cp_cache_map(cpool->length() / 2), 581 _reference_map(cpool->length()), 582 _resolved_references_map(cpool->length() / 2), 583 _invokedynamic_references_map(cpool->length() / 2), 584 _method_handle_invokers(cpool->length()), 585 _invokedynamic_index(0), 586 _field_entry_index(0) 587 { 588 589 // Rewrite bytecodes - exception here exits. 590 rewrite_bytecodes(CHECK); 591 592 // Stress restoring bytecodes 593 if (StressRewriter) { 594 restore_bytecodes(THREAD); 595 rewrite_bytecodes(CHECK); 596 } 597 598 // allocate constant pool cache, now that we've seen all the bytecodes 599 make_constant_pool_cache(THREAD); 600 601 // Restore bytecodes to their unrewritten state if there are exceptions 602 // rewriting bytecodes or allocating the cpCache 603 if (HAS_PENDING_EXCEPTION) { 604 restore_bytecodes(THREAD); 605 return; 606 } 607 608 // Relocate after everything, but still do this under the is_rewritten flag, 609 // so methods with jsrs in custom class lists in aren't attempted to be 610 // rewritten in the RO section of the shared archive. 611 // Relocated bytecodes don't have to be restored, only the cp cache entries 612 int len = _methods->length(); 613 for (int i = len-1; i >= 0; i--) { 614 methodHandle m(THREAD, _methods->at(i)); 615 616 if (m->has_jsrs()) { 617 m = rewrite_jsrs(m, THREAD); 618 // Restore bytecodes to their unrewritten state if there are exceptions 619 // relocating bytecodes. If some are relocated, that is ok because that 620 // doesn't affect constant pool to cpCache rewriting. 621 if (HAS_PENDING_EXCEPTION) { 622 restore_bytecodes(THREAD); 623 return; 624 } 625 // Method might have gotten rewritten. 626 methods->at_put(i, m()); 627 } 628 } 629 } --- EOF ---