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 saw_mh_symbol = true;
59 break;
60 }
61 }
62
63 // Record limits of resolved reference map for constant pool cache indices
64 record_map_limits();
65
66 guarantee((int)_cp_cache_map.length()-1 <= (int)((u2)-1),
67 "all cp cache indexes fit in a u2");
68
69 if (saw_mh_symbol)
70 _method_handle_invokers.initialize(length, (int)0);
71 }
72
73 // Unrewrite the bytecodes if an error occurs.
74 void Rewriter::restore_bytecodes() {
75 int len = _methods->length();
76 bool invokespecial_error = false;
77
177 rewrite_member_reference(bcp, offset, reverse);
178 }
179 } else {
180 rewrite_member_reference(bcp, offset, reverse);
181 }
182 }
183
184
185 // Adjust the invocation bytecode for a signature-polymorphic method (MethodHandle.invoke, etc.)
186 void Rewriter::maybe_rewrite_invokehandle(address opc, int cp_index, int cache_index, bool reverse) {
187 if (!reverse) {
188 if ((*opc) == (u1)Bytecodes::_invokevirtual ||
189 // allow invokespecial as an alias, although it would be very odd:
190 (*opc) == (u1)Bytecodes::_invokespecial) {
191 assert(_pool->tag_at(cp_index).is_method(), "wrong index");
192 // Determine whether this is a signature-polymorphic method.
193 if (cp_index >= _method_handle_invokers.length()) return;
194 int status = _method_handle_invokers[cp_index];
195 assert(status >= -1 && status <= 1, "oob tri-state");
196 if (status == 0) {
197 if (_pool->klass_ref_at_noresolve(cp_index) == vmSymbols::java_lang_invoke_MethodHandle() &&
198 MethodHandles::is_signature_polymorphic_name(SystemDictionary::MethodHandle_klass(),
199 _pool->name_ref_at(cp_index))) {
200 // we may need a resolved_refs entry for the appendix
201 add_invokedynamic_resolved_references_entries(cp_index, cache_index);
202 status = +1;
203 } else {
204 status = -1;
205 }
206 _method_handle_invokers[cp_index] = status;
207 }
208 // We use a special internal bytecode for such methods (if non-static).
209 // The basic reason for this is that such methods need an extra "appendix" argument
210 // to transmit the call site's intended call type.
211 if (status > 0) {
212 (*opc) = (u1)Bytecodes::_invokehandle;
213 }
214 }
215 } else {
216 // Do not need to look at cp_index.
217 if ((*opc) == (u1)Bytecodes::_invokehandle) {
443 // After constant pool is created, revisit methods containing jsrs.
444 methodHandle Rewriter::rewrite_jsrs(methodHandle method, TRAPS) {
445 ResourceMark rm(THREAD);
446 ResolveOopMapConflicts romc(method);
447 methodHandle original_method = method;
448 method = romc.do_potential_rewrite(CHECK_(methodHandle()));
449 // Update monitor matching info.
450 if (romc.monitor_safe()) {
451 method->set_guaranteed_monitor_matching();
452 }
453
454 return method;
455 }
456
457 void Rewriter::rewrite_bytecodes(TRAPS) {
458 assert(_pool->cache() == NULL, "constant pool cache must not be set yet");
459
460 // determine index maps for Method* rewriting
461 compute_index_maps();
462
463 if (RegisterFinalizersAtInit && _klass->name() == vmSymbols::java_lang_Object()) {
464 bool did_rewrite = false;
465 int i = _methods->length();
466 while (i-- > 0) {
467 Method* method = _methods->at(i);
468 if (method->intrinsic_id() == vmIntrinsics::_Object_init) {
469 // rewrite the return bytecodes of Object.<init> to register the
470 // object for finalization if needed.
471 methodHandle m(THREAD, method);
472 rewrite_Object_init(m, CHECK);
473 did_rewrite = true;
474 break;
475 }
476 }
477 assert(did_rewrite, "must find Object::<init> to rewrite it");
478 }
479
480 // rewrite methods, in two passes
481 int len = _methods->length();
482 bool invokespecial_error = false;
483
|
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)->equals(vmSymbols::java_lang_invoke_MethodHandle()))
58 saw_mh_symbol = true;
59 break;
60 }
61 }
62
63 // Record limits of resolved reference map for constant pool cache indices
64 record_map_limits();
65
66 guarantee((int)_cp_cache_map.length()-1 <= (int)((u2)-1),
67 "all cp cache indexes fit in a u2");
68
69 if (saw_mh_symbol)
70 _method_handle_invokers.initialize(length, (int)0);
71 }
72
73 // Unrewrite the bytecodes if an error occurs.
74 void Rewriter::restore_bytecodes() {
75 int len = _methods->length();
76 bool invokespecial_error = false;
77
177 rewrite_member_reference(bcp, offset, reverse);
178 }
179 } else {
180 rewrite_member_reference(bcp, offset, reverse);
181 }
182 }
183
184
185 // Adjust the invocation bytecode for a signature-polymorphic method (MethodHandle.invoke, etc.)
186 void Rewriter::maybe_rewrite_invokehandle(address opc, int cp_index, int cache_index, bool reverse) {
187 if (!reverse) {
188 if ((*opc) == (u1)Bytecodes::_invokevirtual ||
189 // allow invokespecial as an alias, although it would be very odd:
190 (*opc) == (u1)Bytecodes::_invokespecial) {
191 assert(_pool->tag_at(cp_index).is_method(), "wrong index");
192 // Determine whether this is a signature-polymorphic method.
193 if (cp_index >= _method_handle_invokers.length()) return;
194 int status = _method_handle_invokers[cp_index];
195 assert(status >= -1 && status <= 1, "oob tri-state");
196 if (status == 0) {
197 if (_pool->klass_ref_at_noresolve(cp_index)->equals(vmSymbols::java_lang_invoke_MethodHandle()) &&
198 MethodHandles::is_signature_polymorphic_name(SystemDictionary::MethodHandle_klass(),
199 _pool->name_ref_at(cp_index))) {
200 // we may need a resolved_refs entry for the appendix
201 add_invokedynamic_resolved_references_entries(cp_index, cache_index);
202 status = +1;
203 } else {
204 status = -1;
205 }
206 _method_handle_invokers[cp_index] = status;
207 }
208 // We use a special internal bytecode for such methods (if non-static).
209 // The basic reason for this is that such methods need an extra "appendix" argument
210 // to transmit the call site's intended call type.
211 if (status > 0) {
212 (*opc) = (u1)Bytecodes::_invokehandle;
213 }
214 }
215 } else {
216 // Do not need to look at cp_index.
217 if ((*opc) == (u1)Bytecodes::_invokehandle) {
443 // After constant pool is created, revisit methods containing jsrs.
444 methodHandle Rewriter::rewrite_jsrs(methodHandle method, TRAPS) {
445 ResourceMark rm(THREAD);
446 ResolveOopMapConflicts romc(method);
447 methodHandle original_method = method;
448 method = romc.do_potential_rewrite(CHECK_(methodHandle()));
449 // Update monitor matching info.
450 if (romc.monitor_safe()) {
451 method->set_guaranteed_monitor_matching();
452 }
453
454 return method;
455 }
456
457 void Rewriter::rewrite_bytecodes(TRAPS) {
458 assert(_pool->cache() == NULL, "constant pool cache must not be set yet");
459
460 // determine index maps for Method* rewriting
461 compute_index_maps();
462
463 if (RegisterFinalizersAtInit && _klass->name()->equals(vmSymbols::java_lang_Object())) {
464 bool did_rewrite = false;
465 int i = _methods->length();
466 while (i-- > 0) {
467 Method* method = _methods->at(i);
468 if (method->intrinsic_id() == vmIntrinsics::_Object_init) {
469 // rewrite the return bytecodes of Object.<init> to register the
470 // object for finalization if needed.
471 methodHandle m(THREAD, method);
472 rewrite_Object_init(m, CHECK);
473 did_rewrite = true;
474 break;
475 }
476 }
477 assert(did_rewrite, "must find Object::<init> to rewrite it");
478 }
479
480 // rewrite methods, in two passes
481 int len = _methods->length();
482 bool invokespecial_error = false;
483
|