1 /*
   2  * Copyright (c) 1997, 2018, 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/collectedHeap.hpp"
  33 #include "interpreter/interpreter.hpp"
  34 #include "interpreter/interpreterRuntime.hpp"
  35 #include "interpreter/linkResolver.hpp"
  36 #include "interpreter/templateTable.hpp"
  37 #include "logging/log.hpp"
  38 #include "memory/oopFactory.hpp"
  39 #include "memory/resourceArea.hpp"
  40 #include "memory/universe.hpp"
  41 #include "oops/constantPool.hpp"
  42 #include "oops/cpCache.inline.hpp"
  43 #include "oops/instanceKlass.hpp"
  44 #include "oops/methodData.hpp"
  45 #include "oops/objArrayKlass.hpp"
  46 #include "oops/objArrayOop.inline.hpp"
  47 #include "oops/oop.inline.hpp"
  48 #include "oops/symbol.hpp"
  49 #include "prims/jvmtiExport.hpp"
  50 #include "prims/nativeLookup.hpp"
  51 #include "runtime/atomic.hpp"
  52 #include "runtime/biasedLocking.hpp"
  53 #include "runtime/compilationPolicy.hpp"
  54 #include "runtime/deoptimization.hpp"
  55 #include "runtime/fieldDescriptor.hpp"
  56 #include "runtime/frame.inline.hpp"
  57 #include "runtime/handles.inline.hpp"
  58 #include "runtime/icache.hpp"
  59 #include "runtime/interfaceSupport.inline.hpp"
  60 #include "runtime/java.hpp"
  61 #include "runtime/jfieldIDWorkaround.hpp"
  62 #include "runtime/osThread.hpp"
  63 #include "runtime/sharedRuntime.hpp"
  64 #include "runtime/stubRoutines.hpp"
  65 #include "runtime/synchronizer.hpp"
  66 #include "runtime/threadCritical.hpp"
  67 #include "utilities/align.hpp"
  68 #include "utilities/events.hpp"
  69 #ifdef COMPILER2
  70 #include "opto/runtime.hpp"
  71 #endif
  72 
  73 class UnlockFlagSaver {
  74   private:
  75     JavaThread* _thread;
  76     bool _do_not_unlock;
  77   public:
  78     UnlockFlagSaver(JavaThread* t) {
  79       _thread = t;
  80       _do_not_unlock = t->do_not_unlock_if_synchronized();
  81       t->set_do_not_unlock_if_synchronized(false);
  82     }
  83     ~UnlockFlagSaver() {
  84       _thread->set_do_not_unlock_if_synchronized(_do_not_unlock);
  85     }
  86 };
  87 
  88 // Helper class to access current interpreter state
  89 class LastFrameAccessor : public StackObj {
  90   frame _last_frame;
  91 public:
  92   LastFrameAccessor(JavaThread* thread) {
  93     assert(thread == Thread::current(), "sanity");
  94     _last_frame = thread->last_frame();
  95   }
  96   bool is_interpreted_frame() const              { return _last_frame.is_interpreted_frame(); }
  97   Method*   method() const                       { return _last_frame.interpreter_frame_method(); }
  98   address   bcp() const                          { return _last_frame.interpreter_frame_bcp(); }
  99   int       bci() const                          { return _last_frame.interpreter_frame_bci(); }
 100   address   mdp() const                          { return _last_frame.interpreter_frame_mdp(); }
 101 
 102   void      set_bcp(address bcp)                 { _last_frame.interpreter_frame_set_bcp(bcp); }
 103   void      set_mdp(address dp)                  { _last_frame.interpreter_frame_set_mdp(dp); }
 104 
 105   // pass method to avoid calling unsafe bcp_to_method (partial fix 4926272)
 106   Bytecodes::Code code() const                   { return Bytecodes::code_at(method(), bcp()); }
 107 
 108   Bytecode  bytecode() const                     { return Bytecode(method(), bcp()); }
 109   int get_index_u1(Bytecodes::Code bc) const     { return bytecode().get_index_u1(bc); }
 110   int get_index_u2(Bytecodes::Code bc) const     { return bytecode().get_index_u2(bc); }
 111   int get_index_u2_cpcache(Bytecodes::Code bc) const
 112                                                  { return bytecode().get_index_u2_cpcache(bc); }
 113   int get_index_u4(Bytecodes::Code bc) const     { return bytecode().get_index_u4(bc); }
 114   int number_of_dimensions() const               { return bcp()[3]; }
 115   ConstantPoolCacheEntry* cache_entry_at(int i) const
 116                                                  { return method()->constants()->cache()->entry_at(i); }
 117   ConstantPoolCacheEntry* cache_entry() const    { return cache_entry_at(Bytes::get_native_u2(bcp() + 1)); }
 118 
 119   oop callee_receiver(Symbol* signature) {
 120     return _last_frame.interpreter_callee_receiver(signature);
 121   }
 122   BasicObjectLock* monitor_begin() const {
 123     return _last_frame.interpreter_frame_monitor_begin();
 124   }
 125   BasicObjectLock* monitor_end() const {
 126     return _last_frame.interpreter_frame_monitor_end();
 127   }
 128   BasicObjectLock* next_monitor(BasicObjectLock* current) const {
 129     return _last_frame.next_monitor_in_interpreter_frame(current);
 130   }
 131 
 132   frame& get_frame()                             { return _last_frame; }
 133 };
 134 
 135 
 136 bool InterpreterRuntime::is_breakpoint(JavaThread *thread) {
 137   return Bytecodes::code_or_bp_at(LastFrameAccessor(thread).bcp()) == Bytecodes::_breakpoint;
 138 }
 139 
 140 //------------------------------------------------------------------------------------------------------------------------
 141 // State accessors
 142 
 143 void InterpreterRuntime::set_bcp_and_mdp(address bcp, JavaThread *thread) {
 144   LastFrameAccessor last_frame(thread);
 145   last_frame.set_bcp(bcp);
 146   if (ProfileInterpreter) {
 147     // ProfileTraps uses MDOs independently of ProfileInterpreter.
 148     // That is why we must check both ProfileInterpreter and mdo != NULL.
 149     MethodData* mdo = last_frame.method()->method_data();
 150     if (mdo != NULL) {
 151       NEEDS_CLEANUP;
 152       last_frame.set_mdp(mdo->bci_to_dp(last_frame.bci()));
 153     }
 154   }
 155 }
 156 
 157 //------------------------------------------------------------------------------------------------------------------------
 158 // Constants
 159 
 160 
 161 IRT_ENTRY(void, InterpreterRuntime::ldc(JavaThread* thread, bool wide))
 162   // access constant pool
 163   LastFrameAccessor last_frame(thread);
 164   ConstantPool* pool = last_frame.method()->constants();
 165   int index = wide ? last_frame.get_index_u2(Bytecodes::_ldc_w) : last_frame.get_index_u1(Bytecodes::_ldc);
 166   constantTag tag = pool->tag_at(index);
 167 
 168   assert (tag.is_unresolved_klass() || tag.is_klass(), "wrong ldc call");
 169   Klass* klass = pool->klass_at(index, CHECK);
 170     oop java_class = klass->java_mirror();
 171     thread->set_vm_result(java_class);
 172 IRT_END
 173 
 174 IRT_ENTRY(void, InterpreterRuntime::resolve_ldc(JavaThread* thread, Bytecodes::Code bytecode)) {
 175   assert(bytecode == Bytecodes::_ldc ||
 176          bytecode == Bytecodes::_ldc_w ||
 177          bytecode == Bytecodes::_ldc2_w ||
 178          bytecode == Bytecodes::_fast_aldc ||
 179          bytecode == Bytecodes::_fast_aldc_w, "wrong bc");
 180   ResourceMark rm(thread);
 181   const bool is_fast_aldc = (bytecode == Bytecodes::_fast_aldc ||
 182                              bytecode == Bytecodes::_fast_aldc_w);
 183   LastFrameAccessor last_frame(thread);
 184   methodHandle m (thread, last_frame.method());
 185   Bytecode_loadconstant ldc(m, last_frame.bci());
 186 
 187   // Double-check the size.  (Condy can have any type.)
 188   BasicType type = ldc.result_type();
 189   switch (type2size[type]) {
 190   case 2: guarantee(bytecode == Bytecodes::_ldc2_w, ""); break;
 191   case 1: guarantee(bytecode != Bytecodes::_ldc2_w, ""); break;
 192   default: ShouldNotReachHere();
 193   }
 194 
 195   // Resolve the constant.  This does not do unboxing.
 196   // But it does replace Universe::the_null_sentinel by null.
 197   oop result = ldc.resolve_constant(CHECK);
 198   assert(result != NULL || is_fast_aldc, "null result only valid for fast_aldc");
 199 
 200 #ifdef ASSERT
 201   {
 202     // The bytecode wrappers aren't GC-safe so construct a new one
 203     Bytecode_loadconstant ldc2(m, last_frame.bci());
 204     int rindex = ldc2.cache_index();
 205     if (rindex < 0)
 206       rindex = m->constants()->cp_to_object_index(ldc2.pool_index());
 207     if (rindex >= 0) {
 208       oop coop = m->constants()->resolved_references()->obj_at(rindex);
 209       oop roop = (result == NULL ? Universe::the_null_sentinel() : result);
 210       assert(roop == coop, "expected result for assembly code");
 211     }
 212   }
 213 #endif
 214   thread->set_vm_result(result);
 215   if (!is_fast_aldc) {
 216     // Tell the interpreter how to unbox the primitive.
 217     guarantee(java_lang_boxing_object::is_instance(result, type), "");
 218     int offset = java_lang_boxing_object::value_offset_in_bytes(type);
 219     intptr_t flags = ((as_TosState(type) << ConstantPoolCacheEntry::tos_state_shift)
 220                       | (offset & ConstantPoolCacheEntry::field_index_mask));
 221     thread->set_vm_result_2((Metadata*)flags);
 222   }
 223 }
 224 IRT_END
 225 
 226 
 227 //------------------------------------------------------------------------------------------------------------------------
 228 // Allocation
 229 
 230 IRT_ENTRY(void, InterpreterRuntime::_new(JavaThread* thread, ConstantPool* pool, int index))
 231   Klass* k = pool->klass_at(index, CHECK);
 232   InstanceKlass* klass = InstanceKlass::cast(k);
 233 
 234   // Make sure we are not instantiating an abstract klass
 235   klass->check_valid_for_instantiation(true, CHECK);
 236 
 237   // Make sure klass is initialized
 238   klass->initialize(CHECK);
 239 
 240   // At this point the class may not be fully initialized
 241   // because of recursive initialization. If it is fully
 242   // initialized & has_finalized is not set, we rewrite
 243   // it into its fast version (Note: no locking is needed
 244   // here since this is an atomic byte write and can be
 245   // done more than once).
 246   //
 247   // Note: In case of classes with has_finalized we don't
 248   //       rewrite since that saves us an extra check in
 249   //       the fast version which then would call the
 250   //       slow version anyway (and do a call back into
 251   //       Java).
 252   //       If we have a breakpoint, then we don't rewrite
 253   //       because the _breakpoint bytecode would be lost.
 254   oop obj = klass->allocate_instance(CHECK);
 255   thread->set_vm_result(obj);
 256 IRT_END
 257 
 258 
 259 IRT_ENTRY(void, InterpreterRuntime::newarray(JavaThread* thread, BasicType type, jint size))
 260   oop obj = oopFactory::new_typeArray(type, size, CHECK);
 261   thread->set_vm_result(obj);
 262 IRT_END
 263 
 264 
 265 IRT_ENTRY(void, InterpreterRuntime::anewarray(JavaThread* thread, ConstantPool* pool, int index, jint size))
 266   Klass*    klass = pool->klass_at(index, CHECK);
 267   objArrayOop obj = oopFactory::new_objArray(klass, size, CHECK);
 268   thread->set_vm_result(obj);
 269 IRT_END
 270 
 271 
 272 IRT_ENTRY(void, InterpreterRuntime::multianewarray(JavaThread* thread, jint* first_size_address))
 273   // We may want to pass in more arguments - could make this slightly faster
 274   LastFrameAccessor last_frame(thread);
 275   ConstantPool* constants = last_frame.method()->constants();
 276   int          i = last_frame.get_index_u2(Bytecodes::_multianewarray);
 277   Klass* klass   = constants->klass_at(i, CHECK);
 278   int   nof_dims = last_frame.number_of_dimensions();
 279   assert(klass->is_klass(), "not a class");
 280   assert(nof_dims >= 1, "multianewarray rank must be nonzero");
 281 
 282   // We must create an array of jints to pass to multi_allocate.
 283   ResourceMark rm(thread);
 284   const int small_dims = 10;
 285   jint dim_array[small_dims];
 286   jint *dims = &dim_array[0];
 287   if (nof_dims > small_dims) {
 288     dims = (jint*) NEW_RESOURCE_ARRAY(jint, nof_dims);
 289   }
 290   for (int index = 0; index < nof_dims; index++) {
 291     // offset from first_size_address is addressed as local[index]
 292     int n = Interpreter::local_offset_in_bytes(index)/jintSize;
 293     dims[index] = first_size_address[n];
 294   }
 295   oop obj = ArrayKlass::cast(klass)->multi_allocate(nof_dims, dims, CHECK);
 296   thread->set_vm_result(obj);
 297 IRT_END
 298 
 299 
 300 IRT_ENTRY(void, InterpreterRuntime::register_finalizer(JavaThread* thread, oopDesc* obj))
 301   assert(oopDesc::is_oop(obj), "must be a valid oop");
 302   assert(obj->klass()->has_finalizer(), "shouldn't be here otherwise");
 303   InstanceKlass::register_finalizer(instanceOop(obj), CHECK);
 304 IRT_END
 305 
 306 
 307 // Quicken instance-of and check-cast bytecodes
 308 IRT_ENTRY(void, InterpreterRuntime::quicken_io_cc(JavaThread* thread))
 309   // Force resolving; quicken the bytecode
 310   LastFrameAccessor last_frame(thread);
 311   int which = last_frame.get_index_u2(Bytecodes::_checkcast);
 312   ConstantPool* cpool = last_frame.method()->constants();
 313   // We'd expect to assert that we're only here to quicken bytecodes, but in a multithreaded
 314   // program we might have seen an unquick'd bytecode in the interpreter but have another
 315   // thread quicken the bytecode before we get here.
 316   // assert( cpool->tag_at(which).is_unresolved_klass(), "should only come here to quicken bytecodes" );
 317   Klass* klass = cpool->klass_at(which, CHECK);
 318   thread->set_vm_result_2(klass);
 319 IRT_END
 320 
 321 
 322 //------------------------------------------------------------------------------------------------------------------------
 323 // Exceptions
 324 
 325 void InterpreterRuntime::note_trap_inner(JavaThread* thread, int reason,
 326                                          const methodHandle& trap_method, int trap_bci, TRAPS) {
 327   if (trap_method.not_null()) {
 328     MethodData* trap_mdo = trap_method->method_data();
 329     if (trap_mdo == NULL) {
 330       Method::build_interpreter_method_data(trap_method, THREAD);
 331       if (HAS_PENDING_EXCEPTION) {
 332         assert((PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())),
 333                "we expect only an OOM error here");
 334         CLEAR_PENDING_EXCEPTION;
 335       }
 336       trap_mdo = trap_method->method_data();
 337       // and fall through...
 338     }
 339     if (trap_mdo != NULL) {
 340       // Update per-method count of trap events.  The interpreter
 341       // is updating the MDO to simulate the effect of compiler traps.
 342       Deoptimization::update_method_data_from_interpreter(trap_mdo, trap_bci, reason);
 343     }
 344   }
 345 }
 346 
 347 // Assume the compiler is (or will be) interested in this event.
 348 // If necessary, create an MDO to hold the information, and record it.
 349 void InterpreterRuntime::note_trap(JavaThread* thread, int reason, TRAPS) {
 350   assert(ProfileTraps, "call me only if profiling");
 351   LastFrameAccessor last_frame(thread);
 352   methodHandle trap_method(thread, last_frame.method());
 353   int trap_bci = trap_method->bci_from(last_frame.bcp());
 354   note_trap_inner(thread, reason, trap_method, trap_bci, THREAD);
 355 }
 356 
 357 #ifdef CC_INTERP
 358 // As legacy note_trap, but we have more arguments.
 359 IRT_ENTRY(void, InterpreterRuntime::note_trap(JavaThread* thread, int reason, Method *method, int trap_bci))
 360   methodHandle trap_method(method);
 361   note_trap_inner(thread, reason, trap_method, trap_bci, THREAD);
 362 IRT_END
 363 
 364 // Class Deoptimization is not visible in BytecodeInterpreter, so we need a wrapper
 365 // for each exception.
 366 void InterpreterRuntime::note_nullCheck_trap(JavaThread* thread, Method *method, int trap_bci)
 367   { if (ProfileTraps) note_trap(thread, Deoptimization::Reason_null_check, method, trap_bci); }
 368 void InterpreterRuntime::note_div0Check_trap(JavaThread* thread, Method *method, int trap_bci)
 369   { if (ProfileTraps) note_trap(thread, Deoptimization::Reason_div0_check, method, trap_bci); }
 370 void InterpreterRuntime::note_rangeCheck_trap(JavaThread* thread, Method *method, int trap_bci)
 371   { if (ProfileTraps) note_trap(thread, Deoptimization::Reason_range_check, method, trap_bci); }
 372 void InterpreterRuntime::note_classCheck_trap(JavaThread* thread, Method *method, int trap_bci)
 373   { if (ProfileTraps) note_trap(thread, Deoptimization::Reason_class_check, method, trap_bci); }
 374 void InterpreterRuntime::note_arrayCheck_trap(JavaThread* thread, Method *method, int trap_bci)
 375   { if (ProfileTraps) note_trap(thread, Deoptimization::Reason_array_check, method, trap_bci); }
 376 #endif // CC_INTERP
 377 
 378 
 379 static Handle get_preinitialized_exception(Klass* k, TRAPS) {
 380   // get klass
 381   InstanceKlass* klass = InstanceKlass::cast(k);
 382   assert(klass->is_initialized(),
 383          "this klass should have been initialized during VM initialization");
 384   // create instance - do not call constructor since we may have no
 385   // (java) stack space left (should assert constructor is empty)
 386   Handle exception;
 387   oop exception_oop = klass->allocate_instance(CHECK_(exception));
 388   exception = Handle(THREAD, exception_oop);
 389   if (StackTraceInThrowable) {
 390     java_lang_Throwable::fill_in_stack_trace(exception);
 391   }
 392   return exception;
 393 }
 394 
 395 // Special handling for stack overflow: since we don't have any (java) stack
 396 // space left we use the pre-allocated & pre-initialized StackOverflowError
 397 // klass to create an stack overflow error instance.  We do not call its
 398 // constructor for the same reason (it is empty, anyway).
 399 IRT_ENTRY(void, InterpreterRuntime::throw_StackOverflowError(JavaThread* thread))
 400   Handle exception = get_preinitialized_exception(
 401                                  SystemDictionary::StackOverflowError_klass(),
 402                                  CHECK);
 403   // Increment counter for hs_err file reporting
 404   Atomic::inc(&Exceptions::_stack_overflow_errors);
 405   THROW_HANDLE(exception);
 406 IRT_END
 407 
 408 IRT_ENTRY(void, InterpreterRuntime::throw_delayed_StackOverflowError(JavaThread* thread))
 409   Handle exception = get_preinitialized_exception(
 410                                  SystemDictionary::StackOverflowError_klass(),
 411                                  CHECK);
 412   java_lang_Throwable::set_message(exception(),
 413           Universe::delayed_stack_overflow_error_message());
 414   // Increment counter for hs_err file reporting
 415   Atomic::inc(&Exceptions::_stack_overflow_errors);
 416   THROW_HANDLE(exception);
 417 IRT_END
 418 
 419 IRT_ENTRY(void, InterpreterRuntime::create_exception(JavaThread* thread, char* name, char* message))
 420   // lookup exception klass
 421   TempNewSymbol s = SymbolTable::new_symbol(name, CHECK);
 422   if (ProfileTraps) {
 423     if (s == vmSymbols::java_lang_ArithmeticException()) {
 424       note_trap(thread, Deoptimization::Reason_div0_check, CHECK);
 425     } else if (s == vmSymbols::java_lang_NullPointerException()) {
 426       note_trap(thread, Deoptimization::Reason_null_check, CHECK);
 427     }
 428   }
 429   // create exception
 430   Handle exception = Exceptions::new_exception(thread, s, message);
 431   thread->set_vm_result(exception());
 432 IRT_END
 433 
 434 
 435 IRT_ENTRY(void, InterpreterRuntime::create_klass_exception(JavaThread* thread, char* name, oopDesc* obj))
 436   ResourceMark rm(thread);
 437   const char* klass_name = obj->klass()->external_name();
 438   // lookup exception klass
 439   TempNewSymbol s = SymbolTable::new_symbol(name, CHECK);
 440   if (ProfileTraps) {
 441     note_trap(thread, Deoptimization::Reason_class_check, CHECK);
 442   }
 443   // create exception, with klass name as detail message
 444   Handle exception = Exceptions::new_exception(thread, s, klass_name);
 445   thread->set_vm_result(exception());
 446 IRT_END
 447 
 448 
 449 IRT_ENTRY(void, InterpreterRuntime::throw_ArrayIndexOutOfBoundsException(JavaThread* thread, char* name, jint index))
 450   char message[jintAsStringSize];
 451   // lookup exception klass
 452   TempNewSymbol s = SymbolTable::new_symbol(name, CHECK);
 453   if (ProfileTraps) {
 454     note_trap(thread, Deoptimization::Reason_range_check, CHECK);
 455   }
 456   // create exception
 457   sprintf(message, "%d", index);
 458   THROW_MSG(s, message);
 459 IRT_END
 460 
 461 IRT_ENTRY(void, InterpreterRuntime::throw_ClassCastException(
 462   JavaThread* thread, oopDesc* obj))
 463 
 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 = InstanceKlass::cast(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 host_klass, 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->has_host_klass() ? sender->host_klass() : 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   //TO DO: consider passing BCI to Java.
 981   //  int caller_bci = last_frame.method()->bci_from(last_frame.bcp());
 982 
 983   // resolve method
 984   CallInfo info;
 985   constantPoolHandle pool(thread, last_frame.method()->constants());
 986   int index = last_frame.get_index_u4(bytecode);
 987   {
 988     JvmtiHideSingleStepping jhss(thread);
 989     LinkResolver::resolve_invoke(info, Handle(), pool,
 990                                  index, bytecode, CHECK);
 991   } // end JvmtiHideSingleStepping
 992 
 993   ConstantPoolCacheEntry* cp_cache_entry = pool->invokedynamic_cp_cache_entry_at(index);
 994   cp_cache_entry->set_dynamic_call(pool, info);
 995 }
 996 
 997 // This function is the interface to the assembly code. It returns the resolved
 998 // cpCache entry.  This doesn't safepoint, but the helper routines safepoint.
 999 // This function will check for redefinition!
1000 IRT_ENTRY(void, InterpreterRuntime::resolve_from_cache(JavaThread* thread, Bytecodes::Code bytecode)) {
1001   switch (bytecode) {
1002   case Bytecodes::_getstatic:
1003   case Bytecodes::_putstatic:
1004   case Bytecodes::_getfield:
1005   case Bytecodes::_putfield:
1006     resolve_get_put(thread, bytecode);
1007     break;
1008   case Bytecodes::_invokevirtual:
1009   case Bytecodes::_invokespecial:
1010   case Bytecodes::_invokestatic:
1011   case Bytecodes::_invokeinterface:
1012     resolve_invoke(thread, bytecode);
1013     break;
1014   case Bytecodes::_invokehandle:
1015     resolve_invokehandle(thread);
1016     break;
1017   case Bytecodes::_invokedynamic:
1018     resolve_invokedynamic(thread);
1019     break;
1020   default:
1021     fatal("unexpected bytecode: %s", Bytecodes::name(bytecode));
1022     break;
1023   }
1024 }
1025 IRT_END
1026 
1027 //------------------------------------------------------------------------------------------------------------------------
1028 // Miscellaneous
1029 
1030 
1031 nmethod* InterpreterRuntime::frequency_counter_overflow(JavaThread* thread, address branch_bcp) {
1032   nmethod* nm = frequency_counter_overflow_inner(thread, branch_bcp);
1033   assert(branch_bcp != NULL || nm == NULL, "always returns null for non OSR requests");
1034   if (branch_bcp != NULL && nm != NULL) {
1035     // This was a successful request for an OSR nmethod.  Because
1036     // frequency_counter_overflow_inner ends with a safepoint check,
1037     // nm could have been unloaded so look it up again.  It's unsafe
1038     // to examine nm directly since it might have been freed and used
1039     // for something else.
1040     LastFrameAccessor last_frame(thread);
1041     Method* method =  last_frame.method();
1042     int bci = method->bci_from(last_frame.bcp());
1043     nm = method->lookup_osr_nmethod_for(bci, CompLevel_none, false);
1044   }
1045   if (nm != NULL && thread->is_interp_only_mode()) {
1046     // Normally we never get an nm if is_interp_only_mode() is true, because
1047     // policy()->event has a check for this and won't compile the method when
1048     // true. However, it's possible for is_interp_only_mode() to become true
1049     // during the compilation. We don't want to return the nm in that case
1050     // because we want to continue to execute interpreted.
1051     nm = NULL;
1052   }
1053 #ifndef PRODUCT
1054   if (TraceOnStackReplacement) {
1055     if (nm != NULL) {
1056       tty->print("OSR entry @ pc: " INTPTR_FORMAT ": ", p2i(nm->osr_entry()));
1057       nm->print();
1058     }
1059   }
1060 #endif
1061   return nm;
1062 }
1063 
1064 IRT_ENTRY(nmethod*,
1065           InterpreterRuntime::frequency_counter_overflow_inner(JavaThread* thread, address branch_bcp))
1066   // use UnlockFlagSaver to clear and restore the _do_not_unlock_if_synchronized
1067   // flag, in case this method triggers classloading which will call into Java.
1068   UnlockFlagSaver fs(thread);
1069 
1070   LastFrameAccessor last_frame(thread);
1071   assert(last_frame.is_interpreted_frame(), "must come from interpreter");
1072   methodHandle method(thread, last_frame.method());
1073   const int branch_bci = branch_bcp != NULL ? method->bci_from(branch_bcp) : InvocationEntryBci;
1074   const int bci = branch_bcp != NULL ? method->bci_from(last_frame.bcp()) : InvocationEntryBci;
1075 
1076   assert(!HAS_PENDING_EXCEPTION, "Should not have any exceptions pending");
1077   nmethod* osr_nm = CompilationPolicy::policy()->event(method, method, branch_bci, bci, CompLevel_none, NULL, thread);
1078   assert(!HAS_PENDING_EXCEPTION, "Event handler should not throw any exceptions");
1079 
1080   if (osr_nm != NULL) {
1081     // We may need to do on-stack replacement which requires that no
1082     // monitors in the activation are biased because their
1083     // BasicObjectLocks will need to migrate during OSR. Force
1084     // unbiasing of all monitors in the activation now (even though
1085     // the OSR nmethod might be invalidated) because we don't have a
1086     // safepoint opportunity later once the migration begins.
1087     if (UseBiasedLocking) {
1088       ResourceMark rm;
1089       GrowableArray<Handle>* objects_to_revoke = new GrowableArray<Handle>();
1090       for( BasicObjectLock *kptr = last_frame.monitor_end();
1091            kptr < last_frame.monitor_begin();
1092            kptr = last_frame.next_monitor(kptr) ) {
1093         if( kptr->obj() != NULL ) {
1094           objects_to_revoke->append(Handle(THREAD, kptr->obj()));
1095         }
1096       }
1097       BiasedLocking::revoke(objects_to_revoke);
1098     }
1099   }
1100   return osr_nm;
1101 IRT_END
1102 
1103 IRT_LEAF(jint, InterpreterRuntime::bcp_to_di(Method* method, address cur_bcp))
1104   assert(ProfileInterpreter, "must be profiling interpreter");
1105   int bci = method->bci_from(cur_bcp);
1106   MethodData* mdo = method->method_data();
1107   if (mdo == NULL)  return 0;
1108   return mdo->bci_to_di(bci);
1109 IRT_END
1110 
1111 IRT_ENTRY(void, InterpreterRuntime::profile_method(JavaThread* thread))
1112   // use UnlockFlagSaver to clear and restore the _do_not_unlock_if_synchronized
1113   // flag, in case this method triggers classloading which will call into Java.
1114   UnlockFlagSaver fs(thread);
1115 
1116   assert(ProfileInterpreter, "must be profiling interpreter");
1117   LastFrameAccessor last_frame(thread);
1118   assert(last_frame.is_interpreted_frame(), "must come from interpreter");
1119   methodHandle method(thread, last_frame.method());
1120   Method::build_interpreter_method_data(method, THREAD);
1121   if (HAS_PENDING_EXCEPTION) {
1122     assert((PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())), "we expect only an OOM error here");
1123     CLEAR_PENDING_EXCEPTION;
1124     // and fall through...
1125   }
1126 IRT_END
1127 
1128 
1129 #ifdef ASSERT
1130 IRT_LEAF(void, InterpreterRuntime::verify_mdp(Method* method, address bcp, address mdp))
1131   assert(ProfileInterpreter, "must be profiling interpreter");
1132 
1133   MethodData* mdo = method->method_data();
1134   assert(mdo != NULL, "must not be null");
1135 
1136   int bci = method->bci_from(bcp);
1137 
1138   address mdp2 = mdo->bci_to_dp(bci);
1139   if (mdp != mdp2) {
1140     ResourceMark rm;
1141     ResetNoHandleMark rnm; // In a LEAF entry.
1142     HandleMark hm;
1143     tty->print_cr("FAILED verify : actual mdp %p   expected mdp %p @ bci %d", mdp, mdp2, bci);
1144     int current_di = mdo->dp_to_di(mdp);
1145     int expected_di  = mdo->dp_to_di(mdp2);
1146     tty->print_cr("  actual di %d   expected di %d", current_di, expected_di);
1147     int expected_approx_bci = mdo->data_at(expected_di)->bci();
1148     int approx_bci = -1;
1149     if (current_di >= 0) {
1150       approx_bci = mdo->data_at(current_di)->bci();
1151     }
1152     tty->print_cr("  actual bci is %d  expected bci %d", approx_bci, expected_approx_bci);
1153     mdo->print_on(tty);
1154     method->print_codes();
1155   }
1156   assert(mdp == mdp2, "wrong mdp");
1157 IRT_END
1158 #endif // ASSERT
1159 
1160 IRT_ENTRY(void, InterpreterRuntime::update_mdp_for_ret(JavaThread* thread, int return_bci))
1161   assert(ProfileInterpreter, "must be profiling interpreter");
1162   ResourceMark rm(thread);
1163   HandleMark hm(thread);
1164   LastFrameAccessor last_frame(thread);
1165   assert(last_frame.is_interpreted_frame(), "must come from interpreter");
1166   MethodData* h_mdo = last_frame.method()->method_data();
1167 
1168   // Grab a lock to ensure atomic access to setting the return bci and
1169   // the displacement.  This can block and GC, invalidating all naked oops.
1170   MutexLocker ml(RetData_lock);
1171 
1172   // ProfileData is essentially a wrapper around a derived oop, so we
1173   // need to take the lock before making any ProfileData structures.
1174   ProfileData* data = h_mdo->data_at(h_mdo->dp_to_di(last_frame.mdp()));
1175   guarantee(data != NULL, "profile data must be valid");
1176   RetData* rdata = data->as_RetData();
1177   address new_mdp = rdata->fixup_ret(return_bci, h_mdo);
1178   last_frame.set_mdp(new_mdp);
1179 IRT_END
1180 
1181 IRT_ENTRY(MethodCounters*, InterpreterRuntime::build_method_counters(JavaThread* thread, Method* m))
1182   MethodCounters* mcs = Method::build_method_counters(m, thread);
1183   if (HAS_PENDING_EXCEPTION) {
1184     assert((PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())), "we expect only an OOM error here");
1185     CLEAR_PENDING_EXCEPTION;
1186   }
1187   return mcs;
1188 IRT_END
1189 
1190 
1191 IRT_ENTRY(void, InterpreterRuntime::at_safepoint(JavaThread* thread))
1192   // We used to need an explict preserve_arguments here for invoke bytecodes. However,
1193   // stack traversal automatically takes care of preserving arguments for invoke, so
1194   // this is no longer needed.
1195 
1196   // IRT_END does an implicit safepoint check, hence we are guaranteed to block
1197   // if this is called during a safepoint
1198 
1199   if (JvmtiExport::should_post_single_step()) {
1200     // We are called during regular safepoints and when the VM is
1201     // single stepping. If any thread is marked for single stepping,
1202     // then we may have JVMTI work to do.
1203     LastFrameAccessor last_frame(thread);
1204     JvmtiExport::at_single_stepping_point(thread, last_frame.method(), last_frame.bcp());
1205   }
1206 IRT_END
1207 
1208 IRT_ENTRY(void, InterpreterRuntime::post_field_access(JavaThread *thread, oopDesc* obj,
1209 ConstantPoolCacheEntry *cp_entry))
1210 
1211   // check the access_flags for the field in the klass
1212 
1213   InstanceKlass* ik = InstanceKlass::cast(cp_entry->f1_as_klass());
1214   int index = cp_entry->field_index();
1215   if ((ik->field_access_flags(index) & JVM_ACC_FIELD_ACCESS_WATCHED) == 0) return;
1216 
1217   bool is_static = (obj == NULL);
1218   HandleMark hm(thread);
1219 
1220   Handle h_obj;
1221   if (!is_static) {
1222     // non-static field accessors have an object, but we need a handle
1223     h_obj = Handle(thread, obj);
1224   }
1225   InstanceKlass* cp_entry_f1 = InstanceKlass::cast(cp_entry->f1_as_klass());
1226   jfieldID fid = jfieldIDWorkaround::to_jfieldID(cp_entry_f1, cp_entry->f2_as_index(), is_static);
1227   LastFrameAccessor last_frame(thread);
1228   JvmtiExport::post_field_access(thread, last_frame.method(), last_frame.bcp(), cp_entry_f1, h_obj, fid);
1229 IRT_END
1230 
1231 IRT_ENTRY(void, InterpreterRuntime::post_field_modification(JavaThread *thread,
1232   oopDesc* obj, ConstantPoolCacheEntry *cp_entry, jvalue *value))
1233 
1234   Klass* k = cp_entry->f1_as_klass();
1235 
1236   // check the access_flags for the field in the klass
1237   InstanceKlass* ik = InstanceKlass::cast(k);
1238   int index = cp_entry->field_index();
1239   // bail out if field modifications are not watched
1240   if ((ik->field_access_flags(index) & JVM_ACC_FIELD_MODIFICATION_WATCHED) == 0) return;
1241 
1242   char sig_type = '\0';
1243 
1244   switch(cp_entry->flag_state()) {
1245     case btos: sig_type = 'B'; break;
1246     case ztos: sig_type = 'Z'; break;
1247     case ctos: sig_type = 'C'; break;
1248     case stos: sig_type = 'S'; break;
1249     case itos: sig_type = 'I'; break;
1250     case ftos: sig_type = 'F'; break;
1251     case atos: sig_type = 'L'; break;
1252     case ltos: sig_type = 'J'; break;
1253     case dtos: sig_type = 'D'; break;
1254     default:  ShouldNotReachHere(); return;
1255   }
1256   bool is_static = (obj == NULL);
1257 
1258   HandleMark hm(thread);
1259   jfieldID fid = jfieldIDWorkaround::to_jfieldID(ik, cp_entry->f2_as_index(), is_static);
1260   jvalue fvalue;
1261 #ifdef _LP64
1262   fvalue = *value;
1263 #else
1264   // Long/double values are stored unaligned and also noncontiguously with
1265   // tagged stacks.  We can't just do a simple assignment even in the non-
1266   // J/D cases because a C++ compiler is allowed to assume that a jvalue is
1267   // 8-byte aligned, and interpreter stack slots are only 4-byte aligned.
1268   // We assume that the two halves of longs/doubles are stored in interpreter
1269   // stack slots in platform-endian order.
1270   jlong_accessor u;
1271   jint* newval = (jint*)value;
1272   u.words[0] = newval[0];
1273   u.words[1] = newval[Interpreter::stackElementWords]; // skip if tag
1274   fvalue.j = u.long_value;
1275 #endif // _LP64
1276 
1277   Handle h_obj;
1278   if (!is_static) {
1279     // non-static field accessors have an object, but we need a handle
1280     h_obj = Handle(thread, obj);
1281   }
1282 
1283   LastFrameAccessor last_frame(thread);
1284   JvmtiExport::post_raw_field_modification(thread, last_frame.method(), last_frame.bcp(), ik, h_obj,
1285                                            fid, sig_type, &fvalue);
1286 IRT_END
1287 
1288 IRT_ENTRY(void, InterpreterRuntime::post_method_entry(JavaThread *thread))
1289   LastFrameAccessor last_frame(thread);
1290   JvmtiExport::post_method_entry(thread, last_frame.method(), last_frame.get_frame());
1291 IRT_END
1292 
1293 
1294 IRT_ENTRY(void, InterpreterRuntime::post_method_exit(JavaThread *thread))
1295   LastFrameAccessor last_frame(thread);
1296   JvmtiExport::post_method_exit(thread, last_frame.method(), last_frame.get_frame());
1297 IRT_END
1298 
1299 IRT_LEAF(int, InterpreterRuntime::interpreter_contains(address pc))
1300 {
1301   return (Interpreter::contains(pc) ? 1 : 0);
1302 }
1303 IRT_END
1304 
1305 
1306 // Implementation of SignatureHandlerLibrary
1307 
1308 #ifndef SHARING_FAST_NATIVE_FINGERPRINTS
1309 // Dummy definition (else normalization method is defined in CPU
1310 // dependant code)
1311 uint64_t InterpreterRuntime::normalize_fast_native_fingerprint(uint64_t fingerprint) {
1312   return fingerprint;
1313 }
1314 #endif
1315 
1316 address SignatureHandlerLibrary::set_handler_blob() {
1317   BufferBlob* handler_blob = BufferBlob::create("native signature handlers", blob_size);
1318   if (handler_blob == NULL) {
1319     return NULL;
1320   }
1321   address handler = handler_blob->code_begin();
1322   _handler_blob = handler_blob;
1323   _handler = handler;
1324   return handler;
1325 }
1326 
1327 void SignatureHandlerLibrary::initialize() {
1328   if (_fingerprints != NULL) {
1329     return;
1330   }
1331   if (set_handler_blob() == NULL) {
1332     vm_exit_out_of_memory(blob_size, OOM_MALLOC_ERROR, "native signature handlers");
1333   }
1334 
1335   BufferBlob* bb = BufferBlob::create("Signature Handler Temp Buffer",
1336                                       SignatureHandlerLibrary::buffer_size);
1337   _buffer = bb->code_begin();
1338 
1339   _fingerprints = new(ResourceObj::C_HEAP, mtCode)GrowableArray<uint64_t>(32, true);
1340   _handlers     = new(ResourceObj::C_HEAP, mtCode)GrowableArray<address>(32, true);
1341 }
1342 
1343 address SignatureHandlerLibrary::set_handler(CodeBuffer* buffer) {
1344   address handler   = _handler;
1345   int     insts_size = buffer->pure_insts_size();
1346   if (handler + insts_size > _handler_blob->code_end()) {
1347     // get a new handler blob
1348     handler = set_handler_blob();
1349   }
1350   if (handler != NULL) {
1351     memcpy(handler, buffer->insts_begin(), insts_size);
1352     pd_set_handler(handler);
1353     ICache::invalidate_range(handler, insts_size);
1354     _handler = handler + insts_size;
1355   }
1356   return handler;
1357 }
1358 
1359 void SignatureHandlerLibrary::add(const methodHandle& method) {
1360   if (method->signature_handler() == NULL) {
1361     // use slow signature handler if we can't do better
1362     int handler_index = -1;
1363     // check if we can use customized (fast) signature handler
1364     if (UseFastSignatureHandlers && method->size_of_parameters() <= Fingerprinter::max_size_of_parameters) {
1365       // use customized signature handler
1366       MutexLocker mu(SignatureHandlerLibrary_lock);
1367       // make sure data structure is initialized
1368       initialize();
1369       // lookup method signature's fingerprint
1370       uint64_t fingerprint = Fingerprinter(method).fingerprint();
1371       // allow CPU dependant code to optimize the fingerprints for the fast handler
1372       fingerprint = InterpreterRuntime::normalize_fast_native_fingerprint(fingerprint);
1373       handler_index = _fingerprints->find(fingerprint);
1374       // create handler if necessary
1375       if (handler_index < 0) {
1376         ResourceMark rm;
1377         ptrdiff_t align_offset = align_up(_buffer, CodeEntryAlignment) - (address)_buffer;
1378         CodeBuffer buffer((address)(_buffer + align_offset),
1379                           SignatureHandlerLibrary::buffer_size - align_offset);
1380         InterpreterRuntime::SignatureHandlerGenerator(method, &buffer).generate(fingerprint);
1381         // copy into code heap
1382         address handler = set_handler(&buffer);
1383         if (handler == NULL) {
1384           // use slow signature handler (without memorizing it in the fingerprints)
1385         } else {
1386           // debugging suppport
1387           if (PrintSignatureHandlers && (handler != Interpreter::slow_signature_handler())) {
1388             ttyLocker ttyl;
1389             tty->cr();
1390             tty->print_cr("argument handler #%d for: %s %s (fingerprint = " UINT64_FORMAT ", %d bytes generated)",
1391                           _handlers->length(),
1392                           (method->is_static() ? "static" : "receiver"),
1393                           method->name_and_sig_as_C_string(),
1394                           fingerprint,
1395                           buffer.insts_size());
1396             if (buffer.insts_size() > 0) {
1397               Disassembler::decode(handler, handler + buffer.insts_size());
1398             }
1399 #ifndef PRODUCT
1400             address rh_begin = Interpreter::result_handler(method()->result_type());
1401             if (CodeCache::contains(rh_begin)) {
1402               // else it might be special platform dependent values
1403               tty->print_cr(" --- associated result handler ---");
1404               address rh_end = rh_begin;
1405               while (*(int*)rh_end != 0) {
1406                 rh_end += sizeof(int);
1407               }
1408               Disassembler::decode(rh_begin, rh_end);
1409             } else {
1410               tty->print_cr(" associated result handler: " PTR_FORMAT, p2i(rh_begin));
1411             }
1412 #endif
1413           }
1414           // add handler to library
1415           _fingerprints->append(fingerprint);
1416           _handlers->append(handler);
1417           // set handler index
1418           assert(_fingerprints->length() == _handlers->length(), "sanity check");
1419           handler_index = _fingerprints->length() - 1;
1420         }
1421       }
1422       // Set handler under SignatureHandlerLibrary_lock
1423       if (handler_index < 0) {
1424         // use generic signature handler
1425         method->set_signature_handler(Interpreter::slow_signature_handler());
1426       } else {
1427         // set handler
1428         method->set_signature_handler(_handlers->at(handler_index));
1429       }
1430     } else {
1431       CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops());
1432       // use generic signature handler
1433       method->set_signature_handler(Interpreter::slow_signature_handler());
1434     }
1435   }
1436 #ifdef ASSERT
1437   int handler_index = -1;
1438   int fingerprint_index = -2;
1439   {
1440     // '_handlers' and '_fingerprints' are 'GrowableArray's and are NOT synchronized
1441     // in any way if accessed from multiple threads. To avoid races with another
1442     // thread which may change the arrays in the above, mutex protected block, we
1443     // have to protect this read access here with the same mutex as well!
1444     MutexLocker mu(SignatureHandlerLibrary_lock);
1445     if (_handlers != NULL) {
1446       handler_index = _handlers->find(method->signature_handler());
1447       uint64_t fingerprint = Fingerprinter(method).fingerprint();
1448       fingerprint = InterpreterRuntime::normalize_fast_native_fingerprint(fingerprint);
1449       fingerprint_index = _fingerprints->find(fingerprint);
1450     }
1451   }
1452   assert(method->signature_handler() == Interpreter::slow_signature_handler() ||
1453          handler_index == fingerprint_index, "sanity check");
1454 #endif // ASSERT
1455 }
1456 
1457 void SignatureHandlerLibrary::add(uint64_t fingerprint, address handler) {
1458   int handler_index = -1;
1459   // use customized signature handler
1460   MutexLocker mu(SignatureHandlerLibrary_lock);
1461   // make sure data structure is initialized
1462   initialize();
1463   fingerprint = InterpreterRuntime::normalize_fast_native_fingerprint(fingerprint);
1464   handler_index = _fingerprints->find(fingerprint);
1465   // create handler if necessary
1466   if (handler_index < 0) {
1467     if (PrintSignatureHandlers && (handler != Interpreter::slow_signature_handler())) {
1468       tty->cr();
1469       tty->print_cr("argument handler #%d at " PTR_FORMAT " for fingerprint " UINT64_FORMAT,
1470                     _handlers->length(),
1471                     p2i(handler),
1472                     fingerprint);
1473     }
1474     _fingerprints->append(fingerprint);
1475     _handlers->append(handler);
1476   } else {
1477     if (PrintSignatureHandlers) {
1478       tty->cr();
1479       tty->print_cr("duplicate argument handler #%d for fingerprint " UINT64_FORMAT "(old: " PTR_FORMAT ", new : " PTR_FORMAT ")",
1480                     _handlers->length(),
1481                     fingerprint,
1482                     p2i(_handlers->at(handler_index)),
1483                     p2i(handler));
1484     }
1485   }
1486 }
1487 
1488 
1489 BufferBlob*              SignatureHandlerLibrary::_handler_blob = NULL;
1490 address                  SignatureHandlerLibrary::_handler      = NULL;
1491 GrowableArray<uint64_t>* SignatureHandlerLibrary::_fingerprints = NULL;
1492 GrowableArray<address>*  SignatureHandlerLibrary::_handlers     = NULL;
1493 address                  SignatureHandlerLibrary::_buffer       = NULL;
1494 
1495 
1496 IRT_ENTRY(void, InterpreterRuntime::prepare_native_call(JavaThread* thread, Method* method))
1497   methodHandle m(thread, method);
1498   assert(m->is_native(), "sanity check");
1499   // lookup native function entry point if it doesn't exist
1500   bool in_base_library;
1501   if (!m->has_native_function()) {
1502     NativeLookup::lookup(m, in_base_library, CHECK);
1503   }
1504   // make sure signature handler is installed
1505   SignatureHandlerLibrary::add(m);
1506   // The interpreter entry point checks the signature handler first,
1507   // before trying to fetch the native entry point and klass mirror.
1508   // We must set the signature handler last, so that multiple processors
1509   // preparing the same method will be sure to see non-null entry & mirror.
1510 IRT_END
1511 
1512 #if defined(IA32) || defined(AMD64) || defined(ARM)
1513 IRT_LEAF(void, InterpreterRuntime::popframe_move_outgoing_args(JavaThread* thread, void* src_address, void* dest_address))
1514   if (src_address == dest_address) {
1515     return;
1516   }
1517   ResetNoHandleMark rnm; // In a LEAF entry.
1518   HandleMark hm;
1519   ResourceMark rm;
1520   LastFrameAccessor last_frame(thread);
1521   assert(last_frame.is_interpreted_frame(), "");
1522   jint bci = last_frame.bci();
1523   methodHandle mh(thread, last_frame.method());
1524   Bytecode_invoke invoke(mh, bci);
1525   ArgumentSizeComputer asc(invoke.signature());
1526   int size_of_arguments = (asc.size() + (invoke.has_receiver() ? 1 : 0)); // receiver
1527   Copy::conjoint_jbytes(src_address, dest_address,
1528                        size_of_arguments * Interpreter::stackElementSize);
1529 IRT_END
1530 #endif
1531 
1532 #if INCLUDE_JVMTI
1533 // This is a support of the JVMTI PopFrame interface.
1534 // Make sure it is an invokestatic of a polymorphic intrinsic that has a member_name argument
1535 // and return it as a vm_result so that it can be reloaded in the list of invokestatic parameters.
1536 // The member_name argument is a saved reference (in local#0) to the member_name.
1537 // For backward compatibility with some JDK versions (7, 8) it can also be a direct method handle.
1538 // FIXME: remove DMH case after j.l.i.InvokerBytecodeGenerator code shape is updated.
1539 IRT_ENTRY(void, InterpreterRuntime::member_name_arg_or_null(JavaThread* thread, address member_name,
1540                                                             Method* method, address bcp))
1541   Bytecodes::Code code = Bytecodes::code_at(method, bcp);
1542   if (code != Bytecodes::_invokestatic) {
1543     return;
1544   }
1545   ConstantPool* cpool = method->constants();
1546   int cp_index = Bytes::get_native_u2(bcp + 1) + ConstantPool::CPCACHE_INDEX_TAG;
1547   Symbol* cname = cpool->klass_name_at(cpool->klass_ref_index_at(cp_index));
1548   Symbol* mname = cpool->name_ref_at(cp_index);
1549 
1550   if (MethodHandles::has_member_arg(cname, mname)) {
1551     oop member_name_oop = (oop) member_name;
1552     if (java_lang_invoke_DirectMethodHandle::is_instance(member_name_oop)) {
1553       // FIXME: remove after j.l.i.InvokerBytecodeGenerator code shape is updated.
1554       member_name_oop = java_lang_invoke_DirectMethodHandle::member(member_name_oop);
1555     }
1556     thread->set_vm_result(member_name_oop);
1557   } else {
1558     thread->set_vm_result(NULL);
1559   }
1560 IRT_END
1561 #endif // INCLUDE_JVMTI
1562 
1563 #ifndef PRODUCT
1564 // This must be a IRT_LEAF function because the interpreter must save registers on x86 to
1565 // call this, which changes rsp and makes the interpreter's expression stack not walkable.
1566 // The generated code still uses call_VM because that will set up the frame pointer for
1567 // bcp and method.
1568 IRT_LEAF(intptr_t, InterpreterRuntime::trace_bytecode(JavaThread* thread, intptr_t preserve_this_value, intptr_t tos, intptr_t tos2))
1569   LastFrameAccessor last_frame(thread);
1570   assert(last_frame.is_interpreted_frame(), "must be an interpreted frame");
1571   methodHandle mh(thread, last_frame.method());
1572   BytecodeTracer::trace(mh, last_frame.bcp(), tos, tos2);
1573   return preserve_this_value;
1574 IRT_END
1575 #endif // !PRODUCT