1 /*
   2  * Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/javaClasses.inline.hpp"
  27 #include "classfile/symbolTable.hpp"
  28 #include "classfile/vmClasses.hpp"
  29 #include "classfile/vmSymbols.hpp"
  30 #include "code/codeCache.hpp"
  31 #include "compiler/compilationPolicy.hpp"
  32 #include "compiler/compileBroker.hpp"
  33 #include "compiler/disassembler.hpp"
  34 #include "gc/shared/barrierSetNMethod.hpp"
  35 #include "gc/shared/collectedHeap.hpp"
  36 #include "interpreter/bytecodeTracer.hpp"
  37 #include "interpreter/interpreter.hpp"
  38 #include "interpreter/interpreterRuntime.hpp"
  39 #include "interpreter/linkResolver.hpp"
  40 #include "interpreter/templateTable.hpp"
  41 #include "jvm_io.h"
  42 #include "logging/log.hpp"
  43 #include "memory/oopFactory.hpp"
  44 #include "memory/resourceArea.hpp"
  45 #include "memory/universe.hpp"
  46 #include "oops/constantPool.inline.hpp"
  47 #include "oops/cpCache.inline.hpp"
  48 #include "oops/instanceKlass.inline.hpp"
  49 #include "oops/klass.inline.hpp"
  50 #include "oops/methodData.hpp"
  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(); }
  96   address   mdp() const                          { return _last_frame.interpreter_frame_mdp(); }
  97 
  98   void      set_bcp(address bcp)                 { _last_frame.interpreter_frame_set_bcp(bcp); }
  99   void      set_mdp(address dp)                  { _last_frame.interpreter_frame_set_mdp(dp); }
 100 
 101   // pass method to avoid calling unsafe bcp_to_method (partial fix 4926272)
 102   Bytecodes::Code code() const                   { return Bytecodes::code_at(method(), bcp()); }
 103 
 104   Bytecode  bytecode() const                     { return Bytecode(method(), bcp()); }
 105   int get_index_u1(Bytecodes::Code bc) const     { return bytecode().get_index_u1(bc); }
 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 
 181   // Resolve the constant.  This does not do unboxing.
 182   // But it does replace Universe::the_null_sentinel by null.
 183   oop result = ldc.resolve_constant(CHECK);
 184   assert(result != nullptr || is_fast_aldc, "null result only valid for fast_aldc");
 185 
 186 #ifdef ASSERT
 187   {
 188     // The bytecode wrappers aren't GC-safe so construct a new one
 189     Bytecode_loadconstant ldc2(m, last_frame.bci());
 190     int rindex = ldc2.cache_index();
 191     if (rindex < 0)
 192       rindex = m->constants()->cp_to_object_index(ldc2.pool_index());
 193     if (rindex >= 0) {
 194       oop coop = m->constants()->resolved_reference_at(rindex);
 195       oop roop = (result == nullptr ? Universe::the_null_sentinel() : result);
 196       assert(roop == coop, "expected result for assembly code");
 197     }
 198   }
 199 #endif
 200   current->set_vm_result(result);
 201   if (!is_fast_aldc) {
 202     // Tell the interpreter how to unbox the primitive.
 203     guarantee(java_lang_boxing_object::is_instance(result, type), "");
 204     int offset = java_lang_boxing_object::value_offset(type);
 205     intptr_t flags = ((as_TosState(type) << ConstantPoolCache::tos_state_shift)
 206                       | (offset & ConstantPoolCache::field_index_mask));
 207     current->set_vm_result_2((Metadata*)flags);
 208   }
 209 }
 210 JRT_END
 211 
 212 
 213 //------------------------------------------------------------------------------------------------------------------------
 214 // Allocation
 215 
 216 JRT_ENTRY(void, InterpreterRuntime::_new(JavaThread* current, ConstantPool* pool, int index))
 217   Klass* k = pool->klass_at(index, CHECK);
 218   InstanceKlass* klass = InstanceKlass::cast(k);
 219 
 220   // Make sure we are not instantiating an abstract klass
 221   klass->check_valid_for_instantiation(true, CHECK);
 222 
 223   // Make sure klass is initialized
 224   klass->initialize(CHECK);
 225 
 226   // At this point the class may not be fully initialized
 227   // because of recursive initialization. If it is fully
 228   // initialized & has_finalized is not set, we rewrite
 229   // it into its fast version (Note: no locking is needed
 230   // here since this is an atomic byte write and can be
 231   // done more than once).
 232   //
 233   // Note: In case of classes with has_finalized we don't
 234   //       rewrite since that saves us an extra check in
 235   //       the fast version which then would call the
 236   //       slow version anyway (and do a call back into
 237   //       Java).
 238   //       If we have a breakpoint, then we don't rewrite
 239   //       because the _breakpoint bytecode would be lost.
 240   oop obj = klass->allocate_instance(CHECK);
 241   current->set_vm_result(obj);
 242 JRT_END
 243 
 244 
 245 JRT_ENTRY(void, InterpreterRuntime::newarray(JavaThread* current, BasicType type, jint size))
 246   oop obj = oopFactory::new_typeArray(type, size, CHECK);
 247   current->set_vm_result(obj);
 248 JRT_END
 249 
 250 
 251 JRT_ENTRY(void, InterpreterRuntime::anewarray(JavaThread* current, ConstantPool* pool, int index, jint size))
 252   Klass*    klass = pool->klass_at(index, CHECK);
 253   objArrayOop obj = oopFactory::new_objArray(klass, size, CHECK);
 254   current->set_vm_result(obj);
 255 JRT_END
 256 
 257 
 258 JRT_ENTRY(void, InterpreterRuntime::multianewarray(JavaThread* current, jint* first_size_address))
 259   // We may want to pass in more arguments - could make this slightly faster
 260   LastFrameAccessor last_frame(current);
 261   ConstantPool* constants = last_frame.method()->constants();
 262   int          i = last_frame.get_index_u2(Bytecodes::_multianewarray);
 263   Klass* klass   = constants->klass_at(i, CHECK);
 264   int   nof_dims = last_frame.number_of_dimensions();
 265   assert(klass->is_klass(), "not a class");
 266   assert(nof_dims >= 1, "multianewarray rank must be nonzero");
 267 
 268   // We must create an array of jints to pass to multi_allocate.
 269   ResourceMark rm(current);
 270   const int small_dims = 10;
 271   jint dim_array[small_dims];
 272   jint *dims = &dim_array[0];
 273   if (nof_dims > small_dims) {
 274     dims = (jint*) NEW_RESOURCE_ARRAY(jint, nof_dims);
 275   }
 276   for (int index = 0; index < nof_dims; index++) {
 277     // offset from first_size_address is addressed as local[index]
 278     int n = Interpreter::local_offset_in_bytes(index)/jintSize;
 279     dims[index] = first_size_address[n];
 280   }
 281   oop obj = ArrayKlass::cast(klass)->multi_allocate(nof_dims, dims, CHECK);
 282   current->set_vm_result(obj);
 283 JRT_END
 284 
 285 
 286 JRT_ENTRY(void, InterpreterRuntime::register_finalizer(JavaThread* current, oopDesc* obj))
 287   assert(oopDesc::is_oop(obj), "must be a valid oop");
 288   assert(obj->klass()->has_finalizer(), "shouldn't be here otherwise");
 289   InstanceKlass::register_finalizer(instanceOop(obj), CHECK);
 290 JRT_END
 291 
 292 
 293 // Quicken instance-of and check-cast bytecodes
 294 JRT_ENTRY(void, InterpreterRuntime::quicken_io_cc(JavaThread* current))
 295   // Force resolving; quicken the bytecode
 296   LastFrameAccessor last_frame(current);
 297   int which = last_frame.get_index_u2(Bytecodes::_checkcast);
 298   ConstantPool* cpool = last_frame.method()->constants();
 299   // We'd expect to assert that we're only here to quicken bytecodes, but in a multithreaded
 300   // program we might have seen an unquick'd bytecode in the interpreter but have another
 301   // thread quicken the bytecode before we get here.
 302   // assert( cpool->tag_at(which).is_unresolved_klass(), "should only come here to quicken bytecodes" );
 303   Klass* klass = cpool->klass_at(which, CHECK);
 304   current->set_vm_result_2(klass);
 305 JRT_END
 306 
 307 
 308 //------------------------------------------------------------------------------------------------------------------------
 309 // Exceptions
 310 
 311 void InterpreterRuntime::note_trap_inner(JavaThread* current, int reason,
 312                                          const methodHandle& trap_method, int trap_bci) {
 313   if (trap_method.not_null()) {
 314     MethodData* trap_mdo = trap_method->method_data();
 315     if (trap_mdo == nullptr) {
 316       ExceptionMark em(current);
 317       JavaThread* THREAD = current; // For exception macros.
 318       Method::build_profiling_method_data(trap_method, THREAD);
 319       if (HAS_PENDING_EXCEPTION) {
 320         // Only metaspace OOM is expected. No Java code executed.
 321         assert((PENDING_EXCEPTION->is_a(vmClasses::OutOfMemoryError_klass())),
 322                "we expect only an OOM error here");
 323         CLEAR_PENDING_EXCEPTION;
 324       }
 325       trap_mdo = trap_method->method_data();
 326       // and fall through...
 327     }
 328     if (trap_mdo != nullptr) {
 329       // Update per-method count of trap events.  The interpreter
 330       // is updating the MDO to simulate the effect of compiler traps.
 331       Deoptimization::update_method_data_from_interpreter(trap_mdo, trap_bci, reason);
 332     }
 333   }
 334 }
 335 
 336 // Assume the compiler is (or will be) interested in this event.
 337 // If necessary, create an MDO to hold the information, and record it.
 338 void InterpreterRuntime::note_trap(JavaThread* current, int reason) {
 339   assert(ProfileTraps, "call me only if profiling");
 340   LastFrameAccessor last_frame(current);
 341   methodHandle trap_method(current, last_frame.method());
 342   int trap_bci = trap_method->bci_from(last_frame.bcp());
 343   note_trap_inner(current, reason, trap_method, trap_bci);
 344 }
 345 
 346 static Handle get_preinitialized_exception(Klass* k, TRAPS) {
 347   // get klass
 348   InstanceKlass* klass = InstanceKlass::cast(k);
 349   assert(klass->is_initialized(),
 350          "this klass should have been initialized during VM initialization");
 351   // create instance - do not call constructor since we may have no
 352   // (java) stack space left (should assert constructor is empty)
 353   Handle exception;
 354   oop exception_oop = klass->allocate_instance(CHECK_(exception));
 355   exception = Handle(THREAD, exception_oop);
 356   if (StackTraceInThrowable) {
 357     java_lang_Throwable::fill_in_stack_trace(exception);
 358   }
 359   return exception;
 360 }
 361 
 362 // Special handling for stack overflow: since we don't have any (java) stack
 363 // space left we use the pre-allocated & pre-initialized StackOverflowError
 364 // klass to create an stack overflow error instance.  We do not call its
 365 // constructor for the same reason (it is empty, anyway).
 366 JRT_ENTRY(void, InterpreterRuntime::throw_StackOverflowError(JavaThread* current))
 367   Handle exception = get_preinitialized_exception(
 368                                  vmClasses::StackOverflowError_klass(),
 369                                  CHECK);
 370   // Increment counter for hs_err file reporting
 371   Atomic::inc(&Exceptions::_stack_overflow_errors);
 372   // Remove the ScopedValue bindings in case we got a StackOverflowError
 373   // while we were trying to manipulate ScopedValue bindings.
 374   current->clear_scopedValueBindings();
 375   THROW_HANDLE(exception);
 376 JRT_END
 377 
 378 JRT_ENTRY(void, InterpreterRuntime::throw_delayed_StackOverflowError(JavaThread* current))
 379   Handle exception = get_preinitialized_exception(
 380                                  vmClasses::StackOverflowError_klass(),
 381                                  CHECK);
 382   java_lang_Throwable::set_message(exception(),
 383           Universe::delayed_stack_overflow_error_message());
 384   // Increment counter for hs_err file reporting
 385   Atomic::inc(&Exceptions::_stack_overflow_errors);
 386   // Remove the ScopedValue bindings in case we got a StackOverflowError
 387   // while we were trying to manipulate ScopedValue bindings.
 388   current->clear_scopedValueBindings();
 389   THROW_HANDLE(exception);
 390 JRT_END
 391 
 392 JRT_ENTRY(void, InterpreterRuntime::create_exception(JavaThread* current, char* name, char* message))
 393   // lookup exception klass
 394   TempNewSymbol s = SymbolTable::new_symbol(name);
 395   if (ProfileTraps) {
 396     if (s == vmSymbols::java_lang_ArithmeticException()) {
 397       note_trap(current, Deoptimization::Reason_div0_check);
 398     } else if (s == vmSymbols::java_lang_NullPointerException()) {
 399       note_trap(current, Deoptimization::Reason_null_check);
 400     }
 401   }
 402   // create exception
 403   Handle exception = Exceptions::new_exception(current, s, message);
 404   current->set_vm_result(exception());
 405 JRT_END
 406 
 407 
 408 JRT_ENTRY(void, InterpreterRuntime::create_klass_exception(JavaThread* current, char* name, oopDesc* obj))
 409   // Produce the error message first because note_trap can safepoint
 410   ResourceMark rm(current);
 411   const char* klass_name = obj->klass()->external_name();
 412   // lookup exception klass
 413   TempNewSymbol s = SymbolTable::new_symbol(name);
 414   if (ProfileTraps) {
 415     if (s == vmSymbols::java_lang_ArrayStoreException()) {
 416       note_trap(current, Deoptimization::Reason_array_check);
 417     } else {
 418       note_trap(current, Deoptimization::Reason_class_check);
 419     }
 420   }
 421   // create exception, with klass name as detail message
 422   Handle exception = Exceptions::new_exception(current, s, klass_name);
 423   current->set_vm_result(exception());
 424 JRT_END
 425 
 426 JRT_ENTRY(void, InterpreterRuntime::throw_ArrayIndexOutOfBoundsException(JavaThread* current, arrayOopDesc* a, jint index))
 427   // Produce the error message first because note_trap can safepoint
 428   ResourceMark rm(current);
 429   stringStream ss;
 430   ss.print("Index %d out of bounds for length %d", index, a->length());
 431 
 432   if (ProfileTraps) {
 433     note_trap(current, Deoptimization::Reason_range_check);
 434   }
 435 
 436   THROW_MSG(vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), ss.as_string());
 437 JRT_END
 438 
 439 JRT_ENTRY(void, InterpreterRuntime::throw_ClassCastException(
 440   JavaThread* current, oopDesc* obj))
 441 
 442   // Produce the error message first because note_trap can safepoint
 443   ResourceMark rm(current);
 444   char* message = SharedRuntime::generate_class_cast_message(
 445     current, obj->klass());
 446 
 447   if (ProfileTraps) {
 448     note_trap(current, Deoptimization::Reason_class_check);
 449   }
 450 
 451   // create exception
 452   THROW_MSG(vmSymbols::java_lang_ClassCastException(), message);
 453 JRT_END
 454 
 455 // exception_handler_for_exception(...) returns the continuation address,
 456 // the exception oop (via TLS) and sets the bci/bcp for the continuation.
 457 // The exception oop is returned to make sure it is preserved over GC (it
 458 // is only on the stack if the exception was thrown explicitly via athrow).
 459 // During this operation, the expression stack contains the values for the
 460 // bci where the exception happened. If the exception was propagated back
 461 // from a call, the expression stack contains the values for the bci at the
 462 // invoke w/o arguments (i.e., as if one were inside the call).
 463 // Note that the implementation of this method assumes it's only called when an exception has actually occured
 464 JRT_ENTRY(address, InterpreterRuntime::exception_handler_for_exception(JavaThread* current, oopDesc* exception))
 465   // We get here after we have unwound from a callee throwing an exception
 466   // into the interpreter. Any deferred stack processing is notified of
 467   // the event via the StackWatermarkSet.
 468   StackWatermarkSet::after_unwind(current);
 469 
 470   LastFrameAccessor last_frame(current);
 471   Handle             h_exception(current, exception);
 472   methodHandle       h_method   (current, last_frame.method());
 473   constantPoolHandle h_constants(current, h_method->constants());
 474   bool               should_repeat;
 475   int                handler_bci;
 476   int                current_bci = last_frame.bci();
 477 
 478   if (current->frames_to_pop_failed_realloc() > 0) {
 479     // Allocation of scalar replaced object used in this frame
 480     // failed. Unconditionally pop the frame.
 481     current->dec_frames_to_pop_failed_realloc();
 482     current->set_vm_result(h_exception());
 483     // If the method is synchronized we already unlocked the monitor
 484     // during deoptimization so the interpreter needs to skip it when
 485     // the frame is popped.
 486     current->set_do_not_unlock_if_synchronized(true);
 487     return Interpreter::remove_activation_entry();
 488   }
 489 
 490   // Need to do this check first since when _do_not_unlock_if_synchronized
 491   // is set, we don't want to trigger any classloading which may make calls
 492   // into java, or surprisingly find a matching exception handler for bci 0
 493   // since at this moment the method hasn't been "officially" entered yet.
 494   if (current->do_not_unlock_if_synchronized()) {
 495     ResourceMark rm;
 496     assert(current_bci == 0,  "bci isn't zero for do_not_unlock_if_synchronized");
 497     current->set_vm_result(exception);
 498     return Interpreter::remove_activation_entry();
 499   }
 500 
 501   do {
 502     should_repeat = false;
 503 
 504     // assertions
 505     assert(h_exception.not_null(), "null exceptions should be handled by athrow");
 506     // Check that exception is a subclass of Throwable.
 507     assert(h_exception->is_a(vmClasses::Throwable_klass()),
 508            "Exception not subclass of Throwable");
 509 
 510     // tracing
 511     if (log_is_enabled(Info, exceptions)) {
 512       ResourceMark rm(current);
 513       stringStream tempst;
 514       tempst.print("interpreter method <%s>\n"
 515                    " at bci %d for thread " INTPTR_FORMAT " (%s)",
 516                    h_method->print_value_string(), current_bci, p2i(current), current->name());
 517       Exceptions::log_exception(h_exception, tempst.as_string());
 518     }
 519 // Don't go paging in something which won't be used.
 520 //     else if (extable->length() == 0) {
 521 //       // disabled for now - interpreter is not using shortcut yet
 522 //       // (shortcut is not to call runtime if we have no exception handlers)
 523 //       // warning("performance bug: should not call runtime if method has no exception handlers");
 524 //     }
 525     // for AbortVMOnException flag
 526     Exceptions::debug_check_abort(h_exception);
 527 
 528     // exception handler lookup
 529     Klass* klass = h_exception->klass();
 530     handler_bci = Method::fast_exception_handler_bci_for(h_method, klass, current_bci, THREAD);
 531     if (HAS_PENDING_EXCEPTION) {
 532       // We threw an exception while trying to find the exception handler.
 533       // Transfer the new exception to the exception handle which will
 534       // be set into thread local storage, and do another lookup for an
 535       // exception handler for this exception, this time starting at the
 536       // BCI of the exception handler which caused the exception to be
 537       // thrown (bug 4307310).
 538       h_exception = Handle(THREAD, PENDING_EXCEPTION);
 539       CLEAR_PENDING_EXCEPTION;
 540       if (handler_bci >= 0) {
 541         current_bci = handler_bci;
 542         should_repeat = true;
 543       }
 544     }
 545   } while (should_repeat == true);
 546 
 547 #if INCLUDE_JVMCI
 548   if (EnableJVMCI && h_method->method_data() != nullptr) {
 549     ResourceMark rm(current);
 550     MethodData* mdo = h_method->method_data();
 551 
 552     // Lock to read ProfileData, and ensure lock is not broken by a safepoint
 553     MutexLocker ml(mdo->extra_data_lock(), Mutex::_no_safepoint_check_flag);
 554 
 555     ProfileData* pdata = mdo->allocate_bci_to_data(current_bci, nullptr);
 556     if (pdata != nullptr && pdata->is_BitData()) {
 557       BitData* bit_data = (BitData*) pdata;
 558       bit_data->set_exception_seen();
 559     }
 560   }
 561 #endif
 562 
 563   // notify JVMTI of an exception throw; JVMTI will detect if this is a first
 564   // time throw or a stack unwinding throw and accordingly notify the debugger
 565   if (JvmtiExport::can_post_on_exceptions()) {
 566     JvmtiExport::post_exception_throw(current, h_method(), last_frame.bcp(), h_exception());
 567   }
 568 
 569   address continuation = nullptr;
 570   address handler_pc = nullptr;
 571   if (handler_bci < 0 || !current->stack_overflow_state()->reguard_stack((address) &continuation)) {
 572     // Forward exception to callee (leaving bci/bcp untouched) because (a) no
 573     // handler in this method, or (b) after a stack overflow there is not yet
 574     // enough stack space available to reprotect the stack.
 575     continuation = Interpreter::remove_activation_entry();
 576 #if COMPILER2_OR_JVMCI
 577     // Count this for compilation purposes
 578     h_method->interpreter_throwout_increment(THREAD);
 579 #endif
 580   } else {
 581     // handler in this method => change bci/bcp to handler bci/bcp and continue there
 582     handler_pc = h_method->code_base() + handler_bci;
 583     h_method->set_exception_handler_entered(handler_bci); // profiling
 584 #ifndef ZERO
 585     set_bcp_and_mdp(handler_pc, current);
 586     continuation = Interpreter::dispatch_table(vtos)[*handler_pc];
 587 #else
 588     continuation = (address)(intptr_t) handler_bci;
 589 #endif
 590   }
 591 
 592   // notify debugger of an exception catch
 593   // (this is good for exceptions caught in native methods as well)
 594   if (JvmtiExport::can_post_on_exceptions()) {
 595     JvmtiExport::notice_unwind_due_to_exception(current, h_method(), handler_pc, h_exception(), (handler_pc != nullptr));
 596   }
 597 
 598   current->set_vm_result(h_exception());
 599   return continuation;
 600 JRT_END
 601 
 602 
 603 JRT_ENTRY(void, InterpreterRuntime::throw_pending_exception(JavaThread* current))
 604   assert(current->has_pending_exception(), "must only be called if there's an exception pending");
 605   // nothing to do - eventually we should remove this code entirely (see comments @ call sites)
 606 JRT_END
 607 
 608 
 609 JRT_ENTRY(void, InterpreterRuntime::throw_AbstractMethodError(JavaThread* current))
 610   THROW(vmSymbols::java_lang_AbstractMethodError());
 611 JRT_END
 612 
 613 // This method is called from the "abstract_entry" of the interpreter.
 614 // At that point, the arguments have already been removed from the stack
 615 // and therefore we don't have the receiver object at our fingertips. (Though,
 616 // on some platforms the receiver still resides in a register...). Thus,
 617 // we have no choice but print an error message not containing the receiver
 618 // type.
 619 JRT_ENTRY(void, InterpreterRuntime::throw_AbstractMethodErrorWithMethod(JavaThread* current,
 620                                                                         Method* missingMethod))
 621   ResourceMark rm(current);
 622   assert(missingMethod != nullptr, "sanity");
 623   methodHandle m(current, missingMethod);
 624   LinkResolver::throw_abstract_method_error(m, THREAD);
 625 JRT_END
 626 
 627 JRT_ENTRY(void, InterpreterRuntime::throw_AbstractMethodErrorVerbose(JavaThread* current,
 628                                                                      Klass* recvKlass,
 629                                                                      Method* missingMethod))
 630   ResourceMark rm(current);
 631   methodHandle mh = methodHandle(current, missingMethod);
 632   LinkResolver::throw_abstract_method_error(mh, recvKlass, THREAD);
 633 JRT_END
 634 
 635 
 636 JRT_ENTRY(void, InterpreterRuntime::throw_IncompatibleClassChangeError(JavaThread* current))
 637   THROW(vmSymbols::java_lang_IncompatibleClassChangeError());
 638 JRT_END
 639 
 640 JRT_ENTRY(void, InterpreterRuntime::throw_IncompatibleClassChangeErrorVerbose(JavaThread* current,
 641                                                                               Klass* recvKlass,
 642                                                                               Klass* interfaceKlass))
 643   ResourceMark rm(current);
 644   char buf[1000];
 645   buf[0] = '\0';
 646   jio_snprintf(buf, sizeof(buf),
 647                "Class %s does not implement the requested interface %s",
 648                recvKlass ? recvKlass->external_name() : "nullptr",
 649                interfaceKlass ? interfaceKlass->external_name() : "nullptr");
 650   THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
 651 JRT_END
 652 
 653 JRT_ENTRY(void, InterpreterRuntime::throw_NullPointerException(JavaThread* current))
 654   THROW(vmSymbols::java_lang_NullPointerException());
 655 JRT_END
 656 
 657 //------------------------------------------------------------------------------------------------------------------------
 658 // Fields
 659 //
 660 
 661 void InterpreterRuntime::resolve_get_put(JavaThread* current, Bytecodes::Code bytecode) {
 662   // resolve field
 663   fieldDescriptor info;
 664   LastFrameAccessor last_frame(current);
 665   constantPoolHandle pool(current, last_frame.method()->constants());
 666   methodHandle m(current, last_frame.method());
 667   bool is_put    = (bytecode == Bytecodes::_putfield  || bytecode == Bytecodes::_nofast_putfield ||
 668                     bytecode == Bytecodes::_putstatic);
 669   bool is_static = (bytecode == Bytecodes::_getstatic || bytecode == Bytecodes::_putstatic);
 670 
 671   int field_index = last_frame.get_index_u2(bytecode);
 672   {
 673     JvmtiHideSingleStepping jhss(current);
 674     JavaThread* THREAD = current; // For exception macros.
 675     LinkResolver::resolve_field_access(info, pool, field_index,
 676                                        m, bytecode, CHECK);
 677   } // end JvmtiHideSingleStepping
 678 
 679   // check if link resolution caused cpCache to be updated
 680   if (pool->resolved_field_entry_at(field_index)->is_resolved(bytecode)) return;
 681 
 682 
 683   // compute auxiliary field attributes
 684   TosState state  = as_TosState(info.field_type());
 685 
 686   // Resolution of put instructions on final fields is delayed. That is required so that
 687   // exceptions are thrown at the correct place (when the instruction is actually invoked).
 688   // If we do not resolve an instruction in the current pass, leaving the put_code
 689   // set to zero will cause the next put instruction to the same field to reresolve.
 690 
 691   // Resolution of put instructions to final instance fields with invalid updates (i.e.,
 692   // to final instance fields with updates originating from a method different than <init>)
 693   // is inhibited. A putfield instruction targeting an instance final field must throw
 694   // an IllegalAccessError if the instruction is not in an instance
 695   // initializer method <init>. If resolution were not inhibited, a putfield
 696   // in an initializer method could be resolved in the initializer. Subsequent
 697   // putfield instructions to the same field would then use cached information.
 698   // As a result, those instructions would not pass through the VM. That is,
 699   // checks in resolve_field_access() would not be executed for those instructions
 700   // and the required IllegalAccessError would not be thrown.
 701   //
 702   // Also, we need to delay resolving getstatic and putstatic instructions until the
 703   // class is initialized.  This is required so that access to the static
 704   // field will call the initialization function every time until the class
 705   // is completely initialized ala. in 2.17.5 in JVM Specification.
 706   InstanceKlass* klass = info.field_holder();
 707   bool uninitialized_static = is_static && !klass->is_initialized();
 708   bool has_initialized_final_update = info.field_holder()->major_version() >= 53 &&
 709                                       info.has_initialized_final_update();
 710   assert(!(has_initialized_final_update && !info.access_flags().is_final()), "Fields with initialized final updates must be final");
 711 
 712   Bytecodes::Code get_code = (Bytecodes::Code)0;
 713   Bytecodes::Code put_code = (Bytecodes::Code)0;
 714   if (!uninitialized_static) {
 715     get_code = ((is_static) ? Bytecodes::_getstatic : Bytecodes::_getfield);
 716     if ((is_put && !has_initialized_final_update) || !info.access_flags().is_final()) {
 717       put_code = ((is_static) ? Bytecodes::_putstatic : Bytecodes::_putfield);
 718     }
 719   }
 720 
 721   ResolvedFieldEntry* entry = pool->resolved_field_entry_at(field_index);
 722   entry->set_flags(info.access_flags().is_final(), info.access_flags().is_volatile());
 723   entry->fill_in(info.field_holder(), info.offset(),
 724                  checked_cast<u2>(info.index()), checked_cast<u1>(state),
 725                  static_cast<u1>(get_code), static_cast<u1>(put_code));
 726 }
 727 
 728 
 729 //------------------------------------------------------------------------------------------------------------------------
 730 // Synchronization
 731 //
 732 // The interpreter's synchronization code is factored out so that it can
 733 // be shared by method invocation and synchronized blocks.
 734 //%note synchronization_3
 735 
 736 //%note monitor_1
 737 JRT_ENTRY_NO_ASYNC(void, InterpreterRuntime::monitorenter(JavaThread* current, BasicObjectLock* elem))
 738   assert(LockingMode != LM_LIGHTWEIGHT, "Should call monitorenter_obj() when using the new lightweight locking");
 739 #ifdef ASSERT
 740   current->last_frame().interpreter_frame_verify_monitor(elem);
 741 #endif
 742   Handle h_obj(current, elem->obj());
 743   assert(Universe::heap()->is_in_or_null(h_obj()),
 744          "must be null or an object");
 745   ThreadOnMonitorEnter tme(current);
 746   ObjectSynchronizer::enter(h_obj, elem->lock(), current);
 747   assert(Universe::heap()->is_in_or_null(elem->obj()),
 748          "must be null or an object");
 749 #ifdef ASSERT
 750   if (!current->preempting()) current->last_frame().interpreter_frame_verify_monitor(elem);
 751 #endif
 752 JRT_END
 753 
 754 // NOTE: We provide a separate implementation for the new lightweight locking to workaround a limitation
 755 // of registers in x86_32. This entry point accepts an oop instead of a BasicObjectLock*.
 756 // The problem is that we would need to preserve the register that holds the BasicObjectLock,
 757 // but we are using that register to hold the thread. We don't have enough registers to
 758 // also keep the BasicObjectLock, but we don't really need it anyway, we only need
 759 // the object. See also InterpreterMacroAssembler::lock_object().
 760 // As soon as legacy stack-locking goes away we could remove the other monitorenter() entry
 761 // point, and only use oop-accepting entries (same for monitorexit() below).
 762 JRT_ENTRY_NO_ASYNC(void, InterpreterRuntime::monitorenter_obj(JavaThread* current, oopDesc* obj))
 763   assert(LockingMode == LM_LIGHTWEIGHT, "Should call monitorenter() when not using the new lightweight locking");
 764   Handle h_obj(current, cast_to_oop(obj));
 765   assert(Universe::heap()->is_in_or_null(h_obj()),
 766          "must be null or an object");
 767   ThreadOnMonitorEnter tme(current);
 768   ObjectSynchronizer::enter(h_obj, nullptr, current);
 769   return;
 770 JRT_END
 771 
 772 JRT_LEAF(void, InterpreterRuntime::monitorexit(BasicObjectLock* elem))
 773   oop obj = elem->obj();
 774   assert(Universe::heap()->is_in(obj), "must be an object");
 775   // The object could become unlocked through a JNI call, which we have no other checks for.
 776   // Give a fatal message if CheckJNICalls. Otherwise we ignore it.
 777   if (obj->is_unlocked()) {
 778     if (CheckJNICalls) {
 779       fatal("Object has been unlocked by JNI");
 780     }
 781     return;
 782   }
 783   ObjectSynchronizer::exit(obj, elem->lock(), JavaThread::current());
 784   // Free entry. If it is not cleared, the exception handling code will try to unlock the monitor
 785   // again at method exit or in the case of an exception.
 786   elem->set_obj(nullptr);
 787 JRT_END
 788 
 789 
 790 JRT_ENTRY(void, InterpreterRuntime::throw_illegal_monitor_state_exception(JavaThread* current))
 791   THROW(vmSymbols::java_lang_IllegalMonitorStateException());
 792 JRT_END
 793 
 794 
 795 JRT_ENTRY(void, InterpreterRuntime::new_illegal_monitor_state_exception(JavaThread* current))
 796   // Returns an illegal exception to install into the current thread. The
 797   // pending_exception flag is cleared so normal exception handling does not
 798   // trigger. Any current installed exception will be overwritten. This
 799   // method will be called during an exception unwind.
 800 
 801   assert(!HAS_PENDING_EXCEPTION, "no pending exception");
 802   Handle exception(current, current->vm_result());
 803   assert(exception() != nullptr, "vm result should be set");
 804   current->set_vm_result(nullptr); // clear vm result before continuing (may cause memory leaks and assert failures)
 805   exception = get_preinitialized_exception(vmClasses::IllegalMonitorStateException_klass(), CATCH);
 806   current->set_vm_result(exception());
 807 JRT_END
 808 
 809 
 810 //------------------------------------------------------------------------------------------------------------------------
 811 // Invokes
 812 
 813 JRT_ENTRY(Bytecodes::Code, InterpreterRuntime::get_original_bytecode_at(JavaThread* current, Method* method, address bcp))
 814   return method->orig_bytecode_at(method->bci_from(bcp));
 815 JRT_END
 816 
 817 JRT_ENTRY(void, InterpreterRuntime::set_original_bytecode_at(JavaThread* current, Method* method, address bcp, Bytecodes::Code new_code))
 818   method->set_orig_bytecode_at(method->bci_from(bcp), new_code);
 819 JRT_END
 820 
 821 JRT_ENTRY(void, InterpreterRuntime::_breakpoint(JavaThread* current, Method* method, address bcp))
 822   JvmtiExport::post_raw_breakpoint(current, method, bcp);
 823 JRT_END
 824 
 825 void InterpreterRuntime::resolve_invoke(JavaThread* current, Bytecodes::Code bytecode) {
 826   LastFrameAccessor last_frame(current);
 827   // extract receiver from the outgoing argument list if necessary
 828   Handle receiver(current, nullptr);
 829   if (bytecode == Bytecodes::_invokevirtual || bytecode == Bytecodes::_invokeinterface ||
 830       bytecode == Bytecodes::_invokespecial) {
 831     ResourceMark rm(current);
 832     methodHandle m (current, last_frame.method());
 833     Bytecode_invoke call(m, last_frame.bci());
 834     Symbol* signature = call.signature();
 835     receiver = Handle(current, last_frame.callee_receiver(signature));
 836 
 837     assert(Universe::heap()->is_in_or_null(receiver()),
 838            "sanity check");
 839     assert(receiver.is_null() ||
 840            !Universe::heap()->is_in(receiver->klass()),
 841            "sanity check");
 842   }
 843 
 844   // resolve method
 845   CallInfo info;
 846   constantPoolHandle pool(current, last_frame.method()->constants());
 847   ConstantPoolCache* cache = pool->cache();
 848 
 849   methodHandle resolved_method;
 850 
 851   int method_index = last_frame.get_index_u2(bytecode);
 852   {
 853     JvmtiHideSingleStepping jhss(current);
 854     JavaThread* THREAD = current; // For exception macros.
 855     LinkResolver::resolve_invoke(info, receiver, pool,
 856                                  method_index, bytecode,
 857                                  THREAD);
 858 
 859     if (HAS_PENDING_EXCEPTION) {
 860       if (ProfileTraps && PENDING_EXCEPTION->klass()->name() == vmSymbols::java_lang_NullPointerException()) {
 861         // Preserve the original exception across the call to note_trap()
 862         PreserveExceptionMark pm(current);
 863         // Recording the trap will help the compiler to potentially recognize this exception as "hot"
 864         note_trap(current, Deoptimization::Reason_null_check);
 865       }
 866       return;
 867     }
 868 
 869     if (JvmtiExport::can_hotswap_or_post_breakpoint() && info.resolved_method()->is_old()) {
 870       resolved_method = methodHandle(current, info.resolved_method()->get_new_method());
 871     } else {
 872       resolved_method = methodHandle(current, info.resolved_method());
 873     }
 874   } // end JvmtiHideSingleStepping
 875 
 876   // check if link resolution caused cpCache to be updated
 877   if (cache->resolved_method_entry_at(method_index)->is_resolved(bytecode)) return;
 878 
 879 #ifdef ASSERT
 880   if (bytecode == Bytecodes::_invokeinterface) {
 881     if (resolved_method->method_holder() == vmClasses::Object_klass()) {
 882       // NOTE: THIS IS A FIX FOR A CORNER CASE in the JVM spec
 883       // (see also CallInfo::set_interface for details)
 884       assert(info.call_kind() == CallInfo::vtable_call ||
 885              info.call_kind() == CallInfo::direct_call, "");
 886       assert(resolved_method->is_final() || info.has_vtable_index(),
 887              "should have been set already");
 888     } else if (!resolved_method->has_itable_index()) {
 889       // Resolved something like CharSequence.toString.  Use vtable not itable.
 890       assert(info.call_kind() != CallInfo::itable_call, "");
 891     } else {
 892       // Setup itable entry
 893       assert(info.call_kind() == CallInfo::itable_call, "");
 894       int index = resolved_method->itable_index();
 895       assert(info.itable_index() == index, "");
 896     }
 897   } else if (bytecode == Bytecodes::_invokespecial) {
 898     assert(info.call_kind() == CallInfo::direct_call, "must be direct call");
 899   } else {
 900     assert(info.call_kind() == CallInfo::direct_call ||
 901            info.call_kind() == CallInfo::vtable_call, "");
 902   }
 903 #endif
 904   // Get sender and only set cpCache entry to resolved if it is not an
 905   // interface.  The receiver for invokespecial calls within interface
 906   // methods must be checked for every call.
 907   InstanceKlass* sender = pool->pool_holder();
 908 
 909   switch (info.call_kind()) {
 910   case CallInfo::direct_call:
 911     cache->set_direct_call(bytecode, method_index, resolved_method, sender->is_interface());
 912     break;
 913   case CallInfo::vtable_call:
 914     cache->set_vtable_call(bytecode, method_index, resolved_method, info.vtable_index());
 915     break;
 916   case CallInfo::itable_call:
 917     cache->set_itable_call(
 918       bytecode,
 919       method_index,
 920       info.resolved_klass(),
 921       resolved_method,
 922       info.itable_index());
 923     break;
 924   default:  ShouldNotReachHere();
 925   }
 926 }
 927 
 928 
 929 // First time execution:  Resolve symbols, create a permanent MethodType object.
 930 void InterpreterRuntime::resolve_invokehandle(JavaThread* current) {
 931   const Bytecodes::Code bytecode = Bytecodes::_invokehandle;
 932   LastFrameAccessor last_frame(current);
 933 
 934   // resolve method
 935   CallInfo info;
 936   constantPoolHandle pool(current, last_frame.method()->constants());
 937   int method_index = last_frame.get_index_u2(bytecode);
 938   {
 939     JvmtiHideSingleStepping jhss(current);
 940     JavaThread* THREAD = current; // For exception macros.
 941     LinkResolver::resolve_invoke(info, Handle(), pool,
 942                                  method_index, bytecode,
 943                                  CHECK);
 944   } // end JvmtiHideSingleStepping
 945 
 946   pool->cache()->set_method_handle(method_index, info);
 947 }
 948 
 949 // First time execution:  Resolve symbols, create a permanent CallSite object.
 950 void InterpreterRuntime::resolve_invokedynamic(JavaThread* current) {
 951   LastFrameAccessor last_frame(current);
 952   const Bytecodes::Code bytecode = Bytecodes::_invokedynamic;
 953 
 954   // resolve method
 955   CallInfo info;
 956   constantPoolHandle pool(current, last_frame.method()->constants());
 957   int index = last_frame.get_index_u4(bytecode);
 958   {
 959     JvmtiHideSingleStepping jhss(current);
 960     JavaThread* THREAD = current; // For exception macros.
 961     LinkResolver::resolve_invoke(info, Handle(), pool,
 962                                  index, bytecode, CHECK);
 963   } // end JvmtiHideSingleStepping
 964 
 965   pool->cache()->set_dynamic_call(info, pool->decode_invokedynamic_index(index));
 966 }
 967 
 968 // This function is the interface to the assembly code. It returns the resolved
 969 // cpCache entry.  This doesn't safepoint, but the helper routines safepoint.
 970 // This function will check for redefinition!
 971 JRT_ENTRY(void, InterpreterRuntime::resolve_from_cache(JavaThread* current, Bytecodes::Code bytecode)) {
 972   switch (bytecode) {
 973   case Bytecodes::_getstatic:
 974   case Bytecodes::_putstatic:
 975   case Bytecodes::_getfield:
 976   case Bytecodes::_putfield:
 977     resolve_get_put(current, bytecode);
 978     break;
 979   case Bytecodes::_invokevirtual:
 980   case Bytecodes::_invokespecial:
 981   case Bytecodes::_invokestatic:
 982   case Bytecodes::_invokeinterface:
 983     resolve_invoke(current, bytecode);
 984     break;
 985   case Bytecodes::_invokehandle:
 986     resolve_invokehandle(current);
 987     break;
 988   case Bytecodes::_invokedynamic:
 989     resolve_invokedynamic(current);
 990     break;
 991   default:
 992     fatal("unexpected bytecode: %s", Bytecodes::name(bytecode));
 993     break;
 994   }
 995 }
 996 JRT_END
 997 
 998 //------------------------------------------------------------------------------------------------------------------------
 999 // Miscellaneous
1000 
1001 
1002 nmethod* InterpreterRuntime::frequency_counter_overflow(JavaThread* current, address branch_bcp) {
1003   // Enable WXWrite: the function is called directly by interpreter.
1004   MACOS_AARCH64_ONLY(ThreadWXEnable wx(WXWrite, current));
1005 
1006   // frequency_counter_overflow_inner can throw async exception.
1007   nmethod* nm = frequency_counter_overflow_inner(current, branch_bcp);
1008   assert(branch_bcp != nullptr || nm == nullptr, "always returns null for non OSR requests");
1009   if (branch_bcp != nullptr && nm != nullptr) {
1010     // This was a successful request for an OSR nmethod.  Because
1011     // frequency_counter_overflow_inner ends with a safepoint check,
1012     // nm could have been unloaded so look it up again.  It's unsafe
1013     // to examine nm directly since it might have been freed and used
1014     // for something else.
1015     LastFrameAccessor last_frame(current);
1016     Method* method =  last_frame.method();
1017     int bci = method->bci_from(last_frame.bcp());
1018     nm = method->lookup_osr_nmethod_for(bci, CompLevel_none, false);
1019     BarrierSetNMethod* bs_nm = BarrierSet::barrier_set()->barrier_set_nmethod();
1020     if (nm != nullptr && bs_nm != nullptr) {
1021       // in case the transition passed a safepoint we need to barrier this again
1022       if (!bs_nm->nmethod_osr_entry_barrier(nm)) {
1023         nm = nullptr;
1024       }
1025     }
1026   }
1027   if (nm != nullptr && current->is_interp_only_mode()) {
1028     // Normally we never get an nm if is_interp_only_mode() is true, because
1029     // policy()->event has a check for this and won't compile the method when
1030     // true. However, it's possible for is_interp_only_mode() to become true
1031     // during the compilation. We don't want to return the nm in that case
1032     // because we want to continue to execute interpreted.
1033     nm = nullptr;
1034   }
1035 #ifndef PRODUCT
1036   if (TraceOnStackReplacement) {
1037     if (nm != nullptr) {
1038       tty->print("OSR entry @ pc: " INTPTR_FORMAT ": ", p2i(nm->osr_entry()));
1039       nm->print();
1040     }
1041   }
1042 #endif
1043   return nm;
1044 }
1045 
1046 JRT_ENTRY(nmethod*,
1047           InterpreterRuntime::frequency_counter_overflow_inner(JavaThread* current, address branch_bcp))
1048   // use UnlockFlagSaver to clear and restore the _do_not_unlock_if_synchronized
1049   // flag, in case this method triggers classloading which will call into Java.
1050   UnlockFlagSaver fs(current);
1051 
1052   LastFrameAccessor last_frame(current);
1053   assert(last_frame.is_interpreted_frame(), "must come from interpreter");
1054   methodHandle method(current, last_frame.method());
1055   const int branch_bci = branch_bcp != nullptr ? method->bci_from(branch_bcp) : InvocationEntryBci;
1056   const int bci = branch_bcp != nullptr ? method->bci_from(last_frame.bcp()) : InvocationEntryBci;
1057 
1058   nmethod* osr_nm = CompilationPolicy::event(method, method, branch_bci, bci, CompLevel_none, nullptr, CHECK_NULL);
1059 
1060   BarrierSetNMethod* bs_nm = BarrierSet::barrier_set()->barrier_set_nmethod();
1061   if (osr_nm != nullptr && bs_nm != nullptr) {
1062     if (!bs_nm->nmethod_osr_entry_barrier(osr_nm)) {
1063       osr_nm = nullptr;
1064     }
1065   }
1066   return osr_nm;
1067 JRT_END
1068 
1069 JRT_LEAF(jint, InterpreterRuntime::bcp_to_di(Method* method, address cur_bcp))
1070   assert(ProfileInterpreter, "must be profiling interpreter");
1071   int bci = method->bci_from(cur_bcp);
1072   MethodData* mdo = method->method_data();
1073   if (mdo == nullptr)  return 0;
1074   return mdo->bci_to_di(bci);
1075 JRT_END
1076 
1077 #ifdef ASSERT
1078 JRT_LEAF(void, InterpreterRuntime::verify_mdp(Method* method, address bcp, address mdp))
1079   assert(ProfileInterpreter, "must be profiling interpreter");
1080 
1081   MethodData* mdo = method->method_data();
1082   assert(mdo != nullptr, "must not be null");
1083 
1084   int bci = method->bci_from(bcp);
1085 
1086   address mdp2 = mdo->bci_to_dp(bci);
1087   if (mdp != mdp2) {
1088     ResourceMark rm;
1089     tty->print_cr("FAILED verify : actual mdp %p   expected mdp %p @ bci %d", mdp, mdp2, bci);
1090     int current_di = mdo->dp_to_di(mdp);
1091     int expected_di  = mdo->dp_to_di(mdp2);
1092     tty->print_cr("  actual di %d   expected di %d", current_di, expected_di);
1093     int expected_approx_bci = mdo->data_at(expected_di)->bci();
1094     int approx_bci = -1;
1095     if (current_di >= 0) {
1096       approx_bci = mdo->data_at(current_di)->bci();
1097     }
1098     tty->print_cr("  actual bci is %d  expected bci %d", approx_bci, expected_approx_bci);
1099     mdo->print_on(tty);
1100     method->print_codes();
1101   }
1102   assert(mdp == mdp2, "wrong mdp");
1103 JRT_END
1104 #endif // ASSERT
1105 
1106 JRT_ENTRY(void, InterpreterRuntime::update_mdp_for_ret(JavaThread* current, int return_bci))
1107   assert(ProfileInterpreter, "must be profiling interpreter");
1108   ResourceMark rm(current);
1109   LastFrameAccessor last_frame(current);
1110   assert(last_frame.is_interpreted_frame(), "must come from interpreter");
1111   MethodData* h_mdo = last_frame.method()->method_data();
1112 
1113   // Grab a lock to ensure atomic access to setting the return bci and
1114   // the displacement.  This can block and GC, invalidating all naked oops.
1115   MutexLocker ml(RetData_lock);
1116 
1117   // ProfileData is essentially a wrapper around a derived oop, so we
1118   // need to take the lock before making any ProfileData structures.
1119   ProfileData* data = h_mdo->data_at(h_mdo->dp_to_di(last_frame.mdp()));
1120   guarantee(data != nullptr, "profile data must be valid");
1121   RetData* rdata = data->as_RetData();
1122   address new_mdp = rdata->fixup_ret(return_bci, h_mdo);
1123   last_frame.set_mdp(new_mdp);
1124 JRT_END
1125 
1126 JRT_ENTRY(MethodCounters*, InterpreterRuntime::build_method_counters(JavaThread* current, Method* m))
1127   return Method::build_method_counters(current, m);
1128 JRT_END
1129 
1130 
1131 JRT_ENTRY(void, InterpreterRuntime::at_safepoint(JavaThread* current))
1132   // We used to need an explicit preserve_arguments here for invoke bytecodes. However,
1133   // stack traversal automatically takes care of preserving arguments for invoke, so
1134   // this is no longer needed.
1135 
1136   // JRT_END does an implicit safepoint check, hence we are guaranteed to block
1137   // if this is called during a safepoint
1138 
1139   if (JvmtiExport::should_post_single_step()) {
1140     // This function is called by the interpreter when single stepping. Such single
1141     // stepping could unwind a frame. Then, it is important that we process any frames
1142     // that we might return into.
1143     StackWatermarkSet::before_unwind(current);
1144 
1145     // We are called during regular safepoints and when the VM is
1146     // single stepping. If any thread is marked for single stepping,
1147     // then we may have JVMTI work to do.
1148     LastFrameAccessor last_frame(current);
1149     JvmtiExport::at_single_stepping_point(current, last_frame.method(), last_frame.bcp());
1150   }
1151 JRT_END
1152 
1153 JRT_LEAF(void, InterpreterRuntime::at_unwind(JavaThread* current))
1154   assert(current == JavaThread::current(), "pre-condition");
1155   // This function is called by the interpreter when the return poll found a reason
1156   // to call the VM. The reason could be that we are returning into a not yet safe
1157   // to access frame. We handle that below.
1158   // Note that this path does not check for single stepping, because we do not want
1159   // to single step when unwinding frames for an exception being thrown. Instead,
1160   // such single stepping code will use the safepoint table, which will use the
1161   // InterpreterRuntime::at_safepoint callback.
1162   StackWatermarkSet::before_unwind(current);
1163 JRT_END
1164 
1165 JRT_ENTRY(void, InterpreterRuntime::post_field_access(JavaThread* current, oopDesc* obj,
1166                                                       ResolvedFieldEntry *entry))
1167 
1168   // check the access_flags for the field in the klass
1169 
1170   InstanceKlass* ik = entry->field_holder();
1171   int index = entry->field_index();
1172   if (!ik->field_status(index).is_access_watched()) return;
1173 
1174   bool is_static = (obj == nullptr);
1175   HandleMark hm(current);
1176 
1177   Handle h_obj;
1178   if (!is_static) {
1179     // non-static field accessors have an object, but we need a handle
1180     h_obj = Handle(current, obj);
1181   }
1182   InstanceKlass* field_holder = entry->field_holder(); // HERE
1183   jfieldID fid = jfieldIDWorkaround::to_jfieldID(field_holder, entry->field_offset(), is_static);
1184   LastFrameAccessor last_frame(current);
1185   JvmtiExport::post_field_access(current, last_frame.method(), last_frame.bcp(), field_holder, h_obj, fid);
1186 JRT_END
1187 
1188 JRT_ENTRY(void, InterpreterRuntime::post_field_modification(JavaThread* current, oopDesc* obj,
1189                                                             ResolvedFieldEntry *entry, jvalue *value))
1190 
1191   InstanceKlass* ik = entry->field_holder();
1192 
1193   // check the access_flags for the field in the klass
1194   int index = entry->field_index();
1195   // bail out if field modifications are not watched
1196   if (!ik->field_status(index).is_modification_watched()) return;
1197 
1198   char sig_type = '\0';
1199 
1200   switch((TosState)entry->tos_state()) {
1201     case btos: sig_type = JVM_SIGNATURE_BYTE;    break;
1202     case ztos: sig_type = JVM_SIGNATURE_BOOLEAN; break;
1203     case ctos: sig_type = JVM_SIGNATURE_CHAR;    break;
1204     case stos: sig_type = JVM_SIGNATURE_SHORT;   break;
1205     case itos: sig_type = JVM_SIGNATURE_INT;     break;
1206     case ftos: sig_type = JVM_SIGNATURE_FLOAT;   break;
1207     case atos: sig_type = JVM_SIGNATURE_CLASS;   break;
1208     case ltos: sig_type = JVM_SIGNATURE_LONG;    break;
1209     case dtos: sig_type = JVM_SIGNATURE_DOUBLE;  break;
1210     default:  ShouldNotReachHere(); return;
1211   }
1212   bool is_static = (obj == nullptr);
1213 
1214   HandleMark hm(current);
1215   jfieldID fid = jfieldIDWorkaround::to_jfieldID(ik, entry->field_offset(), is_static);
1216   jvalue fvalue;
1217 #ifdef _LP64
1218   fvalue = *value;
1219 #else
1220   // Long/double values are stored unaligned and also noncontiguously with
1221   // tagged stacks.  We can't just do a simple assignment even in the non-
1222   // J/D cases because a C++ compiler is allowed to assume that a jvalue is
1223   // 8-byte aligned, and interpreter stack slots are only 4-byte aligned.
1224   // We assume that the two halves of longs/doubles are stored in interpreter
1225   // stack slots in platform-endian order.
1226   jlong_accessor u;
1227   jint* newval = (jint*)value;
1228   u.words[0] = newval[0];
1229   u.words[1] = newval[Interpreter::stackElementWords]; // skip if tag
1230   fvalue.j = u.long_value;
1231 #endif // _LP64
1232 
1233   Handle h_obj;
1234   if (!is_static) {
1235     // non-static field accessors have an object, but we need a handle
1236     h_obj = Handle(current, obj);
1237   }
1238 
1239   LastFrameAccessor last_frame(current);
1240   JvmtiExport::post_raw_field_modification(current, last_frame.method(), last_frame.bcp(), ik, h_obj,
1241                                            fid, sig_type, &fvalue);
1242 JRT_END
1243 
1244 JRT_ENTRY(void, InterpreterRuntime::post_method_entry(JavaThread* current))
1245   LastFrameAccessor last_frame(current);
1246   JvmtiExport::post_method_entry(current, last_frame.method(), last_frame.get_frame());
1247 JRT_END
1248 
1249 
1250 // This is a JRT_BLOCK_ENTRY because we have to stash away the return oop
1251 // before transitioning to VM, and restore it after transitioning back
1252 // to Java. The return oop at the top-of-stack, is not walked by the GC.
1253 JRT_BLOCK_ENTRY(void, InterpreterRuntime::post_method_exit(JavaThread* current))
1254   LastFrameAccessor last_frame(current);
1255   JvmtiExport::post_method_exit(current, last_frame.method(), last_frame.get_frame());
1256 JRT_END
1257 
1258 JRT_LEAF(int, InterpreterRuntime::interpreter_contains(address pc))
1259 {
1260   return (Interpreter::contains(Continuation::get_top_return_pc_post_barrier(JavaThread::current(), pc)) ? 1 : 0);
1261 }
1262 JRT_END
1263 
1264 
1265 // Implementation of SignatureHandlerLibrary
1266 
1267 #ifndef SHARING_FAST_NATIVE_FINGERPRINTS
1268 // Dummy definition (else normalization method is defined in CPU
1269 // dependent code)
1270 uint64_t InterpreterRuntime::normalize_fast_native_fingerprint(uint64_t fingerprint) {
1271   return fingerprint;
1272 }
1273 #endif
1274 
1275 address SignatureHandlerLibrary::set_handler_blob() {
1276   BufferBlob* handler_blob = BufferBlob::create("native signature handlers", blob_size);
1277   if (handler_blob == nullptr) {
1278     return nullptr;
1279   }
1280   address handler = handler_blob->code_begin();
1281   _handler_blob = handler_blob;
1282   _handler = handler;
1283   return handler;
1284 }
1285 
1286 void SignatureHandlerLibrary::initialize() {
1287   if (_fingerprints != nullptr) {
1288     return;
1289   }
1290   if (set_handler_blob() == nullptr) {
1291     vm_exit_out_of_memory(blob_size, OOM_MALLOC_ERROR, "native signature handlers");
1292   }
1293 
1294   BufferBlob* bb = BufferBlob::create("Signature Handler Temp Buffer",
1295                                       SignatureHandlerLibrary::buffer_size);
1296   _buffer = bb->code_begin();
1297 
1298   _fingerprints = new (mtCode) GrowableArray<uint64_t>(32, mtCode);
1299   _handlers     = new (mtCode) GrowableArray<address>(32, mtCode);
1300 }
1301 
1302 address SignatureHandlerLibrary::set_handler(CodeBuffer* buffer) {
1303   address handler   = _handler;
1304   int     insts_size = buffer->pure_insts_size();
1305   if (handler + insts_size > _handler_blob->code_end()) {
1306     // get a new handler blob
1307     handler = set_handler_blob();
1308   }
1309   if (handler != nullptr) {
1310     memcpy(handler, buffer->insts_begin(), insts_size);
1311     pd_set_handler(handler);
1312     ICache::invalidate_range(handler, insts_size);
1313     _handler = handler + insts_size;
1314   }
1315   return handler;
1316 }
1317 
1318 void SignatureHandlerLibrary::add(const methodHandle& method) {
1319   if (method->signature_handler() == nullptr) {
1320     // use slow signature handler if we can't do better
1321     int handler_index = -1;
1322     // check if we can use customized (fast) signature handler
1323     if (UseFastSignatureHandlers && method->size_of_parameters() <= Fingerprinter::fp_max_size_of_parameters) {
1324       // use customized signature handler
1325       MutexLocker mu(SignatureHandlerLibrary_lock);
1326       // make sure data structure is initialized
1327       initialize();
1328       // lookup method signature's fingerprint
1329       uint64_t fingerprint = Fingerprinter(method).fingerprint();
1330       // allow CPU dependent code to optimize the fingerprints for the fast handler
1331       fingerprint = InterpreterRuntime::normalize_fast_native_fingerprint(fingerprint);
1332       handler_index = _fingerprints->find(fingerprint);
1333       // create handler if necessary
1334       if (handler_index < 0) {
1335         ResourceMark rm;
1336         ptrdiff_t align_offset = align_up(_buffer, CodeEntryAlignment) - (address)_buffer;
1337         CodeBuffer buffer((address)(_buffer + align_offset),
1338                           checked_cast<int>(SignatureHandlerLibrary::buffer_size - align_offset));
1339         InterpreterRuntime::SignatureHandlerGenerator(method, &buffer).generate(fingerprint);
1340         // copy into code heap
1341         address handler = set_handler(&buffer);
1342         if (handler == nullptr) {
1343           // use slow signature handler (without memorizing it in the fingerprints)
1344         } else {
1345           // debugging support
1346           if (PrintSignatureHandlers && (handler != Interpreter::slow_signature_handler())) {
1347             ttyLocker ttyl;
1348             tty->cr();
1349             tty->print_cr("argument handler #%d for: %s %s (fingerprint = " UINT64_FORMAT ", %d bytes generated)",
1350                           _handlers->length(),
1351                           (method->is_static() ? "static" : "receiver"),
1352                           method->name_and_sig_as_C_string(),
1353                           fingerprint,
1354                           buffer.insts_size());
1355             if (buffer.insts_size() > 0) {
1356               Disassembler::decode(handler, handler + buffer.insts_size(), tty
1357                                    NOT_PRODUCT(COMMA &buffer.asm_remarks()));
1358             }
1359 #ifndef PRODUCT
1360             address rh_begin = Interpreter::result_handler(method()->result_type());
1361             if (CodeCache::contains(rh_begin)) {
1362               // else it might be special platform dependent values
1363               tty->print_cr(" --- associated result handler ---");
1364               address rh_end = rh_begin;
1365               while (*(int*)rh_end != 0) {
1366                 rh_end += sizeof(int);
1367               }
1368               Disassembler::decode(rh_begin, rh_end);
1369             } else {
1370               tty->print_cr(" associated result handler: " PTR_FORMAT, p2i(rh_begin));
1371             }
1372 #endif
1373           }
1374           // add handler to library
1375           _fingerprints->append(fingerprint);
1376           _handlers->append(handler);
1377           // set handler index
1378           assert(_fingerprints->length() == _handlers->length(), "sanity check");
1379           handler_index = _fingerprints->length() - 1;
1380         }
1381       }
1382       // Set handler under SignatureHandlerLibrary_lock
1383       if (handler_index < 0) {
1384         // use generic signature handler
1385         method->set_signature_handler(Interpreter::slow_signature_handler());
1386       } else {
1387         // set handler
1388         method->set_signature_handler(_handlers->at(handler_index));
1389       }
1390     } else {
1391       DEBUG_ONLY(JavaThread::current()->check_possible_safepoint());
1392       // use generic signature handler
1393       method->set_signature_handler(Interpreter::slow_signature_handler());
1394     }
1395   }
1396 #ifdef ASSERT
1397   int handler_index = -1;
1398   int fingerprint_index = -2;
1399   {
1400     // '_handlers' and '_fingerprints' are 'GrowableArray's and are NOT synchronized
1401     // in any way if accessed from multiple threads. To avoid races with another
1402     // thread which may change the arrays in the above, mutex protected block, we
1403     // have to protect this read access here with the same mutex as well!
1404     MutexLocker mu(SignatureHandlerLibrary_lock);
1405     if (_handlers != nullptr) {
1406       handler_index = _handlers->find(method->signature_handler());
1407       uint64_t fingerprint = Fingerprinter(method).fingerprint();
1408       fingerprint = InterpreterRuntime::normalize_fast_native_fingerprint(fingerprint);
1409       fingerprint_index = _fingerprints->find(fingerprint);
1410     }
1411   }
1412   assert(method->signature_handler() == Interpreter::slow_signature_handler() ||
1413          handler_index == fingerprint_index, "sanity check");
1414 #endif // ASSERT
1415 }
1416 
1417 void SignatureHandlerLibrary::add(uint64_t fingerprint, address handler) {
1418   int handler_index = -1;
1419   // use customized signature handler
1420   MutexLocker mu(SignatureHandlerLibrary_lock);
1421   // make sure data structure is initialized
1422   initialize();
1423   fingerprint = InterpreterRuntime::normalize_fast_native_fingerprint(fingerprint);
1424   handler_index = _fingerprints->find(fingerprint);
1425   // create handler if necessary
1426   if (handler_index < 0) {
1427     if (PrintSignatureHandlers && (handler != Interpreter::slow_signature_handler())) {
1428       tty->cr();
1429       tty->print_cr("argument handler #%d at " PTR_FORMAT " for fingerprint " UINT64_FORMAT,
1430                     _handlers->length(),
1431                     p2i(handler),
1432                     fingerprint);
1433     }
1434     _fingerprints->append(fingerprint);
1435     _handlers->append(handler);
1436   } else {
1437     if (PrintSignatureHandlers) {
1438       tty->cr();
1439       tty->print_cr("duplicate argument handler #%d for fingerprint " UINT64_FORMAT "(old: " PTR_FORMAT ", new : " PTR_FORMAT ")",
1440                     _handlers->length(),
1441                     fingerprint,
1442                     p2i(_handlers->at(handler_index)),
1443                     p2i(handler));
1444     }
1445   }
1446 }
1447 
1448 
1449 BufferBlob*              SignatureHandlerLibrary::_handler_blob = nullptr;
1450 address                  SignatureHandlerLibrary::_handler      = nullptr;
1451 GrowableArray<uint64_t>* SignatureHandlerLibrary::_fingerprints = nullptr;
1452 GrowableArray<address>*  SignatureHandlerLibrary::_handlers     = nullptr;
1453 address                  SignatureHandlerLibrary::_buffer       = nullptr;
1454 
1455 
1456 JRT_ENTRY(void, InterpreterRuntime::prepare_native_call(JavaThread* current, Method* method))
1457   methodHandle m(current, method);
1458   assert(m->is_native(), "sanity check");
1459   // lookup native function entry point if it doesn't exist
1460   if (!m->has_native_function()) {
1461     NativeLookup::lookup(m, CHECK);
1462   }
1463   // make sure signature handler is installed
1464   SignatureHandlerLibrary::add(m);
1465   // The interpreter entry point checks the signature handler first,
1466   // before trying to fetch the native entry point and klass mirror.
1467   // We must set the signature handler last, so that multiple processors
1468   // preparing the same method will be sure to see non-null entry & mirror.
1469 JRT_END
1470 
1471 #if defined(IA32) || defined(AMD64) || defined(ARM)
1472 JRT_LEAF(void, InterpreterRuntime::popframe_move_outgoing_args(JavaThread* current, void* src_address, void* dest_address))
1473   assert(current == JavaThread::current(), "pre-condition");
1474   if (src_address == dest_address) {
1475     return;
1476   }
1477   ResourceMark rm;
1478   LastFrameAccessor last_frame(current);
1479   assert(last_frame.is_interpreted_frame(), "");
1480   jint bci = last_frame.bci();
1481   methodHandle mh(current, last_frame.method());
1482   Bytecode_invoke invoke(mh, bci);
1483   ArgumentSizeComputer asc(invoke.signature());
1484   int size_of_arguments = (asc.size() + (invoke.has_receiver() ? 1 : 0)); // receiver
1485   Copy::conjoint_jbytes(src_address, dest_address,
1486                        size_of_arguments * Interpreter::stackElementSize);
1487 JRT_END
1488 #endif
1489 
1490 #if INCLUDE_JVMTI
1491 // This is a support of the JVMTI PopFrame interface.
1492 // Make sure it is an invokestatic of a polymorphic intrinsic that has a member_name argument
1493 // and return it as a vm_result so that it can be reloaded in the list of invokestatic parameters.
1494 // The member_name argument is a saved reference (in local#0) to the member_name.
1495 // For backward compatibility with some JDK versions (7, 8) it can also be a direct method handle.
1496 // FIXME: remove DMH case after j.l.i.InvokerBytecodeGenerator code shape is updated.
1497 JRT_ENTRY(void, InterpreterRuntime::member_name_arg_or_null(JavaThread* current, address member_name,
1498                                                             Method* method, address bcp))
1499   Bytecodes::Code code = Bytecodes::code_at(method, bcp);
1500   if (code != Bytecodes::_invokestatic) {
1501     return;
1502   }
1503   ConstantPool* cpool = method->constants();
1504   int cp_index = Bytes::get_native_u2(bcp + 1);
1505   Symbol* cname = cpool->klass_name_at(cpool->klass_ref_index_at(cp_index, code));
1506   Symbol* mname = cpool->name_ref_at(cp_index, code);
1507 
1508   if (MethodHandles::has_member_arg(cname, mname)) {
1509     oop member_name_oop = cast_to_oop(member_name);
1510     if (java_lang_invoke_DirectMethodHandle::is_instance(member_name_oop)) {
1511       // FIXME: remove after j.l.i.InvokerBytecodeGenerator code shape is updated.
1512       member_name_oop = java_lang_invoke_DirectMethodHandle::member(member_name_oop);
1513     }
1514     current->set_vm_result(member_name_oop);
1515   } else {
1516     current->set_vm_result(nullptr);
1517   }
1518 JRT_END
1519 #endif // INCLUDE_JVMTI
1520 
1521 #ifndef PRODUCT
1522 // This must be a JRT_LEAF function because the interpreter must save registers on x86 to
1523 // call this, which changes rsp and makes the interpreter's expression stack not walkable.
1524 // The generated code still uses call_VM because that will set up the frame pointer for
1525 // bcp and method.
1526 JRT_LEAF(intptr_t, InterpreterRuntime::trace_bytecode(JavaThread* current, intptr_t preserve_this_value, intptr_t tos, intptr_t tos2))
1527   assert(current == JavaThread::current(), "pre-condition");
1528   LastFrameAccessor last_frame(current);
1529   assert(last_frame.is_interpreted_frame(), "must be an interpreted frame");
1530   methodHandle mh(current, last_frame.method());
1531   BytecodeTracer::trace_interpreter(mh, last_frame.bcp(), tos, tos2);
1532   return preserve_this_value;
1533 JRT_END
1534 #endif // !PRODUCT