src/share/vm/interpreter/interpreterRuntime.cpp

Thu, 24 May 2018 18:41:44 +0800

author
aoqi
date
Thu, 24 May 2018 18:41:44 +0800
changeset 8856
ac27a9c85bea
parent 8739
0b85ccd62409
parent 8604
04d83ba48607
child 9041
95a08233f46c
permissions
-rw-r--r--

Merge

     1 /*
     2  * Copyright (c) 1997, 2016, 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  */
    25 /*
    26  * This file has been modified by Loongson Technology in 2015. These
    27  * modifications are Copyright (c) 2015 Loongson Technology, and are made
    28  * available on the same license terms set forth above.
    29  */
    31 #include "precompiled.hpp"
    32 #include "classfile/systemDictionary.hpp"
    33 #include "classfile/vmSymbols.hpp"
    34 #include "compiler/compileBroker.hpp"
    35 #include "compiler/disassembler.hpp"
    36 #include "gc_interface/collectedHeap.hpp"
    37 #include "interpreter/interpreter.hpp"
    38 #include "interpreter/interpreterRuntime.hpp"
    39 #include "interpreter/linkResolver.hpp"
    40 #include "interpreter/templateTable.hpp"
    41 #include "memory/oopFactory.hpp"
    42 #include "memory/universe.inline.hpp"
    43 #include "oops/constantPool.hpp"
    44 #include "oops/instanceKlass.hpp"
    45 #include "oops/methodData.hpp"
    46 #include "oops/objArrayKlass.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/biasedLocking.hpp"
    52 #include "runtime/compilationPolicy.hpp"
    53 #include "runtime/deoptimization.hpp"
    54 #include "runtime/fieldDescriptor.hpp"
    55 #include "runtime/handles.inline.hpp"
    56 #include "runtime/interfaceSupport.hpp"
    57 #include "runtime/java.hpp"
    58 #include "runtime/jfieldIDWorkaround.hpp"
    59 #include "runtime/osThread.hpp"
    60 #include "runtime/sharedRuntime.hpp"
    61 #include "runtime/stubRoutines.hpp"
    62 #include "runtime/synchronizer.hpp"
    63 #include "runtime/threadCritical.hpp"
    64 #include "utilities/events.hpp"
    65 #ifdef TARGET_ARCH_x86
    66 # include "vm_version_x86.hpp"
    67 #endif
    68 #ifdef TARGET_ARCH_mips
    69 # include "vm_version_mips.hpp"
    70 #endif
    71 #ifdef TARGET_ARCH_sparc
    72 # include "vm_version_sparc.hpp"
    73 #endif
    74 #ifdef TARGET_ARCH_zero
    75 # include "vm_version_zero.hpp"
    76 #endif
    77 #ifdef TARGET_ARCH_arm
    78 # include "vm_version_arm.hpp"
    79 #endif
    80 #ifdef TARGET_ARCH_ppc
    81 # include "vm_version_ppc.hpp"
    82 #endif
    83 #ifdef COMPILER2
    84 #include "opto/runtime.hpp"
    85 #endif
    87 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
    89 class UnlockFlagSaver {
    90   private:
    91     JavaThread* _thread;
    92     bool _do_not_unlock;
    93   public:
    94     UnlockFlagSaver(JavaThread* t) {
    95       _thread = t;
    96       _do_not_unlock = t->do_not_unlock_if_synchronized();
    97       t->set_do_not_unlock_if_synchronized(false);
    98     }
    99     ~UnlockFlagSaver() {
   100       _thread->set_do_not_unlock_if_synchronized(_do_not_unlock);
   101     }
   102 };
   104 //------------------------------------------------------------------------------------------------------------------------
   105 // State accessors
   107 void InterpreterRuntime::set_bcp_and_mdp(address bcp, JavaThread *thread) {
   108   last_frame(thread).interpreter_frame_set_bcp(bcp);
   109   if (ProfileInterpreter) {
   110     // ProfileTraps uses MDOs independently of ProfileInterpreter.
   111     // That is why we must check both ProfileInterpreter and mdo != NULL.
   112     MethodData* mdo = last_frame(thread).interpreter_frame_method()->method_data();
   113     if (mdo != NULL) {
   114       NEEDS_CLEANUP;
   115       last_frame(thread).interpreter_frame_set_mdp(mdo->bci_to_dp(last_frame(thread).interpreter_frame_bci()));
   116     }
   117   }
   118 }
   120 //------------------------------------------------------------------------------------------------------------------------
   121 // Constants
   124 IRT_ENTRY(void, InterpreterRuntime::ldc(JavaThread* thread, bool wide))
   125   // access constant pool
   126   ConstantPool* pool = method(thread)->constants();
   127   int index = wide ? get_index_u2(thread, Bytecodes::_ldc_w) : get_index_u1(thread, Bytecodes::_ldc);
   128   constantTag tag = pool->tag_at(index);
   130   assert (tag.is_unresolved_klass() || tag.is_klass(), "wrong ldc call");
   131   Klass* klass = pool->klass_at(index, CHECK);
   132     oop java_class = klass->java_mirror();
   133     thread->set_vm_result(java_class);
   134 IRT_END
   136 IRT_ENTRY(void, InterpreterRuntime::resolve_ldc(JavaThread* thread, Bytecodes::Code bytecode)) {
   137   assert(bytecode == Bytecodes::_fast_aldc ||
   138          bytecode == Bytecodes::_fast_aldc_w, "wrong bc");
   139   ResourceMark rm(thread);
   140   methodHandle m (thread, method(thread));
   141   Bytecode_loadconstant ldc(m, bci(thread));
   142   oop result = ldc.resolve_constant(CHECK);
   143 #ifdef ASSERT
   144   {
   145     // The bytecode wrappers aren't GC-safe so construct a new one
   146     Bytecode_loadconstant ldc2(m, bci(thread));
   147     oop coop = m->constants()->resolved_references()->obj_at(ldc2.cache_index());
   148     assert(result == coop, "expected result for assembly code");
   149   }
   150 #endif
   151   thread->set_vm_result(result);
   152 }
   153 IRT_END
   156 //------------------------------------------------------------------------------------------------------------------------
   157 // Allocation
   159 IRT_ENTRY(void, InterpreterRuntime::_new(JavaThread* thread, ConstantPool* pool, int index))
   160   Klass* k_oop = pool->klass_at(index, CHECK);
   161   instanceKlassHandle klass (THREAD, k_oop);
   163   // Make sure we are not instantiating an abstract klass
   164   klass->check_valid_for_instantiation(true, CHECK);
   166   // Make sure klass is initialized
   167   klass->initialize(CHECK);
   169   // At this point the class may not be fully initialized
   170   // because of recursive initialization. If it is fully
   171   // initialized & has_finalized is not set, we rewrite
   172   // it into its fast version (Note: no locking is needed
   173   // here since this is an atomic byte write and can be
   174   // done more than once).
   175   //
   176   // Note: In case of classes with has_finalized we don't
   177   //       rewrite since that saves us an extra check in
   178   //       the fast version which then would call the
   179   //       slow version anyway (and do a call back into
   180   //       Java).
   181   //       If we have a breakpoint, then we don't rewrite
   182   //       because the _breakpoint bytecode would be lost.
   183   oop obj = klass->allocate_instance(CHECK);
   184   thread->set_vm_result(obj);
   185 IRT_END
   188 IRT_ENTRY(void, InterpreterRuntime::newarray(JavaThread* thread, BasicType type, jint size))
   189   oop obj = oopFactory::new_typeArray(type, size, CHECK);
   190   thread->set_vm_result(obj);
   191 IRT_END
   194 IRT_ENTRY(void, InterpreterRuntime::anewarray(JavaThread* thread, ConstantPool* pool, int index, jint size))
   195   // Note: no oopHandle for pool & klass needed since they are not used
   196   //       anymore after new_objArray() and no GC can happen before.
   197   //       (This may have to change if this code changes!)
   198   Klass*    klass = pool->klass_at(index, CHECK);
   199   objArrayOop obj = oopFactory::new_objArray(klass, size, CHECK);
   200   thread->set_vm_result(obj);
   201 IRT_END
   204 IRT_ENTRY(void, InterpreterRuntime::multianewarray(JavaThread* thread, jint* first_size_address))
   205   // We may want to pass in more arguments - could make this slightly faster
   206   ConstantPool* constants = method(thread)->constants();
   207   int          i = get_index_u2(thread, Bytecodes::_multianewarray);
   208   Klass* klass = constants->klass_at(i, CHECK);
   209   int   nof_dims = number_of_dimensions(thread);
   210   assert(klass->is_klass(), "not a class");
   211   assert(nof_dims >= 1, "multianewarray rank must be nonzero");
   213   // We must create an array of jints to pass to multi_allocate.
   214   ResourceMark rm(thread);
   215   const int small_dims = 10;
   216   jint dim_array[small_dims];
   217   jint *dims = &dim_array[0];
   218   if (nof_dims > small_dims) {
   219     dims = (jint*) NEW_RESOURCE_ARRAY(jint, nof_dims);
   220   }
   221   for (int index = 0; index < nof_dims; index++) {
   222     // offset from first_size_address is addressed as local[index]
   223     int n = Interpreter::local_offset_in_bytes(index)/jintSize;
   224     dims[index] = first_size_address[n];
   225   }
   226   oop obj = ArrayKlass::cast(klass)->multi_allocate(nof_dims, dims, CHECK);
   227   thread->set_vm_result(obj);
   228 IRT_END
   231 IRT_ENTRY(void, InterpreterRuntime::register_finalizer(JavaThread* thread, oopDesc* obj))
   232   assert(obj->is_oop(), "must be a valid oop");
   233   assert(obj->klass()->has_finalizer(), "shouldn't be here otherwise");
   234   InstanceKlass::register_finalizer(instanceOop(obj), CHECK);
   235 IRT_END
   238 // Quicken instance-of and check-cast bytecodes
   239 IRT_ENTRY(void, InterpreterRuntime::quicken_io_cc(JavaThread* thread))
   240   // Force resolving; quicken the bytecode
   241   int which = get_index_u2(thread, Bytecodes::_checkcast);
   242   ConstantPool* cpool = method(thread)->constants();
   243   // We'd expect to assert that we're only here to quicken bytecodes, but in a multithreaded
   244   // program we might have seen an unquick'd bytecode in the interpreter but have another
   245   // thread quicken the bytecode before we get here.
   246   // assert( cpool->tag_at(which).is_unresolved_klass(), "should only come here to quicken bytecodes" );
   247   Klass* klass = cpool->klass_at(which, CHECK);
   248   thread->set_vm_result_2(klass);
   249 IRT_END
   252 //------------------------------------------------------------------------------------------------------------------------
   253 // Exceptions
   255 void InterpreterRuntime::note_trap_inner(JavaThread* thread, int reason,
   256                                          methodHandle trap_method, int trap_bci, TRAPS) {
   257   if (trap_method.not_null()) {
   258     MethodData* trap_mdo = trap_method->method_data();
   259     if (trap_mdo == NULL) {
   260       Method::build_interpreter_method_data(trap_method, THREAD);
   261       if (HAS_PENDING_EXCEPTION) {
   262         assert((PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())),
   263                "we expect only an OOM error here");
   264         CLEAR_PENDING_EXCEPTION;
   265       }
   266       trap_mdo = trap_method->method_data();
   267       // and fall through...
   268     }
   269     if (trap_mdo != NULL) {
   270       // Update per-method count of trap events.  The interpreter
   271       // is updating the MDO to simulate the effect of compiler traps.
   272       Deoptimization::update_method_data_from_interpreter(trap_mdo, trap_bci, reason);
   273     }
   274   }
   275 }
   277 // Assume the compiler is (or will be) interested in this event.
   278 // If necessary, create an MDO to hold the information, and record it.
   279 void InterpreterRuntime::note_trap(JavaThread* thread, int reason, TRAPS) {
   280   assert(ProfileTraps, "call me only if profiling");
   281   methodHandle trap_method(thread, method(thread));
   282   int trap_bci = trap_method->bci_from(bcp(thread));
   283   note_trap_inner(thread, reason, trap_method, trap_bci, THREAD);
   284 }
   286 #ifdef CC_INTERP
   287 // As legacy note_trap, but we have more arguments.
   288 IRT_ENTRY(void, InterpreterRuntime::note_trap(JavaThread* thread, int reason, Method *method, int trap_bci))
   289   methodHandle trap_method(method);
   290   note_trap_inner(thread, reason, trap_method, trap_bci, THREAD);
   291 IRT_END
   293 // Class Deoptimization is not visible in BytecodeInterpreter, so we need a wrapper
   294 // for each exception.
   295 void InterpreterRuntime::note_nullCheck_trap(JavaThread* thread, Method *method, int trap_bci)
   296   { if (ProfileTraps) note_trap(thread, Deoptimization::Reason_null_check, method, trap_bci); }
   297 void InterpreterRuntime::note_div0Check_trap(JavaThread* thread, Method *method, int trap_bci)
   298   { if (ProfileTraps) note_trap(thread, Deoptimization::Reason_div0_check, method, trap_bci); }
   299 void InterpreterRuntime::note_rangeCheck_trap(JavaThread* thread, Method *method, int trap_bci)
   300   { if (ProfileTraps) note_trap(thread, Deoptimization::Reason_range_check, method, trap_bci); }
   301 void InterpreterRuntime::note_classCheck_trap(JavaThread* thread, Method *method, int trap_bci)
   302   { if (ProfileTraps) note_trap(thread, Deoptimization::Reason_class_check, method, trap_bci); }
   303 void InterpreterRuntime::note_arrayCheck_trap(JavaThread* thread, Method *method, int trap_bci)
   304   { if (ProfileTraps) note_trap(thread, Deoptimization::Reason_array_check, method, trap_bci); }
   305 #endif // CC_INTERP
   308 static Handle get_preinitialized_exception(Klass* k, TRAPS) {
   309   // get klass
   310   InstanceKlass* klass = InstanceKlass::cast(k);
   311   assert(klass->is_initialized(),
   312          "this klass should have been initialized during VM initialization");
   313   // create instance - do not call constructor since we may have no
   314   // (java) stack space left (should assert constructor is empty)
   315   Handle exception;
   316   oop exception_oop = klass->allocate_instance(CHECK_(exception));
   317   exception = Handle(THREAD, exception_oop);
   318   if (StackTraceInThrowable) {
   319     java_lang_Throwable::fill_in_stack_trace(exception);
   320   }
   321   return exception;
   322 }
   324 // Special handling for stack overflow: since we don't have any (java) stack
   325 // space left we use the pre-allocated & pre-initialized StackOverflowError
   326 // klass to create an stack overflow error instance.  We do not call its
   327 // constructor for the same reason (it is empty, anyway).
   328 IRT_ENTRY(void, InterpreterRuntime::throw_StackOverflowError(JavaThread* thread))
   329   Handle exception = get_preinitialized_exception(
   330                                  SystemDictionary::StackOverflowError_klass(),
   331                                  CHECK);
   332   THROW_HANDLE(exception);
   333 IRT_END
   336 IRT_ENTRY(void, InterpreterRuntime::create_exception(JavaThread* thread, char* name, char* message))
   337   // lookup exception klass
   338   TempNewSymbol s = SymbolTable::new_symbol(name, CHECK);
   339   if (ProfileTraps) {
   340     if (s == vmSymbols::java_lang_ArithmeticException()) {
   341       note_trap(thread, Deoptimization::Reason_div0_check, CHECK);
   342     } else if (s == vmSymbols::java_lang_NullPointerException()) {
   343       note_trap(thread, Deoptimization::Reason_null_check, CHECK);
   344     }
   345   }
   346   // create exception
   347   Handle exception = Exceptions::new_exception(thread, s, message);
   348   thread->set_vm_result(exception());
   349 IRT_END
   352 IRT_ENTRY(void, InterpreterRuntime::create_klass_exception(JavaThread* thread, char* name, oopDesc* obj))
   353   ResourceMark rm(thread);
   354   const char* klass_name = obj->klass()->external_name();
   355   // lookup exception klass
   356   TempNewSymbol s = SymbolTable::new_symbol(name, CHECK);
   357   if (ProfileTraps) {
   358     note_trap(thread, Deoptimization::Reason_class_check, CHECK);
   359   }
   360   // create exception, with klass name as detail message
   361   Handle exception = Exceptions::new_exception(thread, s, klass_name);
   362   thread->set_vm_result(exception());
   363 IRT_END
   366 IRT_ENTRY(void, InterpreterRuntime::throw_ArrayIndexOutOfBoundsException(JavaThread* thread, char* name, jint index))
   367   char message[jintAsStringSize];
   368   // lookup exception klass
   369   TempNewSymbol s = SymbolTable::new_symbol(name, CHECK);
   370   if (ProfileTraps) {
   371     note_trap(thread, Deoptimization::Reason_range_check, CHECK);
   372   }
   373   // create exception
   374   sprintf(message, "%d", index);
   375   THROW_MSG(s, message);
   376 IRT_END
   378 IRT_ENTRY(void, InterpreterRuntime::throw_ClassCastException(
   379   JavaThread* thread, oopDesc* obj))
   381   ResourceMark rm(thread);
   382   char* message = SharedRuntime::generate_class_cast_message(
   383     thread, obj->klass()->external_name());
   385   if (ProfileTraps) {
   386     note_trap(thread, Deoptimization::Reason_class_check, CHECK);
   387   }
   389   // create exception
   390   THROW_MSG(vmSymbols::java_lang_ClassCastException(), message);
   391 IRT_END
   393 // exception_handler_for_exception(...) returns the continuation address,
   394 // the exception oop (via TLS) and sets the bci/bcp for the continuation.
   395 // The exception oop is returned to make sure it is preserved over GC (it
   396 // is only on the stack if the exception was thrown explicitly via athrow).
   397 // During this operation, the expression stack contains the values for the
   398 // bci where the exception happened. If the exception was propagated back
   399 // from a call, the expression stack contains the values for the bci at the
   400 // invoke w/o arguments (i.e., as if one were inside the call).
   401 IRT_ENTRY(address, InterpreterRuntime::exception_handler_for_exception(JavaThread* thread, oopDesc* exception))
   403   Handle             h_exception(thread, exception);
   404   methodHandle       h_method   (thread, method(thread));
   405   constantPoolHandle h_constants(thread, h_method->constants());
   406   bool               should_repeat;
   407   int                handler_bci;
   408   int                current_bci = bci(thread);
   410   if (thread->frames_to_pop_failed_realloc() > 0) {
   411     // Allocation of scalar replaced object used in this frame
   412     // failed. Unconditionally pop the frame.
   413     thread->dec_frames_to_pop_failed_realloc();
   414     thread->set_vm_result(h_exception());
   415     // If the method is synchronized we already unlocked the monitor
   416     // during deoptimization so the interpreter needs to skip it when
   417     // the frame is popped.
   418     thread->set_do_not_unlock_if_synchronized(true);
   419 #ifdef CC_INTERP
   420     return (address) -1;
   421 #else
   422     return Interpreter::remove_activation_entry();
   423 #endif
   424   }
   426   // Need to do this check first since when _do_not_unlock_if_synchronized
   427   // is set, we don't want to trigger any classloading which may make calls
   428   // into java, or surprisingly find a matching exception handler for bci 0
   429   // since at this moment the method hasn't been "officially" entered yet.
   430   if (thread->do_not_unlock_if_synchronized()) {
   431     ResourceMark rm;
   432     assert(current_bci == 0,  "bci isn't zero for do_not_unlock_if_synchronized");
   433     thread->set_vm_result(exception);
   434 #ifdef CC_INTERP
   435     return (address) -1;
   436 #else
   437     return Interpreter::remove_activation_entry();
   438 #endif
   439   }
   441   do {
   442     should_repeat = false;
   444     // assertions
   445 #ifdef ASSERT
   446     assert(h_exception.not_null(), "NULL exceptions should be handled by athrow");
   447     assert(h_exception->is_oop(), "just checking");
   448     // Check that exception is a subclass of Throwable, otherwise we have a VerifyError
   449     if (!(h_exception->is_a(SystemDictionary::Throwable_klass()))) {
   450       if (ExitVMOnVerifyError) vm_exit(-1);
   451       ShouldNotReachHere();
   452     }
   453 #endif
   455     // tracing
   456     if (TraceExceptions) {
   457       ttyLocker ttyl;
   458       ResourceMark rm(thread);
   459       tty->print_cr("Exception <%s> (" INTPTR_FORMAT ")", h_exception->print_value_string(), (address)h_exception());
   460       tty->print_cr(" thrown in interpreter method <%s>", h_method->print_value_string());
   461       tty->print_cr(" at bci %d for thread " INTPTR_FORMAT, current_bci, thread);
   462     }
   463 // Don't go paging in something which won't be used.
   464 //     else if (extable->length() == 0) {
   465 //       // disabled for now - interpreter is not using shortcut yet
   466 //       // (shortcut is not to call runtime if we have no exception handlers)
   467 //       // warning("performance bug: should not call runtime if method has no exception handlers");
   468 //     }
   469     // for AbortVMOnException flag
   470     NOT_PRODUCT(Exceptions::debug_check_abort(h_exception));
   472     // exception handler lookup
   473     KlassHandle h_klass(THREAD, h_exception->klass());
   474     handler_bci = Method::fast_exception_handler_bci_for(h_method, h_klass, current_bci, THREAD);
   475     if (HAS_PENDING_EXCEPTION) {
   476       // We threw an exception while trying to find the exception handler.
   477       // Transfer the new exception to the exception handle which will
   478       // be set into thread local storage, and do another lookup for an
   479       // exception handler for this exception, this time starting at the
   480       // BCI of the exception handler which caused the exception to be
   481       // thrown (bug 4307310).
   482       h_exception = Handle(THREAD, PENDING_EXCEPTION);
   483       CLEAR_PENDING_EXCEPTION;
   484       if (handler_bci >= 0) {
   485         current_bci = handler_bci;
   486         should_repeat = true;
   487       }
   488     }
   489   } while (should_repeat == true);
   491   // notify JVMTI of an exception throw; JVMTI will detect if this is a first
   492   // time throw or a stack unwinding throw and accordingly notify the debugger
   493   if (JvmtiExport::can_post_on_exceptions()) {
   494     JvmtiExport::post_exception_throw(thread, h_method(), bcp(thread), h_exception());
   495   }
   497 #ifdef CC_INTERP
   498   address continuation = (address)(intptr_t) handler_bci;
   499 #else
   500   address continuation = NULL;
   501 #endif
   502   address handler_pc = NULL;
   503   if (handler_bci < 0 || !thread->reguard_stack((address) &continuation)) {
   504     // Forward exception to callee (leaving bci/bcp untouched) because (a) no
   505     // handler in this method, or (b) after a stack overflow there is not yet
   506     // enough stack space available to reprotect the stack.
   507 #ifndef CC_INTERP
   508     continuation = Interpreter::remove_activation_entry();
   509 #endif
   510     // Count this for compilation purposes
   511     h_method->interpreter_throwout_increment(THREAD);
   512   } else {
   513     // handler in this method => change bci/bcp to handler bci/bcp and continue there
   514     handler_pc = h_method->code_base() + handler_bci;
   515 #ifndef CC_INTERP
   516     set_bcp_and_mdp(handler_pc, thread);
   517     continuation = Interpreter::dispatch_table(vtos)[*handler_pc];
   518 #endif
   519   }
   520   // notify debugger of an exception catch
   521   // (this is good for exceptions caught in native methods as well)
   522   if (JvmtiExport::can_post_on_exceptions()) {
   523     JvmtiExport::notice_unwind_due_to_exception(thread, h_method(), handler_pc, h_exception(), (handler_pc != NULL));
   524   }
   526   thread->set_vm_result(h_exception());
   527   return continuation;
   528 IRT_END
   531 IRT_ENTRY(void, InterpreterRuntime::throw_pending_exception(JavaThread* thread))
   532   assert(thread->has_pending_exception(), "must only ne called if there's an exception pending");
   533   // nothing to do - eventually we should remove this code entirely (see comments @ call sites)
   534 IRT_END
   537 IRT_ENTRY(void, InterpreterRuntime::throw_AbstractMethodError(JavaThread* thread))
   538   THROW(vmSymbols::java_lang_AbstractMethodError());
   539 IRT_END
   542 IRT_ENTRY(void, InterpreterRuntime::throw_IncompatibleClassChangeError(JavaThread* thread))
   543   THROW(vmSymbols::java_lang_IncompatibleClassChangeError());
   544 IRT_END
   547 //------------------------------------------------------------------------------------------------------------------------
   548 // Fields
   549 //
   551 IRT_ENTRY(void, InterpreterRuntime::resolve_get_put(JavaThread* thread, Bytecodes::Code bytecode))
   552   // resolve field
   553   fieldDescriptor info;
   554   constantPoolHandle pool(thread, method(thread)->constants());
   555   bool is_put    = (bytecode == Bytecodes::_putfield  || bytecode == Bytecodes::_putstatic);
   556   bool is_static = (bytecode == Bytecodes::_getstatic || bytecode == Bytecodes::_putstatic);
   558   {
   559     JvmtiHideSingleStepping jhss(thread);
   560     LinkResolver::resolve_field_access(info, pool, get_index_u2_cpcache(thread, bytecode),
   561                                        bytecode, CHECK);
   562   } // end JvmtiHideSingleStepping
   564   // check if link resolution caused cpCache to be updated
   565   if (already_resolved(thread)) return;
   567   // compute auxiliary field attributes
   568   TosState state  = as_TosState(info.field_type());
   570   // We need to delay resolving put instructions on final fields
   571   // until we actually invoke one. This is required so we throw
   572   // exceptions at the correct place. If we do not resolve completely
   573   // in the current pass, leaving the put_code set to zero will
   574   // cause the next put instruction to reresolve.
   575   Bytecodes::Code put_code = (Bytecodes::Code)0;
   577   // We also need to delay resolving getstatic instructions until the
   578   // class is intitialized.  This is required so that access to the static
   579   // field will call the initialization function every time until the class
   580   // is completely initialized ala. in 2.17.5 in JVM Specification.
   581   InstanceKlass* klass = InstanceKlass::cast(info.field_holder());
   582   bool uninitialized_static = ((bytecode == Bytecodes::_getstatic || bytecode == Bytecodes::_putstatic) &&
   583                                !klass->is_initialized());
   584   Bytecodes::Code get_code = (Bytecodes::Code)0;
   586   if (!uninitialized_static) {
   587     get_code = ((is_static) ? Bytecodes::_getstatic : Bytecodes::_getfield);
   588     if (is_put || !info.access_flags().is_final()) {
   589       put_code = ((is_static) ? Bytecodes::_putstatic : Bytecodes::_putfield);
   590     }
   591   }
   593   cache_entry(thread)->set_field(
   594     get_code,
   595     put_code,
   596     info.field_holder(),
   597     info.index(),
   598     info.offset(),
   599     state,
   600     info.access_flags().is_final(),
   601     info.access_flags().is_volatile(),
   602     pool->pool_holder()
   603   );
   604 IRT_END
   607 //------------------------------------------------------------------------------------------------------------------------
   608 // Synchronization
   609 //
   610 // The interpreter's synchronization code is factored out so that it can
   611 // be shared by method invocation and synchronized blocks.
   612 //%note synchronization_3
   614 //%note monitor_1
   615 IRT_ENTRY_NO_ASYNC(void, InterpreterRuntime::monitorenter(JavaThread* thread, BasicObjectLock* elem))
   616 #ifdef ASSERT
   617   thread->last_frame().interpreter_frame_verify_monitor(elem);
   618 #endif
   619   if (PrintBiasedLockingStatistics) {
   620     Atomic::inc(BiasedLocking::slow_path_entry_count_addr());
   621   }
   622   Handle h_obj(thread, elem->obj());
   623   assert(Universe::heap()->is_in_reserved_or_null(h_obj()),
   624          "must be NULL or an object");
   625   if (UseBiasedLocking) {
   626     // Retry fast entry if bias is revoked to avoid unnecessary inflation
   627     ObjectSynchronizer::fast_enter(h_obj, elem->lock(), true, CHECK);
   628   } else {
   629     ObjectSynchronizer::slow_enter(h_obj, elem->lock(), CHECK);
   630   }
   631   assert(Universe::heap()->is_in_reserved_or_null(elem->obj()),
   632          "must be NULL or an object");
   633 #ifdef ASSERT
   634   thread->last_frame().interpreter_frame_verify_monitor(elem);
   635 #endif
   636 IRT_END
   639 //%note monitor_1
   640 IRT_ENTRY_NO_ASYNC(void, InterpreterRuntime::monitorexit(JavaThread* thread, BasicObjectLock* elem))
   641 #ifdef ASSERT
   642   thread->last_frame().interpreter_frame_verify_monitor(elem);
   643 #endif
   644   Handle h_obj(thread, elem->obj());
   645   assert(Universe::heap()->is_in_reserved_or_null(h_obj()),
   646          "must be NULL or an object");
   647   if (elem == NULL || h_obj()->is_unlocked()) {
   648     THROW(vmSymbols::java_lang_IllegalMonitorStateException());
   649   }
   650   ObjectSynchronizer::slow_exit(h_obj(), elem->lock(), thread);
   651   // Free entry. This must be done here, since a pending exception might be installed on
   652   // exit. If it is not cleared, the exception handling code will try to unlock the monitor again.
   653   elem->set_obj(NULL);
   654 #ifdef ASSERT
   655   thread->last_frame().interpreter_frame_verify_monitor(elem);
   656 #endif
   657 IRT_END
   660 IRT_ENTRY(void, InterpreterRuntime::throw_illegal_monitor_state_exception(JavaThread* thread))
   661   THROW(vmSymbols::java_lang_IllegalMonitorStateException());
   662 IRT_END
   665 IRT_ENTRY(void, InterpreterRuntime::new_illegal_monitor_state_exception(JavaThread* thread))
   666   // Returns an illegal exception to install into the current thread. The
   667   // pending_exception flag is cleared so normal exception handling does not
   668   // trigger. Any current installed exception will be overwritten. This
   669   // method will be called during an exception unwind.
   671   assert(!HAS_PENDING_EXCEPTION, "no pending exception");
   672   Handle exception(thread, thread->vm_result());
   673   assert(exception() != NULL, "vm result should be set");
   674   thread->set_vm_result(NULL); // clear vm result before continuing (may cause memory leaks and assert failures)
   675   if (!exception->is_a(SystemDictionary::ThreadDeath_klass())) {
   676     exception = get_preinitialized_exception(
   677                        SystemDictionary::IllegalMonitorStateException_klass(),
   678                        CATCH);
   679   }
   680   thread->set_vm_result(exception());
   681 IRT_END
   684 //------------------------------------------------------------------------------------------------------------------------
   685 // Invokes
   687 IRT_ENTRY(Bytecodes::Code, InterpreterRuntime::get_original_bytecode_at(JavaThread* thread, Method* method, address bcp))
   688   return method->orig_bytecode_at(method->bci_from(bcp));
   689 IRT_END
   691 IRT_ENTRY(void, InterpreterRuntime::set_original_bytecode_at(JavaThread* thread, Method* method, address bcp, Bytecodes::Code new_code))
   692   method->set_orig_bytecode_at(method->bci_from(bcp), new_code);
   693 IRT_END
   695 IRT_ENTRY(void, InterpreterRuntime::_breakpoint(JavaThread* thread, Method* method, address bcp))
   696   JvmtiExport::post_raw_breakpoint(thread, method, bcp);
   697 IRT_END
   699 IRT_ENTRY(void, InterpreterRuntime::resolve_invoke(JavaThread* thread, Bytecodes::Code bytecode)) {
   700   // extract receiver from the outgoing argument list if necessary
   701   Handle receiver(thread, NULL);
   702   if (bytecode == Bytecodes::_invokevirtual || bytecode == Bytecodes::_invokeinterface ||
   703       bytecode == Bytecodes::_invokespecial) {
   704     ResourceMark rm(thread);
   705     methodHandle m (thread, method(thread));
   706     Bytecode_invoke call(m, bci(thread));
   707     Symbol* signature = call.signature();
   708     receiver = Handle(thread,
   709                   thread->last_frame().interpreter_callee_receiver(signature));
   710     assert(Universe::heap()->is_in_reserved_or_null(receiver()),
   711            "sanity check");
   712     assert(receiver.is_null() ||
   713            !Universe::heap()->is_in_reserved(receiver->klass()),
   714            "sanity check");
   715   }
   717   // resolve method
   718   CallInfo info;
   719   constantPoolHandle pool(thread, method(thread)->constants());
   721   {
   722     JvmtiHideSingleStepping jhss(thread);
   723     LinkResolver::resolve_invoke(info, receiver, pool,
   724                                  get_index_u2_cpcache(thread, bytecode), bytecode, CHECK);
   725     if (JvmtiExport::can_hotswap_or_post_breakpoint()) {
   726       int retry_count = 0;
   727       while (info.resolved_method()->is_old()) {
   728         // It is very unlikely that method is redefined more than 100 times
   729         // in the middle of resolve. If it is looping here more than 100 times
   730         // means then there could be a bug here.
   731         guarantee((retry_count++ < 100),
   732                   "Could not resolve to latest version of redefined method");
   733         // method is redefined in the middle of resolve so re-try.
   734         LinkResolver::resolve_invoke(info, receiver, pool,
   735                                      get_index_u2_cpcache(thread, bytecode), bytecode, CHECK);
   736       }
   737     }
   738   } // end JvmtiHideSingleStepping
   740   // check if link resolution caused cpCache to be updated
   741   if (already_resolved(thread)) return;
   743   if (bytecode == Bytecodes::_invokeinterface) {
   744     if (TraceItables && Verbose) {
   745       ResourceMark rm(thread);
   746       tty->print_cr("Resolving: klass: %s to method: %s", info.resolved_klass()->name()->as_C_string(), info.resolved_method()->name()->as_C_string());
   747     }
   748   }
   749 #ifdef ASSERT
   750   if (bytecode == Bytecodes::_invokeinterface) {
   751     if (info.resolved_method()->method_holder() ==
   752                                             SystemDictionary::Object_klass()) {
   753       // NOTE: THIS IS A FIX FOR A CORNER CASE in the JVM spec
   754       // (see also CallInfo::set_interface for details)
   755       assert(info.call_kind() == CallInfo::vtable_call ||
   756              info.call_kind() == CallInfo::direct_call, "");
   757       methodHandle rm = info.resolved_method();
   758       assert(rm->is_final() || info.has_vtable_index(),
   759              "should have been set already");
   760     } else if (!info.resolved_method()->has_itable_index()) {
   761       // Resolved something like CharSequence.toString.  Use vtable not itable.
   762       assert(info.call_kind() != CallInfo::itable_call, "");
   763     } else {
   764       // Setup itable entry
   765       assert(info.call_kind() == CallInfo::itable_call, "");
   766       int index = info.resolved_method()->itable_index();
   767       assert(info.itable_index() == index, "");
   768     }
   769   } else if (bytecode == Bytecodes::_invokespecial) {
   770     assert(info.call_kind() == CallInfo::direct_call, "must be direct call");
   771   } else {
   772     assert(info.call_kind() == CallInfo::direct_call ||
   773            info.call_kind() == CallInfo::vtable_call, "");
   774   }
   775 #endif
   776   // Get sender or sender's host_klass, and only set cpCache entry to resolved if
   777   // it is not an interface.  The receiver for invokespecial calls within interface
   778   // methods must be checked for every call.
   779   InstanceKlass* sender = pool->pool_holder();
   780   sender = sender->is_anonymous() ? InstanceKlass::cast(sender->host_klass()) : sender;
   782   switch (info.call_kind()) {
   783   case CallInfo::direct_call:
   784     cache_entry(thread)->set_direct_call(
   785       bytecode,
   786       info.resolved_method(),
   787       sender->is_interface());
   788     break;
   789   case CallInfo::vtable_call:
   790     cache_entry(thread)->set_vtable_call(
   791       bytecode,
   792       info.resolved_method(),
   793       info.vtable_index());
   794     break;
   795   case CallInfo::itable_call:
   796     cache_entry(thread)->set_itable_call(
   797       bytecode,
   798       info.resolved_method(),
   799       info.itable_index());
   800     break;
   801   default:  ShouldNotReachHere();
   802   }
   803 }
   804 IRT_END
   807 // First time execution:  Resolve symbols, create a permanent MethodType object.
   808 IRT_ENTRY(void, InterpreterRuntime::resolve_invokehandle(JavaThread* thread)) {
   809   assert(EnableInvokeDynamic, "");
   810   const Bytecodes::Code bytecode = Bytecodes::_invokehandle;
   812   // resolve method
   813   CallInfo info;
   814   constantPoolHandle pool(thread, method(thread)->constants());
   816   {
   817     JvmtiHideSingleStepping jhss(thread);
   818     LinkResolver::resolve_invoke(info, Handle(), pool,
   819                                  get_index_u2_cpcache(thread, bytecode), bytecode, CHECK);
   820   } // end JvmtiHideSingleStepping
   822   cache_entry(thread)->set_method_handle(pool, info);
   823 }
   824 IRT_END
   827 // First time execution:  Resolve symbols, create a permanent CallSite object.
   828 IRT_ENTRY(void, InterpreterRuntime::resolve_invokedynamic(JavaThread* thread)) {
   829   assert(EnableInvokeDynamic, "");
   830   const Bytecodes::Code bytecode = Bytecodes::_invokedynamic;
   832   //TO DO: consider passing BCI to Java.
   833   //  int caller_bci = method(thread)->bci_from(bcp(thread));
   835   // resolve method
   836   CallInfo info;
   837   constantPoolHandle pool(thread, method(thread)->constants());
   838   int index = get_index_u4(thread, bytecode);
   839   {
   840     JvmtiHideSingleStepping jhss(thread);
   841     LinkResolver::resolve_invoke(info, Handle(), pool,
   842                                  index, bytecode, CHECK);
   843   } // end JvmtiHideSingleStepping
   845   ConstantPoolCacheEntry* cp_cache_entry = pool->invokedynamic_cp_cache_entry_at(index);
   846   cp_cache_entry->set_dynamic_call(pool, info);
   847 }
   848 IRT_END
   851 //------------------------------------------------------------------------------------------------------------------------
   852 // Miscellaneous
   855 nmethod* InterpreterRuntime::frequency_counter_overflow(JavaThread* thread, address branch_bcp) {
   856   nmethod* nm = frequency_counter_overflow_inner(thread, branch_bcp);
   857   assert(branch_bcp != NULL || nm == NULL, "always returns null for non OSR requests");
   858   if (branch_bcp != NULL && nm != NULL) {
   859     // This was a successful request for an OSR nmethod.  Because
   860     // frequency_counter_overflow_inner ends with a safepoint check,
   861     // nm could have been unloaded so look it up again.  It's unsafe
   862     // to examine nm directly since it might have been freed and used
   863     // for something else.
   864     frame fr = thread->last_frame();
   865     Method* method =  fr.interpreter_frame_method();
   866     int bci = method->bci_from(fr.interpreter_frame_bcp());
   867     nm = method->lookup_osr_nmethod_for(bci, CompLevel_none, false);
   868   }
   869 #ifndef PRODUCT
   870   if (TraceOnStackReplacement) {
   871     if (nm != NULL) {
   872       tty->print("OSR entry @ pc: " INTPTR_FORMAT ": ", nm->osr_entry());
   873       nm->print();
   874     }
   875   }
   876 #endif
   877   return nm;
   878 }
   880 IRT_ENTRY(nmethod*,
   881           InterpreterRuntime::frequency_counter_overflow_inner(JavaThread* thread, address branch_bcp))
   882   // use UnlockFlagSaver to clear and restore the _do_not_unlock_if_synchronized
   883   // flag, in case this method triggers classloading which will call into Java.
   884   UnlockFlagSaver fs(thread);
   886   frame fr = thread->last_frame();
   887   assert(fr.is_interpreted_frame(), "must come from interpreter");
   888   methodHandle method(thread, fr.interpreter_frame_method());
   889   const int branch_bci = branch_bcp != NULL ? method->bci_from(branch_bcp) : InvocationEntryBci;
   890   const int bci = branch_bcp != NULL ? method->bci_from(fr.interpreter_frame_bcp()) : InvocationEntryBci;
   892   assert(!HAS_PENDING_EXCEPTION, "Should not have any exceptions pending");
   893   nmethod* osr_nm = CompilationPolicy::policy()->event(method, method, branch_bci, bci, CompLevel_none, NULL, thread);
   894   assert(!HAS_PENDING_EXCEPTION, "Event handler should not throw any exceptions");
   896   if (osr_nm != NULL) {
   897     // We may need to do on-stack replacement which requires that no
   898     // monitors in the activation are biased because their
   899     // BasicObjectLocks will need to migrate during OSR. Force
   900     // unbiasing of all monitors in the activation now (even though
   901     // the OSR nmethod might be invalidated) because we don't have a
   902     // safepoint opportunity later once the migration begins.
   903     if (UseBiasedLocking) {
   904       ResourceMark rm;
   905       GrowableArray<Handle>* objects_to_revoke = new GrowableArray<Handle>();
   906       for( BasicObjectLock *kptr = fr.interpreter_frame_monitor_end();
   907            kptr < fr.interpreter_frame_monitor_begin();
   908            kptr = fr.next_monitor_in_interpreter_frame(kptr) ) {
   909         if( kptr->obj() != NULL ) {
   910           objects_to_revoke->append(Handle(THREAD, kptr->obj()));
   911         }
   912       }
   913       BiasedLocking::revoke(objects_to_revoke);
   914     }
   915   }
   916   return osr_nm;
   917 IRT_END
   919 IRT_LEAF(jint, InterpreterRuntime::bcp_to_di(Method* method, address cur_bcp))
   920   assert(ProfileInterpreter, "must be profiling interpreter");
   921   int bci = method->bci_from(cur_bcp);
   922   MethodData* mdo = method->method_data();
   923   if (mdo == NULL)  return 0;
   924   return mdo->bci_to_di(bci);
   925 IRT_END
   927 IRT_ENTRY(void, InterpreterRuntime::profile_method(JavaThread* thread))
   928   // use UnlockFlagSaver to clear and restore the _do_not_unlock_if_synchronized
   929   // flag, in case this method triggers classloading which will call into Java.
   930   UnlockFlagSaver fs(thread);
   932   assert(ProfileInterpreter, "must be profiling interpreter");
   933   frame fr = thread->last_frame();
   934   assert(fr.is_interpreted_frame(), "must come from interpreter");
   935   methodHandle method(thread, fr.interpreter_frame_method());
   936   Method::build_interpreter_method_data(method, THREAD);
   937   if (HAS_PENDING_EXCEPTION) {
   938     assert((PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())), "we expect only an OOM error here");
   939     CLEAR_PENDING_EXCEPTION;
   940     // and fall through...
   941   }
   942 IRT_END
   945 #ifdef ASSERT
   946 IRT_LEAF(void, InterpreterRuntime::verify_mdp(Method* method, address bcp, address mdp))
   947   assert(ProfileInterpreter, "must be profiling interpreter");
   949   MethodData* mdo = method->method_data();
   950   assert(mdo != NULL, "must not be null");
   952   int bci = method->bci_from(bcp);
   954   address mdp2 = mdo->bci_to_dp(bci);
   955   if (mdp != mdp2) {
   956     ResourceMark rm;
   957     ResetNoHandleMark rnm; // In a LEAF entry.
   958     HandleMark hm;
   959     tty->print_cr("FAILED verify : actual mdp %p   expected mdp %p @ bci %d", mdp, mdp2, bci);
   960     int current_di = mdo->dp_to_di(mdp);
   961     int expected_di  = mdo->dp_to_di(mdp2);
   962     tty->print_cr("  actual di %d   expected di %d", current_di, expected_di);
   963     int expected_approx_bci = mdo->data_at(expected_di)->bci();
   964     int approx_bci = -1;
   965     if (current_di >= 0) {
   966       approx_bci = mdo->data_at(current_di)->bci();
   967     }
   968     tty->print_cr("  actual bci is %d  expected bci %d", approx_bci, expected_approx_bci);
   969     mdo->print_on(tty);
   970     method->print_codes();
   971   }
   972   assert(mdp == mdp2, "wrong mdp");
   973 IRT_END
   974 #endif // ASSERT
   976 IRT_ENTRY(void, InterpreterRuntime::update_mdp_for_ret(JavaThread* thread, int return_bci))
   977   assert(ProfileInterpreter, "must be profiling interpreter");
   978   ResourceMark rm(thread);
   979   HandleMark hm(thread);
   980   frame fr = thread->last_frame();
   981   assert(fr.is_interpreted_frame(), "must come from interpreter");
   982   MethodData* h_mdo = fr.interpreter_frame_method()->method_data();
   984   // Grab a lock to ensure atomic access to setting the return bci and
   985   // the displacement.  This can block and GC, invalidating all naked oops.
   986   MutexLocker ml(RetData_lock);
   988   // ProfileData is essentially a wrapper around a derived oop, so we
   989   // need to take the lock before making any ProfileData structures.
   990   ProfileData* data = h_mdo->data_at(h_mdo->dp_to_di(fr.interpreter_frame_mdp()));
   991   RetData* rdata = data->as_RetData();
   992   address new_mdp = rdata->fixup_ret(return_bci, h_mdo);
   993   fr.interpreter_frame_set_mdp(new_mdp);
   994 IRT_END
   996 IRT_ENTRY(MethodCounters*, InterpreterRuntime::build_method_counters(JavaThread* thread, Method* m))
   997   MethodCounters* mcs = Method::build_method_counters(m, thread);
   998   if (HAS_PENDING_EXCEPTION) {
   999     assert((PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())), "we expect only an OOM error here");
  1000     CLEAR_PENDING_EXCEPTION;
  1002   return mcs;
  1003 IRT_END
  1006 IRT_ENTRY(void, InterpreterRuntime::at_safepoint(JavaThread* thread))
  1007   // We used to need an explict preserve_arguments here for invoke bytecodes. However,
  1008   // stack traversal automatically takes care of preserving arguments for invoke, so
  1009   // this is no longer needed.
  1011   // IRT_END does an implicit safepoint check, hence we are guaranteed to block
  1012   // if this is called during a safepoint
  1014   if (JvmtiExport::should_post_single_step()) {
  1015     // We are called during regular safepoints and when the VM is
  1016     // single stepping. If any thread is marked for single stepping,
  1017     // then we may have JVMTI work to do.
  1018     JvmtiExport::at_single_stepping_point(thread, method(thread), bcp(thread));
  1020 IRT_END
  1022 IRT_ENTRY(void, InterpreterRuntime::post_field_access(JavaThread *thread, oopDesc* obj,
  1023 ConstantPoolCacheEntry *cp_entry))
  1025   // check the access_flags for the field in the klass
  1027   InstanceKlass* ik = InstanceKlass::cast(cp_entry->f1_as_klass());
  1028   int index = cp_entry->field_index();
  1029   if ((ik->field_access_flags(index) & JVM_ACC_FIELD_ACCESS_WATCHED) == 0) return;
  1031   switch(cp_entry->flag_state()) {
  1032     case btos:    // fall through
  1033     case ztos:    // fall through
  1034     case ctos:    // fall through
  1035     case stos:    // fall through
  1036     case itos:    // fall through
  1037     case ftos:    // fall through
  1038     case ltos:    // fall through
  1039     case dtos:    // fall through
  1040     case atos: break;
  1041     default: ShouldNotReachHere(); return;
  1043   bool is_static = (obj == NULL);
  1044   HandleMark hm(thread);
  1046   Handle h_obj;
  1047   if (!is_static) {
  1048     // non-static field accessors have an object, but we need a handle
  1049     h_obj = Handle(thread, obj);
  1051   instanceKlassHandle h_cp_entry_f1(thread, (Klass*)cp_entry->f1_as_klass());
  1052   jfieldID fid = jfieldIDWorkaround::to_jfieldID(h_cp_entry_f1, cp_entry->f2_as_index(), is_static);
  1053   JvmtiExport::post_field_access(thread, method(thread), bcp(thread), h_cp_entry_f1, h_obj, fid);
  1054 IRT_END
  1056 IRT_ENTRY(void, InterpreterRuntime::post_field_modification(JavaThread *thread,
  1057   oopDesc* obj, ConstantPoolCacheEntry *cp_entry, jvalue *value))
  1059   Klass* k = (Klass*)cp_entry->f1_as_klass();
  1061   // check the access_flags for the field in the klass
  1062   InstanceKlass* ik = InstanceKlass::cast(k);
  1063   int index = cp_entry->field_index();
  1064   // bail out if field modifications are not watched
  1065   if ((ik->field_access_flags(index) & JVM_ACC_FIELD_MODIFICATION_WATCHED) == 0) return;
  1067   char sig_type = '\0';
  1069   switch(cp_entry->flag_state()) {
  1070     case btos: sig_type = 'B'; break;
  1071     case ztos: sig_type = 'Z'; break;
  1072     case ctos: sig_type = 'C'; break;
  1073     case stos: sig_type = 'S'; break;
  1074     case itos: sig_type = 'I'; break;
  1075     case ftos: sig_type = 'F'; break;
  1076     case atos: sig_type = 'L'; break;
  1077     case ltos: sig_type = 'J'; break;
  1078     case dtos: sig_type = 'D'; break;
  1079     default:  ShouldNotReachHere(); return;
  1081   bool is_static = (obj == NULL);
  1083   HandleMark hm(thread);
  1084   instanceKlassHandle h_klass(thread, k);
  1085   jfieldID fid = jfieldIDWorkaround::to_jfieldID(h_klass, cp_entry->f2_as_index(), is_static);
  1086   jvalue fvalue;
  1087 #ifdef _LP64
  1088   fvalue = *value;
  1089 #else
  1090   // Long/double values are stored unaligned and also noncontiguously with
  1091   // tagged stacks.  We can't just do a simple assignment even in the non-
  1092   // J/D cases because a C++ compiler is allowed to assume that a jvalue is
  1093   // 8-byte aligned, and interpreter stack slots are only 4-byte aligned.
  1094   // We assume that the two halves of longs/doubles are stored in interpreter
  1095   // stack slots in platform-endian order.
  1096   jlong_accessor u;
  1097   jint* newval = (jint*)value;
  1098   u.words[0] = newval[0];
  1099   u.words[1] = newval[Interpreter::stackElementWords]; // skip if tag
  1100   fvalue.j = u.long_value;
  1101 #endif // _LP64
  1103   Handle h_obj;
  1104   if (!is_static) {
  1105     // non-static field accessors have an object, but we need a handle
  1106     h_obj = Handle(thread, obj);
  1109   JvmtiExport::post_raw_field_modification(thread, method(thread), bcp(thread), h_klass, h_obj,
  1110                                            fid, sig_type, &fvalue);
  1111 IRT_END
  1113 IRT_ENTRY(void, InterpreterRuntime::post_method_entry(JavaThread *thread))
  1114   JvmtiExport::post_method_entry(thread, InterpreterRuntime::method(thread), InterpreterRuntime::last_frame(thread));
  1115 IRT_END
  1118 IRT_ENTRY(void, InterpreterRuntime::post_method_exit(JavaThread *thread))
  1119   JvmtiExport::post_method_exit(thread, InterpreterRuntime::method(thread), InterpreterRuntime::last_frame(thread));
  1120 IRT_END
  1122 IRT_LEAF(int, InterpreterRuntime::interpreter_contains(address pc))
  1124   return (Interpreter::contains(pc) ? 1 : 0);
  1126 IRT_END
  1129 // Implementation of SignatureHandlerLibrary
  1131 address SignatureHandlerLibrary::set_handler_blob() {
  1132   BufferBlob* handler_blob = BufferBlob::create("native signature handlers", blob_size);
  1133   if (handler_blob == NULL) {
  1134     return NULL;
  1136   address handler = handler_blob->code_begin();
  1137   _handler_blob = handler_blob;
  1138   _handler = handler;
  1139   return handler;
  1142 void SignatureHandlerLibrary::initialize() {
  1143   if (_fingerprints != NULL) {
  1144     return;
  1146   if (set_handler_blob() == NULL) {
  1147     vm_exit_out_of_memory(blob_size, OOM_MALLOC_ERROR, "native signature handlers");
  1150   BufferBlob* bb = BufferBlob::create("Signature Handler Temp Buffer",
  1151                                       SignatureHandlerLibrary::buffer_size);
  1152   _buffer = bb->code_begin();
  1154   _fingerprints = new(ResourceObj::C_HEAP, mtCode)GrowableArray<uint64_t>(32, true);
  1155   _handlers     = new(ResourceObj::C_HEAP, mtCode)GrowableArray<address>(32, true);
  1158 address SignatureHandlerLibrary::set_handler(CodeBuffer* buffer) {
  1159   address handler   = _handler;
  1160   int     insts_size = buffer->pure_insts_size();
  1161   if (handler + insts_size > _handler_blob->code_end()) {
  1162     // get a new handler blob
  1163     handler = set_handler_blob();
  1165   if (handler != NULL) {
  1166     memcpy(handler, buffer->insts_begin(), insts_size);
  1167     pd_set_handler(handler);
  1168     ICache::invalidate_range(handler, insts_size);
  1169     _handler = handler + insts_size;
  1171   return handler;
  1174 void SignatureHandlerLibrary::add(methodHandle method) {
  1175   if (method->signature_handler() == NULL) {
  1176     // use slow signature handler if we can't do better
  1177     int handler_index = -1;
  1178     // check if we can use customized (fast) signature handler
  1179     if (UseFastSignatureHandlers && method->size_of_parameters() <= Fingerprinter::max_size_of_parameters) {
  1180       // use customized signature handler
  1181       MutexLocker mu(SignatureHandlerLibrary_lock);
  1182       // make sure data structure is initialized
  1183       initialize();
  1184       // lookup method signature's fingerprint
  1185       uint64_t fingerprint = Fingerprinter(method).fingerprint();
  1186       handler_index = _fingerprints->find(fingerprint);
  1187       // create handler if necessary
  1188       if (handler_index < 0) {
  1189         ResourceMark rm;
  1190         ptrdiff_t align_offset = (address)
  1191           round_to((intptr_t)_buffer, CodeEntryAlignment) - (address)_buffer;
  1192         CodeBuffer buffer((address)(_buffer + align_offset),
  1193                           SignatureHandlerLibrary::buffer_size - align_offset);
  1194         InterpreterRuntime::SignatureHandlerGenerator(method, &buffer).generate(fingerprint);
  1195         // copy into code heap
  1196         address handler = set_handler(&buffer);
  1197         if (handler == NULL) {
  1198           // use slow signature handler
  1199         } else {
  1200           // debugging suppport
  1201           if (PrintSignatureHandlers) {
  1202             tty->cr();
  1203             tty->print_cr("argument handler #%d for: %s %s (fingerprint = " UINT64_FORMAT ", %d bytes generated)",
  1204                           _handlers->length(),
  1205                           (method->is_static() ? "static" : "receiver"),
  1206                           method->name_and_sig_as_C_string(),
  1207                           fingerprint,
  1208                           buffer.insts_size());
  1209             Disassembler::decode(handler, handler + buffer.insts_size());
  1210 #ifndef PRODUCT
  1211             tty->print_cr(" --- associated result handler ---");
  1212             address rh_begin = Interpreter::result_handler(method()->result_type());
  1213             address rh_end = rh_begin;
  1214             while (*(int*)rh_end != 0) {
  1215               rh_end += sizeof(int);
  1217             Disassembler::decode(rh_begin, rh_end);
  1218 #endif
  1220           // add handler to library
  1221           _fingerprints->append(fingerprint);
  1222           _handlers->append(handler);
  1223           // set handler index
  1224           assert(_fingerprints->length() == _handlers->length(), "sanity check");
  1225           handler_index = _fingerprints->length() - 1;
  1228       // Set handler under SignatureHandlerLibrary_lock
  1229     if (handler_index < 0) {
  1230       // use generic signature handler
  1231       method->set_signature_handler(Interpreter::slow_signature_handler());
  1232     } else {
  1233       // set handler
  1234       method->set_signature_handler(_handlers->at(handler_index));
  1236     } else {
  1237       CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops());
  1238       // use generic signature handler
  1239       method->set_signature_handler(Interpreter::slow_signature_handler());
  1242 #ifdef ASSERT
  1243   int handler_index = -1;
  1244   int fingerprint_index = -2;
  1246     // '_handlers' and '_fingerprints' are 'GrowableArray's and are NOT synchronized
  1247     // in any way if accessed from multiple threads. To avoid races with another
  1248     // thread which may change the arrays in the above, mutex protected block, we
  1249     // have to protect this read access here with the same mutex as well!
  1250     MutexLocker mu(SignatureHandlerLibrary_lock);
  1251     if (_handlers != NULL) {
  1252     handler_index = _handlers->find(method->signature_handler());
  1253     fingerprint_index = _fingerprints->find(Fingerprinter(method).fingerprint());
  1256   assert(method->signature_handler() == Interpreter::slow_signature_handler() ||
  1257          handler_index == fingerprint_index, "sanity check");
  1258 #endif // ASSERT
  1262 BufferBlob*              SignatureHandlerLibrary::_handler_blob = NULL;
  1263 address                  SignatureHandlerLibrary::_handler      = NULL;
  1264 GrowableArray<uint64_t>* SignatureHandlerLibrary::_fingerprints = NULL;
  1265 GrowableArray<address>*  SignatureHandlerLibrary::_handlers     = NULL;
  1266 address                  SignatureHandlerLibrary::_buffer       = NULL;
  1269 IRT_ENTRY(void, InterpreterRuntime::prepare_native_call(JavaThread* thread, Method* method))
  1270   methodHandle m(thread, method);
  1271   assert(m->is_native(), "sanity check");
  1272   // lookup native function entry point if it doesn't exist
  1273   bool in_base_library;
  1274   if (!m->has_native_function()) {
  1275     NativeLookup::lookup(m, in_base_library, CHECK);
  1277   // make sure signature handler is installed
  1278   SignatureHandlerLibrary::add(m);
  1279   // The interpreter entry point checks the signature handler first,
  1280   // before trying to fetch the native entry point and klass mirror.
  1281   // We must set the signature handler last, so that multiple processors
  1282   // preparing the same method will be sure to see non-null entry & mirror.
  1283 IRT_END
  1285 #if defined(IA32) || defined(AMD64) || defined(ARM) || defined(MIPS64)
  1286 IRT_LEAF(void, InterpreterRuntime::popframe_move_outgoing_args(JavaThread* thread, void* src_address, void* dest_address))
  1287   if (src_address == dest_address) {
  1288     return;
  1290   ResetNoHandleMark rnm; // In a LEAF entry.
  1291   HandleMark hm;
  1292   ResourceMark rm;
  1293   frame fr = thread->last_frame();
  1294   assert(fr.is_interpreted_frame(), "");
  1295   jint bci = fr.interpreter_frame_bci();
  1296   methodHandle mh(thread, fr.interpreter_frame_method());
  1297   Bytecode_invoke invoke(mh, bci);
  1298   ArgumentSizeComputer asc(invoke.signature());
  1299   int size_of_arguments = (asc.size() + (invoke.has_receiver() ? 1 : 0)); // receiver
  1300   Copy::conjoint_jbytes(src_address, dest_address,
  1301                        size_of_arguments * Interpreter::stackElementSize);
  1302 IRT_END
  1303 #endif
  1305 #if INCLUDE_JVMTI
  1306 // This is a support of the JVMTI PopFrame interface.
  1307 // Make sure it is an invokestatic of a polymorphic intrinsic that has a member_name argument
  1308 // and return it as a vm_result so that it can be reloaded in the list of invokestatic parameters.
  1309 // The member_name argument is a saved reference (in local#0) to the member_name.
  1310 // For backward compatibility with some JDK versions (7, 8) it can also be a direct method handle.
  1311 // FIXME: remove DMH case after j.l.i.InvokerBytecodeGenerator code shape is updated.
  1312 IRT_ENTRY(void, InterpreterRuntime::member_name_arg_or_null(JavaThread* thread, address member_name,
  1313                                                             Method* method, address bcp))
  1314   Bytecodes::Code code = Bytecodes::code_at(method, bcp);
  1315   if (code != Bytecodes::_invokestatic) {
  1316     return;
  1318   ConstantPool* cpool = method->constants();
  1319   int cp_index = Bytes::get_native_u2(bcp + 1) + ConstantPool::CPCACHE_INDEX_TAG;
  1320   Symbol* cname = cpool->klass_name_at(cpool->klass_ref_index_at(cp_index));
  1321   Symbol* mname = cpool->name_ref_at(cp_index);
  1323   if (MethodHandles::has_member_arg(cname, mname)) {
  1324     oop member_name_oop = (oop) member_name;
  1325     if (java_lang_invoke_DirectMethodHandle::is_instance(member_name_oop)) {
  1326       // FIXME: remove after j.l.i.InvokerBytecodeGenerator code shape is updated.
  1327       member_name_oop = java_lang_invoke_DirectMethodHandle::member(member_name_oop);
  1329     thread->set_vm_result(member_name_oop);
  1330   } else {
  1331     thread->set_vm_result(NULL);
  1333 IRT_END
  1334 #endif // INCLUDE_JVMTI

mercurial