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