< prev index next >

src/hotspot/share/interpreter/interpreterRuntime.cpp

Print this page

  50 #include "oops/methodData.hpp"
  51 #include "oops/objArrayKlass.hpp"
  52 #include "oops/objArrayOop.inline.hpp"
  53 #include "oops/oop.inline.hpp"
  54 #include "oops/symbol.hpp"
  55 #include "prims/jvmtiExport.hpp"
  56 #include "prims/methodHandles.hpp"
  57 #include "prims/nativeLookup.hpp"
  58 #include "runtime/atomic.hpp"
  59 #include "runtime/continuation.hpp"
  60 #include "runtime/deoptimization.hpp"
  61 #include "runtime/fieldDescriptor.inline.hpp"
  62 #include "runtime/frame.inline.hpp"
  63 #include "runtime/handles.inline.hpp"
  64 #include "runtime/icache.hpp"
  65 #include "runtime/interfaceSupport.inline.hpp"
  66 #include "runtime/java.hpp"
  67 #include "runtime/javaCalls.hpp"
  68 #include "runtime/jfieldIDWorkaround.hpp"
  69 #include "runtime/osThread.hpp"

  70 #include "runtime/sharedRuntime.hpp"
  71 #include "runtime/stackWatermarkSet.hpp"
  72 #include "runtime/stubRoutines.hpp"
  73 #include "runtime/synchronizer.inline.hpp"

  74 #include "utilities/align.hpp"
  75 #include "utilities/checkedCast.hpp"
  76 #include "utilities/copy.hpp"
  77 #include "utilities/events.hpp"
  78 #if INCLUDE_JFR
  79 #include "jfr/jfr.inline.hpp"
  80 #endif
  81 
  82 // Helper class to access current interpreter state
  83 class LastFrameAccessor : public StackObj {
  84   frame _last_frame;
  85 public:
  86   LastFrameAccessor(JavaThread* current) {
  87     assert(current == Thread::current(), "sanity");
  88     _last_frame = current->last_frame();
  89   }
  90   bool is_interpreted_frame() const              { return _last_frame.is_interpreted_frame(); }
  91   Method*   method() const                       { return _last_frame.interpreter_frame_method(); }
  92   address   bcp() const                          { return _last_frame.interpreter_frame_bcp(); }
  93   int       bci() const                          { return _last_frame.interpreter_frame_bci(); }

 104   int get_index_u2(Bytecodes::Code bc) const     { return bytecode().get_index_u2(bc); }
 105   int get_index_u4(Bytecodes::Code bc) const     { return bytecode().get_index_u4(bc); }
 106   int number_of_dimensions() const               { return bcp()[3]; }
 107 
 108   oop callee_receiver(Symbol* signature) {
 109     return _last_frame.interpreter_callee_receiver(signature);
 110   }
 111   BasicObjectLock* monitor_begin() const {
 112     return _last_frame.interpreter_frame_monitor_begin();
 113   }
 114   BasicObjectLock* monitor_end() const {
 115     return _last_frame.interpreter_frame_monitor_end();
 116   }
 117   BasicObjectLock* next_monitor(BasicObjectLock* current) const {
 118     return _last_frame.next_monitor_in_interpreter_frame(current);
 119   }
 120 
 121   frame& get_frame()                             { return _last_frame; }
 122 };
 123 





















































































































 124 //------------------------------------------------------------------------------------------------------------------------
 125 // State accessors
 126 
 127 void InterpreterRuntime::set_bcp_and_mdp(address bcp, JavaThread* current) {
 128   LastFrameAccessor last_frame(current);
 129   last_frame.set_bcp(bcp);
 130   if (ProfileInterpreter) {
 131     // ProfileTraps uses MDOs independently of ProfileInterpreter.
 132     // That is why we must check both ProfileInterpreter and mdo != nullptr.
 133     MethodData* mdo = last_frame.method()->method_data();
 134     if (mdo != nullptr) {
 135       NEEDS_CLEANUP;
 136       last_frame.set_mdp(mdo->bci_to_dp(last_frame.bci()));
 137     }
 138   }
 139 }
 140 
 141 //------------------------------------------------------------------------------------------------------------------------
 142 // Constants
 143 
 144 
 145 JRT_ENTRY(void, InterpreterRuntime::ldc(JavaThread* current, bool wide))
 146   // access constant pool
 147   LastFrameAccessor last_frame(current);
 148   ConstantPool* pool = last_frame.method()->constants();
 149   int cp_index = wide ? last_frame.get_index_u2(Bytecodes::_ldc_w) : last_frame.get_index_u1(Bytecodes::_ldc);
 150   constantTag tag = pool->tag_at(cp_index);
 151 
 152   assert (tag.is_unresolved_klass() || tag.is_klass(), "wrong ldc call");
 153   Klass* klass = pool->klass_at(cp_index, CHECK);
 154   oop java_class = klass->java_mirror();
 155   current->set_vm_result_oop(java_class);
 156 JRT_END
 157 
 158 JRT_ENTRY(void, InterpreterRuntime::resolve_ldc(JavaThread* current, Bytecodes::Code bytecode)) {
 159   assert(bytecode == Bytecodes::_ldc ||
 160          bytecode == Bytecodes::_ldc_w ||
 161          bytecode == Bytecodes::_ldc2_w ||
 162          bytecode == Bytecodes::_fast_aldc ||
 163          bytecode == Bytecodes::_fast_aldc_w, "wrong bc");
 164   ResourceMark rm(current);
 165   const bool is_fast_aldc = (bytecode == Bytecodes::_fast_aldc ||
 166                              bytecode == Bytecodes::_fast_aldc_w);
 167   LastFrameAccessor last_frame(current);
 168   methodHandle m (current, last_frame.method());
 169   Bytecode_loadconstant ldc(m, last_frame.bci());
 170 
 171   // Double-check the size.  (Condy can have any type.)
 172   BasicType type = ldc.result_type();
 173   switch (type2size[type]) {
 174   case 2: guarantee(bytecode == Bytecodes::_ldc2_w, ""); break;
 175   case 1: guarantee(bytecode != Bytecodes::_ldc2_w, ""); break;
 176   default: ShouldNotReachHere();
 177   }
 178 

 194       assert(roop == coop, "expected result for assembly code");
 195     }
 196   }
 197 #endif
 198   current->set_vm_result_oop(result);
 199   if (!is_fast_aldc) {
 200     // Tell the interpreter how to unbox the primitive.
 201     guarantee(java_lang_boxing_object::is_instance(result, type), "");
 202     int offset = java_lang_boxing_object::value_offset(type);
 203     intptr_t flags = ((as_TosState(type) << ConstantPoolCache::tos_state_shift)
 204                       | (offset & ConstantPoolCache::field_index_mask));
 205     current->set_vm_result_metadata((Metadata*)flags);
 206   }
 207 }
 208 JRT_END
 209 
 210 
 211 //------------------------------------------------------------------------------------------------------------------------
 212 // Allocation
 213 
 214 JRT_ENTRY(void, InterpreterRuntime::_new(JavaThread* current, ConstantPool* pool, int index))
 215   Klass* k = pool->klass_at(index, CHECK);
 216   InstanceKlass* klass = InstanceKlass::cast(k);
 217 
 218   // Make sure we are not instantiating an abstract klass
 219   klass->check_valid_for_instantiation(true, CHECK);
 220 
 221   // Make sure klass is initialized
 222   klass->initialize(CHECK);
 223 
 224   oop obj = klass->allocate_instance(CHECK);
 225   current->set_vm_result_oop(obj);
 226 JRT_END
 227 
 228 
 229 JRT_ENTRY(void, InterpreterRuntime::newarray(JavaThread* current, BasicType type, jint size))
 230   oop obj = oopFactory::new_typeArray(type, size, CHECK);
 231   current->set_vm_result_oop(obj);
 232 JRT_END
 233 
 234 
 235 JRT_ENTRY(void, InterpreterRuntime::anewarray(JavaThread* current, ConstantPool* pool, int index, jint size))
 236   Klass*    klass = pool->klass_at(index, CHECK);
 237   objArrayOop obj = oopFactory::new_objArray(klass, size, CHECK);
 238   current->set_vm_result_oop(obj);
 239 JRT_END
 240 
 241 
 242 JRT_ENTRY(void, InterpreterRuntime::multianewarray(JavaThread* current, jint* first_size_address))
 243   // We may want to pass in more arguments - could make this slightly faster
 244   LastFrameAccessor last_frame(current);
 245   ConstantPool* constants = last_frame.method()->constants();
 246   int          i = last_frame.get_index_u2(Bytecodes::_multianewarray);
 247   Klass* klass   = constants->klass_at(i, CHECK);
 248   int   nof_dims = last_frame.number_of_dimensions();
 249   assert(klass->is_klass(), "not a class");
 250   assert(nof_dims >= 1, "multianewarray rank must be nonzero");
 251 
 252   // We must create an array of jints to pass to multi_allocate.
 253   ResourceMark rm(current);
 254   const int small_dims = 10;
 255   jint dim_array[small_dims];
 256   jint *dims = &dim_array[0];
 257   if (nof_dims > small_dims) {
 258     dims = (jint*) NEW_RESOURCE_ARRAY(jint, nof_dims);
 259   }
 260   for (int index = 0; index < nof_dims; index++) {
 261     // offset from first_size_address is addressed as local[index]
 262     int n = Interpreter::local_offset_in_bytes(index)/jintSize;
 263     dims[index] = first_size_address[n];
 264   }
 265   oop obj = ArrayKlass::cast(klass)->multi_allocate(nof_dims, dims, CHECK);
 266   current->set_vm_result_oop(obj);
 267 JRT_END
 268 
 269 
 270 JRT_ENTRY(void, InterpreterRuntime::register_finalizer(JavaThread* current, oopDesc* obj))
 271   assert(oopDesc::is_oop(obj), "must be a valid oop");
 272   assert(obj->klass()->has_finalizer(), "shouldn't be here otherwise");
 273   InstanceKlass::register_finalizer(instanceOop(obj), CHECK);
 274 JRT_END
 275 
 276 
 277 // Quicken instance-of and check-cast bytecodes
 278 JRT_ENTRY(void, InterpreterRuntime::quicken_io_cc(JavaThread* current))
 279   // Force resolving; quicken the bytecode
 280   LastFrameAccessor last_frame(current);
 281   int which = last_frame.get_index_u2(Bytecodes::_checkcast);
 282   ConstantPool* cpool = last_frame.method()->constants();
 283   // We'd expect to assert that we're only here to quicken bytecodes, but in a multithreaded
 284   // program we might have seen an unquick'd bytecode in the interpreter but have another
 285   // thread quicken the bytecode before we get here.
 286   // assert( cpool->tag_at(which).is_unresolved_klass(), "should only come here to quicken bytecodes" );
 287   Klass* klass = cpool->klass_at(which, CHECK);
 288   current->set_vm_result_metadata(klass);
 289 JRT_END
 290 
 291 
 292 //------------------------------------------------------------------------------------------------------------------------
 293 // Exceptions
 294 
 295 void InterpreterRuntime::note_trap_inner(JavaThread* current, int reason,
 296                                          const methodHandle& trap_method, int trap_bci) {
 297   if (trap_method.not_null()) {
 298     MethodData* trap_mdo = trap_method->method_data();

 330 static Handle get_preinitialized_exception(Klass* k, TRAPS) {
 331   // get klass
 332   InstanceKlass* klass = InstanceKlass::cast(k);
 333   assert(klass->is_initialized(),
 334          "this klass should have been initialized during VM initialization");
 335   // create instance - do not call constructor since we may have no
 336   // (java) stack space left (should assert constructor is empty)
 337   Handle exception;
 338   oop exception_oop = klass->allocate_instance(CHECK_(exception));
 339   exception = Handle(THREAD, exception_oop);
 340   if (StackTraceInThrowable) {
 341     java_lang_Throwable::fill_in_stack_trace(exception);
 342   }
 343   return exception;
 344 }
 345 
 346 // Special handling for stack overflow: since we don't have any (java) stack
 347 // space left we use the pre-allocated & pre-initialized StackOverflowError
 348 // klass to create an stack overflow error instance.  We do not call its
 349 // constructor for the same reason (it is empty, anyway).
 350 JRT_ENTRY(void, InterpreterRuntime::throw_StackOverflowError(JavaThread* current))

 351   Handle exception = get_preinitialized_exception(
 352                                  vmClasses::StackOverflowError_klass(),
 353                                  CHECK);
 354   // Increment counter for hs_err file reporting
 355   Atomic::inc(&Exceptions::_stack_overflow_errors);
 356   // Remove the ScopedValue bindings in case we got a StackOverflowError
 357   // while we were trying to manipulate ScopedValue bindings.
 358   current->clear_scopedValueBindings();
 359   THROW_HANDLE(exception);
 360 JRT_END
 361 
 362 JRT_ENTRY(void, InterpreterRuntime::throw_delayed_StackOverflowError(JavaThread* current))

 363   Handle exception = get_preinitialized_exception(
 364                                  vmClasses::StackOverflowError_klass(),
 365                                  CHECK);
 366   java_lang_Throwable::set_message(exception(),
 367           Universe::delayed_stack_overflow_error_message());
 368   // Increment counter for hs_err file reporting
 369   Atomic::inc(&Exceptions::_stack_overflow_errors);
 370   // Remove the ScopedValue bindings in case we got a StackOverflowError
 371   // while we were trying to manipulate ScopedValue bindings.
 372   current->clear_scopedValueBindings();
 373   THROW_HANDLE(exception);
 374 JRT_END
 375 
 376 JRT_ENTRY(void, InterpreterRuntime::create_exception(JavaThread* current, char* name, char* message))

 377   // lookup exception klass
 378   TempNewSymbol s = SymbolTable::new_symbol(name);
 379   if (ProfileTraps) {
 380     if (s == vmSymbols::java_lang_ArithmeticException()) {
 381       note_trap(current, Deoptimization::Reason_div0_check);
 382     } else if (s == vmSymbols::java_lang_NullPointerException()) {
 383       note_trap(current, Deoptimization::Reason_null_check);
 384     }
 385   }
 386   // create exception
 387   Handle exception = Exceptions::new_exception(current, s, message);
 388   current->set_vm_result_oop(exception());
 389 JRT_END
 390 
 391 
 392 JRT_ENTRY(void, InterpreterRuntime::create_klass_exception(JavaThread* current, char* name, oopDesc* obj))

 393   // Produce the error message first because note_trap can safepoint
 394   ResourceMark rm(current);
 395   const char* klass_name = obj->klass()->external_name();
 396   // lookup exception klass
 397   TempNewSymbol s = SymbolTable::new_symbol(name);
 398   if (ProfileTraps) {
 399     if (s == vmSymbols::java_lang_ArrayStoreException()) {
 400       note_trap(current, Deoptimization::Reason_array_check);
 401     } else {
 402       note_trap(current, Deoptimization::Reason_class_check);
 403     }
 404   }
 405   // create exception, with klass name as detail message
 406   Handle exception = Exceptions::new_exception(current, s, klass_name);
 407   current->set_vm_result_oop(exception());
 408 JRT_END
 409 
 410 JRT_ENTRY(void, InterpreterRuntime::throw_ArrayIndexOutOfBoundsException(JavaThread* current, arrayOopDesc* a, jint index))

 411   // Produce the error message first because note_trap can safepoint
 412   ResourceMark rm(current);
 413   stringStream ss;
 414   ss.print("Index %d out of bounds for length %d", index, a->length());
 415 
 416   if (ProfileTraps) {
 417     note_trap(current, Deoptimization::Reason_range_check);
 418   }
 419 
 420   THROW_MSG(vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), ss.as_string());
 421 JRT_END
 422 
 423 JRT_ENTRY(void, InterpreterRuntime::throw_ClassCastException(

 424   JavaThread* current, oopDesc* obj))
 425 
 426   // Produce the error message first because note_trap can safepoint
 427   ResourceMark rm(current);
 428   char* message = SharedRuntime::generate_class_cast_message(
 429     current, obj->klass());
 430 
 431   if (ProfileTraps) {
 432     note_trap(current, Deoptimization::Reason_class_check);
 433   }
 434 
 435   // create exception
 436   THROW_MSG(vmSymbols::java_lang_ClassCastException(), message);
 437 JRT_END
 438 
 439 // exception_handler_for_exception(...) returns the continuation address,
 440 // the exception oop (via TLS) and sets the bci/bcp for the continuation.
 441 // The exception oop is returned to make sure it is preserved over GC (it
 442 // is only on the stack if the exception was thrown explicitly via athrow).
 443 // During this operation, the expression stack contains the values for the
 444 // bci where the exception happened. If the exception was propagated back
 445 // from a call, the expression stack contains the values for the bci at the
 446 // invoke w/o arguments (i.e., as if one were inside the call).
 447 // Note that the implementation of this method assumes it's only called when an exception has actually occured
 448 JRT_ENTRY(address, InterpreterRuntime::exception_handler_for_exception(JavaThread* current, oopDesc* exception))

 449   // We get here after we have unwound from a callee throwing an exception
 450   // into the interpreter. Any deferred stack processing is notified of
 451   // the event via the StackWatermarkSet.
 452   StackWatermarkSet::after_unwind(current);
 453 
 454   LastFrameAccessor last_frame(current);
 455   Handle             h_exception(current, exception);
 456   methodHandle       h_method   (current, last_frame.method());
 457   constantPoolHandle h_constants(current, h_method->constants());
 458   bool               should_repeat;
 459   int                handler_bci;
 460   int                current_bci = last_frame.bci();
 461 
 462   if (current->frames_to_pop_failed_realloc() > 0) {
 463     // Allocation of scalar replaced object used in this frame
 464     // failed. Unconditionally pop the frame.
 465     current->dec_frames_to_pop_failed_realloc();
 466     current->set_vm_result_oop(h_exception());
 467     // If the method is synchronized we already unlocked the monitor
 468     // during deoptimization so the interpreter needs to skip it when

 571     h_method->set_exception_handler_entered(handler_bci); // profiling
 572 #ifndef ZERO
 573     set_bcp_and_mdp(handler_pc, current);
 574     continuation = Interpreter::dispatch_table(vtos)[*handler_pc];
 575 #else
 576     continuation = (address)(intptr_t) handler_bci;
 577 #endif
 578   }
 579 
 580   // notify debugger of an exception catch
 581   // (this is good for exceptions caught in native methods as well)
 582   if (JvmtiExport::can_post_on_exceptions()) {
 583     JvmtiExport::notice_unwind_due_to_exception(current, h_method(), handler_pc, h_exception(), (handler_pc != nullptr));
 584   }
 585 
 586   current->set_vm_result_oop(h_exception());
 587   return continuation;
 588 JRT_END
 589 
 590 
 591 JRT_ENTRY(void, InterpreterRuntime::throw_pending_exception(JavaThread* current))
 592   assert(current->has_pending_exception(), "must only be called if there's an exception pending");
 593   // nothing to do - eventually we should remove this code entirely (see comments @ call sites)
 594 JRT_END
 595 
 596 
 597 JRT_ENTRY(void, InterpreterRuntime::throw_AbstractMethodError(JavaThread* current))
 598   THROW(vmSymbols::java_lang_AbstractMethodError());
 599 JRT_END
 600 
 601 // This method is called from the "abstract_entry" of the interpreter.
 602 // At that point, the arguments have already been removed from the stack
 603 // and therefore we don't have the receiver object at our fingertips. (Though,
 604 // on some platforms the receiver still resides in a register...). Thus,
 605 // we have no choice but print an error message not containing the receiver
 606 // type.
 607 JRT_ENTRY(void, InterpreterRuntime::throw_AbstractMethodErrorWithMethod(JavaThread* current,
 608                                                                         Method* missingMethod))

 609   ResourceMark rm(current);
 610   assert(missingMethod != nullptr, "sanity");
 611   methodHandle m(current, missingMethod);
 612   LinkResolver::throw_abstract_method_error(m, THREAD);
 613 JRT_END
 614 
 615 JRT_ENTRY(void, InterpreterRuntime::throw_AbstractMethodErrorVerbose(JavaThread* current,
 616                                                                      Klass* recvKlass,
 617                                                                      Method* missingMethod))

 618   ResourceMark rm(current);
 619   methodHandle mh = methodHandle(current, missingMethod);
 620   LinkResolver::throw_abstract_method_error(mh, recvKlass, THREAD);
 621 JRT_END
 622 
 623 
 624 JRT_ENTRY(void, InterpreterRuntime::throw_IncompatibleClassChangeError(JavaThread* current))

 625   THROW(vmSymbols::java_lang_IncompatibleClassChangeError());
 626 JRT_END
 627 
 628 JRT_ENTRY(void, InterpreterRuntime::throw_IncompatibleClassChangeErrorVerbose(JavaThread* current,
 629                                                                               Klass* recvKlass,
 630                                                                               Klass* interfaceKlass))

 631   ResourceMark rm(current);
 632   char buf[1000];
 633   buf[0] = '\0';
 634   jio_snprintf(buf, sizeof(buf),
 635                "Class %s does not implement the requested interface %s",
 636                recvKlass ? recvKlass->external_name() : "nullptr",
 637                interfaceKlass ? interfaceKlass->external_name() : "nullptr");
 638   THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
 639 JRT_END
 640 
 641 JRT_ENTRY(void, InterpreterRuntime::throw_NullPointerException(JavaThread* current))

 642   THROW(vmSymbols::java_lang_NullPointerException());
 643 JRT_END
 644 
 645 //------------------------------------------------------------------------------------------------------------------------
 646 // Fields
 647 //
 648 
















 649 void InterpreterRuntime::resolve_get_put(JavaThread* current, Bytecodes::Code bytecode) {
 650   LastFrameAccessor last_frame(current);
 651   constantPoolHandle pool(current, last_frame.method()->constants());
 652   methodHandle m(current, last_frame.method());
 653 
 654   resolve_get_put(bytecode, last_frame.get_index_u2(bytecode), m, pool, true /*initialize_holder*/, current);
 655 }
 656 
 657 void InterpreterRuntime::resolve_get_put(Bytecodes::Code bytecode, int field_index,
 658                                          methodHandle& m,
 659                                          constantPoolHandle& pool,
 660                                          bool initialize_holder, TRAPS) {
 661   fieldDescriptor info;
 662   bool is_put    = (bytecode == Bytecodes::_putfield  || bytecode == Bytecodes::_nofast_putfield ||
 663                     bytecode == Bytecodes::_putstatic);
 664   bool is_static = (bytecode == Bytecodes::_getstatic || bytecode == Bytecodes::_putstatic);
 665 
 666   {
 667     JvmtiHideSingleStepping jhss(THREAD);
 668     LinkResolver::resolve_field_access(info, pool, field_index,

 686   // an IllegalAccessError if the instruction is not in an instance
 687   // initializer method <init>. If resolution were not inhibited, a putfield
 688   // in an initializer method could be resolved in the initializer. Subsequent
 689   // putfield instructions to the same field would then use cached information.
 690   // As a result, those instructions would not pass through the VM. That is,
 691   // checks in resolve_field_access() would not be executed for those instructions
 692   // and the required IllegalAccessError would not be thrown.
 693   //
 694   // Also, we need to delay resolving getstatic and putstatic instructions until the
 695   // class is initialized.  This is required so that access to the static
 696   // field will call the initialization function every time until the class
 697   // is completely initialized ala. in 2.17.5 in JVM Specification.
 698   InstanceKlass* klass = info.field_holder();
 699   bool uninitialized_static = is_static && !klass->is_initialized();
 700   bool has_initialized_final_update = info.field_holder()->major_version() >= 53 &&
 701                                       info.has_initialized_final_update();
 702   assert(!(has_initialized_final_update && !info.access_flags().is_final()), "Fields with initialized final updates must be final");
 703 
 704   Bytecodes::Code get_code = (Bytecodes::Code)0;
 705   Bytecodes::Code put_code = (Bytecodes::Code)0;
 706   if (!uninitialized_static) {



 707     get_code = ((is_static) ? Bytecodes::_getstatic : Bytecodes::_getfield);
 708     if ((is_put && !has_initialized_final_update) || !info.access_flags().is_final()) {
 709       put_code = ((is_static) ? Bytecodes::_putstatic : Bytecodes::_putfield);
 710     }
 711   }
 712 
 713   ResolvedFieldEntry* entry = pool->resolved_field_entry_at(field_index);
 714   entry->set_flags(info.access_flags().is_final(), info.access_flags().is_volatile());
 715   entry->fill_in(info.field_holder(), info.offset(),
 716                  checked_cast<u2>(info.index()), checked_cast<u1>(state),
 717                  static_cast<u1>(get_code), static_cast<u1>(put_code));
 718 }
 719 
 720 
 721 //------------------------------------------------------------------------------------------------------------------------
 722 // Synchronization
 723 //
 724 // The interpreter's synchronization code is factored out so that it can
 725 // be shared by method invocation and synchronized blocks.
 726 //%note synchronization_3
 727 
 728 //%note monitor_1
 729 JRT_ENTRY_NO_ASYNC(void, InterpreterRuntime::monitorenter(JavaThread* current, BasicObjectLock* elem))
 730 #ifdef ASSERT
 731   current->last_frame().interpreter_frame_verify_monitor(elem);
 732 #endif
 733   Handle h_obj(current, elem->obj());
 734   assert(Universe::heap()->is_in_or_null(h_obj()),
 735          "must be null or an object");
 736   ObjectSynchronizer::enter(h_obj, elem->lock(), current);
 737   assert(Universe::heap()->is_in_or_null(elem->obj()),
 738          "must be null or an object");
 739 #ifdef ASSERT
 740   if (!current->preempting()) current->last_frame().interpreter_frame_verify_monitor(elem);
 741 #endif
 742 JRT_END
 743 
 744 JRT_LEAF(void, InterpreterRuntime::monitorexit(BasicObjectLock* elem))
 745   oop obj = elem->obj();
 746   assert(Universe::heap()->is_in(obj), "must be an object");
 747   // The object could become unlocked through a JNI call, which we have no other checks for.
 748   // Give a fatal message if CheckJNICalls. Otherwise we ignore it.
 749   if (obj->is_unlocked()) {
 750     if (CheckJNICalls) {
 751       fatal("Object has been unlocked by JNI");
 752     }
 753     return;
 754   }
 755   ObjectSynchronizer::exit(obj, elem->lock(), JavaThread::current());
 756   // Free entry. If it is not cleared, the exception handling code will try to unlock the monitor
 757   // again at method exit or in the case of an exception.
 758   elem->set_obj(nullptr);
 759 JRT_END
 760 
 761 
 762 JRT_ENTRY(void, InterpreterRuntime::throw_illegal_monitor_state_exception(JavaThread* current))

 763   THROW(vmSymbols::java_lang_IllegalMonitorStateException());
 764 JRT_END
 765 
 766 
 767 JRT_ENTRY(void, InterpreterRuntime::new_illegal_monitor_state_exception(JavaThread* current))

 768   // Returns an illegal exception to install into the current thread. The
 769   // pending_exception flag is cleared so normal exception handling does not
 770   // trigger. Any current installed exception will be overwritten. This
 771   // method will be called during an exception unwind.
 772 
 773   assert(!HAS_PENDING_EXCEPTION, "no pending exception");
 774   Handle exception(current, current->vm_result_oop());
 775   assert(exception() != nullptr, "vm result should be set");
 776   current->set_vm_result_oop(nullptr); // clear vm result before continuing (may cause memory leaks and assert failures)
 777   exception = get_preinitialized_exception(vmClasses::IllegalMonitorStateException_klass(), CATCH);
 778   current->set_vm_result_oop(exception());
 779 JRT_END
 780 
 781 
 782 //------------------------------------------------------------------------------------------------------------------------
 783 // Invokes
 784 
 785 JRT_ENTRY(Bytecodes::Code, InterpreterRuntime::get_original_bytecode_at(JavaThread* current, Method* method, address bcp))
 786   return method->orig_bytecode_at(method->bci_from(bcp));
 787 JRT_END
 788 
 789 JRT_ENTRY(void, InterpreterRuntime::set_original_bytecode_at(JavaThread* current, Method* method, address bcp, Bytecodes::Code new_code))
 790   method->set_orig_bytecode_at(method->bci_from(bcp), new_code);
 791 JRT_END
 792 
 793 JRT_ENTRY(void, InterpreterRuntime::_breakpoint(JavaThread* current, Method* method, address bcp))
 794   JvmtiExport::post_raw_breakpoint(current, method, bcp);
 795 JRT_END
 796 
















 797 void InterpreterRuntime::resolve_invoke(JavaThread* current, Bytecodes::Code bytecode) {
 798   LastFrameAccessor last_frame(current);
 799   // extract receiver from the outgoing argument list if necessary
 800   Handle receiver(current, nullptr);
 801   if (bytecode == Bytecodes::_invokevirtual || bytecode == Bytecodes::_invokeinterface ||
 802       bytecode == Bytecodes::_invokespecial) {
 803     ResourceMark rm(current);
 804     methodHandle m (current, last_frame.method());
 805     Bytecode_invoke call(m, last_frame.bci());
 806     Symbol* signature = call.signature();
 807     receiver = Handle(current, last_frame.callee_receiver(signature));
 808 
 809     assert(Universe::heap()->is_in_or_null(receiver()),
 810            "sanity check");
 811     assert(receiver.is_null() ||
 812            !Universe::heap()->is_in(receiver->klass()),
 813            "sanity check");
 814   }
 815 
 816   // resolve method

 895     cache->set_itable_call(
 896       bytecode,
 897       method_index,
 898       info.resolved_klass(),
 899       resolved_method,
 900       info.itable_index());
 901     break;
 902   default:  ShouldNotReachHere();
 903   }
 904 }
 905 
 906 void InterpreterRuntime::cds_resolve_invoke(Bytecodes::Code bytecode, int method_index,
 907                                             constantPoolHandle& pool, TRAPS) {
 908   LinkInfo link_info(pool, method_index, bytecode, CHECK);
 909 
 910   if (!link_info.resolved_klass()->is_instance_klass() || InstanceKlass::cast(link_info.resolved_klass())->is_linked()) {
 911     CallInfo call_info;
 912     switch (bytecode) {
 913       case Bytecodes::_invokevirtual:   LinkResolver::cds_resolve_virtual_call  (call_info, link_info, CHECK); break;
 914       case Bytecodes::_invokeinterface: LinkResolver::cds_resolve_interface_call(call_info, link_info, CHECK); break;

 915       case Bytecodes::_invokespecial:   LinkResolver::cds_resolve_special_call  (call_info, link_info, CHECK); break;
 916 
 917       default: fatal("Unimplemented: %s", Bytecodes::name(bytecode));
 918     }
 919     methodHandle resolved_method(THREAD, call_info.resolved_method());
 920     guarantee(resolved_method->method_holder()->is_linked(), "");
 921     update_invoke_cp_cache_entry(call_info, bytecode, resolved_method, pool, method_index);
 922   } else {
 923     // FIXME: why a shared class is not linked yet?
 924     // Can't link it here since there are no guarantees it'll be prelinked on the next run.
 925     ResourceMark rm;
 926     InstanceKlass* resolved_iklass = InstanceKlass::cast(link_info.resolved_klass());
 927     log_info(aot, resolve)("Not resolved: class not linked: %s %s %s",
 928                            resolved_iklass->in_aot_cache() ? "in_aot_cache" : "",
 929                            resolved_iklass->init_state_name(),
 930                            resolved_iklass->external_name());
 931   }
 932 }
 933 
 934 // First time execution:  Resolve symbols, create a permanent MethodType object.
 935 void InterpreterRuntime::resolve_invokehandle(JavaThread* current) {
 936   const Bytecodes::Code bytecode = Bytecodes::_invokehandle;
 937   LastFrameAccessor last_frame(current);
 938 
 939   // resolve method
 940   CallInfo info;
 941   constantPoolHandle pool(current, last_frame.method()->constants());
 942   int method_index = last_frame.get_index_u2(bytecode);
 943   {
 944     JvmtiHideSingleStepping jhss(current);
 945     JavaThread* THREAD = current; // For exception macros.
 946     LinkResolver::resolve_invoke(info, Handle(), pool,
 947                                  method_index, bytecode,
 948                                  CHECK);
 949   } // end JvmtiHideSingleStepping
 950 
 951   pool->cache()->set_method_handle(method_index, info);
 952 }
 953 
 954 void InterpreterRuntime::cds_resolve_invokehandle(int raw_index,
 955                                                   constantPoolHandle& pool, TRAPS) {
 956   const Bytecodes::Code bytecode = Bytecodes::_invokehandle;
 957   CallInfo info;
 958   LinkResolver::resolve_invoke(info, Handle(), pool, raw_index, bytecode, CHECK);
 959 
 960   pool->cache()->set_method_handle(raw_index, info);
 961 }
 962 
 963 // First time execution:  Resolve symbols, create a permanent CallSite object.
 964 void InterpreterRuntime::resolve_invokedynamic(JavaThread* current) {
 965   LastFrameAccessor last_frame(current);
 966   const Bytecodes::Code bytecode = Bytecodes::_invokedynamic;
 967 
 968   // resolve method
 969   CallInfo info;
 970   constantPoolHandle pool(current, last_frame.method()->constants());
 971   int index = last_frame.get_index_u4(bytecode);
 972   {
 973     JvmtiHideSingleStepping jhss(current);
 974     JavaThread* THREAD = current; // For exception macros.
 975     LinkResolver::resolve_invoke(info, Handle(), pool,
 976                                  index, bytecode, CHECK);
 977   } // end JvmtiHideSingleStepping
 978 
 979   pool->cache()->set_dynamic_call(info, index);
 980 }
 981 
 982 void InterpreterRuntime::cds_resolve_invokedynamic(int raw_index,
 983                                                    constantPoolHandle& pool, TRAPS) {
 984   const Bytecodes::Code bytecode = Bytecodes::_invokedynamic;
 985   CallInfo info;
 986   LinkResolver::resolve_invoke(info, Handle(), pool, raw_index, bytecode, CHECK);
 987   pool->cache()->set_dynamic_call(info, raw_index);
 988 }
 989 
 990 // This function is the interface to the assembly code. It returns the resolved
 991 // cpCache entry.  This doesn't safepoint, but the helper routines safepoint.
 992 // This function will check for redefinition!
 993 JRT_ENTRY(void, InterpreterRuntime::resolve_from_cache(JavaThread* current, Bytecodes::Code bytecode)) {


 994   switch (bytecode) {
 995   case Bytecodes::_getstatic:
 996   case Bytecodes::_putstatic:
 997   case Bytecodes::_getfield:
 998   case Bytecodes::_putfield:
 999     resolve_get_put(current, bytecode);
1000     break;
1001   case Bytecodes::_invokevirtual:
1002   case Bytecodes::_invokespecial:
1003   case Bytecodes::_invokestatic:
1004   case Bytecodes::_invokeinterface:
1005     resolve_invoke(current, bytecode);
1006     break;
1007   case Bytecodes::_invokehandle:
1008     resolve_invokehandle(current);
1009     break;
1010   case Bytecodes::_invokedynamic:
1011     resolve_invokedynamic(current);
1012     break;
1013   default:
1014     fatal("unexpected bytecode: %s", Bytecodes::name(bytecode));
1015     break;
1016   }
1017 }
1018 JRT_END
1019 
1020 //------------------------------------------------------------------------------------------------------------------------
1021 // Miscellaneous
1022 
1023 
1024 nmethod* InterpreterRuntime::frequency_counter_overflow(JavaThread* current, address branch_bcp) {


1025   // Enable WXWrite: the function is called directly by interpreter.
1026   MACOS_AARCH64_ONLY(ThreadWXEnable wx(WXWrite, current));
1027 
1028   // frequency_counter_overflow_inner can throw async exception.
1029   nmethod* nm = frequency_counter_overflow_inner(current, branch_bcp);
1030   assert(branch_bcp != nullptr || nm == nullptr, "always returns null for non OSR requests");
1031   if (branch_bcp != nullptr && nm != nullptr) {
1032     // This was a successful request for an OSR nmethod.  Because
1033     // frequency_counter_overflow_inner ends with a safepoint check,
1034     // nm could have been unloaded so look it up again.  It's unsafe
1035     // to examine nm directly since it might have been freed and used
1036     // for something else.
1037     LastFrameAccessor last_frame(current);
1038     Method* method =  last_frame.method();
1039     int bci = method->bci_from(last_frame.bcp());
1040     nm = method->lookup_osr_nmethod_for(bci, CompLevel_none, false);
1041     BarrierSetNMethod* bs_nm = BarrierSet::barrier_set()->barrier_set_nmethod();
1042     if (nm != nullptr) {
1043       // in case the transition passed a safepoint we need to barrier this again
1044       if (!bs_nm->nmethod_osr_entry_barrier(nm)) {

1048   }
1049   if (nm != nullptr && current->is_interp_only_mode()) {
1050     // Normally we never get an nm if is_interp_only_mode() is true, because
1051     // policy()->event has a check for this and won't compile the method when
1052     // true. However, it's possible for is_interp_only_mode() to become true
1053     // during the compilation. We don't want to return the nm in that case
1054     // because we want to continue to execute interpreted.
1055     nm = nullptr;
1056   }
1057 #ifndef PRODUCT
1058   if (TraceOnStackReplacement) {
1059     if (nm != nullptr) {
1060       tty->print("OSR entry @ pc: " INTPTR_FORMAT ": ", p2i(nm->osr_entry()));
1061       nm->print();
1062     }
1063   }
1064 #endif
1065   return nm;
1066 }
1067 
1068 JRT_ENTRY(nmethod*,
1069           InterpreterRuntime::frequency_counter_overflow_inner(JavaThread* current, address branch_bcp))
1070   // use UnlockFlagSaver to clear and restore the _do_not_unlock_if_synchronized
1071   // flag, in case this method triggers classloading which will call into Java.
1072   UnlockFlagSaver fs(current);
1073 
1074   LastFrameAccessor last_frame(current);
1075   assert(last_frame.is_interpreted_frame(), "must come from interpreter");
1076   methodHandle method(current, last_frame.method());
1077   const int branch_bci = branch_bcp != nullptr ? method->bci_from(branch_bcp) : InvocationEntryBci;
1078   const int bci = branch_bcp != nullptr ? method->bci_from(last_frame.bcp()) : InvocationEntryBci;
1079 
1080   nmethod* osr_nm = CompilationPolicy::event(method, method, branch_bci, bci, CompLevel_none, nullptr, CHECK_NULL);
1081 
1082   BarrierSetNMethod* bs_nm = BarrierSet::barrier_set()->barrier_set_nmethod();
1083   if (osr_nm != nullptr) {
1084     if (!bs_nm->nmethod_osr_entry_barrier(osr_nm)) {
1085       osr_nm = nullptr;
1086     }
1087   }
1088   return osr_nm;
1089 JRT_END
1090 
1091 JRT_LEAF(jint, InterpreterRuntime::bcp_to_di(Method* method, address cur_bcp))
1092   assert(ProfileInterpreter, "must be profiling interpreter");
1093   int bci = method->bci_from(cur_bcp);
1094   MethodData* mdo = method->method_data();
1095   if (mdo == nullptr)  return 0;
1096   return mdo->bci_to_di(bci);
1097 JRT_END
1098 
1099 #ifdef ASSERT
1100 JRT_LEAF(void, InterpreterRuntime::verify_mdp(Method* method, address bcp, address mdp))
1101   assert(ProfileInterpreter, "must be profiling interpreter");
1102 
1103   MethodData* mdo = method->method_data();
1104   assert(mdo != nullptr, "must not be null");
1105 
1106   int bci = method->bci_from(bcp);
1107 
1108   address mdp2 = mdo->bci_to_dp(bci);
1109   if (mdp != mdp2) {
1110     ResourceMark rm;
1111     tty->print_cr("FAILED verify : actual mdp %p   expected mdp %p @ bci %d", mdp, mdp2, bci);
1112     int current_di = mdo->dp_to_di(mdp);
1113     int expected_di  = mdo->dp_to_di(mdp2);
1114     tty->print_cr("  actual di %d   expected di %d", current_di, expected_di);
1115     int expected_approx_bci = mdo->data_at(expected_di)->bci();
1116     int approx_bci = -1;
1117     if (current_di >= 0) {
1118       approx_bci = mdo->data_at(current_di)->bci();
1119     }
1120     tty->print_cr("  actual bci is %d  expected bci %d", approx_bci, expected_approx_bci);
1121     mdo->print_on(tty);
1122     method->print_codes();
1123   }
1124   assert(mdp == mdp2, "wrong mdp");
1125 JRT_END
1126 #endif // ASSERT
1127 
1128 JRT_ENTRY(void, InterpreterRuntime::update_mdp_for_ret(JavaThread* current, int return_bci))

1129   assert(ProfileInterpreter, "must be profiling interpreter");
1130   ResourceMark rm(current);
1131   LastFrameAccessor last_frame(current);
1132   assert(last_frame.is_interpreted_frame(), "must come from interpreter");
1133   MethodData* h_mdo = last_frame.method()->method_data();
1134 
1135   // Grab a lock to ensure atomic access to setting the return bci and
1136   // the displacement.  This can block and GC, invalidating all naked oops.
1137   MutexLocker ml(RetData_lock);
1138 
1139   // ProfileData is essentially a wrapper around a derived oop, so we
1140   // need to take the lock before making any ProfileData structures.
1141   ProfileData* data = h_mdo->data_at(h_mdo->dp_to_di(last_frame.mdp()));
1142   guarantee(data != nullptr, "profile data must be valid");
1143   RetData* rdata = data->as_RetData();
1144   address new_mdp = rdata->fixup_ret(return_bci, h_mdo);
1145   last_frame.set_mdp(new_mdp);
1146 JRT_END
1147 
1148 JRT_ENTRY(MethodCounters*, InterpreterRuntime::build_method_counters(JavaThread* current, Method* m))
1149   return Method::build_method_counters(current, m);
1150 JRT_END
1151 
1152 
1153 JRT_ENTRY(void, InterpreterRuntime::at_safepoint(JavaThread* current))
1154   // We used to need an explicit preserve_arguments here for invoke bytecodes. However,
1155   // stack traversal automatically takes care of preserving arguments for invoke, so
1156   // this is no longer needed.
1157 
1158   // JRT_END does an implicit safepoint check, hence we are guaranteed to block
1159   // if this is called during a safepoint
1160 
1161   if (JvmtiExport::should_post_single_step()) {
1162     // This function is called by the interpreter when single stepping. Such single
1163     // stepping could unwind a frame. Then, it is important that we process any frames
1164     // that we might return into.
1165     StackWatermarkSet::before_unwind(current);
1166 
1167     // We are called during regular safepoints and when the VM is
1168     // single stepping. If any thread is marked for single stepping,
1169     // then we may have JVMTI work to do.
1170     LastFrameAccessor last_frame(current);
1171     JvmtiExport::at_single_stepping_point(current, last_frame.method(), last_frame.bcp());
1172   }
1173 JRT_END
1174 
1175 JRT_LEAF(void, InterpreterRuntime::at_unwind(JavaThread* current))
1176   assert(current == JavaThread::current(), "pre-condition");
1177   JFR_ONLY(Jfr::check_and_process_sample_request(current);)
1178   // This function is called by the interpreter when the return poll found a reason
1179   // to call the VM. The reason could be that we are returning into a not yet safe
1180   // to access frame. We handle that below.
1181   // Note that this path does not check for single stepping, because we do not want
1182   // to single step when unwinding frames for an exception being thrown. Instead,
1183   // such single stepping code will use the safepoint table, which will use the
1184   // InterpreterRuntime::at_safepoint callback.
1185   StackWatermarkSet::before_unwind(current);
1186 JRT_END
1187 
1188 JRT_ENTRY(void, InterpreterRuntime::post_field_access(JavaThread* current, oopDesc* obj,
1189                                                       ResolvedFieldEntry *entry))
1190 
1191   // check the access_flags for the field in the klass
1192 
1193   InstanceKlass* ik = entry->field_holder();
1194   int index = entry->field_index();
1195   if (!ik->field_status(index).is_access_watched()) return;
1196 
1197   bool is_static = (obj == nullptr);
1198   HandleMark hm(current);
1199 
1200   Handle h_obj;
1201   if (!is_static) {
1202     // non-static field accessors have an object, but we need a handle
1203     h_obj = Handle(current, obj);
1204   }
1205   InstanceKlass* field_holder = entry->field_holder(); // HERE
1206   jfieldID fid = jfieldIDWorkaround::to_jfieldID(field_holder, entry->field_offset(), is_static);
1207   LastFrameAccessor last_frame(current);
1208   JvmtiExport::post_field_access(current, last_frame.method(), last_frame.bcp(), field_holder, h_obj, fid);
1209 JRT_END
1210 
1211 JRT_ENTRY(void, InterpreterRuntime::post_field_modification(JavaThread* current, oopDesc* obj,
1212                                                             ResolvedFieldEntry *entry, jvalue *value))
1213 
1214   InstanceKlass* ik = entry->field_holder();
1215 
1216   // check the access_flags for the field in the klass
1217   int index = entry->field_index();
1218   // bail out if field modifications are not watched
1219   if (!ik->field_status(index).is_modification_watched()) return;
1220 
1221   char sig_type = '\0';
1222 
1223   switch((TosState)entry->tos_state()) {
1224     case btos: sig_type = JVM_SIGNATURE_BYTE;    break;
1225     case ztos: sig_type = JVM_SIGNATURE_BOOLEAN; break;
1226     case ctos: sig_type = JVM_SIGNATURE_CHAR;    break;
1227     case stos: sig_type = JVM_SIGNATURE_SHORT;   break;
1228     case itos: sig_type = JVM_SIGNATURE_INT;     break;
1229     case ftos: sig_type = JVM_SIGNATURE_FLOAT;   break;
1230     case atos: sig_type = JVM_SIGNATURE_CLASS;   break;
1231     case ltos: sig_type = JVM_SIGNATURE_LONG;    break;
1232     case dtos: sig_type = JVM_SIGNATURE_DOUBLE;  break;

1247   // We assume that the two halves of longs/doubles are stored in interpreter
1248   // stack slots in platform-endian order.
1249   jlong_accessor u;
1250   jint* newval = (jint*)value;
1251   u.words[0] = newval[0];
1252   u.words[1] = newval[Interpreter::stackElementWords]; // skip if tag
1253   fvalue.j = u.long_value;
1254 #endif // _LP64
1255 
1256   Handle h_obj;
1257   if (!is_static) {
1258     // non-static field accessors have an object, but we need a handle
1259     h_obj = Handle(current, obj);
1260   }
1261 
1262   LastFrameAccessor last_frame(current);
1263   JvmtiExport::post_raw_field_modification(current, last_frame.method(), last_frame.bcp(), ik, h_obj,
1264                                            fid, sig_type, &fvalue);
1265 JRT_END
1266 
1267 JRT_ENTRY(void, InterpreterRuntime::post_method_entry(JavaThread* current))
1268   LastFrameAccessor last_frame(current);
1269   JvmtiExport::post_method_entry(current, last_frame.method(), last_frame.get_frame());
1270 JRT_END
1271 
1272 
1273 // This is a JRT_BLOCK_ENTRY because we have to stash away the return oop
1274 // before transitioning to VM, and restore it after transitioning back
1275 // to Java. The return oop at the top-of-stack, is not walked by the GC.
1276 JRT_BLOCK_ENTRY(void, InterpreterRuntime::post_method_exit(JavaThread* current))
1277   LastFrameAccessor last_frame(current);
1278   JvmtiExport::post_method_exit(current, last_frame.method(), last_frame.get_frame());
1279 JRT_END
1280 
1281 JRT_LEAF(int, InterpreterRuntime::interpreter_contains(address pc))
1282 {
1283   return (Interpreter::contains(Continuation::get_top_return_pc_post_barrier(JavaThread::current(), pc)) ? 1 : 0);
1284 }
1285 JRT_END
1286 
1287 
1288 // Implementation of SignatureHandlerLibrary
1289 
1290 #ifndef SHARING_FAST_NATIVE_FINGERPRINTS
1291 // Dummy definition (else normalization method is defined in CPU
1292 // dependent code)
1293 uint64_t InterpreterRuntime::normalize_fast_native_fingerprint(uint64_t fingerprint) {
1294   return fingerprint;
1295 }
1296 #endif
1297 
1298 address SignatureHandlerLibrary::set_handler_blob() {
1299   BufferBlob* handler_blob = BufferBlob::create("native signature handlers", blob_size);
1300   if (handler_blob == nullptr) {
1301     return nullptr;

1427     MutexLocker mu(SignatureHandlerLibrary_lock);
1428     if (_handlers != nullptr) {
1429       handler_index = _handlers->find(method->signature_handler());
1430       uint64_t fingerprint = Fingerprinter(method).fingerprint();
1431       fingerprint = InterpreterRuntime::normalize_fast_native_fingerprint(fingerprint);
1432       fingerprint_index = _fingerprints->find(fingerprint);
1433     }
1434   }
1435   assert(method->signature_handler() == Interpreter::slow_signature_handler() ||
1436          handler_index == fingerprint_index, "sanity check");
1437 #endif // ASSERT
1438 }
1439 
1440 BufferBlob*              SignatureHandlerLibrary::_handler_blob = nullptr;
1441 address                  SignatureHandlerLibrary::_handler      = nullptr;
1442 GrowableArray<uint64_t>* SignatureHandlerLibrary::_fingerprints = nullptr;
1443 GrowableArray<address>*  SignatureHandlerLibrary::_handlers     = nullptr;
1444 address                  SignatureHandlerLibrary::_buffer       = nullptr;
1445 
1446 
1447 JRT_ENTRY(void, InterpreterRuntime::prepare_native_call(JavaThread* current, Method* method))
1448   methodHandle m(current, method);
1449   assert(m->is_native(), "sanity check");
1450   // lookup native function entry point if it doesn't exist
1451   if (!m->has_native_function()) {
1452     NativeLookup::lookup(m, CHECK);
1453   }
1454   // make sure signature handler is installed
1455   SignatureHandlerLibrary::add(m);
1456   // The interpreter entry point checks the signature handler first,
1457   // before trying to fetch the native entry point and klass mirror.
1458   // We must set the signature handler last, so that multiple processors
1459   // preparing the same method will be sure to see non-null entry & mirror.
1460 JRT_END
1461 
1462 #if defined(IA32) || defined(AMD64) || defined(ARM)
1463 JRT_LEAF(void, InterpreterRuntime::popframe_move_outgoing_args(JavaThread* current, void* src_address, void* dest_address))
1464   assert(current == JavaThread::current(), "pre-condition");
1465   if (src_address == dest_address) {
1466     return;
1467   }
1468   ResourceMark rm;
1469   LastFrameAccessor last_frame(current);
1470   assert(last_frame.is_interpreted_frame(), "");
1471   jint bci = last_frame.bci();
1472   methodHandle mh(current, last_frame.method());
1473   Bytecode_invoke invoke(mh, bci);
1474   ArgumentSizeComputer asc(invoke.signature());
1475   int size_of_arguments = (asc.size() + (invoke.has_receiver() ? 1 : 0)); // receiver
1476   Copy::conjoint_jbytes(src_address, dest_address,
1477                        size_of_arguments * Interpreter::stackElementSize);
1478 JRT_END
1479 #endif
1480 
1481 #if INCLUDE_JVMTI
1482 // This is a support of the JVMTI PopFrame interface.
1483 // Make sure it is an invokestatic of a polymorphic intrinsic that has a member_name argument
1484 // and return it as a vm_result_oop so that it can be reloaded in the list of invokestatic parameters.
1485 // The member_name argument is a saved reference (in local#0) to the member_name.
1486 // For backward compatibility with some JDK versions (7, 8) it can also be a direct method handle.
1487 // FIXME: remove DMH case after j.l.i.InvokerBytecodeGenerator code shape is updated.
1488 JRT_ENTRY(void, InterpreterRuntime::member_name_arg_or_null(JavaThread* current, address member_name,
1489                                                             Method* method, address bcp))

1490   Bytecodes::Code code = Bytecodes::code_at(method, bcp);
1491   if (code != Bytecodes::_invokestatic) {
1492     return;
1493   }
1494   ConstantPool* cpool = method->constants();
1495   int cp_index = Bytes::get_native_u2(bcp + 1);
1496   Symbol* cname = cpool->klass_name_at(cpool->klass_ref_index_at(cp_index, code));
1497   Symbol* mname = cpool->name_ref_at(cp_index, code);
1498 
1499   if (MethodHandles::has_member_arg(cname, mname)) {
1500     oop member_name_oop = cast_to_oop(member_name);
1501     if (java_lang_invoke_DirectMethodHandle::is_instance(member_name_oop)) {
1502       // FIXME: remove after j.l.i.InvokerBytecodeGenerator code shape is updated.
1503       member_name_oop = java_lang_invoke_DirectMethodHandle::member(member_name_oop);
1504     }
1505     current->set_vm_result_oop(member_name_oop);
1506   } else {
1507     current->set_vm_result_oop(nullptr);
1508   }
1509 JRT_END
1510 #endif // INCLUDE_JVMTI
1511 
1512 #ifndef PRODUCT
1513 // This must be a JRT_LEAF function because the interpreter must save registers on x86 to
1514 // call this, which changes rsp and makes the interpreter's expression stack not walkable.
1515 // The generated code still uses call_VM because that will set up the frame pointer for
1516 // bcp and method.
1517 JRT_LEAF(intptr_t, InterpreterRuntime::trace_bytecode(JavaThread* current, intptr_t preserve_this_value, intptr_t tos, intptr_t tos2))
1518   assert(current == JavaThread::current(), "pre-condition");
1519   LastFrameAccessor last_frame(current);
1520   assert(last_frame.is_interpreted_frame(), "must be an interpreted frame");
1521   methodHandle mh(current, last_frame.method());
1522   BytecodeTracer::trace_interpreter(mh, last_frame.bcp(), tos, tos2);
1523   return preserve_this_value;
1524 JRT_END
1525 #endif // !PRODUCT







































































































  50 #include "oops/methodData.hpp"
  51 #include "oops/objArrayKlass.hpp"
  52 #include "oops/objArrayOop.inline.hpp"
  53 #include "oops/oop.inline.hpp"
  54 #include "oops/symbol.hpp"
  55 #include "prims/jvmtiExport.hpp"
  56 #include "prims/methodHandles.hpp"
  57 #include "prims/nativeLookup.hpp"
  58 #include "runtime/atomic.hpp"
  59 #include "runtime/continuation.hpp"
  60 #include "runtime/deoptimization.hpp"
  61 #include "runtime/fieldDescriptor.inline.hpp"
  62 #include "runtime/frame.inline.hpp"
  63 #include "runtime/handles.inline.hpp"
  64 #include "runtime/icache.hpp"
  65 #include "runtime/interfaceSupport.inline.hpp"
  66 #include "runtime/java.hpp"
  67 #include "runtime/javaCalls.hpp"
  68 #include "runtime/jfieldIDWorkaround.hpp"
  69 #include "runtime/osThread.hpp"
  70 #include "runtime/perfData.inline.hpp"
  71 #include "runtime/sharedRuntime.hpp"
  72 #include "runtime/stackWatermarkSet.hpp"
  73 #include "runtime/stubRoutines.hpp"
  74 #include "runtime/synchronizer.inline.hpp"
  75 #include "services/management.hpp"
  76 #include "utilities/align.hpp"
  77 #include "utilities/checkedCast.hpp"
  78 #include "utilities/copy.hpp"
  79 #include "utilities/events.hpp"
  80 #if INCLUDE_JFR
  81 #include "jfr/jfr.inline.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 static bool is_resolved(JavaThread* current) {
 127   LastFrameAccessor last_frame(current);
 128   ConstantPool* constants = last_frame.method()->constants();
 129   Bytecodes::Code bc = last_frame.code();
 130 
 131   if (bc == Bytecodes::_ldc || bc == Bytecodes::_ldc_w || bc == Bytecodes::_ldc2_w ||
 132       bc == Bytecodes::_fast_aldc || bc == Bytecodes::_fast_aldc_w) {
 133     bool is_wide = (bc != Bytecodes::_ldc) && (bc != Bytecodes::_fast_aldc);
 134     int index = (is_wide ? last_frame.get_index_u1(bc) : last_frame.get_index_u2(bc));
 135     constantTag tag = constants->tag_at(index);
 136     assert(tag.is_klass_or_reference(), "unknown tag: %s", tag.internal_name());
 137     return constants->tag_at(index).is_klass();
 138   } else if (bc == Bytecodes::_invokedynamic) {
 139     int index = last_frame.get_index_u4(bc);
 140     int indy_index = index;
 141     ResolvedIndyEntry* indy_entry = constants->resolved_indy_entry_at(indy_index);
 142     return indy_entry->is_resolved();
 143   } else if (Bytecodes::is_invoke(bc)) {
 144     int index = last_frame.get_index_u2(bc);
 145     ResolvedMethodEntry* rme = constants->resolved_method_entry_at(index);
 146     return rme->is_resolved(bc);
 147   } else if (Bytecodes::is_field_code(bc) || bc == Bytecodes::_nofast_getfield || bc == Bytecodes::_nofast_putfield) {
 148     if (bc == Bytecodes::_nofast_getfield) {
 149       bc = Bytecodes::_getfield;
 150     } else if (bc == Bytecodes::_nofast_putfield) {
 151       bc = Bytecodes::_putfield;
 152     }
 153     int index = last_frame.get_index_u2(bc);
 154     ResolvedFieldEntry* field_entry = constants->cache()->resolved_field_entry_at(index);
 155     return field_entry->is_resolved(bc);
 156   } else if (bc == Bytecodes::_new) {
 157     int index = last_frame.get_index_u2(bc);
 158     constantTag tag = constants->tag_at(index);
 159     assert(tag.is_klass_or_reference(), "unknown tag: %s", tag.internal_name());
 160     return constants->tag_at(index).is_klass();
 161   }
 162   return false;
 163 }
 164 
 165 static void trace_current_location(JavaThread* current) {
 166   LogStreamHandle(Debug, init, interpreter) log;
 167   if (current->profile_rt_calls() && log.is_enabled()) {
 168     ResourceMark rm(current);
 169     LastFrameAccessor last_frame(current);
 170     Method* caller = last_frame.method();
 171     ConstantPool* constants = caller->constants();
 172     Bytecodes::Code bc = last_frame.code();
 173     log.print("InterpreterRuntime: " INTPTR_FORMAT ": %s: " INTPTR_FORMAT,
 174               p2i(current), Bytecodes::name(bc), p2i(caller));
 175     if (caller->in_aot_cache()) {
 176       log.print(" aot");
 177     }
 178     if (is_resolved(current)) {
 179       log.print(" resolved");
 180     }
 181     log.print(" ");
 182     caller->print_short_name(&log);
 183     log.print(" @ %d:", last_frame.bci());
 184     int instruction_size = last_frame.bytecode().instruction_size();
 185 
 186     if (Bytecodes::is_invoke(bc) && bc != Bytecodes::_invokedynamic) {
 187       int index = last_frame.get_index_u2(bc);
 188       ResolvedMethodEntry* rme = constants->resolved_method_entry_at(index);
 189       if (rme->is_resolved(bc)) {
 190         Method* m = rme->method();
 191         if (m != nullptr) {
 192           log.print(" %s", m->method_holder()->init_state_name());
 193         } else {
 194           log.print(" null");
 195         }
 196       }
 197     } else if (Bytecodes::is_field_code(bc) || bc == Bytecodes::_nofast_getfield || bc == Bytecodes::_nofast_putfield) {
 198       if (bc == Bytecodes::_nofast_getfield) {
 199         bc = Bytecodes::_getfield;
 200       } else if (bc == Bytecodes::_nofast_putfield) {
 201         bc = Bytecodes::_putfield;
 202       }
 203       int index = last_frame.get_index_u2(bc);
 204       ResolvedFieldEntry* field_entry = constants->cache()->resolved_field_entry_at(index);
 205 
 206       if (field_entry->is_resolved(bc)) {
 207         log.print(" %s", field_entry->field_holder()->init_state_name());
 208       }
 209     } else if (bc == Bytecodes::_new) {
 210       int index = last_frame.get_index_u2(bc);
 211       constantTag tag = constants->tag_at(index);
 212       assert(tag.is_klass_or_reference(), "unknown tag: %s", tag.internal_name());
 213       if (constants->tag_at(index).is_klass()) {
 214         CPKlassSlot kslot = constants->klass_slot_at(index);
 215         int resolved_klass_index = kslot.resolved_klass_index();
 216         Klass* k = constants->resolved_klasses()->at(resolved_klass_index);
 217         log.print(": %s", InstanceKlass::cast(k)->init_state_name());
 218       }
 219     }
 220     log.print(" ");
 221     caller->print_codes_on(last_frame.bci(), last_frame.bci() + instruction_size, &log, /*flags*/ 0);
 222 
 223     LogStreamHandle(Trace, init, interpreter) log1;
 224     if (log1.is_enabled()) {
 225       if (bc == Bytecodes::_invokedynamic) {
 226         int index = last_frame.get_index_u4(bc);
 227         int indy_index = index;
 228         ResolvedIndyEntry* indy_entry = constants->resolved_indy_entry_at(indy_index);
 229         indy_entry->print_on(&log1);
 230       } else if (Bytecodes::is_invoke(bc)) {
 231         int index = last_frame.get_index_u2(bc);
 232         ResolvedMethodEntry* rme = constants->resolved_method_entry_at(index);
 233         rme->print_on(&log1);
 234       } else if (Bytecodes::is_field_code(bc) || bc == Bytecodes::_nofast_getfield || bc == Bytecodes::_nofast_putfield) {
 235         int index = last_frame.get_index_u2(bc);
 236         ResolvedFieldEntry* field_entry = constants->cache()->resolved_field_entry_at(index);
 237         field_entry->print_on(&log1);
 238       }
 239     }
 240   }
 241 }
 242 
 243 //------------------------------------------------------------------------------------------------------------------------
 244 // State accessors
 245 
 246 void InterpreterRuntime::set_bcp_and_mdp(address bcp, JavaThread* current) {
 247   LastFrameAccessor last_frame(current);
 248   last_frame.set_bcp(bcp);
 249   if (ProfileInterpreter) {
 250     // ProfileTraps uses MDOs independently of ProfileInterpreter.
 251     // That is why we must check both ProfileInterpreter and mdo != nullptr.
 252     MethodData* mdo = last_frame.method()->method_data();
 253     if (mdo != nullptr) {
 254       NEEDS_CLEANUP;
 255       last_frame.set_mdp(mdo->bci_to_dp(last_frame.bci()));
 256     }
 257   }
 258 }
 259 
 260 //------------------------------------------------------------------------------------------------------------------------
 261 // Constants
 262 
 263 
 264 JRT_ENTRY_PROF(void, InterpreterRuntime, ldc, InterpreterRuntime::ldc(JavaThread* current, bool wide))
 265   // access constant pool
 266   LastFrameAccessor last_frame(current);
 267   ConstantPool* pool = last_frame.method()->constants();
 268   int cp_index = wide ? last_frame.get_index_u2(Bytecodes::_ldc_w) : last_frame.get_index_u1(Bytecodes::_ldc);
 269   constantTag tag = pool->tag_at(cp_index);
 270 
 271   assert (tag.is_unresolved_klass() || tag.is_klass(), "wrong ldc call");
 272   Klass* klass = pool->klass_at(cp_index, CHECK);
 273   oop java_class = klass->java_mirror();
 274   current->set_vm_result_oop(java_class);
 275 JRT_END
 276 
 277 JRT_ENTRY_PROF(void, InterpreterRuntime, resolve_ldc, InterpreterRuntime::resolve_ldc(JavaThread* current, Bytecodes::Code bytecode)) {
 278   assert(bytecode == Bytecodes::_ldc ||
 279          bytecode == Bytecodes::_ldc_w ||
 280          bytecode == Bytecodes::_ldc2_w ||
 281          bytecode == Bytecodes::_fast_aldc ||
 282          bytecode == Bytecodes::_fast_aldc_w, "wrong bc");
 283   ResourceMark rm(current);
 284   const bool is_fast_aldc = (bytecode == Bytecodes::_fast_aldc ||
 285                              bytecode == Bytecodes::_fast_aldc_w);
 286   LastFrameAccessor last_frame(current);
 287   methodHandle m (current, last_frame.method());
 288   Bytecode_loadconstant ldc(m, last_frame.bci());
 289 
 290   // Double-check the size.  (Condy can have any type.)
 291   BasicType type = ldc.result_type();
 292   switch (type2size[type]) {
 293   case 2: guarantee(bytecode == Bytecodes::_ldc2_w, ""); break;
 294   case 1: guarantee(bytecode != Bytecodes::_ldc2_w, ""); break;
 295   default: ShouldNotReachHere();
 296   }
 297 

 313       assert(roop == coop, "expected result for assembly code");
 314     }
 315   }
 316 #endif
 317   current->set_vm_result_oop(result);
 318   if (!is_fast_aldc) {
 319     // Tell the interpreter how to unbox the primitive.
 320     guarantee(java_lang_boxing_object::is_instance(result, type), "");
 321     int offset = java_lang_boxing_object::value_offset(type);
 322     intptr_t flags = ((as_TosState(type) << ConstantPoolCache::tos_state_shift)
 323                       | (offset & ConstantPoolCache::field_index_mask));
 324     current->set_vm_result_metadata((Metadata*)flags);
 325   }
 326 }
 327 JRT_END
 328 
 329 
 330 //------------------------------------------------------------------------------------------------------------------------
 331 // Allocation
 332 
 333 JRT_ENTRY_PROF(void, InterpreterRuntime, new, InterpreterRuntime::_new(JavaThread* current, ConstantPool* pool, int index))
 334   Klass* k = pool->klass_at(index, CHECK);
 335   InstanceKlass* klass = InstanceKlass::cast(k);
 336 
 337   // Make sure we are not instantiating an abstract klass
 338   klass->check_valid_for_instantiation(true, CHECK);
 339 
 340   // Make sure klass is initialized
 341   klass->initialize(CHECK);
 342 
 343   oop obj = klass->allocate_instance(CHECK);
 344   current->set_vm_result_oop(obj);
 345 JRT_END
 346 
 347 
 348 JRT_ENTRY_PROF(void, InterpreterRuntime, newarray, InterpreterRuntime::newarray(JavaThread* current, BasicType type, jint size))
 349   oop obj = oopFactory::new_typeArray(type, size, CHECK);
 350   current->set_vm_result_oop(obj);
 351 JRT_END
 352 
 353 
 354 JRT_ENTRY_PROF(void, InterpreterRuntime, anewarray, InterpreterRuntime::anewarray(JavaThread* current, ConstantPool* pool, int index, jint size))
 355   Klass*    klass = pool->klass_at(index, CHECK);
 356   objArrayOop obj = oopFactory::new_objArray(klass, size, CHECK);
 357   current->set_vm_result_oop(obj);
 358 JRT_END
 359 
 360 
 361 JRT_ENTRY_PROF(void, InterpreterRuntime, multianewarray, InterpreterRuntime::multianewarray(JavaThread* current, jint* first_size_address))
 362   // We may want to pass in more arguments - could make this slightly faster
 363   LastFrameAccessor last_frame(current);
 364   ConstantPool* constants = last_frame.method()->constants();
 365   int          i = last_frame.get_index_u2(Bytecodes::_multianewarray);
 366   Klass* klass   = constants->klass_at(i, CHECK);
 367   int   nof_dims = last_frame.number_of_dimensions();
 368   assert(klass->is_klass(), "not a class");
 369   assert(nof_dims >= 1, "multianewarray rank must be nonzero");
 370 
 371   // We must create an array of jints to pass to multi_allocate.
 372   ResourceMark rm(current);
 373   const int small_dims = 10;
 374   jint dim_array[small_dims];
 375   jint *dims = &dim_array[0];
 376   if (nof_dims > small_dims) {
 377     dims = (jint*) NEW_RESOURCE_ARRAY(jint, nof_dims);
 378   }
 379   for (int index = 0; index < nof_dims; index++) {
 380     // offset from first_size_address is addressed as local[index]
 381     int n = Interpreter::local_offset_in_bytes(index)/jintSize;
 382     dims[index] = first_size_address[n];
 383   }
 384   oop obj = ArrayKlass::cast(klass)->multi_allocate(nof_dims, dims, CHECK);
 385   current->set_vm_result_oop(obj);
 386 JRT_END
 387 
 388 
 389 JRT_ENTRY_PROF(void, InterpreterRuntime, register_finalizer, InterpreterRuntime::register_finalizer(JavaThread* current, oopDesc* obj))
 390   assert(oopDesc::is_oop(obj), "must be a valid oop");
 391   assert(obj->klass()->has_finalizer(), "shouldn't be here otherwise");
 392   InstanceKlass::register_finalizer(instanceOop(obj), CHECK);
 393 JRT_END
 394 
 395 
 396 // Quicken instance-of and check-cast bytecodes
 397 JRT_ENTRY_PROF(void, InterpreterRuntime, quicken_io_cc, InterpreterRuntime::quicken_io_cc(JavaThread* current))
 398   // Force resolving; quicken the bytecode
 399   LastFrameAccessor last_frame(current);
 400   int which = last_frame.get_index_u2(Bytecodes::_checkcast);
 401   ConstantPool* cpool = last_frame.method()->constants();
 402   // We'd expect to assert that we're only here to quicken bytecodes, but in a multithreaded
 403   // program we might have seen an unquick'd bytecode in the interpreter but have another
 404   // thread quicken the bytecode before we get here.
 405   // assert( cpool->tag_at(which).is_unresolved_klass(), "should only come here to quicken bytecodes" );
 406   Klass* klass = cpool->klass_at(which, CHECK);
 407   current->set_vm_result_metadata(klass);
 408 JRT_END
 409 
 410 
 411 //------------------------------------------------------------------------------------------------------------------------
 412 // Exceptions
 413 
 414 void InterpreterRuntime::note_trap_inner(JavaThread* current, int reason,
 415                                          const methodHandle& trap_method, int trap_bci) {
 416   if (trap_method.not_null()) {
 417     MethodData* trap_mdo = trap_method->method_data();

 449 static Handle get_preinitialized_exception(Klass* k, TRAPS) {
 450   // get klass
 451   InstanceKlass* klass = InstanceKlass::cast(k);
 452   assert(klass->is_initialized(),
 453          "this klass should have been initialized during VM initialization");
 454   // create instance - do not call constructor since we may have no
 455   // (java) stack space left (should assert constructor is empty)
 456   Handle exception;
 457   oop exception_oop = klass->allocate_instance(CHECK_(exception));
 458   exception = Handle(THREAD, exception_oop);
 459   if (StackTraceInThrowable) {
 460     java_lang_Throwable::fill_in_stack_trace(exception);
 461   }
 462   return exception;
 463 }
 464 
 465 // Special handling for stack overflow: since we don't have any (java) stack
 466 // space left we use the pre-allocated & pre-initialized StackOverflowError
 467 // klass to create an stack overflow error instance.  We do not call its
 468 // constructor for the same reason (it is empty, anyway).
 469 JRT_ENTRY_PROF(void, InterpreterRuntime, throw_StackOverflowError,
 470            InterpreterRuntime::throw_StackOverflowError(JavaThread* current))
 471   Handle exception = get_preinitialized_exception(
 472                                  vmClasses::StackOverflowError_klass(),
 473                                  CHECK);
 474   // Increment counter for hs_err file reporting
 475   Atomic::inc(&Exceptions::_stack_overflow_errors);
 476   // Remove the ScopedValue bindings in case we got a StackOverflowError
 477   // while we were trying to manipulate ScopedValue bindings.
 478   current->clear_scopedValueBindings();
 479   THROW_HANDLE(exception);
 480 JRT_END
 481 
 482 JRT_ENTRY_PROF(void, InterpreterRuntime, throw_delayed_StackOverflowError,
 483            InterpreterRuntime::throw_delayed_StackOverflowError(JavaThread* current))
 484   Handle exception = get_preinitialized_exception(
 485                                  vmClasses::StackOverflowError_klass(),
 486                                  CHECK);
 487   java_lang_Throwable::set_message(exception(),
 488           Universe::delayed_stack_overflow_error_message());
 489   // Increment counter for hs_err file reporting
 490   Atomic::inc(&Exceptions::_stack_overflow_errors);
 491   // Remove the ScopedValue bindings in case we got a StackOverflowError
 492   // while we were trying to manipulate ScopedValue bindings.
 493   current->clear_scopedValueBindings();
 494   THROW_HANDLE(exception);
 495 JRT_END
 496 
 497 JRT_ENTRY_PROF(void, InterpreterRuntime, create_exception,
 498            InterpreterRuntime::create_exception(JavaThread* current, char* name, char* message))
 499   // lookup exception klass
 500   TempNewSymbol s = SymbolTable::new_symbol(name);
 501   if (ProfileTraps) {
 502     if (s == vmSymbols::java_lang_ArithmeticException()) {
 503       note_trap(current, Deoptimization::Reason_div0_check);
 504     } else if (s == vmSymbols::java_lang_NullPointerException()) {
 505       note_trap(current, Deoptimization::Reason_null_check);
 506     }
 507   }
 508   // create exception
 509   Handle exception = Exceptions::new_exception(current, s, message);
 510   current->set_vm_result_oop(exception());
 511 JRT_END
 512 
 513 
 514 JRT_ENTRY_PROF(void, InterpreterRuntime, create_klass_exception,
 515            InterpreterRuntime::create_klass_exception(JavaThread* current, char* name, oopDesc* obj))
 516   // Produce the error message first because note_trap can safepoint
 517   ResourceMark rm(current);
 518   const char* klass_name = obj->klass()->external_name();
 519   // lookup exception klass
 520   TempNewSymbol s = SymbolTable::new_symbol(name);
 521   if (ProfileTraps) {
 522     if (s == vmSymbols::java_lang_ArrayStoreException()) {
 523       note_trap(current, Deoptimization::Reason_array_check);
 524     } else {
 525       note_trap(current, Deoptimization::Reason_class_check);
 526     }
 527   }
 528   // create exception, with klass name as detail message
 529   Handle exception = Exceptions::new_exception(current, s, klass_name);
 530   current->set_vm_result_oop(exception());
 531 JRT_END
 532 
 533 JRT_ENTRY_PROF(void, InterpreterRuntime, throw_ArrayIndexOutOfBoundsException,
 534            InterpreterRuntime::throw_ArrayIndexOutOfBoundsException(JavaThread* current, arrayOopDesc* a, jint index))
 535   // Produce the error message first because note_trap can safepoint
 536   ResourceMark rm(current);
 537   stringStream ss;
 538   ss.print("Index %d out of bounds for length %d", index, a->length());
 539 
 540   if (ProfileTraps) {
 541     note_trap(current, Deoptimization::Reason_range_check);
 542   }
 543 
 544   THROW_MSG(vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), ss.as_string());
 545 JRT_END
 546 
 547 JRT_ENTRY_PROF(void, InterpreterRuntime, throw_ClassCastException,
 548            InterpreterRuntime::throw_ClassCastException(
 549   JavaThread* current, oopDesc* obj))
 550 
 551   // Produce the error message first because note_trap can safepoint
 552   ResourceMark rm(current);
 553   char* message = SharedRuntime::generate_class_cast_message(
 554     current, obj->klass());
 555 
 556   if (ProfileTraps) {
 557     note_trap(current, Deoptimization::Reason_class_check);
 558   }
 559 
 560   // create exception
 561   THROW_MSG(vmSymbols::java_lang_ClassCastException(), message);
 562 JRT_END
 563 
 564 // exception_handler_for_exception(...) returns the continuation address,
 565 // the exception oop (via TLS) and sets the bci/bcp for the continuation.
 566 // The exception oop is returned to make sure it is preserved over GC (it
 567 // is only on the stack if the exception was thrown explicitly via athrow).
 568 // During this operation, the expression stack contains the values for the
 569 // bci where the exception happened. If the exception was propagated back
 570 // from a call, the expression stack contains the values for the bci at the
 571 // invoke w/o arguments (i.e., as if one were inside the call).
 572 // Note that the implementation of this method assumes it's only called when an exception has actually occured
 573 JRT_ENTRY_PROF(address, InterpreterRuntime, exception_handler_for_exception,
 574            InterpreterRuntime::exception_handler_for_exception(JavaThread* current, oopDesc* exception))
 575   // We get here after we have unwound from a callee throwing an exception
 576   // into the interpreter. Any deferred stack processing is notified of
 577   // the event via the StackWatermarkSet.
 578   StackWatermarkSet::after_unwind(current);
 579 
 580   LastFrameAccessor last_frame(current);
 581   Handle             h_exception(current, exception);
 582   methodHandle       h_method   (current, last_frame.method());
 583   constantPoolHandle h_constants(current, h_method->constants());
 584   bool               should_repeat;
 585   int                handler_bci;
 586   int                current_bci = last_frame.bci();
 587 
 588   if (current->frames_to_pop_failed_realloc() > 0) {
 589     // Allocation of scalar replaced object used in this frame
 590     // failed. Unconditionally pop the frame.
 591     current->dec_frames_to_pop_failed_realloc();
 592     current->set_vm_result_oop(h_exception());
 593     // If the method is synchronized we already unlocked the monitor
 594     // during deoptimization so the interpreter needs to skip it when

 697     h_method->set_exception_handler_entered(handler_bci); // profiling
 698 #ifndef ZERO
 699     set_bcp_and_mdp(handler_pc, current);
 700     continuation = Interpreter::dispatch_table(vtos)[*handler_pc];
 701 #else
 702     continuation = (address)(intptr_t) handler_bci;
 703 #endif
 704   }
 705 
 706   // notify debugger of an exception catch
 707   // (this is good for exceptions caught in native methods as well)
 708   if (JvmtiExport::can_post_on_exceptions()) {
 709     JvmtiExport::notice_unwind_due_to_exception(current, h_method(), handler_pc, h_exception(), (handler_pc != nullptr));
 710   }
 711 
 712   current->set_vm_result_oop(h_exception());
 713   return continuation;
 714 JRT_END
 715 
 716 
 717 JRT_ENTRY_PROF(void, InterpreterRuntime, throw_pending_exception, InterpreterRuntime::throw_pending_exception(JavaThread* current))
 718   assert(current->has_pending_exception(), "must only be called if there's an exception pending");
 719   // nothing to do - eventually we should remove this code entirely (see comments @ call sites)
 720 JRT_END
 721 
 722 
 723 JRT_ENTRY_PROF(void, InterpreterRuntime, throw_AbstractMethodError, InterpreterRuntime::throw_AbstractMethodError(JavaThread* current))
 724   THROW(vmSymbols::java_lang_AbstractMethodError());
 725 JRT_END
 726 
 727 // This method is called from the "abstract_entry" of the interpreter.
 728 // At that point, the arguments have already been removed from the stack
 729 // and therefore we don't have the receiver object at our fingertips. (Though,
 730 // on some platforms the receiver still resides in a register...). Thus,
 731 // we have no choice but print an error message not containing the receiver
 732 // type.
 733 JRT_ENTRY_PROF(void, InterpreterRuntime, throw_AbstractMethodErrorWithMethod,
 734            InterpreterRuntime::throw_AbstractMethodErrorWithMethod(JavaThread* current,
 735                                                                    Method* missingMethod))
 736   ResourceMark rm(current);
 737   assert(missingMethod != nullptr, "sanity");
 738   methodHandle m(current, missingMethod);
 739   LinkResolver::throw_abstract_method_error(m, THREAD);
 740 JRT_END
 741 
 742 JRT_ENTRY_PROF(void, InterpreterRuntime, throw_AbstractMethodErrorVerbose,
 743           InterpreterRuntime::throw_AbstractMethodErrorVerbose(JavaThread* current,
 744                                                                Klass* recvKlass,
 745                                                                Method* missingMethod))
 746   ResourceMark rm(current);
 747   methodHandle mh = methodHandle(current, missingMethod);
 748   LinkResolver::throw_abstract_method_error(mh, recvKlass, THREAD);
 749 JRT_END
 750 
 751 
 752 JRT_ENTRY_PROF(void, InterpreterRuntime, throw_IncompatibleClassChangeError,
 753            InterpreterRuntime::throw_IncompatibleClassChangeError(JavaThread* current))
 754   THROW(vmSymbols::java_lang_IncompatibleClassChangeError());
 755 JRT_END
 756 
 757 JRT_ENTRY_PROF(void, InterpreterRuntime, throw_IncompatibleClassChangeErrorVerbose,
 758            InterpreterRuntime::throw_IncompatibleClassChangeErrorVerbose(JavaThread* current,
 759                                                                          Klass* recvKlass,
 760                                                                          Klass* interfaceKlass))
 761   ResourceMark rm(current);
 762   char buf[1000];
 763   buf[0] = '\0';
 764   jio_snprintf(buf, sizeof(buf),
 765                "Class %s does not implement the requested interface %s",
 766                recvKlass ? recvKlass->external_name() : "nullptr",
 767                interfaceKlass ? interfaceKlass->external_name() : "nullptr");
 768   THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
 769 JRT_END
 770 
 771 JRT_ENTRY_PROF(void, InterpreterRuntime, throw_NullPointerException,
 772            InterpreterRuntime::throw_NullPointerException(JavaThread* current))
 773   THROW(vmSymbols::java_lang_NullPointerException());
 774 JRT_END
 775 
 776 //------------------------------------------------------------------------------------------------------------------------
 777 // Fields
 778 //
 779 
 780 PROF_ENTRY(void, InterpreterRuntime, resolve_getfield, InterpreterRuntime::resolve_getfield(JavaThread* current))
 781   resolve_get_put(current, Bytecodes::_getfield);
 782 PROF_END
 783 
 784 PROF_ENTRY(void, InterpreterRuntime, resolve_putfield, InterpreterRuntime::resolve_putfield(JavaThread* current))
 785   resolve_get_put(current, Bytecodes::_putfield);
 786 PROF_END
 787 
 788 PROF_ENTRY(void, InterpreterRuntime, resolve_getstatic, InterpreterRuntime::resolve_getstatic(JavaThread* current))
 789   resolve_get_put(current, Bytecodes::_getstatic);
 790 PROF_END
 791 
 792 PROF_ENTRY(void, InterpreterRuntime, resolve_putstatic, InterpreterRuntime::resolve_putstatic(JavaThread* current))
 793   resolve_get_put(current, Bytecodes::_putstatic);
 794 PROF_END
 795 
 796 void InterpreterRuntime::resolve_get_put(JavaThread* current, Bytecodes::Code bytecode) {
 797   LastFrameAccessor last_frame(current);
 798   constantPoolHandle pool(current, last_frame.method()->constants());
 799   methodHandle m(current, last_frame.method());
 800 
 801   resolve_get_put(bytecode, last_frame.get_index_u2(bytecode), m, pool, true /*initialize_holder*/, current);
 802 }
 803 
 804 void InterpreterRuntime::resolve_get_put(Bytecodes::Code bytecode, int field_index,
 805                                          methodHandle& m,
 806                                          constantPoolHandle& pool,
 807                                          bool initialize_holder, TRAPS) {
 808   fieldDescriptor info;
 809   bool is_put    = (bytecode == Bytecodes::_putfield  || bytecode == Bytecodes::_nofast_putfield ||
 810                     bytecode == Bytecodes::_putstatic);
 811   bool is_static = (bytecode == Bytecodes::_getstatic || bytecode == Bytecodes::_putstatic);
 812 
 813   {
 814     JvmtiHideSingleStepping jhss(THREAD);
 815     LinkResolver::resolve_field_access(info, pool, field_index,

 833   // an IllegalAccessError if the instruction is not in an instance
 834   // initializer method <init>. If resolution were not inhibited, a putfield
 835   // in an initializer method could be resolved in the initializer. Subsequent
 836   // putfield instructions to the same field would then use cached information.
 837   // As a result, those instructions would not pass through the VM. That is,
 838   // checks in resolve_field_access() would not be executed for those instructions
 839   // and the required IllegalAccessError would not be thrown.
 840   //
 841   // Also, we need to delay resolving getstatic and putstatic instructions until the
 842   // class is initialized.  This is required so that access to the static
 843   // field will call the initialization function every time until the class
 844   // is completely initialized ala. in 2.17.5 in JVM Specification.
 845   InstanceKlass* klass = info.field_holder();
 846   bool uninitialized_static = is_static && !klass->is_initialized();
 847   bool has_initialized_final_update = info.field_holder()->major_version() >= 53 &&
 848                                       info.has_initialized_final_update();
 849   assert(!(has_initialized_final_update && !info.access_flags().is_final()), "Fields with initialized final updates must be final");
 850 
 851   Bytecodes::Code get_code = (Bytecodes::Code)0;
 852   Bytecodes::Code put_code = (Bytecodes::Code)0;
 853   if (!uninitialized_static || VM_Version::supports_fast_class_init_checks()) {
 854 #if !defined(X86) && !defined(AARCH64)
 855     guarantee(!uninitialized_static, "fast class init checks missing in interpreter"); // FIXME
 856 #endif // !X86 && !AARCH64
 857     get_code = ((is_static) ? Bytecodes::_getstatic : Bytecodes::_getfield);
 858     if ((is_put && !has_initialized_final_update) || !info.access_flags().is_final()) {
 859       put_code = ((is_static) ? Bytecodes::_putstatic : Bytecodes::_putfield);
 860     }
 861   }
 862 
 863   ResolvedFieldEntry* entry = pool->resolved_field_entry_at(field_index);
 864   entry->set_flags(info.access_flags().is_final(), info.access_flags().is_volatile());
 865   entry->fill_in(info.field_holder(), info.offset(),
 866                  checked_cast<u2>(info.index()), checked_cast<u1>(state),
 867                  static_cast<u1>(get_code), static_cast<u1>(put_code));
 868 }
 869 
 870 
 871 //------------------------------------------------------------------------------------------------------------------------
 872 // Synchronization
 873 //
 874 // The interpreter's synchronization code is factored out so that it can
 875 // be shared by method invocation and synchronized blocks.
 876 //%note synchronization_3
 877 
 878 //%note monitor_1
 879 JRT_ENTRY_NO_ASYNC_PROF(void, InterpreterRuntime, monitorenter, InterpreterRuntime::monitorenter(JavaThread* current, BasicObjectLock* elem))
 880 #ifdef ASSERT
 881   current->last_frame().interpreter_frame_verify_monitor(elem);
 882 #endif
 883   Handle h_obj(current, elem->obj());
 884   assert(Universe::heap()->is_in_or_null(h_obj()),
 885          "must be null or an object");
 886   ObjectSynchronizer::enter(h_obj, elem->lock(), current);
 887   assert(Universe::heap()->is_in_or_null(elem->obj()),
 888          "must be null or an object");
 889 #ifdef ASSERT
 890   if (!current->preempting()) current->last_frame().interpreter_frame_verify_monitor(elem);
 891 #endif
 892 JRT_END
 893 
 894 JRT_LEAF_PROF_NO_THREAD(void, InterpreterRuntime, monitorexit, InterpreterRuntime::monitorexit(BasicObjectLock* elem))
 895   oop obj = elem->obj();
 896   assert(Universe::heap()->is_in(obj), "must be an object");
 897   // The object could become unlocked through a JNI call, which we have no other checks for.
 898   // Give a fatal message if CheckJNICalls. Otherwise we ignore it.
 899   if (obj->is_unlocked()) {
 900     if (CheckJNICalls) {
 901       fatal("Object has been unlocked by JNI");
 902     }
 903     return;
 904   }
 905   ObjectSynchronizer::exit(obj, elem->lock(), JavaThread::current());
 906   // Free entry. If it is not cleared, the exception handling code will try to unlock the monitor
 907   // again at method exit or in the case of an exception.
 908   elem->set_obj(nullptr);
 909 JRT_END
 910 
 911 
 912 JRT_ENTRY_PROF(void, InterpreterRuntime, throw_illegal_monitor_state_exception,
 913            InterpreterRuntime::throw_illegal_monitor_state_exception(JavaThread* current))
 914   THROW(vmSymbols::java_lang_IllegalMonitorStateException());
 915 JRT_END
 916 
 917 
 918 JRT_ENTRY_PROF(void, InterpreterRuntime, new_illegal_monitor_state_exception,
 919            InterpreterRuntime::new_illegal_monitor_state_exception(JavaThread* current))
 920   // Returns an illegal exception to install into the current thread. The
 921   // pending_exception flag is cleared so normal exception handling does not
 922   // trigger. Any current installed exception will be overwritten. This
 923   // method will be called during an exception unwind.
 924 
 925   assert(!HAS_PENDING_EXCEPTION, "no pending exception");
 926   Handle exception(current, current->vm_result_oop());
 927   assert(exception() != nullptr, "vm result should be set");
 928   current->set_vm_result_oop(nullptr); // clear vm result before continuing (may cause memory leaks and assert failures)
 929   exception = get_preinitialized_exception(vmClasses::IllegalMonitorStateException_klass(), CATCH);
 930   current->set_vm_result_oop(exception());
 931 JRT_END
 932 
 933 
 934 //------------------------------------------------------------------------------------------------------------------------
 935 // Invokes
 936 
 937 JRT_ENTRY_PROF(Bytecodes::Code, InterpreterRuntime, get_original_bytecode_at, InterpreterRuntime::get_original_bytecode_at(JavaThread* current, Method* method, address bcp))
 938   return method->orig_bytecode_at(method->bci_from(bcp));
 939 JRT_END
 940 
 941 JRT_ENTRY_PROF(void, InterpreterRuntime, set_original_bytecode_at, InterpreterRuntime::set_original_bytecode_at(JavaThread* current, Method* method, address bcp, Bytecodes::Code new_code))
 942   method->set_orig_bytecode_at(method->bci_from(bcp), new_code);
 943 JRT_END
 944 
 945 JRT_ENTRY_PROF(void, InterpreterRuntime, breakpoint, InterpreterRuntime::_breakpoint(JavaThread* current, Method* method, address bcp))
 946   JvmtiExport::post_raw_breakpoint(current, method, bcp);
 947 JRT_END
 948 
 949 PROF_ENTRY(void, InterpreterRuntime, resolve_invokevirtual, InterpreterRuntime::resolve_invokevirtual(JavaThread* current))
 950   resolve_invoke(current, Bytecodes::_invokevirtual);
 951 PROF_END
 952 
 953 PROF_ENTRY(void, InterpreterRuntime, resolve_invokespecial, InterpreterRuntime::resolve_invokespecial(JavaThread* current))
 954   resolve_invoke(current, Bytecodes::_invokespecial);
 955 PROF_END
 956 
 957 PROF_ENTRY(void, InterpreterRuntime, resolve_invokestatic, InterpreterRuntime::resolve_invokestatic(JavaThread* current))
 958   resolve_invoke(current, Bytecodes::_invokestatic);
 959 PROF_END
 960 
 961 PROF_ENTRY(void, InterpreterRuntime, resolve_invokeinterface, InterpreterRuntime::resolve_invokeinterface(JavaThread* current))
 962   resolve_invoke(current, Bytecodes::_invokeinterface);
 963 PROF_END
 964 
 965 void InterpreterRuntime::resolve_invoke(JavaThread* current, Bytecodes::Code bytecode) {
 966   LastFrameAccessor last_frame(current);
 967   // extract receiver from the outgoing argument list if necessary
 968   Handle receiver(current, nullptr);
 969   if (bytecode == Bytecodes::_invokevirtual || bytecode == Bytecodes::_invokeinterface ||
 970       bytecode == Bytecodes::_invokespecial) {
 971     ResourceMark rm(current);
 972     methodHandle m (current, last_frame.method());
 973     Bytecode_invoke call(m, last_frame.bci());
 974     Symbol* signature = call.signature();
 975     receiver = Handle(current, last_frame.callee_receiver(signature));
 976 
 977     assert(Universe::heap()->is_in_or_null(receiver()),
 978            "sanity check");
 979     assert(receiver.is_null() ||
 980            !Universe::heap()->is_in(receiver->klass()),
 981            "sanity check");
 982   }
 983 
 984   // resolve method

1063     cache->set_itable_call(
1064       bytecode,
1065       method_index,
1066       info.resolved_klass(),
1067       resolved_method,
1068       info.itable_index());
1069     break;
1070   default:  ShouldNotReachHere();
1071   }
1072 }
1073 
1074 void InterpreterRuntime::cds_resolve_invoke(Bytecodes::Code bytecode, int method_index,
1075                                             constantPoolHandle& pool, TRAPS) {
1076   LinkInfo link_info(pool, method_index, bytecode, CHECK);
1077 
1078   if (!link_info.resolved_klass()->is_instance_klass() || InstanceKlass::cast(link_info.resolved_klass())->is_linked()) {
1079     CallInfo call_info;
1080     switch (bytecode) {
1081       case Bytecodes::_invokevirtual:   LinkResolver::cds_resolve_virtual_call  (call_info, link_info, CHECK); break;
1082       case Bytecodes::_invokeinterface: LinkResolver::cds_resolve_interface_call(call_info, link_info, CHECK); break;
1083       case Bytecodes::_invokestatic:    LinkResolver::cds_resolve_static_call   (call_info, link_info, CHECK); break;
1084       case Bytecodes::_invokespecial:   LinkResolver::cds_resolve_special_call  (call_info, link_info, CHECK); break;
1085 
1086       default: fatal("Unimplemented: %s", Bytecodes::name(bytecode));
1087     }
1088     methodHandle resolved_method(THREAD, call_info.resolved_method());
1089     guarantee(resolved_method->method_holder()->is_linked(), "");
1090     update_invoke_cp_cache_entry(call_info, bytecode, resolved_method, pool, method_index);
1091   } else {
1092     // FIXME: why a shared class is not linked yet?
1093     // Can't link it here since there are no guarantees it'll be prelinked on the next run.
1094     ResourceMark rm;
1095     InstanceKlass* resolved_iklass = InstanceKlass::cast(link_info.resolved_klass());
1096     log_info(aot, resolve)("Not resolved: class not linked: %s %s %s",
1097                            resolved_iklass->in_aot_cache() ? "in_aot_cache" : "",
1098                            resolved_iklass->init_state_name(),
1099                            resolved_iklass->external_name());
1100   }
1101 }
1102 
1103 // First time execution:  Resolve symbols, create a permanent MethodType object.
1104 PROF_ENTRY(void, InterpreterRuntime, resolve_invokehandle, InterpreterRuntime::resolve_invokehandle(JavaThread* current))
1105   const Bytecodes::Code bytecode = Bytecodes::_invokehandle;
1106   LastFrameAccessor last_frame(current);
1107 
1108   // resolve method
1109   CallInfo info;
1110   constantPoolHandle pool(current, last_frame.method()->constants());
1111   int method_index = last_frame.get_index_u2(bytecode);
1112   {
1113     JvmtiHideSingleStepping jhss(current);
1114     JavaThread* THREAD = current; // For exception macros.
1115     LinkResolver::resolve_invoke(info, Handle(), pool,
1116                                  method_index, bytecode,
1117                                  CHECK);
1118   } // end JvmtiHideSingleStepping
1119 
1120   pool->cache()->set_method_handle(method_index, info);
1121 PROF_END
1122 
1123 void InterpreterRuntime::cds_resolve_invokehandle(int raw_index,
1124                                                   constantPoolHandle& pool, TRAPS) {
1125   const Bytecodes::Code bytecode = Bytecodes::_invokehandle;
1126   CallInfo info;
1127   LinkResolver::resolve_invoke(info, Handle(), pool, raw_index, bytecode, CHECK);
1128 
1129   pool->cache()->set_method_handle(raw_index, info);
1130 }
1131 
1132 // First time execution:  Resolve symbols, create a permanent CallSite object.
1133 PROF_ENTRY(void, InterpreterRuntime, resolve_invokedynamic, InterpreterRuntime::resolve_invokedynamic(JavaThread* current))
1134   LastFrameAccessor last_frame(current);
1135   const Bytecodes::Code bytecode = Bytecodes::_invokedynamic;
1136 
1137   // resolve method
1138   CallInfo info;
1139   constantPoolHandle pool(current, last_frame.method()->constants());
1140   int index = last_frame.get_index_u4(bytecode);
1141   {
1142     JvmtiHideSingleStepping jhss(current);
1143     JavaThread* THREAD = current; // For exception macros.
1144     LinkResolver::resolve_invoke(info, Handle(), pool,
1145                                  index, bytecode, CHECK);
1146   } // end JvmtiHideSingleStepping
1147 
1148   pool->cache()->set_dynamic_call(info, index);
1149 PROF_END
1150 
1151 void InterpreterRuntime::cds_resolve_invokedynamic(int raw_index,
1152                                                    constantPoolHandle& pool, TRAPS) {
1153   const Bytecodes::Code bytecode = Bytecodes::_invokedynamic;
1154   CallInfo info;
1155   LinkResolver::resolve_invoke(info, Handle(), pool, raw_index, bytecode, CHECK);
1156   pool->cache()->set_dynamic_call(info, raw_index);
1157 }
1158 
1159 // This function is the interface to the assembly code. It returns the resolved
1160 // cpCache entry.  This doesn't safepoint, but the helper routines safepoint.
1161 // This function will check for redefinition!
1162 JRT_ENTRY(void, InterpreterRuntime::resolve_from_cache(JavaThread* current, Bytecodes::Code bytecode)) {
1163   trace_current_location(current);
1164 
1165   switch (bytecode) {
1166   case Bytecodes::_getstatic: resolve_getstatic(current); break;
1167   case Bytecodes::_putstatic: resolve_putstatic(current); break;
1168   case Bytecodes::_getfield:  resolve_getfield(current);  break;
1169   case Bytecodes::_putfield:  resolve_putfield(current);  break;
1170 
1171   case Bytecodes::_invokevirtual:   resolve_invokevirtual(current);   break;
1172   case Bytecodes::_invokespecial:   resolve_invokespecial(current);   break;
1173   case Bytecodes::_invokestatic:    resolve_invokestatic(current);    break;
1174   case Bytecodes::_invokeinterface: resolve_invokeinterface(current); break;
1175   case Bytecodes::_invokehandle:    resolve_invokehandle(current);    break;
1176   case Bytecodes::_invokedynamic:   resolve_invokedynamic(current);   break;
1177 






1178   default:
1179     fatal("unexpected bytecode: %s", Bytecodes::name(bytecode));
1180     break;
1181   }
1182 }
1183 JRT_END
1184 
1185 //------------------------------------------------------------------------------------------------------------------------
1186 // Miscellaneous
1187 
1188 
1189 nmethod* InterpreterRuntime::frequency_counter_overflow(JavaThread* current, address branch_bcp) {
1190   assert(!PreloadOnly, "Should not be using interpreter counters");
1191 
1192   // Enable WXWrite: the function is called directly by interpreter.
1193   MACOS_AARCH64_ONLY(ThreadWXEnable wx(WXWrite, current));
1194 
1195   // frequency_counter_overflow_inner can throw async exception.
1196   nmethod* nm = frequency_counter_overflow_inner(current, branch_bcp);
1197   assert(branch_bcp != nullptr || nm == nullptr, "always returns null for non OSR requests");
1198   if (branch_bcp != nullptr && nm != nullptr) {
1199     // This was a successful request for an OSR nmethod.  Because
1200     // frequency_counter_overflow_inner ends with a safepoint check,
1201     // nm could have been unloaded so look it up again.  It's unsafe
1202     // to examine nm directly since it might have been freed and used
1203     // for something else.
1204     LastFrameAccessor last_frame(current);
1205     Method* method =  last_frame.method();
1206     int bci = method->bci_from(last_frame.bcp());
1207     nm = method->lookup_osr_nmethod_for(bci, CompLevel_none, false);
1208     BarrierSetNMethod* bs_nm = BarrierSet::barrier_set()->barrier_set_nmethod();
1209     if (nm != nullptr) {
1210       // in case the transition passed a safepoint we need to barrier this again
1211       if (!bs_nm->nmethod_osr_entry_barrier(nm)) {

1215   }
1216   if (nm != nullptr && current->is_interp_only_mode()) {
1217     // Normally we never get an nm if is_interp_only_mode() is true, because
1218     // policy()->event has a check for this and won't compile the method when
1219     // true. However, it's possible for is_interp_only_mode() to become true
1220     // during the compilation. We don't want to return the nm in that case
1221     // because we want to continue to execute interpreted.
1222     nm = nullptr;
1223   }
1224 #ifndef PRODUCT
1225   if (TraceOnStackReplacement) {
1226     if (nm != nullptr) {
1227       tty->print("OSR entry @ pc: " INTPTR_FORMAT ": ", p2i(nm->osr_entry()));
1228       nm->print();
1229     }
1230   }
1231 #endif
1232   return nm;
1233 }
1234 
1235 JRT_ENTRY_PROF(nmethod*, InterpreterRuntime, frequency_counter_overflow,
1236           InterpreterRuntime::frequency_counter_overflow_inner(JavaThread* current, address branch_bcp))
1237   // use UnlockFlagSaver to clear and restore the _do_not_unlock_if_synchronized
1238   // flag, in case this method triggers classloading which will call into Java.
1239   UnlockFlagSaver fs(current);
1240 
1241   LastFrameAccessor last_frame(current);
1242   assert(last_frame.is_interpreted_frame(), "must come from interpreter");
1243   methodHandle method(current, last_frame.method());
1244   const int branch_bci = branch_bcp != nullptr ? method->bci_from(branch_bcp) : InvocationEntryBci;
1245   const int bci = branch_bcp != nullptr ? method->bci_from(last_frame.bcp()) : InvocationEntryBci;
1246 
1247   nmethod* osr_nm = CompilationPolicy::event(method, method, branch_bci, bci, CompLevel_none, nullptr, CHECK_NULL);
1248 
1249   BarrierSetNMethod* bs_nm = BarrierSet::barrier_set()->barrier_set_nmethod();
1250   if (osr_nm != nullptr) {
1251     if (!bs_nm->nmethod_osr_entry_barrier(osr_nm)) {
1252       osr_nm = nullptr;
1253     }
1254   }
1255   return osr_nm;
1256 JRT_END
1257 
1258 JRT_LEAF_PROF_NO_THREAD(jint, InterpreterRuntime, bcp_to_di, InterpreterRuntime::bcp_to_di(Method* method, address cur_bcp))
1259   assert(ProfileInterpreter, "must be profiling interpreter");
1260   int bci = method->bci_from(cur_bcp);
1261   MethodData* mdo = method->method_data();
1262   if (mdo == nullptr)  return 0;
1263   return mdo->bci_to_di(bci);
1264 JRT_END
1265 
1266 #ifdef ASSERT
1267 JRT_LEAF(void, InterpreterRuntime::verify_mdp(Method* method, address bcp, address mdp))
1268   assert(ProfileInterpreter, "must be profiling interpreter");
1269 
1270   MethodData* mdo = method->method_data();
1271   assert(mdo != nullptr, "must not be null");
1272 
1273   int bci = method->bci_from(bcp);
1274 
1275   address mdp2 = mdo->bci_to_dp(bci);
1276   if (mdp != mdp2) {
1277     ResourceMark rm;
1278     tty->print_cr("FAILED verify : actual mdp %p   expected mdp %p @ bci %d", mdp, mdp2, bci);
1279     int current_di = mdo->dp_to_di(mdp);
1280     int expected_di  = mdo->dp_to_di(mdp2);
1281     tty->print_cr("  actual di %d   expected di %d", current_di, expected_di);
1282     int expected_approx_bci = mdo->data_at(expected_di)->bci();
1283     int approx_bci = -1;
1284     if (current_di >= 0) {
1285       approx_bci = mdo->data_at(current_di)->bci();
1286     }
1287     tty->print_cr("  actual bci is %d  expected bci %d", approx_bci, expected_approx_bci);
1288     mdo->print_on(tty);
1289     method->print_codes();
1290   }
1291   assert(mdp == mdp2, "wrong mdp");
1292 JRT_END
1293 #endif // ASSERT
1294 
1295 JRT_ENTRY_PROF(void, InterpreterRuntime, update_mdp_for_ret, InterpreterRuntime::update_mdp_for_ret(JavaThread* current, int return_bci))
1296   assert(!PreloadOnly, "Should not be using interpreter counters");
1297   assert(ProfileInterpreter, "must be profiling interpreter");
1298   ResourceMark rm(current);
1299   LastFrameAccessor last_frame(current);
1300   assert(last_frame.is_interpreted_frame(), "must come from interpreter");
1301   MethodData* h_mdo = last_frame.method()->method_data();
1302 
1303   // Grab a lock to ensure atomic access to setting the return bci and
1304   // the displacement.  This can block and GC, invalidating all naked oops.
1305   MutexLocker ml(RetData_lock);
1306 
1307   // ProfileData is essentially a wrapper around a derived oop, so we
1308   // need to take the lock before making any ProfileData structures.
1309   ProfileData* data = h_mdo->data_at(h_mdo->dp_to_di(last_frame.mdp()));
1310   guarantee(data != nullptr, "profile data must be valid");
1311   RetData* rdata = data->as_RetData();
1312   address new_mdp = rdata->fixup_ret(return_bci, h_mdo);
1313   last_frame.set_mdp(new_mdp);
1314 JRT_END
1315 
1316 JRT_ENTRY_PROF(MethodCounters*, InterpreterRuntime, build_method_counters, InterpreterRuntime::build_method_counters(JavaThread* current, Method* m))
1317   return Method::build_method_counters(current, m);
1318 JRT_END
1319 
1320 
1321 JRT_ENTRY_PROF(void, InterpreterRuntime, at_safepoint, InterpreterRuntime::at_safepoint(JavaThread* current))
1322   // We used to need an explicit preserve_arguments here for invoke bytecodes. However,
1323   // stack traversal automatically takes care of preserving arguments for invoke, so
1324   // this is no longer needed.
1325 
1326   // JRT_END does an implicit safepoint check, hence we are guaranteed to block
1327   // if this is called during a safepoint
1328 
1329   if (JvmtiExport::should_post_single_step()) {
1330     // This function is called by the interpreter when single stepping. Such single
1331     // stepping could unwind a frame. Then, it is important that we process any frames
1332     // that we might return into.
1333     StackWatermarkSet::before_unwind(current);
1334 
1335     // We are called during regular safepoints and when the VM is
1336     // single stepping. If any thread is marked for single stepping,
1337     // then we may have JVMTI work to do.
1338     LastFrameAccessor last_frame(current);
1339     JvmtiExport::at_single_stepping_point(current, last_frame.method(), last_frame.bcp());
1340   }
1341 JRT_END
1342 
1343 JRT_LEAF_PROF(void, InterpreterRuntime, at_unwind, InterpreterRuntime::at_unwind(JavaThread* current))
1344   assert(current == JavaThread::current(), "pre-condition");
1345   JFR_ONLY(Jfr::check_and_process_sample_request(current);)
1346   // This function is called by the interpreter when the return poll found a reason
1347   // to call the VM. The reason could be that we are returning into a not yet safe
1348   // to access frame. We handle that below.
1349   // Note that this path does not check for single stepping, because we do not want
1350   // to single step when unwinding frames for an exception being thrown. Instead,
1351   // such single stepping code will use the safepoint table, which will use the
1352   // InterpreterRuntime::at_safepoint callback.
1353   StackWatermarkSet::before_unwind(current);
1354 JRT_END
1355 
1356 JRT_ENTRY_PROF(void, InterpreterRuntime, post_field_access, InterpreterRuntime::post_field_access(JavaThread* current, oopDesc* obj,
1357                                                                                ResolvedFieldEntry *entry))
1358 
1359   // check the access_flags for the field in the klass
1360 
1361   InstanceKlass* ik = entry->field_holder();
1362   int index = entry->field_index();
1363   if (!ik->field_status(index).is_access_watched()) return;
1364 
1365   bool is_static = (obj == nullptr);
1366   HandleMark hm(current);
1367 
1368   Handle h_obj;
1369   if (!is_static) {
1370     // non-static field accessors have an object, but we need a handle
1371     h_obj = Handle(current, obj);
1372   }
1373   InstanceKlass* field_holder = entry->field_holder(); // HERE
1374   jfieldID fid = jfieldIDWorkaround::to_jfieldID(field_holder, entry->field_offset(), is_static);
1375   LastFrameAccessor last_frame(current);
1376   JvmtiExport::post_field_access(current, last_frame.method(), last_frame.bcp(), field_holder, h_obj, fid);
1377 JRT_END
1378 
1379 JRT_ENTRY_PROF(void, InterpreterRuntime, post_field_modification, InterpreterRuntime::post_field_modification(JavaThread* current, oopDesc* obj,
1380                                                                                            ResolvedFieldEntry *entry, jvalue *value))
1381 
1382   InstanceKlass* ik = entry->field_holder();
1383 
1384   // check the access_flags for the field in the klass
1385   int index = entry->field_index();
1386   // bail out if field modifications are not watched
1387   if (!ik->field_status(index).is_modification_watched()) return;
1388 
1389   char sig_type = '\0';
1390 
1391   switch((TosState)entry->tos_state()) {
1392     case btos: sig_type = JVM_SIGNATURE_BYTE;    break;
1393     case ztos: sig_type = JVM_SIGNATURE_BOOLEAN; break;
1394     case ctos: sig_type = JVM_SIGNATURE_CHAR;    break;
1395     case stos: sig_type = JVM_SIGNATURE_SHORT;   break;
1396     case itos: sig_type = JVM_SIGNATURE_INT;     break;
1397     case ftos: sig_type = JVM_SIGNATURE_FLOAT;   break;
1398     case atos: sig_type = JVM_SIGNATURE_CLASS;   break;
1399     case ltos: sig_type = JVM_SIGNATURE_LONG;    break;
1400     case dtos: sig_type = JVM_SIGNATURE_DOUBLE;  break;

1415   // We assume that the two halves of longs/doubles are stored in interpreter
1416   // stack slots in platform-endian order.
1417   jlong_accessor u;
1418   jint* newval = (jint*)value;
1419   u.words[0] = newval[0];
1420   u.words[1] = newval[Interpreter::stackElementWords]; // skip if tag
1421   fvalue.j = u.long_value;
1422 #endif // _LP64
1423 
1424   Handle h_obj;
1425   if (!is_static) {
1426     // non-static field accessors have an object, but we need a handle
1427     h_obj = Handle(current, obj);
1428   }
1429 
1430   LastFrameAccessor last_frame(current);
1431   JvmtiExport::post_raw_field_modification(current, last_frame.method(), last_frame.bcp(), ik, h_obj,
1432                                            fid, sig_type, &fvalue);
1433 JRT_END
1434 
1435 JRT_ENTRY_PROF(void, InterpreterRuntime, post_method_entry, InterpreterRuntime::post_method_entry(JavaThread* current))
1436   LastFrameAccessor last_frame(current);
1437   JvmtiExport::post_method_entry(current, last_frame.method(), last_frame.get_frame());
1438 JRT_END
1439 
1440 
1441 // This is a JRT_BLOCK_ENTRY because we have to stash away the return oop
1442 // before transitioning to VM, and restore it after transitioning back
1443 // to Java. The return oop at the top-of-stack, is not walked by the GC.
1444 JRT_BLOCK_ENTRY_PROF(void, InterpreterRuntime, post_method_exit, InterpreterRuntime::post_method_exit(JavaThread* current))
1445   LastFrameAccessor last_frame(current);
1446   JvmtiExport::post_method_exit(current, last_frame.method(), last_frame.get_frame());
1447 JRT_END
1448 
1449 JRT_LEAF_PROF_NO_THREAD(int, InterpreterRuntime, interpreter_contains, InterpreterRuntime::interpreter_contains(address pc))
1450 {
1451   return (Interpreter::contains(Continuation::get_top_return_pc_post_barrier(JavaThread::current(), pc)) ? 1 : 0);
1452 }
1453 JRT_END
1454 
1455 
1456 // Implementation of SignatureHandlerLibrary
1457 
1458 #ifndef SHARING_FAST_NATIVE_FINGERPRINTS
1459 // Dummy definition (else normalization method is defined in CPU
1460 // dependent code)
1461 uint64_t InterpreterRuntime::normalize_fast_native_fingerprint(uint64_t fingerprint) {
1462   return fingerprint;
1463 }
1464 #endif
1465 
1466 address SignatureHandlerLibrary::set_handler_blob() {
1467   BufferBlob* handler_blob = BufferBlob::create("native signature handlers", blob_size);
1468   if (handler_blob == nullptr) {
1469     return nullptr;

1595     MutexLocker mu(SignatureHandlerLibrary_lock);
1596     if (_handlers != nullptr) {
1597       handler_index = _handlers->find(method->signature_handler());
1598       uint64_t fingerprint = Fingerprinter(method).fingerprint();
1599       fingerprint = InterpreterRuntime::normalize_fast_native_fingerprint(fingerprint);
1600       fingerprint_index = _fingerprints->find(fingerprint);
1601     }
1602   }
1603   assert(method->signature_handler() == Interpreter::slow_signature_handler() ||
1604          handler_index == fingerprint_index, "sanity check");
1605 #endif // ASSERT
1606 }
1607 
1608 BufferBlob*              SignatureHandlerLibrary::_handler_blob = nullptr;
1609 address                  SignatureHandlerLibrary::_handler      = nullptr;
1610 GrowableArray<uint64_t>* SignatureHandlerLibrary::_fingerprints = nullptr;
1611 GrowableArray<address>*  SignatureHandlerLibrary::_handlers     = nullptr;
1612 address                  SignatureHandlerLibrary::_buffer       = nullptr;
1613 
1614 
1615 JRT_ENTRY_PROF(void, InterpreterRuntime, prepare_native_call, InterpreterRuntime::prepare_native_call(JavaThread* current, Method* method))
1616   methodHandle m(current, method);
1617   assert(m->is_native(), "sanity check");
1618   // lookup native function entry point if it doesn't exist
1619   if (!m->has_native_function()) {
1620     NativeLookup::lookup(m, CHECK);
1621   }
1622   // make sure signature handler is installed
1623   SignatureHandlerLibrary::add(m);
1624   // The interpreter entry point checks the signature handler first,
1625   // before trying to fetch the native entry point and klass mirror.
1626   // We must set the signature handler last, so that multiple processors
1627   // preparing the same method will be sure to see non-null entry & mirror.
1628 JRT_END
1629 
1630 #if defined(IA32) || defined(AMD64) || defined(ARM)
1631 JRT_LEAF(void, InterpreterRuntime::popframe_move_outgoing_args(JavaThread* current, void* src_address, void* dest_address))
1632   assert(current == JavaThread::current(), "pre-condition");
1633   if (src_address == dest_address) {
1634     return;
1635   }
1636   ResourceMark rm;
1637   LastFrameAccessor last_frame(current);
1638   assert(last_frame.is_interpreted_frame(), "");
1639   jint bci = last_frame.bci();
1640   methodHandle mh(current, last_frame.method());
1641   Bytecode_invoke invoke(mh, bci);
1642   ArgumentSizeComputer asc(invoke.signature());
1643   int size_of_arguments = (asc.size() + (invoke.has_receiver() ? 1 : 0)); // receiver
1644   Copy::conjoint_jbytes(src_address, dest_address,
1645                        size_of_arguments * Interpreter::stackElementSize);
1646 JRT_END
1647 #endif
1648 
1649 #if INCLUDE_JVMTI
1650 // This is a support of the JVMTI PopFrame interface.
1651 // Make sure it is an invokestatic of a polymorphic intrinsic that has a member_name argument
1652 // and return it as a vm_result_oop so that it can be reloaded in the list of invokestatic parameters.
1653 // The member_name argument is a saved reference (in local#0) to the member_name.
1654 // For backward compatibility with some JDK versions (7, 8) it can also be a direct method handle.
1655 // FIXME: remove DMH case after j.l.i.InvokerBytecodeGenerator code shape is updated.
1656 JRT_ENTRY_PROF(void, InterpreterRuntime, member_name_arg_or_null,
1657            InterpreterRuntime::member_name_arg_or_null(JavaThread* current, address member_name,
1658                                                        Method* method, address bcp))
1659   Bytecodes::Code code = Bytecodes::code_at(method, bcp);
1660   if (code != Bytecodes::_invokestatic) {
1661     return;
1662   }
1663   ConstantPool* cpool = method->constants();
1664   int cp_index = Bytes::get_native_u2(bcp + 1);
1665   Symbol* cname = cpool->klass_name_at(cpool->klass_ref_index_at(cp_index, code));
1666   Symbol* mname = cpool->name_ref_at(cp_index, code);
1667 
1668   if (MethodHandles::has_member_arg(cname, mname)) {
1669     oop member_name_oop = cast_to_oop(member_name);
1670     if (java_lang_invoke_DirectMethodHandle::is_instance(member_name_oop)) {
1671       // FIXME: remove after j.l.i.InvokerBytecodeGenerator code shape is updated.
1672       member_name_oop = java_lang_invoke_DirectMethodHandle::member(member_name_oop);
1673     }
1674     current->set_vm_result_oop(member_name_oop);
1675   } else {
1676     current->set_vm_result_oop(nullptr);
1677   }
1678 JRT_END
1679 #endif // INCLUDE_JVMTI
1680 
1681 #ifndef PRODUCT
1682 // This must be a JRT_LEAF function because the interpreter must save registers on x86 to
1683 // call this, which changes rsp and makes the interpreter's expression stack not walkable.
1684 // The generated code still uses call_VM because that will set up the frame pointer for
1685 // bcp and method.
1686 JRT_LEAF(intptr_t, InterpreterRuntime::trace_bytecode(JavaThread* current, intptr_t preserve_this_value, intptr_t tos, intptr_t tos2))
1687   assert(current == JavaThread::current(), "pre-condition");
1688   LastFrameAccessor last_frame(current);
1689   assert(last_frame.is_interpreted_frame(), "must be an interpreted frame");
1690   methodHandle mh(current, last_frame.method());
1691   BytecodeTracer::trace_interpreter(mh, last_frame.bcp(), tos, tos2);
1692   return preserve_this_value;
1693 JRT_END
1694 #endif // !PRODUCT
1695 
1696 #define DO_COUNTERS(macro) \
1697   macro(InterpreterRuntime, ldc) \
1698   macro(InterpreterRuntime, resolve_ldc) \
1699   macro(InterpreterRuntime, new) \
1700   macro(InterpreterRuntime, newarray) \
1701   macro(InterpreterRuntime, anewarray) \
1702   macro(InterpreterRuntime, multianewarray) \
1703   macro(InterpreterRuntime, register_finalizer) \
1704   macro(InterpreterRuntime, quicken_io_cc) \
1705   macro(InterpreterRuntime, throw_StackOverflowError) \
1706   macro(InterpreterRuntime, throw_delayed_StackOverflowError) \
1707   macro(InterpreterRuntime, create_exception) \
1708   macro(InterpreterRuntime, create_klass_exception) \
1709   macro(InterpreterRuntime, throw_ArrayIndexOutOfBoundsException) \
1710   macro(InterpreterRuntime, throw_ClassCastException) \
1711   macro(InterpreterRuntime, exception_handler_for_exception) \
1712   macro(InterpreterRuntime, throw_pending_exception) \
1713   macro(InterpreterRuntime, throw_AbstractMethodError) \
1714   macro(InterpreterRuntime, throw_AbstractMethodErrorWithMethod) \
1715   macro(InterpreterRuntime, throw_AbstractMethodErrorVerbose) \
1716   macro(InterpreterRuntime, throw_IncompatibleClassChangeError) \
1717   macro(InterpreterRuntime, throw_IncompatibleClassChangeErrorVerbose) \
1718   macro(InterpreterRuntime, throw_NullPointerException) \
1719   macro(InterpreterRuntime, monitorenter) \
1720   macro(InterpreterRuntime, monitorexit) \
1721   macro(InterpreterRuntime, throw_illegal_monitor_state_exception) \
1722   macro(InterpreterRuntime, new_illegal_monitor_state_exception) \
1723   macro(InterpreterRuntime, get_original_bytecode_at) \
1724   macro(InterpreterRuntime, set_original_bytecode_at) \
1725   macro(InterpreterRuntime, breakpoint) \
1726   macro(InterpreterRuntime, resolve_getfield) \
1727   macro(InterpreterRuntime, resolve_putfield) \
1728   macro(InterpreterRuntime, resolve_getstatic) \
1729   macro(InterpreterRuntime, resolve_putstatic) \
1730   macro(InterpreterRuntime, resolve_invokevirtual) \
1731   macro(InterpreterRuntime, resolve_invokespecial) \
1732   macro(InterpreterRuntime, resolve_invokestatic) \
1733   macro(InterpreterRuntime, resolve_invokeinterface) \
1734   macro(InterpreterRuntime, resolve_invokehandle) \
1735   macro(InterpreterRuntime, resolve_invokedynamic) \
1736   macro(InterpreterRuntime, frequency_counter_overflow) \
1737   macro(InterpreterRuntime, bcp_to_di) \
1738   macro(InterpreterRuntime, update_mdp_for_ret) \
1739   macro(InterpreterRuntime, build_method_counters) \
1740   macro(InterpreterRuntime, at_safepoint) \
1741   macro(InterpreterRuntime, at_unwind) \
1742   macro(InterpreterRuntime, post_field_access) \
1743   macro(InterpreterRuntime, post_field_modification) \
1744   macro(InterpreterRuntime, post_method_entry) \
1745   macro(InterpreterRuntime, post_method_exit) \
1746   macro(InterpreterRuntime, interpreter_contains) \
1747   macro(InterpreterRuntime, prepare_native_call)
1748 
1749 #if INCLUDE_JVMTI
1750 #define DO_JVMTI_COUNTERS(macro) \
1751   macro(InterpreterRuntime, member_name_arg_or_null)
1752 #else
1753 #define DO_JVMTI_COUNTERS(macro)
1754 #endif /* INCLUDE_JVMTI */
1755 
1756 #define INIT_COUNTER(sub, name) \
1757   NEWPERFTICKCOUNTERS(_perf_##sub##_##name##_timer, SUN_CI, #sub "::" #name); \
1758   NEWPERFEVENTCOUNTER(_perf_##sub##_##name##_count, SUN_CI, #sub "::" #name "_count");
1759 
1760 void InterpreterRuntime::init_counters() {
1761   if (UsePerfData) {
1762     EXCEPTION_MARK;
1763 
1764     DO_COUNTERS(INIT_COUNTER)
1765     DO_JVMTI_COUNTERS(INIT_COUNTER)
1766 
1767     if (HAS_PENDING_EXCEPTION) {
1768       vm_exit_during_initialization("jvm_perf_init failed unexpectedly");
1769     }
1770   }
1771 }
1772 #undef INIT_COUNTER
1773 
1774 #define PRINT_COUNTER(sub, name) { \
1775   jlong count = _perf_##sub##_##name##_count->get_value(); \
1776   if (count > 0) { \
1777     st->print_cr("  %-50s = " JLONG_FORMAT_W(6) "us (elapsed) " JLONG_FORMAT_W(6) "us (thread) (" JLONG_FORMAT_W(5) " events)", \
1778                  #sub "::" #name, \
1779                  _perf_##sub##_##name##_timer->elapsed_counter_value_us(), \
1780                  _perf_##sub##_##name##_timer->thread_counter_value_us(), \
1781                  count); \
1782   }}
1783 
1784 void InterpreterRuntime::print_counters_on(outputStream* st) {
1785   if (UsePerfData && ProfileRuntimeCalls) {
1786     DO_COUNTERS(PRINT_COUNTER)
1787     DO_JVMTI_COUNTERS(PRINT_COUNTER)
1788   } else {
1789     st->print_cr("  InterpreterRuntime: no info (%s is disabled)", (UsePerfData ? "ProfileRuntimeCalls" : "UsePerfData"));
1790   }
1791 }
1792 
1793 #undef PRINT_COUNTER
1794 #undef DO_JVMTI_COUNTERS
1795 #undef DO_COUNTERS
1796 
< prev index next >