src/share/vm/interpreter/interpreterRuntime.cpp

Thu, 27 Jan 2011 16:11:27 -0800

author
coleenp
date
Thu, 27 Jan 2011 16:11:27 -0800
changeset 2497
3582bf76420e
parent 2464
633a44a9fc45
child 2508
b92c45f2bc75
permissions
-rw-r--r--

6990754: Use native memory and reference counting to implement SymbolTable
Summary: move symbols from permgen into C heap and reference count them
Reviewed-by: never, acorn, jmasa, stefank

     1 /*
     2  * Copyright (c) 1997, 2011, 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 #include "precompiled.hpp"
    26 #include "classfile/systemDictionary.hpp"
    27 #include "classfile/vmSymbols.hpp"
    28 #include "compiler/compileBroker.hpp"
    29 #include "gc_interface/collectedHeap.hpp"
    30 #include "interpreter/interpreter.hpp"
    31 #include "interpreter/interpreterRuntime.hpp"
    32 #include "interpreter/linkResolver.hpp"
    33 #include "interpreter/templateTable.hpp"
    34 #include "memory/oopFactory.hpp"
    35 #include "memory/universe.inline.hpp"
    36 #include "oops/constantPoolOop.hpp"
    37 #include "oops/cpCacheOop.hpp"
    38 #include "oops/instanceKlass.hpp"
    39 #include "oops/methodDataOop.hpp"
    40 #include "oops/objArrayKlass.hpp"
    41 #include "oops/oop.inline.hpp"
    42 #include "oops/symbol.hpp"
    43 #include "prims/jvmtiExport.hpp"
    44 #include "prims/nativeLookup.hpp"
    45 #include "runtime/biasedLocking.hpp"
    46 #include "runtime/compilationPolicy.hpp"
    47 #include "runtime/deoptimization.hpp"
    48 #include "runtime/fieldDescriptor.hpp"
    49 #include "runtime/handles.inline.hpp"
    50 #include "runtime/interfaceSupport.hpp"
    51 #include "runtime/java.hpp"
    52 #include "runtime/jfieldIDWorkaround.hpp"
    53 #include "runtime/osThread.hpp"
    54 #include "runtime/sharedRuntime.hpp"
    55 #include "runtime/stubRoutines.hpp"
    56 #include "runtime/synchronizer.hpp"
    57 #include "runtime/threadCritical.hpp"
    58 #include "utilities/events.hpp"
    59 #ifdef TARGET_ARCH_x86
    60 # include "vm_version_x86.hpp"
    61 #endif
    62 #ifdef TARGET_ARCH_sparc
    63 # include "vm_version_sparc.hpp"
    64 #endif
    65 #ifdef TARGET_ARCH_zero
    66 # include "vm_version_zero.hpp"
    67 #endif
    68 #ifdef COMPILER2
    69 #include "opto/runtime.hpp"
    70 #endif
    72 class UnlockFlagSaver {
    73   private:
    74     JavaThread* _thread;
    75     bool _do_not_unlock;
    76   public:
    77     UnlockFlagSaver(JavaThread* t) {
    78       _thread = t;
    79       _do_not_unlock = t->do_not_unlock_if_synchronized();
    80       t->set_do_not_unlock_if_synchronized(false);
    81     }
    82     ~UnlockFlagSaver() {
    83       _thread->set_do_not_unlock_if_synchronized(_do_not_unlock);
    84     }
    85 };
    87 //------------------------------------------------------------------------------------------------------------------------
    88 // State accessors
    90 void InterpreterRuntime::set_bcp_and_mdp(address bcp, JavaThread *thread) {
    91   last_frame(thread).interpreter_frame_set_bcp(bcp);
    92   if (ProfileInterpreter) {
    93     // ProfileTraps uses MDOs independently of ProfileInterpreter.
    94     // That is why we must check both ProfileInterpreter and mdo != NULL.
    95     methodDataOop mdo = last_frame(thread).interpreter_frame_method()->method_data();
    96     if (mdo != NULL) {
    97       NEEDS_CLEANUP;
    98       last_frame(thread).interpreter_frame_set_mdp(mdo->bci_to_dp(last_frame(thread).interpreter_frame_bci()));
    99     }
   100   }
   101 }
   103 //------------------------------------------------------------------------------------------------------------------------
   104 // Constants
   107 IRT_ENTRY(void, InterpreterRuntime::ldc(JavaThread* thread, bool wide))
   108   // access constant pool
   109   constantPoolOop pool = method(thread)->constants();
   110   int index = wide ? get_index_u2(thread, Bytecodes::_ldc_w) : get_index_u1(thread, Bytecodes::_ldc);
   111   constantTag tag = pool->tag_at(index);
   113   if (tag.is_unresolved_klass() || tag.is_klass()) {
   114     klassOop klass = pool->klass_at(index, CHECK);
   115     oop java_class = klass->klass_part()->java_mirror();
   116     thread->set_vm_result(java_class);
   117   } else {
   118 #ifdef ASSERT
   119     // If we entered this runtime routine, we believed the tag contained
   120     // an unresolved string, an unresolved class or a resolved class.
   121     // However, another thread could have resolved the unresolved string
   122     // or class by the time we go there.
   123     assert(tag.is_unresolved_string()|| tag.is_string(), "expected string");
   124 #endif
   125     oop s_oop = pool->string_at(index, CHECK);
   126     thread->set_vm_result(s_oop);
   127   }
   128 IRT_END
   130 IRT_ENTRY(void, InterpreterRuntime::resolve_ldc(JavaThread* thread, Bytecodes::Code bytecode)) {
   131   assert(bytecode == Bytecodes::_fast_aldc ||
   132          bytecode == Bytecodes::_fast_aldc_w, "wrong bc");
   133   ResourceMark rm(thread);
   134   methodHandle m (thread, method(thread));
   135   Bytecode_loadconstant ldc(m, bci(thread));
   136   oop result = ldc.resolve_constant(THREAD);
   137   DEBUG_ONLY(ConstantPoolCacheEntry* cpce = m->constants()->cache()->entry_at(ldc.cache_index()));
   138   assert(result == cpce->f1(), "expected result for assembly code");
   139 }
   140 IRT_END
   143 //------------------------------------------------------------------------------------------------------------------------
   144 // Allocation
   146 IRT_ENTRY(void, InterpreterRuntime::_new(JavaThread* thread, constantPoolOopDesc* pool, int index))
   147   klassOop k_oop = pool->klass_at(index, CHECK);
   148   instanceKlassHandle klass (THREAD, k_oop);
   150   // Make sure we are not instantiating an abstract klass
   151   klass->check_valid_for_instantiation(true, CHECK);
   153   // Make sure klass is initialized
   154   klass->initialize(CHECK);
   156   // At this point the class may not be fully initialized
   157   // because of recursive initialization. If it is fully
   158   // initialized & has_finalized is not set, we rewrite
   159   // it into its fast version (Note: no locking is needed
   160   // here since this is an atomic byte write and can be
   161   // done more than once).
   162   //
   163   // Note: In case of classes with has_finalized we don't
   164   //       rewrite since that saves us an extra check in
   165   //       the fast version which then would call the
   166   //       slow version anyway (and do a call back into
   167   //       Java).
   168   //       If we have a breakpoint, then we don't rewrite
   169   //       because the _breakpoint bytecode would be lost.
   170   oop obj = klass->allocate_instance(CHECK);
   171   thread->set_vm_result(obj);
   172 IRT_END
   175 IRT_ENTRY(void, InterpreterRuntime::newarray(JavaThread* thread, BasicType type, jint size))
   176   oop obj = oopFactory::new_typeArray(type, size, CHECK);
   177   thread->set_vm_result(obj);
   178 IRT_END
   181 IRT_ENTRY(void, InterpreterRuntime::anewarray(JavaThread* thread, constantPoolOopDesc* pool, int index, jint size))
   182   // Note: no oopHandle for pool & klass needed since they are not used
   183   //       anymore after new_objArray() and no GC can happen before.
   184   //       (This may have to change if this code changes!)
   185   klassOop  klass = pool->klass_at(index, CHECK);
   186   objArrayOop obj = oopFactory::new_objArray(klass, size, CHECK);
   187   thread->set_vm_result(obj);
   188 IRT_END
   191 IRT_ENTRY(void, InterpreterRuntime::multianewarray(JavaThread* thread, jint* first_size_address))
   192   // We may want to pass in more arguments - could make this slightly faster
   193   constantPoolOop constants = method(thread)->constants();
   194   int          i = get_index_u2(thread, Bytecodes::_multianewarray);
   195   klassOop klass = constants->klass_at(i, CHECK);
   196   int   nof_dims = number_of_dimensions(thread);
   197   assert(oop(klass)->is_klass(), "not a class");
   198   assert(nof_dims >= 1, "multianewarray rank must be nonzero");
   200   // We must create an array of jints to pass to multi_allocate.
   201   ResourceMark rm(thread);
   202   const int small_dims = 10;
   203   jint dim_array[small_dims];
   204   jint *dims = &dim_array[0];
   205   if (nof_dims > small_dims) {
   206     dims = (jint*) NEW_RESOURCE_ARRAY(jint, nof_dims);
   207   }
   208   for (int index = 0; index < nof_dims; index++) {
   209     // offset from first_size_address is addressed as local[index]
   210     int n = Interpreter::local_offset_in_bytes(index)/jintSize;
   211     dims[index] = first_size_address[n];
   212   }
   213   oop obj = arrayKlass::cast(klass)->multi_allocate(nof_dims, dims, CHECK);
   214   thread->set_vm_result(obj);
   215 IRT_END
   218 IRT_ENTRY(void, InterpreterRuntime::register_finalizer(JavaThread* thread, oopDesc* obj))
   219   assert(obj->is_oop(), "must be a valid oop");
   220   assert(obj->klass()->klass_part()->has_finalizer(), "shouldn't be here otherwise");
   221   instanceKlass::register_finalizer(instanceOop(obj), CHECK);
   222 IRT_END
   225 // Quicken instance-of and check-cast bytecodes
   226 IRT_ENTRY(void, InterpreterRuntime::quicken_io_cc(JavaThread* thread))
   227   // Force resolving; quicken the bytecode
   228   int which = get_index_u2(thread, Bytecodes::_checkcast);
   229   constantPoolOop cpool = method(thread)->constants();
   230   // We'd expect to assert that we're only here to quicken bytecodes, but in a multithreaded
   231   // program we might have seen an unquick'd bytecode in the interpreter but have another
   232   // thread quicken the bytecode before we get here.
   233   // assert( cpool->tag_at(which).is_unresolved_klass(), "should only come here to quicken bytecodes" );
   234   klassOop klass = cpool->klass_at(which, CHECK);
   235   thread->set_vm_result(klass);
   236 IRT_END
   239 //------------------------------------------------------------------------------------------------------------------------
   240 // Exceptions
   242 // Assume the compiler is (or will be) interested in this event.
   243 // If necessary, create an MDO to hold the information, and record it.
   244 void InterpreterRuntime::note_trap(JavaThread* thread, int reason, TRAPS) {
   245   assert(ProfileTraps, "call me only if profiling");
   246   methodHandle trap_method(thread, method(thread));
   248   if (trap_method.not_null()) {
   249     methodDataHandle trap_mdo(thread, trap_method->method_data());
   250     if (trap_mdo.is_null()) {
   251       methodOopDesc::build_interpreter_method_data(trap_method, THREAD);
   252       if (HAS_PENDING_EXCEPTION) {
   253         assert((PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())), "we expect only an OOM error here");
   254         CLEAR_PENDING_EXCEPTION;
   255       }
   256       trap_mdo = methodDataHandle(thread, trap_method->method_data());
   257       // and fall through...
   258     }
   259     if (trap_mdo.not_null()) {
   260       // Update per-method count of trap events.  The interpreter
   261       // is updating the MDO to simulate the effect of compiler traps.
   262       int trap_bci = trap_method->bci_from(bcp(thread));
   263       Deoptimization::update_method_data_from_interpreter(trap_mdo, trap_bci, reason);
   264     }
   265   }
   266 }
   268 static Handle get_preinitialized_exception(klassOop k, TRAPS) {
   269   // get klass
   270   instanceKlass* klass = instanceKlass::cast(k);
   271   assert(klass->is_initialized(),
   272          "this klass should have been initialized during VM initialization");
   273   // create instance - do not call constructor since we may have no
   274   // (java) stack space left (should assert constructor is empty)
   275   Handle exception;
   276   oop exception_oop = klass->allocate_instance(CHECK_(exception));
   277   exception = Handle(THREAD, exception_oop);
   278   if (StackTraceInThrowable) {
   279     java_lang_Throwable::fill_in_stack_trace(exception);
   280   }
   281   return exception;
   282 }
   284 // Special handling for stack overflow: since we don't have any (java) stack
   285 // space left we use the pre-allocated & pre-initialized StackOverflowError
   286 // klass to create an stack overflow error instance.  We do not call its
   287 // constructor for the same reason (it is empty, anyway).
   288 IRT_ENTRY(void, InterpreterRuntime::throw_StackOverflowError(JavaThread* thread))
   289   Handle exception = get_preinitialized_exception(
   290                                  SystemDictionary::StackOverflowError_klass(),
   291                                  CHECK);
   292   THROW_HANDLE(exception);
   293 IRT_END
   296 IRT_ENTRY(void, InterpreterRuntime::create_exception(JavaThread* thread, char* name, char* message))
   297   // lookup exception klass
   298   TempNewSymbol s = SymbolTable::new_symbol(name, CHECK);
   299   if (ProfileTraps) {
   300     if (s == vmSymbols::java_lang_ArithmeticException()) {
   301       note_trap(thread, Deoptimization::Reason_div0_check, CHECK);
   302     } else if (s == vmSymbols::java_lang_NullPointerException()) {
   303       note_trap(thread, Deoptimization::Reason_null_check, CHECK);
   304     }
   305   }
   306   // create exception
   307   Handle exception = Exceptions::new_exception(thread, s, message);
   308   thread->set_vm_result(exception());
   309 IRT_END
   312 IRT_ENTRY(void, InterpreterRuntime::create_klass_exception(JavaThread* thread, char* name, oopDesc* obj))
   313   ResourceMark rm(thread);
   314   const char* klass_name = Klass::cast(obj->klass())->external_name();
   315   // lookup exception klass
   316   TempNewSymbol s = SymbolTable::new_symbol(name, CHECK);
   317   if (ProfileTraps) {
   318     note_trap(thread, Deoptimization::Reason_class_check, CHECK);
   319   }
   320   // create exception, with klass name as detail message
   321   Handle exception = Exceptions::new_exception(thread, s, klass_name);
   322   thread->set_vm_result(exception());
   323 IRT_END
   326 IRT_ENTRY(void, InterpreterRuntime::throw_ArrayIndexOutOfBoundsException(JavaThread* thread, char* name, jint index))
   327   char message[jintAsStringSize];
   328   // lookup exception klass
   329   TempNewSymbol s = SymbolTable::new_symbol(name, CHECK);
   330   if (ProfileTraps) {
   331     note_trap(thread, Deoptimization::Reason_range_check, CHECK);
   332   }
   333   // create exception
   334   sprintf(message, "%d", index);
   335   THROW_MSG(s, message);
   336 IRT_END
   338 IRT_ENTRY(void, InterpreterRuntime::throw_ClassCastException(
   339   JavaThread* thread, oopDesc* obj))
   341   ResourceMark rm(thread);
   342   char* message = SharedRuntime::generate_class_cast_message(
   343     thread, Klass::cast(obj->klass())->external_name());
   345   if (ProfileTraps) {
   346     note_trap(thread, Deoptimization::Reason_class_check, CHECK);
   347   }
   349   // create exception
   350   THROW_MSG(vmSymbols::java_lang_ClassCastException(), message);
   351 IRT_END
   353 // required can be either a MethodType, or a Class (for a single argument)
   354 // actual (if not null) can be either a MethodHandle, or an arbitrary value (for a single argument)
   355 IRT_ENTRY(void, InterpreterRuntime::throw_WrongMethodTypeException(JavaThread* thread,
   356                                                                    oopDesc* required,
   357                                                                    oopDesc* actual)) {
   358   ResourceMark rm(thread);
   359   char* message = SharedRuntime::generate_wrong_method_type_message(thread, required, actual);
   361   if (ProfileTraps) {
   362     note_trap(thread, Deoptimization::Reason_constraint, CHECK);
   363   }
   365   // create exception
   366   THROW_MSG(vmSymbols::java_dyn_WrongMethodTypeException(), message);
   367 }
   368 IRT_END
   372 // exception_handler_for_exception(...) returns the continuation address,
   373 // the exception oop (via TLS) and sets the bci/bcp for the continuation.
   374 // The exception oop is returned to make sure it is preserved over GC (it
   375 // is only on the stack if the exception was thrown explicitly via athrow).
   376 // During this operation, the expression stack contains the values for the
   377 // bci where the exception happened. If the exception was propagated back
   378 // from a call, the expression stack contains the values for the bci at the
   379 // invoke w/o arguments (i.e., as if one were inside the call).
   380 IRT_ENTRY(address, InterpreterRuntime::exception_handler_for_exception(JavaThread* thread, oopDesc* exception))
   382   Handle             h_exception(thread, exception);
   383   methodHandle       h_method   (thread, method(thread));
   384   constantPoolHandle h_constants(thread, h_method->constants());
   385   typeArrayHandle    h_extable  (thread, h_method->exception_table());
   386   bool               should_repeat;
   387   int                handler_bci;
   388   int                current_bci = bci(thread);
   390   // Need to do this check first since when _do_not_unlock_if_synchronized
   391   // is set, we don't want to trigger any classloading which may make calls
   392   // into java, or surprisingly find a matching exception handler for bci 0
   393   // since at this moment the method hasn't been "officially" entered yet.
   394   if (thread->do_not_unlock_if_synchronized()) {
   395     ResourceMark rm;
   396     assert(current_bci == 0,  "bci isn't zero for do_not_unlock_if_synchronized");
   397     thread->set_vm_result(exception);
   398 #ifdef CC_INTERP
   399     return (address) -1;
   400 #else
   401     return Interpreter::remove_activation_entry();
   402 #endif
   403   }
   405   do {
   406     should_repeat = false;
   408     // assertions
   409 #ifdef ASSERT
   410     assert(h_exception.not_null(), "NULL exceptions should be handled by athrow");
   411     assert(h_exception->is_oop(), "just checking");
   412     // Check that exception is a subclass of Throwable, otherwise we have a VerifyError
   413     if (!(h_exception->is_a(SystemDictionary::Throwable_klass()))) {
   414       if (ExitVMOnVerifyError) vm_exit(-1);
   415       ShouldNotReachHere();
   416     }
   417 #endif
   419     // tracing
   420     if (TraceExceptions) {
   421       ttyLocker ttyl;
   422       ResourceMark rm(thread);
   423       tty->print_cr("Exception <%s> (" INTPTR_FORMAT ")", h_exception->print_value_string(), (address)h_exception());
   424       tty->print_cr(" thrown in interpreter method <%s>", h_method->print_value_string());
   425       tty->print_cr(" at bci %d for thread " INTPTR_FORMAT, current_bci, thread);
   426     }
   427 // Don't go paging in something which won't be used.
   428 //     else if (h_extable->length() == 0) {
   429 //       // disabled for now - interpreter is not using shortcut yet
   430 //       // (shortcut is not to call runtime if we have no exception handlers)
   431 //       // warning("performance bug: should not call runtime if method has no exception handlers");
   432 //     }
   433     // for AbortVMOnException flag
   434     NOT_PRODUCT(Exceptions::debug_check_abort(h_exception));
   436     // exception handler lookup
   437     KlassHandle h_klass(THREAD, h_exception->klass());
   438     handler_bci = h_method->fast_exception_handler_bci_for(h_klass, current_bci, THREAD);
   439     if (HAS_PENDING_EXCEPTION) {
   440       // We threw an exception while trying to find the exception handler.
   441       // Transfer the new exception to the exception handle which will
   442       // be set into thread local storage, and do another lookup for an
   443       // exception handler for this exception, this time starting at the
   444       // BCI of the exception handler which caused the exception to be
   445       // thrown (bug 4307310).
   446       h_exception = Handle(THREAD, PENDING_EXCEPTION);
   447       CLEAR_PENDING_EXCEPTION;
   448       if (handler_bci >= 0) {
   449         current_bci = handler_bci;
   450         should_repeat = true;
   451       }
   452     }
   453   } while (should_repeat == true);
   455   // notify JVMTI of an exception throw; JVMTI will detect if this is a first
   456   // time throw or a stack unwinding throw and accordingly notify the debugger
   457   if (JvmtiExport::can_post_on_exceptions()) {
   458     JvmtiExport::post_exception_throw(thread, h_method(), bcp(thread), h_exception());
   459   }
   461 #ifdef CC_INTERP
   462   address continuation = (address)(intptr_t) handler_bci;
   463 #else
   464   address continuation = NULL;
   465 #endif
   466   address handler_pc = NULL;
   467   if (handler_bci < 0 || !thread->reguard_stack((address) &continuation)) {
   468     // Forward exception to callee (leaving bci/bcp untouched) because (a) no
   469     // handler in this method, or (b) after a stack overflow there is not yet
   470     // enough stack space available to reprotect the stack.
   471 #ifndef CC_INTERP
   472     continuation = Interpreter::remove_activation_entry();
   473 #endif
   474     // Count this for compilation purposes
   475     h_method->interpreter_throwout_increment();
   476   } else {
   477     // handler in this method => change bci/bcp to handler bci/bcp and continue there
   478     handler_pc = h_method->code_base() + handler_bci;
   479 #ifndef CC_INTERP
   480     set_bcp_and_mdp(handler_pc, thread);
   481     continuation = Interpreter::dispatch_table(vtos)[*handler_pc];
   482 #endif
   483   }
   484   // notify debugger of an exception catch
   485   // (this is good for exceptions caught in native methods as well)
   486   if (JvmtiExport::can_post_on_exceptions()) {
   487     JvmtiExport::notice_unwind_due_to_exception(thread, h_method(), handler_pc, h_exception(), (handler_pc != NULL));
   488   }
   490   thread->set_vm_result(h_exception());
   491   return continuation;
   492 IRT_END
   495 IRT_ENTRY(void, InterpreterRuntime::throw_pending_exception(JavaThread* thread))
   496   assert(thread->has_pending_exception(), "must only ne called if there's an exception pending");
   497   // nothing to do - eventually we should remove this code entirely (see comments @ call sites)
   498 IRT_END
   501 IRT_ENTRY(void, InterpreterRuntime::throw_AbstractMethodError(JavaThread* thread))
   502   THROW(vmSymbols::java_lang_AbstractMethodError());
   503 IRT_END
   506 IRT_ENTRY(void, InterpreterRuntime::throw_IncompatibleClassChangeError(JavaThread* thread))
   507   THROW(vmSymbols::java_lang_IncompatibleClassChangeError());
   508 IRT_END
   511 //------------------------------------------------------------------------------------------------------------------------
   512 // Fields
   513 //
   515 IRT_ENTRY(void, InterpreterRuntime::resolve_get_put(JavaThread* thread, Bytecodes::Code bytecode))
   516   // resolve field
   517   FieldAccessInfo info;
   518   constantPoolHandle pool(thread, method(thread)->constants());
   519   bool is_static = (bytecode == Bytecodes::_getstatic || bytecode == Bytecodes::_putstatic);
   521   {
   522     JvmtiHideSingleStepping jhss(thread);
   523     LinkResolver::resolve_field(info, pool, get_index_u2_cpcache(thread, bytecode),
   524                                 bytecode, false, CHECK);
   525   } // end JvmtiHideSingleStepping
   527   // check if link resolution caused cpCache to be updated
   528   if (already_resolved(thread)) return;
   530   // compute auxiliary field attributes
   531   TosState state  = as_TosState(info.field_type());
   533   // We need to delay resolving put instructions on final fields
   534   // until we actually invoke one. This is required so we throw
   535   // exceptions at the correct place. If we do not resolve completely
   536   // in the current pass, leaving the put_code set to zero will
   537   // cause the next put instruction to reresolve.
   538   bool is_put = (bytecode == Bytecodes::_putfield ||
   539                  bytecode == Bytecodes::_putstatic);
   540   Bytecodes::Code put_code = (Bytecodes::Code)0;
   542   // We also need to delay resolving getstatic instructions until the
   543   // class is intitialized.  This is required so that access to the static
   544   // field will call the initialization function every time until the class
   545   // is completely initialized ala. in 2.17.5 in JVM Specification.
   546   instanceKlass *klass = instanceKlass::cast(info.klass()->as_klassOop());
   547   bool uninitialized_static = ((bytecode == Bytecodes::_getstatic || bytecode == Bytecodes::_putstatic) &&
   548                                !klass->is_initialized());
   549   Bytecodes::Code get_code = (Bytecodes::Code)0;
   552   if (!uninitialized_static) {
   553     get_code = ((is_static) ? Bytecodes::_getstatic : Bytecodes::_getfield);
   554     if (is_put || !info.access_flags().is_final()) {
   555       put_code = ((is_static) ? Bytecodes::_putstatic : Bytecodes::_putfield);
   556     }
   557   }
   559   cache_entry(thread)->set_field(
   560     get_code,
   561     put_code,
   562     info.klass(),
   563     info.field_index(),
   564     info.field_offset(),
   565     state,
   566     info.access_flags().is_final(),
   567     info.access_flags().is_volatile()
   568   );
   569 IRT_END
   572 //------------------------------------------------------------------------------------------------------------------------
   573 // Synchronization
   574 //
   575 // The interpreter's synchronization code is factored out so that it can
   576 // be shared by method invocation and synchronized blocks.
   577 //%note synchronization_3
   579 static void trace_locking(Handle& h_locking_obj, bool is_locking) {
   580   ObjectSynchronizer::trace_locking(h_locking_obj, false, true, is_locking);
   581 }
   584 //%note monitor_1
   585 IRT_ENTRY_NO_ASYNC(void, InterpreterRuntime::monitorenter(JavaThread* thread, BasicObjectLock* elem))
   586 #ifdef ASSERT
   587   thread->last_frame().interpreter_frame_verify_monitor(elem);
   588 #endif
   589   if (PrintBiasedLockingStatistics) {
   590     Atomic::inc(BiasedLocking::slow_path_entry_count_addr());
   591   }
   592   Handle h_obj(thread, elem->obj());
   593   assert(Universe::heap()->is_in_reserved_or_null(h_obj()),
   594          "must be NULL or an object");
   595   if (UseBiasedLocking) {
   596     // Retry fast entry if bias is revoked to avoid unnecessary inflation
   597     ObjectSynchronizer::fast_enter(h_obj, elem->lock(), true, CHECK);
   598   } else {
   599     ObjectSynchronizer::slow_enter(h_obj, elem->lock(), CHECK);
   600   }
   601   assert(Universe::heap()->is_in_reserved_or_null(elem->obj()),
   602          "must be NULL or an object");
   603 #ifdef ASSERT
   604   thread->last_frame().interpreter_frame_verify_monitor(elem);
   605 #endif
   606 IRT_END
   609 //%note monitor_1
   610 IRT_ENTRY_NO_ASYNC(void, InterpreterRuntime::monitorexit(JavaThread* thread, BasicObjectLock* elem))
   611 #ifdef ASSERT
   612   thread->last_frame().interpreter_frame_verify_monitor(elem);
   613 #endif
   614   Handle h_obj(thread, elem->obj());
   615   assert(Universe::heap()->is_in_reserved_or_null(h_obj()),
   616          "must be NULL or an object");
   617   if (elem == NULL || h_obj()->is_unlocked()) {
   618     THROW(vmSymbols::java_lang_IllegalMonitorStateException());
   619   }
   620   ObjectSynchronizer::slow_exit(h_obj(), elem->lock(), thread);
   621   // Free entry. This must be done here, since a pending exception might be installed on
   622   // exit. If it is not cleared, the exception handling code will try to unlock the monitor again.
   623   elem->set_obj(NULL);
   624 #ifdef ASSERT
   625   thread->last_frame().interpreter_frame_verify_monitor(elem);
   626 #endif
   627 IRT_END
   630 IRT_ENTRY(void, InterpreterRuntime::throw_illegal_monitor_state_exception(JavaThread* thread))
   631   THROW(vmSymbols::java_lang_IllegalMonitorStateException());
   632 IRT_END
   635 IRT_ENTRY(void, InterpreterRuntime::new_illegal_monitor_state_exception(JavaThread* thread))
   636   // Returns an illegal exception to install into the current thread. The
   637   // pending_exception flag is cleared so normal exception handling does not
   638   // trigger. Any current installed exception will be overwritten. This
   639   // method will be called during an exception unwind.
   641   assert(!HAS_PENDING_EXCEPTION, "no pending exception");
   642   Handle exception(thread, thread->vm_result());
   643   assert(exception() != NULL, "vm result should be set");
   644   thread->set_vm_result(NULL); // clear vm result before continuing (may cause memory leaks and assert failures)
   645   if (!exception->is_a(SystemDictionary::ThreadDeath_klass())) {
   646     exception = get_preinitialized_exception(
   647                        SystemDictionary::IllegalMonitorStateException_klass(),
   648                        CATCH);
   649   }
   650   thread->set_vm_result(exception());
   651 IRT_END
   654 //------------------------------------------------------------------------------------------------------------------------
   655 // Invokes
   657 IRT_ENTRY(Bytecodes::Code, InterpreterRuntime::get_original_bytecode_at(JavaThread* thread, methodOopDesc* method, address bcp))
   658   return method->orig_bytecode_at(method->bci_from(bcp));
   659 IRT_END
   661 IRT_ENTRY(void, InterpreterRuntime::set_original_bytecode_at(JavaThread* thread, methodOopDesc* method, address bcp, Bytecodes::Code new_code))
   662   method->set_orig_bytecode_at(method->bci_from(bcp), new_code);
   663 IRT_END
   665 IRT_ENTRY(void, InterpreterRuntime::_breakpoint(JavaThread* thread, methodOopDesc* method, address bcp))
   666   JvmtiExport::post_raw_breakpoint(thread, method, bcp);
   667 IRT_END
   669 IRT_ENTRY(void, InterpreterRuntime::resolve_invoke(JavaThread* thread, Bytecodes::Code bytecode))
   670   // extract receiver from the outgoing argument list if necessary
   671   Handle receiver(thread, NULL);
   672   if (bytecode == Bytecodes::_invokevirtual || bytecode == Bytecodes::_invokeinterface) {
   673     ResourceMark rm(thread);
   674     methodHandle m (thread, method(thread));
   675     Bytecode_invoke call(m, bci(thread));
   676     Symbol* signature = call.signature();
   677     receiver = Handle(thread,
   678                   thread->last_frame().interpreter_callee_receiver(signature));
   679     assert(Universe::heap()->is_in_reserved_or_null(receiver()),
   680            "sanity check");
   681     assert(receiver.is_null() ||
   682            Universe::heap()->is_in_reserved(receiver->klass()),
   683            "sanity check");
   684   }
   686   // resolve method
   687   CallInfo info;
   688   constantPoolHandle pool(thread, method(thread)->constants());
   690   {
   691     JvmtiHideSingleStepping jhss(thread);
   692     LinkResolver::resolve_invoke(info, receiver, pool,
   693                                  get_index_u2_cpcache(thread, bytecode), bytecode, CHECK);
   694     if (JvmtiExport::can_hotswap_or_post_breakpoint()) {
   695       int retry_count = 0;
   696       while (info.resolved_method()->is_old()) {
   697         // It is very unlikely that method is redefined more than 100 times
   698         // in the middle of resolve. If it is looping here more than 100 times
   699         // means then there could be a bug here.
   700         guarantee((retry_count++ < 100),
   701                   "Could not resolve to latest version of redefined method");
   702         // method is redefined in the middle of resolve so re-try.
   703         LinkResolver::resolve_invoke(info, receiver, pool,
   704                                      get_index_u2_cpcache(thread, bytecode), bytecode, CHECK);
   705       }
   706     }
   707   } // end JvmtiHideSingleStepping
   709   // check if link resolution caused cpCache to be updated
   710   if (already_resolved(thread)) return;
   712   if (bytecode == Bytecodes::_invokeinterface) {
   714     if (TraceItables && Verbose) {
   715       ResourceMark rm(thread);
   716       tty->print_cr("Resolving: klass: %s to method: %s", info.resolved_klass()->name()->as_C_string(), info.resolved_method()->name()->as_C_string());
   717     }
   718     if (info.resolved_method()->method_holder() ==
   719                                             SystemDictionary::Object_klass()) {
   720       // NOTE: THIS IS A FIX FOR A CORNER CASE in the JVM spec
   721       // (see also cpCacheOop.cpp for details)
   722       methodHandle rm = info.resolved_method();
   723       assert(rm->is_final() || info.has_vtable_index(),
   724              "should have been set already");
   725       cache_entry(thread)->set_method(bytecode, rm, info.vtable_index());
   726     } else {
   727       // Setup itable entry
   728       int index = klassItable::compute_itable_index(info.resolved_method()());
   729       cache_entry(thread)->set_interface_call(info.resolved_method(), index);
   730     }
   731   } else {
   732     cache_entry(thread)->set_method(
   733       bytecode,
   734       info.resolved_method(),
   735       info.vtable_index());
   736   }
   737 IRT_END
   740 // First time execution:  Resolve symbols, create a permanent CallSite object.
   741 IRT_ENTRY(void, InterpreterRuntime::resolve_invokedynamic(JavaThread* thread)) {
   742   ResourceMark rm(thread);
   744   assert(EnableInvokeDynamic, "");
   746   const Bytecodes::Code bytecode = Bytecodes::_invokedynamic;
   748   methodHandle caller_method(thread, method(thread));
   750   constantPoolHandle pool(thread, caller_method->constants());
   751   pool->set_invokedynamic();    // mark header to flag active call sites
   753   int caller_bci = 0;
   754   int site_index = 0;
   755   { address caller_bcp = bcp(thread);
   756     caller_bci = caller_method->bci_from(caller_bcp);
   757     site_index = Bytes::get_native_u4(caller_bcp+1);
   758   }
   759   assert(site_index == InterpreterRuntime::bytecode(thread).get_index_u4(bytecode), "");
   760   assert(constantPoolCacheOopDesc::is_secondary_index(site_index), "proper format");
   761   // there is a second CPC entries that is of interest; it caches signature info:
   762   int main_index = pool->cache()->secondary_entry_at(site_index)->main_entry_index();
   763   int pool_index = pool->cache()->entry_at(main_index)->constant_pool_index();
   765   // first resolve the signature to a MH.invoke methodOop
   766   if (!pool->cache()->entry_at(main_index)->is_resolved(bytecode)) {
   767     JvmtiHideSingleStepping jhss(thread);
   768     CallInfo callinfo;
   769     LinkResolver::resolve_invoke(callinfo, Handle(), pool,
   770                                  site_index, bytecode, CHECK);
   771     // The main entry corresponds to a JVM_CONSTANT_InvokeDynamic, and serves
   772     // as a common reference point for all invokedynamic call sites with
   773     // that exact call descriptor.  We will link it in the CP cache exactly
   774     // as if it were an invokevirtual of MethodHandle.invoke.
   775     pool->cache()->entry_at(main_index)->set_method(
   776       bytecode,
   777       callinfo.resolved_method(),
   778       callinfo.vtable_index());
   779   }
   781   // The method (f2 entry) of the main entry is the MH.invoke for the
   782   // invokedynamic target call signature.
   783   oop f1_value = pool->cache()->entry_at(main_index)->f1();
   784   methodHandle signature_invoker(THREAD, (methodOop) f1_value);
   785   assert(signature_invoker.not_null() && signature_invoker->is_method() && signature_invoker->is_method_handle_invoke(),
   786          "correct result from LinkResolver::resolve_invokedynamic");
   788   Handle info;  // optional argument(s) in JVM_CONSTANT_InvokeDynamic
   789   Handle bootm = SystemDictionary::find_bootstrap_method(caller_method, caller_bci,
   790                                                          main_index, info, CHECK);
   791   if (!java_dyn_MethodHandle::is_instance(bootm())) {
   792     THROW_MSG(vmSymbols::java_lang_IllegalStateException(),
   793               "no bootstrap method found for invokedynamic");
   794   }
   796   // Short circuit if CallSite has been bound already:
   797   if (!pool->cache()->secondary_entry_at(site_index)->is_f1_null())
   798     return;
   800   Symbol*  call_site_name = pool->name_ref_at(site_index);
   802   Handle call_site
   803     = SystemDictionary::make_dynamic_call_site(bootm,
   804                                                // Callee information:
   805                                                call_site_name,
   806                                                signature_invoker,
   807                                                info,
   808                                                // Caller information:
   809                                                caller_method,
   810                                                caller_bci,
   811                                                CHECK);
   813   // In the secondary entry, the f1 field is the call site, and the f2 (index)
   814   // field is some data about the invoke site.  Currently, it is just the BCI.
   815   // Later, it might be changed to help manage inlining dependencies.
   816   pool->cache()->secondary_entry_at(site_index)->set_dynamic_call(call_site, signature_invoker);
   817 }
   818 IRT_END
   821 //------------------------------------------------------------------------------------------------------------------------
   822 // Miscellaneous
   825 nmethod* InterpreterRuntime::frequency_counter_overflow(JavaThread* thread, address branch_bcp) {
   826   nmethod* nm = frequency_counter_overflow_inner(thread, branch_bcp);
   827   assert(branch_bcp != NULL || nm == NULL, "always returns null for non OSR requests");
   828   if (branch_bcp != NULL && nm != NULL) {
   829     // This was a successful request for an OSR nmethod.  Because
   830     // frequency_counter_overflow_inner ends with a safepoint check,
   831     // nm could have been unloaded so look it up again.  It's unsafe
   832     // to examine nm directly since it might have been freed and used
   833     // for something else.
   834     frame fr = thread->last_frame();
   835     methodOop method =  fr.interpreter_frame_method();
   836     int bci = method->bci_from(fr.interpreter_frame_bcp());
   837     nm = method->lookup_osr_nmethod_for(bci, CompLevel_none, false);
   838   }
   839   return nm;
   840 }
   842 IRT_ENTRY(nmethod*,
   843           InterpreterRuntime::frequency_counter_overflow_inner(JavaThread* thread, address branch_bcp))
   844   // use UnlockFlagSaver to clear and restore the _do_not_unlock_if_synchronized
   845   // flag, in case this method triggers classloading which will call into Java.
   846   UnlockFlagSaver fs(thread);
   848   frame fr = thread->last_frame();
   849   assert(fr.is_interpreted_frame(), "must come from interpreter");
   850   methodHandle method(thread, fr.interpreter_frame_method());
   851   const int branch_bci = branch_bcp != NULL ? method->bci_from(branch_bcp) : InvocationEntryBci;
   852   const int bci = branch_bcp != NULL ? method->bci_from(fr.interpreter_frame_bcp()) : InvocationEntryBci;
   854   nmethod* osr_nm = CompilationPolicy::policy()->event(method, method, branch_bci, bci, CompLevel_none, thread);
   856   if (osr_nm != NULL) {
   857     // We may need to do on-stack replacement which requires that no
   858     // monitors in the activation are biased because their
   859     // BasicObjectLocks will need to migrate during OSR. Force
   860     // unbiasing of all monitors in the activation now (even though
   861     // the OSR nmethod might be invalidated) because we don't have a
   862     // safepoint opportunity later once the migration begins.
   863     if (UseBiasedLocking) {
   864       ResourceMark rm;
   865       GrowableArray<Handle>* objects_to_revoke = new GrowableArray<Handle>();
   866       for( BasicObjectLock *kptr = fr.interpreter_frame_monitor_end();
   867            kptr < fr.interpreter_frame_monitor_begin();
   868            kptr = fr.next_monitor_in_interpreter_frame(kptr) ) {
   869         if( kptr->obj() != NULL ) {
   870           objects_to_revoke->append(Handle(THREAD, kptr->obj()));
   871         }
   872       }
   873       BiasedLocking::revoke(objects_to_revoke);
   874     }
   875   }
   876   return osr_nm;
   877 IRT_END
   879 IRT_LEAF(jint, InterpreterRuntime::bcp_to_di(methodOopDesc* method, address cur_bcp))
   880   assert(ProfileInterpreter, "must be profiling interpreter");
   881   int bci = method->bci_from(cur_bcp);
   882   methodDataOop mdo = method->method_data();
   883   if (mdo == NULL)  return 0;
   884   return mdo->bci_to_di(bci);
   885 IRT_END
   887 IRT_ENTRY(void, InterpreterRuntime::profile_method(JavaThread* thread))
   888   // use UnlockFlagSaver to clear and restore the _do_not_unlock_if_synchronized
   889   // flag, in case this method triggers classloading which will call into Java.
   890   UnlockFlagSaver fs(thread);
   892   assert(ProfileInterpreter, "must be profiling interpreter");
   893   frame fr = thread->last_frame();
   894   assert(fr.is_interpreted_frame(), "must come from interpreter");
   895   methodHandle method(thread, fr.interpreter_frame_method());
   896   methodOopDesc::build_interpreter_method_data(method, THREAD);
   897   if (HAS_PENDING_EXCEPTION) {
   898     assert((PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())), "we expect only an OOM error here");
   899     CLEAR_PENDING_EXCEPTION;
   900     // and fall through...
   901   }
   902 IRT_END
   905 #ifdef ASSERT
   906 IRT_LEAF(void, InterpreterRuntime::verify_mdp(methodOopDesc* method, address bcp, address mdp))
   907   assert(ProfileInterpreter, "must be profiling interpreter");
   909   methodDataOop mdo = method->method_data();
   910   assert(mdo != NULL, "must not be null");
   912   int bci = method->bci_from(bcp);
   914   address mdp2 = mdo->bci_to_dp(bci);
   915   if (mdp != mdp2) {
   916     ResourceMark rm;
   917     ResetNoHandleMark rnm; // In a LEAF entry.
   918     HandleMark hm;
   919     tty->print_cr("FAILED verify : actual mdp %p   expected mdp %p @ bci %d", mdp, mdp2, bci);
   920     int current_di = mdo->dp_to_di(mdp);
   921     int expected_di  = mdo->dp_to_di(mdp2);
   922     tty->print_cr("  actual di %d   expected di %d", current_di, expected_di);
   923     int expected_approx_bci = mdo->data_at(expected_di)->bci();
   924     int approx_bci = -1;
   925     if (current_di >= 0) {
   926       approx_bci = mdo->data_at(current_di)->bci();
   927     }
   928     tty->print_cr("  actual bci is %d  expected bci %d", approx_bci, expected_approx_bci);
   929     mdo->print_on(tty);
   930     method->print_codes();
   931   }
   932   assert(mdp == mdp2, "wrong mdp");
   933 IRT_END
   934 #endif // ASSERT
   936 IRT_ENTRY(void, InterpreterRuntime::update_mdp_for_ret(JavaThread* thread, int return_bci))
   937   assert(ProfileInterpreter, "must be profiling interpreter");
   938   ResourceMark rm(thread);
   939   HandleMark hm(thread);
   940   frame fr = thread->last_frame();
   941   assert(fr.is_interpreted_frame(), "must come from interpreter");
   942   methodDataHandle h_mdo(thread, fr.interpreter_frame_method()->method_data());
   944   // Grab a lock to ensure atomic access to setting the return bci and
   945   // the displacement.  This can block and GC, invalidating all naked oops.
   946   MutexLocker ml(RetData_lock);
   948   // ProfileData is essentially a wrapper around a derived oop, so we
   949   // need to take the lock before making any ProfileData structures.
   950   ProfileData* data = h_mdo->data_at(h_mdo->dp_to_di(fr.interpreter_frame_mdp()));
   951   RetData* rdata = data->as_RetData();
   952   address new_mdp = rdata->fixup_ret(return_bci, h_mdo);
   953   fr.interpreter_frame_set_mdp(new_mdp);
   954 IRT_END
   957 IRT_ENTRY(void, InterpreterRuntime::at_safepoint(JavaThread* thread))
   958   // We used to need an explict preserve_arguments here for invoke bytecodes. However,
   959   // stack traversal automatically takes care of preserving arguments for invoke, so
   960   // this is no longer needed.
   962   // IRT_END does an implicit safepoint check, hence we are guaranteed to block
   963   // if this is called during a safepoint
   965   if (JvmtiExport::should_post_single_step()) {
   966     // We are called during regular safepoints and when the VM is
   967     // single stepping. If any thread is marked for single stepping,
   968     // then we may have JVMTI work to do.
   969     JvmtiExport::at_single_stepping_point(thread, method(thread), bcp(thread));
   970   }
   971 IRT_END
   973 IRT_ENTRY(void, InterpreterRuntime::post_field_access(JavaThread *thread, oopDesc* obj,
   974 ConstantPoolCacheEntry *cp_entry))
   976   // check the access_flags for the field in the klass
   977   instanceKlass* ik = instanceKlass::cast((klassOop)cp_entry->f1());
   978   typeArrayOop fields = ik->fields();
   979   int index = cp_entry->field_index();
   980   assert(index < fields->length(), "holders field index is out of range");
   981   // bail out if field accesses are not watched
   982   if ((fields->ushort_at(index) & JVM_ACC_FIELD_ACCESS_WATCHED) == 0) return;
   984   switch(cp_entry->flag_state()) {
   985     case btos:    // fall through
   986     case ctos:    // fall through
   987     case stos:    // fall through
   988     case itos:    // fall through
   989     case ftos:    // fall through
   990     case ltos:    // fall through
   991     case dtos:    // fall through
   992     case atos: break;
   993     default: ShouldNotReachHere(); return;
   994   }
   995   bool is_static = (obj == NULL);
   996   HandleMark hm(thread);
   998   Handle h_obj;
   999   if (!is_static) {
  1000     // non-static field accessors have an object, but we need a handle
  1001     h_obj = Handle(thread, obj);
  1003   instanceKlassHandle h_cp_entry_f1(thread, (klassOop)cp_entry->f1());
  1004   jfieldID fid = jfieldIDWorkaround::to_jfieldID(h_cp_entry_f1, cp_entry->f2(), is_static);
  1005   JvmtiExport::post_field_access(thread, method(thread), bcp(thread), h_cp_entry_f1, h_obj, fid);
  1006 IRT_END
  1008 IRT_ENTRY(void, InterpreterRuntime::post_field_modification(JavaThread *thread,
  1009   oopDesc* obj, ConstantPoolCacheEntry *cp_entry, jvalue *value))
  1011   klassOop k = (klassOop)cp_entry->f1();
  1013   // check the access_flags for the field in the klass
  1014   instanceKlass* ik = instanceKlass::cast(k);
  1015   typeArrayOop fields = ik->fields();
  1016   int index = cp_entry->field_index();
  1017   assert(index < fields->length(), "holders field index is out of range");
  1018   // bail out if field modifications are not watched
  1019   if ((fields->ushort_at(index) & JVM_ACC_FIELD_MODIFICATION_WATCHED) == 0) return;
  1021   char sig_type = '\0';
  1023   switch(cp_entry->flag_state()) {
  1024     case btos: sig_type = 'Z'; break;
  1025     case ctos: sig_type = 'C'; break;
  1026     case stos: sig_type = 'S'; break;
  1027     case itos: sig_type = 'I'; break;
  1028     case ftos: sig_type = 'F'; break;
  1029     case atos: sig_type = 'L'; break;
  1030     case ltos: sig_type = 'J'; break;
  1031     case dtos: sig_type = 'D'; break;
  1032     default:  ShouldNotReachHere(); return;
  1034   bool is_static = (obj == NULL);
  1036   HandleMark hm(thread);
  1037   instanceKlassHandle h_klass(thread, k);
  1038   jfieldID fid = jfieldIDWorkaround::to_jfieldID(h_klass, cp_entry->f2(), is_static);
  1039   jvalue fvalue;
  1040 #ifdef _LP64
  1041   fvalue = *value;
  1042 #else
  1043   // Long/double values are stored unaligned and also noncontiguously with
  1044   // tagged stacks.  We can't just do a simple assignment even in the non-
  1045   // J/D cases because a C++ compiler is allowed to assume that a jvalue is
  1046   // 8-byte aligned, and interpreter stack slots are only 4-byte aligned.
  1047   // We assume that the two halves of longs/doubles are stored in interpreter
  1048   // stack slots in platform-endian order.
  1049   jlong_accessor u;
  1050   jint* newval = (jint*)value;
  1051   u.words[0] = newval[0];
  1052   u.words[1] = newval[Interpreter::stackElementWords]; // skip if tag
  1053   fvalue.j = u.long_value;
  1054 #endif // _LP64
  1056   Handle h_obj;
  1057   if (!is_static) {
  1058     // non-static field accessors have an object, but we need a handle
  1059     h_obj = Handle(thread, obj);
  1062   JvmtiExport::post_raw_field_modification(thread, method(thread), bcp(thread), h_klass, h_obj,
  1063                                            fid, sig_type, &fvalue);
  1064 IRT_END
  1066 IRT_ENTRY(void, InterpreterRuntime::post_method_entry(JavaThread *thread))
  1067   JvmtiExport::post_method_entry(thread, InterpreterRuntime::method(thread), InterpreterRuntime::last_frame(thread));
  1068 IRT_END
  1071 IRT_ENTRY(void, InterpreterRuntime::post_method_exit(JavaThread *thread))
  1072   JvmtiExport::post_method_exit(thread, InterpreterRuntime::method(thread), InterpreterRuntime::last_frame(thread));
  1073 IRT_END
  1075 IRT_LEAF(int, InterpreterRuntime::interpreter_contains(address pc))
  1077   return (Interpreter::contains(pc) ? 1 : 0);
  1079 IRT_END
  1082 // Implementation of SignatureHandlerLibrary
  1084 address SignatureHandlerLibrary::set_handler_blob() {
  1085   BufferBlob* handler_blob = BufferBlob::create("native signature handlers", blob_size);
  1086   if (handler_blob == NULL) {
  1087     return NULL;
  1089   address handler = handler_blob->code_begin();
  1090   _handler_blob = handler_blob;
  1091   _handler = handler;
  1092   return handler;
  1095 void SignatureHandlerLibrary::initialize() {
  1096   if (_fingerprints != NULL) {
  1097     return;
  1099   if (set_handler_blob() == NULL) {
  1100     vm_exit_out_of_memory(blob_size, "native signature handlers");
  1103   BufferBlob* bb = BufferBlob::create("Signature Handler Temp Buffer",
  1104                                       SignatureHandlerLibrary::buffer_size);
  1105   _buffer = bb->code_begin();
  1107   _fingerprints = new(ResourceObj::C_HEAP)GrowableArray<uint64_t>(32, true);
  1108   _handlers     = new(ResourceObj::C_HEAP)GrowableArray<address>(32, true);
  1111 address SignatureHandlerLibrary::set_handler(CodeBuffer* buffer) {
  1112   address handler   = _handler;
  1113   int     insts_size = buffer->pure_insts_size();
  1114   if (handler + insts_size > _handler_blob->code_end()) {
  1115     // get a new handler blob
  1116     handler = set_handler_blob();
  1118   if (handler != NULL) {
  1119     memcpy(handler, buffer->insts_begin(), insts_size);
  1120     pd_set_handler(handler);
  1121     ICache::invalidate_range(handler, insts_size);
  1122     _handler = handler + insts_size;
  1124   return handler;
  1127 void SignatureHandlerLibrary::add(methodHandle method) {
  1128   if (method->signature_handler() == NULL) {
  1129     // use slow signature handler if we can't do better
  1130     int handler_index = -1;
  1131     // check if we can use customized (fast) signature handler
  1132     if (UseFastSignatureHandlers && method->size_of_parameters() <= Fingerprinter::max_size_of_parameters) {
  1133       // use customized signature handler
  1134       MutexLocker mu(SignatureHandlerLibrary_lock);
  1135       // make sure data structure is initialized
  1136       initialize();
  1137       // lookup method signature's fingerprint
  1138       uint64_t fingerprint = Fingerprinter(method).fingerprint();
  1139       handler_index = _fingerprints->find(fingerprint);
  1140       // create handler if necessary
  1141       if (handler_index < 0) {
  1142         ResourceMark rm;
  1143         ptrdiff_t align_offset = (address)
  1144           round_to((intptr_t)_buffer, CodeEntryAlignment) - (address)_buffer;
  1145         CodeBuffer buffer((address)(_buffer + align_offset),
  1146                           SignatureHandlerLibrary::buffer_size - align_offset);
  1147         InterpreterRuntime::SignatureHandlerGenerator(method, &buffer).generate(fingerprint);
  1148         // copy into code heap
  1149         address handler = set_handler(&buffer);
  1150         if (handler == NULL) {
  1151           // use slow signature handler
  1152         } else {
  1153           // debugging suppport
  1154           if (PrintSignatureHandlers) {
  1155             tty->cr();
  1156             tty->print_cr("argument handler #%d for: %s %s (fingerprint = " UINT64_FORMAT ", %d bytes generated)",
  1157                           _handlers->length(),
  1158                           (method->is_static() ? "static" : "receiver"),
  1159                           method->name_and_sig_as_C_string(),
  1160                           fingerprint,
  1161                           buffer.insts_size());
  1162             Disassembler::decode(handler, handler + buffer.insts_size());
  1163 #ifndef PRODUCT
  1164             tty->print_cr(" --- associated result handler ---");
  1165             address rh_begin = Interpreter::result_handler(method()->result_type());
  1166             address rh_end = rh_begin;
  1167             while (*(int*)rh_end != 0) {
  1168               rh_end += sizeof(int);
  1170             Disassembler::decode(rh_begin, rh_end);
  1171 #endif
  1173           // add handler to library
  1174           _fingerprints->append(fingerprint);
  1175           _handlers->append(handler);
  1176           // set handler index
  1177           assert(_fingerprints->length() == _handlers->length(), "sanity check");
  1178           handler_index = _fingerprints->length() - 1;
  1181     } else {
  1182       CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops());
  1184     if (handler_index < 0) {
  1185       // use generic signature handler
  1186       method->set_signature_handler(Interpreter::slow_signature_handler());
  1187     } else {
  1188       // set handler
  1189       method->set_signature_handler(_handlers->at(handler_index));
  1192 #ifdef ASSERT
  1193   int handler_index, fingerprint_index;
  1195     // '_handlers' and '_fingerprints' are 'GrowableArray's and are NOT synchronized
  1196     // in any way if accessed from multiple threads. To avoid races with another
  1197     // thread which may change the arrays in the above, mutex protected block, we
  1198     // have to protect this read access here with the same mutex as well!
  1199     MutexLocker mu(SignatureHandlerLibrary_lock);
  1200     handler_index = _handlers->find(method->signature_handler());
  1201     fingerprint_index = _fingerprints->find(Fingerprinter(method).fingerprint());
  1203   assert(method->signature_handler() == Interpreter::slow_signature_handler() ||
  1204          handler_index == fingerprint_index, "sanity check");
  1205 #endif
  1209 BufferBlob*              SignatureHandlerLibrary::_handler_blob = NULL;
  1210 address                  SignatureHandlerLibrary::_handler      = NULL;
  1211 GrowableArray<uint64_t>* SignatureHandlerLibrary::_fingerprints = NULL;
  1212 GrowableArray<address>*  SignatureHandlerLibrary::_handlers     = NULL;
  1213 address                  SignatureHandlerLibrary::_buffer       = NULL;
  1216 IRT_ENTRY(void, InterpreterRuntime::prepare_native_call(JavaThread* thread, methodOopDesc* method))
  1217   methodHandle m(thread, method);
  1218   assert(m->is_native(), "sanity check");
  1219   // lookup native function entry point if it doesn't exist
  1220   bool in_base_library;
  1221   if (!m->has_native_function()) {
  1222     NativeLookup::lookup(m, in_base_library, CHECK);
  1224   // make sure signature handler is installed
  1225   SignatureHandlerLibrary::add(m);
  1226   // The interpreter entry point checks the signature handler first,
  1227   // before trying to fetch the native entry point and klass mirror.
  1228   // We must set the signature handler last, so that multiple processors
  1229   // preparing the same method will be sure to see non-null entry & mirror.
  1230 IRT_END
  1232 #if defined(IA32) || defined(AMD64)
  1233 IRT_LEAF(void, InterpreterRuntime::popframe_move_outgoing_args(JavaThread* thread, void* src_address, void* dest_address))
  1234   if (src_address == dest_address) {
  1235     return;
  1237   ResetNoHandleMark rnm; // In a LEAF entry.
  1238   HandleMark hm;
  1239   ResourceMark rm;
  1240   frame fr = thread->last_frame();
  1241   assert(fr.is_interpreted_frame(), "");
  1242   jint bci = fr.interpreter_frame_bci();
  1243   methodHandle mh(thread, fr.interpreter_frame_method());
  1244   Bytecode_invoke invoke(mh, bci);
  1245   ArgumentSizeComputer asc(invoke.signature());
  1246   int size_of_arguments = (asc.size() + (invoke.has_receiver() ? 1 : 0)); // receiver
  1247   Copy::conjoint_jbytes(src_address, dest_address,
  1248                        size_of_arguments * Interpreter::stackElementSize);
  1249 IRT_END
  1250 #endif

mercurial