< prev index next >

src/hotspot/share/interpreter/interpreterRuntime.cpp

Print this page

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

  71 #include "runtime/sharedRuntime.hpp"
  72 #include "runtime/stackWatermarkSet.hpp"
  73 #include "runtime/stubRoutines.hpp"
  74 #include "runtime/synchronizer.hpp"
  75 #include "runtime/threadCritical.hpp"

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

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





















































































































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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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
















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

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



 705     get_code = ((is_static) ? Bytecodes::_getstatic : Bytecodes::_getfield);
 706     if ((is_put && !has_initialized_final_update) || !info.access_flags().is_final()) {
 707       put_code = ((is_static) ? Bytecodes::_putstatic : Bytecodes::_putfield);
 708     }
 709   }
 710 
 711   ResolvedFieldEntry* entry = pool->resolved_field_entry_at(field_index);
 712   entry->set_flags(info.access_flags().is_final(), info.access_flags().is_volatile());
 713   entry->fill_in(info.field_holder(), info.offset(),
 714                  checked_cast<u2>(info.index()), checked_cast<u1>(state),
 715                  static_cast<u1>(get_code), static_cast<u1>(put_code));
 716 }
 717 
 718 
 719 //------------------------------------------------------------------------------------------------------------------------
 720 // Synchronization
 721 //
 722 // The interpreter's synchronization code is factored out so that it can
 723 // be shared by method invocation and synchronized blocks.
 724 //%note synchronization_3
 725 
 726 //%note monitor_1
 727 JRT_ENTRY_NO_ASYNC(void, InterpreterRuntime::monitorenter(JavaThread* current, BasicObjectLock* elem))
 728   assert(LockingMode != LM_LIGHTWEIGHT, "Should call monitorenter_obj() when using the new lightweight locking");
 729 #ifdef ASSERT
 730   current->last_frame().interpreter_frame_verify_monitor(elem);
 731 #endif
 732   Handle h_obj(current, elem->obj());
 733   assert(Universe::heap()->is_in_or_null(h_obj()),
 734          "must be null or an object");
 735   ObjectSynchronizer::enter(h_obj, elem->lock(), current);
 736   assert(Universe::heap()->is_in_or_null(elem->obj()),
 737          "must be null or an object");
 738 #ifdef ASSERT
 739   current->last_frame().interpreter_frame_verify_monitor(elem);
 740 #endif
 741 JRT_END
 742 
 743 // NOTE: We provide a separate implementation for the new lightweight locking to workaround a limitation
 744 // of registers in x86_32. This entry point accepts an oop instead of a BasicObjectLock*.
 745 // The problem is that we would need to preserve the register that holds the BasicObjectLock,
 746 // but we are using that register to hold the thread. We don't have enough registers to
 747 // also keep the BasicObjectLock, but we don't really need it anyway, we only need
 748 // the object. See also InterpreterMacroAssembler::lock_object().
 749 // As soon as legacy stack-locking goes away we could remove the other monitorenter() entry
 750 // point, and only use oop-accepting entries (same for monitorexit() below).
 751 JRT_ENTRY_NO_ASYNC(void, InterpreterRuntime::monitorenter_obj(JavaThread* current, oopDesc* obj))
 752   assert(LockingMode == LM_LIGHTWEIGHT, "Should call monitorenter() when not using the new lightweight locking");
 753   Handle h_obj(current, cast_to_oop(obj));
 754   assert(Universe::heap()->is_in_or_null(h_obj()),
 755          "must be null or an object");
 756   ObjectSynchronizer::enter(h_obj, nullptr, current);
 757   return;
 758 JRT_END
 759 
 760 JRT_LEAF(void, InterpreterRuntime::monitorexit(BasicObjectLock* elem))
 761   oop obj = elem->obj();
 762   assert(Universe::heap()->is_in(obj), "must be an object");
 763   // The object could become unlocked through a JNI call, which we have no other checks for.
 764   // Give a fatal message if CheckJNICalls. Otherwise we ignore it.
 765   if (obj->is_unlocked()) {
 766     if (CheckJNICalls) {
 767       fatal("Object has been unlocked by JNI");
 768     }
 769     return;
 770   }
 771   ObjectSynchronizer::exit(obj, elem->lock(), JavaThread::current());
 772   // Free entry. If it is not cleared, the exception handling code will try to unlock the monitor
 773   // again at method exit or in the case of an exception.
 774   elem->set_obj(nullptr);
 775 JRT_END
 776 
 777 
 778 JRT_ENTRY(void, InterpreterRuntime::throw_illegal_monitor_state_exception(JavaThread* current))

 779   THROW(vmSymbols::java_lang_IllegalMonitorStateException());
 780 JRT_END
 781 
 782 
 783 JRT_ENTRY(void, InterpreterRuntime::new_illegal_monitor_state_exception(JavaThread* current))

 784   // Returns an illegal exception to install into the current thread. The
 785   // pending_exception flag is cleared so normal exception handling does not
 786   // trigger. Any current installed exception will be overwritten. This
 787   // method will be called during an exception unwind.
 788 
 789   assert(!HAS_PENDING_EXCEPTION, "no pending exception");
 790   Handle exception(current, current->vm_result());
 791   assert(exception() != nullptr, "vm result should be set");
 792   current->set_vm_result(nullptr); // clear vm result before continuing (may cause memory leaks and assert failures)
 793   exception = get_preinitialized_exception(vmClasses::IllegalMonitorStateException_klass(), CATCH);
 794   current->set_vm_result(exception());
 795 JRT_END
 796 
 797 
 798 //------------------------------------------------------------------------------------------------------------------------
 799 // Invokes
 800 
 801 JRT_ENTRY(Bytecodes::Code, InterpreterRuntime::get_original_bytecode_at(JavaThread* current, Method* method, address bcp))
 802   return method->orig_bytecode_at(method->bci_from(bcp));
 803 JRT_END
 804 
 805 JRT_ENTRY(void, InterpreterRuntime::set_original_bytecode_at(JavaThread* current, Method* method, address bcp, Bytecodes::Code new_code))
 806   method->set_orig_bytecode_at(method->bci_from(bcp), new_code);
 807 JRT_END
 808 
 809 JRT_ENTRY(void, InterpreterRuntime::_breakpoint(JavaThread* current, Method* method, address bcp))
 810   JvmtiExport::post_raw_breakpoint(current, method, bcp);
 811 JRT_END
 812 
















 813 void InterpreterRuntime::resolve_invoke(JavaThread* current, Bytecodes::Code bytecode) {
 814   LastFrameAccessor last_frame(current);
 815   // extract receiver from the outgoing argument list if necessary
 816   Handle receiver(current, nullptr);
 817   if (bytecode == Bytecodes::_invokevirtual || bytecode == Bytecodes::_invokeinterface ||
 818       bytecode == Bytecodes::_invokespecial) {
 819     ResourceMark rm(current);
 820     methodHandle m (current, last_frame.method());
 821     Bytecode_invoke call(m, last_frame.bci());
 822     Symbol* signature = call.signature();
 823     receiver = Handle(current, last_frame.callee_receiver(signature));
 824 
 825     assert(Universe::heap()->is_in_or_null(receiver()),
 826            "sanity check");
 827     assert(receiver.is_null() ||
 828            !Universe::heap()->is_in(receiver->klass()),
 829            "sanity check");
 830   }
 831 
 832   // resolve method

 911     cache->set_itable_call(
 912       bytecode,
 913       method_index,
 914       info.resolved_klass(),
 915       resolved_method,
 916       info.itable_index());
 917     break;
 918   default:  ShouldNotReachHere();
 919   }
 920 }
 921 
 922 void InterpreterRuntime::cds_resolve_invoke(Bytecodes::Code bytecode, int method_index,
 923                                             constantPoolHandle& pool, TRAPS) {
 924   LinkInfo link_info(pool, method_index, bytecode, CHECK);
 925 
 926   if (!link_info.resolved_klass()->is_instance_klass() || InstanceKlass::cast(link_info.resolved_klass())->is_linked()) {
 927     CallInfo call_info;
 928     switch (bytecode) {
 929       case Bytecodes::_invokevirtual:   LinkResolver::cds_resolve_virtual_call  (call_info, link_info, CHECK); break;
 930       case Bytecodes::_invokeinterface: LinkResolver::cds_resolve_interface_call(call_info, link_info, CHECK); break;

 931       case Bytecodes::_invokespecial:   LinkResolver::cds_resolve_special_call  (call_info, link_info, CHECK); break;
 932 
 933       default: fatal("Unimplemented: %s", Bytecodes::name(bytecode));
 934     }
 935     methodHandle resolved_method(THREAD, call_info.resolved_method());
 936     guarantee(resolved_method->method_holder()->is_linked(), "");
 937     update_invoke_cp_cache_entry(call_info, bytecode, resolved_method, pool, method_index);
 938   } else {
 939     // FIXME: why a shared class is not linked yet?
 940     // Can't link it here since there are no guarantees it'll be prelinked on the next run.
 941     ResourceMark rm;
 942     InstanceKlass* resolved_iklass = InstanceKlass::cast(link_info.resolved_klass());
 943     log_info(cds, resolve)("Not resolved: class not linked: %s %s %s",
 944                            resolved_iklass->is_shared() ? "is_shared" : "",
 945                            resolved_iklass->init_state_name(),
 946                            resolved_iklass->external_name());
 947   }
 948 }
 949 
 950 // First time execution:  Resolve symbols, create a permanent MethodType object.
 951 void InterpreterRuntime::resolve_invokehandle(JavaThread* current) {
 952   const Bytecodes::Code bytecode = Bytecodes::_invokehandle;
 953   LastFrameAccessor last_frame(current);
 954 
 955   // resolve method
 956   CallInfo info;
 957   constantPoolHandle pool(current, last_frame.method()->constants());
 958   int method_index = last_frame.get_index_u2(bytecode);
 959   {
 960     JvmtiHideSingleStepping jhss(current);
 961     JavaThread* THREAD = current; // For exception macros.
 962     LinkResolver::resolve_invoke(info, Handle(), pool,
 963                                  method_index, bytecode,
 964                                  CHECK);
 965   } // end JvmtiHideSingleStepping
 966 
 967   pool->cache()->set_method_handle(method_index, info);










 968 }
 969 
 970 // First time execution:  Resolve symbols, create a permanent CallSite object.
 971 void InterpreterRuntime::resolve_invokedynamic(JavaThread* current) {
 972   LastFrameAccessor last_frame(current);
 973   const Bytecodes::Code bytecode = Bytecodes::_invokedynamic;
 974 
 975   // resolve method
 976   CallInfo info;
 977   constantPoolHandle pool(current, last_frame.method()->constants());
 978   int index = last_frame.get_index_u4(bytecode);
 979   {
 980     JvmtiHideSingleStepping jhss(current);
 981     JavaThread* THREAD = current; // For exception macros.
 982     LinkResolver::resolve_invoke(info, Handle(), pool,
 983                                  index, bytecode, CHECK);
 984   } // end JvmtiHideSingleStepping
 985 
 986   pool->cache()->set_dynamic_call(info, index);









 987 }
 988 
 989 // This function is the interface to the assembly code. It returns the resolved
 990 // cpCache entry.  This doesn't safepoint, but the helper routines safepoint.
 991 // This function will check for redefinition!
 992 JRT_ENTRY(void, InterpreterRuntime::resolve_from_cache(JavaThread* current, Bytecodes::Code bytecode)) {


 993   switch (bytecode) {
 994   case Bytecodes::_getstatic:
 995   case Bytecodes::_putstatic:
 996   case Bytecodes::_getfield:
 997   case Bytecodes::_putfield:
 998     resolve_get_put(current, bytecode);
 999     break;
1000   case Bytecodes::_invokevirtual:
1001   case Bytecodes::_invokespecial:
1002   case Bytecodes::_invokestatic:
1003   case Bytecodes::_invokeinterface:
1004     resolve_invoke(current, bytecode);
1005     break;
1006   case Bytecodes::_invokehandle:
1007     resolve_invokehandle(current);
1008     break;
1009   case Bytecodes::_invokedynamic:
1010     resolve_invokedynamic(current);
1011     break;
1012   default:
1013     fatal("unexpected bytecode: %s", Bytecodes::name(bytecode));
1014     break;
1015   }
1016 }
1017 JRT_END
1018 
1019 //------------------------------------------------------------------------------------------------------------------------
1020 // Miscellaneous
1021 
1022 
1023 nmethod* InterpreterRuntime::frequency_counter_overflow(JavaThread* current, address branch_bcp) {
1024   // Enable WXWrite: the function is called directly by interpreter.
1025   MACOS_AARCH64_ONLY(ThreadWXEnable wx(WXWrite, current));
1026 
1027   // frequency_counter_overflow_inner can throw async exception.
1028   nmethod* nm = frequency_counter_overflow_inner(current, branch_bcp);
1029   assert(branch_bcp != nullptr || nm == nullptr, "always returns null for non OSR requests");
1030   if (branch_bcp != nullptr && nm != nullptr) {
1031     // This was a successful request for an OSR nmethod.  Because

1047   }
1048   if (nm != nullptr && current->is_interp_only_mode()) {
1049     // Normally we never get an nm if is_interp_only_mode() is true, because
1050     // policy()->event has a check for this and won't compile the method when
1051     // true. However, it's possible for is_interp_only_mode() to become true
1052     // during the compilation. We don't want to return the nm in that case
1053     // because we want to continue to execute interpreted.
1054     nm = nullptr;
1055   }
1056 #ifndef PRODUCT
1057   if (TraceOnStackReplacement) {
1058     if (nm != nullptr) {
1059       tty->print("OSR entry @ pc: " INTPTR_FORMAT ": ", p2i(nm->osr_entry()));
1060       nm->print();
1061     }
1062   }
1063 #endif
1064   return nm;
1065 }
1066 
1067 JRT_ENTRY(nmethod*,
1068           InterpreterRuntime::frequency_counter_overflow_inner(JavaThread* current, address branch_bcp))
1069   // use UnlockFlagSaver to clear and restore the _do_not_unlock_if_synchronized
1070   // flag, in case this method triggers classloading which will call into Java.
1071   UnlockFlagSaver fs(current);
1072 
1073   LastFrameAccessor last_frame(current);
1074   assert(last_frame.is_interpreted_frame(), "must come from interpreter");
1075   methodHandle method(current, last_frame.method());
1076   const int branch_bci = branch_bcp != nullptr ? method->bci_from(branch_bcp) : InvocationEntryBci;
1077   const int bci = branch_bcp != nullptr ? method->bci_from(last_frame.bcp()) : InvocationEntryBci;
1078 
1079   nmethod* osr_nm = CompilationPolicy::event(method, method, branch_bci, bci, CompLevel_none, nullptr, CHECK_NULL);
1080 
1081   BarrierSetNMethod* bs_nm = BarrierSet::barrier_set()->barrier_set_nmethod();
1082   if (osr_nm != nullptr && bs_nm != nullptr) {
1083     if (!bs_nm->nmethod_osr_entry_barrier(osr_nm)) {
1084       osr_nm = nullptr;
1085     }
1086   }
1087   return osr_nm;
1088 JRT_END
1089 
1090 JRT_LEAF(jint, InterpreterRuntime::bcp_to_di(Method* method, address cur_bcp))
1091   assert(ProfileInterpreter, "must be profiling interpreter");
1092   int bci = method->bci_from(cur_bcp);
1093   MethodData* mdo = method->method_data();
1094   if (mdo == nullptr)  return 0;
1095   return mdo->bci_to_di(bci);
1096 JRT_END
1097 
1098 #ifdef ASSERT
1099 JRT_LEAF(void, InterpreterRuntime::verify_mdp(Method* method, address bcp, address mdp))
1100   assert(ProfileInterpreter, "must be profiling interpreter");
1101 
1102   MethodData* mdo = method->method_data();
1103   assert(mdo != nullptr, "must not be null");
1104 
1105   int bci = method->bci_from(bcp);
1106 
1107   address mdp2 = mdo->bci_to_dp(bci);
1108   if (mdp != mdp2) {
1109     ResourceMark rm;
1110     tty->print_cr("FAILED verify : actual mdp %p   expected mdp %p @ bci %d", mdp, mdp2, bci);
1111     int current_di = mdo->dp_to_di(mdp);
1112     int expected_di  = mdo->dp_to_di(mdp2);
1113     tty->print_cr("  actual di %d   expected di %d", current_di, expected_di);
1114     int expected_approx_bci = mdo->data_at(expected_di)->bci();
1115     int approx_bci = -1;
1116     if (current_di >= 0) {
1117       approx_bci = mdo->data_at(current_di)->bci();
1118     }
1119     tty->print_cr("  actual bci is %d  expected bci %d", approx_bci, expected_approx_bci);
1120     mdo->print_on(tty);
1121     method->print_codes();
1122   }
1123   assert(mdp == mdp2, "wrong mdp");
1124 JRT_END
1125 #endif // ASSERT
1126 
1127 JRT_ENTRY(void, InterpreterRuntime::update_mdp_for_ret(JavaThread* current, int return_bci))
1128   assert(ProfileInterpreter, "must be profiling interpreter");
1129   ResourceMark rm(current);
1130   LastFrameAccessor last_frame(current);
1131   assert(last_frame.is_interpreted_frame(), "must come from interpreter");
1132   MethodData* h_mdo = last_frame.method()->method_data();
1133 
1134   // Grab a lock to ensure atomic access to setting the return bci and
1135   // the displacement.  This can block and GC, invalidating all naked oops.
1136   MutexLocker ml(RetData_lock);
1137 
1138   // ProfileData is essentially a wrapper around a derived oop, so we
1139   // need to take the lock before making any ProfileData structures.
1140   ProfileData* data = h_mdo->data_at(h_mdo->dp_to_di(last_frame.mdp()));
1141   guarantee(data != nullptr, "profile data must be valid");
1142   RetData* rdata = data->as_RetData();
1143   address new_mdp = rdata->fixup_ret(return_bci, h_mdo);
1144   last_frame.set_mdp(new_mdp);
1145 JRT_END
1146 
1147 JRT_ENTRY(MethodCounters*, InterpreterRuntime::build_method_counters(JavaThread* current, Method* m))
1148   return Method::build_method_counters(current, m);
1149 JRT_END
1150 
1151 
1152 JRT_ENTRY(void, InterpreterRuntime::at_safepoint(JavaThread* current))
1153   // We used to need an explicit preserve_arguments here for invoke bytecodes. However,
1154   // stack traversal automatically takes care of preserving arguments for invoke, so
1155   // this is no longer needed.
1156 
1157   // JRT_END does an implicit safepoint check, hence we are guaranteed to block
1158   // if this is called during a safepoint
1159 
1160   if (JvmtiExport::should_post_single_step()) {
1161     // This function is called by the interpreter when single stepping. Such single
1162     // stepping could unwind a frame. Then, it is important that we process any frames
1163     // that we might return into.
1164     StackWatermarkSet::before_unwind(current);
1165 
1166     // We are called during regular safepoints and when the VM is
1167     // single stepping. If any thread is marked for single stepping,
1168     // then we may have JVMTI work to do.
1169     LastFrameAccessor last_frame(current);
1170     JvmtiExport::at_single_stepping_point(current, last_frame.method(), last_frame.bcp());
1171   }
1172 JRT_END
1173 
1174 JRT_LEAF(void, InterpreterRuntime::at_unwind(JavaThread* current))
1175   assert(current == JavaThread::current(), "pre-condition");
1176   // This function is called by the interpreter when the return poll found a reason
1177   // to call the VM. The reason could be that we are returning into a not yet safe
1178   // to access frame. We handle that below.
1179   // Note that this path does not check for single stepping, because we do not want
1180   // to single step when unwinding frames for an exception being thrown. Instead,
1181   // such single stepping code will use the safepoint table, which will use the
1182   // InterpreterRuntime::at_safepoint callback.
1183   StackWatermarkSet::before_unwind(current);
1184 JRT_END
1185 
1186 JRT_ENTRY(void, InterpreterRuntime::post_field_access(JavaThread* current, oopDesc* obj,
1187                                                       ResolvedFieldEntry *entry))
1188 
1189   // check the access_flags for the field in the klass
1190 
1191   InstanceKlass* ik = entry->field_holder();
1192   int index = entry->field_index();
1193   if (!ik->field_status(index).is_access_watched()) return;
1194 
1195   bool is_static = (obj == nullptr);
1196   HandleMark hm(current);
1197 
1198   Handle h_obj;
1199   if (!is_static) {
1200     // non-static field accessors have an object, but we need a handle
1201     h_obj = Handle(current, obj);
1202   }
1203   InstanceKlass* field_holder = entry->field_holder(); // HERE
1204   jfieldID fid = jfieldIDWorkaround::to_jfieldID(field_holder, entry->field_offset(), is_static);
1205   LastFrameAccessor last_frame(current);
1206   JvmtiExport::post_field_access(current, last_frame.method(), last_frame.bcp(), field_holder, h_obj, fid);
1207 JRT_END
1208 
1209 JRT_ENTRY(void, InterpreterRuntime::post_field_modification(JavaThread* current, oopDesc* obj,
1210                                                             ResolvedFieldEntry *entry, jvalue *value))
1211 
1212   InstanceKlass* ik = entry->field_holder();
1213 
1214   // check the access_flags for the field in the klass
1215   int index = entry->field_index();
1216   // bail out if field modifications are not watched
1217   if (!ik->field_status(index).is_modification_watched()) return;
1218 
1219   char sig_type = '\0';
1220 
1221   switch((TosState)entry->tos_state()) {
1222     case btos: sig_type = JVM_SIGNATURE_BYTE;    break;
1223     case ztos: sig_type = JVM_SIGNATURE_BOOLEAN; break;
1224     case ctos: sig_type = JVM_SIGNATURE_CHAR;    break;
1225     case stos: sig_type = JVM_SIGNATURE_SHORT;   break;
1226     case itos: sig_type = JVM_SIGNATURE_INT;     break;
1227     case ftos: sig_type = JVM_SIGNATURE_FLOAT;   break;
1228     case atos: sig_type = JVM_SIGNATURE_CLASS;   break;
1229     case ltos: sig_type = JVM_SIGNATURE_LONG;    break;
1230     case dtos: sig_type = JVM_SIGNATURE_DOUBLE;  break;

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

1457   } else {
1458     if (PrintSignatureHandlers) {
1459       tty->cr();
1460       tty->print_cr("duplicate argument handler #%d for fingerprint " UINT64_FORMAT "(old: " PTR_FORMAT ", new : " PTR_FORMAT ")",
1461                     _handlers->length(),
1462                     fingerprint,
1463                     p2i(_handlers->at(handler_index)),
1464                     p2i(handler));
1465     }
1466   }
1467 }
1468 
1469 
1470 BufferBlob*              SignatureHandlerLibrary::_handler_blob = nullptr;
1471 address                  SignatureHandlerLibrary::_handler      = nullptr;
1472 GrowableArray<uint64_t>* SignatureHandlerLibrary::_fingerprints = nullptr;
1473 GrowableArray<address>*  SignatureHandlerLibrary::_handlers     = nullptr;
1474 address                  SignatureHandlerLibrary::_buffer       = nullptr;
1475 
1476 
1477 JRT_ENTRY(void, InterpreterRuntime::prepare_native_call(JavaThread* current, Method* method))
1478   methodHandle m(current, method);
1479   assert(m->is_native(), "sanity check");
1480   // lookup native function entry point if it doesn't exist
1481   if (!m->has_native_function()) {
1482     NativeLookup::lookup(m, CHECK);
1483   }
1484   // make sure signature handler is installed
1485   SignatureHandlerLibrary::add(m);
1486   // The interpreter entry point checks the signature handler first,
1487   // before trying to fetch the native entry point and klass mirror.
1488   // We must set the signature handler last, so that multiple processors
1489   // preparing the same method will be sure to see non-null entry & mirror.
1490 JRT_END
1491 
1492 #if defined(IA32) || defined(AMD64) || defined(ARM)
1493 JRT_LEAF(void, InterpreterRuntime::popframe_move_outgoing_args(JavaThread* current, void* src_address, void* dest_address))
1494   assert(current == JavaThread::current(), "pre-condition");
1495   if (src_address == dest_address) {
1496     return;
1497   }
1498   ResourceMark rm;
1499   LastFrameAccessor last_frame(current);
1500   assert(last_frame.is_interpreted_frame(), "");
1501   jint bci = last_frame.bci();
1502   methodHandle mh(current, last_frame.method());
1503   Bytecode_invoke invoke(mh, bci);
1504   ArgumentSizeComputer asc(invoke.signature());
1505   int size_of_arguments = (asc.size() + (invoke.has_receiver() ? 1 : 0)); // receiver
1506   Copy::conjoint_jbytes(src_address, dest_address,
1507                        size_of_arguments * Interpreter::stackElementSize);
1508 JRT_END
1509 #endif
1510 
1511 #if INCLUDE_JVMTI
1512 // This is a support of the JVMTI PopFrame interface.
1513 // Make sure it is an invokestatic of a polymorphic intrinsic that has a member_name argument
1514 // and return it as a vm_result so that it can be reloaded in the list of invokestatic parameters.
1515 // The member_name argument is a saved reference (in local#0) to the member_name.
1516 // For backward compatibility with some JDK versions (7, 8) it can also be a direct method handle.
1517 // FIXME: remove DMH case after j.l.i.InvokerBytecodeGenerator code shape is updated.
1518 JRT_ENTRY(void, InterpreterRuntime::member_name_arg_or_null(JavaThread* current, address member_name,
1519                                                             Method* method, address bcp))

1520   Bytecodes::Code code = Bytecodes::code_at(method, bcp);
1521   if (code != Bytecodes::_invokestatic) {
1522     return;
1523   }
1524   ConstantPool* cpool = method->constants();
1525   int cp_index = Bytes::get_native_u2(bcp + 1);
1526   Symbol* cname = cpool->klass_name_at(cpool->klass_ref_index_at(cp_index, code));
1527   Symbol* mname = cpool->name_ref_at(cp_index, code);
1528 
1529   if (MethodHandles::has_member_arg(cname, mname)) {
1530     oop member_name_oop = cast_to_oop(member_name);
1531     if (java_lang_invoke_DirectMethodHandle::is_instance(member_name_oop)) {
1532       // FIXME: remove after j.l.i.InvokerBytecodeGenerator code shape is updated.
1533       member_name_oop = java_lang_invoke_DirectMethodHandle::member(member_name_oop);
1534     }
1535     current->set_vm_result(member_name_oop);
1536   } else {
1537     current->set_vm_result(nullptr);
1538   }
1539 JRT_END
1540 #endif // INCLUDE_JVMTI
1541 
1542 #ifndef PRODUCT
1543 // This must be a JRT_LEAF function because the interpreter must save registers on x86 to
1544 // call this, which changes rsp and makes the interpreter's expression stack not walkable.
1545 // The generated code still uses call_VM because that will set up the frame pointer for
1546 // bcp and method.
1547 JRT_LEAF(intptr_t, InterpreterRuntime::trace_bytecode(JavaThread* current, intptr_t preserve_this_value, intptr_t tos, intptr_t tos2))
1548   assert(current == JavaThread::current(), "pre-condition");
1549   LastFrameAccessor last_frame(current);
1550   assert(last_frame.is_interpreted_frame(), "must be an interpreted frame");
1551   methodHandle mh(current, last_frame.method());
1552   BytecodeTracer::trace_interpreter(mh, last_frame.bcp(), tos, tos2);
1553   return preserve_this_value;
1554 JRT_END
1555 #endif // !PRODUCT







































































































  51 #include "oops/method.inline.hpp"
  52 #include "oops/objArrayKlass.hpp"
  53 #include "oops/objArrayOop.inline.hpp"
  54 #include "oops/oop.inline.hpp"
  55 #include "oops/symbol.hpp"
  56 #include "prims/jvmtiExport.hpp"
  57 #include "prims/methodHandles.hpp"
  58 #include "prims/nativeLookup.hpp"
  59 #include "runtime/atomic.hpp"
  60 #include "runtime/continuation.hpp"
  61 #include "runtime/deoptimization.hpp"
  62 #include "runtime/fieldDescriptor.inline.hpp"
  63 #include "runtime/frame.inline.hpp"
  64 #include "runtime/handles.inline.hpp"
  65 #include "runtime/icache.hpp"
  66 #include "runtime/interfaceSupport.inline.hpp"
  67 #include "runtime/java.hpp"
  68 #include "runtime/javaCalls.hpp"
  69 #include "runtime/jfieldIDWorkaround.hpp"
  70 #include "runtime/osThread.hpp"
  71 #include "runtime/perfData.inline.hpp"
  72 #include "runtime/sharedRuntime.hpp"
  73 #include "runtime/stackWatermarkSet.hpp"
  74 #include "runtime/stubRoutines.hpp"
  75 #include "runtime/synchronizer.hpp"
  76 #include "runtime/threadCritical.hpp"
  77 #include "services/management.hpp"
  78 #include "utilities/align.hpp"
  79 #include "utilities/checkedCast.hpp"
  80 #include "utilities/copy.hpp"
  81 #include "utilities/events.hpp"
  82 #ifdef COMPILER2
  83 #include "opto/runtime.hpp"
  84 #endif
  85 
  86 // Helper class to access current interpreter state
  87 class LastFrameAccessor : public StackObj {
  88   frame _last_frame;
  89 public:
  90   LastFrameAccessor(JavaThread* current) {
  91     assert(current == Thread::current(), "sanity");
  92     _last_frame = current->last_frame();
  93   }
  94   bool is_interpreted_frame() const              { return _last_frame.is_interpreted_frame(); }
  95   Method*   method() const                       { return _last_frame.interpreter_frame_method(); }
  96   address   bcp() const                          { return _last_frame.interpreter_frame_bcp(); }
  97   int       bci() const                          { return _last_frame.interpreter_frame_bci(); }

 108   int get_index_u2(Bytecodes::Code bc) const     { return bytecode().get_index_u2(bc); }
 109   int get_index_u4(Bytecodes::Code bc) const     { return bytecode().get_index_u4(bc); }
 110   int number_of_dimensions() const               { return bcp()[3]; }
 111 
 112   oop callee_receiver(Symbol* signature) {
 113     return _last_frame.interpreter_callee_receiver(signature);
 114   }
 115   BasicObjectLock* monitor_begin() const {
 116     return _last_frame.interpreter_frame_monitor_begin();
 117   }
 118   BasicObjectLock* monitor_end() const {
 119     return _last_frame.interpreter_frame_monitor_end();
 120   }
 121   BasicObjectLock* next_monitor(BasicObjectLock* current) const {
 122     return _last_frame.next_monitor_in_interpreter_frame(current);
 123   }
 124 
 125   frame& get_frame()                             { return _last_frame; }
 126 };
 127 
 128 static bool is_resolved(JavaThread* current) {
 129   LastFrameAccessor last_frame(current);
 130   ConstantPool* constants = last_frame.method()->constants();
 131   Bytecodes::Code bc = last_frame.code();
 132 
 133   if (bc == Bytecodes::_ldc || bc == Bytecodes::_ldc_w || bc == Bytecodes::_ldc2_w ||
 134       bc == Bytecodes::_fast_aldc || bc == Bytecodes::_fast_aldc_w) {
 135     bool is_wide = (bc != Bytecodes::_ldc) && (bc != Bytecodes::_fast_aldc);
 136     int index = (is_wide ? last_frame.get_index_u1(bc) : last_frame.get_index_u2(bc));
 137     constantTag tag = constants->tag_at(index);
 138     assert(tag.is_klass_or_reference(), "unknown tag: %s", tag.internal_name());
 139     return constants->tag_at(index).is_klass();
 140   } else if (bc == Bytecodes::_invokedynamic) {
 141     int index = last_frame.get_index_u4(bc);
 142     int indy_index = index;
 143     ResolvedIndyEntry* indy_entry = constants->resolved_indy_entry_at(indy_index);
 144     return indy_entry->is_resolved();
 145   } else if (Bytecodes::is_invoke(bc)) {
 146     int index = last_frame.get_index_u2(bc);
 147     ResolvedMethodEntry* rme = constants->resolved_method_entry_at(index);
 148     return rme->is_resolved(bc);
 149   } else if (Bytecodes::is_field_code(bc) || bc == Bytecodes::_nofast_getfield || bc == Bytecodes::_nofast_putfield) {
 150     if (bc == Bytecodes::_nofast_getfield) {
 151       bc = Bytecodes::_getfield;
 152     } else if (bc == Bytecodes::_nofast_putfield) {
 153       bc = Bytecodes::_putfield;
 154     }
 155     int index = last_frame.get_index_u2(bc);
 156     ResolvedFieldEntry* field_entry = constants->cache()->resolved_field_entry_at(index);
 157     return field_entry->is_resolved(bc);
 158   } else if (bc == Bytecodes::_new) {
 159     int index = last_frame.get_index_u2(bc);
 160     constantTag tag = constants->tag_at(index);
 161     assert(tag.is_klass_or_reference(), "unknown tag: %s", tag.internal_name());
 162     return constants->tag_at(index).is_klass();
 163   }
 164   return false;
 165 }
 166 
 167 static void trace_current_location(JavaThread* current) {
 168   LogStreamHandle(Debug, init, interpreter) log;
 169   if (current->profile_rt_calls() && log.is_enabled()) {
 170     ResourceMark rm(current);
 171     LastFrameAccessor last_frame(current);
 172     Method* caller = last_frame.method();
 173     ConstantPool* constants = caller->constants();
 174     Bytecodes::Code bc = last_frame.code();
 175     log.print("InterpreterRuntime: " INTPTR_FORMAT ": %s: " INTPTR_FORMAT,
 176               p2i(current), Bytecodes::name(bc), p2i(caller));
 177     if (caller->is_shared()) {
 178       log.print(" shared");
 179     }
 180     if (is_resolved(current)) {
 181       log.print(" resolved");
 182     }
 183     log.print(" ");
 184     caller->print_short_name(&log);
 185     log.print(" @ %d:", last_frame.bci());
 186     int instruction_size = last_frame.bytecode().instruction_size();
 187 
 188     if (Bytecodes::is_invoke(bc) && bc != Bytecodes::_invokedynamic) {
 189       int index = last_frame.get_index_u2(bc);
 190       ResolvedMethodEntry* rme = constants->resolved_method_entry_at(index);
 191       if (rme->is_resolved(bc)) {
 192         Method* m = rme->method();
 193         if (m != nullptr) {
 194           log.print(" %s", m->method_holder()->init_state_name());
 195         } else {
 196           log.print(" null");
 197         }
 198       }
 199     } else if (Bytecodes::is_field_code(bc) || bc == Bytecodes::_nofast_getfield || bc == Bytecodes::_nofast_putfield) {
 200       if (bc == Bytecodes::_nofast_getfield) {
 201         bc = Bytecodes::_getfield;
 202       } else if (bc == Bytecodes::_nofast_putfield) {
 203         bc = Bytecodes::_putfield;
 204       }
 205       int index = last_frame.get_index_u2(bc);
 206       ResolvedFieldEntry* field_entry = constants->cache()->resolved_field_entry_at(index);
 207 
 208       if (field_entry->is_resolved(bc)) {
 209         log.print(" %s", field_entry->field_holder()->init_state_name());
 210       }
 211     } else if (bc == Bytecodes::_new) {
 212       int index = last_frame.get_index_u2(bc);
 213       constantTag tag = constants->tag_at(index);
 214       assert(tag.is_klass_or_reference(), "unknown tag: %s", tag.internal_name());
 215       if (constants->tag_at(index).is_klass()) {
 216         CPKlassSlot kslot = constants->klass_slot_at(index);
 217         int resolved_klass_index = kslot.resolved_klass_index();
 218         Klass* k = constants->resolved_klasses()->at(resolved_klass_index);
 219         log.print(": %s", InstanceKlass::cast(k)->init_state_name());
 220       }
 221     }
 222     log.print(" ");
 223     caller->print_codes_on(last_frame.bci(), last_frame.bci() + instruction_size, &log, /*flags*/ 0);
 224 
 225     LogStreamHandle(Trace, init, interpreter) log1;
 226     if (log1.is_enabled()) {
 227       if (bc == Bytecodes::_invokedynamic) {
 228         int index = last_frame.get_index_u4(bc);
 229         int indy_index = index;
 230         ResolvedIndyEntry* indy_entry = constants->resolved_indy_entry_at(indy_index);
 231         indy_entry->print_on(&log1);
 232       } else if (Bytecodes::is_invoke(bc)) {
 233         int index = last_frame.get_index_u2(bc);
 234         ResolvedMethodEntry* rme = constants->resolved_method_entry_at(index);
 235         rme->print_on(&log1);
 236       } else if (Bytecodes::is_field_code(bc) || bc == Bytecodes::_nofast_getfield || bc == Bytecodes::_nofast_putfield) {
 237         int index = last_frame.get_index_u2(bc);
 238         ResolvedFieldEntry* field_entry = constants->cache()->resolved_field_entry_at(index);
 239         field_entry->print_on(&log1);
 240       }
 241     }
 242   }
 243 }
 244 
 245 //------------------------------------------------------------------------------------------------------------------------
 246 // State accessors
 247 
 248 void InterpreterRuntime::set_bcp_and_mdp(address bcp, JavaThread* current) {
 249   LastFrameAccessor last_frame(current);
 250   last_frame.set_bcp(bcp);
 251   if (ProfileInterpreter) {
 252     // ProfileTraps uses MDOs independently of ProfileInterpreter.
 253     // That is why we must check both ProfileInterpreter and mdo != nullptr.
 254     MethodData* mdo = last_frame.method()->method_data();
 255     if (mdo != nullptr) {
 256       NEEDS_CLEANUP;
 257       last_frame.set_mdp(mdo->bci_to_dp(last_frame.bci()));
 258     }
 259   }
 260 }
 261 
 262 //------------------------------------------------------------------------------------------------------------------------
 263 // Constants
 264 
 265 
 266 JRT_ENTRY_PROF(void, InterpreterRuntime, ldc, InterpreterRuntime::ldc(JavaThread* current, bool wide))
 267   // access constant pool
 268   LastFrameAccessor last_frame(current);
 269   ConstantPool* pool = last_frame.method()->constants();
 270   int cp_index = wide ? last_frame.get_index_u2(Bytecodes::_ldc_w) : last_frame.get_index_u1(Bytecodes::_ldc);
 271   constantTag tag = pool->tag_at(cp_index);
 272 
 273   assert (tag.is_unresolved_klass() || tag.is_klass(), "wrong ldc call");
 274   Klass* klass = pool->klass_at(cp_index, CHECK);
 275   oop java_class = klass->java_mirror();
 276   current->set_vm_result(java_class);
 277 JRT_END
 278 
 279 JRT_ENTRY_PROF(void, InterpreterRuntime, resolve_ldc, InterpreterRuntime::resolve_ldc(JavaThread* current, Bytecodes::Code bytecode)) {
 280   assert(bytecode == Bytecodes::_ldc ||
 281          bytecode == Bytecodes::_ldc_w ||
 282          bytecode == Bytecodes::_ldc2_w ||
 283          bytecode == Bytecodes::_fast_aldc ||
 284          bytecode == Bytecodes::_fast_aldc_w, "wrong bc");
 285   ResourceMark rm(current);
 286   const bool is_fast_aldc = (bytecode == Bytecodes::_fast_aldc ||
 287                              bytecode == Bytecodes::_fast_aldc_w);
 288   LastFrameAccessor last_frame(current);
 289   methodHandle m (current, last_frame.method());
 290   Bytecode_loadconstant ldc(m, last_frame.bci());
 291 
 292   // Double-check the size.  (Condy can have any type.)
 293   BasicType type = ldc.result_type();
 294   switch (type2size[type]) {
 295   case 2: guarantee(bytecode == Bytecodes::_ldc2_w, ""); break;
 296   case 1: guarantee(bytecode != Bytecodes::_ldc2_w, ""); break;
 297   default: ShouldNotReachHere();
 298   }
 299 

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

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

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

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

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






1196   default:
1197     fatal("unexpected bytecode: %s", Bytecodes::name(bytecode));
1198     break;
1199   }
1200 }
1201 JRT_END
1202 
1203 //------------------------------------------------------------------------------------------------------------------------
1204 // Miscellaneous
1205 
1206 
1207 nmethod* InterpreterRuntime::frequency_counter_overflow(JavaThread* current, address branch_bcp) {
1208   // Enable WXWrite: the function is called directly by interpreter.
1209   MACOS_AARCH64_ONLY(ThreadWXEnable wx(WXWrite, current));
1210 
1211   // frequency_counter_overflow_inner can throw async exception.
1212   nmethod* nm = frequency_counter_overflow_inner(current, branch_bcp);
1213   assert(branch_bcp != nullptr || nm == nullptr, "always returns null for non OSR requests");
1214   if (branch_bcp != nullptr && nm != nullptr) {
1215     // This was a successful request for an OSR nmethod.  Because

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

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

1641   } else {
1642     if (PrintSignatureHandlers) {
1643       tty->cr();
1644       tty->print_cr("duplicate argument handler #%d for fingerprint " UINT64_FORMAT "(old: " PTR_FORMAT ", new : " PTR_FORMAT ")",
1645                     _handlers->length(),
1646                     fingerprint,
1647                     p2i(_handlers->at(handler_index)),
1648                     p2i(handler));
1649     }
1650   }
1651 }
1652 
1653 
1654 BufferBlob*              SignatureHandlerLibrary::_handler_blob = nullptr;
1655 address                  SignatureHandlerLibrary::_handler      = nullptr;
1656 GrowableArray<uint64_t>* SignatureHandlerLibrary::_fingerprints = nullptr;
1657 GrowableArray<address>*  SignatureHandlerLibrary::_handlers     = nullptr;
1658 address                  SignatureHandlerLibrary::_buffer       = nullptr;
1659 
1660 
1661 JRT_ENTRY_PROF(void, InterpreterRuntime, prepare_native_call, InterpreterRuntime::prepare_native_call(JavaThread* current, Method* method))
1662   methodHandle m(current, method);
1663   assert(m->is_native(), "sanity check");
1664   // lookup native function entry point if it doesn't exist
1665   if (!m->has_native_function()) {
1666     NativeLookup::lookup(m, CHECK);
1667   }
1668   // make sure signature handler is installed
1669   SignatureHandlerLibrary::add(m);
1670   // The interpreter entry point checks the signature handler first,
1671   // before trying to fetch the native entry point and klass mirror.
1672   // We must set the signature handler last, so that multiple processors
1673   // preparing the same method will be sure to see non-null entry & mirror.
1674 JRT_END
1675 
1676 #if defined(IA32) || defined(AMD64) || defined(ARM)
1677 JRT_LEAF(void, InterpreterRuntime::popframe_move_outgoing_args(JavaThread* current, void* src_address, void* dest_address))
1678   assert(current == JavaThread::current(), "pre-condition");
1679   if (src_address == dest_address) {
1680     return;
1681   }
1682   ResourceMark rm;
1683   LastFrameAccessor last_frame(current);
1684   assert(last_frame.is_interpreted_frame(), "");
1685   jint bci = last_frame.bci();
1686   methodHandle mh(current, last_frame.method());
1687   Bytecode_invoke invoke(mh, bci);
1688   ArgumentSizeComputer asc(invoke.signature());
1689   int size_of_arguments = (asc.size() + (invoke.has_receiver() ? 1 : 0)); // receiver
1690   Copy::conjoint_jbytes(src_address, dest_address,
1691                        size_of_arguments * Interpreter::stackElementSize);
1692 JRT_END
1693 #endif
1694 
1695 #if INCLUDE_JVMTI
1696 // This is a support of the JVMTI PopFrame interface.
1697 // Make sure it is an invokestatic of a polymorphic intrinsic that has a member_name argument
1698 // and return it as a vm_result so that it can be reloaded in the list of invokestatic parameters.
1699 // The member_name argument is a saved reference (in local#0) to the member_name.
1700 // For backward compatibility with some JDK versions (7, 8) it can also be a direct method handle.
1701 // FIXME: remove DMH case after j.l.i.InvokerBytecodeGenerator code shape is updated.
1702 JRT_ENTRY_PROF(void, InterpreterRuntime, member_name_arg_or_null,
1703            InterpreterRuntime::member_name_arg_or_null(JavaThread* current, address member_name,
1704                                                        Method* method, address bcp))
1705   Bytecodes::Code code = Bytecodes::code_at(method, bcp);
1706   if (code != Bytecodes::_invokestatic) {
1707     return;
1708   }
1709   ConstantPool* cpool = method->constants();
1710   int cp_index = Bytes::get_native_u2(bcp + 1);
1711   Symbol* cname = cpool->klass_name_at(cpool->klass_ref_index_at(cp_index, code));
1712   Symbol* mname = cpool->name_ref_at(cp_index, code);
1713 
1714   if (MethodHandles::has_member_arg(cname, mname)) {
1715     oop member_name_oop = cast_to_oop(member_name);
1716     if (java_lang_invoke_DirectMethodHandle::is_instance(member_name_oop)) {
1717       // FIXME: remove after j.l.i.InvokerBytecodeGenerator code shape is updated.
1718       member_name_oop = java_lang_invoke_DirectMethodHandle::member(member_name_oop);
1719     }
1720     current->set_vm_result(member_name_oop);
1721   } else {
1722     current->set_vm_result(nullptr);
1723   }
1724 JRT_END
1725 #endif // INCLUDE_JVMTI
1726 
1727 #ifndef PRODUCT
1728 // This must be a JRT_LEAF function because the interpreter must save registers on x86 to
1729 // call this, which changes rsp and makes the interpreter's expression stack not walkable.
1730 // The generated code still uses call_VM because that will set up the frame pointer for
1731 // bcp and method.
1732 JRT_LEAF(intptr_t, InterpreterRuntime::trace_bytecode(JavaThread* current, intptr_t preserve_this_value, intptr_t tos, intptr_t tos2))
1733   assert(current == JavaThread::current(), "pre-condition");
1734   LastFrameAccessor last_frame(current);
1735   assert(last_frame.is_interpreted_frame(), "must be an interpreted frame");
1736   methodHandle mh(current, last_frame.method());
1737   BytecodeTracer::trace_interpreter(mh, last_frame.bcp(), tos, tos2);
1738   return preserve_this_value;
1739 JRT_END
1740 #endif // !PRODUCT
1741 
1742 #define DO_COUNTERS(macro) \
1743   macro(InterpreterRuntime, ldc) \
1744   macro(InterpreterRuntime, resolve_ldc) \
1745   macro(InterpreterRuntime, new) \
1746   macro(InterpreterRuntime, newarray) \
1747   macro(InterpreterRuntime, anewarray) \
1748   macro(InterpreterRuntime, multianewarray) \
1749   macro(InterpreterRuntime, register_finalizer) \
1750   macro(InterpreterRuntime, quicken_io_cc) \
1751   macro(InterpreterRuntime, throw_StackOverflowError) \
1752   macro(InterpreterRuntime, throw_delayed_StackOverflowError) \
1753   macro(InterpreterRuntime, create_exception) \
1754   macro(InterpreterRuntime, create_klass_exception) \
1755   macro(InterpreterRuntime, throw_ArrayIndexOutOfBoundsException) \
1756   macro(InterpreterRuntime, throw_ClassCastException) \
1757   macro(InterpreterRuntime, exception_handler_for_exception) \
1758   macro(InterpreterRuntime, throw_pending_exception) \
1759   macro(InterpreterRuntime, throw_AbstractMethodError) \
1760   macro(InterpreterRuntime, throw_AbstractMethodErrorWithMethod) \
1761   macro(InterpreterRuntime, throw_AbstractMethodErrorVerbose) \
1762   macro(InterpreterRuntime, throw_IncompatibleClassChangeError) \
1763   macro(InterpreterRuntime, throw_IncompatibleClassChangeErrorVerbose) \
1764   macro(InterpreterRuntime, throw_NullPointerException) \
1765   macro(InterpreterRuntime, monitorenter) \
1766   macro(InterpreterRuntime, monitorenter_obj) \
1767   macro(InterpreterRuntime, monitorexit) \
1768   macro(InterpreterRuntime, throw_illegal_monitor_state_exception) \
1769   macro(InterpreterRuntime, new_illegal_monitor_state_exception) \
1770   macro(InterpreterRuntime, get_original_bytecode_at) \
1771   macro(InterpreterRuntime, set_original_bytecode_at) \
1772   macro(InterpreterRuntime, breakpoint) \
1773   macro(InterpreterRuntime, resolve_getfield) \
1774   macro(InterpreterRuntime, resolve_putfield) \
1775   macro(InterpreterRuntime, resolve_getstatic) \
1776   macro(InterpreterRuntime, resolve_putstatic) \
1777   macro(InterpreterRuntime, resolve_invokevirtual) \
1778   macro(InterpreterRuntime, resolve_invokespecial) \
1779   macro(InterpreterRuntime, resolve_invokestatic) \
1780   macro(InterpreterRuntime, resolve_invokeinterface) \
1781   macro(InterpreterRuntime, resolve_invokehandle) \
1782   macro(InterpreterRuntime, resolve_invokedynamic) \
1783   macro(InterpreterRuntime, frequency_counter_overflow) \
1784   macro(InterpreterRuntime, bcp_to_di) \
1785   macro(InterpreterRuntime, update_mdp_for_ret) \
1786   macro(InterpreterRuntime, build_method_counters) \
1787   macro(InterpreterRuntime, at_safepoint) \
1788   macro(InterpreterRuntime, at_unwind) \
1789   macro(InterpreterRuntime, post_field_access) \
1790   macro(InterpreterRuntime, post_field_modification) \
1791   macro(InterpreterRuntime, post_method_entry) \
1792   macro(InterpreterRuntime, post_method_exit) \
1793   macro(InterpreterRuntime, interpreter_contains) \
1794   macro(InterpreterRuntime, prepare_native_call)
1795 
1796 #if INCLUDE_JVMTI
1797 #define DO_JVMTI_COUNTERS(macro) \
1798   macro(InterpreterRuntime, member_name_arg_or_null)
1799 #else
1800 #define DO_JVMTI_COUNTERS(macro)
1801 #endif /* INCLUDE_JVMTI */
1802 
1803 #define INIT_COUNTER(sub, name) \
1804   NEWPERFTICKCOUNTERS(_perf_##sub##_##name##_timer, SUN_CI, #sub "::" #name); \
1805   NEWPERFEVENTCOUNTER(_perf_##sub##_##name##_count, SUN_CI, #sub "::" #name "_count");
1806 
1807 void InterpreterRuntime::init_counters() {
1808   if (UsePerfData) {
1809     EXCEPTION_MARK;
1810 
1811     DO_COUNTERS(INIT_COUNTER)
1812     DO_JVMTI_COUNTERS(INIT_COUNTER)
1813 
1814     if (HAS_PENDING_EXCEPTION) {
1815       vm_exit_during_initialization("jvm_perf_init failed unexpectedly");
1816     }
1817   }
1818 }
1819 #undef INIT_COUNTER
1820 
1821 #define PRINT_COUNTER(sub, name) { \
1822   jlong count = _perf_##sub##_##name##_count->get_value(); \
1823   if (count > 0) { \
1824     st->print_cr("  %-50s = %4ldms (elapsed) %4ldms (thread) (%5ld events)", #sub "::" #name, \
1825                  _perf_##sub##_##name##_timer->elapsed_counter_value_ms(), \
1826                  _perf_##sub##_##name##_timer->thread_counter_value_ms(), \
1827                  count); \
1828   }}
1829 
1830 void InterpreterRuntime::print_counters_on(outputStream* st) {
1831   if (UsePerfData && ProfileRuntimeCalls) {
1832     DO_COUNTERS(PRINT_COUNTER)
1833     DO_JVMTI_COUNTERS(PRINT_COUNTER)
1834   } else {
1835     st->print_cr("  InterpreterRuntime: no info (%s is disabled)", (UsePerfData ? "ProfileRuntimeCalls" : "UsePerfData"));
1836   }
1837 }
1838 
1839 #undef PRINT_COUNTER
1840 #undef DO_JVMTI_COUNTERS
1841 #undef DO_COUNTERS
1842 
< prev index next >