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 "jvm_io.h"
27 #include "classfile/javaClasses.inline.hpp"
28 #include "classfile/symbolTable.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/interpreter.hpp"
38 #include "interpreter/interpreterRuntime.hpp"
39 #include "interpreter/linkResolver.hpp"
40 #include "interpreter/templateTable.hpp"
41 #include "logging/log.hpp"
42 #include "memory/oopFactory.hpp"
43 #include "memory/resourceArea.hpp"
44 #include "memory/universe.hpp"
45 #include "oops/constantPool.hpp"
46 #include "oops/cpCache.inline.hpp"
47 #include "oops/instanceKlass.inline.hpp"
48 #include "oops/klass.inline.hpp"
49 #include "oops/methodData.hpp"
50 #include "oops/objArrayKlass.hpp"
51 #include "oops/objArrayOop.inline.hpp"
52 #include "oops/oop.inline.hpp"
53 #include "oops/symbol.hpp"
54 #include "prims/jvmtiExport.hpp"
55 #include "prims/methodHandles.hpp"
56 #include "prims/nativeLookup.hpp"
57 #include "runtime/atomic.hpp"
58 #include "runtime/deoptimization.hpp"
59 #include "runtime/fieldDescriptor.inline.hpp"
60 #include "runtime/frame.inline.hpp"
61 #include "runtime/handles.inline.hpp"
62 #include "runtime/icache.hpp"
63 #include "runtime/interfaceSupport.inline.hpp"
64 #include "runtime/java.hpp"
65 #include "runtime/javaCalls.hpp"
66 #include "runtime/jfieldIDWorkaround.hpp"
67 #include "runtime/osThread.hpp"
68 #include "runtime/sharedRuntime.hpp"
69 #include "runtime/stackWatermarkSet.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 #ifdef COMPILER2
77 #include "opto/runtime.hpp"
78 #endif
79
80 // Helper class to access current interpreter state
81 class LastFrameAccessor : public StackObj {
82 frame _last_frame;
83 public:
84 LastFrameAccessor(JavaThread* current) {
85 assert(current == Thread::current(), "sanity");
86 _last_frame = current->last_frame();
87 }
88 bool is_interpreted_frame() const { return _last_frame.is_interpreted_frame(); }
89 Method* method() const { return _last_frame.interpreter_frame_method(); }
90 address bcp() const { return _last_frame.interpreter_frame_bcp(); }
91 int bci() const { return _last_frame.interpreter_frame_bci(); }
92 address mdp() const { return _last_frame.interpreter_frame_mdp(); }
93
94 void set_bcp(address bcp) { _last_frame.interpreter_frame_set_bcp(bcp); }
95 void set_mdp(address dp) { _last_frame.interpreter_frame_set_mdp(dp); }
137 if (mdo != NULL) {
138 NEEDS_CLEANUP;
139 last_frame.set_mdp(mdo->bci_to_dp(last_frame.bci()));
140 }
141 }
142 }
143
144 //------------------------------------------------------------------------------------------------------------------------
145 // Constants
146
147
148 JRT_ENTRY(void, InterpreterRuntime::ldc(JavaThread* current, bool wide))
149 // access constant pool
150 LastFrameAccessor last_frame(current);
151 ConstantPool* pool = last_frame.method()->constants();
152 int index = wide ? last_frame.get_index_u2(Bytecodes::_ldc_w) : last_frame.get_index_u1(Bytecodes::_ldc);
153 constantTag tag = pool->tag_at(index);
154
155 assert (tag.is_unresolved_klass() || tag.is_klass(), "wrong ldc call");
156 Klass* klass = pool->klass_at(index, CHECK);
157 oop java_class = klass->java_mirror();
158 current->set_vm_result(java_class);
159 JRT_END
160
161 JRT_ENTRY(void, InterpreterRuntime::resolve_ldc(JavaThread* current, Bytecodes::Code bytecode)) {
162 assert(bytecode == Bytecodes::_ldc ||
163 bytecode == Bytecodes::_ldc_w ||
164 bytecode == Bytecodes::_ldc2_w ||
165 bytecode == Bytecodes::_fast_aldc ||
166 bytecode == Bytecodes::_fast_aldc_w, "wrong bc");
167 ResourceMark rm(current);
168 const bool is_fast_aldc = (bytecode == Bytecodes::_fast_aldc ||
169 bytecode == Bytecodes::_fast_aldc_w);
170 LastFrameAccessor last_frame(current);
171 methodHandle m (current, last_frame.method());
172 Bytecode_loadconstant ldc(m, last_frame.bci());
173
174 // Double-check the size. (Condy can have any type.)
175 BasicType type = ldc.result_type();
176 switch (type2size[type]) {
177 case 2: guarantee(bytecode == Bytecodes::_ldc2_w, ""); break;
201 current->set_vm_result(result);
202 if (!is_fast_aldc) {
203 // Tell the interpreter how to unbox the primitive.
204 guarantee(java_lang_boxing_object::is_instance(result, type), "");
205 int offset = java_lang_boxing_object::value_offset(type);
206 intptr_t flags = ((as_TosState(type) << ConstantPoolCacheEntry::tos_state_shift)
207 | (offset & ConstantPoolCacheEntry::field_index_mask));
208 current->set_vm_result_2((Metadata*)flags);
209 }
210 }
211 JRT_END
212
213
214 //------------------------------------------------------------------------------------------------------------------------
215 // Allocation
216
217 JRT_ENTRY(void, InterpreterRuntime::_new(JavaThread* current, ConstantPool* pool, int index))
218 Klass* k = pool->klass_at(index, CHECK);
219 InstanceKlass* klass = InstanceKlass::cast(k);
220
221 // Make sure we are not instantiating an abstract klass
222 klass->check_valid_for_instantiation(true, CHECK);
223
224 // Make sure klass is initialized
225 klass->initialize(CHECK);
226
227 // At this point the class may not be fully initialized
228 // because of recursive initialization. If it is fully
229 // initialized & has_finalized is not set, we rewrite
230 // it into its fast version (Note: no locking is needed
231 // here since this is an atomic byte write and can be
232 // done more than once).
233 //
234 // Note: In case of classes with has_finalized we don't
235 // rewrite since that saves us an extra check in
236 // the fast version which then would call the
237 // slow version anyway (and do a call back into
238 // Java).
239 // If we have a breakpoint, then we don't rewrite
240 // because the _breakpoint bytecode would be lost.
241 oop obj = klass->allocate_instance(CHECK);
242 current->set_vm_result(obj);
243 JRT_END
244
245
246 JRT_ENTRY(void, InterpreterRuntime::newarray(JavaThread* current, BasicType type, jint size))
247 oop obj = oopFactory::new_typeArray(type, size, CHECK);
248 current->set_vm_result(obj);
249 JRT_END
250
251
252 JRT_ENTRY(void, InterpreterRuntime::anewarray(JavaThread* current, ConstantPool* pool, int index, jint size))
253 Klass* klass = pool->klass_at(index, CHECK);
254 objArrayOop obj = oopFactory::new_objArray(klass, size, CHECK);
255 current->set_vm_result(obj);
256 JRT_END
257
258
259 JRT_ENTRY(void, InterpreterRuntime::multianewarray(JavaThread* current, jint* first_size_address))
260 // We may want to pass in more arguments - could make this slightly faster
261 LastFrameAccessor last_frame(current);
262 ConstantPool* constants = last_frame.method()->constants();
263 int i = last_frame.get_index_u2(Bytecodes::_multianewarray);
264 Klass* klass = constants->klass_at(i, CHECK);
265 int nof_dims = last_frame.number_of_dimensions();
266 assert(klass->is_klass(), "not a class");
267 assert(nof_dims >= 1, "multianewarray rank must be nonzero");
268
269 // We must create an array of jints to pass to multi_allocate.
270 ResourceMark rm(current);
271 const int small_dims = 10;
272 jint dim_array[small_dims];
273 jint *dims = &dim_array[0];
274 if (nof_dims > small_dims) {
275 dims = (jint*) NEW_RESOURCE_ARRAY(jint, nof_dims);
276 }
277 for (int index = 0; index < nof_dims; index++) {
278 // offset from first_size_address is addressed as local[index]
279 int n = Interpreter::local_offset_in_bytes(index)/jintSize;
280 dims[index] = first_size_address[n];
281 }
282 oop obj = ArrayKlass::cast(klass)->multi_allocate(nof_dims, dims, CHECK);
283 current->set_vm_result(obj);
284 JRT_END
285
286
287 JRT_ENTRY(void, InterpreterRuntime::register_finalizer(JavaThread* current, oopDesc* obj))
288 assert(oopDesc::is_oop(obj), "must be a valid oop");
289 assert(obj->klass()->has_finalizer(), "shouldn't be here otherwise");
290 InstanceKlass::register_finalizer(instanceOop(obj), CHECK);
291 JRT_END
292
293
294 // Quicken instance-of and check-cast bytecodes
295 JRT_ENTRY(void, InterpreterRuntime::quicken_io_cc(JavaThread* current))
296 // Force resolving; quicken the bytecode
297 LastFrameAccessor last_frame(current);
298 int which = last_frame.get_index_u2(Bytecodes::_checkcast);
299 ConstantPool* cpool = last_frame.method()->constants();
300 // We'd expect to assert that we're only here to quicken bytecodes, but in a multithreaded
301 // program we might have seen an unquick'd bytecode in the interpreter but have another
302 // thread quicken the bytecode before we get here.
303 // assert( cpool->tag_at(which).is_unresolved_klass(), "should only come here to quicken bytecodes" );
304 Klass* klass = cpool->klass_at(which, CHECK);
305 current->set_vm_result_2(klass);
306 JRT_END
307
308
309 //------------------------------------------------------------------------------------------------------------------------
310 // Exceptions
311
312 void InterpreterRuntime::note_trap_inner(JavaThread* current, int reason,
603 // and therefore we don't have the receiver object at our fingertips. (Though,
604 // on some platforms the receiver still resides in a register...). Thus,
605 // we have no choice but print an error message not containing the receiver
606 // type.
607 JRT_ENTRY(void, InterpreterRuntime::throw_AbstractMethodErrorWithMethod(JavaThread* current,
608 Method* missingMethod))
609 ResourceMark rm(current);
610 assert(missingMethod != NULL, "sanity");
611 methodHandle m(current, missingMethod);
612 LinkResolver::throw_abstract_method_error(m, THREAD);
613 JRT_END
614
615 JRT_ENTRY(void, InterpreterRuntime::throw_AbstractMethodErrorVerbose(JavaThread* current,
616 Klass* recvKlass,
617 Method* missingMethod))
618 ResourceMark rm(current);
619 methodHandle mh = methodHandle(current, missingMethod);
620 LinkResolver::throw_abstract_method_error(mh, recvKlass, THREAD);
621 JRT_END
622
623
624 JRT_ENTRY(void, InterpreterRuntime::throw_IncompatibleClassChangeError(JavaThread* current))
625 THROW(vmSymbols::java_lang_IncompatibleClassChangeError());
626 JRT_END
627
628 JRT_ENTRY(void, InterpreterRuntime::throw_IncompatibleClassChangeErrorVerbose(JavaThread* current,
629 Klass* recvKlass,
630 Klass* interfaceKlass))
631 ResourceMark rm(current);
632 char buf[1000];
633 buf[0] = '\0';
634 jio_snprintf(buf, sizeof(buf),
635 "Class %s does not implement the requested interface %s",
636 recvKlass ? recvKlass->external_name() : "NULL",
637 interfaceKlass ? interfaceKlass->external_name() : "NULL");
638 THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
639 JRT_END
640
641 JRT_ENTRY(void, InterpreterRuntime::throw_NullPointerException(JavaThread* current))
642 THROW(vmSymbols::java_lang_NullPointerException());
643 JRT_END
644
645 //------------------------------------------------------------------------------------------------------------------------
646 // Fields
647 //
648
649 void InterpreterRuntime::resolve_get_put(JavaThread* current, Bytecodes::Code bytecode) {
650 // resolve field
651 fieldDescriptor info;
652 LastFrameAccessor last_frame(current);
653 constantPoolHandle pool(current, last_frame.method()->constants());
654 methodHandle m(current, last_frame.method());
655 bool is_put = (bytecode == Bytecodes::_putfield || bytecode == Bytecodes::_nofast_putfield ||
656 bytecode == Bytecodes::_putstatic);
657 bool is_static = (bytecode == Bytecodes::_getstatic || bytecode == Bytecodes::_putstatic);
658
659 {
660 JvmtiHideSingleStepping jhss(current);
661 JavaThread* THREAD = current; // For exception macros.
662 LinkResolver::resolve_field_access(info, pool, last_frame.get_index_u2_cpcache(bytecode),
663 m, bytecode, CHECK);
664 } // end JvmtiHideSingleStepping
665
666 // check if link resolution caused cpCache to be updated
667 ConstantPoolCacheEntry* cp_cache_entry = last_frame.cache_entry();
668 if (cp_cache_entry->is_resolved(bytecode)) return;
669
670 // compute auxiliary field attributes
671 TosState state = as_TosState(info.field_type());
672
673 // Resolution of put instructions on final fields is delayed. That is required so that
674 // exceptions are thrown at the correct place (when the instruction is actually invoked).
675 // If we do not resolve an instruction in the current pass, leaving the put_code
676 // set to zero will cause the next put instruction to the same field to reresolve.
677
682 // initializer method <init>. If resolution were not inhibited, a putfield
683 // in an initializer method could be resolved in the initializer. Subsequent
684 // putfield instructions to the same field would then use cached information.
685 // As a result, those instructions would not pass through the VM. That is,
686 // checks in resolve_field_access() would not be executed for those instructions
687 // and the required IllegalAccessError would not be thrown.
688 //
689 // Also, we need to delay resolving getstatic and putstatic instructions until the
690 // class is initialized. This is required so that access to the static
691 // field will call the initialization function every time until the class
692 // is completely initialized ala. in 2.17.5 in JVM Specification.
693 InstanceKlass* klass = info.field_holder();
694 bool uninitialized_static = is_static && !klass->is_initialized();
695 bool has_initialized_final_update = info.field_holder()->major_version() >= 53 &&
696 info.has_initialized_final_update();
697 assert(!(has_initialized_final_update && !info.access_flags().is_final()), "Fields with initialized final updates must be final");
698
699 Bytecodes::Code get_code = (Bytecodes::Code)0;
700 Bytecodes::Code put_code = (Bytecodes::Code)0;
701 if (!uninitialized_static) {
702 get_code = ((is_static) ? Bytecodes::_getstatic : Bytecodes::_getfield);
703 if ((is_put && !has_initialized_final_update) || !info.access_flags().is_final()) {
704 put_code = ((is_static) ? Bytecodes::_putstatic : Bytecodes::_putfield);
705 }
706 }
707
708 cp_cache_entry->set_field(
709 get_code,
710 put_code,
711 info.field_holder(),
712 info.index(),
713 info.offset(),
714 state,
715 info.access_flags().is_final(),
716 info.access_flags().is_volatile()
717 );
718 }
719
720
721 //------------------------------------------------------------------------------------------------------------------------
722 // Synchronization
723 //
724 // The interpreter's synchronization code is factored out so that it can
725 // be shared by method invocation and synchronized blocks.
726 //%note synchronization_3
727
728 //%note monitor_1
729 JRT_ENTRY_NO_ASYNC(void, InterpreterRuntime::monitorenter(JavaThread* current, BasicObjectLock* elem))
730 #ifdef ASSERT
731 current->last_frame().interpreter_frame_verify_monitor(elem);
732 #endif
733 Handle h_obj(current, elem->obj());
734 assert(Universe::heap()->is_in_or_null(h_obj()),
735 "must be NULL or an object");
736 ObjectSynchronizer::enter(h_obj, elem->lock(), current);
939 {
940 JvmtiHideSingleStepping jhss(current);
941 JavaThread* THREAD = current; // For exception macros.
942 LinkResolver::resolve_invoke(info, Handle(), pool,
943 index, bytecode, CHECK);
944 } // end JvmtiHideSingleStepping
945
946 ConstantPoolCacheEntry* cp_cache_entry = pool->invokedynamic_cp_cache_entry_at(index);
947 cp_cache_entry->set_dynamic_call(pool, info);
948 }
949
950 // This function is the interface to the assembly code. It returns the resolved
951 // cpCache entry. This doesn't safepoint, but the helper routines safepoint.
952 // This function will check for redefinition!
953 JRT_ENTRY(void, InterpreterRuntime::resolve_from_cache(JavaThread* current, Bytecodes::Code bytecode)) {
954 switch (bytecode) {
955 case Bytecodes::_getstatic:
956 case Bytecodes::_putstatic:
957 case Bytecodes::_getfield:
958 case Bytecodes::_putfield:
959 resolve_get_put(current, bytecode);
960 break;
961 case Bytecodes::_invokevirtual:
962 case Bytecodes::_invokespecial:
963 case Bytecodes::_invokestatic:
964 case Bytecodes::_invokeinterface:
965 resolve_invoke(current, bytecode);
966 break;
967 case Bytecodes::_invokehandle:
968 resolve_invokehandle(current);
969 break;
970 case Bytecodes::_invokedynamic:
971 resolve_invokedynamic(current);
972 break;
973 default:
974 fatal("unexpected bytecode: %s", Bytecodes::name(bytecode));
975 break;
976 }
977 }
978 JRT_END
1136 // This function is called by the interpreter when the return poll found a reason
1137 // to call the VM. The reason could be that we are returning into a not yet safe
1138 // to access frame. We handle that below.
1139 // Note that this path does not check for single stepping, because we do not want
1140 // to single step when unwinding frames for an exception being thrown. Instead,
1141 // such single stepping code will use the safepoint table, which will use the
1142 // InterpreterRuntime::at_safepoint callback.
1143 StackWatermarkSet::before_unwind(current);
1144 JRT_END
1145
1146 JRT_ENTRY(void, InterpreterRuntime::post_field_access(JavaThread* current, oopDesc* obj,
1147 ConstantPoolCacheEntry *cp_entry))
1148
1149 // check the access_flags for the field in the klass
1150
1151 InstanceKlass* ik = InstanceKlass::cast(cp_entry->f1_as_klass());
1152 int index = cp_entry->field_index();
1153 if ((ik->field_access_flags(index) & JVM_ACC_FIELD_ACCESS_WATCHED) == 0) return;
1154
1155 bool is_static = (obj == NULL);
1156 HandleMark hm(current);
1157
1158 Handle h_obj;
1159 if (!is_static) {
1160 // non-static field accessors have an object, but we need a handle
1161 h_obj = Handle(current, obj);
1162 }
1163 InstanceKlass* cp_entry_f1 = InstanceKlass::cast(cp_entry->f1_as_klass());
1164 jfieldID fid = jfieldIDWorkaround::to_jfieldID(cp_entry_f1, cp_entry->f2_as_index(), is_static);
1165 LastFrameAccessor last_frame(current);
1166 JvmtiExport::post_field_access(current, last_frame.method(), last_frame.bcp(), cp_entry_f1, h_obj, fid);
1167 JRT_END
1168
1169 JRT_ENTRY(void, InterpreterRuntime::post_field_modification(JavaThread* current, oopDesc* obj,
1170 ConstantPoolCacheEntry *cp_entry, jvalue *value))
1171
1172 Klass* k = cp_entry->f1_as_klass();
1173
1174 // check the access_flags for the field in the klass
1175 InstanceKlass* ik = InstanceKlass::cast(k);
1176 int index = cp_entry->field_index();
1177 // bail out if field modifications are not watched
1178 if ((ik->field_access_flags(index) & JVM_ACC_FIELD_MODIFICATION_WATCHED) == 0) return;
1179
1180 char sig_type = '\0';
1181
1182 switch(cp_entry->flag_state()) {
1183 case btos: sig_type = JVM_SIGNATURE_BYTE; break;
1184 case ztos: sig_type = JVM_SIGNATURE_BOOLEAN; break;
1185 case ctos: sig_type = JVM_SIGNATURE_CHAR; break;
1186 case stos: sig_type = JVM_SIGNATURE_SHORT; break;
1187 case itos: sig_type = JVM_SIGNATURE_INT; break;
1188 case ftos: sig_type = JVM_SIGNATURE_FLOAT; break;
1189 case atos: sig_type = JVM_SIGNATURE_CLASS; break;
1190 case ltos: sig_type = JVM_SIGNATURE_LONG; break;
1191 case dtos: sig_type = JVM_SIGNATURE_DOUBLE; break;
1192 default: ShouldNotReachHere(); return;
1193 }
1194 bool is_static = (obj == NULL);
1195
1196 HandleMark hm(current);
1197 jfieldID fid = jfieldIDWorkaround::to_jfieldID(ik, cp_entry->f2_as_index(), is_static);
1198 jvalue fvalue;
1199 #ifdef _LP64
1200 fvalue = *value;
1201 #else
1202 // Long/double values are stored unaligned and also noncontiguously with
1203 // tagged stacks. We can't just do a simple assignment even in the non-
1204 // J/D cases because a C++ compiler is allowed to assume that a jvalue is
1205 // 8-byte aligned, and interpreter stack slots are only 4-byte aligned.
1206 // We assume that the two halves of longs/doubles are stored in interpreter
1207 // stack slots in platform-endian order.
1208 jlong_accessor u;
1209 jint* newval = (jint*)value;
1210 u.words[0] = newval[0];
1211 u.words[1] = newval[Interpreter::stackElementWords]; // skip if tag
1212 fvalue.j = u.long_value;
1213 #endif // _LP64
1214
1215 Handle h_obj;
1216 if (!is_static) {
1217 // non-static field accessors have an object, but we need a handle
|
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 "jvm_io.h"
27 #include "classfile/javaClasses.inline.hpp"
28 #include "classfile/symbolTable.hpp"
29 #include "classfile/systemDictionary.hpp"
30 #include "classfile/vmClasses.hpp"
31 #include "classfile/vmSymbols.hpp"
32 #include "code/codeCache.hpp"
33 #include "compiler/compilationPolicy.hpp"
34 #include "compiler/compileBroker.hpp"
35 #include "compiler/disassembler.hpp"
36 #include "gc/shared/barrierSetNMethod.hpp"
37 #include "gc/shared/collectedHeap.hpp"
38 #include "interpreter/interpreter.hpp"
39 #include "interpreter/interpreterRuntime.hpp"
40 #include "interpreter/linkResolver.hpp"
41 #include "interpreter/templateTable.hpp"
42 #include "logging/log.hpp"
43 #include "memory/oopFactory.hpp"
44 #include "memory/resourceArea.hpp"
45 #include "memory/universe.hpp"
46 #include "oops/constantPool.hpp"
47 #include "oops/cpCache.inline.hpp"
48 #include "oops/flatArrayKlass.hpp"
49 #include "oops/flatArrayOop.inline.hpp"
50 #include "oops/inlineKlass.inline.hpp"
51 #include "oops/instanceKlass.inline.hpp"
52 #include "oops/klass.inline.hpp"
53 #include "oops/methodData.hpp"
54 #include "oops/objArrayKlass.hpp"
55 #include "oops/objArrayOop.inline.hpp"
56 #include "oops/oop.inline.hpp"
57 #include "oops/symbol.hpp"
58 #include "prims/jvmtiExport.hpp"
59 #include "prims/methodHandles.hpp"
60 #include "prims/nativeLookup.hpp"
61 #include "runtime/atomic.hpp"
62 #include "runtime/deoptimization.hpp"
63 #include "runtime/fieldDescriptor.inline.hpp"
64 #include "runtime/frame.inline.hpp"
65 #include "runtime/handles.inline.hpp"
66 #include "runtime/icache.hpp"
67 #include "runtime/interfaceSupport.inline.hpp"
68 #include "runtime/java.hpp"
69 #include "runtime/javaCalls.hpp"
70 #include "runtime/jfieldIDWorkaround.hpp"
71 #include "runtime/osThread.hpp"
72 #include "runtime/sharedRuntime.hpp"
73 #include "runtime/stackWatermarkSet.hpp"
74 #include "runtime/stubRoutines.hpp"
75 #include "runtime/synchronizer.hpp"
76 #include "runtime/threadCritical.hpp"
77 #include "utilities/align.hpp"
78 #include "utilities/copy.hpp"
79 #include "utilities/events.hpp"
80 #include "utilities/globalDefinitions.hpp"
81 #ifdef COMPILER2
82 #include "opto/runtime.hpp"
83 #endif
84
85 // Helper class to access current interpreter state
86 class LastFrameAccessor : public StackObj {
87 frame _last_frame;
88 public:
89 LastFrameAccessor(JavaThread* current) {
90 assert(current == Thread::current(), "sanity");
91 _last_frame = current->last_frame();
92 }
93 bool is_interpreted_frame() const { return _last_frame.is_interpreted_frame(); }
94 Method* method() const { return _last_frame.interpreter_frame_method(); }
95 address bcp() const { return _last_frame.interpreter_frame_bcp(); }
96 int bci() const { return _last_frame.interpreter_frame_bci(); }
97 address mdp() const { return _last_frame.interpreter_frame_mdp(); }
98
99 void set_bcp(address bcp) { _last_frame.interpreter_frame_set_bcp(bcp); }
100 void set_mdp(address dp) { _last_frame.interpreter_frame_set_mdp(dp); }
142 if (mdo != NULL) {
143 NEEDS_CLEANUP;
144 last_frame.set_mdp(mdo->bci_to_dp(last_frame.bci()));
145 }
146 }
147 }
148
149 //------------------------------------------------------------------------------------------------------------------------
150 // Constants
151
152
153 JRT_ENTRY(void, InterpreterRuntime::ldc(JavaThread* current, bool wide))
154 // access constant pool
155 LastFrameAccessor last_frame(current);
156 ConstantPool* pool = last_frame.method()->constants();
157 int index = wide ? last_frame.get_index_u2(Bytecodes::_ldc_w) : last_frame.get_index_u1(Bytecodes::_ldc);
158 constantTag tag = pool->tag_at(index);
159
160 assert (tag.is_unresolved_klass() || tag.is_klass(), "wrong ldc call");
161 Klass* klass = pool->klass_at(index, CHECK);
162 oop java_class = tag.is_Qdescriptor_klass()
163 ? InlineKlass::cast(klass)->val_mirror()
164 : klass->java_mirror();
165 current->set_vm_result(java_class);
166 JRT_END
167
168 JRT_ENTRY(void, InterpreterRuntime::resolve_ldc(JavaThread* current, Bytecodes::Code bytecode)) {
169 assert(bytecode == Bytecodes::_ldc ||
170 bytecode == Bytecodes::_ldc_w ||
171 bytecode == Bytecodes::_ldc2_w ||
172 bytecode == Bytecodes::_fast_aldc ||
173 bytecode == Bytecodes::_fast_aldc_w, "wrong bc");
174 ResourceMark rm(current);
175 const bool is_fast_aldc = (bytecode == Bytecodes::_fast_aldc ||
176 bytecode == Bytecodes::_fast_aldc_w);
177 LastFrameAccessor last_frame(current);
178 methodHandle m (current, last_frame.method());
179 Bytecode_loadconstant ldc(m, last_frame.bci());
180
181 // Double-check the size. (Condy can have any type.)
182 BasicType type = ldc.result_type();
183 switch (type2size[type]) {
184 case 2: guarantee(bytecode == Bytecodes::_ldc2_w, ""); break;
208 current->set_vm_result(result);
209 if (!is_fast_aldc) {
210 // Tell the interpreter how to unbox the primitive.
211 guarantee(java_lang_boxing_object::is_instance(result, type), "");
212 int offset = java_lang_boxing_object::value_offset(type);
213 intptr_t flags = ((as_TosState(type) << ConstantPoolCacheEntry::tos_state_shift)
214 | (offset & ConstantPoolCacheEntry::field_index_mask));
215 current->set_vm_result_2((Metadata*)flags);
216 }
217 }
218 JRT_END
219
220
221 //------------------------------------------------------------------------------------------------------------------------
222 // Allocation
223
224 JRT_ENTRY(void, InterpreterRuntime::_new(JavaThread* current, ConstantPool* pool, int index))
225 Klass* k = pool->klass_at(index, CHECK);
226 InstanceKlass* klass = InstanceKlass::cast(k);
227
228 if (klass->is_inline_klass()) {
229 THROW(vmSymbols::java_lang_InstantiationError());
230 }
231
232 // Make sure we are not instantiating an abstract klass
233 klass->check_valid_for_instantiation(true, CHECK);
234
235 // Make sure klass is initialized
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 current->set_vm_result(obj);
254 JRT_END
255
256 JRT_ENTRY(void, InterpreterRuntime::aconst_init(JavaThread* current, ConstantPool* pool, int index))
257 // Getting the InlineKlass
258 Klass* k = pool->klass_at(index, CHECK);
259 if (!k->is_inline_klass()) {
260 // inconsistency with 'new' which throws an InstantiationError
261 // in the future, aconst_init will just return null instead of throwing an exception
262 THROW(vmSymbols::java_lang_IncompatibleClassChangeError());
263 }
264 assert(k->is_inline_klass(), "aconst_init argument must be the inline type class");
265 InlineKlass* vklass = InlineKlass::cast(k);
266
267 vklass->initialize(CHECK);
268 oop res = vklass->default_value();
269 current->set_vm_result(res);
270 JRT_END
271
272 JRT_ENTRY(int, InterpreterRuntime::withfield(JavaThread* current, ConstantPoolCacheEntry* cpe, uintptr_t ptr))
273 oop obj = NULL;
274 int recv_offset = type2size[as_BasicType(cpe->flag_state())];
275 assert(frame::interpreter_frame_expression_stack_direction() == -1, "currently is -1 on all platforms");
276 int ret_adj = (recv_offset + type2size[T_OBJECT] )* AbstractInterpreter::stackElementSize;
277 int offset = cpe->f2_as_offset();
278 obj = (oopDesc*)(((uintptr_t*)ptr)[recv_offset * Interpreter::stackElementWords]);
279 if (obj == NULL) {
280 THROW_(vmSymbols::java_lang_NullPointerException(), ret_adj);
281 }
282 assert(oopDesc::is_oop(obj), "Verifying receiver");
283 assert(obj->klass()->is_inline_klass(), "Must have been checked during resolution");
284 instanceHandle old_value_h(THREAD, (instanceOop)obj);
285 oop ref = NULL;
286 if (cpe->flag_state() == atos) {
287 ref = *(oopDesc**)ptr;
288 }
289 Handle ref_h(THREAD, ref);
290 InlineKlass* ik = InlineKlass::cast(old_value_h()->klass());
291 // Ensure that the class is initialized or being initialized
292 // If the class is in error state, the creation of a new value should not be allowed
293 ik->initialize(CHECK_(ret_adj));
294
295 bool can_skip = false;
296 switch(cpe->flag_state()) {
297 case ztos:
298 if (old_value_h()->bool_field(offset) == (jboolean)(*(jint*)ptr)) can_skip = true;
299 break;
300 case btos:
301 if (old_value_h()->byte_field(offset) == (jbyte)(*(jint*)ptr)) can_skip = true;
302 break;
303 case ctos:
304 if (old_value_h()->char_field(offset) == (jchar)(*(jint*)ptr)) can_skip = true;
305 break;
306 case stos:
307 if (old_value_h()->short_field(offset) == (jshort)(*(jint*)ptr)) can_skip = true;
308 break;
309 case itos:
310 if (old_value_h()->int_field(offset) == *(jint*)ptr) can_skip = true;
311 break;
312 case ltos:
313 if (old_value_h()->long_field(offset) == *(jlong*)ptr) can_skip = true;
314 break;
315 case ftos:
316 if (memcmp(old_value_h()->field_addr<jfloat>(offset), (jfloat*)ptr, sizeof(jfloat)) == 0) can_skip = true;
317 break;
318 case dtos:
319 if (memcmp(old_value_h()->field_addr<jdouble>(offset), (jdouble*)ptr, sizeof(jdouble)) == 0) can_skip = true;
320 break;
321 case atos:
322 if (!cpe->is_inlined() && old_value_h()->obj_field(offset) == ref_h()) can_skip = true;
323 break;
324 default:
325 break;
326 }
327 if (can_skip) {
328 current->set_vm_result(old_value_h());
329 return ret_adj;
330 }
331
332 instanceOop new_value = ik->allocate_instance_buffer(CHECK_(ret_adj));
333 Handle new_value_h = Handle(THREAD, new_value);
334 ik->inline_copy_oop_to_new_oop(old_value_h(), new_value_h());
335 switch(cpe->flag_state()) {
336 case ztos:
337 new_value_h()->bool_field_put(offset, (jboolean)(*(jint*)ptr));
338 break;
339 case btos:
340 new_value_h()->byte_field_put(offset, (jbyte)(*(jint*)ptr));
341 break;
342 case ctos:
343 new_value_h()->char_field_put(offset, (jchar)(*(jint*)ptr));
344 break;
345 case stos:
346 new_value_h()->short_field_put(offset, (jshort)(*(jint*)ptr));
347 break;
348 case itos:
349 new_value_h()->int_field_put(offset, (*(jint*)ptr));
350 break;
351 case ltos:
352 new_value_h()->long_field_put(offset, *(jlong*)ptr);
353 break;
354 case ftos:
355 new_value_h()->float_field_put(offset, *(jfloat*)ptr);
356 break;
357 case dtos:
358 new_value_h()->double_field_put(offset, *(jdouble*)ptr);
359 break;
360 case atos:
361 {
362 if (cpe->is_null_free_inline_type()) {
363 if (!cpe->is_inlined()) {
364 if (ref_h() == NULL) {
365 THROW_(vmSymbols::java_lang_NullPointerException(), ret_adj);
366 }
367 new_value_h()->obj_field_put(offset, ref_h());
368 } else {
369 int field_index = cpe->field_index();
370 InlineKlass* field_ik = InlineKlass::cast(ik->get_inline_type_field_klass(field_index));
371 field_ik->write_inlined_field(new_value_h(), offset, ref_h(), CHECK_(ret_adj));
372 }
373 } else {
374 new_value_h()->obj_field_put(offset, ref_h());
375 }
376 }
377 break;
378 default:
379 ShouldNotReachHere();
380 }
381 current->set_vm_result(new_value_h());
382 return ret_adj;
383 JRT_END
384
385 JRT_ENTRY(void, InterpreterRuntime::uninitialized_static_inline_type_field(JavaThread* current, oopDesc* mirror, int index))
386 // The interpreter tries to access an inline static field that has not been initialized.
387 // This situation can happen in different scenarios:
388 // 1 - if the load or initialization of the field failed during step 8 of
389 // the initialization of the holder of the field, in this case the access to the field
390 // must fail
391 // 2 - it can also happen when the initialization of the holder class triggered the initialization of
392 // another class which accesses this field in its static initializer, in this case the
393 // access must succeed to allow circularity
394 // The code below tries to load and initialize the field's class again before returning the default value.
395 // If the field was not initialized because of an error, an exception should be thrown.
396 // If the class is being initialized, the default value is returned.
397 instanceHandle mirror_h(THREAD, (instanceOop)mirror);
398 InstanceKlass* klass = InstanceKlass::cast(java_lang_Class::as_Klass(mirror));
399 assert(klass->field_signature(index)->is_Q_signature(), "Sanity check");
400 if (klass->is_being_initialized() && klass->is_reentrant_initialization(THREAD)) {
401 int offset = klass->field_offset(index);
402 Klass* field_k = klass->get_inline_type_field_klass_or_null(index);
403 if (field_k == NULL) {
404 field_k = SystemDictionary::resolve_or_fail(klass->field_signature(index)->fundamental_name(THREAD),
405 Handle(THREAD, klass->class_loader()),
406 Handle(THREAD, klass->protection_domain()),
407 true, CHECK);
408 assert(field_k != NULL, "Should have been loaded or an exception thrown above");
409 klass->set_inline_type_field_klass(index, field_k);
410 }
411 field_k->initialize(CHECK);
412 oop defaultvalue = InlineKlass::cast(field_k)->default_value();
413 // It is safe to initialize the static field because 1) the current thread is the initializing thread
414 // and is the only one that can access it, and 2) the field is actually not initialized (i.e. null)
415 // otherwise the JVM should not be executing this code.
416 mirror_h()->obj_field_put(offset, defaultvalue);
417 current->set_vm_result(defaultvalue);
418 } else {
419 assert(klass->is_in_error_state(), "If not initializing, initialization must have failed to get there");
420 ResourceMark rm(THREAD);
421 const char* desc = "Could not initialize class ";
422 const char* className = klass->external_name();
423 size_t msglen = strlen(desc) + strlen(className) + 1;
424 char* message = NEW_RESOURCE_ARRAY(char, msglen);
425 if (NULL == message) {
426 // Out of memory: can't create detailed error message
427 THROW_MSG(vmSymbols::java_lang_NoClassDefFoundError(), className);
428 } else {
429 jio_snprintf(message, msglen, "%s%s", desc, className);
430 THROW_MSG(vmSymbols::java_lang_NoClassDefFoundError(), message);
431 }
432 }
433 JRT_END
434
435 JRT_ENTRY(void, InterpreterRuntime::read_inlined_field(JavaThread* current, oopDesc* obj, int index, Klass* field_holder))
436 Handle obj_h(THREAD, obj);
437
438 assert(oopDesc::is_oop(obj), "Sanity check");
439
440 assert(field_holder->is_instance_klass(), "Sanity check");
441 InstanceKlass* klass = InstanceKlass::cast(field_holder);
442
443 assert(klass->field_is_inlined(index), "Sanity check");
444
445 InlineKlass* field_vklass = InlineKlass::cast(klass->get_inline_type_field_klass(index));
446
447 oop res = field_vklass->read_inlined_field(obj_h(), klass->field_offset(index), CHECK);
448 current->set_vm_result(res);
449 JRT_END
450
451 JRT_ENTRY(void, InterpreterRuntime::newarray(JavaThread* current, BasicType type, jint size))
452 oop obj = oopFactory::new_typeArray(type, size, CHECK);
453 current->set_vm_result(obj);
454 JRT_END
455
456
457 JRT_ENTRY(void, InterpreterRuntime::anewarray(JavaThread* current, ConstantPool* pool, int index, jint size))
458 Klass* klass = pool->klass_at(index, CHECK);
459 bool is_qtype_desc = pool->tag_at(index).is_Qdescriptor_klass();
460 arrayOop obj;
461 if ((!klass->is_array_klass()) && is_qtype_desc) { // Logically creates elements, ensure klass init
462 klass->initialize(CHECK);
463 obj = oopFactory::new_valueArray(klass, size, CHECK);
464 } else {
465 obj = oopFactory::new_objArray(klass, size, CHECK);
466 }
467 current->set_vm_result(obj);
468 JRT_END
469
470 JRT_ENTRY(void, InterpreterRuntime::value_array_load(JavaThread* current, arrayOopDesc* array, int index))
471 flatArrayHandle vah(current, (flatArrayOop)array);
472 oop value_holder = flatArrayOopDesc::value_alloc_copy_from_index(vah, index, CHECK);
473 current->set_vm_result(value_holder);
474 JRT_END
475
476 JRT_ENTRY(void, InterpreterRuntime::value_array_store(JavaThread* current, void* val, arrayOopDesc* array, int index))
477 assert(val != NULL, "can't store null into flat array");
478 ((flatArrayOop)array)->value_copy_to_index(cast_to_oop(val), index);
479 JRT_END
480
481 JRT_ENTRY(void, InterpreterRuntime::multianewarray(JavaThread* current, jint* first_size_address))
482 // We may want to pass in more arguments - could make this slightly faster
483 LastFrameAccessor last_frame(current);
484 ConstantPool* constants = last_frame.method()->constants();
485 int i = last_frame.get_index_u2(Bytecodes::_multianewarray);
486 Klass* klass = constants->klass_at(i, CHECK);
487 bool is_qtype = klass->name()->is_Q_array_signature();
488 int nof_dims = last_frame.number_of_dimensions();
489 assert(klass->is_klass(), "not a class");
490 assert(nof_dims >= 1, "multianewarray rank must be nonzero");
491
492 if (is_qtype) { // Logically creates elements, ensure klass init
493 klass->initialize(CHECK);
494 }
495
496 // We must create an array of jints to pass to multi_allocate.
497 ResourceMark rm(current);
498 const int small_dims = 10;
499 jint dim_array[small_dims];
500 jint *dims = &dim_array[0];
501 if (nof_dims > small_dims) {
502 dims = (jint*) NEW_RESOURCE_ARRAY(jint, nof_dims);
503 }
504 for (int index = 0; index < nof_dims; index++) {
505 // offset from first_size_address is addressed as local[index]
506 int n = Interpreter::local_offset_in_bytes(index)/jintSize;
507 dims[index] = first_size_address[n];
508 }
509 oop obj = ArrayKlass::cast(klass)->multi_allocate(nof_dims, dims, CHECK);
510 current->set_vm_result(obj);
511 JRT_END
512
513
514 JRT_ENTRY(void, InterpreterRuntime::register_finalizer(JavaThread* current, oopDesc* obj))
515 assert(oopDesc::is_oop(obj), "must be a valid oop");
516 assert(obj->klass()->has_finalizer(), "shouldn't be here otherwise");
517 InstanceKlass::register_finalizer(instanceOop(obj), CHECK);
518 JRT_END
519
520 JRT_ENTRY(jboolean, InterpreterRuntime::is_substitutable(JavaThread* current, oopDesc* aobj, oopDesc* bobj))
521 assert(oopDesc::is_oop(aobj) && oopDesc::is_oop(bobj), "must be valid oops");
522
523 Handle ha(THREAD, aobj);
524 Handle hb(THREAD, bobj);
525 JavaValue result(T_BOOLEAN);
526 JavaCallArguments args;
527 args.push_oop(ha);
528 args.push_oop(hb);
529 methodHandle method(current, Universe::is_substitutable_method());
530 JavaCalls::call(&result, method, &args, THREAD);
531 if (HAS_PENDING_EXCEPTION) {
532 // Something really bad happened because isSubstitutable() should not throw exceptions
533 // If it is an error, just let it propagate
534 // If it is an exception, wrap it into an InternalError
535 if (!PENDING_EXCEPTION->is_a(vmClasses::Error_klass())) {
536 Handle e(THREAD, PENDING_EXCEPTION);
537 CLEAR_PENDING_EXCEPTION;
538 THROW_MSG_CAUSE_(vmSymbols::java_lang_InternalError(), "Internal error in substitutability test", e, false);
539 }
540 }
541 return result.get_jboolean();
542 JRT_END
543
544 // Quicken instance-of and check-cast bytecodes
545 JRT_ENTRY(void, InterpreterRuntime::quicken_io_cc(JavaThread* current))
546 // Force resolving; quicken the bytecode
547 LastFrameAccessor last_frame(current);
548 int which = last_frame.get_index_u2(Bytecodes::_checkcast);
549 ConstantPool* cpool = last_frame.method()->constants();
550 // We'd expect to assert that we're only here to quicken bytecodes, but in a multithreaded
551 // program we might have seen an unquick'd bytecode in the interpreter but have another
552 // thread quicken the bytecode before we get here.
553 // assert( cpool->tag_at(which).is_unresolved_klass(), "should only come here to quicken bytecodes" );
554 Klass* klass = cpool->klass_at(which, CHECK);
555 current->set_vm_result_2(klass);
556 JRT_END
557
558
559 //------------------------------------------------------------------------------------------------------------------------
560 // Exceptions
561
562 void InterpreterRuntime::note_trap_inner(JavaThread* current, int reason,
853 // and therefore we don't have the receiver object at our fingertips. (Though,
854 // on some platforms the receiver still resides in a register...). Thus,
855 // we have no choice but print an error message not containing the receiver
856 // type.
857 JRT_ENTRY(void, InterpreterRuntime::throw_AbstractMethodErrorWithMethod(JavaThread* current,
858 Method* missingMethod))
859 ResourceMark rm(current);
860 assert(missingMethod != NULL, "sanity");
861 methodHandle m(current, missingMethod);
862 LinkResolver::throw_abstract_method_error(m, THREAD);
863 JRT_END
864
865 JRT_ENTRY(void, InterpreterRuntime::throw_AbstractMethodErrorVerbose(JavaThread* current,
866 Klass* recvKlass,
867 Method* missingMethod))
868 ResourceMark rm(current);
869 methodHandle mh = methodHandle(current, missingMethod);
870 LinkResolver::throw_abstract_method_error(mh, recvKlass, THREAD);
871 JRT_END
872
873 JRT_ENTRY(void, InterpreterRuntime::throw_InstantiationError(JavaThread* current))
874 THROW(vmSymbols::java_lang_InstantiationError());
875 JRT_END
876
877
878 JRT_ENTRY(void, InterpreterRuntime::throw_IncompatibleClassChangeError(JavaThread* current))
879 THROW(vmSymbols::java_lang_IncompatibleClassChangeError());
880 JRT_END
881
882 JRT_ENTRY(void, InterpreterRuntime::throw_IncompatibleClassChangeErrorVerbose(JavaThread* current,
883 Klass* recvKlass,
884 Klass* interfaceKlass))
885 ResourceMark rm(current);
886 char buf[1000];
887 buf[0] = '\0';
888 jio_snprintf(buf, sizeof(buf),
889 "Class %s does not implement the requested interface %s",
890 recvKlass ? recvKlass->external_name() : "NULL",
891 interfaceKlass ? interfaceKlass->external_name() : "NULL");
892 THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
893 JRT_END
894
895 JRT_ENTRY(void, InterpreterRuntime::throw_NullPointerException(JavaThread* current))
896 THROW(vmSymbols::java_lang_NullPointerException());
897 JRT_END
898
899 //------------------------------------------------------------------------------------------------------------------------
900 // Fields
901 //
902
903 void InterpreterRuntime::resolve_get_put(JavaThread* current, Bytecodes::Code bytecode) {
904 // resolve field
905 fieldDescriptor info;
906 LastFrameAccessor last_frame(current);
907 constantPoolHandle pool(current, last_frame.method()->constants());
908 methodHandle m(current, last_frame.method());
909 bool is_put = (bytecode == Bytecodes::_putfield || bytecode == Bytecodes::_nofast_putfield ||
910 bytecode == Bytecodes::_putstatic || bytecode == Bytecodes::_withfield);
911 bool is_static = (bytecode == Bytecodes::_getstatic || bytecode == Bytecodes::_putstatic);
912 bool is_inline_type = bytecode == Bytecodes::_withfield;
913
914 {
915 JvmtiHideSingleStepping jhss(current);
916 JavaThread* THREAD = current; // For exception macros.
917 LinkResolver::resolve_field_access(info, pool, last_frame.get_index_u2_cpcache(bytecode),
918 m, bytecode, CHECK);
919 } // end JvmtiHideSingleStepping
920
921 // check if link resolution caused cpCache to be updated
922 ConstantPoolCacheEntry* cp_cache_entry = last_frame.cache_entry();
923 if (cp_cache_entry->is_resolved(bytecode)) return;
924
925 // compute auxiliary field attributes
926 TosState state = as_TosState(info.field_type());
927
928 // Resolution of put instructions on final fields is delayed. That is required so that
929 // exceptions are thrown at the correct place (when the instruction is actually invoked).
930 // If we do not resolve an instruction in the current pass, leaving the put_code
931 // set to zero will cause the next put instruction to the same field to reresolve.
932
937 // initializer method <init>. If resolution were not inhibited, a putfield
938 // in an initializer method could be resolved in the initializer. Subsequent
939 // putfield instructions to the same field would then use cached information.
940 // As a result, those instructions would not pass through the VM. That is,
941 // checks in resolve_field_access() would not be executed for those instructions
942 // and the required IllegalAccessError would not be thrown.
943 //
944 // Also, we need to delay resolving getstatic and putstatic instructions until the
945 // class is initialized. This is required so that access to the static
946 // field will call the initialization function every time until the class
947 // is completely initialized ala. in 2.17.5 in JVM Specification.
948 InstanceKlass* klass = info.field_holder();
949 bool uninitialized_static = is_static && !klass->is_initialized();
950 bool has_initialized_final_update = info.field_holder()->major_version() >= 53 &&
951 info.has_initialized_final_update();
952 assert(!(has_initialized_final_update && !info.access_flags().is_final()), "Fields with initialized final updates must be final");
953
954 Bytecodes::Code get_code = (Bytecodes::Code)0;
955 Bytecodes::Code put_code = (Bytecodes::Code)0;
956 if (!uninitialized_static) {
957 if (is_static) {
958 get_code = Bytecodes::_getstatic;
959 } else {
960 get_code = Bytecodes::_getfield;
961 }
962 if (is_put && is_inline_type) {
963 put_code = ((is_static) ? Bytecodes::_putstatic : Bytecodes::_withfield);
964 } else if ((is_put && !has_initialized_final_update) || !info.access_flags().is_final()) {
965 put_code = ((is_static) ? Bytecodes::_putstatic : Bytecodes::_putfield);
966 }
967 }
968
969 cp_cache_entry->set_field(
970 get_code,
971 put_code,
972 info.field_holder(),
973 info.index(),
974 info.offset(),
975 state,
976 info.access_flags().is_final(),
977 info.access_flags().is_volatile(),
978 info.is_inlined(),
979 info.signature()->is_Q_signature() && info.is_inline_type()
980 );
981 }
982
983
984 //------------------------------------------------------------------------------------------------------------------------
985 // Synchronization
986 //
987 // The interpreter's synchronization code is factored out so that it can
988 // be shared by method invocation and synchronized blocks.
989 //%note synchronization_3
990
991 //%note monitor_1
992 JRT_ENTRY_NO_ASYNC(void, InterpreterRuntime::monitorenter(JavaThread* current, BasicObjectLock* elem))
993 #ifdef ASSERT
994 current->last_frame().interpreter_frame_verify_monitor(elem);
995 #endif
996 Handle h_obj(current, elem->obj());
997 assert(Universe::heap()->is_in_or_null(h_obj()),
998 "must be NULL or an object");
999 ObjectSynchronizer::enter(h_obj, elem->lock(), current);
1202 {
1203 JvmtiHideSingleStepping jhss(current);
1204 JavaThread* THREAD = current; // For exception macros.
1205 LinkResolver::resolve_invoke(info, Handle(), pool,
1206 index, bytecode, CHECK);
1207 } // end JvmtiHideSingleStepping
1208
1209 ConstantPoolCacheEntry* cp_cache_entry = pool->invokedynamic_cp_cache_entry_at(index);
1210 cp_cache_entry->set_dynamic_call(pool, info);
1211 }
1212
1213 // This function is the interface to the assembly code. It returns the resolved
1214 // cpCache entry. This doesn't safepoint, but the helper routines safepoint.
1215 // This function will check for redefinition!
1216 JRT_ENTRY(void, InterpreterRuntime::resolve_from_cache(JavaThread* current, Bytecodes::Code bytecode)) {
1217 switch (bytecode) {
1218 case Bytecodes::_getstatic:
1219 case Bytecodes::_putstatic:
1220 case Bytecodes::_getfield:
1221 case Bytecodes::_putfield:
1222 case Bytecodes::_withfield:
1223 resolve_get_put(current, bytecode);
1224 break;
1225 case Bytecodes::_invokevirtual:
1226 case Bytecodes::_invokespecial:
1227 case Bytecodes::_invokestatic:
1228 case Bytecodes::_invokeinterface:
1229 resolve_invoke(current, bytecode);
1230 break;
1231 case Bytecodes::_invokehandle:
1232 resolve_invokehandle(current);
1233 break;
1234 case Bytecodes::_invokedynamic:
1235 resolve_invokedynamic(current);
1236 break;
1237 default:
1238 fatal("unexpected bytecode: %s", Bytecodes::name(bytecode));
1239 break;
1240 }
1241 }
1242 JRT_END
1400 // This function is called by the interpreter when the return poll found a reason
1401 // to call the VM. The reason could be that we are returning into a not yet safe
1402 // to access frame. We handle that below.
1403 // Note that this path does not check for single stepping, because we do not want
1404 // to single step when unwinding frames for an exception being thrown. Instead,
1405 // such single stepping code will use the safepoint table, which will use the
1406 // InterpreterRuntime::at_safepoint callback.
1407 StackWatermarkSet::before_unwind(current);
1408 JRT_END
1409
1410 JRT_ENTRY(void, InterpreterRuntime::post_field_access(JavaThread* current, oopDesc* obj,
1411 ConstantPoolCacheEntry *cp_entry))
1412
1413 // check the access_flags for the field in the klass
1414
1415 InstanceKlass* ik = InstanceKlass::cast(cp_entry->f1_as_klass());
1416 int index = cp_entry->field_index();
1417 if ((ik->field_access_flags(index) & JVM_ACC_FIELD_ACCESS_WATCHED) == 0) return;
1418
1419 bool is_static = (obj == NULL);
1420 bool is_inlined = cp_entry->is_inlined();
1421 HandleMark hm(current);
1422
1423 Handle h_obj;
1424 if (!is_static) {
1425 // non-static field accessors have an object, but we need a handle
1426 h_obj = Handle(current, obj);
1427 }
1428 InstanceKlass* cp_entry_f1 = InstanceKlass::cast(cp_entry->f1_as_klass());
1429 jfieldID fid = jfieldIDWorkaround::to_jfieldID(cp_entry_f1, cp_entry->f2_as_index(), is_static, is_inlined);
1430 LastFrameAccessor last_frame(current);
1431 JvmtiExport::post_field_access(current, last_frame.method(), last_frame.bcp(), cp_entry_f1, h_obj, fid);
1432 JRT_END
1433
1434 JRT_ENTRY(void, InterpreterRuntime::post_field_modification(JavaThread* current, oopDesc* obj,
1435 ConstantPoolCacheEntry *cp_entry, jvalue *value))
1436
1437 Klass* k = cp_entry->f1_as_klass();
1438
1439 // check the access_flags for the field in the klass
1440 InstanceKlass* ik = InstanceKlass::cast(k);
1441 int index = cp_entry->field_index();
1442 // bail out if field modifications are not watched
1443 if ((ik->field_access_flags(index) & JVM_ACC_FIELD_MODIFICATION_WATCHED) == 0) return;
1444
1445 char sig_type = '\0';
1446
1447 switch(cp_entry->flag_state()) {
1448 case btos: sig_type = JVM_SIGNATURE_BYTE; break;
1449 case ztos: sig_type = JVM_SIGNATURE_BOOLEAN; break;
1450 case ctos: sig_type = JVM_SIGNATURE_CHAR; break;
1451 case stos: sig_type = JVM_SIGNATURE_SHORT; break;
1452 case itos: sig_type = JVM_SIGNATURE_INT; break;
1453 case ftos: sig_type = JVM_SIGNATURE_FLOAT; break;
1454 case atos: sig_type = JVM_SIGNATURE_CLASS; break;
1455 case ltos: sig_type = JVM_SIGNATURE_LONG; break;
1456 case dtos: sig_type = JVM_SIGNATURE_DOUBLE; break;
1457 default: ShouldNotReachHere(); return;
1458 }
1459
1460 // Both Q-signatures and L-signatures are mapped to atos
1461 if (cp_entry->flag_state() == atos && ik->field_signature(index)->is_Q_signature()) {
1462 sig_type = JVM_SIGNATURE_PRIMITIVE_OBJECT;
1463 }
1464
1465 bool is_static = (obj == NULL);
1466 bool is_inlined = cp_entry->is_inlined();
1467
1468 HandleMark hm(current);
1469 jfieldID fid = jfieldIDWorkaround::to_jfieldID(ik, cp_entry->f2_as_index(), is_static, is_inlined);
1470 jvalue fvalue;
1471 #ifdef _LP64
1472 fvalue = *value;
1473 #else
1474 // Long/double values are stored unaligned and also noncontiguously with
1475 // tagged stacks. We can't just do a simple assignment even in the non-
1476 // J/D cases because a C++ compiler is allowed to assume that a jvalue is
1477 // 8-byte aligned, and interpreter stack slots are only 4-byte aligned.
1478 // We assume that the two halves of longs/doubles are stored in interpreter
1479 // stack slots in platform-endian order.
1480 jlong_accessor u;
1481 jint* newval = (jint*)value;
1482 u.words[0] = newval[0];
1483 u.words[1] = newval[Interpreter::stackElementWords]; // skip if tag
1484 fvalue.j = u.long_value;
1485 #endif // _LP64
1486
1487 Handle h_obj;
1488 if (!is_static) {
1489 // non-static field accessors have an object, but we need a handle
|