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 
 924   switch (info.call_kind()) {
 925   case CallInfo::direct_call: {
 926     // Get sender or sender's unsafe_anonymous_host, and only set cpCache entry to resolved if
 927     // it is not an interface.  The receiver for invokespecial calls within interface
 928     // methods must be checked for every call.
 929     InstanceKlass* pool_holder = pool->pool_holder();
 930     InstanceKlass* sender = pool_holder->is_unsafe_anonymous() ?
 931                               pool_holder->unsafe_anonymous_host() : pool_holder;
 932 
 933     cp_cache_entry->set_direct_call(
 934       bytecode,
 935       info.resolved_method(),
 936       sender->is_interface(),
 937       pool_holder);
 938     break;
 939   }
 940   case CallInfo::vtable_call:
 941     cp_cache_entry->set_vtable_call(
 942       bytecode,
 943       info.resolved_method(),
 944       info.vtable_index());
 945     break;
 946   case CallInfo::itable_call:
 947     cp_cache_entry->set_itable_call(
 948       bytecode,
 949       info.resolved_klass(),
 950       info.resolved_method(),
 951       info.itable_index());
 952     break;
 953   default:  ShouldNotReachHere();
 954   }
 955 }
 956 
 957 
 958 // First time execution:  Resolve symbols, create a permanent MethodType object.
 959 void InterpreterRuntime::resolve_invokehandle(JavaThread* thread) {
 960   Thread* THREAD = thread;
 961   const Bytecodes::Code bytecode = Bytecodes::_invokehandle;
 962   LastFrameAccessor last_frame(thread);
 963 
 964   // resolve method
 965   CallInfo info;
 966   constantPoolHandle pool(thread, last_frame.method()->constants());
 967   {
 968     JvmtiHideSingleStepping jhss(thread);
 969     LinkResolver::resolve_invoke(info, Handle(), pool,
 970                                  last_frame.get_index_u2_cpcache(bytecode), bytecode,
 971                                  CHECK);
 972   } // end JvmtiHideSingleStepping
 973 
 974   ConstantPoolCacheEntry* cp_cache_entry = last_frame.cache_entry();
 975   cp_cache_entry->set_method_handle(pool, info);
 976 }
 977 
 978 // First time execution:  Resolve symbols, create a permanent CallSite object.
 979 void InterpreterRuntime::resolve_invokedynamic(JavaThread* thread) {
 980   Thread* THREAD = thread;
 981   LastFrameAccessor last_frame(thread);
 982   const Bytecodes::Code bytecode = Bytecodes::_invokedynamic;
 983 
 984   // resolve method
 985   CallInfo info;
 986   constantPoolHandle pool(thread, last_frame.method()->constants());
 987   int index = last_frame.get_index_u4(bytecode);
 988   {
 989     JvmtiHideSingleStepping jhss(thread);
 990     LinkResolver::resolve_invoke(info, Handle(), pool,
 991                                  index, bytecode, CHECK);
 992   } // end JvmtiHideSingleStepping
 993 
 994   ConstantPoolCacheEntry* cp_cache_entry = pool->invokedynamic_cp_cache_entry_at(index);
 995   cp_cache_entry->set_dynamic_call(pool, info);
 996 }
 997 
 998 // This function is the interface to the assembly code. It returns the resolved
 999 // cpCache entry.  This doesn't safepoint, but the helper routines safepoint.
1000 // This function will check for redefinition!
1001 IRT_ENTRY(void, InterpreterRuntime::resolve_from_cache(JavaThread* thread, Bytecodes::Code bytecode)) {
1002   switch (bytecode) {
1003   case Bytecodes::_getstatic:
1004   case Bytecodes::_putstatic:
1005   case Bytecodes::_getfield:
1006   case Bytecodes::_putfield:
1007     resolve_get_put(thread, bytecode);
1008     break;
1009   case Bytecodes::_invokevirtual:
1010   case Bytecodes::_invokespecial:
1011   case Bytecodes::_invokestatic:
1012   case Bytecodes::_invokeinterface:
1013     resolve_invoke(thread, bytecode);
1014     break;
1015   case Bytecodes::_invokehandle:
1016     resolve_invokehandle(thread);
1017     break;
1018   case Bytecodes::_invokedynamic:
1019     resolve_invokedynamic(thread);
1020     break;
1021   default:
1022     fatal("unexpected bytecode: %s", Bytecodes::name(bytecode));
1023     break;
1024   }
1025 }
1026 IRT_END
1027 
1028 //------------------------------------------------------------------------------------------------------------------------
1029 // Miscellaneous
1030 
1031 
1032 nmethod* InterpreterRuntime::frequency_counter_overflow(JavaThread* thread, address branch_bcp) {
1033   nmethod* nm = frequency_counter_overflow_inner(thread, branch_bcp);
1034   assert(branch_bcp != NULL || nm == NULL, "always returns null for non OSR requests");
1035   if (branch_bcp != NULL && nm != NULL) {
1036     // This was a successful request for an OSR nmethod.  Because
1037     // frequency_counter_overflow_inner ends with a safepoint check,
1038     // nm could have been unloaded so look it up again.  It's unsafe
1039     // to examine nm directly since it might have been freed and used
1040     // for something else.
1041     LastFrameAccessor last_frame(thread);
1042     Method* method =  last_frame.method();
1043     int bci = method->bci_from(last_frame.bcp());
1044     nm = method->lookup_osr_nmethod_for(bci, CompLevel_none, false);
1045     BarrierSetNMethod* bs_nm = BarrierSet::barrier_set()->barrier_set_nmethod();
1046     if (nm != NULL && bs_nm != NULL) {
1047       // in case the transition passed a safepoint we need to barrier this again
1048       if (!bs_nm->nmethod_osr_entry_barrier(nm)) {
1049         nm = NULL;
1050       }
1051     }
1052   }
1053   if (nm != NULL && thread->is_interp_only_mode()) {
1054     // Normally we never get an nm if is_interp_only_mode() is true, because
1055     // policy()->event has a check for this and won't compile the method when
1056     // true. However, it's possible for is_interp_only_mode() to become true
1057     // during the compilation. We don't want to return the nm in that case
1058     // because we want to continue to execute interpreted.
1059     nm = NULL;
1060   }
1061 #ifndef PRODUCT
1062   if (TraceOnStackReplacement) {
1063     if (nm != NULL) {
1064       tty->print("OSR entry @ pc: " INTPTR_FORMAT ": ", p2i(nm->osr_entry()));
1065       nm->print();
1066     }
1067   }
1068 #endif
1069   return nm;
1070 }
1071 
1072 IRT_ENTRY(nmethod*,
1073           InterpreterRuntime::frequency_counter_overflow_inner(JavaThread* thread, address branch_bcp))
1074   // use UnlockFlagSaver to clear and restore the _do_not_unlock_if_synchronized
1075   // flag, in case this method triggers classloading which will call into Java.
1076   UnlockFlagSaver fs(thread);
1077 
1078   LastFrameAccessor last_frame(thread);
1079   assert(last_frame.is_interpreted_frame(), "must come from interpreter");
1080   methodHandle method(thread, last_frame.method());
1081   const int branch_bci = branch_bcp != NULL ? method->bci_from(branch_bcp) : InvocationEntryBci;
1082   const int bci = branch_bcp != NULL ? method->bci_from(last_frame.bcp()) : InvocationEntryBci;
1083 
1084   assert(!HAS_PENDING_EXCEPTION, "Should not have any exceptions pending");
1085   nmethod* osr_nm = CompilationPolicy::policy()->event(method, method, branch_bci, bci, CompLevel_none, NULL, thread);
1086   assert(!HAS_PENDING_EXCEPTION, "Event handler should not throw any exceptions");
1087 
1088   BarrierSetNMethod* bs_nm = BarrierSet::barrier_set()->barrier_set_nmethod();
1089   if (osr_nm != NULL && bs_nm != NULL) {
1090     if (!bs_nm->nmethod_osr_entry_barrier(osr_nm)) {
1091       osr_nm = NULL;
1092     }
1093   }
1094 
1095   if (osr_nm != NULL) {
1096     // We may need to do on-stack replacement which requires that no
1097     // monitors in the activation are biased because their
1098     // BasicObjectLocks will need to migrate during OSR. Force
1099     // unbiasing of all monitors in the activation now (even though
1100     // the OSR nmethod might be invalidated) because we don't have a
1101     // safepoint opportunity later once the migration begins.
1102     if (UseBiasedLocking) {
1103       ResourceMark rm;
1104       GrowableArray<Handle>* objects_to_revoke = new GrowableArray<Handle>();
1105       for( BasicObjectLock *kptr = last_frame.monitor_end();
1106            kptr < last_frame.monitor_begin();
1107            kptr = last_frame.next_monitor(kptr) ) {
1108         if( kptr->obj() != NULL ) {
1109           objects_to_revoke->append(Handle(THREAD, kptr->obj()));
1110         }
1111       }
1112       BiasedLocking::revoke(objects_to_revoke);
1113     }
1114   }
1115   return osr_nm;
1116 IRT_END
1117 
1118 IRT_LEAF(jint, InterpreterRuntime::bcp_to_di(Method* method, address cur_bcp))
1119   assert(ProfileInterpreter, "must be profiling interpreter");
1120   int bci = method->bci_from(cur_bcp);
1121   MethodData* mdo = method->method_data();
1122   if (mdo == NULL)  return 0;
1123   return mdo->bci_to_di(bci);
1124 IRT_END
1125 
1126 IRT_ENTRY(void, InterpreterRuntime::profile_method(JavaThread* thread))
1127   // use UnlockFlagSaver to clear and restore the _do_not_unlock_if_synchronized
1128   // flag, in case this method triggers classloading which will call into Java.
1129   UnlockFlagSaver fs(thread);
1130 
1131   assert(ProfileInterpreter, "must be profiling interpreter");
1132   LastFrameAccessor last_frame(thread);
1133   assert(last_frame.is_interpreted_frame(), "must come from interpreter");
1134   methodHandle method(thread, last_frame.method());
1135   Method::build_interpreter_method_data(method, THREAD);
1136   if (HAS_PENDING_EXCEPTION) {
1137     assert((PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())), "we expect only an OOM error here");
1138     CLEAR_PENDING_EXCEPTION;
1139     // and fall through...
1140   }
1141 IRT_END
1142 
1143 
1144 #ifdef ASSERT
1145 IRT_LEAF(void, InterpreterRuntime::verify_mdp(Method* method, address bcp, address mdp))
1146   assert(ProfileInterpreter, "must be profiling interpreter");
1147 
1148   MethodData* mdo = method->method_data();
1149   assert(mdo != NULL, "must not be null");
1150 
1151   int bci = method->bci_from(bcp);
1152 
1153   address mdp2 = mdo->bci_to_dp(bci);
1154   if (mdp != mdp2) {
1155     ResourceMark rm;
1156     ResetNoHandleMark rnm; // In a LEAF entry.
1157     HandleMark hm;
1158     tty->print_cr("FAILED verify : actual mdp %p   expected mdp %p @ bci %d", mdp, mdp2, bci);
1159     int current_di = mdo->dp_to_di(mdp);
1160     int expected_di  = mdo->dp_to_di(mdp2);
1161     tty->print_cr("  actual di %d   expected di %d", current_di, expected_di);
1162     int expected_approx_bci = mdo->data_at(expected_di)->bci();
1163     int approx_bci = -1;
1164     if (current_di >= 0) {
1165       approx_bci = mdo->data_at(current_di)->bci();
1166     }
1167     tty->print_cr("  actual bci is %d  expected bci %d", approx_bci, expected_approx_bci);
1168     mdo->print_on(tty);
1169     method->print_codes();
1170   }
1171   assert(mdp == mdp2, "wrong mdp");
1172 IRT_END
1173 #endif // ASSERT
1174 
1175 IRT_ENTRY(void, InterpreterRuntime::update_mdp_for_ret(JavaThread* thread, int return_bci))
1176   assert(ProfileInterpreter, "must be profiling interpreter");
1177   ResourceMark rm(thread);
1178   HandleMark hm(thread);
1179   LastFrameAccessor last_frame(thread);
1180   assert(last_frame.is_interpreted_frame(), "must come from interpreter");
1181   MethodData* h_mdo = last_frame.method()->method_data();
1182 
1183   // Grab a lock to ensure atomic access to setting the return bci and
1184   // the displacement.  This can block and GC, invalidating all naked oops.
1185   MutexLocker ml(RetData_lock);
1186 
1187   // ProfileData is essentially a wrapper around a derived oop, so we
1188   // need to take the lock before making any ProfileData structures.
1189   ProfileData* data = h_mdo->data_at(h_mdo->dp_to_di(last_frame.mdp()));
1190   guarantee(data != NULL, "profile data must be valid");
1191   RetData* rdata = data->as_RetData();
1192   address new_mdp = rdata->fixup_ret(return_bci, h_mdo);
1193   last_frame.set_mdp(new_mdp);
1194 IRT_END
1195 
1196 IRT_ENTRY(MethodCounters*, InterpreterRuntime::build_method_counters(JavaThread* thread, Method* m))
1197   MethodCounters* mcs = Method::build_method_counters(m, thread);
1198   if (HAS_PENDING_EXCEPTION) {
1199     assert((PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())), "we expect only an OOM error here");
1200     CLEAR_PENDING_EXCEPTION;
1201   }
1202   return mcs;
1203 IRT_END
1204 
1205 
1206 IRT_ENTRY(void, InterpreterRuntime::at_safepoint(JavaThread* thread))
1207   // We used to need an explict preserve_arguments here for invoke bytecodes. However,
1208   // stack traversal automatically takes care of preserving arguments for invoke, so
1209   // this is no longer needed.
1210 
1211   // IRT_END does an implicit safepoint check, hence we are guaranteed to block
1212   // if this is called during a safepoint
1213 
1214   if (JvmtiExport::should_post_single_step()) {
1215     // We are called during regular safepoints and when the VM is
1216     // single stepping. If any thread is marked for single stepping,
1217     // then we may have JVMTI work to do.
1218     LastFrameAccessor last_frame(thread);
1219     JvmtiExport::at_single_stepping_point(thread, last_frame.method(), last_frame.bcp());
1220   }
1221 IRT_END
1222 
1223 IRT_ENTRY(void, InterpreterRuntime::post_field_access(JavaThread *thread, oopDesc* obj,
1224 ConstantPoolCacheEntry *cp_entry))
1225 
1226   // check the access_flags for the field in the klass
1227 
1228   InstanceKlass* ik = InstanceKlass::cast(cp_entry->f1_as_klass());
1229   int index = cp_entry->field_index();
1230   if ((ik->field_access_flags(index) & JVM_ACC_FIELD_ACCESS_WATCHED) == 0) return;
1231 
1232   bool is_static = (obj == NULL);
1233   HandleMark hm(thread);
1234 
1235   Handle h_obj;
1236   if (!is_static) {
1237     // non-static field accessors have an object, but we need a handle
1238     h_obj = Handle(thread, obj);
1239   }
1240   InstanceKlass* cp_entry_f1 = InstanceKlass::cast(cp_entry->f1_as_klass());
1241   jfieldID fid = jfieldIDWorkaround::to_jfieldID(cp_entry_f1, cp_entry->f2_as_index(), is_static);
1242   LastFrameAccessor last_frame(thread);
1243   JvmtiExport::post_field_access(thread, last_frame.method(), last_frame.bcp(), cp_entry_f1, h_obj, fid);
1244 IRT_END
1245 
1246 IRT_ENTRY(void, InterpreterRuntime::post_field_modification(JavaThread *thread,
1247   oopDesc* obj, ConstantPoolCacheEntry *cp_entry, jvalue *value))
1248 
1249   Klass* k = cp_entry->f1_as_klass();
1250 
1251   // check the access_flags for the field in the klass
1252   InstanceKlass* ik = InstanceKlass::cast(k);
1253   int index = cp_entry->field_index();
1254   // bail out if field modifications are not watched
1255   if ((ik->field_access_flags(index) & JVM_ACC_FIELD_MODIFICATION_WATCHED) == 0) return;
1256 
1257   char sig_type = '\0';
1258 
1259   switch(cp_entry->flag_state()) {
1260     case btos: sig_type = 'B'; break;
1261     case ztos: sig_type = 'Z'; break;
1262     case ctos: sig_type = 'C'; break;
1263     case stos: sig_type = 'S'; break;
1264     case itos: sig_type = 'I'; break;
1265     case ftos: sig_type = 'F'; break;
1266     case atos: sig_type = 'L'; break;
1267     case ltos: sig_type = 'J'; break;
1268     case dtos: sig_type = 'D'; break;
1269     default:  ShouldNotReachHere(); return;
1270   }
1271   bool is_static = (obj == NULL);
1272 
1273   HandleMark hm(thread);
1274   jfieldID fid = jfieldIDWorkaround::to_jfieldID(ik, cp_entry->f2_as_index(), is_static);
1275   jvalue fvalue;
1276 #ifdef _LP64
1277   fvalue = *value;
1278 #else
1279   // Long/double values are stored unaligned and also noncontiguously with
1280   // tagged stacks.  We can't just do a simple assignment even in the non-
1281   // J/D cases because a C++ compiler is allowed to assume that a jvalue is
1282   // 8-byte aligned, and interpreter stack slots are only 4-byte aligned.
1283   // We assume that the two halves of longs/doubles are stored in interpreter
1284   // stack slots in platform-endian order.
1285   jlong_accessor u;
1286   jint* newval = (jint*)value;
1287   u.words[0] = newval[0];
1288   u.words[1] = newval[Interpreter::stackElementWords]; // skip if tag
1289   fvalue.j = u.long_value;
1290 #endif // _LP64
1291 
1292   Handle h_obj;
1293   if (!is_static) {
1294     // non-static field accessors have an object, but we need a handle
1295     h_obj = Handle(thread, obj);
1296   }
1297 
1298   LastFrameAccessor last_frame(thread);
1299   JvmtiExport::post_raw_field_modification(thread, last_frame.method(), last_frame.bcp(), ik, h_obj,
1300                                            fid, sig_type, &fvalue);
1301 IRT_END
1302 
1303 IRT_ENTRY(void, InterpreterRuntime::post_method_entry(JavaThread *thread))
1304   LastFrameAccessor last_frame(thread);
1305   JvmtiExport::post_method_entry(thread, last_frame.method(), last_frame.get_frame());
1306 IRT_END
1307 
1308 
1309 IRT_ENTRY(void, InterpreterRuntime::post_method_exit(JavaThread *thread))
1310   LastFrameAccessor last_frame(thread);
1311   JvmtiExport::post_method_exit(thread, last_frame.method(), last_frame.get_frame());
1312 IRT_END
1313 
1314 IRT_LEAF(int, InterpreterRuntime::interpreter_contains(address pc))
1315 {
1316   return (Interpreter::contains(pc) ? 1 : 0);
1317 }
1318 IRT_END
1319 
1320 
1321 // Implementation of SignatureHandlerLibrary
1322 
1323 #ifndef SHARING_FAST_NATIVE_FINGERPRINTS
1324 // Dummy definition (else normalization method is defined in CPU
1325 // dependant code)
1326 uint64_t InterpreterRuntime::normalize_fast_native_fingerprint(uint64_t fingerprint) {
1327   return fingerprint;
1328 }
1329 #endif
1330 
1331 address SignatureHandlerLibrary::set_handler_blob() {
1332   BufferBlob* handler_blob = BufferBlob::create("native signature handlers", blob_size);
1333   if (handler_blob == NULL) {
1334     return NULL;
1335   }
1336   address handler = handler_blob->code_begin();
1337   _handler_blob = handler_blob;
1338   _handler = handler;
1339   return handler;
1340 }
1341 
1342 void SignatureHandlerLibrary::initialize() {
1343   if (_fingerprints != NULL) {
1344     return;
1345   }
1346   if (set_handler_blob() == NULL) {
1347     vm_exit_out_of_memory(blob_size, OOM_MALLOC_ERROR, "native signature handlers");
1348   }
1349 
1350   BufferBlob* bb = BufferBlob::create("Signature Handler Temp Buffer",
1351                                       SignatureHandlerLibrary::buffer_size);
1352   _buffer = bb->code_begin();
1353 
1354   _fingerprints = new(ResourceObj::C_HEAP, mtCode)GrowableArray<uint64_t>(32, true);
1355   _handlers     = new(ResourceObj::C_HEAP, mtCode)GrowableArray<address>(32, true);
1356 }
1357 
1358 address SignatureHandlerLibrary::set_handler(CodeBuffer* buffer) {
1359   address handler   = _handler;
1360   int     insts_size = buffer->pure_insts_size();
1361   if (handler + insts_size > _handler_blob->code_end()) {
1362     // get a new handler blob
1363     handler = set_handler_blob();
1364   }
1365   if (handler != NULL) {
1366     memcpy(handler, buffer->insts_begin(), insts_size);
1367     pd_set_handler(handler);
1368     ICache::invalidate_range(handler, insts_size);
1369     _handler = handler + insts_size;
1370   }
1371   return handler;
1372 }
1373 
1374 void SignatureHandlerLibrary::add(const methodHandle& method) {
1375   if (method->signature_handler() == NULL) {
1376     // use slow signature handler if we can't do better
1377     int handler_index = -1;
1378     // check if we can use customized (fast) signature handler
1379     if (UseFastSignatureHandlers && method->size_of_parameters() <= Fingerprinter::max_size_of_parameters) {
1380       // use customized signature handler
1381       MutexLocker mu(SignatureHandlerLibrary_lock);
1382       // make sure data structure is initialized
1383       initialize();
1384       // lookup method signature's fingerprint
1385       uint64_t fingerprint = Fingerprinter(method).fingerprint();
1386       // allow CPU dependant code to optimize the fingerprints for the fast handler
1387       fingerprint = InterpreterRuntime::normalize_fast_native_fingerprint(fingerprint);
1388       handler_index = _fingerprints->find(fingerprint);
1389       // create handler if necessary
1390       if (handler_index < 0) {
1391         ResourceMark rm;
1392         ptrdiff_t align_offset = align_up(_buffer, CodeEntryAlignment) - (address)_buffer;
1393         CodeBuffer buffer((address)(_buffer + align_offset),
1394                           SignatureHandlerLibrary::buffer_size - align_offset);
1395         InterpreterRuntime::SignatureHandlerGenerator(method, &buffer).generate(fingerprint);
1396         // copy into code heap
1397         address handler = set_handler(&buffer);
1398         if (handler == NULL) {
1399           // use slow signature handler (without memorizing it in the fingerprints)
1400         } else {
1401           // debugging suppport
1402           if (PrintSignatureHandlers && (handler != Interpreter::slow_signature_handler())) {
1403             ttyLocker ttyl;
1404             tty->cr();
1405             tty->print_cr("argument handler #%d for: %s %s (fingerprint = " UINT64_FORMAT ", %d bytes generated)",
1406                           _handlers->length(),
1407                           (method->is_static() ? "static" : "receiver"),
1408                           method->name_and_sig_as_C_string(),
1409                           fingerprint,
1410                           buffer.insts_size());
1411             if (buffer.insts_size() > 0) {
1412               Disassembler::decode(handler, handler + buffer.insts_size());
1413             }
1414 #ifndef PRODUCT
1415             address rh_begin = Interpreter::result_handler(method()->result_type());
1416             if (CodeCache::contains(rh_begin)) {
1417               // else it might be special platform dependent values
1418               tty->print_cr(" --- associated result handler ---");
1419               address rh_end = rh_begin;
1420               while (*(int*)rh_end != 0) {
1421                 rh_end += sizeof(int);
1422               }
1423               Disassembler::decode(rh_begin, rh_end);
1424             } else {
1425               tty->print_cr(" associated result handler: " PTR_FORMAT, p2i(rh_begin));
1426             }
1427 #endif
1428           }
1429           // add handler to library
1430           _fingerprints->append(fingerprint);
1431           _handlers->append(handler);
1432           // set handler index
1433           assert(_fingerprints->length() == _handlers->length(), "sanity check");
1434           handler_index = _fingerprints->length() - 1;
1435         }
1436       }
1437       // Set handler under SignatureHandlerLibrary_lock
1438       if (handler_index < 0) {
1439         // use generic signature handler
1440         method->set_signature_handler(Interpreter::slow_signature_handler());
1441       } else {
1442         // set handler
1443         method->set_signature_handler(_handlers->at(handler_index));
1444       }
1445     } else {
1446       CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops());
1447       // use generic signature handler
1448       method->set_signature_handler(Interpreter::slow_signature_handler());
1449     }
1450   }
1451 #ifdef ASSERT
1452   int handler_index = -1;
1453   int fingerprint_index = -2;
1454   {
1455     // '_handlers' and '_fingerprints' are 'GrowableArray's and are NOT synchronized
1456     // in any way if accessed from multiple threads. To avoid races with another
1457     // thread which may change the arrays in the above, mutex protected block, we
1458     // have to protect this read access here with the same mutex as well!
1459     MutexLocker mu(SignatureHandlerLibrary_lock);
1460     if (_handlers != NULL) {
1461       handler_index = _handlers->find(method->signature_handler());
1462       uint64_t fingerprint = Fingerprinter(method).fingerprint();
1463       fingerprint = InterpreterRuntime::normalize_fast_native_fingerprint(fingerprint);
1464       fingerprint_index = _fingerprints->find(fingerprint);
1465     }
1466   }
1467   assert(method->signature_handler() == Interpreter::slow_signature_handler() ||
1468          handler_index == fingerprint_index, "sanity check");
1469 #endif // ASSERT
1470 }
1471 
1472 void SignatureHandlerLibrary::add(uint64_t fingerprint, address handler) {
1473   int handler_index = -1;
1474   // use customized signature handler
1475   MutexLocker mu(SignatureHandlerLibrary_lock);
1476   // make sure data structure is initialized
1477   initialize();
1478   fingerprint = InterpreterRuntime::normalize_fast_native_fingerprint(fingerprint);
1479   handler_index = _fingerprints->find(fingerprint);
1480   // create handler if necessary
1481   if (handler_index < 0) {
1482     if (PrintSignatureHandlers && (handler != Interpreter::slow_signature_handler())) {
1483       tty->cr();
1484       tty->print_cr("argument handler #%d at " PTR_FORMAT " for fingerprint " UINT64_FORMAT,
1485                     _handlers->length(),
1486                     p2i(handler),
1487                     fingerprint);
1488     }
1489     _fingerprints->append(fingerprint);
1490     _handlers->append(handler);
1491   } else {
1492     if (PrintSignatureHandlers) {
1493       tty->cr();
1494       tty->print_cr("duplicate argument handler #%d for fingerprint " UINT64_FORMAT "(old: " PTR_FORMAT ", new : " PTR_FORMAT ")",
1495                     _handlers->length(),
1496                     fingerprint,
1497                     p2i(_handlers->at(handler_index)),
1498                     p2i(handler));
1499     }
1500   }
1501 }
1502 
1503 
1504 BufferBlob*              SignatureHandlerLibrary::_handler_blob = NULL;
1505 address                  SignatureHandlerLibrary::_handler      = NULL;
1506 GrowableArray<uint64_t>* SignatureHandlerLibrary::_fingerprints = NULL;
1507 GrowableArray<address>*  SignatureHandlerLibrary::_handlers     = NULL;
1508 address                  SignatureHandlerLibrary::_buffer       = NULL;
1509 
1510 
1511 IRT_ENTRY(void, InterpreterRuntime::prepare_native_call(JavaThread* thread, Method* method))
1512   methodHandle m(thread, method);
1513   assert(m->is_native(), "sanity check");
1514   // lookup native function entry point if it doesn't exist
1515   bool in_base_library;
1516   if (!m->has_native_function()) {
1517     NativeLookup::lookup(m, in_base_library, CHECK);
1518   }
1519   // make sure signature handler is installed
1520   SignatureHandlerLibrary::add(m);
1521   // The interpreter entry point checks the signature handler first,
1522   // before trying to fetch the native entry point and klass mirror.
1523   // We must set the signature handler last, so that multiple processors
1524   // preparing the same method will be sure to see non-null entry & mirror.
1525 IRT_END
1526 
1527 #if defined(IA32) || defined(AMD64) || defined(ARM)
1528 IRT_LEAF(void, InterpreterRuntime::popframe_move_outgoing_args(JavaThread* thread, void* src_address, void* dest_address))
1529   if (src_address == dest_address) {
1530     return;
1531   }
1532   ResetNoHandleMark rnm; // In a LEAF entry.
1533   HandleMark hm;
1534   ResourceMark rm;
1535   LastFrameAccessor last_frame(thread);
1536   assert(last_frame.is_interpreted_frame(), "");
1537   jint bci = last_frame.bci();
1538   methodHandle mh(thread, last_frame.method());
1539   Bytecode_invoke invoke(mh, bci);
1540   ArgumentSizeComputer asc(invoke.signature());
1541   int size_of_arguments = (asc.size() + (invoke.has_receiver() ? 1 : 0)); // receiver
1542   Copy::conjoint_jbytes(src_address, dest_address,
1543                        size_of_arguments * Interpreter::stackElementSize);
1544 IRT_END
1545 #endif
1546 
1547 #if INCLUDE_JVMTI
1548 // This is a support of the JVMTI PopFrame interface.
1549 // Make sure it is an invokestatic of a polymorphic intrinsic that has a member_name argument
1550 // and return it as a vm_result so that it can be reloaded in the list of invokestatic parameters.
1551 // The member_name argument is a saved reference (in local#0) to the member_name.
1552 // For backward compatibility with some JDK versions (7, 8) it can also be a direct method handle.
1553 // FIXME: remove DMH case after j.l.i.InvokerBytecodeGenerator code shape is updated.
1554 IRT_ENTRY(void, InterpreterRuntime::member_name_arg_or_null(JavaThread* thread, address member_name,
1555                                                             Method* method, address bcp))
1556   Bytecodes::Code code = Bytecodes::code_at(method, bcp);
1557   if (code != Bytecodes::_invokestatic) {
1558     return;
1559   }
1560   ConstantPool* cpool = method->constants();
1561   int cp_index = Bytes::get_native_u2(bcp + 1) + ConstantPool::CPCACHE_INDEX_TAG;
1562   Symbol* cname = cpool->klass_name_at(cpool->klass_ref_index_at(cp_index));
1563   Symbol* mname = cpool->name_ref_at(cp_index);
1564 
1565   if (MethodHandles::has_member_arg(cname, mname)) {
1566     oop member_name_oop = (oop) member_name;
1567     if (java_lang_invoke_DirectMethodHandle::is_instance(member_name_oop)) {
1568       // FIXME: remove after j.l.i.InvokerBytecodeGenerator code shape is updated.
1569       member_name_oop = java_lang_invoke_DirectMethodHandle::member(member_name_oop);
1570     }
1571     thread->set_vm_result(member_name_oop);
1572   } else {
1573     thread->set_vm_result(NULL);
1574   }
1575 IRT_END
1576 #endif // INCLUDE_JVMTI
1577 
1578 #ifndef PRODUCT
1579 // This must be a IRT_LEAF function because the interpreter must save registers on x86 to
1580 // call this, which changes rsp and makes the interpreter's expression stack not walkable.
1581 // The generated code still uses call_VM because that will set up the frame pointer for
1582 // bcp and method.
1583 IRT_LEAF(intptr_t, InterpreterRuntime::trace_bytecode(JavaThread* thread, intptr_t preserve_this_value, intptr_t tos, intptr_t tos2))
1584   LastFrameAccessor last_frame(thread);
1585   assert(last_frame.is_interpreted_frame(), "must be an interpreted frame");
1586   methodHandle mh(thread, last_frame.method());
1587   BytecodeTracer::trace(mh, last_frame.bcp(), tos, tos2);
1588   return preserve_this_value;
1589 IRT_END
1590 #endif // !PRODUCT