30 #include "compiler/compileBroker.hpp"
31 #include "compiler/disassembler.hpp"
32 #include "gc/shared/barrierSetNMethod.hpp"
33 #include "gc/shared/collectedHeap.hpp"
34 #include "interpreter/interpreter.hpp"
35 #include "interpreter/interpreterRuntime.hpp"
36 #include "interpreter/linkResolver.hpp"
37 #include "interpreter/templateTable.hpp"
38 #include "logging/log.hpp"
39 #include "memory/oopFactory.hpp"
40 #include "memory/resourceArea.hpp"
41 #include "memory/universe.hpp"
42 #include "oops/constantPool.hpp"
43 #include "oops/cpCache.inline.hpp"
44 #include "oops/instanceKlass.hpp"
45 #include "oops/methodData.hpp"
46 #include "oops/objArrayKlass.hpp"
47 #include "oops/objArrayOop.inline.hpp"
48 #include "oops/oop.inline.hpp"
49 #include "oops/symbol.hpp"
50 #include "prims/jvmtiExport.hpp"
51 #include "prims/nativeLookup.hpp"
52 #include "runtime/atomic.hpp"
53 #include "runtime/biasedLocking.hpp"
54 #include "runtime/compilationPolicy.hpp"
55 #include "runtime/deoptimization.hpp"
56 #include "runtime/fieldDescriptor.inline.hpp"
57 #include "runtime/frame.inline.hpp"
58 #include "runtime/handles.inline.hpp"
59 #include "runtime/icache.hpp"
60 #include "runtime/interfaceSupport.inline.hpp"
61 #include "runtime/java.hpp"
62 #include "runtime/javaCalls.hpp"
63 #include "runtime/jfieldIDWorkaround.hpp"
64 #include "runtime/osThread.hpp"
65 #include "runtime/sharedRuntime.hpp"
66 #include "runtime/stubRoutines.hpp"
67 #include "runtime/synchronizer.hpp"
68 #include "runtime/threadCritical.hpp"
69 #include "utilities/align.hpp"
70 #include "utilities/copy.hpp"
71 #include "utilities/events.hpp"
72 #ifdef COMPILER2
73 #include "opto/runtime.hpp"
74 #endif
75
76 class UnlockFlagSaver {
77 private:
78 JavaThread* _thread;
79 bool _do_not_unlock;
80 public:
81 UnlockFlagSaver(JavaThread* t) {
82 _thread = t;
83 _do_not_unlock = t->do_not_unlock_if_synchronized();
84 t->set_do_not_unlock_if_synchronized(false);
85 }
86 ~UnlockFlagSaver() {
87 _thread->set_do_not_unlock_if_synchronized(_do_not_unlock);
88 }
89 };
90
91 // Helper class to access current interpreter state
236 klass->initialize(CHECK);
237
238 // At this point the class may not be fully initialized
239 // because of recursive initialization. If it is fully
240 // initialized & has_finalized is not set, we rewrite
241 // it into its fast version (Note: no locking is needed
242 // here since this is an atomic byte write and can be
243 // done more than once).
244 //
245 // Note: In case of classes with has_finalized we don't
246 // rewrite since that saves us an extra check in
247 // the fast version which then would call the
248 // slow version anyway (and do a call back into
249 // Java).
250 // If we have a breakpoint, then we don't rewrite
251 // because the _breakpoint bytecode would be lost.
252 oop obj = klass->allocate_instance(CHECK);
253 thread->set_vm_result(obj);
254 IRT_END
255
256
257 IRT_ENTRY(void, InterpreterRuntime::newarray(JavaThread* thread, BasicType type, jint size))
258 oop obj = oopFactory::new_typeArray(type, size, CHECK);
259 thread->set_vm_result(obj);
260 IRT_END
261
262
263 IRT_ENTRY(void, InterpreterRuntime::anewarray(JavaThread* thread, ConstantPool* pool, int index, jint size))
264 Klass* klass = pool->klass_at(index, CHECK);
265 objArrayOop obj = oopFactory::new_objArray(klass, size, CHECK);
266 thread->set_vm_result(obj);
267 IRT_END
268
269
270 IRT_ENTRY(void, InterpreterRuntime::multianewarray(JavaThread* thread, jint* first_size_address))
271 // We may want to pass in more arguments - could make this slightly faster
272 LastFrameAccessor last_frame(thread);
273 ConstantPool* constants = last_frame.method()->constants();
274 int i = last_frame.get_index_u2(Bytecodes::_multianewarray);
275 Klass* klass = constants->klass_at(i, CHECK);
276 int nof_dims = last_frame.number_of_dimensions();
277 assert(klass->is_klass(), "not a class");
278 assert(nof_dims >= 1, "multianewarray rank must be nonzero");
279
280 // We must create an array of jints to pass to multi_allocate.
281 ResourceMark rm(thread);
282 const int small_dims = 10;
283 jint dim_array[small_dims];
284 jint *dims = &dim_array[0];
285 if (nof_dims > small_dims) {
286 dims = (jint*) NEW_RESOURCE_ARRAY(jint, nof_dims);
287 }
288 for (int index = 0; index < nof_dims; index++) {
289 // offset from first_size_address is addressed as local[index]
290 int n = Interpreter::local_offset_in_bytes(index)/jintSize;
291 dims[index] = first_size_address[n];
292 }
293 oop obj = ArrayKlass::cast(klass)->multi_allocate(nof_dims, dims, CHECK);
294 thread->set_vm_result(obj);
295 IRT_END
296
297
298 IRT_ENTRY(void, InterpreterRuntime::register_finalizer(JavaThread* thread, oopDesc* obj))
299 assert(oopDesc::is_oop(obj), "must be a valid oop");
670 buf[0] = '\0';
671 jio_snprintf(buf, sizeof(buf),
672 "Class %s does not implement the requested interface %s",
673 recvKlass ? recvKlass->external_name() : "NULL",
674 interfaceKlass ? interfaceKlass->external_name() : "NULL");
675 THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
676 IRT_END
677
678 //------------------------------------------------------------------------------------------------------------------------
679 // Fields
680 //
681
682 void InterpreterRuntime::resolve_get_put(JavaThread* thread, Bytecodes::Code bytecode) {
683 Thread* THREAD = thread;
684 // resolve field
685 fieldDescriptor info;
686 LastFrameAccessor last_frame(thread);
687 constantPoolHandle pool(thread, last_frame.method()->constants());
688 methodHandle m(thread, last_frame.method());
689 bool is_put = (bytecode == Bytecodes::_putfield || bytecode == Bytecodes::_nofast_putfield ||
690 bytecode == Bytecodes::_putstatic);
691 bool is_static = (bytecode == Bytecodes::_getstatic || bytecode == Bytecodes::_putstatic);
692
693 {
694 JvmtiHideSingleStepping jhss(thread);
695 LinkResolver::resolve_field_access(info, pool, last_frame.get_index_u2_cpcache(bytecode),
696 m, bytecode, CHECK);
697 } // end JvmtiHideSingleStepping
698
699 // check if link resolution caused cpCache to be updated
700 ConstantPoolCacheEntry* cp_cache_entry = last_frame.cache_entry();
701 if (cp_cache_entry->is_resolved(bytecode)) return;
702
703 // compute auxiliary field attributes
704 TosState state = as_TosState(info.field_type());
705
706 // Resolution of put instructions on final fields is delayed. That is required so that
707 // exceptions are thrown at the correct place (when the instruction is actually invoked).
708 // If we do not resolve an instruction in the current pass, leaving the put_code
709 // set to zero will cause the next put instruction to the same field to reresolve.
710
711 // Resolution of put instructions to final instance fields with invalid updates (i.e.,
715 // initializer method <init>. If resolution were not inhibited, a putfield
716 // in an initializer method could be resolved in the initializer. Subsequent
717 // putfield instructions to the same field would then use cached information.
718 // As a result, those instructions would not pass through the VM. That is,
719 // checks in resolve_field_access() would not be executed for those instructions
720 // and the required IllegalAccessError would not be thrown.
721 //
722 // Also, we need to delay resolving getstatic and putstatic instructions until the
723 // class is initialized. This is required so that access to the static
724 // field will call the initialization function every time until the class
725 // is completely initialized ala. in 2.17.5 in JVM Specification.
726 InstanceKlass* klass = info.field_holder();
727 bool uninitialized_static = is_static && !klass->is_initialized();
728 bool has_initialized_final_update = info.field_holder()->major_version() >= 53 &&
729 info.has_initialized_final_update();
730 assert(!(has_initialized_final_update && !info.access_flags().is_final()), "Fields with initialized final updates must be final");
731
732 Bytecodes::Code get_code = (Bytecodes::Code)0;
733 Bytecodes::Code put_code = (Bytecodes::Code)0;
734 if (!uninitialized_static) {
735 get_code = ((is_static) ? Bytecodes::_getstatic : Bytecodes::_getfield);
736 if ((is_put && !has_initialized_final_update) || !info.access_flags().is_final()) {
737 put_code = ((is_static) ? Bytecodes::_putstatic : Bytecodes::_putfield);
738 }
739 }
740
741 cp_cache_entry->set_field(
742 get_code,
743 put_code,
744 info.field_holder(),
745 info.index(),
746 info.offset(),
747 state,
748 info.access_flags().is_final(),
749 info.access_flags().is_volatile(),
750 pool->pool_holder()
751 );
752 }
753
754
755 //------------------------------------------------------------------------------------------------------------------------
756 // Synchronization
757 //
758 // The interpreter's synchronization code is factored out so that it can
759 // be shared by method invocation and synchronized blocks.
760 //%note synchronization_3
761
762 //%note monitor_1
763 IRT_ENTRY_NO_ASYNC(void, InterpreterRuntime::monitorenter(JavaThread* thread, BasicObjectLock* elem))
764 #ifdef ASSERT
765 thread->last_frame().interpreter_frame_verify_monitor(elem);
766 #endif
767 if (PrintBiasedLockingStatistics) {
768 Atomic::inc(BiasedLocking::slow_path_entry_count_addr());
769 }
840 method->set_orig_bytecode_at(method->bci_from(bcp), new_code);
841 IRT_END
842
843 IRT_ENTRY(void, InterpreterRuntime::_breakpoint(JavaThread* thread, Method* method, address bcp))
844 JvmtiExport::post_raw_breakpoint(thread, method, bcp);
845 IRT_END
846
847 void InterpreterRuntime::resolve_invoke(JavaThread* thread, Bytecodes::Code bytecode) {
848 Thread* THREAD = thread;
849 LastFrameAccessor last_frame(thread);
850 // extract receiver from the outgoing argument list if necessary
851 Handle receiver(thread, NULL);
852 if (bytecode == Bytecodes::_invokevirtual || bytecode == Bytecodes::_invokeinterface ||
853 bytecode == Bytecodes::_invokespecial) {
854 ResourceMark rm(thread);
855 methodHandle m (thread, last_frame.method());
856 Bytecode_invoke call(m, last_frame.bci());
857 Symbol* signature = call.signature();
858 receiver = Handle(thread, last_frame.callee_receiver(signature));
859
860 assert(Universe::heap()->is_in_reserved_or_null(receiver()),
861 "sanity check");
862 assert(receiver.is_null() ||
863 !Universe::heap()->is_in_reserved(receiver->klass()),
864 "sanity check");
865 }
866
867 // resolve method
868 CallInfo info;
869 constantPoolHandle pool(thread, last_frame.method()->constants());
870
871 {
872 JvmtiHideSingleStepping jhss(thread);
873 LinkResolver::resolve_invoke(info, receiver, pool,
874 last_frame.get_index_u2_cpcache(bytecode), bytecode,
875 CHECK);
876 if (JvmtiExport::can_hotswap_or_post_breakpoint()) {
877 int retry_count = 0;
878 while (info.resolved_method()->is_old()) {
879 // It is very unlikely that method is redefined more than 100 times
880 // in the middle of resolve. If it is looping here more than 100 times
881 // means then there could be a bug here.
983 int index = last_frame.get_index_u4(bytecode);
984 {
985 JvmtiHideSingleStepping jhss(thread);
986 LinkResolver::resolve_invoke(info, Handle(), pool,
987 index, bytecode, CHECK);
988 } // end JvmtiHideSingleStepping
989
990 ConstantPoolCacheEntry* cp_cache_entry = pool->invokedynamic_cp_cache_entry_at(index);
991 cp_cache_entry->set_dynamic_call(pool, info);
992 }
993
994 // This function is the interface to the assembly code. It returns the resolved
995 // cpCache entry. This doesn't safepoint, but the helper routines safepoint.
996 // This function will check for redefinition!
997 IRT_ENTRY(void, InterpreterRuntime::resolve_from_cache(JavaThread* thread, Bytecodes::Code bytecode)) {
998 switch (bytecode) {
999 case Bytecodes::_getstatic:
1000 case Bytecodes::_putstatic:
1001 case Bytecodes::_getfield:
1002 case Bytecodes::_putfield:
1003 resolve_get_put(thread, bytecode);
1004 break;
1005 case Bytecodes::_invokevirtual:
1006 case Bytecodes::_invokespecial:
1007 case Bytecodes::_invokestatic:
1008 case Bytecodes::_invokeinterface:
1009 resolve_invoke(thread, bytecode);
1010 break;
1011 case Bytecodes::_invokehandle:
1012 resolve_invokehandle(thread);
1013 break;
1014 case Bytecodes::_invokedynamic:
1015 resolve_invokedynamic(thread);
1016 break;
1017 default:
1018 fatal("unexpected bytecode: %s", Bytecodes::name(bytecode));
1019 break;
1020 }
1021 }
1022 IRT_END
1247 // check the access_flags for the field in the klass
1248 InstanceKlass* ik = InstanceKlass::cast(k);
1249 int index = cp_entry->field_index();
1250 // bail out if field modifications are not watched
1251 if ((ik->field_access_flags(index) & JVM_ACC_FIELD_MODIFICATION_WATCHED) == 0) return;
1252
1253 char sig_type = '\0';
1254
1255 switch(cp_entry->flag_state()) {
1256 case btos: sig_type = 'B'; break;
1257 case ztos: sig_type = 'Z'; break;
1258 case ctos: sig_type = 'C'; break;
1259 case stos: sig_type = 'S'; break;
1260 case itos: sig_type = 'I'; break;
1261 case ftos: sig_type = 'F'; break;
1262 case atos: sig_type = 'L'; break;
1263 case ltos: sig_type = 'J'; break;
1264 case dtos: sig_type = 'D'; break;
1265 default: ShouldNotReachHere(); return;
1266 }
1267 bool is_static = (obj == NULL);
1268
1269 HandleMark hm(thread);
1270 jfieldID fid = jfieldIDWorkaround::to_jfieldID(ik, cp_entry->f2_as_index(), is_static);
1271 jvalue fvalue;
1272 #ifdef _LP64
1273 fvalue = *value;
1274 #else
1275 // Long/double values are stored unaligned and also noncontiguously with
1276 // tagged stacks. We can't just do a simple assignment even in the non-
1277 // J/D cases because a C++ compiler is allowed to assume that a jvalue is
1278 // 8-byte aligned, and interpreter stack slots are only 4-byte aligned.
1279 // We assume that the two halves of longs/doubles are stored in interpreter
1280 // stack slots in platform-endian order.
1281 jlong_accessor u;
1282 jint* newval = (jint*)value;
1283 u.words[0] = newval[0];
1284 u.words[1] = newval[Interpreter::stackElementWords]; // skip if tag
1285 fvalue.j = u.long_value;
1286 #endif // _LP64
|
30 #include "compiler/compileBroker.hpp"
31 #include "compiler/disassembler.hpp"
32 #include "gc/shared/barrierSetNMethod.hpp"
33 #include "gc/shared/collectedHeap.hpp"
34 #include "interpreter/interpreter.hpp"
35 #include "interpreter/interpreterRuntime.hpp"
36 #include "interpreter/linkResolver.hpp"
37 #include "interpreter/templateTable.hpp"
38 #include "logging/log.hpp"
39 #include "memory/oopFactory.hpp"
40 #include "memory/resourceArea.hpp"
41 #include "memory/universe.hpp"
42 #include "oops/constantPool.hpp"
43 #include "oops/cpCache.inline.hpp"
44 #include "oops/instanceKlass.hpp"
45 #include "oops/methodData.hpp"
46 #include "oops/objArrayKlass.hpp"
47 #include "oops/objArrayOop.inline.hpp"
48 #include "oops/oop.inline.hpp"
49 #include "oops/symbol.hpp"
50 #include "oops/valueKlass.hpp"
51 #include "oops/valueArrayKlass.hpp"
52 #include "oops/valueArrayOop.hpp"
53 #include "oops/valueArrayOop.inline.hpp"
54 #include "prims/jvmtiExport.hpp"
55 #include "prims/nativeLookup.hpp"
56 #include "runtime/atomic.hpp"
57 #include "runtime/biasedLocking.hpp"
58 #include "runtime/compilationPolicy.hpp"
59 #include "runtime/deoptimization.hpp"
60 #include "runtime/fieldDescriptor.inline.hpp"
61 #include "runtime/frame.inline.hpp"
62 #include "runtime/handles.inline.hpp"
63 #include "runtime/icache.hpp"
64 #include "runtime/interfaceSupport.inline.hpp"
65 #include "runtime/java.hpp"
66 #include "runtime/javaCalls.hpp"
67 #include "runtime/jfieldIDWorkaround.hpp"
68 #include "runtime/osThread.hpp"
69 #include "runtime/sharedRuntime.hpp"
70 #include "runtime/stubRoutines.hpp"
71 #include "runtime/synchronizer.hpp"
72 #include "runtime/threadCritical.hpp"
73 #include "utilities/align.hpp"
74 #include "utilities/copy.hpp"
75 #include "utilities/events.hpp"
76 #include "utilities/globalDefinitions.hpp"
77 #ifdef COMPILER2
78 #include "opto/runtime.hpp"
79 #endif
80
81 class UnlockFlagSaver {
82 private:
83 JavaThread* _thread;
84 bool _do_not_unlock;
85 public:
86 UnlockFlagSaver(JavaThread* t) {
87 _thread = t;
88 _do_not_unlock = t->do_not_unlock_if_synchronized();
89 t->set_do_not_unlock_if_synchronized(false);
90 }
91 ~UnlockFlagSaver() {
92 _thread->set_do_not_unlock_if_synchronized(_do_not_unlock);
93 }
94 };
95
96 // Helper class to access current interpreter state
241 klass->initialize(CHECK);
242
243 // At this point the class may not be fully initialized
244 // because of recursive initialization. If it is fully
245 // initialized & has_finalized is not set, we rewrite
246 // it into its fast version (Note: no locking is needed
247 // here since this is an atomic byte write and can be
248 // done more than once).
249 //
250 // Note: In case of classes with has_finalized we don't
251 // rewrite since that saves us an extra check in
252 // the fast version which then would call the
253 // slow version anyway (and do a call back into
254 // Java).
255 // If we have a breakpoint, then we don't rewrite
256 // because the _breakpoint bytecode would be lost.
257 oop obj = klass->allocate_instance(CHECK);
258 thread->set_vm_result(obj);
259 IRT_END
260
261 void copy_primitive_argument(intptr_t* addr, Handle instance, int offset, BasicType type) {
262 switch (type) {
263 case T_BOOLEAN:
264 instance()->bool_field_put(offset, (jboolean)*((int*)addr));
265 break;
266 case T_CHAR:
267 instance()->char_field_put(offset, (jchar) *((int*)addr));
268 break;
269 case T_FLOAT:
270 instance()->float_field_put(offset, (jfloat)*((float*)addr));
271 break;
272 case T_DOUBLE:
273 instance()->double_field_put(offset, (jdouble)*((double*)addr));
274 break;
275 case T_BYTE:
276 instance()->byte_field_put(offset, (jbyte)*((int*)addr));
277 break;
278 case T_SHORT:
279 instance()->short_field_put(offset, (jshort)*((int*)addr));
280 break;
281 case T_INT:
282 instance()->int_field_put(offset, (jint)*((int*)addr));
283 break;
284 case T_LONG:
285 instance()->long_field_put(offset, (jlong)*((long long*)addr));
286 break;
287 case T_OBJECT:
288 case T_ARRAY:
289 case T_VALUETYPE:
290 fatal("Should not be handled with this method");
291 break;
292 default:
293 fatal("Unsupported BasicType");
294 }
295 }
296
297 IRT_ENTRY(void, InterpreterRuntime::defaultvalue(JavaThread* thread, ConstantPool* pool, int index))
298 // Getting the ValueKlass
299 Klass* k = pool->klass_at(index, CHECK);
300 assert(k->is_value(), "defaultvalue argument must be the value type class");
301 ValueKlass* vklass = ValueKlass::cast(k);
302
303 vklass->initialize(THREAD);
304 oop res = vklass->default_value();
305 thread->set_vm_result(res);
306 IRT_END
307
308 IRT_ENTRY(int, InterpreterRuntime::withfield(JavaThread* thread, ConstantPoolCache* cp_cache))
309 LastFrameAccessor last_frame(thread);
310 // Getting the ValueKlass
311 int index = ConstantPool::decode_cpcache_index(last_frame.get_index_u2_cpcache(Bytecodes::_withfield));
312 ConstantPoolCacheEntry* cp_entry = cp_cache->entry_at(index);
313 assert(cp_entry->is_resolved(Bytecodes::_withfield), "Should have been resolved");
314 Klass* klass = cp_entry->f1_as_klass();
315 assert(klass->is_value(), "withfield only applies to value types");
316 ValueKlass* vklass = ValueKlass::cast(klass);
317
318 // Getting Field information
319 int offset = cp_entry->f2_as_index();
320 int field_index = cp_entry->field_index();
321 int field_offset = cp_entry->f2_as_offset();
322 Symbol* field_signature = vklass->field_signature(field_index);
323 ResourceMark rm(THREAD);
324 const char* signature = (const char *) field_signature->as_utf8();
325 BasicType field_type = char2type(signature[0]);
326
327 // Getting old value
328 frame& f = last_frame.get_frame();
329 jint tos_idx = f.interpreter_frame_expression_stack_size() - 1;
330 int vt_offset = type2size[field_type];
331 oop old_value = *(oop*)f.interpreter_frame_expression_stack_at(tos_idx - vt_offset);
332 assert(old_value != NULL && oopDesc::is_oop(old_value) && old_value->is_value(),"Verifying receiver");
333 Handle old_value_h(THREAD, old_value);
334
335 // Creating new value by copying the one passed in argument
336 instanceOop new_value = vklass->allocate_instance(
337 CHECK_((type2size[field_type]) * AbstractInterpreter::stackElementSize));
338 Handle new_value_h = Handle(THREAD, new_value);
339 int first_offset = vklass->first_field_offset();
340 vklass->value_store(vklass->data_for_oop(old_value_h()),
341 vklass->data_for_oop(new_value_h()), true, false);
342
343 // Updating the field specified in arguments
344 if (field_type == T_ARRAY || field_type == T_OBJECT) {
345 oop aoop = *(oop*)f.interpreter_frame_expression_stack_at(tos_idx);
346 assert(aoop == NULL || oopDesc::is_oop(aoop),"argument must be a reference type");
347 new_value_h()->obj_field_put(field_offset, aoop);
348 } else if (field_type == T_VALUETYPE) {
349 if (cp_entry->is_flattened()) {
350 oop vt_oop = *(oop*)f.interpreter_frame_expression_stack_at(tos_idx);
351 if (vt_oop == NULL) {
352 THROW_(vmSymbols::java_lang_NullPointerException(),
353 (type2size[field_type] * AbstractInterpreter::stackElementSize));
354 }
355 assert(vt_oop != NULL && oopDesc::is_oop(vt_oop) && vt_oop->is_value(),"argument must be a value type");
356 Klass* field_k = vklass->get_value_field_klass(field_index);
357 ValueKlass* field_vk = ValueKlass::cast(field_k);
358 assert(field_vk == vt_oop->klass(), "Must match");
359 field_vk->value_store(field_vk->data_for_oop(vt_oop),
360 ((char*)(oopDesc*)new_value_h()) + field_offset, false, false);
361 } else { // not flattened
362 oop voop = *(oop*)f.interpreter_frame_expression_stack_at(tos_idx);
363 if (voop == NULL && cp_entry->is_flattenable()) {
364 THROW_(vmSymbols::java_lang_NullPointerException(),
365 (type2size[field_type] * AbstractInterpreter::stackElementSize));
366 }
367 assert(voop == NULL || oopDesc::is_oop(voop),"checking argument");
368 new_value_h()->obj_field_put(field_offset, voop);
369 }
370 } else { // not T_OBJECT nor T_ARRAY nor T_VALUETYPE
371 intptr_t* addr = f.interpreter_frame_expression_stack_at(tos_idx);
372 copy_primitive_argument(addr, new_value_h, field_offset, field_type);
373 }
374
375 // returning result
376 thread->set_vm_result(new_value_h());
377 return (type2size[field_type] + type2size[T_OBJECT]) * AbstractInterpreter::stackElementSize;
378 IRT_END
379
380 IRT_ENTRY(void, InterpreterRuntime::uninitialized_static_value_field(JavaThread* thread, oopDesc* mirror, int index))
381 instanceHandle mirror_h(THREAD, (instanceOop)mirror);
382 InstanceKlass* klass = InstanceKlass::cast(java_lang_Class::as_Klass(mirror));
383 int offset = klass->field_offset(index);
384 Klass* field_k = klass->get_value_field_klass_or_null(index);
385 assert(field_k != NULL, "Must have been initialized");
386 ValueKlass* field_vklass = ValueKlass::cast(field_k);
387 instanceOop res = (instanceOop)field_vklass->default_value();
388 thread->set_vm_result(res);
389 IRT_END
390
391 IRT_ENTRY(void, InterpreterRuntime::uninitialized_instance_value_field(JavaThread* thread, oopDesc* obj, int index))
392 instanceHandle obj_h(THREAD, (instanceOop)obj);
393 InstanceKlass* klass = InstanceKlass::cast(obj_h()->klass());
394 Klass* field_k = klass->get_value_field_klass_or_null(index);
395 assert(field_k != NULL, "Must have been initialized");
396 ValueKlass* field_vklass = ValueKlass::cast(field_k);
397 assert(field_vklass->is_initialized(), "Must have been initialized at this point");
398 instanceOop res = (instanceOop)field_vklass->default_value();
399 thread->set_vm_result(res);
400 IRT_END
401
402 IRT_ENTRY(void, InterpreterRuntime::write_flattened_value(JavaThread* thread, oopDesc* value, int offset, oopDesc* rcv))
403 assert(oopDesc::is_oop(value), "Sanity check");
404 assert(oopDesc::is_oop(rcv), "Sanity check");
405 assert(value->is_value(), "Sanity check");
406
407 ValueKlass* vklass = ValueKlass::cast(value->klass());
408 vklass->value_store(vklass->data_for_oop(value), ((char*)(oopDesc*)rcv) + offset, true, true);
409 IRT_END
410
411 IRT_ENTRY(void, InterpreterRuntime::read_flattened_field(JavaThread* thread, oopDesc* obj, int index, Klass* field_holder))
412 Handle obj_h(THREAD, obj);
413
414 assert(oopDesc::is_oop(obj), "Sanity check");
415
416 assert(field_holder->is_instance_klass(), "Sanity check");
417 InstanceKlass* klass = InstanceKlass::cast(field_holder);
418
419 assert(klass->field_is_flattened(index), "Sanity check");
420
421 ValueKlass* field_vklass = ValueKlass::cast(klass->get_value_field_klass(index));
422 assert(field_vklass->is_initialized(), "Must be initialized at this point");
423
424 // allocate instance
425 instanceOop res = field_vklass->allocate_instance(CHECK);
426 // copy value
427 field_vklass->value_store(((char*)(oopDesc*)obj_h()) + klass->field_offset(index),
428 field_vklass->data_for_oop(res), true, true);
429 thread->set_vm_result(res);
430 IRT_END
431
432 IRT_ENTRY(void, InterpreterRuntime::newarray(JavaThread* thread, BasicType type, jint size))
433 oop obj = oopFactory::new_typeArray(type, size, CHECK);
434 thread->set_vm_result(obj);
435 IRT_END
436
437
438 IRT_ENTRY(void, InterpreterRuntime::anewarray(JavaThread* thread, ConstantPool* pool, int index, jint size))
439 Klass* klass = pool->klass_at(index, CHECK);
440 if (klass->is_value()) { // Logically creates elements, ensure klass init
441 klass->initialize(CHECK);
442 }
443 arrayOop obj = oopFactory::new_array(klass, size, CHECK);
444 thread->set_vm_result(obj);
445 IRT_END
446
447 IRT_ENTRY(void, InterpreterRuntime::value_array_load(JavaThread* thread, arrayOopDesc* array, int index))
448 Klass* klass = array->klass();
449 assert(klass->is_valueArray_klass(), "expected value array oop");
450
451 ValueArrayKlass* vaklass = ValueArrayKlass::cast(klass);
452 ValueKlass* vklass = vaklass->element_klass();
453 arrayHandle ah(THREAD, array);
454 instanceOop value_holder = vklass->allocate_instance(CHECK);
455 void* src = ((valueArrayOop)ah())->value_at_addr(index, vaklass->layout_helper());
456 vklass->value_store(src, vklass->data_for_oop(value_holder),
457 vaklass->element_byte_size(), true, false);
458 thread->set_vm_result(value_holder);
459 IRT_END
460
461 IRT_ENTRY(void, InterpreterRuntime::value_array_store(JavaThread* thread, void* val, arrayOopDesc* array, int index))
462 assert(val != NULL, "can't store null into flat array");
463 Klass* klass = array->klass();
464 assert(klass->is_valueArray_klass(), "expected value array");
465 assert(ArrayKlass::cast(klass)->element_klass() == ((oop)val)->klass(), "Store type incorrect");
466
467 valueArrayOop varray = (valueArrayOop)array;
468 ValueArrayKlass* vaklass = ValueArrayKlass::cast(klass);
469 ValueKlass* vklass = vaklass->element_klass();
470 const int lh = vaklass->layout_helper();
471 vklass->value_store(vklass->data_for_oop((oop)val), varray->value_at_addr(index, lh),
472 vaklass->element_byte_size(), true, false);
473 IRT_END
474
475 IRT_ENTRY(void, InterpreterRuntime::multianewarray(JavaThread* thread, jint* first_size_address))
476 // We may want to pass in more arguments - could make this slightly faster
477 LastFrameAccessor last_frame(thread);
478 ConstantPool* constants = last_frame.method()->constants();
479 int i = last_frame.get_index_u2(Bytecodes::_multianewarray);
480 Klass* klass = constants->klass_at(i, CHECK);
481 int nof_dims = last_frame.number_of_dimensions();
482 assert(klass->is_klass(), "not a class");
483 assert(nof_dims >= 1, "multianewarray rank must be nonzero");
484
485 if (klass->is_value()) { // Logically creates elements, ensure klass init
486 klass->initialize(CHECK);
487 }
488
489 // We must create an array of jints to pass to multi_allocate.
490 ResourceMark rm(thread);
491 const int small_dims = 10;
492 jint dim_array[small_dims];
493 jint *dims = &dim_array[0];
494 if (nof_dims > small_dims) {
495 dims = (jint*) NEW_RESOURCE_ARRAY(jint, nof_dims);
496 }
497 for (int index = 0; index < nof_dims; index++) {
498 // offset from first_size_address is addressed as local[index]
499 int n = Interpreter::local_offset_in_bytes(index)/jintSize;
500 dims[index] = first_size_address[n];
501 }
502 oop obj = ArrayKlass::cast(klass)->multi_allocate(nof_dims, dims, CHECK);
503 thread->set_vm_result(obj);
504 IRT_END
505
506
507 IRT_ENTRY(void, InterpreterRuntime::register_finalizer(JavaThread* thread, oopDesc* obj))
508 assert(oopDesc::is_oop(obj), "must be a valid oop");
879 buf[0] = '\0';
880 jio_snprintf(buf, sizeof(buf),
881 "Class %s does not implement the requested interface %s",
882 recvKlass ? recvKlass->external_name() : "NULL",
883 interfaceKlass ? interfaceKlass->external_name() : "NULL");
884 THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
885 IRT_END
886
887 //------------------------------------------------------------------------------------------------------------------------
888 // Fields
889 //
890
891 void InterpreterRuntime::resolve_get_put(JavaThread* thread, Bytecodes::Code bytecode) {
892 Thread* THREAD = thread;
893 // resolve field
894 fieldDescriptor info;
895 LastFrameAccessor last_frame(thread);
896 constantPoolHandle pool(thread, last_frame.method()->constants());
897 methodHandle m(thread, last_frame.method());
898 bool is_put = (bytecode == Bytecodes::_putfield || bytecode == Bytecodes::_nofast_putfield ||
899 bytecode == Bytecodes::_putstatic || bytecode == Bytecodes::_withfield);
900 bool is_static = (bytecode == Bytecodes::_getstatic || bytecode == Bytecodes::_putstatic);
901 bool is_value = bytecode == Bytecodes::_withfield;
902
903 {
904 JvmtiHideSingleStepping jhss(thread);
905 LinkResolver::resolve_field_access(info, pool, last_frame.get_index_u2_cpcache(bytecode),
906 m, bytecode, CHECK);
907 } // end JvmtiHideSingleStepping
908
909 // check if link resolution caused cpCache to be updated
910 ConstantPoolCacheEntry* cp_cache_entry = last_frame.cache_entry();
911 if (cp_cache_entry->is_resolved(bytecode)) return;
912
913 // compute auxiliary field attributes
914 TosState state = as_TosState(info.field_type());
915
916 // Resolution of put instructions on final fields is delayed. That is required so that
917 // exceptions are thrown at the correct place (when the instruction is actually invoked).
918 // If we do not resolve an instruction in the current pass, leaving the put_code
919 // set to zero will cause the next put instruction to the same field to reresolve.
920
921 // Resolution of put instructions to final instance fields with invalid updates (i.e.,
925 // initializer method <init>. If resolution were not inhibited, a putfield
926 // in an initializer method could be resolved in the initializer. Subsequent
927 // putfield instructions to the same field would then use cached information.
928 // As a result, those instructions would not pass through the VM. That is,
929 // checks in resolve_field_access() would not be executed for those instructions
930 // and the required IllegalAccessError would not be thrown.
931 //
932 // Also, we need to delay resolving getstatic and putstatic instructions until the
933 // class is initialized. This is required so that access to the static
934 // field will call the initialization function every time until the class
935 // is completely initialized ala. in 2.17.5 in JVM Specification.
936 InstanceKlass* klass = info.field_holder();
937 bool uninitialized_static = is_static && !klass->is_initialized();
938 bool has_initialized_final_update = info.field_holder()->major_version() >= 53 &&
939 info.has_initialized_final_update();
940 assert(!(has_initialized_final_update && !info.access_flags().is_final()), "Fields with initialized final updates must be final");
941
942 Bytecodes::Code get_code = (Bytecodes::Code)0;
943 Bytecodes::Code put_code = (Bytecodes::Code)0;
944 if (!uninitialized_static) {
945 if (is_static) {
946 get_code = Bytecodes::_getstatic;
947 } else {
948 get_code = Bytecodes::_getfield;
949 }
950 if (is_put && is_value) {
951 put_code = ((is_static) ? Bytecodes::_putstatic : Bytecodes::_withfield);
952 } else if ((is_put && !has_initialized_final_update) || !info.access_flags().is_final()) {
953 put_code = ((is_static) ? Bytecodes::_putstatic : Bytecodes::_putfield);
954 }
955 }
956
957 cp_cache_entry->set_field(
958 get_code,
959 put_code,
960 info.field_holder(),
961 info.index(),
962 info.offset(),
963 state,
964 info.access_flags().is_final(),
965 info.access_flags().is_volatile(),
966 info.is_flattened(),
967 info.is_flattenable(),
968 pool->pool_holder()
969 );
970 }
971
972
973 //------------------------------------------------------------------------------------------------------------------------
974 // Synchronization
975 //
976 // The interpreter's synchronization code is factored out so that it can
977 // be shared by method invocation and synchronized blocks.
978 //%note synchronization_3
979
980 //%note monitor_1
981 IRT_ENTRY_NO_ASYNC(void, InterpreterRuntime::monitorenter(JavaThread* thread, BasicObjectLock* elem))
982 #ifdef ASSERT
983 thread->last_frame().interpreter_frame_verify_monitor(elem);
984 #endif
985 if (PrintBiasedLockingStatistics) {
986 Atomic::inc(BiasedLocking::slow_path_entry_count_addr());
987 }
1058 method->set_orig_bytecode_at(method->bci_from(bcp), new_code);
1059 IRT_END
1060
1061 IRT_ENTRY(void, InterpreterRuntime::_breakpoint(JavaThread* thread, Method* method, address bcp))
1062 JvmtiExport::post_raw_breakpoint(thread, method, bcp);
1063 IRT_END
1064
1065 void InterpreterRuntime::resolve_invoke(JavaThread* thread, Bytecodes::Code bytecode) {
1066 Thread* THREAD = thread;
1067 LastFrameAccessor last_frame(thread);
1068 // extract receiver from the outgoing argument list if necessary
1069 Handle receiver(thread, NULL);
1070 if (bytecode == Bytecodes::_invokevirtual || bytecode == Bytecodes::_invokeinterface ||
1071 bytecode == Bytecodes::_invokespecial) {
1072 ResourceMark rm(thread);
1073 methodHandle m (thread, last_frame.method());
1074 Bytecode_invoke call(m, last_frame.bci());
1075 Symbol* signature = call.signature();
1076 receiver = Handle(thread, last_frame.callee_receiver(signature));
1077
1078 assert(Universe::heap()->is_in_reserved_or_null(receiver()), "sanity check");
1079 assert(receiver.is_null() ||
1080 !Universe::heap()->is_in_reserved(receiver->klass()),
1081 "sanity check");
1082 }
1083
1084 // resolve method
1085 CallInfo info;
1086 constantPoolHandle pool(thread, last_frame.method()->constants());
1087
1088 {
1089 JvmtiHideSingleStepping jhss(thread);
1090 LinkResolver::resolve_invoke(info, receiver, pool,
1091 last_frame.get_index_u2_cpcache(bytecode), bytecode,
1092 CHECK);
1093 if (JvmtiExport::can_hotswap_or_post_breakpoint()) {
1094 int retry_count = 0;
1095 while (info.resolved_method()->is_old()) {
1096 // It is very unlikely that method is redefined more than 100 times
1097 // in the middle of resolve. If it is looping here more than 100 times
1098 // means then there could be a bug here.
1200 int index = last_frame.get_index_u4(bytecode);
1201 {
1202 JvmtiHideSingleStepping jhss(thread);
1203 LinkResolver::resolve_invoke(info, Handle(), pool,
1204 index, bytecode, CHECK);
1205 } // end JvmtiHideSingleStepping
1206
1207 ConstantPoolCacheEntry* cp_cache_entry = pool->invokedynamic_cp_cache_entry_at(index);
1208 cp_cache_entry->set_dynamic_call(pool, info);
1209 }
1210
1211 // This function is the interface to the assembly code. It returns the resolved
1212 // cpCache entry. This doesn't safepoint, but the helper routines safepoint.
1213 // This function will check for redefinition!
1214 IRT_ENTRY(void, InterpreterRuntime::resolve_from_cache(JavaThread* thread, Bytecodes::Code bytecode)) {
1215 switch (bytecode) {
1216 case Bytecodes::_getstatic:
1217 case Bytecodes::_putstatic:
1218 case Bytecodes::_getfield:
1219 case Bytecodes::_putfield:
1220 case Bytecodes::_withfield:
1221 resolve_get_put(thread, bytecode);
1222 break;
1223 case Bytecodes::_invokevirtual:
1224 case Bytecodes::_invokespecial:
1225 case Bytecodes::_invokestatic:
1226 case Bytecodes::_invokeinterface:
1227 resolve_invoke(thread, bytecode);
1228 break;
1229 case Bytecodes::_invokehandle:
1230 resolve_invokehandle(thread);
1231 break;
1232 case Bytecodes::_invokedynamic:
1233 resolve_invokedynamic(thread);
1234 break;
1235 default:
1236 fatal("unexpected bytecode: %s", Bytecodes::name(bytecode));
1237 break;
1238 }
1239 }
1240 IRT_END
1465 // check the access_flags for the field in the klass
1466 InstanceKlass* ik = InstanceKlass::cast(k);
1467 int index = cp_entry->field_index();
1468 // bail out if field modifications are not watched
1469 if ((ik->field_access_flags(index) & JVM_ACC_FIELD_MODIFICATION_WATCHED) == 0) return;
1470
1471 char sig_type = '\0';
1472
1473 switch(cp_entry->flag_state()) {
1474 case btos: sig_type = 'B'; break;
1475 case ztos: sig_type = 'Z'; break;
1476 case ctos: sig_type = 'C'; break;
1477 case stos: sig_type = 'S'; break;
1478 case itos: sig_type = 'I'; break;
1479 case ftos: sig_type = 'F'; break;
1480 case atos: sig_type = 'L'; break;
1481 case ltos: sig_type = 'J'; break;
1482 case dtos: sig_type = 'D'; break;
1483 default: ShouldNotReachHere(); return;
1484 }
1485
1486 // Both Q-signatures and L-signatures are mapped to atos
1487 if (cp_entry->flag_state() == atos && ik->field_signature(index)->is_Q_signature()) {
1488 sig_type = 'Q';
1489 }
1490
1491 bool is_static = (obj == NULL);
1492
1493 HandleMark hm(thread);
1494 jfieldID fid = jfieldIDWorkaround::to_jfieldID(ik, cp_entry->f2_as_index(), is_static);
1495 jvalue fvalue;
1496 #ifdef _LP64
1497 fvalue = *value;
1498 #else
1499 // Long/double values are stored unaligned and also noncontiguously with
1500 // tagged stacks. We can't just do a simple assignment even in the non-
1501 // J/D cases because a C++ compiler is allowed to assume that a jvalue is
1502 // 8-byte aligned, and interpreter stack slots are only 4-byte aligned.
1503 // We assume that the two halves of longs/doubles are stored in interpreter
1504 // stack slots in platform-endian order.
1505 jlong_accessor u;
1506 jint* newval = (jint*)value;
1507 u.words[0] = newval[0];
1508 u.words[1] = newval[Interpreter::stackElementWords]; // skip if tag
1509 fvalue.j = u.long_value;
1510 #endif // _LP64
|