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