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 "precompiled.hpp"
26 #include "classfile/javaClasses.inline.hpp"
27 #include "classfile/symbolTable.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/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/methodData.hpp"
51 #include "oops/method.inline.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/atomic.hpp"
60 #include "runtime/continuation.hpp"
61 #include "runtime/deoptimization.hpp"
62 #include "runtime/fieldDescriptor.inline.hpp"
63 #include "runtime/frame.inline.hpp"
64 #include "runtime/handles.inline.hpp"
65 #include "runtime/icache.hpp"
66 #include "runtime/interfaceSupport.inline.hpp"
67 #include "runtime/java.hpp"
68 #include "runtime/javaCalls.hpp"
69 #include "runtime/jfieldIDWorkaround.hpp"
70 #include "runtime/osThread.hpp"
71 #include "runtime/sharedRuntime.hpp"
72 #include "runtime/stackWatermarkSet.hpp"
73 #include "runtime/stubRoutines.hpp"
74 #include "runtime/synchronizer.hpp"
75 #include "runtime/threadCritical.hpp"
76 #include "utilities/align.hpp"
77 #include "utilities/checkedCast.hpp"
78 #include "utilities/copy.hpp"
79 #include "utilities/events.hpp"
80 #ifdef COMPILER2
81 #include "opto/runtime.hpp"
82 #endif
83
84 // Helper class to access current interpreter state
85 class LastFrameAccessor : public StackObj {
86 frame _last_frame;
87 public:
88 LastFrameAccessor(JavaThread* current) {
89 assert(current == Thread::current(), "sanity");
90 _last_frame = current->last_frame();
91 }
92 bool is_interpreted_frame() const { return _last_frame.is_interpreted_frame(); }
93 Method* method() const { return _last_frame.interpreter_frame_method(); }
94 address bcp() const { return _last_frame.interpreter_frame_bcp(); }
95 int bci() const { return _last_frame.interpreter_frame_bci(); }
96 address mdp() const { return _last_frame.interpreter_frame_mdp(); }
97
98 void set_bcp(address bcp) { _last_frame.interpreter_frame_set_bcp(bcp); }
99 void set_mdp(address dp) { _last_frame.interpreter_frame_set_mdp(dp); }
224 klass->initialize(CHECK);
225
226 // At this point the class may not be fully initialized
227 // because of recursive initialization. If it is fully
228 // initialized & has_finalized is not set, we rewrite
229 // it into its fast version (Note: no locking is needed
230 // here since this is an atomic byte write and can be
231 // done more than once).
232 //
233 // Note: In case of classes with has_finalized we don't
234 // rewrite since that saves us an extra check in
235 // the fast version which then would call the
236 // slow version anyway (and do a call back into
237 // Java).
238 // If we have a breakpoint, then we don't rewrite
239 // because the _breakpoint bytecode would be lost.
240 oop obj = klass->allocate_instance(CHECK);
241 current->set_vm_result(obj);
242 JRT_END
243
244
245 JRT_ENTRY(void, InterpreterRuntime::newarray(JavaThread* current, BasicType type, jint size))
246 oop obj = oopFactory::new_typeArray(type, size, CHECK);
247 current->set_vm_result(obj);
248 JRT_END
249
250
251 JRT_ENTRY(void, InterpreterRuntime::anewarray(JavaThread* current, ConstantPool* pool, int index, jint size))
252 Klass* klass = pool->klass_at(index, CHECK);
253 objArrayOop obj = oopFactory::new_objArray(klass, size, CHECK);
254 current->set_vm_result(obj);
255 JRT_END
256
257
258 JRT_ENTRY(void, InterpreterRuntime::multianewarray(JavaThread* current, jint* first_size_address))
259 // We may want to pass in more arguments - could make this slightly faster
260 LastFrameAccessor last_frame(current);
261 ConstantPool* constants = last_frame.method()->constants();
262 int i = last_frame.get_index_u2(Bytecodes::_multianewarray);
263 Klass* klass = constants->klass_at(i, CHECK);
264 int nof_dims = last_frame.number_of_dimensions();
265 assert(klass->is_klass(), "not a class");
266 assert(nof_dims >= 1, "multianewarray rank must be nonzero");
267
268 // We must create an array of jints to pass to multi_allocate.
269 ResourceMark rm(current);
270 const int small_dims = 10;
271 jint dim_array[small_dims];
272 jint *dims = &dim_array[0];
273 if (nof_dims > small_dims) {
274 dims = (jint*) NEW_RESOURCE_ARRAY(jint, nof_dims);
275 }
276 for (int index = 0; index < nof_dims; index++) {
277 // offset from first_size_address is addressed as local[index]
278 int n = Interpreter::local_offset_in_bytes(index)/jintSize;
279 dims[index] = first_size_address[n];
280 }
281 oop obj = ArrayKlass::cast(klass)->multi_allocate(nof_dims, dims, CHECK);
282 current->set_vm_result(obj);
283 JRT_END
284
285
286 JRT_ENTRY(void, InterpreterRuntime::register_finalizer(JavaThread* current, oopDesc* obj))
287 assert(oopDesc::is_oop(obj), "must be a valid oop");
288 assert(obj->klass()->has_finalizer(), "shouldn't be here otherwise");
289 InstanceKlass::register_finalizer(instanceOop(obj), CHECK);
290 JRT_END
291
292
293 // Quicken instance-of and check-cast bytecodes
294 JRT_ENTRY(void, InterpreterRuntime::quicken_io_cc(JavaThread* current))
295 // Force resolving; quicken the bytecode
296 LastFrameAccessor last_frame(current);
297 int which = last_frame.get_index_u2(Bytecodes::_checkcast);
298 ConstantPool* cpool = last_frame.method()->constants();
299 // We'd expect to assert that we're only here to quicken bytecodes, but in a multithreaded
300 // program we might have seen an unquick'd bytecode in the interpreter but have another
301 // thread quicken the bytecode before we get here.
302 // assert( cpool->tag_at(which).is_unresolved_klass(), "should only come here to quicken bytecodes" );
303 Klass* klass = cpool->klass_at(which, CHECK);
304 current->set_vm_result_2(klass);
305 JRT_END
306
307
308 //------------------------------------------------------------------------------------------------------------------------
309 // Exceptions
310
311 void InterpreterRuntime::note_trap_inner(JavaThread* current, int reason,
610 // and therefore we don't have the receiver object at our fingertips. (Though,
611 // on some platforms the receiver still resides in a register...). Thus,
612 // we have no choice but print an error message not containing the receiver
613 // type.
614 JRT_ENTRY(void, InterpreterRuntime::throw_AbstractMethodErrorWithMethod(JavaThread* current,
615 Method* missingMethod))
616 ResourceMark rm(current);
617 assert(missingMethod != nullptr, "sanity");
618 methodHandle m(current, missingMethod);
619 LinkResolver::throw_abstract_method_error(m, THREAD);
620 JRT_END
621
622 JRT_ENTRY(void, InterpreterRuntime::throw_AbstractMethodErrorVerbose(JavaThread* current,
623 Klass* recvKlass,
624 Method* missingMethod))
625 ResourceMark rm(current);
626 methodHandle mh = methodHandle(current, missingMethod);
627 LinkResolver::throw_abstract_method_error(mh, recvKlass, THREAD);
628 JRT_END
629
630
631 JRT_ENTRY(void, InterpreterRuntime::throw_IncompatibleClassChangeError(JavaThread* current))
632 THROW(vmSymbols::java_lang_IncompatibleClassChangeError());
633 JRT_END
634
635 JRT_ENTRY(void, InterpreterRuntime::throw_IncompatibleClassChangeErrorVerbose(JavaThread* current,
636 Klass* recvKlass,
637 Klass* interfaceKlass))
638 ResourceMark rm(current);
639 char buf[1000];
640 buf[0] = '\0';
641 jio_snprintf(buf, sizeof(buf),
642 "Class %s does not implement the requested interface %s",
643 recvKlass ? recvKlass->external_name() : "nullptr",
644 interfaceKlass ? interfaceKlass->external_name() : "nullptr");
645 THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
646 JRT_END
647
648 JRT_ENTRY(void, InterpreterRuntime::throw_NullPointerException(JavaThread* current))
649 THROW(vmSymbols::java_lang_NullPointerException());
690 // initializer method <init>. If resolution were not inhibited, a putfield
691 // in an initializer method could be resolved in the initializer. Subsequent
692 // putfield instructions to the same field would then use cached information.
693 // As a result, those instructions would not pass through the VM. That is,
694 // checks in resolve_field_access() would not be executed for those instructions
695 // and the required IllegalAccessError would not be thrown.
696 //
697 // Also, we need to delay resolving getstatic and putstatic instructions until the
698 // class is initialized. This is required so that access to the static
699 // field will call the initialization function every time until the class
700 // is completely initialized ala. in 2.17.5 in JVM Specification.
701 InstanceKlass* klass = info.field_holder();
702 bool uninitialized_static = is_static && !klass->is_initialized();
703 bool has_initialized_final_update = info.field_holder()->major_version() >= 53 &&
704 info.has_initialized_final_update();
705 assert(!(has_initialized_final_update && !info.access_flags().is_final()), "Fields with initialized final updates must be final");
706
707 Bytecodes::Code get_code = (Bytecodes::Code)0;
708 Bytecodes::Code put_code = (Bytecodes::Code)0;
709 if (!uninitialized_static) {
710 get_code = ((is_static) ? Bytecodes::_getstatic : Bytecodes::_getfield);
711 if ((is_put && !has_initialized_final_update) || !info.access_flags().is_final()) {
712 put_code = ((is_static) ? Bytecodes::_putstatic : Bytecodes::_putfield);
713 }
714 }
715
716 ResolvedFieldEntry* entry = pool->resolved_field_entry_at(field_index);
717 entry->set_flags(info.access_flags().is_final(), info.access_flags().is_volatile());
718 entry->fill_in(info.field_holder(), info.offset(),
719 checked_cast<u2>(info.index()), checked_cast<u1>(state),
720 static_cast<u1>(get_code), static_cast<u1>(put_code));
721 }
722
723
724 //------------------------------------------------------------------------------------------------------------------------
725 // Synchronization
726 //
727 // The interpreter's synchronization code is factored out so that it can
728 // be shared by method invocation and synchronized blocks.
729 //%note synchronization_3
730
731 //%note monitor_1
732 JRT_ENTRY_NO_ASYNC(void, InterpreterRuntime::monitorenter(JavaThread* current, BasicObjectLock* elem))
733 assert(LockingMode != LM_LIGHTWEIGHT, "Should call monitorenter_obj() when using the new lightweight locking");
734 #ifdef ASSERT
735 current->last_frame().interpreter_frame_verify_monitor(elem);
736 #endif
737 Handle h_obj(current, elem->obj());
1141 LastFrameAccessor last_frame(current);
1142 JvmtiExport::at_single_stepping_point(current, last_frame.method(), last_frame.bcp());
1143 }
1144 JRT_END
1145
1146 JRT_LEAF(void, InterpreterRuntime::at_unwind(JavaThread* current))
1147 assert(current == JavaThread::current(), "pre-condition");
1148 // This function is called by the interpreter when the return poll found a reason
1149 // to call the VM. The reason could be that we are returning into a not yet safe
1150 // to access frame. We handle that below.
1151 // Note that this path does not check for single stepping, because we do not want
1152 // to single step when unwinding frames for an exception being thrown. Instead,
1153 // such single stepping code will use the safepoint table, which will use the
1154 // InterpreterRuntime::at_safepoint callback.
1155 StackWatermarkSet::before_unwind(current);
1156 JRT_END
1157
1158 JRT_ENTRY(void, InterpreterRuntime::post_field_access(JavaThread* current, oopDesc* obj,
1159 ResolvedFieldEntry *entry))
1160
1161 // check the access_flags for the field in the klass
1162
1163 InstanceKlass* ik = entry->field_holder();
1164 int index = entry->field_index();
1165 if (!ik->field_status(index).is_access_watched()) return;
1166
1167 bool is_static = (obj == nullptr);
1168 HandleMark hm(current);
1169
1170 Handle h_obj;
1171 if (!is_static) {
1172 // non-static field accessors have an object, but we need a handle
1173 h_obj = Handle(current, obj);
1174 }
1175 InstanceKlass* field_holder = entry->field_holder(); // HERE
1176 jfieldID fid = jfieldIDWorkaround::to_jfieldID(field_holder, entry->field_offset(), is_static);
1177 LastFrameAccessor last_frame(current);
1178 JvmtiExport::post_field_access(current, last_frame.method(), last_frame.bcp(), field_holder, h_obj, fid);
1179 JRT_END
1180
1181 JRT_ENTRY(void, InterpreterRuntime::post_field_modification(JavaThread* current, oopDesc* obj,
1182 ResolvedFieldEntry *entry, jvalue *value))
1183
1184 InstanceKlass* ik = entry->field_holder();
1185
1186 // check the access_flags for the field in the klass
1187 int index = entry->field_index();
1188 // bail out if field modifications are not watched
1189 if (!ik->field_status(index).is_modification_watched()) return;
1190
1191 char sig_type = '\0';
1192
1193 switch((TosState)entry->tos_state()) {
1194 case btos: sig_type = JVM_SIGNATURE_BYTE; break;
1195 case ztos: sig_type = JVM_SIGNATURE_BOOLEAN; break;
1196 case ctos: sig_type = JVM_SIGNATURE_CHAR; break;
1197 case stos: sig_type = JVM_SIGNATURE_SHORT; break;
1198 case itos: sig_type = JVM_SIGNATURE_INT; break;
1199 case ftos: sig_type = JVM_SIGNATURE_FLOAT; break;
1200 case atos: sig_type = JVM_SIGNATURE_CLASS; break;
1201 case ltos: sig_type = JVM_SIGNATURE_LONG; break;
1202 case dtos: sig_type = JVM_SIGNATURE_DOUBLE; break;
1203 default: ShouldNotReachHere(); return;
1204 }
1205 bool is_static = (obj == nullptr);
1206
1207 HandleMark hm(current);
1208 jfieldID fid = jfieldIDWorkaround::to_jfieldID(ik, entry->field_offset(), is_static);
1209 jvalue fvalue;
1210 #ifdef _LP64
1211 fvalue = *value;
1212 #else
1213 // Long/double values are stored unaligned and also noncontiguously with
1214 // tagged stacks. We can't just do a simple assignment even in the non-
1215 // J/D cases because a C++ compiler is allowed to assume that a jvalue is
1216 // 8-byte aligned, and interpreter stack slots are only 4-byte aligned.
1217 // We assume that the two halves of longs/doubles are stored in interpreter
1218 // stack slots in platform-endian order.
1219 jlong_accessor u;
1220 jint* newval = (jint*)value;
1221 u.words[0] = newval[0];
1222 u.words[1] = newval[Interpreter::stackElementWords]; // skip if tag
1223 fvalue.j = u.long_value;
1224 #endif // _LP64
1225
1226 Handle h_obj;
1227 if (!is_static) {
1228 // non-static field accessors have an object, but we need a handle
|
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 "precompiled.hpp"
26 #include "classfile/javaClasses.inline.hpp"
27 #include "classfile/symbolTable.hpp"
28 #include "classfile/systemDictionary.hpp"
29 #include "classfile/vmClasses.hpp"
30 #include "classfile/vmSymbols.hpp"
31 #include "code/codeCache.hpp"
32 #include "compiler/compilationPolicy.hpp"
33 #include "compiler/compileBroker.hpp"
34 #include "compiler/disassembler.hpp"
35 #include "gc/shared/barrierSetNMethod.hpp"
36 #include "gc/shared/collectedHeap.hpp"
37 #include "interpreter/bytecodeTracer.hpp"
38 #include "interpreter/interpreter.hpp"
39 #include "interpreter/interpreterRuntime.hpp"
40 #include "interpreter/linkResolver.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/methodData.hpp"
55 #include "oops/method.inline.hpp"
56 #include "oops/objArrayKlass.hpp"
57 #include "oops/objArrayOop.inline.hpp"
58 #include "oops/oop.inline.hpp"
59 #include "oops/symbol.hpp"
60 #include "prims/jvmtiExport.hpp"
61 #include "prims/methodHandles.hpp"
62 #include "prims/nativeLookup.hpp"
63 #include "runtime/atomic.hpp"
64 #include "runtime/continuation.hpp"
65 #include "runtime/deoptimization.hpp"
66 #include "runtime/fieldDescriptor.inline.hpp"
67 #include "runtime/frame.inline.hpp"
68 #include "runtime/handles.inline.hpp"
69 #include "runtime/icache.hpp"
70 #include "runtime/interfaceSupport.inline.hpp"
71 #include "runtime/java.hpp"
72 #include "runtime/javaCalls.hpp"
73 #include "runtime/jfieldIDWorkaround.hpp"
74 #include "runtime/osThread.hpp"
75 #include "runtime/sharedRuntime.hpp"
76 #include "runtime/stackWatermarkSet.hpp"
77 #include "runtime/stubRoutines.hpp"
78 #include "runtime/synchronizer.hpp"
79 #include "runtime/threadCritical.hpp"
80 #include "utilities/align.hpp"
81 #include "utilities/checkedCast.hpp"
82 #include "utilities/copy.hpp"
83 #include "utilities/events.hpp"
84 #include "utilities/globalDefinitions.hpp"
85 #ifdef COMPILER2
86 #include "opto/runtime.hpp"
87 #endif
88
89 // Helper class to access current interpreter state
90 class LastFrameAccessor : public StackObj {
91 frame _last_frame;
92 public:
93 LastFrameAccessor(JavaThread* current) {
94 assert(current == Thread::current(), "sanity");
95 _last_frame = current->last_frame();
96 }
97 bool is_interpreted_frame() const { return _last_frame.is_interpreted_frame(); }
98 Method* method() const { return _last_frame.interpreter_frame_method(); }
99 address bcp() const { return _last_frame.interpreter_frame_bcp(); }
100 int bci() const { return _last_frame.interpreter_frame_bci(); }
101 address mdp() const { return _last_frame.interpreter_frame_mdp(); }
102
103 void set_bcp(address bcp) { _last_frame.interpreter_frame_set_bcp(bcp); }
104 void set_mdp(address dp) { _last_frame.interpreter_frame_set_mdp(dp); }
229 klass->initialize(CHECK);
230
231 // At this point the class may not be fully initialized
232 // because of recursive initialization. If it is fully
233 // initialized & has_finalized is not set, we rewrite
234 // it into its fast version (Note: no locking is needed
235 // here since this is an atomic byte write and can be
236 // done more than once).
237 //
238 // Note: In case of classes with has_finalized we don't
239 // rewrite since that saves us an extra check in
240 // the fast version which then would call the
241 // slow version anyway (and do a call back into
242 // Java).
243 // If we have a breakpoint, then we don't rewrite
244 // because the _breakpoint bytecode would be lost.
245 oop obj = klass->allocate_instance(CHECK);
246 current->set_vm_result(obj);
247 JRT_END
248
249 JRT_ENTRY(void, InterpreterRuntime::uninitialized_static_inline_type_field(JavaThread* current, oopDesc* mirror, ResolvedFieldEntry* entry))
250 // The interpreter tries to access an inline static field that has not been initialized.
251 // This situation can happen in different scenarios:
252 // 1 - if the load or initialization of the field failed during step 8 of
253 // the initialization of the holder of the field, in this case the access to the field
254 // must fail
255 // 2 - it can also happen when the initialization of the holder class triggered the initialization of
256 // another class which accesses this field in its static initializer, in this case the
257 // access must succeed to allow circularity
258 // The code below tries to load and initialize the field's class again before returning the default value.
259 // If the field was not initialized because of an error, an exception should be thrown.
260 // If the class is being initialized, the default value is returned.
261 assert(entry->is_valid(), "Invalid ResolvedFieldEntry");
262 instanceHandle mirror_h(THREAD, (instanceOop)mirror);
263 InstanceKlass* klass = entry->field_holder();
264 u2 index = entry->field_index();
265 assert(klass == java_lang_Class::as_Klass(mirror), "Not the field holder klass");
266 assert(klass->field_is_null_free_inline_type(index), "Sanity check");
267 if (klass->is_being_initialized() && klass->is_init_thread(THREAD)) {
268 int offset = klass->field_offset(index);
269 Klass* field_k = klass->get_inline_type_field_klass_or_null(index);
270 if (field_k == nullptr) {
271 field_k = SystemDictionary::resolve_or_fail(klass->field_signature(index)->fundamental_name(THREAD),
272 Handle(THREAD, klass->class_loader()),
273 Handle(THREAD, klass->protection_domain()),
274 true, CHECK);
275 assert(field_k != nullptr, "Should have been loaded or an exception thrown above");
276 klass->set_inline_type_field_klass(index, InlineKlass::cast(field_k));
277 }
278 field_k->initialize(CHECK);
279 oop defaultvalue = InlineKlass::cast(field_k)->default_value();
280 // It is safe to initialize the static field because 1) the current thread is the initializing thread
281 // and is the only one that can access it, and 2) the field is actually not initialized (i.e. null)
282 // otherwise the JVM should not be executing this code.
283 mirror_h()->obj_field_put(offset, defaultvalue);
284 current->set_vm_result(defaultvalue);
285 } else {
286 assert(klass->is_in_error_state(), "If not initializing, initialization must have failed to get there");
287 ResourceMark rm(THREAD);
288 const char* desc = "Could not initialize class ";
289 const char* className = klass->external_name();
290 size_t msglen = strlen(desc) + strlen(className) + 1;
291 char* message = NEW_RESOURCE_ARRAY(char, msglen);
292 if (nullptr == message) {
293 // Out of memory: can't create detailed error message
294 THROW_MSG(vmSymbols::java_lang_NoClassDefFoundError(), className);
295 } else {
296 jio_snprintf(message, msglen, "%s%s", desc, className);
297 THROW_MSG(vmSymbols::java_lang_NoClassDefFoundError(), message);
298 }
299 }
300 JRT_END
301
302 JRT_ENTRY(void, InterpreterRuntime::read_flat_field(JavaThread* current, oopDesc* obj, int index, Klass* field_holder))
303 Handle obj_h(THREAD, obj);
304
305 assert(oopDesc::is_oop(obj), "Sanity check");
306
307 assert(field_holder->is_instance_klass(), "Sanity check");
308 InstanceKlass* klass = InstanceKlass::cast(field_holder);
309
310 assert(klass->field_is_flat(index), "Sanity check");
311
312 InlineKlass* field_vklass = InlineKlass::cast(klass->get_inline_type_field_klass(index));
313
314 oop res = field_vklass->read_flat_field(obj_h(), klass->field_offset(index), CHECK);
315 current->set_vm_result(res);
316 JRT_END
317
318 JRT_ENTRY(void, InterpreterRuntime::newarray(JavaThread* current, BasicType type, jint size))
319 oop obj = oopFactory::new_typeArray(type, size, CHECK);
320 current->set_vm_result(obj);
321 JRT_END
322
323
324 JRT_ENTRY(void, InterpreterRuntime::anewarray(JavaThread* current, ConstantPool* pool, int index, jint size))
325 Klass* klass = pool->klass_at(index, CHECK);
326 arrayOop obj = oopFactory::new_objArray(klass, size, CHECK);
327 current->set_vm_result(obj);
328 JRT_END
329
330 JRT_ENTRY(void, InterpreterRuntime::value_array_load(JavaThread* current, arrayOopDesc* array, int index))
331 flatArrayHandle vah(current, (flatArrayOop)array);
332 oop value_holder = flatArrayOopDesc::value_alloc_copy_from_index(vah, index, CHECK);
333 current->set_vm_result(value_holder);
334 JRT_END
335
336 JRT_ENTRY(void, InterpreterRuntime::value_array_store(JavaThread* current, void* val, arrayOopDesc* array, int index))
337 assert(val != nullptr, "can't store null into flat array");
338 ((flatArrayOop)array)->value_copy_to_index(cast_to_oop(val), index);
339 JRT_END
340
341 JRT_ENTRY(void, InterpreterRuntime::multianewarray(JavaThread* current, jint* first_size_address))
342 // We may want to pass in more arguments - could make this slightly faster
343 LastFrameAccessor last_frame(current);
344 ConstantPool* constants = last_frame.method()->constants();
345 int i = last_frame.get_index_u2(Bytecodes::_multianewarray);
346 Klass* klass = constants->klass_at(i, CHECK);
347 int nof_dims = last_frame.number_of_dimensions();
348 assert(klass->is_klass(), "not a class");
349 assert(nof_dims >= 1, "multianewarray rank must be nonzero");
350
351 // We must create an array of jints to pass to multi_allocate.
352 ResourceMark rm(current);
353 const int small_dims = 10;
354 jint dim_array[small_dims];
355 jint *dims = &dim_array[0];
356 if (nof_dims > small_dims) {
357 dims = (jint*) NEW_RESOURCE_ARRAY(jint, nof_dims);
358 }
359 for (int index = 0; index < nof_dims; index++) {
360 // offset from first_size_address is addressed as local[index]
361 int n = Interpreter::local_offset_in_bytes(index)/jintSize;
362 dims[index] = first_size_address[n];
363 }
364 oop obj = ArrayKlass::cast(klass)->multi_allocate(nof_dims, dims, CHECK);
365 current->set_vm_result(obj);
366 JRT_END
367
368
369 JRT_ENTRY(void, InterpreterRuntime::register_finalizer(JavaThread* current, oopDesc* obj))
370 assert(oopDesc::is_oop(obj), "must be a valid oop");
371 assert(obj->klass()->has_finalizer(), "shouldn't be here otherwise");
372 InstanceKlass::register_finalizer(instanceOop(obj), CHECK);
373 JRT_END
374
375 JRT_ENTRY(jboolean, InterpreterRuntime::is_substitutable(JavaThread* current, oopDesc* aobj, oopDesc* bobj))
376 assert(oopDesc::is_oop(aobj) && oopDesc::is_oop(bobj), "must be valid oops");
377
378 Handle ha(THREAD, aobj);
379 Handle hb(THREAD, bobj);
380 JavaValue result(T_BOOLEAN);
381 JavaCallArguments args;
382 args.push_oop(ha);
383 args.push_oop(hb);
384 methodHandle method(current, Universe::is_substitutable_method());
385 JavaCalls::call(&result, method, &args, THREAD);
386 if (HAS_PENDING_EXCEPTION) {
387 // Something really bad happened because isSubstitutable() should not throw exceptions
388 // If it is an error, just let it propagate
389 // If it is an exception, wrap it into an InternalError
390 if (!PENDING_EXCEPTION->is_a(vmClasses::Error_klass())) {
391 Handle e(THREAD, PENDING_EXCEPTION);
392 CLEAR_PENDING_EXCEPTION;
393 THROW_MSG_CAUSE_(vmSymbols::java_lang_InternalError(), "Internal error in substitutability test", e, false);
394 }
395 }
396 return result.get_jboolean();
397 JRT_END
398
399 // Quicken instance-of and check-cast bytecodes
400 JRT_ENTRY(void, InterpreterRuntime::quicken_io_cc(JavaThread* current))
401 // Force resolving; quicken the bytecode
402 LastFrameAccessor last_frame(current);
403 int which = last_frame.get_index_u2(Bytecodes::_checkcast);
404 ConstantPool* cpool = last_frame.method()->constants();
405 // We'd expect to assert that we're only here to quicken bytecodes, but in a multithreaded
406 // program we might have seen an unquick'd bytecode in the interpreter but have another
407 // thread quicken the bytecode before we get here.
408 // assert( cpool->tag_at(which).is_unresolved_klass(), "should only come here to quicken bytecodes" );
409 Klass* klass = cpool->klass_at(which, CHECK);
410 current->set_vm_result_2(klass);
411 JRT_END
412
413
414 //------------------------------------------------------------------------------------------------------------------------
415 // Exceptions
416
417 void InterpreterRuntime::note_trap_inner(JavaThread* current, int reason,
716 // and therefore we don't have the receiver object at our fingertips. (Though,
717 // on some platforms the receiver still resides in a register...). Thus,
718 // we have no choice but print an error message not containing the receiver
719 // type.
720 JRT_ENTRY(void, InterpreterRuntime::throw_AbstractMethodErrorWithMethod(JavaThread* current,
721 Method* missingMethod))
722 ResourceMark rm(current);
723 assert(missingMethod != nullptr, "sanity");
724 methodHandle m(current, missingMethod);
725 LinkResolver::throw_abstract_method_error(m, THREAD);
726 JRT_END
727
728 JRT_ENTRY(void, InterpreterRuntime::throw_AbstractMethodErrorVerbose(JavaThread* current,
729 Klass* recvKlass,
730 Method* missingMethod))
731 ResourceMark rm(current);
732 methodHandle mh = methodHandle(current, missingMethod);
733 LinkResolver::throw_abstract_method_error(mh, recvKlass, THREAD);
734 JRT_END
735
736 JRT_ENTRY(void, InterpreterRuntime::throw_InstantiationError(JavaThread* current))
737 THROW(vmSymbols::java_lang_InstantiationError());
738 JRT_END
739
740
741 JRT_ENTRY(void, InterpreterRuntime::throw_IncompatibleClassChangeError(JavaThread* current))
742 THROW(vmSymbols::java_lang_IncompatibleClassChangeError());
743 JRT_END
744
745 JRT_ENTRY(void, InterpreterRuntime::throw_IncompatibleClassChangeErrorVerbose(JavaThread* current,
746 Klass* recvKlass,
747 Klass* interfaceKlass))
748 ResourceMark rm(current);
749 char buf[1000];
750 buf[0] = '\0';
751 jio_snprintf(buf, sizeof(buf),
752 "Class %s does not implement the requested interface %s",
753 recvKlass ? recvKlass->external_name() : "nullptr",
754 interfaceKlass ? interfaceKlass->external_name() : "nullptr");
755 THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
756 JRT_END
757
758 JRT_ENTRY(void, InterpreterRuntime::throw_NullPointerException(JavaThread* current))
759 THROW(vmSymbols::java_lang_NullPointerException());
800 // initializer method <init>. If resolution were not inhibited, a putfield
801 // in an initializer method could be resolved in the initializer. Subsequent
802 // putfield instructions to the same field would then use cached information.
803 // As a result, those instructions would not pass through the VM. That is,
804 // checks in resolve_field_access() would not be executed for those instructions
805 // and the required IllegalAccessError would not be thrown.
806 //
807 // Also, we need to delay resolving getstatic and putstatic instructions until the
808 // class is initialized. This is required so that access to the static
809 // field will call the initialization function every time until the class
810 // is completely initialized ala. in 2.17.5 in JVM Specification.
811 InstanceKlass* klass = info.field_holder();
812 bool uninitialized_static = is_static && !klass->is_initialized();
813 bool has_initialized_final_update = info.field_holder()->major_version() >= 53 &&
814 info.has_initialized_final_update();
815 assert(!(has_initialized_final_update && !info.access_flags().is_final()), "Fields with initialized final updates must be final");
816
817 Bytecodes::Code get_code = (Bytecodes::Code)0;
818 Bytecodes::Code put_code = (Bytecodes::Code)0;
819 if (!uninitialized_static) {
820 if (is_static) {
821 get_code = Bytecodes::_getstatic;
822 } else {
823 get_code = Bytecodes::_getfield;
824 }
825 if ((is_put && !has_initialized_final_update) || !info.access_flags().is_final()) {
826 put_code = ((is_static) ? Bytecodes::_putstatic : Bytecodes::_putfield);
827 }
828 }
829
830 ResolvedFieldEntry* entry = pool->resolved_field_entry_at(field_index);
831 entry->set_flags(info.access_flags().is_final(), info.access_flags().is_volatile(),
832 info.is_flat(), info.is_null_free_inline_type());
833 entry->fill_in(info.field_holder(), info.offset(),
834 checked_cast<u2>(info.index()), checked_cast<u1>(state),
835 static_cast<u1>(get_code), static_cast<u1>(put_code));
836 }
837
838
839 //------------------------------------------------------------------------------------------------------------------------
840 // Synchronization
841 //
842 // The interpreter's synchronization code is factored out so that it can
843 // be shared by method invocation and synchronized blocks.
844 //%note synchronization_3
845
846 //%note monitor_1
847 JRT_ENTRY_NO_ASYNC(void, InterpreterRuntime::monitorenter(JavaThread* current, BasicObjectLock* elem))
848 assert(LockingMode != LM_LIGHTWEIGHT, "Should call monitorenter_obj() when using the new lightweight locking");
849 #ifdef ASSERT
850 current->last_frame().interpreter_frame_verify_monitor(elem);
851 #endif
852 Handle h_obj(current, elem->obj());
1256 LastFrameAccessor last_frame(current);
1257 JvmtiExport::at_single_stepping_point(current, last_frame.method(), last_frame.bcp());
1258 }
1259 JRT_END
1260
1261 JRT_LEAF(void, InterpreterRuntime::at_unwind(JavaThread* current))
1262 assert(current == JavaThread::current(), "pre-condition");
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 assert(entry->is_valid(), "Invalid ResolvedFieldEntry");
1277 // check the access_flags for the field in the klass
1278
1279 InstanceKlass* ik = entry->field_holder();
1280 int index = entry->field_index();
1281 if (!ik->field_status(index).is_access_watched()) return;
1282
1283 bool is_static = (obj == nullptr);
1284 bool is_flat = entry->is_flat();
1285 HandleMark hm(current);
1286
1287 Handle h_obj;
1288 if (!is_static) {
1289 // non-static field accessors have an object, but we need a handle
1290 h_obj = Handle(current, obj);
1291 }
1292 InstanceKlass* field_holder = entry->field_holder(); // HERE
1293 jfieldID fid = jfieldIDWorkaround::to_jfieldID(field_holder, entry->field_offset(), is_static, is_flat);
1294 LastFrameAccessor last_frame(current);
1295 JvmtiExport::post_field_access(current, last_frame.method(), last_frame.bcp(), field_holder, h_obj, fid);
1296 JRT_END
1297
1298 JRT_ENTRY(void, InterpreterRuntime::post_field_modification(JavaThread* current, oopDesc* obj,
1299 ResolvedFieldEntry *entry, jvalue *value))
1300
1301 assert(entry->is_valid(), "Invalid ResolvedFieldEntry");
1302 InstanceKlass* ik = entry->field_holder();
1303
1304 // check the access_flags for the field in the klass
1305 int index = entry->field_index();
1306 // bail out if field modifications are not watched
1307 if (!ik->field_status(index).is_modification_watched()) return;
1308
1309 char sig_type = '\0';
1310
1311 switch((TosState)entry->tos_state()) {
1312 case btos: sig_type = JVM_SIGNATURE_BYTE; break;
1313 case ztos: sig_type = JVM_SIGNATURE_BOOLEAN; break;
1314 case ctos: sig_type = JVM_SIGNATURE_CHAR; break;
1315 case stos: sig_type = JVM_SIGNATURE_SHORT; break;
1316 case itos: sig_type = JVM_SIGNATURE_INT; break;
1317 case ftos: sig_type = JVM_SIGNATURE_FLOAT; break;
1318 case atos: sig_type = JVM_SIGNATURE_CLASS; break;
1319 case ltos: sig_type = JVM_SIGNATURE_LONG; break;
1320 case dtos: sig_type = JVM_SIGNATURE_DOUBLE; break;
1321 default: ShouldNotReachHere(); return;
1322 }
1323
1324 bool is_static = (obj == nullptr);
1325 bool is_flat = entry->is_flat();
1326
1327 HandleMark hm(current);
1328 jfieldID fid = jfieldIDWorkaround::to_jfieldID(ik, entry->field_offset(), is_static, is_flat);
1329 jvalue fvalue;
1330 #ifdef _LP64
1331 fvalue = *value;
1332 #else
1333 // Long/double values are stored unaligned and also noncontiguously with
1334 // tagged stacks. We can't just do a simple assignment even in the non-
1335 // J/D cases because a C++ compiler is allowed to assume that a jvalue is
1336 // 8-byte aligned, and interpreter stack slots are only 4-byte aligned.
1337 // We assume that the two halves of longs/doubles are stored in interpreter
1338 // stack slots in platform-endian order.
1339 jlong_accessor u;
1340 jint* newval = (jint*)value;
1341 u.words[0] = newval[0];
1342 u.words[1] = newval[Interpreter::stackElementWords]; // skip if tag
1343 fvalue.j = u.long_value;
1344 #endif // _LP64
1345
1346 Handle h_obj;
1347 if (!is_static) {
1348 // non-static field accessors have an object, but we need a handle
|