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(); }
106 int get_index_u2(Bytecodes::Code bc) const { return bytecode().get_index_u2(bc); }
107 int get_index_u4(Bytecodes::Code bc) const { return bytecode().get_index_u4(bc); }
108 int number_of_dimensions() const { return bcp()[3]; }
109
110 oop callee_receiver(Symbol* signature) {
111 return _last_frame.interpreter_callee_receiver(signature);
112 }
113 BasicObjectLock* monitor_begin() const {
114 return _last_frame.interpreter_frame_monitor_begin();
115 }
116 BasicObjectLock* monitor_end() const {
117 return _last_frame.interpreter_frame_monitor_end();
118 }
119 BasicObjectLock* next_monitor(BasicObjectLock* current) const {
120 return _last_frame.next_monitor_in_interpreter_frame(current);
121 }
122
123 frame& get_frame() { return _last_frame; }
124 };
125
126 //------------------------------------------------------------------------------------------------------------------------
127 // State accessors
128
129 void InterpreterRuntime::set_bcp_and_mdp(address bcp, JavaThread* current) {
130 LastFrameAccessor last_frame(current);
131 last_frame.set_bcp(bcp);
132 if (ProfileInterpreter) {
133 // ProfileTraps uses MDOs independently of ProfileInterpreter.
134 // That is why we must check both ProfileInterpreter and mdo != nullptr.
135 MethodData* mdo = last_frame.method()->method_data();
136 if (mdo != nullptr) {
137 NEEDS_CLEANUP;
138 last_frame.set_mdp(mdo->bci_to_dp(last_frame.bci()));
139 }
140 }
141 }
142
143 //------------------------------------------------------------------------------------------------------------------------
144 // Constants
145
146
147 JRT_ENTRY(void, InterpreterRuntime::ldc(JavaThread* current, bool wide))
148 // access constant pool
149 LastFrameAccessor last_frame(current);
150 ConstantPool* pool = last_frame.method()->constants();
151 int cp_index = wide ? last_frame.get_index_u2(Bytecodes::_ldc_w) : last_frame.get_index_u1(Bytecodes::_ldc);
152 constantTag tag = pool->tag_at(cp_index);
153
154 assert (tag.is_unresolved_klass() || tag.is_klass(), "wrong ldc call");
155 Klass* klass = pool->klass_at(cp_index, CHECK);
156 oop java_class = klass->java_mirror();
157 current->set_vm_result(java_class);
158 JRT_END
159
160 JRT_ENTRY(void, InterpreterRuntime::resolve_ldc(JavaThread* current, Bytecodes::Code bytecode)) {
161 assert(bytecode == Bytecodes::_ldc ||
162 bytecode == Bytecodes::_ldc_w ||
163 bytecode == Bytecodes::_ldc2_w ||
164 bytecode == Bytecodes::_fast_aldc ||
165 bytecode == Bytecodes::_fast_aldc_w, "wrong bc");
166 ResourceMark rm(current);
167 const bool is_fast_aldc = (bytecode == Bytecodes::_fast_aldc ||
168 bytecode == Bytecodes::_fast_aldc_w);
169 LastFrameAccessor last_frame(current);
170 methodHandle m (current, last_frame.method());
171 Bytecode_loadconstant ldc(m, last_frame.bci());
172
173 // Double-check the size. (Condy can have any type.)
174 BasicType type = ldc.result_type();
175 switch (type2size[type]) {
176 case 2: guarantee(bytecode == Bytecodes::_ldc2_w, ""); break;
177 case 1: guarantee(bytecode != Bytecodes::_ldc2_w, ""); break;
178 default: ShouldNotReachHere();
179 }
180
196 assert(roop == coop, "expected result for assembly code");
197 }
198 }
199 #endif
200 current->set_vm_result(result);
201 if (!is_fast_aldc) {
202 // Tell the interpreter how to unbox the primitive.
203 guarantee(java_lang_boxing_object::is_instance(result, type), "");
204 int offset = java_lang_boxing_object::value_offset(type);
205 intptr_t flags = ((as_TosState(type) << ConstantPoolCache::tos_state_shift)
206 | (offset & ConstantPoolCache::field_index_mask));
207 current->set_vm_result_2((Metadata*)flags);
208 }
209 }
210 JRT_END
211
212
213 //------------------------------------------------------------------------------------------------------------------------
214 // Allocation
215
216 JRT_ENTRY(void, InterpreterRuntime::_new(JavaThread* current, ConstantPool* pool, int index))
217 Klass* k = pool->klass_at(index, CHECK);
218 InstanceKlass* klass = InstanceKlass::cast(k);
219
220 // Make sure we are not instantiating an abstract klass
221 klass->check_valid_for_instantiation(true, CHECK);
222
223 // Make sure klass is initialized
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,
312 const methodHandle& trap_method, int trap_bci) {
313 if (trap_method.not_null()) {
314 MethodData* trap_mdo = trap_method->method_data();
346 static Handle get_preinitialized_exception(Klass* k, TRAPS) {
347 // get klass
348 InstanceKlass* klass = InstanceKlass::cast(k);
349 assert(klass->is_initialized(),
350 "this klass should have been initialized during VM initialization");
351 // create instance - do not call constructor since we may have no
352 // (java) stack space left (should assert constructor is empty)
353 Handle exception;
354 oop exception_oop = klass->allocate_instance(CHECK_(exception));
355 exception = Handle(THREAD, exception_oop);
356 if (StackTraceInThrowable) {
357 java_lang_Throwable::fill_in_stack_trace(exception);
358 }
359 return exception;
360 }
361
362 // Special handling for stack overflow: since we don't have any (java) stack
363 // space left we use the pre-allocated & pre-initialized StackOverflowError
364 // klass to create an stack overflow error instance. We do not call its
365 // constructor for the same reason (it is empty, anyway).
366 JRT_ENTRY(void, InterpreterRuntime::throw_StackOverflowError(JavaThread* current))
367 Handle exception = get_preinitialized_exception(
368 vmClasses::StackOverflowError_klass(),
369 CHECK);
370 // Increment counter for hs_err file reporting
371 Atomic::inc(&Exceptions::_stack_overflow_errors);
372 // Remove the ScopedValue bindings in case we got a StackOverflowError
373 // while we were trying to manipulate ScopedValue bindings.
374 current->clear_scopedValueBindings();
375 THROW_HANDLE(exception);
376 JRT_END
377
378 JRT_ENTRY(void, InterpreterRuntime::throw_delayed_StackOverflowError(JavaThread* current))
379 Handle exception = get_preinitialized_exception(
380 vmClasses::StackOverflowError_klass(),
381 CHECK);
382 java_lang_Throwable::set_message(exception(),
383 Universe::delayed_stack_overflow_error_message());
384 // Increment counter for hs_err file reporting
385 Atomic::inc(&Exceptions::_stack_overflow_errors);
386 // Remove the ScopedValue bindings in case we got a StackOverflowError
387 // while we were trying to manipulate ScopedValue bindings.
388 current->clear_scopedValueBindings();
389 THROW_HANDLE(exception);
390 JRT_END
391
392 JRT_ENTRY(void, InterpreterRuntime::create_exception(JavaThread* current, char* name, char* message))
393 // lookup exception klass
394 TempNewSymbol s = SymbolTable::new_symbol(name);
395 if (ProfileTraps) {
396 if (s == vmSymbols::java_lang_ArithmeticException()) {
397 note_trap(current, Deoptimization::Reason_div0_check);
398 } else if (s == vmSymbols::java_lang_NullPointerException()) {
399 note_trap(current, Deoptimization::Reason_null_check);
400 }
401 }
402 // create exception
403 Handle exception = Exceptions::new_exception(current, s, message);
404 current->set_vm_result(exception());
405 JRT_END
406
407
408 JRT_ENTRY(void, InterpreterRuntime::create_klass_exception(JavaThread* current, char* name, oopDesc* obj))
409 // Produce the error message first because note_trap can safepoint
410 ResourceMark rm(current);
411 const char* klass_name = obj->klass()->external_name();
412 // lookup exception klass
413 TempNewSymbol s = SymbolTable::new_symbol(name);
414 if (ProfileTraps) {
415 if (s == vmSymbols::java_lang_ArrayStoreException()) {
416 note_trap(current, Deoptimization::Reason_array_check);
417 } else {
418 note_trap(current, Deoptimization::Reason_class_check);
419 }
420 }
421 // create exception, with klass name as detail message
422 Handle exception = Exceptions::new_exception(current, s, klass_name);
423 current->set_vm_result(exception());
424 JRT_END
425
426 JRT_ENTRY(void, InterpreterRuntime::throw_ArrayIndexOutOfBoundsException(JavaThread* current, arrayOopDesc* a, jint index))
427 // Produce the error message first because note_trap can safepoint
428 ResourceMark rm(current);
429 stringStream ss;
430 ss.print("Index %d out of bounds for length %d", index, a->length());
431
432 if (ProfileTraps) {
433 note_trap(current, Deoptimization::Reason_range_check);
434 }
435
436 THROW_MSG(vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), ss.as_string());
437 JRT_END
438
439 JRT_ENTRY(void, InterpreterRuntime::throw_ClassCastException(
440 JavaThread* current, oopDesc* obj))
441
442 // Produce the error message first because note_trap can safepoint
443 ResourceMark rm(current);
444 char* message = SharedRuntime::generate_class_cast_message(
445 current, obj->klass());
446
447 if (ProfileTraps) {
448 note_trap(current, Deoptimization::Reason_class_check);
449 }
450
451 // create exception
452 THROW_MSG(vmSymbols::java_lang_ClassCastException(), message);
453 JRT_END
454
455 // exception_handler_for_exception(...) returns the continuation address,
456 // the exception oop (via TLS) and sets the bci/bcp for the continuation.
457 // The exception oop is returned to make sure it is preserved over GC (it
458 // is only on the stack if the exception was thrown explicitly via athrow).
459 // During this operation, the expression stack contains the values for the
460 // bci where the exception happened. If the exception was propagated back
461 // from a call, the expression stack contains the values for the bci at the
462 // invoke w/o arguments (i.e., as if one were inside the call).
463 // Note that the implementation of this method assumes it's only called when an exception has actually occured
464 JRT_ENTRY(address, InterpreterRuntime::exception_handler_for_exception(JavaThread* current, oopDesc* exception))
465 // We get here after we have unwound from a callee throwing an exception
466 // into the interpreter. Any deferred stack processing is notified of
467 // the event via the StackWatermarkSet.
468 StackWatermarkSet::after_unwind(current);
469
470 LastFrameAccessor last_frame(current);
471 Handle h_exception(current, exception);
472 methodHandle h_method (current, last_frame.method());
473 constantPoolHandle h_constants(current, h_method->constants());
474 bool should_repeat;
475 int handler_bci;
476 int current_bci = last_frame.bci();
477
478 if (current->frames_to_pop_failed_realloc() > 0) {
479 // Allocation of scalar replaced object used in this frame
480 // failed. Unconditionally pop the frame.
481 current->dec_frames_to_pop_failed_realloc();
482 current->set_vm_result(h_exception());
483 // If the method is synchronized we already unlocked the monitor
484 // during deoptimization so the interpreter needs to skip it when
583 h_method->set_exception_handler_entered(handler_bci); // profiling
584 #ifndef ZERO
585 set_bcp_and_mdp(handler_pc, current);
586 continuation = Interpreter::dispatch_table(vtos)[*handler_pc];
587 #else
588 continuation = (address)(intptr_t) handler_bci;
589 #endif
590 }
591
592 // notify debugger of an exception catch
593 // (this is good for exceptions caught in native methods as well)
594 if (JvmtiExport::can_post_on_exceptions()) {
595 JvmtiExport::notice_unwind_due_to_exception(current, h_method(), handler_pc, h_exception(), (handler_pc != nullptr));
596 }
597
598 current->set_vm_result(h_exception());
599 return continuation;
600 JRT_END
601
602
603 JRT_ENTRY(void, InterpreterRuntime::throw_pending_exception(JavaThread* current))
604 assert(current->has_pending_exception(), "must only be called if there's an exception pending");
605 // nothing to do - eventually we should remove this code entirely (see comments @ call sites)
606 JRT_END
607
608
609 JRT_ENTRY(void, InterpreterRuntime::throw_AbstractMethodError(JavaThread* current))
610 THROW(vmSymbols::java_lang_AbstractMethodError());
611 JRT_END
612
613 // This method is called from the "abstract_entry" of the interpreter.
614 // At that point, the arguments have already been removed from the stack
615 // and therefore we don't have the receiver object at our fingertips. (Though,
616 // on some platforms the receiver still resides in a register...). Thus,
617 // we have no choice but print an error message not containing the receiver
618 // type.
619 JRT_ENTRY(void, InterpreterRuntime::throw_AbstractMethodErrorWithMethod(JavaThread* current,
620 Method* missingMethod))
621 ResourceMark rm(current);
622 assert(missingMethod != nullptr, "sanity");
623 methodHandle m(current, missingMethod);
624 LinkResolver::throw_abstract_method_error(m, THREAD);
625 JRT_END
626
627 JRT_ENTRY(void, InterpreterRuntime::throw_AbstractMethodErrorVerbose(JavaThread* current,
628 Klass* recvKlass,
629 Method* missingMethod))
630 ResourceMark rm(current);
631 methodHandle mh = methodHandle(current, missingMethod);
632 LinkResolver::throw_abstract_method_error(mh, recvKlass, THREAD);
633 JRT_END
634
635
636 JRT_ENTRY(void, InterpreterRuntime::throw_IncompatibleClassChangeError(JavaThread* current))
637 THROW(vmSymbols::java_lang_IncompatibleClassChangeError());
638 JRT_END
639
640 JRT_ENTRY(void, InterpreterRuntime::throw_IncompatibleClassChangeErrorVerbose(JavaThread* current,
641 Klass* recvKlass,
642 Klass* interfaceKlass))
643 ResourceMark rm(current);
644 char buf[1000];
645 buf[0] = '\0';
646 jio_snprintf(buf, sizeof(buf),
647 "Class %s does not implement the requested interface %s",
648 recvKlass ? recvKlass->external_name() : "nullptr",
649 interfaceKlass ? interfaceKlass->external_name() : "nullptr");
650 THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
651 JRT_END
652
653 JRT_ENTRY(void, InterpreterRuntime::throw_NullPointerException(JavaThread* current))
654 THROW(vmSymbols::java_lang_NullPointerException());
655 JRT_END
656
657 //------------------------------------------------------------------------------------------------------------------------
658 // Fields
659 //
660
661 void InterpreterRuntime::resolve_get_put(JavaThread* current, Bytecodes::Code bytecode) {
662 // resolve field
663 fieldDescriptor info;
664 LastFrameAccessor last_frame(current);
665 constantPoolHandle pool(current, last_frame.method()->constants());
666 methodHandle m(current, last_frame.method());
667 bool is_put = (bytecode == Bytecodes::_putfield || bytecode == Bytecodes::_nofast_putfield ||
668 bytecode == Bytecodes::_putstatic);
669 bool is_static = (bytecode == Bytecodes::_getstatic || bytecode == Bytecodes::_putstatic);
670
671 int field_index = last_frame.get_index_u2(bytecode);
672 {
673 JvmtiHideSingleStepping jhss(current);
674 JavaThread* THREAD = current; // For exception macros.
675 LinkResolver::resolve_field_access(info, pool, field_index,
676 m, bytecode, CHECK);
677 } // end JvmtiHideSingleStepping
678
679 // check if link resolution caused cpCache to be updated
680 if (pool->resolved_field_entry_at(field_index)->is_resolved(bytecode)) return;
681
682
683 // compute auxiliary field attributes
684 TosState state = as_TosState(info.field_type());
685
686 // Resolution of put instructions on final fields is delayed. That is required so that
687 // exceptions are thrown at the correct place (when the instruction is actually invoked).
688 // If we do not resolve an instruction in the current pass, leaving the put_code
689 // set to zero will cause the next put instruction to the same field to reresolve.
690
691 // Resolution of put instructions to final instance fields with invalid updates (i.e.,
692 // to final instance fields with updates originating from a method different than <init>)
693 // is inhibited. A putfield instruction targeting an instance final field must throw
694 // an IllegalAccessError if the instruction is not in an instance
695 // initializer method <init>. If resolution were not inhibited, a putfield
696 // in an initializer method could be resolved in the initializer. Subsequent
697 // putfield instructions to the same field would then use cached information.
698 // As a result, those instructions would not pass through the VM. That is,
699 // checks in resolve_field_access() would not be executed for those instructions
700 // and the required IllegalAccessError would not be thrown.
701 //
702 // Also, we need to delay resolving getstatic and putstatic instructions until the
703 // class is initialized. This is required so that access to the static
704 // field will call the initialization function every time until the class
705 // is completely initialized ala. in 2.17.5 in JVM Specification.
706 InstanceKlass* klass = info.field_holder();
707 bool uninitialized_static = is_static && !klass->is_initialized();
708 bool has_initialized_final_update = info.field_holder()->major_version() >= 53 &&
709 info.has_initialized_final_update();
710 assert(!(has_initialized_final_update && !info.access_flags().is_final()), "Fields with initialized final updates must be final");
711
712 Bytecodes::Code get_code = (Bytecodes::Code)0;
713 Bytecodes::Code put_code = (Bytecodes::Code)0;
714 if (!uninitialized_static) {
715 get_code = ((is_static) ? Bytecodes::_getstatic : Bytecodes::_getfield);
716 if ((is_put && !has_initialized_final_update) || !info.access_flags().is_final()) {
717 put_code = ((is_static) ? Bytecodes::_putstatic : Bytecodes::_putfield);
718 }
719 }
720
721 ResolvedFieldEntry* entry = pool->resolved_field_entry_at(field_index);
722 entry->set_flags(info.access_flags().is_final(), info.access_flags().is_volatile());
723 entry->fill_in(info.field_holder(), info.offset(),
724 checked_cast<u2>(info.index()), checked_cast<u1>(state),
725 static_cast<u1>(get_code), static_cast<u1>(put_code));
726 }
727
728
729 //------------------------------------------------------------------------------------------------------------------------
730 // Synchronization
731 //
732 // The interpreter's synchronization code is factored out so that it can
733 // be shared by method invocation and synchronized blocks.
734 //%note synchronization_3
735
736 //%note monitor_1
737 JRT_ENTRY_NO_ASYNC(void, InterpreterRuntime::monitorenter(JavaThread* current, BasicObjectLock* elem))
738 assert(LockingMode != LM_LIGHTWEIGHT, "Should call monitorenter_obj() when using the new lightweight locking");
739 #ifdef ASSERT
740 current->last_frame().interpreter_frame_verify_monitor(elem);
741 #endif
742 Handle h_obj(current, elem->obj());
743 assert(Universe::heap()->is_in_or_null(h_obj()),
744 "must be null or an object");
745 ObjectSynchronizer::enter(h_obj, elem->lock(), current);
746 assert(Universe::heap()->is_in_or_null(elem->obj()),
747 "must be null or an object");
748 #ifdef ASSERT
749 current->last_frame().interpreter_frame_verify_monitor(elem);
750 #endif
751 JRT_END
752
753 // NOTE: We provide a separate implementation for the new lightweight locking to workaround a limitation
754 // of registers in x86_32. This entry point accepts an oop instead of a BasicObjectLock*.
755 // The problem is that we would need to preserve the register that holds the BasicObjectLock,
756 // but we are using that register to hold the thread. We don't have enough registers to
757 // also keep the BasicObjectLock, but we don't really need it anyway, we only need
758 // the object. See also InterpreterMacroAssembler::lock_object().
759 // As soon as legacy stack-locking goes away we could remove the other monitorenter() entry
760 // point, and only use oop-accepting entries (same for monitorexit() below).
761 JRT_ENTRY_NO_ASYNC(void, InterpreterRuntime::monitorenter_obj(JavaThread* current, oopDesc* obj))
762 assert(LockingMode == LM_LIGHTWEIGHT, "Should call monitorenter() when not using the new lightweight locking");
763 Handle h_obj(current, cast_to_oop(obj));
764 assert(Universe::heap()->is_in_or_null(h_obj()),
765 "must be null or an object");
766 ObjectSynchronizer::enter(h_obj, nullptr, current);
767 return;
768 JRT_END
769
770 JRT_LEAF(void, InterpreterRuntime::monitorexit(BasicObjectLock* elem))
771 oop obj = elem->obj();
772 assert(Universe::heap()->is_in(obj), "must be an object");
773 // The object could become unlocked through a JNI call, which we have no other checks for.
774 // Give a fatal message if CheckJNICalls. Otherwise we ignore it.
775 if (obj->is_unlocked()) {
776 if (CheckJNICalls) {
777 fatal("Object has been unlocked by JNI");
778 }
779 return;
780 }
781 ObjectSynchronizer::exit(obj, elem->lock(), JavaThread::current());
782 // Free entry. If it is not cleared, the exception handling code will try to unlock the monitor
783 // again at method exit or in the case of an exception.
784 elem->set_obj(nullptr);
785 JRT_END
786
787
788 JRT_ENTRY(void, InterpreterRuntime::throw_illegal_monitor_state_exception(JavaThread* current))
789 THROW(vmSymbols::java_lang_IllegalMonitorStateException());
790 JRT_END
791
792
793 JRT_ENTRY(void, InterpreterRuntime::new_illegal_monitor_state_exception(JavaThread* current))
794 // Returns an illegal exception to install into the current thread. The
795 // pending_exception flag is cleared so normal exception handling does not
796 // trigger. Any current installed exception will be overwritten. This
797 // method will be called during an exception unwind.
798
799 assert(!HAS_PENDING_EXCEPTION, "no pending exception");
800 Handle exception(current, current->vm_result());
801 assert(exception() != nullptr, "vm result should be set");
802 current->set_vm_result(nullptr); // clear vm result before continuing (may cause memory leaks and assert failures)
803 exception = get_preinitialized_exception(vmClasses::IllegalMonitorStateException_klass(), CATCH);
804 current->set_vm_result(exception());
805 JRT_END
806
807
808 //------------------------------------------------------------------------------------------------------------------------
809 // Invokes
810
811 JRT_ENTRY(Bytecodes::Code, InterpreterRuntime::get_original_bytecode_at(JavaThread* current, Method* method, address bcp))
812 return method->orig_bytecode_at(method->bci_from(bcp));
813 JRT_END
814
815 JRT_ENTRY(void, InterpreterRuntime::set_original_bytecode_at(JavaThread* current, Method* method, address bcp, Bytecodes::Code new_code))
816 method->set_orig_bytecode_at(method->bci_from(bcp), new_code);
817 JRT_END
818
819 JRT_ENTRY(void, InterpreterRuntime::_breakpoint(JavaThread* current, Method* method, address bcp))
820 JvmtiExport::post_raw_breakpoint(current, method, bcp);
821 JRT_END
822
823 void InterpreterRuntime::resolve_invoke(JavaThread* current, Bytecodes::Code bytecode) {
824 LastFrameAccessor last_frame(current);
825 // extract receiver from the outgoing argument list if necessary
826 Handle receiver(current, nullptr);
827 if (bytecode == Bytecodes::_invokevirtual || bytecode == Bytecodes::_invokeinterface ||
828 bytecode == Bytecodes::_invokespecial) {
829 ResourceMark rm(current);
830 methodHandle m (current, last_frame.method());
831 Bytecode_invoke call(m, last_frame.bci());
832 Symbol* signature = call.signature();
833 receiver = Handle(current, last_frame.callee_receiver(signature));
834
835 assert(Universe::heap()->is_in_or_null(receiver()),
836 "sanity check");
837 assert(receiver.is_null() ||
838 !Universe::heap()->is_in(receiver->klass()),
839 "sanity check");
840 }
841
842 // resolve method
843 CallInfo info;
844 constantPoolHandle pool(current, last_frame.method()->constants());
845 ConstantPoolCache* cache = pool->cache();
846
847 methodHandle resolved_method;
848
849 int method_index = last_frame.get_index_u2(bytecode);
850 {
851 JvmtiHideSingleStepping jhss(current);
852 JavaThread* THREAD = current; // For exception macros.
853 LinkResolver::resolve_invoke(info, receiver, pool,
854 method_index, bytecode,
855 THREAD);
856
857 if (HAS_PENDING_EXCEPTION) {
858 if (ProfileTraps && PENDING_EXCEPTION->klass()->name() == vmSymbols::java_lang_NullPointerException()) {
859 // Preserve the original exception across the call to note_trap()
860 PreserveExceptionMark pm(current);
861 // Recording the trap will help the compiler to potentially recognize this exception as "hot"
862 note_trap(current, Deoptimization::Reason_null_check);
863 }
864 return;
865 }
866
867 resolved_method = methodHandle(current, info.resolved_method());
868 } // end JvmtiHideSingleStepping
869
870 // Don't allow safepoints until the method is cached.
871 NoSafepointVerifier nsv;
872
873 // check if link resolution caused cpCache to be updated
874 if (cache->resolved_method_entry_at(method_index)->is_resolved(bytecode)) return;
875
876 #ifdef ASSERT
877 if (bytecode == Bytecodes::_invokeinterface) {
878 if (resolved_method->method_holder() == vmClasses::Object_klass()) {
879 // NOTE: THIS IS A FIX FOR A CORNER CASE in the JVM spec
880 // (see also CallInfo::set_interface for details)
881 assert(info.call_kind() == CallInfo::vtable_call ||
882 info.call_kind() == CallInfo::direct_call, "");
883 assert(resolved_method->is_final() || info.has_vtable_index(),
884 "should have been set already");
885 } else if (!resolved_method->has_itable_index()) {
886 // Resolved something like CharSequence.toString. Use vtable not itable.
887 assert(info.call_kind() != CallInfo::itable_call, "");
888 } else {
889 // Setup itable entry
890 assert(info.call_kind() == CallInfo::itable_call, "");
891 int index = resolved_method->itable_index();
892 assert(info.itable_index() == index, "");
893 }
906 switch (info.call_kind()) {
907 case CallInfo::direct_call:
908 cache->set_direct_call(bytecode, method_index, resolved_method, sender->is_interface());
909 break;
910 case CallInfo::vtable_call:
911 cache->set_vtable_call(bytecode, method_index, resolved_method, info.vtable_index());
912 break;
913 case CallInfo::itable_call:
914 cache->set_itable_call(
915 bytecode,
916 method_index,
917 info.resolved_klass(),
918 resolved_method,
919 info.itable_index());
920 break;
921 default: ShouldNotReachHere();
922 }
923 }
924
925
926 // First time execution: Resolve symbols, create a permanent MethodType object.
927 void InterpreterRuntime::resolve_invokehandle(JavaThread* current) {
928 const Bytecodes::Code bytecode = Bytecodes::_invokehandle;
929 LastFrameAccessor last_frame(current);
930
931 // resolve method
932 CallInfo info;
933 constantPoolHandle pool(current, last_frame.method()->constants());
934 int method_index = last_frame.get_index_u2(bytecode);
935 {
936 JvmtiHideSingleStepping jhss(current);
937 JavaThread* THREAD = current; // For exception macros.
938 LinkResolver::resolve_invoke(info, Handle(), pool,
939 method_index, bytecode,
940 CHECK);
941 } // end JvmtiHideSingleStepping
942
943 pool->cache()->set_method_handle(method_index, info);
944 }
945
946 // First time execution: Resolve symbols, create a permanent CallSite object.
947 void InterpreterRuntime::resolve_invokedynamic(JavaThread* current) {
948 LastFrameAccessor last_frame(current);
949 const Bytecodes::Code bytecode = Bytecodes::_invokedynamic;
950
951 // resolve method
952 CallInfo info;
953 constantPoolHandle pool(current, last_frame.method()->constants());
954 int index = last_frame.get_index_u4(bytecode);
955 {
956 JvmtiHideSingleStepping jhss(current);
957 JavaThread* THREAD = current; // For exception macros.
958 LinkResolver::resolve_invoke(info, Handle(), pool,
959 index, bytecode, CHECK);
960 } // end JvmtiHideSingleStepping
961
962 pool->cache()->set_dynamic_call(info, index);
963 }
964
965 // This function is the interface to the assembly code. It returns the resolved
966 // cpCache entry. This doesn't safepoint, but the helper routines safepoint.
967 // This function will check for redefinition!
968 JRT_ENTRY(void, InterpreterRuntime::resolve_from_cache(JavaThread* current, Bytecodes::Code bytecode)) {
969 switch (bytecode) {
970 case Bytecodes::_getstatic:
971 case Bytecodes::_putstatic:
972 case Bytecodes::_getfield:
973 case Bytecodes::_putfield:
974 resolve_get_put(current, bytecode);
975 break;
976 case Bytecodes::_invokevirtual:
977 case Bytecodes::_invokespecial:
978 case Bytecodes::_invokestatic:
979 case Bytecodes::_invokeinterface:
980 resolve_invoke(current, bytecode);
981 break;
982 case Bytecodes::_invokehandle:
983 resolve_invokehandle(current);
984 break;
985 case Bytecodes::_invokedynamic:
986 resolve_invokedynamic(current);
987 break;
988 default:
989 fatal("unexpected bytecode: %s", Bytecodes::name(bytecode));
990 break;
991 }
992 }
993 JRT_END
994
995 //------------------------------------------------------------------------------------------------------------------------
996 // Miscellaneous
997
998
999 nmethod* InterpreterRuntime::frequency_counter_overflow(JavaThread* current, address branch_bcp) {
1000 // Enable WXWrite: the function is called directly by interpreter.
1001 MACOS_AARCH64_ONLY(ThreadWXEnable wx(WXWrite, current));
1002
1003 // frequency_counter_overflow_inner can throw async exception.
1004 nmethod* nm = frequency_counter_overflow_inner(current, branch_bcp);
1005 assert(branch_bcp != nullptr || nm == nullptr, "always returns null for non OSR requests");
1006 if (branch_bcp != nullptr && nm != nullptr) {
1007 // This was a successful request for an OSR nmethod. Because
1023 }
1024 if (nm != nullptr && current->is_interp_only_mode()) {
1025 // Normally we never get an nm if is_interp_only_mode() is true, because
1026 // policy()->event has a check for this and won't compile the method when
1027 // true. However, it's possible for is_interp_only_mode() to become true
1028 // during the compilation. We don't want to return the nm in that case
1029 // because we want to continue to execute interpreted.
1030 nm = nullptr;
1031 }
1032 #ifndef PRODUCT
1033 if (TraceOnStackReplacement) {
1034 if (nm != nullptr) {
1035 tty->print("OSR entry @ pc: " INTPTR_FORMAT ": ", p2i(nm->osr_entry()));
1036 nm->print();
1037 }
1038 }
1039 #endif
1040 return nm;
1041 }
1042
1043 JRT_ENTRY(nmethod*,
1044 InterpreterRuntime::frequency_counter_overflow_inner(JavaThread* current, address branch_bcp))
1045 // use UnlockFlagSaver to clear and restore the _do_not_unlock_if_synchronized
1046 // flag, in case this method triggers classloading which will call into Java.
1047 UnlockFlagSaver fs(current);
1048
1049 LastFrameAccessor last_frame(current);
1050 assert(last_frame.is_interpreted_frame(), "must come from interpreter");
1051 methodHandle method(current, last_frame.method());
1052 const int branch_bci = branch_bcp != nullptr ? method->bci_from(branch_bcp) : InvocationEntryBci;
1053 const int bci = branch_bcp != nullptr ? method->bci_from(last_frame.bcp()) : InvocationEntryBci;
1054
1055 nmethod* osr_nm = CompilationPolicy::event(method, method, branch_bci, bci, CompLevel_none, nullptr, CHECK_NULL);
1056
1057 BarrierSetNMethod* bs_nm = BarrierSet::barrier_set()->barrier_set_nmethod();
1058 if (osr_nm != nullptr && bs_nm != nullptr) {
1059 if (!bs_nm->nmethod_osr_entry_barrier(osr_nm)) {
1060 osr_nm = nullptr;
1061 }
1062 }
1063 return osr_nm;
1064 JRT_END
1065
1066 JRT_LEAF(jint, InterpreterRuntime::bcp_to_di(Method* method, address cur_bcp))
1067 assert(ProfileInterpreter, "must be profiling interpreter");
1068 int bci = method->bci_from(cur_bcp);
1069 MethodData* mdo = method->method_data();
1070 if (mdo == nullptr) return 0;
1071 return mdo->bci_to_di(bci);
1072 JRT_END
1073
1074 #ifdef ASSERT
1075 JRT_LEAF(void, InterpreterRuntime::verify_mdp(Method* method, address bcp, address mdp))
1076 assert(ProfileInterpreter, "must be profiling interpreter");
1077
1078 MethodData* mdo = method->method_data();
1079 assert(mdo != nullptr, "must not be null");
1080
1081 int bci = method->bci_from(bcp);
1082
1083 address mdp2 = mdo->bci_to_dp(bci);
1084 if (mdp != mdp2) {
1085 ResourceMark rm;
1086 tty->print_cr("FAILED verify : actual mdp %p expected mdp %p @ bci %d", mdp, mdp2, bci);
1087 int current_di = mdo->dp_to_di(mdp);
1088 int expected_di = mdo->dp_to_di(mdp2);
1089 tty->print_cr(" actual di %d expected di %d", current_di, expected_di);
1090 int expected_approx_bci = mdo->data_at(expected_di)->bci();
1091 int approx_bci = -1;
1092 if (current_di >= 0) {
1093 approx_bci = mdo->data_at(current_di)->bci();
1094 }
1095 tty->print_cr(" actual bci is %d expected bci %d", approx_bci, expected_approx_bci);
1096 mdo->print_on(tty);
1097 method->print_codes();
1098 }
1099 assert(mdp == mdp2, "wrong mdp");
1100 JRT_END
1101 #endif // ASSERT
1102
1103 JRT_ENTRY(void, InterpreterRuntime::update_mdp_for_ret(JavaThread* current, int return_bci))
1104 assert(ProfileInterpreter, "must be profiling interpreter");
1105 ResourceMark rm(current);
1106 LastFrameAccessor last_frame(current);
1107 assert(last_frame.is_interpreted_frame(), "must come from interpreter");
1108 MethodData* h_mdo = last_frame.method()->method_data();
1109
1110 // Grab a lock to ensure atomic access to setting the return bci and
1111 // the displacement. This can block and GC, invalidating all naked oops.
1112 MutexLocker ml(RetData_lock);
1113
1114 // ProfileData is essentially a wrapper around a derived oop, so we
1115 // need to take the lock before making any ProfileData structures.
1116 ProfileData* data = h_mdo->data_at(h_mdo->dp_to_di(last_frame.mdp()));
1117 guarantee(data != nullptr, "profile data must be valid");
1118 RetData* rdata = data->as_RetData();
1119 address new_mdp = rdata->fixup_ret(return_bci, h_mdo);
1120 last_frame.set_mdp(new_mdp);
1121 JRT_END
1122
1123 JRT_ENTRY(MethodCounters*, InterpreterRuntime::build_method_counters(JavaThread* current, Method* m))
1124 return Method::build_method_counters(current, m);
1125 JRT_END
1126
1127
1128 JRT_ENTRY(void, InterpreterRuntime::at_safepoint(JavaThread* current))
1129 // We used to need an explicit preserve_arguments here for invoke bytecodes. However,
1130 // stack traversal automatically takes care of preserving arguments for invoke, so
1131 // this is no longer needed.
1132
1133 // JRT_END does an implicit safepoint check, hence we are guaranteed to block
1134 // if this is called during a safepoint
1135
1136 if (JvmtiExport::should_post_single_step()) {
1137 // This function is called by the interpreter when single stepping. Such single
1138 // stepping could unwind a frame. Then, it is important that we process any frames
1139 // that we might return into.
1140 StackWatermarkSet::before_unwind(current);
1141
1142 // We are called during regular safepoints and when the VM is
1143 // single stepping. If any thread is marked for single stepping,
1144 // then we may have JVMTI work to do.
1145 LastFrameAccessor last_frame(current);
1146 JvmtiExport::at_single_stepping_point(current, last_frame.method(), last_frame.bcp());
1147 }
1148 JRT_END
1149
1150 JRT_LEAF(void, InterpreterRuntime::at_unwind(JavaThread* current))
1151 assert(current == JavaThread::current(), "pre-condition");
1152 // This function is called by the interpreter when the return poll found a reason
1153 // to call the VM. The reason could be that we are returning into a not yet safe
1154 // to access frame. We handle that below.
1155 // Note that this path does not check for single stepping, because we do not want
1156 // to single step when unwinding frames for an exception being thrown. Instead,
1157 // such single stepping code will use the safepoint table, which will use the
1158 // InterpreterRuntime::at_safepoint callback.
1159 StackWatermarkSet::before_unwind(current);
1160 JRT_END
1161
1162 JRT_ENTRY(void, InterpreterRuntime::post_field_access(JavaThread* current, oopDesc* obj,
1163 ResolvedFieldEntry *entry))
1164
1165 // check the access_flags for the field in the klass
1166
1167 InstanceKlass* ik = entry->field_holder();
1168 int index = entry->field_index();
1169 if (!ik->field_status(index).is_access_watched()) return;
1170
1171 bool is_static = (obj == nullptr);
1172 HandleMark hm(current);
1173
1174 Handle h_obj;
1175 if (!is_static) {
1176 // non-static field accessors have an object, but we need a handle
1177 h_obj = Handle(current, obj);
1178 }
1179 InstanceKlass* field_holder = entry->field_holder(); // HERE
1180 jfieldID fid = jfieldIDWorkaround::to_jfieldID(field_holder, entry->field_offset(), is_static);
1181 LastFrameAccessor last_frame(current);
1182 JvmtiExport::post_field_access(current, last_frame.method(), last_frame.bcp(), field_holder, h_obj, fid);
1183 JRT_END
1184
1185 JRT_ENTRY(void, InterpreterRuntime::post_field_modification(JavaThread* current, oopDesc* obj,
1186 ResolvedFieldEntry *entry, jvalue *value))
1187
1188 InstanceKlass* ik = entry->field_holder();
1189
1190 // check the access_flags for the field in the klass
1191 int index = entry->field_index();
1192 // bail out if field modifications are not watched
1193 if (!ik->field_status(index).is_modification_watched()) return;
1194
1195 char sig_type = '\0';
1196
1197 switch((TosState)entry->tos_state()) {
1198 case btos: sig_type = JVM_SIGNATURE_BYTE; break;
1199 case ztos: sig_type = JVM_SIGNATURE_BOOLEAN; break;
1200 case ctos: sig_type = JVM_SIGNATURE_CHAR; break;
1201 case stos: sig_type = JVM_SIGNATURE_SHORT; break;
1202 case itos: sig_type = JVM_SIGNATURE_INT; break;
1203 case ftos: sig_type = JVM_SIGNATURE_FLOAT; break;
1204 case atos: sig_type = JVM_SIGNATURE_CLASS; break;
1205 case ltos: sig_type = JVM_SIGNATURE_LONG; break;
1206 case dtos: sig_type = JVM_SIGNATURE_DOUBLE; break;
1221 // We assume that the two halves of longs/doubles are stored in interpreter
1222 // stack slots in platform-endian order.
1223 jlong_accessor u;
1224 jint* newval = (jint*)value;
1225 u.words[0] = newval[0];
1226 u.words[1] = newval[Interpreter::stackElementWords]; // skip if tag
1227 fvalue.j = u.long_value;
1228 #endif // _LP64
1229
1230 Handle h_obj;
1231 if (!is_static) {
1232 // non-static field accessors have an object, but we need a handle
1233 h_obj = Handle(current, obj);
1234 }
1235
1236 LastFrameAccessor last_frame(current);
1237 JvmtiExport::post_raw_field_modification(current, last_frame.method(), last_frame.bcp(), ik, h_obj,
1238 fid, sig_type, &fvalue);
1239 JRT_END
1240
1241 JRT_ENTRY(void, InterpreterRuntime::post_method_entry(JavaThread* current))
1242 LastFrameAccessor last_frame(current);
1243 JvmtiExport::post_method_entry(current, last_frame.method(), last_frame.get_frame());
1244 JRT_END
1245
1246
1247 // This is a JRT_BLOCK_ENTRY because we have to stash away the return oop
1248 // before transitioning to VM, and restore it after transitioning back
1249 // to Java. The return oop at the top-of-stack, is not walked by the GC.
1250 JRT_BLOCK_ENTRY(void, InterpreterRuntime::post_method_exit(JavaThread* current))
1251 LastFrameAccessor last_frame(current);
1252 JvmtiExport::post_method_exit(current, last_frame.method(), last_frame.get_frame());
1253 JRT_END
1254
1255 JRT_LEAF(int, InterpreterRuntime::interpreter_contains(address pc))
1256 {
1257 return (Interpreter::contains(Continuation::get_top_return_pc_post_barrier(JavaThread::current(), pc)) ? 1 : 0);
1258 }
1259 JRT_END
1260
1261
1262 // Implementation of SignatureHandlerLibrary
1263
1264 #ifndef SHARING_FAST_NATIVE_FINGERPRINTS
1265 // Dummy definition (else normalization method is defined in CPU
1266 // dependent code)
1267 uint64_t InterpreterRuntime::normalize_fast_native_fingerprint(uint64_t fingerprint) {
1268 return fingerprint;
1269 }
1270 #endif
1271
1272 address SignatureHandlerLibrary::set_handler_blob() {
1273 BufferBlob* handler_blob = BufferBlob::create("native signature handlers", blob_size);
1274 if (handler_blob == nullptr) {
1275 return nullptr;
1433 } else {
1434 if (PrintSignatureHandlers) {
1435 tty->cr();
1436 tty->print_cr("duplicate argument handler #%d for fingerprint " UINT64_FORMAT "(old: " PTR_FORMAT ", new : " PTR_FORMAT ")",
1437 _handlers->length(),
1438 fingerprint,
1439 p2i(_handlers->at(handler_index)),
1440 p2i(handler));
1441 }
1442 }
1443 }
1444
1445
1446 BufferBlob* SignatureHandlerLibrary::_handler_blob = nullptr;
1447 address SignatureHandlerLibrary::_handler = nullptr;
1448 GrowableArray<uint64_t>* SignatureHandlerLibrary::_fingerprints = nullptr;
1449 GrowableArray<address>* SignatureHandlerLibrary::_handlers = nullptr;
1450 address SignatureHandlerLibrary::_buffer = nullptr;
1451
1452
1453 JRT_ENTRY(void, InterpreterRuntime::prepare_native_call(JavaThread* current, Method* method))
1454 methodHandle m(current, method);
1455 assert(m->is_native(), "sanity check");
1456 // lookup native function entry point if it doesn't exist
1457 if (!m->has_native_function()) {
1458 NativeLookup::lookup(m, CHECK);
1459 }
1460 // make sure signature handler is installed
1461 SignatureHandlerLibrary::add(m);
1462 // The interpreter entry point checks the signature handler first,
1463 // before trying to fetch the native entry point and klass mirror.
1464 // We must set the signature handler last, so that multiple processors
1465 // preparing the same method will be sure to see non-null entry & mirror.
1466 JRT_END
1467
1468 #if defined(IA32) || defined(AMD64) || defined(ARM)
1469 JRT_LEAF(void, InterpreterRuntime::popframe_move_outgoing_args(JavaThread* current, void* src_address, void* dest_address))
1470 assert(current == JavaThread::current(), "pre-condition");
1471 if (src_address == dest_address) {
1472 return;
1473 }
1474 ResourceMark rm;
1475 LastFrameAccessor last_frame(current);
1476 assert(last_frame.is_interpreted_frame(), "");
1477 jint bci = last_frame.bci();
1478 methodHandle mh(current, last_frame.method());
1479 Bytecode_invoke invoke(mh, bci);
1480 ArgumentSizeComputer asc(invoke.signature());
1481 int size_of_arguments = (asc.size() + (invoke.has_receiver() ? 1 : 0)); // receiver
1482 Copy::conjoint_jbytes(src_address, dest_address,
1483 size_of_arguments * Interpreter::stackElementSize);
1484 JRT_END
1485 #endif
1486
1487 #if INCLUDE_JVMTI
1488 // This is a support of the JVMTI PopFrame interface.
1489 // Make sure it is an invokestatic of a polymorphic intrinsic that has a member_name argument
1490 // and return it as a vm_result so that it can be reloaded in the list of invokestatic parameters.
1491 // The member_name argument is a saved reference (in local#0) to the member_name.
1492 // For backward compatibility with some JDK versions (7, 8) it can also be a direct method handle.
1493 // FIXME: remove DMH case after j.l.i.InvokerBytecodeGenerator code shape is updated.
1494 JRT_ENTRY(void, InterpreterRuntime::member_name_arg_or_null(JavaThread* current, address member_name,
1495 Method* method, address bcp))
1496 Bytecodes::Code code = Bytecodes::code_at(method, bcp);
1497 if (code != Bytecodes::_invokestatic) {
1498 return;
1499 }
1500 ConstantPool* cpool = method->constants();
1501 int cp_index = Bytes::get_native_u2(bcp + 1);
1502 Symbol* cname = cpool->klass_name_at(cpool->klass_ref_index_at(cp_index, code));
1503 Symbol* mname = cpool->name_ref_at(cp_index, code);
1504
1505 if (MethodHandles::has_member_arg(cname, mname)) {
1506 oop member_name_oop = cast_to_oop(member_name);
1507 if (java_lang_invoke_DirectMethodHandle::is_instance(member_name_oop)) {
1508 // FIXME: remove after j.l.i.InvokerBytecodeGenerator code shape is updated.
1509 member_name_oop = java_lang_invoke_DirectMethodHandle::member(member_name_oop);
1510 }
1511 current->set_vm_result(member_name_oop);
1512 } else {
1513 current->set_vm_result(nullptr);
1514 }
1515 JRT_END
1516 #endif // INCLUDE_JVMTI
1517
1518 #ifndef PRODUCT
1519 // This must be a JRT_LEAF function because the interpreter must save registers on x86 to
1520 // call this, which changes rsp and makes the interpreter's expression stack not walkable.
1521 // The generated code still uses call_VM because that will set up the frame pointer for
1522 // bcp and method.
1523 JRT_LEAF(intptr_t, InterpreterRuntime::trace_bytecode(JavaThread* current, intptr_t preserve_this_value, intptr_t tos, intptr_t tos2))
1524 assert(current == JavaThread::current(), "pre-condition");
1525 LastFrameAccessor last_frame(current);
1526 assert(last_frame.is_interpreted_frame(), "must be an interpreted frame");
1527 methodHandle mh(current, last_frame.method());
1528 BytecodeTracer::trace_interpreter(mh, last_frame.bcp(), tos, tos2);
1529 return preserve_this_value;
1530 JRT_END
1531 #endif // !PRODUCT
|
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/perfData.inline.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 "services/management.hpp"
78 #include "utilities/align.hpp"
79 #include "utilities/checkedCast.hpp"
80 #include "utilities/copy.hpp"
81 #include "utilities/events.hpp"
82 #ifdef COMPILER2
83 #include "opto/runtime.hpp"
84 #endif
85
86 // Helper class to access current interpreter state
87 class LastFrameAccessor : public StackObj {
88 frame _last_frame;
89 public:
90 LastFrameAccessor(JavaThread* current) {
91 assert(current == Thread::current(), "sanity");
92 _last_frame = current->last_frame();
93 }
94 bool is_interpreted_frame() const { return _last_frame.is_interpreted_frame(); }
95 Method* method() const { return _last_frame.interpreter_frame_method(); }
96 address bcp() const { return _last_frame.interpreter_frame_bcp(); }
97 int bci() const { return _last_frame.interpreter_frame_bci(); }
108 int get_index_u2(Bytecodes::Code bc) const { return bytecode().get_index_u2(bc); }
109 int get_index_u4(Bytecodes::Code bc) const { return bytecode().get_index_u4(bc); }
110 int number_of_dimensions() const { return bcp()[3]; }
111
112 oop callee_receiver(Symbol* signature) {
113 return _last_frame.interpreter_callee_receiver(signature);
114 }
115 BasicObjectLock* monitor_begin() const {
116 return _last_frame.interpreter_frame_monitor_begin();
117 }
118 BasicObjectLock* monitor_end() const {
119 return _last_frame.interpreter_frame_monitor_end();
120 }
121 BasicObjectLock* next_monitor(BasicObjectLock* current) const {
122 return _last_frame.next_monitor_in_interpreter_frame(current);
123 }
124
125 frame& get_frame() { return _last_frame; }
126 };
127
128 static bool is_resolved(JavaThread* current) {
129 LastFrameAccessor last_frame(current);
130 ConstantPool* constants = last_frame.method()->constants();
131 Bytecodes::Code bc = last_frame.code();
132
133 if (bc == Bytecodes::_ldc || bc == Bytecodes::_ldc_w || bc == Bytecodes::_ldc2_w ||
134 bc == Bytecodes::_fast_aldc || bc == Bytecodes::_fast_aldc_w) {
135 bool is_wide = (bc != Bytecodes::_ldc) && (bc != Bytecodes::_fast_aldc);
136 int index = (is_wide ? last_frame.get_index_u1(bc) : last_frame.get_index_u2(bc));
137 constantTag tag = constants->tag_at(index);
138 assert(tag.is_klass_or_reference(), "unknown tag: %s", tag.internal_name());
139 return constants->tag_at(index).is_klass();
140 } else if (bc == Bytecodes::_invokedynamic) {
141 int index = last_frame.get_index_u4(bc);
142 int indy_index = index;
143 ResolvedIndyEntry* indy_entry = constants->resolved_indy_entry_at(indy_index);
144 return indy_entry->is_resolved();
145 } else if (Bytecodes::is_invoke(bc)) {
146 int index = last_frame.get_index_u2(bc);
147 ResolvedMethodEntry* rme = constants->resolved_method_entry_at(index);
148 return rme->is_resolved(bc);
149 } else if (Bytecodes::is_field_code(bc) || bc == Bytecodes::_nofast_getfield || bc == Bytecodes::_nofast_putfield) {
150 if (bc == Bytecodes::_nofast_getfield) {
151 bc = Bytecodes::_getfield;
152 } else if (bc == Bytecodes::_nofast_putfield) {
153 bc = Bytecodes::_putfield;
154 }
155 int index = last_frame.get_index_u2(bc);
156 ResolvedFieldEntry* field_entry = constants->cache()->resolved_field_entry_at(index);
157 return field_entry->is_resolved(bc);
158 } else if (bc == Bytecodes::_new) {
159 int index = last_frame.get_index_u2(bc);
160 constantTag tag = constants->tag_at(index);
161 assert(tag.is_klass_or_reference(), "unknown tag: %s", tag.internal_name());
162 return constants->tag_at(index).is_klass();
163 }
164 return false;
165 }
166
167 static void trace_current_location(JavaThread* current) {
168 LogStreamHandle(Debug, init, interpreter) log;
169 if (current->profile_rt_calls() && log.is_enabled()) {
170 ResourceMark rm(current);
171 LastFrameAccessor last_frame(current);
172 Method* caller = last_frame.method();
173 ConstantPool* constants = caller->constants();
174 Bytecodes::Code bc = last_frame.code();
175 log.print("InterpreterRuntime: " INTPTR_FORMAT ": %s: " INTPTR_FORMAT,
176 p2i(current), Bytecodes::name(bc), p2i(caller));
177 if (caller->is_shared()) {
178 log.print(" shared");
179 }
180 if (is_resolved(current)) {
181 log.print(" resolved");
182 }
183 log.print(" ");
184 caller->print_short_name(&log);
185 log.print(" @ %d:", last_frame.bci());
186 int instruction_size = last_frame.bytecode().instruction_size();
187
188 if (Bytecodes::is_invoke(bc) && bc != Bytecodes::_invokedynamic) {
189 int index = last_frame.get_index_u2(bc);
190 ResolvedMethodEntry* rme = constants->resolved_method_entry_at(index);
191 if (rme->is_resolved(bc)) {
192 Method* m = rme->method();
193 if (m != nullptr) {
194 log.print(" %s", m->method_holder()->init_state_name());
195 } else {
196 log.print(" null");
197 }
198 }
199 } else if (Bytecodes::is_field_code(bc) || bc == Bytecodes::_nofast_getfield || bc == Bytecodes::_nofast_putfield) {
200 if (bc == Bytecodes::_nofast_getfield) {
201 bc = Bytecodes::_getfield;
202 } else if (bc == Bytecodes::_nofast_putfield) {
203 bc = Bytecodes::_putfield;
204 }
205 int index = last_frame.get_index_u2(bc);
206 ResolvedFieldEntry* field_entry = constants->cache()->resolved_field_entry_at(index);
207
208 if (field_entry->is_resolved(bc)) {
209 log.print(" %s", field_entry->field_holder()->init_state_name());
210 }
211 } else if (bc == Bytecodes::_new) {
212 int index = last_frame.get_index_u2(bc);
213 constantTag tag = constants->tag_at(index);
214 assert(tag.is_klass_or_reference(), "unknown tag: %s", tag.internal_name());
215 if (constants->tag_at(index).is_klass()) {
216 CPKlassSlot kslot = constants->klass_slot_at(index);
217 int resolved_klass_index = kslot.resolved_klass_index();
218 Klass* k = constants->resolved_klasses()->at(resolved_klass_index);
219 log.print(": %s", InstanceKlass::cast(k)->init_state_name());
220 }
221 }
222 log.print(" ");
223 caller->print_codes_on(last_frame.bci(), last_frame.bci() + instruction_size, &log, /*flags*/ 0);
224
225 LogStreamHandle(Trace, init, interpreter) log1;
226 if (log1.is_enabled()) {
227 if (bc == Bytecodes::_invokedynamic) {
228 int index = last_frame.get_index_u4(bc);
229 int indy_index = index;
230 ResolvedIndyEntry* indy_entry = constants->resolved_indy_entry_at(indy_index);
231 indy_entry->print_on(&log1);
232 } else if (Bytecodes::is_invoke(bc)) {
233 int index = last_frame.get_index_u2(bc);
234 ResolvedMethodEntry* rme = constants->resolved_method_entry_at(index);
235 rme->print_on(&log1);
236 } else if (Bytecodes::is_field_code(bc) || bc == Bytecodes::_nofast_getfield || bc == Bytecodes::_nofast_putfield) {
237 int index = last_frame.get_index_u2(bc);
238 ResolvedFieldEntry* field_entry = constants->cache()->resolved_field_entry_at(index);
239 field_entry->print_on(&log1);
240 }
241 }
242 }
243 }
244
245 //------------------------------------------------------------------------------------------------------------------------
246 // State accessors
247
248 void InterpreterRuntime::set_bcp_and_mdp(address bcp, JavaThread* current) {
249 LastFrameAccessor last_frame(current);
250 last_frame.set_bcp(bcp);
251 if (ProfileInterpreter) {
252 // ProfileTraps uses MDOs independently of ProfileInterpreter.
253 // That is why we must check both ProfileInterpreter and mdo != nullptr.
254 MethodData* mdo = last_frame.method()->method_data();
255 if (mdo != nullptr) {
256 NEEDS_CLEANUP;
257 last_frame.set_mdp(mdo->bci_to_dp(last_frame.bci()));
258 }
259 }
260 }
261
262 //------------------------------------------------------------------------------------------------------------------------
263 // Constants
264
265
266 JRT_ENTRY_PROF(void, InterpreterRuntime, ldc, InterpreterRuntime::ldc(JavaThread* current, bool wide))
267 // access constant pool
268 LastFrameAccessor last_frame(current);
269 ConstantPool* pool = last_frame.method()->constants();
270 int cp_index = wide ? last_frame.get_index_u2(Bytecodes::_ldc_w) : last_frame.get_index_u1(Bytecodes::_ldc);
271 constantTag tag = pool->tag_at(cp_index);
272
273 assert (tag.is_unresolved_klass() || tag.is_klass(), "wrong ldc call");
274 Klass* klass = pool->klass_at(cp_index, CHECK);
275 oop java_class = klass->java_mirror();
276 current->set_vm_result(java_class);
277 JRT_END
278
279 JRT_ENTRY_PROF(void, InterpreterRuntime, resolve_ldc, InterpreterRuntime::resolve_ldc(JavaThread* current, Bytecodes::Code bytecode)) {
280 assert(bytecode == Bytecodes::_ldc ||
281 bytecode == Bytecodes::_ldc_w ||
282 bytecode == Bytecodes::_ldc2_w ||
283 bytecode == Bytecodes::_fast_aldc ||
284 bytecode == Bytecodes::_fast_aldc_w, "wrong bc");
285 ResourceMark rm(current);
286 const bool is_fast_aldc = (bytecode == Bytecodes::_fast_aldc ||
287 bytecode == Bytecodes::_fast_aldc_w);
288 LastFrameAccessor last_frame(current);
289 methodHandle m (current, last_frame.method());
290 Bytecode_loadconstant ldc(m, last_frame.bci());
291
292 // Double-check the size. (Condy can have any type.)
293 BasicType type = ldc.result_type();
294 switch (type2size[type]) {
295 case 2: guarantee(bytecode == Bytecodes::_ldc2_w, ""); break;
296 case 1: guarantee(bytecode != Bytecodes::_ldc2_w, ""); break;
297 default: ShouldNotReachHere();
298 }
299
315 assert(roop == coop, "expected result for assembly code");
316 }
317 }
318 #endif
319 current->set_vm_result(result);
320 if (!is_fast_aldc) {
321 // Tell the interpreter how to unbox the primitive.
322 guarantee(java_lang_boxing_object::is_instance(result, type), "");
323 int offset = java_lang_boxing_object::value_offset(type);
324 intptr_t flags = ((as_TosState(type) << ConstantPoolCache::tos_state_shift)
325 | (offset & ConstantPoolCache::field_index_mask));
326 current->set_vm_result_2((Metadata*)flags);
327 }
328 }
329 JRT_END
330
331
332 //------------------------------------------------------------------------------------------------------------------------
333 // Allocation
334
335 JRT_ENTRY_PROF(void, InterpreterRuntime, new, InterpreterRuntime::_new(JavaThread* current, ConstantPool* pool, int index))
336 Klass* k = pool->klass_at(index, CHECK);
337 InstanceKlass* klass = InstanceKlass::cast(k);
338
339 // Make sure we are not instantiating an abstract klass
340 klass->check_valid_for_instantiation(true, CHECK);
341
342 // Make sure klass is initialized
343 klass->initialize(CHECK);
344
345 // At this point the class may not be fully initialized
346 // because of recursive initialization. If it is fully
347 // initialized & has_finalized is not set, we rewrite
348 // it into its fast version (Note: no locking is needed
349 // here since this is an atomic byte write and can be
350 // done more than once).
351 //
352 // Note: In case of classes with has_finalized we don't
353 // rewrite since that saves us an extra check in
354 // the fast version which then would call the
355 // slow version anyway (and do a call back into
356 // Java).
357 // If we have a breakpoint, then we don't rewrite
358 // because the _breakpoint bytecode would be lost.
359 oop obj = klass->allocate_instance(CHECK);
360 current->set_vm_result(obj);
361 JRT_END
362
363
364 JRT_ENTRY_PROF(void, InterpreterRuntime, newarray, InterpreterRuntime::newarray(JavaThread* current, BasicType type, jint size))
365 oop obj = oopFactory::new_typeArray(type, size, CHECK);
366 current->set_vm_result(obj);
367 JRT_END
368
369
370 JRT_ENTRY_PROF(void, InterpreterRuntime, anewarray, InterpreterRuntime::anewarray(JavaThread* current, ConstantPool* pool, int index, jint size))
371 Klass* klass = pool->klass_at(index, CHECK);
372 objArrayOop obj = oopFactory::new_objArray(klass, size, CHECK);
373 current->set_vm_result(obj);
374 JRT_END
375
376
377 JRT_ENTRY_PROF(void, InterpreterRuntime, multianewarray, InterpreterRuntime::multianewarray(JavaThread* current, jint* first_size_address))
378 // We may want to pass in more arguments - could make this slightly faster
379 LastFrameAccessor last_frame(current);
380 ConstantPool* constants = last_frame.method()->constants();
381 int i = last_frame.get_index_u2(Bytecodes::_multianewarray);
382 Klass* klass = constants->klass_at(i, CHECK);
383 int nof_dims = last_frame.number_of_dimensions();
384 assert(klass->is_klass(), "not a class");
385 assert(nof_dims >= 1, "multianewarray rank must be nonzero");
386
387 // We must create an array of jints to pass to multi_allocate.
388 ResourceMark rm(current);
389 const int small_dims = 10;
390 jint dim_array[small_dims];
391 jint *dims = &dim_array[0];
392 if (nof_dims > small_dims) {
393 dims = (jint*) NEW_RESOURCE_ARRAY(jint, nof_dims);
394 }
395 for (int index = 0; index < nof_dims; index++) {
396 // offset from first_size_address is addressed as local[index]
397 int n = Interpreter::local_offset_in_bytes(index)/jintSize;
398 dims[index] = first_size_address[n];
399 }
400 oop obj = ArrayKlass::cast(klass)->multi_allocate(nof_dims, dims, CHECK);
401 current->set_vm_result(obj);
402 JRT_END
403
404
405 JRT_ENTRY_PROF(void, InterpreterRuntime, register_finalizer, InterpreterRuntime::register_finalizer(JavaThread* current, oopDesc* obj))
406 assert(oopDesc::is_oop(obj), "must be a valid oop");
407 assert(obj->klass()->has_finalizer(), "shouldn't be here otherwise");
408 InstanceKlass::register_finalizer(instanceOop(obj), CHECK);
409 JRT_END
410
411
412 // Quicken instance-of and check-cast bytecodes
413 JRT_ENTRY_PROF(void, InterpreterRuntime, quicken_io_cc, InterpreterRuntime::quicken_io_cc(JavaThread* current))
414 // Force resolving; quicken the bytecode
415 LastFrameAccessor last_frame(current);
416 int which = last_frame.get_index_u2(Bytecodes::_checkcast);
417 ConstantPool* cpool = last_frame.method()->constants();
418 // We'd expect to assert that we're only here to quicken bytecodes, but in a multithreaded
419 // program we might have seen an unquick'd bytecode in the interpreter but have another
420 // thread quicken the bytecode before we get here.
421 // assert( cpool->tag_at(which).is_unresolved_klass(), "should only come here to quicken bytecodes" );
422 Klass* klass = cpool->klass_at(which, CHECK);
423 current->set_vm_result_2(klass);
424 JRT_END
425
426
427 //------------------------------------------------------------------------------------------------------------------------
428 // Exceptions
429
430 void InterpreterRuntime::note_trap_inner(JavaThread* current, int reason,
431 const methodHandle& trap_method, int trap_bci) {
432 if (trap_method.not_null()) {
433 MethodData* trap_mdo = trap_method->method_data();
465 static Handle get_preinitialized_exception(Klass* k, TRAPS) {
466 // get klass
467 InstanceKlass* klass = InstanceKlass::cast(k);
468 assert(klass->is_initialized(),
469 "this klass should have been initialized during VM initialization");
470 // create instance - do not call constructor since we may have no
471 // (java) stack space left (should assert constructor is empty)
472 Handle exception;
473 oop exception_oop = klass->allocate_instance(CHECK_(exception));
474 exception = Handle(THREAD, exception_oop);
475 if (StackTraceInThrowable) {
476 java_lang_Throwable::fill_in_stack_trace(exception);
477 }
478 return exception;
479 }
480
481 // Special handling for stack overflow: since we don't have any (java) stack
482 // space left we use the pre-allocated & pre-initialized StackOverflowError
483 // klass to create an stack overflow error instance. We do not call its
484 // constructor for the same reason (it is empty, anyway).
485 JRT_ENTRY_PROF(void, InterpreterRuntime, throw_StackOverflowError,
486 InterpreterRuntime::throw_StackOverflowError(JavaThread* current))
487 Handle exception = get_preinitialized_exception(
488 vmClasses::StackOverflowError_klass(),
489 CHECK);
490 // Increment counter for hs_err file reporting
491 Atomic::inc(&Exceptions::_stack_overflow_errors);
492 // Remove the ScopedValue bindings in case we got a StackOverflowError
493 // while we were trying to manipulate ScopedValue bindings.
494 current->clear_scopedValueBindings();
495 THROW_HANDLE(exception);
496 JRT_END
497
498 JRT_ENTRY_PROF(void, InterpreterRuntime, throw_delayed_StackOverflowError,
499 InterpreterRuntime::throw_delayed_StackOverflowError(JavaThread* current))
500 Handle exception = get_preinitialized_exception(
501 vmClasses::StackOverflowError_klass(),
502 CHECK);
503 java_lang_Throwable::set_message(exception(),
504 Universe::delayed_stack_overflow_error_message());
505 // Increment counter for hs_err file reporting
506 Atomic::inc(&Exceptions::_stack_overflow_errors);
507 // Remove the ScopedValue bindings in case we got a StackOverflowError
508 // while we were trying to manipulate ScopedValue bindings.
509 current->clear_scopedValueBindings();
510 THROW_HANDLE(exception);
511 JRT_END
512
513 JRT_ENTRY_PROF(void, InterpreterRuntime, create_exception,
514 InterpreterRuntime::create_exception(JavaThread* current, char* name, char* message))
515 // lookup exception klass
516 TempNewSymbol s = SymbolTable::new_symbol(name);
517 if (ProfileTraps) {
518 if (s == vmSymbols::java_lang_ArithmeticException()) {
519 note_trap(current, Deoptimization::Reason_div0_check);
520 } else if (s == vmSymbols::java_lang_NullPointerException()) {
521 note_trap(current, Deoptimization::Reason_null_check);
522 }
523 }
524 // create exception
525 Handle exception = Exceptions::new_exception(current, s, message);
526 current->set_vm_result(exception());
527 JRT_END
528
529
530 JRT_ENTRY_PROF(void, InterpreterRuntime, create_klass_exception,
531 InterpreterRuntime::create_klass_exception(JavaThread* current, char* name, oopDesc* obj))
532 // Produce the error message first because note_trap can safepoint
533 ResourceMark rm(current);
534 const char* klass_name = obj->klass()->external_name();
535 // lookup exception klass
536 TempNewSymbol s = SymbolTable::new_symbol(name);
537 if (ProfileTraps) {
538 if (s == vmSymbols::java_lang_ArrayStoreException()) {
539 note_trap(current, Deoptimization::Reason_array_check);
540 } else {
541 note_trap(current, Deoptimization::Reason_class_check);
542 }
543 }
544 // create exception, with klass name as detail message
545 Handle exception = Exceptions::new_exception(current, s, klass_name);
546 current->set_vm_result(exception());
547 JRT_END
548
549 JRT_ENTRY_PROF(void, InterpreterRuntime, throw_ArrayIndexOutOfBoundsException,
550 InterpreterRuntime::throw_ArrayIndexOutOfBoundsException(JavaThread* current, arrayOopDesc* a, jint index))
551 // Produce the error message first because note_trap can safepoint
552 ResourceMark rm(current);
553 stringStream ss;
554 ss.print("Index %d out of bounds for length %d", index, a->length());
555
556 if (ProfileTraps) {
557 note_trap(current, Deoptimization::Reason_range_check);
558 }
559
560 THROW_MSG(vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), ss.as_string());
561 JRT_END
562
563 JRT_ENTRY_PROF(void, InterpreterRuntime, throw_ClassCastException,
564 InterpreterRuntime::throw_ClassCastException(
565 JavaThread* current, oopDesc* obj))
566
567 // Produce the error message first because note_trap can safepoint
568 ResourceMark rm(current);
569 char* message = SharedRuntime::generate_class_cast_message(
570 current, obj->klass());
571
572 if (ProfileTraps) {
573 note_trap(current, Deoptimization::Reason_class_check);
574 }
575
576 // create exception
577 THROW_MSG(vmSymbols::java_lang_ClassCastException(), message);
578 JRT_END
579
580 // exception_handler_for_exception(...) returns the continuation address,
581 // the exception oop (via TLS) and sets the bci/bcp for the continuation.
582 // The exception oop is returned to make sure it is preserved over GC (it
583 // is only on the stack if the exception was thrown explicitly via athrow).
584 // During this operation, the expression stack contains the values for the
585 // bci where the exception happened. If the exception was propagated back
586 // from a call, the expression stack contains the values for the bci at the
587 // invoke w/o arguments (i.e., as if one were inside the call).
588 // Note that the implementation of this method assumes it's only called when an exception has actually occured
589 JRT_ENTRY_PROF(address, InterpreterRuntime, exception_handler_for_exception,
590 InterpreterRuntime::exception_handler_for_exception(JavaThread* current, oopDesc* exception))
591 // We get here after we have unwound from a callee throwing an exception
592 // into the interpreter. Any deferred stack processing is notified of
593 // the event via the StackWatermarkSet.
594 StackWatermarkSet::after_unwind(current);
595
596 LastFrameAccessor last_frame(current);
597 Handle h_exception(current, exception);
598 methodHandle h_method (current, last_frame.method());
599 constantPoolHandle h_constants(current, h_method->constants());
600 bool should_repeat;
601 int handler_bci;
602 int current_bci = last_frame.bci();
603
604 if (current->frames_to_pop_failed_realloc() > 0) {
605 // Allocation of scalar replaced object used in this frame
606 // failed. Unconditionally pop the frame.
607 current->dec_frames_to_pop_failed_realloc();
608 current->set_vm_result(h_exception());
609 // If the method is synchronized we already unlocked the monitor
610 // during deoptimization so the interpreter needs to skip it when
709 h_method->set_exception_handler_entered(handler_bci); // profiling
710 #ifndef ZERO
711 set_bcp_and_mdp(handler_pc, current);
712 continuation = Interpreter::dispatch_table(vtos)[*handler_pc];
713 #else
714 continuation = (address)(intptr_t) handler_bci;
715 #endif
716 }
717
718 // notify debugger of an exception catch
719 // (this is good for exceptions caught in native methods as well)
720 if (JvmtiExport::can_post_on_exceptions()) {
721 JvmtiExport::notice_unwind_due_to_exception(current, h_method(), handler_pc, h_exception(), (handler_pc != nullptr));
722 }
723
724 current->set_vm_result(h_exception());
725 return continuation;
726 JRT_END
727
728
729 JRT_ENTRY_PROF(void, InterpreterRuntime, throw_pending_exception, InterpreterRuntime::throw_pending_exception(JavaThread* current))
730 assert(current->has_pending_exception(), "must only be called if there's an exception pending");
731 // nothing to do - eventually we should remove this code entirely (see comments @ call sites)
732 JRT_END
733
734
735 JRT_ENTRY_PROF(void, InterpreterRuntime, throw_AbstractMethodError, InterpreterRuntime::throw_AbstractMethodError(JavaThread* current))
736 THROW(vmSymbols::java_lang_AbstractMethodError());
737 JRT_END
738
739 // This method is called from the "abstract_entry" of the interpreter.
740 // At that point, the arguments have already been removed from the stack
741 // and therefore we don't have the receiver object at our fingertips. (Though,
742 // on some platforms the receiver still resides in a register...). Thus,
743 // we have no choice but print an error message not containing the receiver
744 // type.
745 JRT_ENTRY_PROF(void, InterpreterRuntime, throw_AbstractMethodErrorWithMethod,
746 InterpreterRuntime::throw_AbstractMethodErrorWithMethod(JavaThread* current,
747 Method* missingMethod))
748 ResourceMark rm(current);
749 assert(missingMethod != nullptr, "sanity");
750 methodHandle m(current, missingMethod);
751 LinkResolver::throw_abstract_method_error(m, THREAD);
752 JRT_END
753
754 JRT_ENTRY_PROF(void, InterpreterRuntime, throw_AbstractMethodErrorVerbose,
755 InterpreterRuntime::throw_AbstractMethodErrorVerbose(JavaThread* current,
756 Klass* recvKlass,
757 Method* missingMethod))
758 ResourceMark rm(current);
759 methodHandle mh = methodHandle(current, missingMethod);
760 LinkResolver::throw_abstract_method_error(mh, recvKlass, THREAD);
761 JRT_END
762
763
764 JRT_ENTRY_PROF(void, InterpreterRuntime, throw_IncompatibleClassChangeError,
765 InterpreterRuntime::throw_IncompatibleClassChangeError(JavaThread* current))
766 THROW(vmSymbols::java_lang_IncompatibleClassChangeError());
767 JRT_END
768
769 JRT_ENTRY_PROF(void, InterpreterRuntime, throw_IncompatibleClassChangeErrorVerbose,
770 InterpreterRuntime::throw_IncompatibleClassChangeErrorVerbose(JavaThread* current,
771 Klass* recvKlass,
772 Klass* interfaceKlass))
773 ResourceMark rm(current);
774 char buf[1000];
775 buf[0] = '\0';
776 jio_snprintf(buf, sizeof(buf),
777 "Class %s does not implement the requested interface %s",
778 recvKlass ? recvKlass->external_name() : "nullptr",
779 interfaceKlass ? interfaceKlass->external_name() : "nullptr");
780 THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
781 JRT_END
782
783 JRT_ENTRY_PROF(void, InterpreterRuntime, throw_NullPointerException,
784 InterpreterRuntime::throw_NullPointerException(JavaThread* current))
785 THROW(vmSymbols::java_lang_NullPointerException());
786 JRT_END
787
788 //------------------------------------------------------------------------------------------------------------------------
789 // Fields
790 //
791
792 PROF_ENTRY(void, InterpreterRuntime, resolve_getfield, InterpreterRuntime::resolve_getfield(JavaThread* current))
793 resolve_get_put(current, Bytecodes::_getfield);
794 PROF_END
795
796 PROF_ENTRY(void, InterpreterRuntime, resolve_putfield, InterpreterRuntime::resolve_putfield(JavaThread* current))
797 resolve_get_put(current, Bytecodes::_putfield);
798 PROF_END
799
800 PROF_ENTRY(void, InterpreterRuntime, resolve_getstatic, InterpreterRuntime::resolve_getstatic(JavaThread* current))
801 resolve_get_put(current, Bytecodes::_getstatic);
802 PROF_END
803
804 PROF_ENTRY(void, InterpreterRuntime, resolve_putstatic, InterpreterRuntime::resolve_putstatic(JavaThread* current))
805 resolve_get_put(current, Bytecodes::_putstatic);
806 PROF_END
807
808 void InterpreterRuntime::resolve_get_put(JavaThread* current, Bytecodes::Code bytecode) {
809 LastFrameAccessor last_frame(current);
810 constantPoolHandle pool(current, last_frame.method()->constants());
811 methodHandle m(current, last_frame.method());
812
813 resolve_get_put(bytecode, last_frame.get_index_u2(bytecode), m, pool, true /*initialize_holder*/, current);
814 }
815
816 void InterpreterRuntime::resolve_get_put(Bytecodes::Code bytecode, int field_index,
817 methodHandle& m,
818 constantPoolHandle& pool,
819 bool initialize_holder, TRAPS) {
820 fieldDescriptor info;
821 bool is_put = (bytecode == Bytecodes::_putfield || bytecode == Bytecodes::_nofast_putfield ||
822 bytecode == Bytecodes::_putstatic);
823 bool is_static = (bytecode == Bytecodes::_getstatic || bytecode == Bytecodes::_putstatic);
824
825 {
826 JvmtiHideSingleStepping jhss(THREAD);
827 LinkResolver::resolve_field_access(info, pool, field_index,
828 m, bytecode, initialize_holder, CHECK);
829 } // end JvmtiHideSingleStepping
830
831 // check if link resolution caused cpCache to be updated
832 if (pool->resolved_field_entry_at(field_index)->is_resolved(bytecode)) return;
833
834 // compute auxiliary field attributes
835 TosState state = as_TosState(info.field_type());
836
837 // Resolution of put instructions on final fields is delayed. That is required so that
838 // exceptions are thrown at the correct place (when the instruction is actually invoked).
839 // If we do not resolve an instruction in the current pass, leaving the put_code
840 // set to zero will cause the next put instruction to the same field to reresolve.
841
842 // Resolution of put instructions to final instance fields with invalid updates (i.e.,
843 // to final instance fields with updates originating from a method different than <init>)
844 // is inhibited. A putfield instruction targeting an instance final field must throw
845 // an IllegalAccessError if the instruction is not in an instance
846 // initializer method <init>. If resolution were not inhibited, a putfield
847 // in an initializer method could be resolved in the initializer. Subsequent
848 // putfield instructions to the same field would then use cached information.
849 // As a result, those instructions would not pass through the VM. That is,
850 // checks in resolve_field_access() would not be executed for those instructions
851 // and the required IllegalAccessError would not be thrown.
852 //
853 // Also, we need to delay resolving getstatic and putstatic instructions until the
854 // class is initialized. This is required so that access to the static
855 // field will call the initialization function every time until the class
856 // is completely initialized ala. in 2.17.5 in JVM Specification.
857 InstanceKlass* klass = info.field_holder();
858 bool uninitialized_static = is_static && !klass->is_initialized();
859 bool has_initialized_final_update = info.field_holder()->major_version() >= 53 &&
860 info.has_initialized_final_update();
861 assert(!(has_initialized_final_update && !info.access_flags().is_final()), "Fields with initialized final updates must be final");
862
863 Bytecodes::Code get_code = (Bytecodes::Code)0;
864 Bytecodes::Code put_code = (Bytecodes::Code)0;
865 if (!uninitialized_static || VM_Version::supports_fast_class_init_checks()) {
866 #if !defined(X86) && !defined(AARCH64)
867 guarantee(!uninitialized_static, "fast class init checks missing in interpreter"); // FIXME
868 #endif // !X86 && !AARCH64
869 get_code = ((is_static) ? Bytecodes::_getstatic : Bytecodes::_getfield);
870 if ((is_put && !has_initialized_final_update) || !info.access_flags().is_final()) {
871 put_code = ((is_static) ? Bytecodes::_putstatic : Bytecodes::_putfield);
872 }
873 }
874
875 ResolvedFieldEntry* entry = pool->resolved_field_entry_at(field_index);
876 entry->set_flags(info.access_flags().is_final(), info.access_flags().is_volatile());
877 entry->fill_in(info.field_holder(), info.offset(),
878 checked_cast<u2>(info.index()), checked_cast<u1>(state),
879 static_cast<u1>(get_code), static_cast<u1>(put_code));
880 }
881
882
883 //------------------------------------------------------------------------------------------------------------------------
884 // Synchronization
885 //
886 // The interpreter's synchronization code is factored out so that it can
887 // be shared by method invocation and synchronized blocks.
888 //%note synchronization_3
889
890 //%note monitor_1
891 JRT_ENTRY_NO_ASYNC_PROF(void, InterpreterRuntime, monitorenter, InterpreterRuntime::monitorenter(JavaThread* current, BasicObjectLock* elem))
892 assert(LockingMode != LM_LIGHTWEIGHT, "Should call monitorenter_obj() when using the new lightweight locking");
893 #ifdef ASSERT
894 current->last_frame().interpreter_frame_verify_monitor(elem);
895 #endif
896 Handle h_obj(current, elem->obj());
897 assert(Universe::heap()->is_in_or_null(h_obj()),
898 "must be null or an object");
899 ObjectSynchronizer::enter(h_obj, elem->lock(), current);
900 assert(Universe::heap()->is_in_or_null(elem->obj()),
901 "must be null or an object");
902 #ifdef ASSERT
903 current->last_frame().interpreter_frame_verify_monitor(elem);
904 #endif
905 JRT_END
906
907 // NOTE: We provide a separate implementation for the new lightweight locking to workaround a limitation
908 // of registers in x86_32. This entry point accepts an oop instead of a BasicObjectLock*.
909 // The problem is that we would need to preserve the register that holds the BasicObjectLock,
910 // but we are using that register to hold the thread. We don't have enough registers to
911 // also keep the BasicObjectLock, but we don't really need it anyway, we only need
912 // the object. See also InterpreterMacroAssembler::lock_object().
913 // As soon as legacy stack-locking goes away we could remove the other monitorenter() entry
914 // point, and only use oop-accepting entries (same for monitorexit() below).
915 JRT_ENTRY_NO_ASYNC_PROF(void, InterpreterRuntime, monitorenter_obj, InterpreterRuntime::monitorenter_obj(JavaThread* current, oopDesc* obj))
916 assert(LockingMode == LM_LIGHTWEIGHT, "Should call monitorenter() when not using the new lightweight locking");
917 Handle h_obj(current, cast_to_oop(obj));
918 assert(Universe::heap()->is_in_or_null(h_obj()),
919 "must be null or an object");
920 ObjectSynchronizer::enter(h_obj, nullptr, current);
921 return;
922 JRT_END
923
924 JRT_LEAF_PROF_NO_THREAD(void, InterpreterRuntime, monitorexit, InterpreterRuntime::monitorexit(BasicObjectLock* elem))
925 oop obj = elem->obj();
926 assert(Universe::heap()->is_in(obj), "must be an object");
927 // The object could become unlocked through a JNI call, which we have no other checks for.
928 // Give a fatal message if CheckJNICalls. Otherwise we ignore it.
929 if (obj->is_unlocked()) {
930 if (CheckJNICalls) {
931 fatal("Object has been unlocked by JNI");
932 }
933 return;
934 }
935 ObjectSynchronizer::exit(obj, elem->lock(), JavaThread::current());
936 // Free entry. If it is not cleared, the exception handling code will try to unlock the monitor
937 // again at method exit or in the case of an exception.
938 elem->set_obj(nullptr);
939 JRT_END
940
941
942 JRT_ENTRY_PROF(void, InterpreterRuntime, throw_illegal_monitor_state_exception,
943 InterpreterRuntime::throw_illegal_monitor_state_exception(JavaThread* current))
944 THROW(vmSymbols::java_lang_IllegalMonitorStateException());
945 JRT_END
946
947
948 JRT_ENTRY_PROF(void, InterpreterRuntime, new_illegal_monitor_state_exception,
949 InterpreterRuntime::new_illegal_monitor_state_exception(JavaThread* current))
950 // Returns an illegal exception to install into the current thread. The
951 // pending_exception flag is cleared so normal exception handling does not
952 // trigger. Any current installed exception will be overwritten. This
953 // method will be called during an exception unwind.
954
955 assert(!HAS_PENDING_EXCEPTION, "no pending exception");
956 Handle exception(current, current->vm_result());
957 assert(exception() != nullptr, "vm result should be set");
958 current->set_vm_result(nullptr); // clear vm result before continuing (may cause memory leaks and assert failures)
959 exception = get_preinitialized_exception(vmClasses::IllegalMonitorStateException_klass(), CATCH);
960 current->set_vm_result(exception());
961 JRT_END
962
963
964 //------------------------------------------------------------------------------------------------------------------------
965 // Invokes
966
967 JRT_ENTRY_PROF(Bytecodes::Code, InterpreterRuntime, get_original_bytecode_at, InterpreterRuntime::get_original_bytecode_at(JavaThread* current, Method* method, address bcp))
968 return method->orig_bytecode_at(method->bci_from(bcp));
969 JRT_END
970
971 JRT_ENTRY_PROF(void, InterpreterRuntime, set_original_bytecode_at, InterpreterRuntime::set_original_bytecode_at(JavaThread* current, Method* method, address bcp, Bytecodes::Code new_code))
972 method->set_orig_bytecode_at(method->bci_from(bcp), new_code);
973 JRT_END
974
975 JRT_ENTRY_PROF(void, InterpreterRuntime, breakpoint, InterpreterRuntime::_breakpoint(JavaThread* current, Method* method, address bcp))
976 JvmtiExport::post_raw_breakpoint(current, method, bcp);
977 JRT_END
978
979 PROF_ENTRY(void, InterpreterRuntime, resolve_invokevirtual, InterpreterRuntime::resolve_invokevirtual(JavaThread* current))
980 resolve_invoke(current, Bytecodes::_invokevirtual);
981 PROF_END
982
983 PROF_ENTRY(void, InterpreterRuntime, resolve_invokespecial, InterpreterRuntime::resolve_invokespecial(JavaThread* current))
984 resolve_invoke(current, Bytecodes::_invokespecial);
985 PROF_END
986
987 PROF_ENTRY(void, InterpreterRuntime, resolve_invokestatic, InterpreterRuntime::resolve_invokestatic(JavaThread* current))
988 resolve_invoke(current, Bytecodes::_invokestatic);
989 PROF_END
990
991 PROF_ENTRY(void, InterpreterRuntime, resolve_invokeinterface, InterpreterRuntime::resolve_invokeinterface(JavaThread* current))
992 resolve_invoke(current, Bytecodes::_invokeinterface);
993 PROF_END
994
995 void InterpreterRuntime::resolve_invoke(JavaThread* current, Bytecodes::Code bytecode) {
996 LastFrameAccessor last_frame(current);
997 // extract receiver from the outgoing argument list if necessary
998 Handle receiver(current, nullptr);
999 if (bytecode == Bytecodes::_invokevirtual || bytecode == Bytecodes::_invokeinterface ||
1000 bytecode == Bytecodes::_invokespecial) {
1001 ResourceMark rm(current);
1002 methodHandle m (current, last_frame.method());
1003 Bytecode_invoke call(m, last_frame.bci());
1004 Symbol* signature = call.signature();
1005 receiver = Handle(current, last_frame.callee_receiver(signature));
1006
1007 assert(Universe::heap()->is_in_or_null(receiver()),
1008 "sanity check");
1009 assert(receiver.is_null() ||
1010 !Universe::heap()->is_in(receiver->klass()),
1011 "sanity check");
1012 }
1013
1014 // resolve method
1015 CallInfo info;
1016 constantPoolHandle pool(current, last_frame.method()->constants());
1017
1018 methodHandle resolved_method;
1019
1020 int method_index = last_frame.get_index_u2(bytecode);
1021 {
1022 JvmtiHideSingleStepping jhss(current);
1023 JavaThread* THREAD = current; // For exception macros.
1024 LinkResolver::resolve_invoke(info, receiver, pool,
1025 method_index, bytecode,
1026 THREAD);
1027
1028 if (HAS_PENDING_EXCEPTION) {
1029 if (ProfileTraps && PENDING_EXCEPTION->klass()->name() == vmSymbols::java_lang_NullPointerException()) {
1030 // Preserve the original exception across the call to note_trap()
1031 PreserveExceptionMark pm(current);
1032 // Recording the trap will help the compiler to potentially recognize this exception as "hot"
1033 note_trap(current, Deoptimization::Reason_null_check);
1034 }
1035 return;
1036 }
1037
1038 resolved_method = methodHandle(current, info.resolved_method());
1039 } // end JvmtiHideSingleStepping
1040
1041 update_invoke_cp_cache_entry(info, bytecode, resolved_method, pool, method_index);
1042 }
1043
1044 void InterpreterRuntime::update_invoke_cp_cache_entry(CallInfo& info, Bytecodes::Code bytecode,
1045 methodHandle& resolved_method,
1046 constantPoolHandle& pool,
1047 int method_index) {
1048 // Don't allow safepoints until the method is cached.
1049 NoSafepointVerifier nsv;
1050
1051 // check if link resolution caused cpCache to be updated
1052 ConstantPoolCache* cache = pool->cache();
1053 if (cache->resolved_method_entry_at(method_index)->is_resolved(bytecode)) return;
1054
1055 #ifdef ASSERT
1056 if (bytecode == Bytecodes::_invokeinterface) {
1057 if (resolved_method->method_holder() == vmClasses::Object_klass()) {
1058 // NOTE: THIS IS A FIX FOR A CORNER CASE in the JVM spec
1059 // (see also CallInfo::set_interface for details)
1060 assert(info.call_kind() == CallInfo::vtable_call ||
1061 info.call_kind() == CallInfo::direct_call, "");
1062 assert(resolved_method->is_final() || info.has_vtable_index(),
1063 "should have been set already");
1064 } else if (!resolved_method->has_itable_index()) {
1065 // Resolved something like CharSequence.toString. Use vtable not itable.
1066 assert(info.call_kind() != CallInfo::itable_call, "");
1067 } else {
1068 // Setup itable entry
1069 assert(info.call_kind() == CallInfo::itable_call, "");
1070 int index = resolved_method->itable_index();
1071 assert(info.itable_index() == index, "");
1072 }
1085 switch (info.call_kind()) {
1086 case CallInfo::direct_call:
1087 cache->set_direct_call(bytecode, method_index, resolved_method, sender->is_interface());
1088 break;
1089 case CallInfo::vtable_call:
1090 cache->set_vtable_call(bytecode, method_index, resolved_method, info.vtable_index());
1091 break;
1092 case CallInfo::itable_call:
1093 cache->set_itable_call(
1094 bytecode,
1095 method_index,
1096 info.resolved_klass(),
1097 resolved_method,
1098 info.itable_index());
1099 break;
1100 default: ShouldNotReachHere();
1101 }
1102 }
1103
1104
1105 void InterpreterRuntime::cds_resolve_invoke(Bytecodes::Code bytecode, int method_index,
1106 methodHandle& m, constantPoolHandle& pool, TRAPS) {
1107 LinkInfo link_info(pool, method_index, bytecode, CHECK);
1108
1109 if (!link_info.resolved_klass()->is_instance_klass() || InstanceKlass::cast(link_info.resolved_klass())->is_linked()) {
1110 CallInfo call_info;
1111 switch (bytecode) {
1112 case Bytecodes::_invokevirtual: LinkResolver::cds_resolve_virtual_call (call_info, link_info, CHECK); break;
1113 case Bytecodes::_invokeinterface: LinkResolver::cds_resolve_interface_call(call_info, link_info, CHECK); break;
1114 case Bytecodes::_invokestatic: LinkResolver::cds_resolve_static_call (call_info, link_info, CHECK); break;
1115 case Bytecodes::_invokespecial: LinkResolver::cds_resolve_special_call (call_info, link_info, CHECK); break;
1116
1117 default: fatal("NYI: %s", Bytecodes::name(bytecode));
1118 }
1119 methodHandle resolved_method(THREAD, call_info.resolved_method());
1120 guarantee(resolved_method->method_holder()->is_linked(), "");
1121 update_invoke_cp_cache_entry(call_info, bytecode, resolved_method, pool, method_index);
1122 } else {
1123 // FIXME: why a shared class is not linked yet?
1124 // Can't link it here since there are no guarantees it'll be prelinked on the next run.
1125 ResourceMark rm;
1126 InstanceKlass* resolved_iklass = InstanceKlass::cast(link_info.resolved_klass());
1127 log_info(cds, resolve)("Not resolved: class not linked: %s %s %s",
1128 resolved_iklass->is_shared() ? "is_shared" : "",
1129 resolved_iklass->init_state_name(),
1130 resolved_iklass->external_name());
1131 }
1132 }
1133
1134 // First time execution: Resolve symbols, create a permanent MethodType object.
1135 PROF_ENTRY(void, InterpreterRuntime, resolve_invokehandle, InterpreterRuntime::resolve_invokehandle(JavaThread* current))
1136 const Bytecodes::Code bytecode = Bytecodes::_invokehandle;
1137 LastFrameAccessor last_frame(current);
1138
1139 // resolve method
1140 CallInfo info;
1141 constantPoolHandle pool(current, last_frame.method()->constants());
1142 int method_index = last_frame.get_index_u2(bytecode);
1143 {
1144 JvmtiHideSingleStepping jhss(current);
1145 JavaThread* THREAD = current; // For exception macros.
1146 LinkResolver::resolve_invoke(info, Handle(), pool,
1147 method_index, bytecode,
1148 CHECK);
1149 } // end JvmtiHideSingleStepping
1150
1151 pool->cache()->set_method_handle(method_index, info);
1152 PROF_END
1153
1154 void InterpreterRuntime::cds_resolve_invokehandle(int raw_index,
1155 constantPoolHandle& pool, TRAPS) {
1156 const Bytecodes::Code bytecode = Bytecodes::_invokehandle;
1157 CallInfo info;
1158 LinkResolver::resolve_invoke(info, Handle(), pool,
1159 raw_index, bytecode, CHECK);
1160
1161 pool->cache()->set_method_handle(raw_index, info);
1162 }
1163
1164 // First time execution: Resolve symbols, create a permanent CallSite object.
1165 PROF_ENTRY(void, InterpreterRuntime, resolve_invokedynamic, InterpreterRuntime::resolve_invokedynamic(JavaThread* current))
1166 LastFrameAccessor last_frame(current);
1167 const Bytecodes::Code bytecode = Bytecodes::_invokedynamic;
1168
1169 // resolve method
1170 CallInfo info;
1171 constantPoolHandle pool(current, last_frame.method()->constants());
1172 int index = last_frame.get_index_u4(bytecode);
1173 {
1174 JvmtiHideSingleStepping jhss(current);
1175 JavaThread* THREAD = current; // For exception macros.
1176 LinkResolver::resolve_invoke(info, Handle(), pool,
1177 index, bytecode, CHECK);
1178 } // end JvmtiHideSingleStepping
1179
1180 pool->cache()->set_dynamic_call(info, index);
1181 PROF_END
1182
1183 void InterpreterRuntime::cds_resolve_invokedynamic(int raw_index,
1184 constantPoolHandle& pool, TRAPS) {
1185 const Bytecodes::Code bytecode = Bytecodes::_invokedynamic;
1186 CallInfo info;
1187 LinkResolver::resolve_invoke(info, Handle(), pool,
1188 raw_index, bytecode, CHECK);
1189 pool->cache()->set_dynamic_call(info, raw_index);
1190 }
1191
1192 // This function is the interface to the assembly code. It returns the resolved
1193 // cpCache entry. This doesn't safepoint, but the helper routines safepoint.
1194 // This function will check for redefinition!
1195 JRT_ENTRY(void, InterpreterRuntime::resolve_from_cache(JavaThread* current, Bytecodes::Code bytecode)) {
1196 trace_current_location(current);
1197
1198 switch (bytecode) {
1199 case Bytecodes::_getstatic: resolve_getstatic(current); break;
1200 case Bytecodes::_putstatic: resolve_putstatic(current); break;
1201 case Bytecodes::_getfield: resolve_getfield(current); break;
1202 case Bytecodes::_putfield: resolve_putfield(current); break;
1203
1204 case Bytecodes::_invokevirtual: resolve_invokevirtual(current); break;
1205 case Bytecodes::_invokespecial: resolve_invokespecial(current); break;
1206 case Bytecodes::_invokestatic: resolve_invokestatic(current); break;
1207 case Bytecodes::_invokeinterface: resolve_invokeinterface(current); break;
1208 case Bytecodes::_invokehandle: resolve_invokehandle(current); break;
1209 case Bytecodes::_invokedynamic: resolve_invokedynamic(current); break;
1210
1211 default:
1212 fatal("unexpected bytecode: %s", Bytecodes::name(bytecode));
1213 break;
1214 }
1215 }
1216 JRT_END
1217
1218 //------------------------------------------------------------------------------------------------------------------------
1219 // Miscellaneous
1220
1221
1222 nmethod* InterpreterRuntime::frequency_counter_overflow(JavaThread* current, address branch_bcp) {
1223 // Enable WXWrite: the function is called directly by interpreter.
1224 MACOS_AARCH64_ONLY(ThreadWXEnable wx(WXWrite, current));
1225
1226 // frequency_counter_overflow_inner can throw async exception.
1227 nmethod* nm = frequency_counter_overflow_inner(current, branch_bcp);
1228 assert(branch_bcp != nullptr || nm == nullptr, "always returns null for non OSR requests");
1229 if (branch_bcp != nullptr && nm != nullptr) {
1230 // This was a successful request for an OSR nmethod. Because
1246 }
1247 if (nm != nullptr && current->is_interp_only_mode()) {
1248 // Normally we never get an nm if is_interp_only_mode() is true, because
1249 // policy()->event has a check for this and won't compile the method when
1250 // true. However, it's possible for is_interp_only_mode() to become true
1251 // during the compilation. We don't want to return the nm in that case
1252 // because we want to continue to execute interpreted.
1253 nm = nullptr;
1254 }
1255 #ifndef PRODUCT
1256 if (TraceOnStackReplacement) {
1257 if (nm != nullptr) {
1258 tty->print("OSR entry @ pc: " INTPTR_FORMAT ": ", p2i(nm->osr_entry()));
1259 nm->print();
1260 }
1261 }
1262 #endif
1263 return nm;
1264 }
1265
1266 JRT_ENTRY_PROF(nmethod*, InterpreterRuntime, frequency_counter_overflow,
1267 InterpreterRuntime::frequency_counter_overflow_inner(JavaThread* current, address branch_bcp))
1268 // use UnlockFlagSaver to clear and restore the _do_not_unlock_if_synchronized
1269 // flag, in case this method triggers classloading which will call into Java.
1270 UnlockFlagSaver fs(current);
1271
1272 LastFrameAccessor last_frame(current);
1273 assert(last_frame.is_interpreted_frame(), "must come from interpreter");
1274 methodHandle method(current, last_frame.method());
1275 const int branch_bci = branch_bcp != nullptr ? method->bci_from(branch_bcp) : InvocationEntryBci;
1276 const int bci = branch_bcp != nullptr ? method->bci_from(last_frame.bcp()) : InvocationEntryBci;
1277
1278 nmethod* osr_nm = CompilationPolicy::event(method, method, branch_bci, bci, CompLevel_none, nullptr, CHECK_NULL);
1279
1280 BarrierSetNMethod* bs_nm = BarrierSet::barrier_set()->barrier_set_nmethod();
1281 if (osr_nm != nullptr && bs_nm != nullptr) {
1282 if (!bs_nm->nmethod_osr_entry_barrier(osr_nm)) {
1283 osr_nm = nullptr;
1284 }
1285 }
1286 return osr_nm;
1287 JRT_END
1288
1289 JRT_LEAF_PROF_NO_THREAD(jint, InterpreterRuntime, bcp_to_di, InterpreterRuntime::bcp_to_di(Method* method, address cur_bcp))
1290 assert(ProfileInterpreter, "must be profiling interpreter");
1291 int bci = method->bci_from(cur_bcp);
1292 MethodData* mdo = method->method_data();
1293 if (mdo == nullptr) return 0;
1294 return mdo->bci_to_di(bci);
1295 JRT_END
1296
1297 #ifdef ASSERT
1298 JRT_LEAF(void, InterpreterRuntime::verify_mdp(Method* method, address bcp, address mdp))
1299 assert(ProfileInterpreter, "must be profiling interpreter");
1300
1301 MethodData* mdo = method->method_data();
1302 assert(mdo != nullptr, "must not be null");
1303
1304 int bci = method->bci_from(bcp);
1305
1306 address mdp2 = mdo->bci_to_dp(bci);
1307 if (mdp != mdp2) {
1308 ResourceMark rm;
1309 tty->print_cr("FAILED verify : actual mdp %p expected mdp %p @ bci %d", mdp, mdp2, bci);
1310 int current_di = mdo->dp_to_di(mdp);
1311 int expected_di = mdo->dp_to_di(mdp2);
1312 tty->print_cr(" actual di %d expected di %d", current_di, expected_di);
1313 int expected_approx_bci = mdo->data_at(expected_di)->bci();
1314 int approx_bci = -1;
1315 if (current_di >= 0) {
1316 approx_bci = mdo->data_at(current_di)->bci();
1317 }
1318 tty->print_cr(" actual bci is %d expected bci %d", approx_bci, expected_approx_bci);
1319 mdo->print_on(tty);
1320 method->print_codes();
1321 }
1322 assert(mdp == mdp2, "wrong mdp");
1323 JRT_END
1324 #endif // ASSERT
1325
1326 JRT_ENTRY_PROF(void, InterpreterRuntime, update_mdp_for_ret, InterpreterRuntime::update_mdp_for_ret(JavaThread* current, int return_bci))
1327 assert(ProfileInterpreter, "must be profiling interpreter");
1328 ResourceMark rm(current);
1329 LastFrameAccessor last_frame(current);
1330 assert(last_frame.is_interpreted_frame(), "must come from interpreter");
1331 MethodData* h_mdo = last_frame.method()->method_data();
1332
1333 // Grab a lock to ensure atomic access to setting the return bci and
1334 // the displacement. This can block and GC, invalidating all naked oops.
1335 MutexLocker ml(RetData_lock);
1336
1337 // ProfileData is essentially a wrapper around a derived oop, so we
1338 // need to take the lock before making any ProfileData structures.
1339 ProfileData* data = h_mdo->data_at(h_mdo->dp_to_di(last_frame.mdp()));
1340 guarantee(data != nullptr, "profile data must be valid");
1341 RetData* rdata = data->as_RetData();
1342 address new_mdp = rdata->fixup_ret(return_bci, h_mdo);
1343 last_frame.set_mdp(new_mdp);
1344 JRT_END
1345
1346 JRT_ENTRY_PROF(MethodCounters*, InterpreterRuntime, build_method_counters, InterpreterRuntime::build_method_counters(JavaThread* current, Method* m))
1347 return Method::build_method_counters(current, m);
1348 JRT_END
1349
1350
1351 JRT_ENTRY_PROF(void, InterpreterRuntime, at_safepoint, InterpreterRuntime::at_safepoint(JavaThread* current))
1352 // We used to need an explicit preserve_arguments here for invoke bytecodes. However,
1353 // stack traversal automatically takes care of preserving arguments for invoke, so
1354 // this is no longer needed.
1355
1356 // JRT_END does an implicit safepoint check, hence we are guaranteed to block
1357 // if this is called during a safepoint
1358
1359 if (JvmtiExport::should_post_single_step()) {
1360 // This function is called by the interpreter when single stepping. Such single
1361 // stepping could unwind a frame. Then, it is important that we process any frames
1362 // that we might return into.
1363 StackWatermarkSet::before_unwind(current);
1364
1365 // We are called during regular safepoints and when the VM is
1366 // single stepping. If any thread is marked for single stepping,
1367 // then we may have JVMTI work to do.
1368 LastFrameAccessor last_frame(current);
1369 JvmtiExport::at_single_stepping_point(current, last_frame.method(), last_frame.bcp());
1370 }
1371 JRT_END
1372
1373 JRT_LEAF_PROF(void, InterpreterRuntime, at_unwind, InterpreterRuntime::at_unwind(JavaThread* current))
1374 assert(current == JavaThread::current(), "pre-condition");
1375 // This function is called by the interpreter when the return poll found a reason
1376 // to call the VM. The reason could be that we are returning into a not yet safe
1377 // to access frame. We handle that below.
1378 // Note that this path does not check for single stepping, because we do not want
1379 // to single step when unwinding frames for an exception being thrown. Instead,
1380 // such single stepping code will use the safepoint table, which will use the
1381 // InterpreterRuntime::at_safepoint callback.
1382 StackWatermarkSet::before_unwind(current);
1383 JRT_END
1384
1385 JRT_ENTRY_PROF(void, InterpreterRuntime, post_field_access, InterpreterRuntime::post_field_access(JavaThread* current, oopDesc* obj,
1386 ResolvedFieldEntry *entry))
1387
1388 // check the access_flags for the field in the klass
1389
1390 InstanceKlass* ik = entry->field_holder();
1391 int index = entry->field_index();
1392 if (!ik->field_status(index).is_access_watched()) return;
1393
1394 bool is_static = (obj == nullptr);
1395 HandleMark hm(current);
1396
1397 Handle h_obj;
1398 if (!is_static) {
1399 // non-static field accessors have an object, but we need a handle
1400 h_obj = Handle(current, obj);
1401 }
1402 InstanceKlass* field_holder = entry->field_holder(); // HERE
1403 jfieldID fid = jfieldIDWorkaround::to_jfieldID(field_holder, entry->field_offset(), is_static);
1404 LastFrameAccessor last_frame(current);
1405 JvmtiExport::post_field_access(current, last_frame.method(), last_frame.bcp(), field_holder, h_obj, fid);
1406 JRT_END
1407
1408 JRT_ENTRY_PROF(void, InterpreterRuntime, post_field_modification, InterpreterRuntime::post_field_modification(JavaThread* current, oopDesc* obj,
1409 ResolvedFieldEntry *entry, jvalue *value))
1410
1411 InstanceKlass* ik = entry->field_holder();
1412
1413 // check the access_flags for the field in the klass
1414 int index = entry->field_index();
1415 // bail out if field modifications are not watched
1416 if (!ik->field_status(index).is_modification_watched()) return;
1417
1418 char sig_type = '\0';
1419
1420 switch((TosState)entry->tos_state()) {
1421 case btos: sig_type = JVM_SIGNATURE_BYTE; break;
1422 case ztos: sig_type = JVM_SIGNATURE_BOOLEAN; break;
1423 case ctos: sig_type = JVM_SIGNATURE_CHAR; break;
1424 case stos: sig_type = JVM_SIGNATURE_SHORT; break;
1425 case itos: sig_type = JVM_SIGNATURE_INT; break;
1426 case ftos: sig_type = JVM_SIGNATURE_FLOAT; break;
1427 case atos: sig_type = JVM_SIGNATURE_CLASS; break;
1428 case ltos: sig_type = JVM_SIGNATURE_LONG; break;
1429 case dtos: sig_type = JVM_SIGNATURE_DOUBLE; break;
1444 // We assume that the two halves of longs/doubles are stored in interpreter
1445 // stack slots in platform-endian order.
1446 jlong_accessor u;
1447 jint* newval = (jint*)value;
1448 u.words[0] = newval[0];
1449 u.words[1] = newval[Interpreter::stackElementWords]; // skip if tag
1450 fvalue.j = u.long_value;
1451 #endif // _LP64
1452
1453 Handle h_obj;
1454 if (!is_static) {
1455 // non-static field accessors have an object, but we need a handle
1456 h_obj = Handle(current, obj);
1457 }
1458
1459 LastFrameAccessor last_frame(current);
1460 JvmtiExport::post_raw_field_modification(current, last_frame.method(), last_frame.bcp(), ik, h_obj,
1461 fid, sig_type, &fvalue);
1462 JRT_END
1463
1464 JRT_ENTRY_PROF(void, InterpreterRuntime, post_method_entry, InterpreterRuntime::post_method_entry(JavaThread* current))
1465 LastFrameAccessor last_frame(current);
1466 JvmtiExport::post_method_entry(current, last_frame.method(), last_frame.get_frame());
1467 JRT_END
1468
1469
1470 // This is a JRT_BLOCK_ENTRY because we have to stash away the return oop
1471 // before transitioning to VM, and restore it after transitioning back
1472 // to Java. The return oop at the top-of-stack, is not walked by the GC.
1473 JRT_BLOCK_ENTRY_PROF(void, InterpreterRuntime, post_method_exit, InterpreterRuntime::post_method_exit(JavaThread* current))
1474 LastFrameAccessor last_frame(current);
1475 JvmtiExport::post_method_exit(current, last_frame.method(), last_frame.get_frame());
1476 JRT_END
1477
1478 JRT_LEAF_PROF_NO_THREAD(int, InterpreterRuntime, interpreter_contains, InterpreterRuntime::interpreter_contains(address pc))
1479 {
1480 return (Interpreter::contains(Continuation::get_top_return_pc_post_barrier(JavaThread::current(), pc)) ? 1 : 0);
1481 }
1482 JRT_END
1483
1484
1485 // Implementation of SignatureHandlerLibrary
1486
1487 #ifndef SHARING_FAST_NATIVE_FINGERPRINTS
1488 // Dummy definition (else normalization method is defined in CPU
1489 // dependent code)
1490 uint64_t InterpreterRuntime::normalize_fast_native_fingerprint(uint64_t fingerprint) {
1491 return fingerprint;
1492 }
1493 #endif
1494
1495 address SignatureHandlerLibrary::set_handler_blob() {
1496 BufferBlob* handler_blob = BufferBlob::create("native signature handlers", blob_size);
1497 if (handler_blob == nullptr) {
1498 return nullptr;
1656 } else {
1657 if (PrintSignatureHandlers) {
1658 tty->cr();
1659 tty->print_cr("duplicate argument handler #%d for fingerprint " UINT64_FORMAT "(old: " PTR_FORMAT ", new : " PTR_FORMAT ")",
1660 _handlers->length(),
1661 fingerprint,
1662 p2i(_handlers->at(handler_index)),
1663 p2i(handler));
1664 }
1665 }
1666 }
1667
1668
1669 BufferBlob* SignatureHandlerLibrary::_handler_blob = nullptr;
1670 address SignatureHandlerLibrary::_handler = nullptr;
1671 GrowableArray<uint64_t>* SignatureHandlerLibrary::_fingerprints = nullptr;
1672 GrowableArray<address>* SignatureHandlerLibrary::_handlers = nullptr;
1673 address SignatureHandlerLibrary::_buffer = nullptr;
1674
1675
1676 JRT_ENTRY_PROF(void, InterpreterRuntime, prepare_native_call, InterpreterRuntime::prepare_native_call(JavaThread* current, Method* method))
1677 methodHandle m(current, method);
1678 assert(m->is_native(), "sanity check");
1679 // lookup native function entry point if it doesn't exist
1680 if (!m->has_native_function()) {
1681 NativeLookup::lookup(m, CHECK);
1682 }
1683 // make sure signature handler is installed
1684 SignatureHandlerLibrary::add(m);
1685 // The interpreter entry point checks the signature handler first,
1686 // before trying to fetch the native entry point and klass mirror.
1687 // We must set the signature handler last, so that multiple processors
1688 // preparing the same method will be sure to see non-null entry & mirror.
1689 JRT_END
1690
1691 #if defined(IA32) || defined(AMD64) || defined(ARM)
1692 JRT_LEAF(void, InterpreterRuntime::popframe_move_outgoing_args(JavaThread* current, void* src_address, void* dest_address))
1693 assert(current == JavaThread::current(), "pre-condition");
1694 if (src_address == dest_address) {
1695 return;
1696 }
1697 ResourceMark rm;
1698 LastFrameAccessor last_frame(current);
1699 assert(last_frame.is_interpreted_frame(), "");
1700 jint bci = last_frame.bci();
1701 methodHandle mh(current, last_frame.method());
1702 Bytecode_invoke invoke(mh, bci);
1703 ArgumentSizeComputer asc(invoke.signature());
1704 int size_of_arguments = (asc.size() + (invoke.has_receiver() ? 1 : 0)); // receiver
1705 Copy::conjoint_jbytes(src_address, dest_address,
1706 size_of_arguments * Interpreter::stackElementSize);
1707 JRT_END
1708 #endif
1709
1710 #if INCLUDE_JVMTI
1711 // This is a support of the JVMTI PopFrame interface.
1712 // Make sure it is an invokestatic of a polymorphic intrinsic that has a member_name argument
1713 // and return it as a vm_result so that it can be reloaded in the list of invokestatic parameters.
1714 // The member_name argument is a saved reference (in local#0) to the member_name.
1715 // For backward compatibility with some JDK versions (7, 8) it can also be a direct method handle.
1716 // FIXME: remove DMH case after j.l.i.InvokerBytecodeGenerator code shape is updated.
1717 JRT_ENTRY_PROF(void, InterpreterRuntime, member_name_arg_or_null,
1718 InterpreterRuntime::member_name_arg_or_null(JavaThread* current, address member_name,
1719 Method* method, address bcp))
1720 Bytecodes::Code code = Bytecodes::code_at(method, bcp);
1721 if (code != Bytecodes::_invokestatic) {
1722 return;
1723 }
1724 ConstantPool* cpool = method->constants();
1725 int cp_index = Bytes::get_native_u2(bcp + 1);
1726 Symbol* cname = cpool->klass_name_at(cpool->klass_ref_index_at(cp_index, code));
1727 Symbol* mname = cpool->name_ref_at(cp_index, code);
1728
1729 if (MethodHandles::has_member_arg(cname, mname)) {
1730 oop member_name_oop = cast_to_oop(member_name);
1731 if (java_lang_invoke_DirectMethodHandle::is_instance(member_name_oop)) {
1732 // FIXME: remove after j.l.i.InvokerBytecodeGenerator code shape is updated.
1733 member_name_oop = java_lang_invoke_DirectMethodHandle::member(member_name_oop);
1734 }
1735 current->set_vm_result(member_name_oop);
1736 } else {
1737 current->set_vm_result(nullptr);
1738 }
1739 JRT_END
1740 #endif // INCLUDE_JVMTI
1741
1742 #ifndef PRODUCT
1743 // This must be a JRT_LEAF function because the interpreter must save registers on x86 to
1744 // call this, which changes rsp and makes the interpreter's expression stack not walkable.
1745 // The generated code still uses call_VM because that will set up the frame pointer for
1746 // bcp and method.
1747 JRT_LEAF(intptr_t, InterpreterRuntime::trace_bytecode(JavaThread* current, intptr_t preserve_this_value, intptr_t tos, intptr_t tos2))
1748 assert(current == JavaThread::current(), "pre-condition");
1749 LastFrameAccessor last_frame(current);
1750 assert(last_frame.is_interpreted_frame(), "must be an interpreted frame");
1751 methodHandle mh(current, last_frame.method());
1752 BytecodeTracer::trace_interpreter(mh, last_frame.bcp(), tos, tos2);
1753 return preserve_this_value;
1754 JRT_END
1755 #endif // !PRODUCT
1756
1757 #define DO_COUNTERS(macro) \
1758 macro(InterpreterRuntime, ldc) \
1759 macro(InterpreterRuntime, resolve_ldc) \
1760 macro(InterpreterRuntime, new) \
1761 macro(InterpreterRuntime, newarray) \
1762 macro(InterpreterRuntime, anewarray) \
1763 macro(InterpreterRuntime, multianewarray) \
1764 macro(InterpreterRuntime, register_finalizer) \
1765 macro(InterpreterRuntime, quicken_io_cc) \
1766 macro(InterpreterRuntime, throw_StackOverflowError) \
1767 macro(InterpreterRuntime, throw_delayed_StackOverflowError) \
1768 macro(InterpreterRuntime, create_exception) \
1769 macro(InterpreterRuntime, create_klass_exception) \
1770 macro(InterpreterRuntime, throw_ArrayIndexOutOfBoundsException) \
1771 macro(InterpreterRuntime, throw_ClassCastException) \
1772 macro(InterpreterRuntime, exception_handler_for_exception) \
1773 macro(InterpreterRuntime, throw_pending_exception) \
1774 macro(InterpreterRuntime, throw_AbstractMethodError) \
1775 macro(InterpreterRuntime, throw_AbstractMethodErrorWithMethod) \
1776 macro(InterpreterRuntime, throw_AbstractMethodErrorVerbose) \
1777 macro(InterpreterRuntime, throw_IncompatibleClassChangeError) \
1778 macro(InterpreterRuntime, throw_IncompatibleClassChangeErrorVerbose) \
1779 macro(InterpreterRuntime, throw_NullPointerException) \
1780 macro(InterpreterRuntime, monitorenter) \
1781 macro(InterpreterRuntime, monitorenter_obj) \
1782 macro(InterpreterRuntime, monitorexit) \
1783 macro(InterpreterRuntime, throw_illegal_monitor_state_exception) \
1784 macro(InterpreterRuntime, new_illegal_monitor_state_exception) \
1785 macro(InterpreterRuntime, get_original_bytecode_at) \
1786 macro(InterpreterRuntime, set_original_bytecode_at) \
1787 macro(InterpreterRuntime, breakpoint) \
1788 macro(InterpreterRuntime, resolve_getfield) \
1789 macro(InterpreterRuntime, resolve_putfield) \
1790 macro(InterpreterRuntime, resolve_getstatic) \
1791 macro(InterpreterRuntime, resolve_putstatic) \
1792 macro(InterpreterRuntime, resolve_invokevirtual) \
1793 macro(InterpreterRuntime, resolve_invokespecial) \
1794 macro(InterpreterRuntime, resolve_invokestatic) \
1795 macro(InterpreterRuntime, resolve_invokeinterface) \
1796 macro(InterpreterRuntime, resolve_invokehandle) \
1797 macro(InterpreterRuntime, resolve_invokedynamic) \
1798 macro(InterpreterRuntime, frequency_counter_overflow) \
1799 macro(InterpreterRuntime, bcp_to_di) \
1800 macro(InterpreterRuntime, update_mdp_for_ret) \
1801 macro(InterpreterRuntime, build_method_counters) \
1802 macro(InterpreterRuntime, at_safepoint) \
1803 macro(InterpreterRuntime, at_unwind) \
1804 macro(InterpreterRuntime, post_field_access) \
1805 macro(InterpreterRuntime, post_field_modification) \
1806 macro(InterpreterRuntime, post_method_entry) \
1807 macro(InterpreterRuntime, post_method_exit) \
1808 macro(InterpreterRuntime, interpreter_contains) \
1809 macro(InterpreterRuntime, prepare_native_call) \
1810 macro(InterpreterRuntime, member_name_arg_or_null)
1811
1812 #define INIT_COUNTER(sub, name) \
1813 NEWPERFTICKCOUNTERS(_perf_##sub##_##name##_timer, SUN_CI, #sub "::" #name); \
1814 NEWPERFEVENTCOUNTER(_perf_##sub##_##name##_count, SUN_CI, #sub "::" #name "_count");
1815
1816 void InterpreterRuntime::init_counters() {
1817 if (UsePerfData) {
1818 EXCEPTION_MARK;
1819
1820 DO_COUNTERS(INIT_COUNTER)
1821
1822 if (HAS_PENDING_EXCEPTION) {
1823 vm_exit_during_initialization("jvm_perf_init failed unexpectedly");
1824 }
1825 }
1826 }
1827 #undef INIT_COUNTER
1828
1829 #define PRINT_COUNTER(sub, name) { \
1830 jlong count = _perf_##sub##_##name##_count->get_value(); \
1831 if (count > 0) { \
1832 st->print_cr(" %-50s = %4ldms (elapsed) %4ldms (thread) (%5ld events)", #sub "::" #name, \
1833 _perf_##sub##_##name##_timer->elapsed_counter_value_ms(), \
1834 _perf_##sub##_##name##_timer->thread_counter_value_ms(), \
1835 count); \
1836 }}
1837
1838 void InterpreterRuntime::print_counters_on(outputStream* st) {
1839 if (UsePerfData && ProfileRuntimeCalls) {
1840 DO_COUNTERS(PRINT_COUNTER)
1841 } else {
1842 st->print_cr(" InterpreterRuntime: no info (%s is disabled)", (UsePerfData ? "ProfileRuntimeCalls" : "UsePerfData"));
1843 }
1844 }
1845
1846 #undef PRINT_COUNTER
1847 #undef DO_COUNTERS
1848
|