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