104 int get_index_u2(Bytecodes::Code bc) const { return bytecode().get_index_u2(bc); }
105 int get_index_u4(Bytecodes::Code bc) const { return bytecode().get_index_u4(bc); }
106 int number_of_dimensions() const { return bcp()[3]; }
107
108 oop callee_receiver(Symbol* signature) {
109 return _last_frame.interpreter_callee_receiver(signature);
110 }
111 BasicObjectLock* monitor_begin() const {
112 return _last_frame.interpreter_frame_monitor_begin();
113 }
114 BasicObjectLock* monitor_end() const {
115 return _last_frame.interpreter_frame_monitor_end();
116 }
117 BasicObjectLock* next_monitor(BasicObjectLock* current) const {
118 return _last_frame.next_monitor_in_interpreter_frame(current);
119 }
120
121 frame& get_frame() { return _last_frame; }
122 };
123
124 //------------------------------------------------------------------------------------------------------------------------
125 // State accessors
126
127 void InterpreterRuntime::set_bcp_and_mdp(address bcp, JavaThread* current) {
128 LastFrameAccessor last_frame(current);
129 last_frame.set_bcp(bcp);
130 if (ProfileInterpreter) {
131 // ProfileTraps uses MDOs independently of ProfileInterpreter.
132 // That is why we must check both ProfileInterpreter and mdo != nullptr.
133 MethodData* mdo = last_frame.method()->method_data();
134 if (mdo != nullptr) {
135 NEEDS_CLEANUP;
136 last_frame.set_mdp(mdo->bci_to_dp(last_frame.bci()));
137 }
138 }
139 }
140
141 //------------------------------------------------------------------------------------------------------------------------
142 // Constants
143
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.
803 ResourceMark rm(current);
804 methodHandle m (current, last_frame.method());
805 Bytecode_invoke call(m, last_frame.bci());
806 Symbol* signature = call.signature();
807 receiver = Handle(current, last_frame.callee_receiver(signature));
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
857 #ifdef ASSERT
858 if (bytecode == Bytecodes::_invokeinterface) {
859 if (resolved_method->method_holder() == vmClasses::Object_klass()) {
860 // NOTE: THIS IS A FIX FOR A CORNER CASE in the JVM spec
|
104 int get_index_u2(Bytecodes::Code bc) const { return bytecode().get_index_u2(bc); }
105 int get_index_u4(Bytecodes::Code bc) const { return bytecode().get_index_u4(bc); }
106 int number_of_dimensions() const { return bcp()[3]; }
107
108 oop callee_receiver(Symbol* signature) {
109 return _last_frame.interpreter_callee_receiver(signature);
110 }
111 BasicObjectLock* monitor_begin() const {
112 return _last_frame.interpreter_frame_monitor_begin();
113 }
114 BasicObjectLock* monitor_end() const {
115 return _last_frame.interpreter_frame_monitor_end();
116 }
117 BasicObjectLock* next_monitor(BasicObjectLock* current) const {
118 return _last_frame.next_monitor_in_interpreter_frame(current);
119 }
120
121 frame& get_frame() { return _last_frame; }
122 };
123
124 class ProfileTrapsMark : public StackObj {
125 JavaThread* _thread;
126 public:
127 ProfileTrapsMark(JavaThread* current) : _thread(current) {}
128 ~ProfileTrapsMark() {
129 JavaThread* THREAD = _thread;
130 if (HAS_PENDING_EXCEPTION) {
131 if (ProfileTraps && PENDING_EXCEPTION->klass()->name() == vmSymbols::java_lang_NullPointerException()) {
132 // Preserve the original exception across the call to note_trap()
133 PreserveExceptionMark pm(_thread);
134 // Recording the trap will help the compiler to potentially recognize this exception as "hot"
135 InterpreterRuntime::note_trap(_thread, Deoptimization::Reason_null_check);
136 }
137 }
138 }
139 };
140
141 //------------------------------------------------------------------------------------------------------------------------
142 // State accessors
143
144 void InterpreterRuntime::set_bcp_and_mdp(address bcp, JavaThread* current) {
145 LastFrameAccessor last_frame(current);
146 last_frame.set_bcp(bcp);
147 if (ProfileInterpreter) {
148 // ProfileTraps uses MDOs independently of ProfileInterpreter.
149 // That is why we must check both ProfileInterpreter and mdo != nullptr.
150 MethodData* mdo = last_frame.method()->method_data();
151 if (mdo != nullptr) {
152 NEEDS_CLEANUP;
153 last_frame.set_mdp(mdo->bci_to_dp(last_frame.bci()));
154 }
155 }
156 }
157
158 //------------------------------------------------------------------------------------------------------------------------
159 // Constants
160
219 int offset = java_lang_boxing_object::value_offset(type);
220 intptr_t flags = ((as_TosState(type) << ConstantPoolCache::tos_state_shift)
221 | (offset & ConstantPoolCache::field_index_mask));
222 current->set_vm_result_metadata((Metadata*)flags);
223 }
224 }
225 JRT_END
226
227
228 //------------------------------------------------------------------------------------------------------------------------
229 // Allocation
230
231 JRT_ENTRY(void, InterpreterRuntime::_new(JavaThread* current, ConstantPool* pool, int index))
232 Klass* k = pool->klass_at(index, CHECK);
233 InstanceKlass* klass = InstanceKlass::cast(k);
234
235 // Make sure we are not instantiating an abstract klass
236 klass->check_valid_for_instantiation(true, CHECK);
237
238 // Make sure klass is initialized
239 klass->initialize_preemptable(CHECK_AND_CLEAR_PREEMPTED);
240
241 oop obj = klass->allocate_instance(CHECK);
242 current->set_vm_result_oop(obj);
243 JRT_END
244
245
246 JRT_ENTRY(void, InterpreterRuntime::newarray(JavaThread* current, BasicType type, jint size))
247 oop obj = oopFactory::new_typeArray(type, size, CHECK);
248 current->set_vm_result_oop(obj);
249 JRT_END
250
251
252 JRT_ENTRY(void, InterpreterRuntime::anewarray(JavaThread* current, ConstantPool* pool, int index, jint size))
253 Klass* klass = pool->klass_at(index, CHECK);
254 objArrayOop obj = oopFactory::new_objArray(klass, size, CHECK);
255 current->set_vm_result_oop(obj);
256 JRT_END
257
258
259 JRT_ENTRY(void, InterpreterRuntime::multianewarray(JavaThread* current, jint* first_size_address))
647 Klass* interfaceKlass))
648 ResourceMark rm(current);
649 char buf[1000];
650 buf[0] = '\0';
651 jio_snprintf(buf, sizeof(buf),
652 "Class %s does not implement the requested interface %s",
653 recvKlass ? recvKlass->external_name() : "nullptr",
654 interfaceKlass ? interfaceKlass->external_name() : "nullptr");
655 THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
656 JRT_END
657
658 JRT_ENTRY(void, InterpreterRuntime::throw_NullPointerException(JavaThread* current))
659 THROW(vmSymbols::java_lang_NullPointerException());
660 JRT_END
661
662 //------------------------------------------------------------------------------------------------------------------------
663 // Fields
664 //
665
666 void InterpreterRuntime::resolve_get_put(JavaThread* current, Bytecodes::Code bytecode) {
667 JavaThread* THREAD = current;
668 LastFrameAccessor last_frame(current);
669 constantPoolHandle pool(current, last_frame.method()->constants());
670 methodHandle m(current, last_frame.method());
671
672 resolve_get_put(bytecode, last_frame.get_index_u2(bytecode), m, pool, StaticMode::initialize_klass_preemptable, CHECK_AND_CLEAR_PREEMPTED);
673 }
674
675 void InterpreterRuntime::resolve_get_put(Bytecodes::Code bytecode, int field_index,
676 methodHandle& m,
677 constantPoolHandle& pool,
678 StaticMode static_mode, TRAPS) {
679 fieldDescriptor info;
680 bool is_put = (bytecode == Bytecodes::_putfield || bytecode == Bytecodes::_nofast_putfield ||
681 bytecode == Bytecodes::_putstatic);
682 bool is_static = (bytecode == Bytecodes::_getstatic || bytecode == Bytecodes::_putstatic);
683
684 {
685 JvmtiHideSingleStepping jhss(THREAD);
686 LinkResolver::resolve_field_access(info, pool, field_index,
687 m, bytecode, static_mode, CHECK);
688 } // end JvmtiHideSingleStepping
689
690 // check if link resolution caused cpCache to be updated
691 if (pool->resolved_field_entry_at(field_index)->is_resolved(bytecode)) return;
692
693 // compute auxiliary field attributes
694 TosState state = as_TosState(info.field_type());
695
696 // Resolution of put instructions on final fields is delayed. That is required so that
697 // exceptions are thrown at the correct place (when the instruction is actually invoked).
698 // If we do not resolve an instruction in the current pass, leaving the put_code
699 // set to zero will cause the next put instruction to the same field to reresolve.
700
701 // Resolution of put instructions to final instance fields with invalid updates (i.e.,
702 // to final instance fields with updates originating from a method different than <init>)
703 // is inhibited. A putfield instruction targeting an instance final field must throw
704 // an IllegalAccessError if the instruction is not in an instance
705 // initializer method <init>. If resolution were not inhibited, a putfield
706 // in an initializer method could be resolved in the initializer. Subsequent
707 // putfield instructions to the same field would then use cached information.
821 ResourceMark rm(current);
822 methodHandle m (current, last_frame.method());
823 Bytecode_invoke call(m, last_frame.bci());
824 Symbol* signature = call.signature();
825 receiver = Handle(current, last_frame.callee_receiver(signature));
826
827 assert(Universe::heap()->is_in_or_null(receiver()),
828 "sanity check");
829 assert(receiver.is_null() ||
830 !Universe::heap()->is_in(receiver->klass()),
831 "sanity check");
832 }
833
834 // resolve method
835 CallInfo info;
836 constantPoolHandle pool(current, last_frame.method()->constants());
837
838 methodHandle resolved_method;
839
840 int method_index = last_frame.get_index_u2(bytecode);
841 { ProfileTrapsMark pt(current);
842 JvmtiHideSingleStepping jhss(current);
843 JavaThread* THREAD = current; // For exception macros.
844 LinkResolver::resolve_invoke(info, receiver, pool,
845 method_index, bytecode,
846 StaticMode::initialize_klass_preemptable, CHECK_AND_CLEAR_PREEMPTED);
847 resolved_method = methodHandle(current, info.resolved_method());
848 ResourceMark rm(THREAD);
849 } // end JvmtiHideSingleStepping
850
851 update_invoke_cp_cache_entry(info, bytecode, resolved_method, pool, method_index);
852 }
853
854 void InterpreterRuntime::update_invoke_cp_cache_entry(CallInfo& info, Bytecodes::Code bytecode,
855 methodHandle& resolved_method,
856 constantPoolHandle& pool,
857 int method_index) {
858 // Don't allow safepoints until the method is cached.
859 NoSafepointVerifier nsv;
860
861 // check if link resolution caused cpCache to be updated
862 ConstantPoolCache* cache = pool->cache();
863 if (cache->resolved_method_entry_at(method_index)->is_resolved(bytecode)) return;
864
865 #ifdef ASSERT
866 if (bytecode == Bytecodes::_invokeinterface) {
867 if (resolved_method->method_holder() == vmClasses::Object_klass()) {
868 // NOTE: THIS IS A FIX FOR A CORNER CASE in the JVM spec
|