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 "classfile/javaClasses.inline.hpp"
26 #include "classfile/symbolTable.hpp"
27 #include "classfile/vmClasses.hpp"
28 #include "classfile/vmSymbols.hpp"
29 #include "code/codeCache.hpp"
30 #include "compiler/compilationPolicy.hpp"
31 #include "compiler/compileBroker.hpp"
32 #include "compiler/disassembler.hpp"
33 #include "gc/shared/barrierSetNMethod.hpp"
34 #include "gc/shared/collectedHeap.hpp"
35 #include "interpreter/bytecodeTracer.hpp"
36 #include "interpreter/interpreter.hpp"
37 #include "interpreter/interpreterRuntime.hpp"
38 #include "interpreter/linkResolver.hpp"
39 #include "interpreter/oopMapCache.hpp"
40 #include "interpreter/templateTable.hpp"
41 #include "jvm_io.h"
42 #include "logging/log.hpp"
43 #include "memory/oopFactory.hpp"
44 #include "memory/resourceArea.hpp"
45 #include "memory/universe.hpp"
46 #include "oops/constantPool.inline.hpp"
47 #include "oops/cpCache.inline.hpp"
48 #include "oops/instanceKlass.inline.hpp"
49 #include "oops/klass.inline.hpp"
50 #include "oops/method.inline.hpp"
51 #include "oops/methodData.hpp"
52 #include "oops/objArrayKlass.hpp"
53 #include "oops/objArrayOop.inline.hpp"
54 #include "oops/oop.inline.hpp"
55 #include "oops/symbol.hpp"
56 #include "prims/jvmtiExport.hpp"
57 #include "prims/methodHandles.hpp"
58 #include "prims/nativeLookup.hpp"
59 #include "runtime/continuation.hpp"
60 #include "runtime/deoptimization.hpp"
61 #include "runtime/fieldDescriptor.inline.hpp"
62 #include "runtime/frame.inline.hpp"
63 #include "runtime/handles.inline.hpp"
64 #include "runtime/icache.hpp"
65 #include "runtime/interfaceSupport.inline.hpp"
66 #include "runtime/java.hpp"
67 #include "runtime/javaCalls.hpp"
68 #include "runtime/jfieldIDWorkaround.hpp"
69 #include "runtime/osThread.hpp"
70 #include "runtime/sharedRuntime.hpp"
71 #include "runtime/stackWatermarkSet.hpp"
72 #include "runtime/stubRoutines.hpp"
73 #include "runtime/synchronizer.hpp"
74 #include "utilities/align.hpp"
75 #include "utilities/checkedCast.hpp"
76 #include "utilities/copy.hpp"
77 #include "utilities/events.hpp"
78 #include "utilities/exceptions.hpp"
79 #if INCLUDE_JFR
80 #include "jfr/jfr.inline.hpp"
81 #endif
82
83 // Helper class to access current interpreter state
84 class LastFrameAccessor : public StackObj {
85 frame _last_frame;
86 public:
87 LastFrameAccessor(JavaThread* current) {
88 assert(current == Thread::current(), "sanity");
89 _last_frame = current->last_frame();
90 }
91 bool is_interpreted_frame() const { return _last_frame.is_interpreted_frame(); }
92 Method* method() const { return _last_frame.interpreter_frame_method(); }
93 address bcp() const { return _last_frame.interpreter_frame_bcp(); }
94 int bci() const { return _last_frame.interpreter_frame_bci(); }
95 address mdp() const { return _last_frame.interpreter_frame_mdp(); }
96
97 void set_bcp(address bcp) { _last_frame.interpreter_frame_set_bcp(bcp); }
98 void set_mdp(address dp) { _last_frame.interpreter_frame_set_mdp(dp); }
209 JRT_END
210
211
212 //------------------------------------------------------------------------------------------------------------------------
213 // Allocation
214
215 JRT_ENTRY(void, InterpreterRuntime::_new(JavaThread* current, ConstantPool* pool, int index))
216 Klass* k = pool->klass_at(index, CHECK);
217 InstanceKlass* klass = InstanceKlass::cast(k);
218
219 // Make sure we are not instantiating an abstract klass
220 klass->check_valid_for_instantiation(true, CHECK);
221
222 // Make sure klass is initialized
223 klass->initialize_preemptable(CHECK_AND_CLEAR_PREEMPTED);
224
225 oop obj = klass->allocate_instance(CHECK);
226 current->set_vm_result_oop(obj);
227 JRT_END
228
229
230 JRT_ENTRY(void, InterpreterRuntime::newarray(JavaThread* current, BasicType type, jint size))
231 oop obj = oopFactory::new_typeArray(type, size, CHECK);
232 current->set_vm_result_oop(obj);
233 JRT_END
234
235
236 JRT_ENTRY(void, InterpreterRuntime::anewarray(JavaThread* current, ConstantPool* pool, int index, jint size))
237 Klass* klass = pool->klass_at(index, CHECK);
238 objArrayOop obj = oopFactory::new_objArray(klass, size, CHECK);
239 current->set_vm_result_oop(obj);
240 JRT_END
241
242
243 JRT_ENTRY(void, InterpreterRuntime::multianewarray(JavaThread* current, jint* first_size_address))
244 // We may want to pass in more arguments - could make this slightly faster
245 LastFrameAccessor last_frame(current);
246 ConstantPool* constants = last_frame.method()->constants();
247 int i = last_frame.get_index_u2(Bytecodes::_multianewarray);
248 Klass* klass = constants->klass_at(i, CHECK);
249 int nof_dims = last_frame.number_of_dimensions();
250 assert(klass->is_klass(), "not a class");
251 assert(nof_dims >= 1, "multianewarray rank must be nonzero");
252
253 // We must create an array of jints to pass to multi_allocate.
254 ResourceMark rm(current);
255 const int small_dims = 10;
256 jint dim_array[small_dims];
257 jint *dims = &dim_array[0];
258 if (nof_dims > small_dims) {
259 dims = (jint*) NEW_RESOURCE_ARRAY(jint, nof_dims);
260 }
261 for (int index = 0; index < nof_dims; index++) {
262 // offset from first_size_address is addressed as local[index]
263 int n = Interpreter::local_offset_in_bytes(index)/jintSize;
264 dims[index] = first_size_address[n];
265 }
266 oop obj = ArrayKlass::cast(klass)->multi_allocate(nof_dims, dims, CHECK);
267 current->set_vm_result_oop(obj);
268 JRT_END
269
270
271 JRT_ENTRY(void, InterpreterRuntime::register_finalizer(JavaThread* current, oopDesc* obj))
272 assert(oopDesc::is_oop(obj), "must be a valid oop");
273 assert(obj->klass()->has_finalizer(), "shouldn't be here otherwise");
274 InstanceKlass::register_finalizer(instanceOop(obj), CHECK);
275 JRT_END
276
277
278 // Quicken instance-of and check-cast bytecodes
279 JRT_ENTRY(void, InterpreterRuntime::quicken_io_cc(JavaThread* current))
280 // Force resolving; quicken the bytecode
281 LastFrameAccessor last_frame(current);
282 int which = last_frame.get_index_u2(Bytecodes::_checkcast);
283 ConstantPool* cpool = last_frame.method()->constants();
284 // We'd expect to assert that we're only here to quicken bytecodes, but in a multithreaded
285 // program we might have seen an unquick'd bytecode in the interpreter but have another
286 // thread quicken the bytecode before we get here.
287 // assert( cpool->tag_at(which).is_unresolved_klass(), "should only come here to quicken bytecodes" );
288 Klass* klass = cpool->klass_at(which, CHECK);
289 current->set_vm_result_metadata(klass);
290 JRT_END
291
292
293 //------------------------------------------------------------------------------------------------------------------------
294 // Exceptions
295
296 void InterpreterRuntime::note_trap_inner(JavaThread* current, int reason,
604 // and therefore we don't have the receiver object at our fingertips. (Though,
605 // on some platforms the receiver still resides in a register...). Thus,
606 // we have no choice but print an error message not containing the receiver
607 // type.
608 JRT_ENTRY(void, InterpreterRuntime::throw_AbstractMethodErrorWithMethod(JavaThread* current,
609 Method* missingMethod))
610 ResourceMark rm(current);
611 assert(missingMethod != nullptr, "sanity");
612 methodHandle m(current, missingMethod);
613 LinkResolver::throw_abstract_method_error(m, THREAD);
614 JRT_END
615
616 JRT_ENTRY(void, InterpreterRuntime::throw_AbstractMethodErrorVerbose(JavaThread* current,
617 Klass* recvKlass,
618 Method* missingMethod))
619 ResourceMark rm(current);
620 methodHandle mh = methodHandle(current, missingMethod);
621 LinkResolver::throw_abstract_method_error(mh, recvKlass, THREAD);
622 JRT_END
623
624
625 JRT_ENTRY(void, InterpreterRuntime::throw_IncompatibleClassChangeError(JavaThread* current))
626 THROW(vmSymbols::java_lang_IncompatibleClassChangeError());
627 JRT_END
628
629 JRT_ENTRY(void, InterpreterRuntime::throw_IncompatibleClassChangeErrorVerbose(JavaThread* current,
630 Klass* recvKlass,
631 Klass* interfaceKlass))
632 ResourceMark rm(current);
633 char buf[1000];
634 buf[0] = '\0';
635 jio_snprintf(buf, sizeof(buf),
636 "Class %s does not implement the requested interface %s",
637 recvKlass ? recvKlass->external_name() : "nullptr",
638 interfaceKlass ? interfaceKlass->external_name() : "nullptr");
639 THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
640 JRT_END
641
642 JRT_ENTRY(void, InterpreterRuntime::throw_NullPointerException(JavaThread* current))
643 THROW(vmSymbols::java_lang_NullPointerException());
644 JRT_END
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.
691 // As a result, those instructions would not pass through the VM. That is,
692 // checks in resolve_field_access() would not be executed for those instructions
693 // and the required IllegalAccessError would not be thrown.
694 //
695 // Also, we need to delay resolving getstatic and putstatic instructions until the
696 // class is initialized. This is required so that access to the static
697 // field will call the initialization function every time until the class
698 // is completely initialized ala. in 2.17.5 in JVM Specification.
699 InstanceKlass* klass = info.field_holder();
700 bool uninitialized_static = is_static && !klass->is_initialized();
701 bool has_initialized_final_update = info.field_holder()->major_version() >= 53 &&
702 info.has_initialized_final_update();
703 assert(!(has_initialized_final_update && !info.access_flags().is_final()), "Fields with initialized final updates must be final");
704
705 Bytecodes::Code get_code = (Bytecodes::Code)0;
706 Bytecodes::Code put_code = (Bytecodes::Code)0;
707 if (!uninitialized_static || VM_Version::supports_fast_class_init_checks()) {
708 get_code = ((is_static) ? Bytecodes::_getstatic : Bytecodes::_getfield);
709 if ((is_put && !has_initialized_final_update) || !info.access_flags().is_final()) {
710 put_code = ((is_static) ? Bytecodes::_putstatic : Bytecodes::_putfield);
711 }
712 }
713
714 ResolvedFieldEntry* entry = pool->resolved_field_entry_at(field_index);
715 entry->fill_in(info, checked_cast<u1>(state),
716 static_cast<u1>(get_code), static_cast<u1>(put_code));
717 }
718
719
720 //------------------------------------------------------------------------------------------------------------------------
721 // Synchronization
722 //
723 // The interpreter's synchronization code is factored out so that it can
724 // be shared by method invocation and synchronized blocks.
725 //%note synchronization_3
726
727 //%note monitor_1
758 JRT_END
759
760 JRT_ENTRY(void, InterpreterRuntime::throw_illegal_monitor_state_exception(JavaThread* current))
761 THROW(vmSymbols::java_lang_IllegalMonitorStateException());
762 JRT_END
763
764 JRT_ENTRY(void, InterpreterRuntime::new_illegal_monitor_state_exception(JavaThread* current))
765 // Returns an illegal exception to install into the current thread. The
766 // pending_exception flag is cleared so normal exception handling does not
767 // trigger. Any current installed exception will be overwritten. This
768 // method will be called during an exception unwind.
769
770 assert(!HAS_PENDING_EXCEPTION, "no pending exception");
771 Handle exception(current, current->vm_result_oop());
772 assert(exception() != nullptr, "vm result should be set");
773 current->set_vm_result_oop(nullptr); // clear vm result before continuing (may cause memory leaks and assert failures)
774 exception = get_preinitialized_exception(vmClasses::IllegalMonitorStateException_klass(), CATCH);
775 current->set_vm_result_oop(exception());
776 JRT_END
777
778
779 //------------------------------------------------------------------------------------------------------------------------
780 // Invokes
781
782 JRT_ENTRY(Bytecodes::Code, InterpreterRuntime::get_original_bytecode_at(JavaThread* current, Method* method, address bcp))
783 return method->orig_bytecode_at(method->bci_from(bcp));
784 JRT_END
785
786 JRT_ENTRY(void, InterpreterRuntime::set_original_bytecode_at(JavaThread* current, Method* method, address bcp, Bytecodes::Code new_code))
787 method->set_orig_bytecode_at(method->bci_from(bcp), new_code);
788 JRT_END
789
790 JRT_ENTRY(void, InterpreterRuntime::_breakpoint(JavaThread* current, Method* method, address bcp))
791 JvmtiExport::post_raw_breakpoint(current, method, bcp);
792 JRT_END
793
794 void InterpreterRuntime::resolve_invoke(Bytecodes::Code bytecode, TRAPS) {
795 JavaThread* current = THREAD;
796 LastFrameAccessor last_frame(current);
797 // extract receiver from the outgoing argument list if necessary
1177 JFR_ONLY(Jfr::check_and_process_sample_request(current);)
1178 // This function is called by the interpreter when the return poll found a reason
1179 // to call the VM. The reason could be that we are returning into a not yet safe
1180 // to access frame. We handle that below.
1181 // Note that this path does not check for single stepping, because we do not want
1182 // to single step when unwinding frames for an exception being thrown. Instead,
1183 // such single stepping code will use the safepoint table, which will use the
1184 // InterpreterRuntime::at_safepoint callback.
1185 StackWatermarkSet::before_unwind(current);
1186 JRT_END
1187
1188 JRT_ENTRY(void, InterpreterRuntime::post_field_access(JavaThread* current, oopDesc* obj,
1189 ResolvedFieldEntry* entry))
1190
1191 // check the access_flags for the field in the klass
1192 InstanceKlass* ik = entry->field_holder();
1193 int index = entry->field_index();
1194 if (!ik->field_status(index).is_access_watched()) return;
1195
1196 bool is_static = (obj == nullptr);
1197 HandleMark hm(current);
1198
1199 Handle h_obj;
1200 if (!is_static) {
1201 // non-static field accessors have an object, but we need a handle
1202 h_obj = Handle(current, obj);
1203 }
1204 InstanceKlass* field_holder = entry->field_holder(); // HERE
1205 jfieldID fid = jfieldIDWorkaround::to_jfieldID(field_holder, entry->field_offset(), is_static);
1206 LastFrameAccessor last_frame(current);
1207 JvmtiExport::post_field_access(current, last_frame.method(), last_frame.bcp(), field_holder, h_obj, fid);
1208 JRT_END
1209
1210 JRT_ENTRY(void, InterpreterRuntime::post_field_modification(JavaThread* current, oopDesc* obj,
1211 ResolvedFieldEntry* entry, jvalue* value))
1212
1213 // check the access_flags for the field in the klass
1214 InstanceKlass* ik = entry->field_holder();
1215 int index = entry->field_index();
1216 // bail out if field modifications are not watched
1217 if (!ik->field_status(index).is_modification_watched()) return;
1218
1219 char sig_type = '\0';
1220
1221 switch((TosState)entry->tos_state()) {
1222 case btos: sig_type = JVM_SIGNATURE_BYTE; break;
1223 case ztos: sig_type = JVM_SIGNATURE_BOOLEAN; break;
1224 case ctos: sig_type = JVM_SIGNATURE_CHAR; break;
1225 case stos: sig_type = JVM_SIGNATURE_SHORT; break;
1226 case itos: sig_type = JVM_SIGNATURE_INT; break;
1227 case ftos: sig_type = JVM_SIGNATURE_FLOAT; break;
1228 case atos: sig_type = JVM_SIGNATURE_CLASS; break;
1229 case ltos: sig_type = JVM_SIGNATURE_LONG; break;
1230 case dtos: sig_type = JVM_SIGNATURE_DOUBLE; break;
1231 default: ShouldNotReachHere(); return;
1232 }
1233 bool is_static = (obj == nullptr);
1234
1235 HandleMark hm(current);
1236 jfieldID fid = jfieldIDWorkaround::to_jfieldID(ik, entry->field_offset(), is_static);
1237 jvalue fvalue;
1238 #ifdef _LP64
1239 fvalue = *value;
1240 #else
1241 // Long/double values are stored unaligned and also noncontiguously with
1242 // tagged stacks. We can't just do a simple assignment even in the non-
1243 // J/D cases because a C++ compiler is allowed to assume that a jvalue is
1244 // 8-byte aligned, and interpreter stack slots are only 4-byte aligned.
1245 // We assume that the two halves of longs/doubles are stored in interpreter
1246 // stack slots in platform-endian order.
1247 jlong_accessor u;
1248 jint* newval = (jint*)value;
1249 u.words[0] = newval[0];
1250 u.words[1] = newval[Interpreter::stackElementWords]; // skip if tag
1251 fvalue.j = u.long_value;
1252 #endif // _LP64
1253
1254 Handle h_obj;
1255 if (!is_static) {
1256 // non-static field accessors have an object, but we need a handle
|
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 "classfile/javaClasses.inline.hpp"
26 #include "classfile/symbolTable.hpp"
27 #include "classfile/systemDictionary.hpp"
28 #include "classfile/vmClasses.hpp"
29 #include "classfile/vmSymbols.hpp"
30 #include "code/codeCache.hpp"
31 #include "compiler/compilationPolicy.hpp"
32 #include "compiler/compileBroker.hpp"
33 #include "compiler/disassembler.hpp"
34 #include "gc/shared/barrierSetNMethod.hpp"
35 #include "gc/shared/collectedHeap.hpp"
36 #include "interpreter/bytecodeTracer.hpp"
37 #include "interpreter/interpreter.hpp"
38 #include "interpreter/interpreterRuntime.hpp"
39 #include "interpreter/linkResolver.hpp"
40 #include "interpreter/oopMapCache.hpp"
41 #include "interpreter/templateTable.hpp"
42 #include "jvm_io.h"
43 #include "logging/log.hpp"
44 #include "memory/oopFactory.hpp"
45 #include "memory/resourceArea.hpp"
46 #include "memory/universe.hpp"
47 #include "oops/constantPool.inline.hpp"
48 #include "oops/cpCache.inline.hpp"
49 #include "oops/flatArrayKlass.hpp"
50 #include "oops/flatArrayOop.inline.hpp"
51 #include "oops/inlineKlass.inline.hpp"
52 #include "oops/instanceKlass.inline.hpp"
53 #include "oops/klass.inline.hpp"
54 #include "oops/method.inline.hpp"
55 #include "oops/methodData.hpp"
56 #include "oops/objArrayKlass.hpp"
57 #include "oops/objArrayOop.inline.hpp"
58 #include "oops/oop.inline.hpp"
59 #include "oops/oopsHierarchy.hpp"
60 #include "oops/symbol.hpp"
61 #include "oops/valuePayload.inline.hpp"
62 #include "prims/jvmtiExport.hpp"
63 #include "prims/methodHandles.hpp"
64 #include "prims/nativeLookup.hpp"
65 #include "runtime/continuation.hpp"
66 #include "runtime/deoptimization.hpp"
67 #include "runtime/fieldDescriptor.inline.hpp"
68 #include "runtime/frame.inline.hpp"
69 #include "runtime/handles.inline.hpp"
70 #include "runtime/icache.hpp"
71 #include "runtime/interfaceSupport.inline.hpp"
72 #include "runtime/java.hpp"
73 #include "runtime/javaCalls.hpp"
74 #include "runtime/jfieldIDWorkaround.hpp"
75 #include "runtime/osThread.hpp"
76 #include "runtime/sharedRuntime.hpp"
77 #include "runtime/stackWatermarkSet.hpp"
78 #include "runtime/stubRoutines.hpp"
79 #include "runtime/synchronizer.hpp"
80 #include "utilities/align.hpp"
81 #include "utilities/checkedCast.hpp"
82 #include "utilities/copy.hpp"
83 #include "utilities/events.hpp"
84 #include "utilities/exceptions.hpp"
85 #include "utilities/globalDefinitions.hpp"
86 #if INCLUDE_JFR
87 #include "jfr/jfr.inline.hpp"
88 #endif
89
90 // Helper class to access current interpreter state
91 class LastFrameAccessor : public StackObj {
92 frame _last_frame;
93 public:
94 LastFrameAccessor(JavaThread* current) {
95 assert(current == Thread::current(), "sanity");
96 _last_frame = current->last_frame();
97 }
98 bool is_interpreted_frame() const { return _last_frame.is_interpreted_frame(); }
99 Method* method() const { return _last_frame.interpreter_frame_method(); }
100 address bcp() const { return _last_frame.interpreter_frame_bcp(); }
101 int bci() const { return _last_frame.interpreter_frame_bci(); }
102 address mdp() const { return _last_frame.interpreter_frame_mdp(); }
103
104 void set_bcp(address bcp) { _last_frame.interpreter_frame_set_bcp(bcp); }
105 void set_mdp(address dp) { _last_frame.interpreter_frame_set_mdp(dp); }
216 JRT_END
217
218
219 //------------------------------------------------------------------------------------------------------------------------
220 // Allocation
221
222 JRT_ENTRY(void, InterpreterRuntime::_new(JavaThread* current, ConstantPool* pool, int index))
223 Klass* k = pool->klass_at(index, CHECK);
224 InstanceKlass* klass = InstanceKlass::cast(k);
225
226 // Make sure we are not instantiating an abstract klass
227 klass->check_valid_for_instantiation(true, CHECK);
228
229 // Make sure klass is initialized
230 klass->initialize_preemptable(CHECK_AND_CLEAR_PREEMPTED);
231
232 oop obj = klass->allocate_instance(CHECK);
233 current->set_vm_result_oop(obj);
234 JRT_END
235
236 JRT_BLOCK_ENTRY(void, InterpreterRuntime::read_flat_field(JavaThread* current, oopDesc* obj, ResolvedFieldEntry* entry))
237 assert(oopDesc::is_oop(obj), "Sanity check");
238
239 FlatFieldPayload payload(instanceOop(obj), entry);
240 if (payload.is_payload_null()) {
241 // If the payload is null return before entering the JRT_BLOCK.
242 current->set_vm_result_oop(nullptr);
243 return;
244 }
245 JRT_BLOCK
246 oop res = payload.read(CHECK);
247 current->set_vm_result_oop(res);
248 JRT_BLOCK_END
249 JRT_END
250
251 JRT_ENTRY(void, InterpreterRuntime::write_flat_field(JavaThread* current, oopDesc* obj, oopDesc* value, ResolvedFieldEntry* entry))
252 assert(oopDesc::is_oop(obj), "Sanity check");
253 assert(oopDesc::is_oop_or_null(value), "Sanity check");
254
255 FlatFieldPayload payload(instanceOop(obj), entry);
256 payload.write(inlineOop(value), CHECK);
257 JRT_END
258
259 JRT_ENTRY(void, InterpreterRuntime::newarray(JavaThread* current, BasicType type, jint size))
260 oop obj = oopFactory::new_typeArray(type, size, CHECK);
261 current->set_vm_result_oop(obj);
262 JRT_END
263
264
265 JRT_ENTRY(void, InterpreterRuntime::anewarray(JavaThread* current, ConstantPool* pool, int index, jint size))
266 Klass* klass = pool->klass_at(index, CHECK);
267 objArrayOop obj = oopFactory::new_objArray(klass, size, CHECK);
268 current->set_vm_result_oop(obj);
269 JRT_END
270
271 JRT_ENTRY(void, InterpreterRuntime::flat_array_load(JavaThread* current, arrayOopDesc* array, int index))
272 assert(array->is_flatArray(), "Must be");
273 flatArrayOop farray = (flatArrayOop)array;
274 oop res = farray->obj_at(index, CHECK);
275 current->set_vm_result_oop(res);
276 JRT_END
277
278 JRT_ENTRY(void, InterpreterRuntime::flat_array_store(JavaThread* current, oopDesc* val, arrayOopDesc* array, int index))
279 assert(array->is_flatArray(), "Must be");
280 flatArrayOop farray = (flatArrayOop)array;
281 farray->obj_at_put(index, val, CHECK);
282 JRT_END
283
284 JRT_ENTRY(void, InterpreterRuntime::multianewarray(JavaThread* current, jint* first_size_address))
285 // We may want to pass in more arguments - could make this slightly faster
286 LastFrameAccessor last_frame(current);
287 ConstantPool* constants = last_frame.method()->constants();
288 int i = last_frame.get_index_u2(Bytecodes::_multianewarray);
289 Klass* klass = constants->klass_at(i, CHECK);
290 int nof_dims = last_frame.number_of_dimensions();
291 assert(klass->is_klass(), "not a class");
292 assert(nof_dims >= 1, "multianewarray rank must be nonzero");
293
294 // We must create an array of jints to pass to multi_allocate.
295 ResourceMark rm(current);
296 const int small_dims = 10;
297 jint dim_array[small_dims];
298 jint *dims = &dim_array[0];
299 if (nof_dims > small_dims) {
300 dims = (jint*) NEW_RESOURCE_ARRAY(jint, nof_dims);
301 }
302 for (int index = 0; index < nof_dims; index++) {
303 // offset from first_size_address is addressed as local[index]
304 int n = Interpreter::local_offset_in_bytes(index)/jintSize;
305 dims[index] = first_size_address[n];
306 }
307 oop obj = ArrayKlass::cast(klass)->multi_allocate(nof_dims, dims, CHECK);
308 current->set_vm_result_oop(obj);
309 JRT_END
310
311
312 JRT_ENTRY(void, InterpreterRuntime::register_finalizer(JavaThread* current, oopDesc* obj))
313 assert(oopDesc::is_oop(obj), "must be a valid oop");
314 assert(obj->klass()->has_finalizer(), "shouldn't be here otherwise");
315 InstanceKlass::register_finalizer(instanceOop(obj), CHECK);
316 JRT_END
317
318 JRT_ENTRY(jboolean, InterpreterRuntime::is_substitutable(JavaThread* current, oopDesc* aobj, oopDesc* bobj))
319 assert(oopDesc::is_oop(aobj) && oopDesc::is_oop(bobj), "must be valid oops");
320
321 Handle ha(THREAD, aobj);
322 Handle hb(THREAD, bobj);
323 JavaValue result(T_BOOLEAN);
324 JavaCallArguments args;
325 args.push_oop(ha);
326 args.push_oop(hb);
327 methodHandle method(current, Universe::is_substitutable_method());
328 method->method_holder()->initialize(CHECK_false); // Ensure class ValueObjectMethods is initialized
329 JavaCalls::call(&result, method, &args, THREAD);
330 Exceptions::wrap_exception_in_internal_error("Internal error in substitutability test", CHECK_false);
331
332 return result.get_jboolean();
333 JRT_END
334
335 // Quicken instance-of and check-cast bytecodes
336 JRT_ENTRY(void, InterpreterRuntime::quicken_io_cc(JavaThread* current))
337 // Force resolving; quicken the bytecode
338 LastFrameAccessor last_frame(current);
339 int which = last_frame.get_index_u2(Bytecodes::_checkcast);
340 ConstantPool* cpool = last_frame.method()->constants();
341 // We'd expect to assert that we're only here to quicken bytecodes, but in a multithreaded
342 // program we might have seen an unquick'd bytecode in the interpreter but have another
343 // thread quicken the bytecode before we get here.
344 // assert( cpool->tag_at(which).is_unresolved_klass(), "should only come here to quicken bytecodes" );
345 Klass* klass = cpool->klass_at(which, CHECK);
346 current->set_vm_result_metadata(klass);
347 JRT_END
348
349
350 //------------------------------------------------------------------------------------------------------------------------
351 // Exceptions
352
353 void InterpreterRuntime::note_trap_inner(JavaThread* current, int reason,
661 // and therefore we don't have the receiver object at our fingertips. (Though,
662 // on some platforms the receiver still resides in a register...). Thus,
663 // we have no choice but print an error message not containing the receiver
664 // type.
665 JRT_ENTRY(void, InterpreterRuntime::throw_AbstractMethodErrorWithMethod(JavaThread* current,
666 Method* missingMethod))
667 ResourceMark rm(current);
668 assert(missingMethod != nullptr, "sanity");
669 methodHandle m(current, missingMethod);
670 LinkResolver::throw_abstract_method_error(m, THREAD);
671 JRT_END
672
673 JRT_ENTRY(void, InterpreterRuntime::throw_AbstractMethodErrorVerbose(JavaThread* current,
674 Klass* recvKlass,
675 Method* missingMethod))
676 ResourceMark rm(current);
677 methodHandle mh = methodHandle(current, missingMethod);
678 LinkResolver::throw_abstract_method_error(mh, recvKlass, THREAD);
679 JRT_END
680
681 JRT_ENTRY(void, InterpreterRuntime::throw_IncompatibleClassChangeError(JavaThread* current))
682 THROW(vmSymbols::java_lang_IncompatibleClassChangeError());
683 JRT_END
684
685 JRT_ENTRY(void, InterpreterRuntime::throw_IncompatibleClassChangeErrorVerbose(JavaThread* current,
686 Klass* recvKlass,
687 Klass* interfaceKlass))
688 ResourceMark rm(current);
689 char buf[1000];
690 buf[0] = '\0';
691 jio_snprintf(buf, sizeof(buf),
692 "Class %s does not implement the requested interface %s",
693 recvKlass ? recvKlass->external_name() : "nullptr",
694 interfaceKlass ? interfaceKlass->external_name() : "nullptr");
695 THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
696 JRT_END
697
698 JRT_ENTRY(void, InterpreterRuntime::throw_NullPointerException(JavaThread* current))
699 THROW(vmSymbols::java_lang_NullPointerException());
700 JRT_END
739
740 // Resolution of put instructions to final instance fields with invalid updates (i.e.,
741 // to final instance fields with updates originating from a method different than <init>)
742 // is inhibited. A putfield instruction targeting an instance final field must throw
743 // an IllegalAccessError if the instruction is not in an instance
744 // initializer method <init>. If resolution were not inhibited, a putfield
745 // in an initializer method could be resolved in the initializer. Subsequent
746 // putfield instructions to the same field would then use cached information.
747 // As a result, those instructions would not pass through the VM. That is,
748 // checks in resolve_field_access() would not be executed for those instructions
749 // and the required IllegalAccessError would not be thrown.
750 //
751 // Also, we need to delay resolving getstatic and putstatic instructions until the
752 // class is initialized. This is required so that access to the static
753 // field will call the initialization function every time until the class
754 // is completely initialized ala. in 2.17.5 in JVM Specification.
755 InstanceKlass* klass = info.field_holder();
756 bool uninitialized_static = is_static && !klass->is_initialized();
757 bool has_initialized_final_update = info.field_holder()->major_version() >= 53 &&
758 info.has_initialized_final_update();
759 bool strict_static_final = info.is_strict() && info.is_static() && info.is_final();
760 assert(!(has_initialized_final_update && !info.access_flags().is_final()), "Fields with initialized final updates must be final");
761
762 Bytecodes::Code get_code = (Bytecodes::Code)0;
763 Bytecodes::Code put_code = (Bytecodes::Code)0;
764 if (uninitialized_static && (info.is_strict_static_unset() || strict_static_final)) {
765 // During <clinit>, closely track the state of strict statics.
766 // 1. if we are reading an uninitialized strict static, throw
767 // 2. if we are writing one, clear the "unset" flag
768 //
769 // Note: If we were handling an attempted write of a null to a
770 // null-restricted strict static, we would NOT clear the "unset"
771 // flag.
772 assert(klass->is_being_initialized(), "else should have thrown");
773 assert(klass->is_reentrant_initialization(THREAD),
774 "<clinit> must be running in current thread");
775 klass->notify_strict_static_access(info.index(), is_put, CHECK);
776 assert(!info.is_strict_static_unset(), "after initialization, no unset flags");
777 } else if (!uninitialized_static || VM_Version::supports_fast_class_init_checks()) {
778 get_code = ((is_static) ? Bytecodes::_getstatic : Bytecodes::_getfield);
779 if ((is_put && !has_initialized_final_update) || !info.access_flags().is_final()) {
780 put_code = ((is_static) ? Bytecodes::_putstatic : Bytecodes::_putfield);
781 }
782 }
783
784 ResolvedFieldEntry* entry = pool->resolved_field_entry_at(field_index);
785 entry->fill_in(info, checked_cast<u1>(state),
786 static_cast<u1>(get_code), static_cast<u1>(put_code));
787 }
788
789
790 //------------------------------------------------------------------------------------------------------------------------
791 // Synchronization
792 //
793 // The interpreter's synchronization code is factored out so that it can
794 // be shared by method invocation and synchronized blocks.
795 //%note synchronization_3
796
797 //%note monitor_1
828 JRT_END
829
830 JRT_ENTRY(void, InterpreterRuntime::throw_illegal_monitor_state_exception(JavaThread* current))
831 THROW(vmSymbols::java_lang_IllegalMonitorStateException());
832 JRT_END
833
834 JRT_ENTRY(void, InterpreterRuntime::new_illegal_monitor_state_exception(JavaThread* current))
835 // Returns an illegal exception to install into the current thread. The
836 // pending_exception flag is cleared so normal exception handling does not
837 // trigger. Any current installed exception will be overwritten. This
838 // method will be called during an exception unwind.
839
840 assert(!HAS_PENDING_EXCEPTION, "no pending exception");
841 Handle exception(current, current->vm_result_oop());
842 assert(exception() != nullptr, "vm result should be set");
843 current->set_vm_result_oop(nullptr); // clear vm result before continuing (may cause memory leaks and assert failures)
844 exception = get_preinitialized_exception(vmClasses::IllegalMonitorStateException_klass(), CATCH);
845 current->set_vm_result_oop(exception());
846 JRT_END
847
848 JRT_ENTRY(void, InterpreterRuntime::throw_identity_exception(JavaThread* current, oopDesc* obj))
849 Klass* klass = cast_to_oop(obj)->klass();
850 ResourceMark rm(THREAD);
851 const char* desc = "Cannot synchronize on an instance of value class ";
852 const char* className = klass->external_name();
853 size_t msglen = strlen(desc) + strlen(className) + 1;
854 char* message = NEW_RESOURCE_ARRAY(char, msglen);
855 if (nullptr == message) {
856 // Out of memory: can't create detailed error message
857 THROW_MSG(vmSymbols::java_lang_IdentityException(), className);
858 } else {
859 jio_snprintf(message, msglen, "%s%s", desc, className);
860 THROW_MSG(vmSymbols::java_lang_IdentityException(), message);
861 }
862 JRT_END
863
864 //------------------------------------------------------------------------------------------------------------------------
865 // Invokes
866
867 JRT_ENTRY(Bytecodes::Code, InterpreterRuntime::get_original_bytecode_at(JavaThread* current, Method* method, address bcp))
868 return method->orig_bytecode_at(method->bci_from(bcp));
869 JRT_END
870
871 JRT_ENTRY(void, InterpreterRuntime::set_original_bytecode_at(JavaThread* current, Method* method, address bcp, Bytecodes::Code new_code))
872 method->set_orig_bytecode_at(method->bci_from(bcp), new_code);
873 JRT_END
874
875 JRT_ENTRY(void, InterpreterRuntime::_breakpoint(JavaThread* current, Method* method, address bcp))
876 JvmtiExport::post_raw_breakpoint(current, method, bcp);
877 JRT_END
878
879 void InterpreterRuntime::resolve_invoke(Bytecodes::Code bytecode, TRAPS) {
880 JavaThread* current = THREAD;
881 LastFrameAccessor last_frame(current);
882 // extract receiver from the outgoing argument list if necessary
1262 JFR_ONLY(Jfr::check_and_process_sample_request(current);)
1263 // This function is called by the interpreter when the return poll found a reason
1264 // to call the VM. The reason could be that we are returning into a not yet safe
1265 // to access frame. We handle that below.
1266 // Note that this path does not check for single stepping, because we do not want
1267 // to single step when unwinding frames for an exception being thrown. Instead,
1268 // such single stepping code will use the safepoint table, which will use the
1269 // InterpreterRuntime::at_safepoint callback.
1270 StackWatermarkSet::before_unwind(current);
1271 JRT_END
1272
1273 JRT_ENTRY(void, InterpreterRuntime::post_field_access(JavaThread* current, oopDesc* obj,
1274 ResolvedFieldEntry* entry))
1275
1276 // check the access_flags for the field in the klass
1277 InstanceKlass* ik = entry->field_holder();
1278 int index = entry->field_index();
1279 if (!ik->field_status(index).is_access_watched()) return;
1280
1281 bool is_static = (obj == nullptr);
1282 bool is_flat = entry->is_flat();
1283 HandleMark hm(current);
1284
1285 Handle h_obj;
1286 if (!is_static) {
1287 // non-static field accessors have an object, but we need a handle
1288 h_obj = Handle(current, obj);
1289 }
1290 InstanceKlass* field_holder = entry->field_holder(); // HERE
1291 jfieldID fid = jfieldIDWorkaround::to_jfieldID(field_holder, entry->field_offset(), is_static, is_flat);
1292 LastFrameAccessor last_frame(current);
1293 JvmtiExport::post_field_access(current, last_frame.method(), last_frame.bcp(), field_holder, h_obj, fid);
1294 JRT_END
1295
1296 JRT_ENTRY(void, InterpreterRuntime::post_field_modification(JavaThread* current, oopDesc* obj,
1297 ResolvedFieldEntry* entry, jvalue* value))
1298
1299 // check the access_flags for the field in the klass
1300 InstanceKlass* ik = entry->field_holder();
1301 int index = entry->field_index();
1302 // bail out if field modifications are not watched
1303 if (!ik->field_status(index).is_modification_watched()) return;
1304
1305 char sig_type = '\0';
1306
1307 switch((TosState)entry->tos_state()) {
1308 case btos: sig_type = JVM_SIGNATURE_BYTE; break;
1309 case ztos: sig_type = JVM_SIGNATURE_BOOLEAN; break;
1310 case ctos: sig_type = JVM_SIGNATURE_CHAR; break;
1311 case stos: sig_type = JVM_SIGNATURE_SHORT; break;
1312 case itos: sig_type = JVM_SIGNATURE_INT; break;
1313 case ftos: sig_type = JVM_SIGNATURE_FLOAT; break;
1314 case atos: sig_type = JVM_SIGNATURE_CLASS; break;
1315 case ltos: sig_type = JVM_SIGNATURE_LONG; break;
1316 case dtos: sig_type = JVM_SIGNATURE_DOUBLE; break;
1317 default: ShouldNotReachHere(); return;
1318 }
1319
1320 bool is_static = (obj == nullptr);
1321 bool is_flat = entry->is_flat();
1322
1323 HandleMark hm(current);
1324 jfieldID fid = jfieldIDWorkaround::to_jfieldID(ik, entry->field_offset(), is_static, is_flat);
1325 jvalue fvalue;
1326 #ifdef _LP64
1327 fvalue = *value;
1328 #else
1329 // Long/double values are stored unaligned and also noncontiguously with
1330 // tagged stacks. We can't just do a simple assignment even in the non-
1331 // J/D cases because a C++ compiler is allowed to assume that a jvalue is
1332 // 8-byte aligned, and interpreter stack slots are only 4-byte aligned.
1333 // We assume that the two halves of longs/doubles are stored in interpreter
1334 // stack slots in platform-endian order.
1335 jlong_accessor u;
1336 jint* newval = (jint*)value;
1337 u.words[0] = newval[0];
1338 u.words[1] = newval[Interpreter::stackElementWords]; // skip if tag
1339 fvalue.j = u.long_value;
1340 #endif // _LP64
1341
1342 Handle h_obj;
1343 if (!is_static) {
1344 // non-static field accessors have an object, but we need a handle
|