202 int offset = java_lang_boxing_object::value_offset(type);
203 intptr_t flags = ((as_TosState(type) << ConstantPoolCache::tos_state_shift)
204 | (offset & ConstantPoolCache::field_index_mask));
205 current->set_vm_result_metadata((Metadata*)flags);
206 }
207 }
208 JRT_END
209
210
211 //------------------------------------------------------------------------------------------------------------------------
212 // Allocation
213
214 JRT_ENTRY(void, InterpreterRuntime::_new(JavaThread* current, ConstantPool* pool, int index))
215 Klass* k = pool->klass_at(index, CHECK);
216 InstanceKlass* klass = InstanceKlass::cast(k);
217
218 // Make sure we are not instantiating an abstract klass
219 klass->check_valid_for_instantiation(true, CHECK);
220
221 // Make sure klass is initialized
222 klass->initialize(CHECK);
223
224 oop obj = klass->allocate_instance(CHECK);
225 current->set_vm_result_oop(obj);
226 JRT_END
227
228
229 JRT_ENTRY(void, InterpreterRuntime::newarray(JavaThread* current, BasicType type, jint size))
230 oop obj = oopFactory::new_typeArray(type, size, CHECK);
231 current->set_vm_result_oop(obj);
232 JRT_END
233
234
235 JRT_ENTRY(void, InterpreterRuntime::anewarray(JavaThread* current, ConstantPool* pool, int index, jint size))
236 Klass* klass = pool->klass_at(index, CHECK);
237 objArrayOop obj = oopFactory::new_objArray(klass, size, CHECK);
238 current->set_vm_result_oop(obj);
239 JRT_END
240
241
242 JRT_ENTRY(void, InterpreterRuntime::multianewarray(JavaThread* current, jint* first_size_address))
630 Klass* interfaceKlass))
631 ResourceMark rm(current);
632 char buf[1000];
633 buf[0] = '\0';
634 jio_snprintf(buf, sizeof(buf),
635 "Class %s does not implement the requested interface %s",
636 recvKlass ? recvKlass->external_name() : "nullptr",
637 interfaceKlass ? interfaceKlass->external_name() : "nullptr");
638 THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
639 JRT_END
640
641 JRT_ENTRY(void, InterpreterRuntime::throw_NullPointerException(JavaThread* current))
642 THROW(vmSymbols::java_lang_NullPointerException());
643 JRT_END
644
645 //------------------------------------------------------------------------------------------------------------------------
646 // Fields
647 //
648
649 void InterpreterRuntime::resolve_get_put(JavaThread* current, Bytecodes::Code bytecode) {
650 LastFrameAccessor last_frame(current);
651 constantPoolHandle pool(current, last_frame.method()->constants());
652 methodHandle m(current, last_frame.method());
653
654 resolve_get_put(bytecode, last_frame.get_index_u2(bytecode), m, pool, true /*initialize_holder*/, current);
655 }
656
657 void InterpreterRuntime::resolve_get_put(Bytecodes::Code bytecode, int field_index,
658 methodHandle& m,
659 constantPoolHandle& pool,
660 bool initialize_holder, TRAPS) {
661 fieldDescriptor info;
662 bool is_put = (bytecode == Bytecodes::_putfield || bytecode == Bytecodes::_nofast_putfield ||
663 bytecode == Bytecodes::_putstatic);
664 bool is_static = (bytecode == Bytecodes::_getstatic || bytecode == Bytecodes::_putstatic);
665
666 {
667 JvmtiHideSingleStepping jhss(THREAD);
668 LinkResolver::resolve_field_access(info, pool, field_index,
669 m, bytecode, initialize_holder, CHECK);
670 } // end JvmtiHideSingleStepping
671
672 // check if link resolution caused cpCache to be updated
673 if (pool->resolved_field_entry_at(field_index)->is_resolved(bytecode)) return;
674
675 // compute auxiliary field attributes
676 TosState state = as_TosState(info.field_type());
677
678 // Resolution of put instructions on final fields is delayed. That is required so that
679 // exceptions are thrown at the correct place (when the instruction is actually invoked).
680 // If we do not resolve an instruction in the current pass, leaving the put_code
681 // set to zero will cause the next put instruction to the same field to reresolve.
682
683 // Resolution of put instructions to final instance fields with invalid updates (i.e.,
684 // to final instance fields with updates originating from a method different than <init>)
685 // is inhibited. A putfield instruction targeting an instance final field must throw
686 // an IllegalAccessError if the instruction is not in an instance
687 // initializer method <init>. If resolution were not inhibited, a putfield
688 // in an initializer method could be resolved in the initializer. Subsequent
689 // putfield instructions to the same field would then use cached information.
808
809 assert(Universe::heap()->is_in_or_null(receiver()),
810 "sanity check");
811 assert(receiver.is_null() ||
812 !Universe::heap()->is_in(receiver->klass()),
813 "sanity check");
814 }
815
816 // resolve method
817 CallInfo info;
818 constantPoolHandle pool(current, last_frame.method()->constants());
819
820 methodHandle resolved_method;
821
822 int method_index = last_frame.get_index_u2(bytecode);
823 {
824 JvmtiHideSingleStepping jhss(current);
825 JavaThread* THREAD = current; // For exception macros.
826 LinkResolver::resolve_invoke(info, receiver, pool,
827 method_index, bytecode,
828 THREAD);
829
830 if (HAS_PENDING_EXCEPTION) {
831 if (ProfileTraps && PENDING_EXCEPTION->klass()->name() == vmSymbols::java_lang_NullPointerException()) {
832 // Preserve the original exception across the call to note_trap()
833 PreserveExceptionMark pm(current);
834 // Recording the trap will help the compiler to potentially recognize this exception as "hot"
835 note_trap(current, Deoptimization::Reason_null_check);
836 }
837 return;
838 }
839
840 resolved_method = methodHandle(current, info.resolved_method());
841 } // end JvmtiHideSingleStepping
842
843 update_invoke_cp_cache_entry(info, bytecode, resolved_method, pool, method_index);
844 }
845
846 void InterpreterRuntime::update_invoke_cp_cache_entry(CallInfo& info, Bytecodes::Code bytecode,
847 methodHandle& resolved_method,
848 constantPoolHandle& pool,
849 int method_index) {
850 // Don't allow safepoints until the method is cached.
851 NoSafepointVerifier nsv;
852
853 // check if link resolution caused cpCache to be updated
854 ConstantPoolCache* cache = pool->cache();
855 if (cache->resolved_method_entry_at(method_index)->is_resolved(bytecode)) return;
856
1506 } else {
1507 current->set_vm_result_oop(nullptr);
1508 }
1509 JRT_END
1510 #endif // INCLUDE_JVMTI
1511
1512 #ifndef PRODUCT
1513 // This must be a JRT_LEAF function because the interpreter must save registers on x86 to
1514 // call this, which changes rsp and makes the interpreter's expression stack not walkable.
1515 // The generated code still uses call_VM because that will set up the frame pointer for
1516 // bcp and method.
1517 JRT_LEAF(intptr_t, InterpreterRuntime::trace_bytecode(JavaThread* current, intptr_t preserve_this_value, intptr_t tos, intptr_t tos2))
1518 assert(current == JavaThread::current(), "pre-condition");
1519 LastFrameAccessor last_frame(current);
1520 assert(last_frame.is_interpreted_frame(), "must be an interpreted frame");
1521 methodHandle mh(current, last_frame.method());
1522 BytecodeTracer::trace_interpreter(mh, last_frame.bcp(), tos, tos2);
1523 return preserve_this_value;
1524 JRT_END
1525 #endif // !PRODUCT
|
202 int offset = java_lang_boxing_object::value_offset(type);
203 intptr_t flags = ((as_TosState(type) << ConstantPoolCache::tos_state_shift)
204 | (offset & ConstantPoolCache::field_index_mask));
205 current->set_vm_result_metadata((Metadata*)flags);
206 }
207 }
208 JRT_END
209
210
211 //------------------------------------------------------------------------------------------------------------------------
212 // Allocation
213
214 JRT_ENTRY(void, InterpreterRuntime::_new(JavaThread* current, ConstantPool* pool, int index))
215 Klass* k = pool->klass_at(index, CHECK);
216 InstanceKlass* klass = InstanceKlass::cast(k);
217
218 // Make sure we are not instantiating an abstract klass
219 klass->check_valid_for_instantiation(true, CHECK);
220
221 // Make sure klass is initialized
222 klass->initialize_preemptable(CHECK_AND_CLEAR_PREEMPTED);
223
224 oop obj = klass->allocate_instance(CHECK);
225 current->set_vm_result_oop(obj);
226 JRT_END
227
228
229 JRT_ENTRY(void, InterpreterRuntime::newarray(JavaThread* current, BasicType type, jint size))
230 oop obj = oopFactory::new_typeArray(type, size, CHECK);
231 current->set_vm_result_oop(obj);
232 JRT_END
233
234
235 JRT_ENTRY(void, InterpreterRuntime::anewarray(JavaThread* current, ConstantPool* pool, int index, jint size))
236 Klass* klass = pool->klass_at(index, CHECK);
237 objArrayOop obj = oopFactory::new_objArray(klass, size, CHECK);
238 current->set_vm_result_oop(obj);
239 JRT_END
240
241
242 JRT_ENTRY(void, InterpreterRuntime::multianewarray(JavaThread* current, jint* first_size_address))
630 Klass* interfaceKlass))
631 ResourceMark rm(current);
632 char buf[1000];
633 buf[0] = '\0';
634 jio_snprintf(buf, sizeof(buf),
635 "Class %s does not implement the requested interface %s",
636 recvKlass ? recvKlass->external_name() : "nullptr",
637 interfaceKlass ? interfaceKlass->external_name() : "nullptr");
638 THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
639 JRT_END
640
641 JRT_ENTRY(void, InterpreterRuntime::throw_NullPointerException(JavaThread* current))
642 THROW(vmSymbols::java_lang_NullPointerException());
643 JRT_END
644
645 //------------------------------------------------------------------------------------------------------------------------
646 // Fields
647 //
648
649 void InterpreterRuntime::resolve_get_put(JavaThread* current, Bytecodes::Code bytecode) {
650 JavaThread* THREAD = current;
651 LastFrameAccessor last_frame(current);
652 constantPoolHandle pool(current, last_frame.method()->constants());
653 methodHandle m(current, last_frame.method());
654
655 resolve_get_put(bytecode, last_frame.get_index_u2(bytecode), m, pool, StaticMode::initialize_klass_preemptable, CHECK_AND_CLEAR_PREEMPTED);
656 }
657
658 void InterpreterRuntime::resolve_get_put(Bytecodes::Code bytecode, int field_index,
659 methodHandle& m,
660 constantPoolHandle& pool,
661 StaticMode static_mode, TRAPS) {
662 fieldDescriptor info;
663 bool is_put = (bytecode == Bytecodes::_putfield || bytecode == Bytecodes::_nofast_putfield ||
664 bytecode == Bytecodes::_putstatic);
665 bool is_static = (bytecode == Bytecodes::_getstatic || bytecode == Bytecodes::_putstatic);
666
667 {
668 JvmtiHideSingleStepping jhss(THREAD);
669 LinkResolver::resolve_field_access(info, pool, field_index,
670 m, bytecode, static_mode, CHECK);
671 } // end JvmtiHideSingleStepping
672
673 // check if link resolution caused cpCache to be updated
674 if (pool->resolved_field_entry_at(field_index)->is_resolved(bytecode)) return;
675
676 // compute auxiliary field attributes
677 TosState state = as_TosState(info.field_type());
678
679 // Resolution of put instructions on final fields is delayed. That is required so that
680 // exceptions are thrown at the correct place (when the instruction is actually invoked).
681 // If we do not resolve an instruction in the current pass, leaving the put_code
682 // set to zero will cause the next put instruction to the same field to reresolve.
683
684 // Resolution of put instructions to final instance fields with invalid updates (i.e.,
685 // to final instance fields with updates originating from a method different than <init>)
686 // is inhibited. A putfield instruction targeting an instance final field must throw
687 // an IllegalAccessError if the instruction is not in an instance
688 // initializer method <init>. If resolution were not inhibited, a putfield
689 // in an initializer method could be resolved in the initializer. Subsequent
690 // putfield instructions to the same field would then use cached information.
809
810 assert(Universe::heap()->is_in_or_null(receiver()),
811 "sanity check");
812 assert(receiver.is_null() ||
813 !Universe::heap()->is_in(receiver->klass()),
814 "sanity check");
815 }
816
817 // resolve method
818 CallInfo info;
819 constantPoolHandle pool(current, last_frame.method()->constants());
820
821 methodHandle resolved_method;
822
823 int method_index = last_frame.get_index_u2(bytecode);
824 {
825 JvmtiHideSingleStepping jhss(current);
826 JavaThread* THREAD = current; // For exception macros.
827 LinkResolver::resolve_invoke(info, receiver, pool,
828 method_index, bytecode,
829 StaticMode::initialize_klass_preemptable, THREAD);
830
831 if (HAS_PENDING_EXCEPTION) {
832 if (ProfileTraps && PENDING_EXCEPTION->klass()->name() == vmSymbols::java_lang_NullPointerException()) {
833 // Preserve the original exception across the call to note_trap()
834 PreserveExceptionMark pm(current);
835 // Recording the trap will help the compiler to potentially recognize this exception as "hot"
836 note_trap(current, Deoptimization::Reason_null_check);
837 }
838 CLEAR_PENDING_PREEMPTED_EXCEPTION;
839 return;
840 }
841
842 resolved_method = methodHandle(current, info.resolved_method());
843 } // end JvmtiHideSingleStepping
844
845 update_invoke_cp_cache_entry(info, bytecode, resolved_method, pool, method_index);
846 }
847
848 void InterpreterRuntime::update_invoke_cp_cache_entry(CallInfo& info, Bytecodes::Code bytecode,
849 methodHandle& resolved_method,
850 constantPoolHandle& pool,
851 int method_index) {
852 // Don't allow safepoints until the method is cached.
853 NoSafepointVerifier nsv;
854
855 // check if link resolution caused cpCache to be updated
856 ConstantPoolCache* cache = pool->cache();
857 if (cache->resolved_method_entry_at(method_index)->is_resolved(bytecode)) return;
858
1508 } else {
1509 current->set_vm_result_oop(nullptr);
1510 }
1511 JRT_END
1512 #endif // INCLUDE_JVMTI
1513
1514 #ifndef PRODUCT
1515 // This must be a JRT_LEAF function because the interpreter must save registers on x86 to
1516 // call this, which changes rsp and makes the interpreter's expression stack not walkable.
1517 // The generated code still uses call_VM because that will set up the frame pointer for
1518 // bcp and method.
1519 JRT_LEAF(intptr_t, InterpreterRuntime::trace_bytecode(JavaThread* current, intptr_t preserve_this_value, intptr_t tos, intptr_t tos2))
1520 assert(current == JavaThread::current(), "pre-condition");
1521 LastFrameAccessor last_frame(current);
1522 assert(last_frame.is_interpreted_frame(), "must be an interpreted frame");
1523 methodHandle mh(current, last_frame.method());
1524 BytecodeTracer::trace_interpreter(mh, last_frame.bcp(), tos, tos2);
1525 return preserve_this_value;
1526 JRT_END
1527 #endif // !PRODUCT
1528
1529 #ifdef ASSERT
1530 bool InterpreterRuntime::is_preemptable_call(address entry_point) {
1531 return entry_point == CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter) ||
1532 entry_point == CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_from_cache) ||
1533 entry_point == CAST_FROM_FN_PTR(address, InterpreterRuntime::_new);
1534 }
1535 #endif // ASSERT
|