188 // different than the resolution for invokeinterface with InterfaceMethodref.
189 // These cannot share cpCache entries.
190 void Rewriter::rewrite_invokespecial(address bcp, int offset, bool reverse, bool* invokespecial_error) {
191 address p = bcp + offset;
192 if (!reverse) {
193 int cp_index = Bytes::get_Java_u2(p);
194 if (_pool->tag_at(cp_index).is_interface_method()) {
195 int cache_index = add_invokespecial_cp_cache_entry(cp_index);
196 if (cache_index != (int)(jushort) cache_index) {
197 *invokespecial_error = true;
198 }
199 Bytes::put_native_u2(p, cache_index);
200 } else {
201 rewrite_member_reference(bcp, offset, reverse);
202 }
203 } else {
204 rewrite_member_reference(bcp, offset, reverse);
205 }
206 }
207
208
209 // Adjust the invocation bytecode for a signature-polymorphic method (MethodHandle.invoke, etc.)
210 void Rewriter::maybe_rewrite_invokehandle(address opc, int cp_index, int cache_index, bool reverse) {
211 if (!reverse) {
212 if ((*opc) == (u1)Bytecodes::_invokevirtual ||
213 // allow invokespecial as an alias, although it would be very odd:
214 (*opc) == (u1)Bytecodes::_invokespecial) {
215 assert(_pool->tag_at(cp_index).is_method(), "wrong index");
216 // Determine whether this is a signature-polymorphic method.
217 if (cp_index >= _method_handle_invokers.length()) return;
218 int status = _method_handle_invokers.at(cp_index);
219 assert(status >= -1 && status <= 1, "oob tri-state");
220 if (status == 0) {
221 if (_pool->klass_ref_at_noresolve(cp_index) == vmSymbols::java_lang_invoke_MethodHandle() &&
222 MethodHandles::is_signature_polymorphic_name(SystemDictionary::MethodHandle_klass(),
223 _pool->name_ref_at(cp_index))) {
224 // we may need a resolved_refs entry for the appendix
225 add_invokedynamic_resolved_references_entry(cp_index, cache_index);
226 status = +1;
227 } else if (_pool->klass_ref_at_noresolve(cp_index) == vmSymbols::java_lang_invoke_VarHandle() &&
228 MethodHandles::is_signature_polymorphic_name(SystemDictionary::VarHandle_klass(),
449 fieldDescriptor fd;
450 if (klass->find_field(field_name, field_sig, &fd) != NULL) {
451 if (fd.access_flags().is_final()) {
452 if (fd.access_flags().is_static()) {
453 if (!method->is_static_initializer()) {
454 fd.set_has_initialized_final_update(true);
455 }
456 } else {
457 if (!method->is_object_initializer()) {
458 fd.set_has_initialized_final_update(true);
459 }
460 }
461 }
462 }
463 }
464 }
465 }
466 // fall through
467 case Bytecodes::_getstatic : // fall through
468 case Bytecodes::_getfield : // fall through
469 case Bytecodes::_invokevirtual : // fall through
470 case Bytecodes::_invokestatic :
471 case Bytecodes::_invokeinterface:
472 case Bytecodes::_invokehandle : // if reverse=true
473 rewrite_member_reference(bcp, prefix_length+1, reverse);
474 break;
475 case Bytecodes::_invokedynamic:
476 rewrite_invokedynamic(bcp, prefix_length+1, reverse);
477 break;
478 case Bytecodes::_ldc:
479 case Bytecodes::_fast_aldc: // if reverse=true
480 maybe_rewrite_ldc(bcp, prefix_length+1, false, reverse);
481 break;
482 case Bytecodes::_ldc_w:
483 case Bytecodes::_fast_aldc_w: // if reverse=true
484 maybe_rewrite_ldc(bcp, prefix_length+1, true, reverse);
485 break;
486 case Bytecodes::_jsr : // fall through
487 case Bytecodes::_jsr_w : nof_jsrs++; break;
488 case Bytecodes::_monitorenter : // fall through
|
188 // different than the resolution for invokeinterface with InterfaceMethodref.
189 // These cannot share cpCache entries.
190 void Rewriter::rewrite_invokespecial(address bcp, int offset, bool reverse, bool* invokespecial_error) {
191 address p = bcp + offset;
192 if (!reverse) {
193 int cp_index = Bytes::get_Java_u2(p);
194 if (_pool->tag_at(cp_index).is_interface_method()) {
195 int cache_index = add_invokespecial_cp_cache_entry(cp_index);
196 if (cache_index != (int)(jushort) cache_index) {
197 *invokespecial_error = true;
198 }
199 Bytes::put_native_u2(p, cache_index);
200 } else {
201 rewrite_member_reference(bcp, offset, reverse);
202 }
203 } else {
204 rewrite_member_reference(bcp, offset, reverse);
205 }
206 }
207
208 // Adjust the invocation bytecode for a signature-polymorphic method (MethodHandle.invoke, etc.)
209 void Rewriter::maybe_rewrite_invokehandle(address opc, int cp_index, int cache_index, bool reverse) {
210 if (!reverse) {
211 if ((*opc) == (u1)Bytecodes::_invokevirtual ||
212 // allow invokespecial as an alias, although it would be very odd:
213 (*opc) == (u1)Bytecodes::_invokespecial) {
214 assert(_pool->tag_at(cp_index).is_method(), "wrong index");
215 // Determine whether this is a signature-polymorphic method.
216 if (cp_index >= _method_handle_invokers.length()) return;
217 int status = _method_handle_invokers.at(cp_index);
218 assert(status >= -1 && status <= 1, "oob tri-state");
219 if (status == 0) {
220 if (_pool->klass_ref_at_noresolve(cp_index) == vmSymbols::java_lang_invoke_MethodHandle() &&
221 MethodHandles::is_signature_polymorphic_name(SystemDictionary::MethodHandle_klass(),
222 _pool->name_ref_at(cp_index))) {
223 // we may need a resolved_refs entry for the appendix
224 add_invokedynamic_resolved_references_entry(cp_index, cache_index);
225 status = +1;
226 } else if (_pool->klass_ref_at_noresolve(cp_index) == vmSymbols::java_lang_invoke_VarHandle() &&
227 MethodHandles::is_signature_polymorphic_name(SystemDictionary::VarHandle_klass(),
448 fieldDescriptor fd;
449 if (klass->find_field(field_name, field_sig, &fd) != NULL) {
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 case Bytecodes::_withfield : // fall through but may require more checks for correctness
469 case Bytecodes::_invokevirtual : // fall through
470 case Bytecodes::_invokestatic :
471 case Bytecodes::_invokeinterface:
472 case Bytecodes::_invokehandle : // if reverse=true
473 rewrite_member_reference(bcp, prefix_length+1, reverse);
474 break;
475 case Bytecodes::_invokedynamic:
476 rewrite_invokedynamic(bcp, prefix_length+1, reverse);
477 break;
478 case Bytecodes::_ldc:
479 case Bytecodes::_fast_aldc: // if reverse=true
480 maybe_rewrite_ldc(bcp, prefix_length+1, false, reverse);
481 break;
482 case Bytecodes::_ldc_w:
483 case Bytecodes::_fast_aldc_w: // if reverse=true
484 maybe_rewrite_ldc(bcp, prefix_length+1, true, reverse);
485 break;
486 case Bytecodes::_jsr : // fall through
487 case Bytecodes::_jsr_w : nof_jsrs++; break;
488 case Bytecodes::_monitorenter : // fall through
|