< prev index next >

src/hotspot/share/interpreter/interpreterRuntime.cpp

Print this page

  50 #include "oops/method.inline.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

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

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

 614   ResourceMark rm(current);
 615   methodHandle mh = methodHandle(current, missingMethod);
 616   LinkResolver::throw_abstract_method_error(mh, recvKlass, THREAD);
 617 JRT_END
 618 
 619 
 620 JRT_ENTRY(void, InterpreterRuntime::throw_IncompatibleClassChangeError(JavaThread* current))

 621   THROW(vmSymbols::java_lang_IncompatibleClassChangeError());
 622 JRT_END
 623 
 624 JRT_ENTRY(void, InterpreterRuntime::throw_IncompatibleClassChangeErrorVerbose(JavaThread* current,
 625                                                                               Klass* recvKlass,
 626                                                                               Klass* interfaceKlass))

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

 638   THROW(vmSymbols::java_lang_NullPointerException());
 639 JRT_END
 640 
 641 //------------------------------------------------------------------------------------------------------------------------
 642 // Fields
 643 //
 644 
















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

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



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

 759   THROW(vmSymbols::java_lang_IllegalMonitorStateException());
 760 JRT_END
 761 
 762 
 763 JRT_ENTRY(void, InterpreterRuntime::new_illegal_monitor_state_exception(JavaThread* current))

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
















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

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

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


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


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

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

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

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

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

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







































































































  50 #include "oops/method.inline.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->is_shared()) {
 176       log.print(" shared");
 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

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

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

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






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

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

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

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