src/share/vm/interpreter/interpreterRuntime.cpp

changeset 0
f90c822e73f8
child 1
2d8a650513c2
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/interpreter/interpreterRuntime.cpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,1289 @@
     1.4 +/*
     1.5 + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#include "precompiled.hpp"
    1.29 +#include "classfile/systemDictionary.hpp"
    1.30 +#include "classfile/vmSymbols.hpp"
    1.31 +#include "compiler/compileBroker.hpp"
    1.32 +#include "compiler/disassembler.hpp"
    1.33 +#include "gc_interface/collectedHeap.hpp"
    1.34 +#include "interpreter/interpreter.hpp"
    1.35 +#include "interpreter/interpreterRuntime.hpp"
    1.36 +#include "interpreter/linkResolver.hpp"
    1.37 +#include "interpreter/templateTable.hpp"
    1.38 +#include "memory/oopFactory.hpp"
    1.39 +#include "memory/universe.inline.hpp"
    1.40 +#include "oops/constantPool.hpp"
    1.41 +#include "oops/instanceKlass.hpp"
    1.42 +#include "oops/methodData.hpp"
    1.43 +#include "oops/objArrayKlass.hpp"
    1.44 +#include "oops/oop.inline.hpp"
    1.45 +#include "oops/symbol.hpp"
    1.46 +#include "prims/jvmtiExport.hpp"
    1.47 +#include "prims/nativeLookup.hpp"
    1.48 +#include "runtime/biasedLocking.hpp"
    1.49 +#include "runtime/compilationPolicy.hpp"
    1.50 +#include "runtime/deoptimization.hpp"
    1.51 +#include "runtime/fieldDescriptor.hpp"
    1.52 +#include "runtime/handles.inline.hpp"
    1.53 +#include "runtime/interfaceSupport.hpp"
    1.54 +#include "runtime/java.hpp"
    1.55 +#include "runtime/jfieldIDWorkaround.hpp"
    1.56 +#include "runtime/osThread.hpp"
    1.57 +#include "runtime/sharedRuntime.hpp"
    1.58 +#include "runtime/stubRoutines.hpp"
    1.59 +#include "runtime/synchronizer.hpp"
    1.60 +#include "runtime/threadCritical.hpp"
    1.61 +#include "utilities/events.hpp"
    1.62 +#ifdef TARGET_ARCH_x86
    1.63 +# include "vm_version_x86.hpp"
    1.64 +#endif
    1.65 +#ifdef TARGET_ARCH_sparc
    1.66 +# include "vm_version_sparc.hpp"
    1.67 +#endif
    1.68 +#ifdef TARGET_ARCH_zero
    1.69 +# include "vm_version_zero.hpp"
    1.70 +#endif
    1.71 +#ifdef TARGET_ARCH_arm
    1.72 +# include "vm_version_arm.hpp"
    1.73 +#endif
    1.74 +#ifdef TARGET_ARCH_ppc
    1.75 +# include "vm_version_ppc.hpp"
    1.76 +#endif
    1.77 +#ifdef COMPILER2
    1.78 +#include "opto/runtime.hpp"
    1.79 +#endif
    1.80 +
    1.81 +PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
    1.82 +
    1.83 +class UnlockFlagSaver {
    1.84 +  private:
    1.85 +    JavaThread* _thread;
    1.86 +    bool _do_not_unlock;
    1.87 +  public:
    1.88 +    UnlockFlagSaver(JavaThread* t) {
    1.89 +      _thread = t;
    1.90 +      _do_not_unlock = t->do_not_unlock_if_synchronized();
    1.91 +      t->set_do_not_unlock_if_synchronized(false);
    1.92 +    }
    1.93 +    ~UnlockFlagSaver() {
    1.94 +      _thread->set_do_not_unlock_if_synchronized(_do_not_unlock);
    1.95 +    }
    1.96 +};
    1.97 +
    1.98 +//------------------------------------------------------------------------------------------------------------------------
    1.99 +// State accessors
   1.100 +
   1.101 +void InterpreterRuntime::set_bcp_and_mdp(address bcp, JavaThread *thread) {
   1.102 +  last_frame(thread).interpreter_frame_set_bcp(bcp);
   1.103 +  if (ProfileInterpreter) {
   1.104 +    // ProfileTraps uses MDOs independently of ProfileInterpreter.
   1.105 +    // That is why we must check both ProfileInterpreter and mdo != NULL.
   1.106 +    MethodData* mdo = last_frame(thread).interpreter_frame_method()->method_data();
   1.107 +    if (mdo != NULL) {
   1.108 +      NEEDS_CLEANUP;
   1.109 +      last_frame(thread).interpreter_frame_set_mdp(mdo->bci_to_dp(last_frame(thread).interpreter_frame_bci()));
   1.110 +    }
   1.111 +  }
   1.112 +}
   1.113 +
   1.114 +//------------------------------------------------------------------------------------------------------------------------
   1.115 +// Constants
   1.116 +
   1.117 +
   1.118 +IRT_ENTRY(void, InterpreterRuntime::ldc(JavaThread* thread, bool wide))
   1.119 +  // access constant pool
   1.120 +  ConstantPool* pool = method(thread)->constants();
   1.121 +  int index = wide ? get_index_u2(thread, Bytecodes::_ldc_w) : get_index_u1(thread, Bytecodes::_ldc);
   1.122 +  constantTag tag = pool->tag_at(index);
   1.123 +
   1.124 +  assert (tag.is_unresolved_klass() || tag.is_klass(), "wrong ldc call");
   1.125 +  Klass* klass = pool->klass_at(index, CHECK);
   1.126 +    oop java_class = klass->java_mirror();
   1.127 +    thread->set_vm_result(java_class);
   1.128 +IRT_END
   1.129 +
   1.130 +IRT_ENTRY(void, InterpreterRuntime::resolve_ldc(JavaThread* thread, Bytecodes::Code bytecode)) {
   1.131 +  assert(bytecode == Bytecodes::_fast_aldc ||
   1.132 +         bytecode == Bytecodes::_fast_aldc_w, "wrong bc");
   1.133 +  ResourceMark rm(thread);
   1.134 +  methodHandle m (thread, method(thread));
   1.135 +  Bytecode_loadconstant ldc(m, bci(thread));
   1.136 +  oop result = ldc.resolve_constant(CHECK);
   1.137 +#ifdef ASSERT
   1.138 +  {
   1.139 +    // The bytecode wrappers aren't GC-safe so construct a new one
   1.140 +    Bytecode_loadconstant ldc2(m, bci(thread));
   1.141 +    oop coop = m->constants()->resolved_references()->obj_at(ldc2.cache_index());
   1.142 +    assert(result == coop, "expected result for assembly code");
   1.143 +  }
   1.144 +#endif
   1.145 +  thread->set_vm_result(result);
   1.146 +}
   1.147 +IRT_END
   1.148 +
   1.149 +
   1.150 +//------------------------------------------------------------------------------------------------------------------------
   1.151 +// Allocation
   1.152 +
   1.153 +IRT_ENTRY(void, InterpreterRuntime::_new(JavaThread* thread, ConstantPool* pool, int index))
   1.154 +  Klass* k_oop = pool->klass_at(index, CHECK);
   1.155 +  instanceKlassHandle klass (THREAD, k_oop);
   1.156 +
   1.157 +  // Make sure we are not instantiating an abstract klass
   1.158 +  klass->check_valid_for_instantiation(true, CHECK);
   1.159 +
   1.160 +  // Make sure klass is initialized
   1.161 +  klass->initialize(CHECK);
   1.162 +
   1.163 +  // At this point the class may not be fully initialized
   1.164 +  // because of recursive initialization. If it is fully
   1.165 +  // initialized & has_finalized is not set, we rewrite
   1.166 +  // it into its fast version (Note: no locking is needed
   1.167 +  // here since this is an atomic byte write and can be
   1.168 +  // done more than once).
   1.169 +  //
   1.170 +  // Note: In case of classes with has_finalized we don't
   1.171 +  //       rewrite since that saves us an extra check in
   1.172 +  //       the fast version which then would call the
   1.173 +  //       slow version anyway (and do a call back into
   1.174 +  //       Java).
   1.175 +  //       If we have a breakpoint, then we don't rewrite
   1.176 +  //       because the _breakpoint bytecode would be lost.
   1.177 +  oop obj = klass->allocate_instance(CHECK);
   1.178 +  thread->set_vm_result(obj);
   1.179 +IRT_END
   1.180 +
   1.181 +
   1.182 +IRT_ENTRY(void, InterpreterRuntime::newarray(JavaThread* thread, BasicType type, jint size))
   1.183 +  oop obj = oopFactory::new_typeArray(type, size, CHECK);
   1.184 +  thread->set_vm_result(obj);
   1.185 +IRT_END
   1.186 +
   1.187 +
   1.188 +IRT_ENTRY(void, InterpreterRuntime::anewarray(JavaThread* thread, ConstantPool* pool, int index, jint size))
   1.189 +  // Note: no oopHandle for pool & klass needed since they are not used
   1.190 +  //       anymore after new_objArray() and no GC can happen before.
   1.191 +  //       (This may have to change if this code changes!)
   1.192 +  Klass*    klass = pool->klass_at(index, CHECK);
   1.193 +  objArrayOop obj = oopFactory::new_objArray(klass, size, CHECK);
   1.194 +  thread->set_vm_result(obj);
   1.195 +IRT_END
   1.196 +
   1.197 +
   1.198 +IRT_ENTRY(void, InterpreterRuntime::multianewarray(JavaThread* thread, jint* first_size_address))
   1.199 +  // We may want to pass in more arguments - could make this slightly faster
   1.200 +  ConstantPool* constants = method(thread)->constants();
   1.201 +  int          i = get_index_u2(thread, Bytecodes::_multianewarray);
   1.202 +  Klass* klass = constants->klass_at(i, CHECK);
   1.203 +  int   nof_dims = number_of_dimensions(thread);
   1.204 +  assert(klass->is_klass(), "not a class");
   1.205 +  assert(nof_dims >= 1, "multianewarray rank must be nonzero");
   1.206 +
   1.207 +  // We must create an array of jints to pass to multi_allocate.
   1.208 +  ResourceMark rm(thread);
   1.209 +  const int small_dims = 10;
   1.210 +  jint dim_array[small_dims];
   1.211 +  jint *dims = &dim_array[0];
   1.212 +  if (nof_dims > small_dims) {
   1.213 +    dims = (jint*) NEW_RESOURCE_ARRAY(jint, nof_dims);
   1.214 +  }
   1.215 +  for (int index = 0; index < nof_dims; index++) {
   1.216 +    // offset from first_size_address is addressed as local[index]
   1.217 +    int n = Interpreter::local_offset_in_bytes(index)/jintSize;
   1.218 +    dims[index] = first_size_address[n];
   1.219 +  }
   1.220 +  oop obj = ArrayKlass::cast(klass)->multi_allocate(nof_dims, dims, CHECK);
   1.221 +  thread->set_vm_result(obj);
   1.222 +IRT_END
   1.223 +
   1.224 +
   1.225 +IRT_ENTRY(void, InterpreterRuntime::register_finalizer(JavaThread* thread, oopDesc* obj))
   1.226 +  assert(obj->is_oop(), "must be a valid oop");
   1.227 +  assert(obj->klass()->has_finalizer(), "shouldn't be here otherwise");
   1.228 +  InstanceKlass::register_finalizer(instanceOop(obj), CHECK);
   1.229 +IRT_END
   1.230 +
   1.231 +
   1.232 +// Quicken instance-of and check-cast bytecodes
   1.233 +IRT_ENTRY(void, InterpreterRuntime::quicken_io_cc(JavaThread* thread))
   1.234 +  // Force resolving; quicken the bytecode
   1.235 +  int which = get_index_u2(thread, Bytecodes::_checkcast);
   1.236 +  ConstantPool* cpool = method(thread)->constants();
   1.237 +  // We'd expect to assert that we're only here to quicken bytecodes, but in a multithreaded
   1.238 +  // program we might have seen an unquick'd bytecode in the interpreter but have another
   1.239 +  // thread quicken the bytecode before we get here.
   1.240 +  // assert( cpool->tag_at(which).is_unresolved_klass(), "should only come here to quicken bytecodes" );
   1.241 +  Klass* klass = cpool->klass_at(which, CHECK);
   1.242 +  thread->set_vm_result_2(klass);
   1.243 +IRT_END
   1.244 +
   1.245 +
   1.246 +//------------------------------------------------------------------------------------------------------------------------
   1.247 +// Exceptions
   1.248 +
   1.249 +void InterpreterRuntime::note_trap_inner(JavaThread* thread, int reason,
   1.250 +                                         methodHandle trap_method, int trap_bci, TRAPS) {
   1.251 +  if (trap_method.not_null()) {
   1.252 +    MethodData* trap_mdo = trap_method->method_data();
   1.253 +    if (trap_mdo == NULL) {
   1.254 +      Method::build_interpreter_method_data(trap_method, THREAD);
   1.255 +      if (HAS_PENDING_EXCEPTION) {
   1.256 +        assert((PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())),
   1.257 +               "we expect only an OOM error here");
   1.258 +        CLEAR_PENDING_EXCEPTION;
   1.259 +      }
   1.260 +      trap_mdo = trap_method->method_data();
   1.261 +      // and fall through...
   1.262 +    }
   1.263 +    if (trap_mdo != NULL) {
   1.264 +      // Update per-method count of trap events.  The interpreter
   1.265 +      // is updating the MDO to simulate the effect of compiler traps.
   1.266 +      Deoptimization::update_method_data_from_interpreter(trap_mdo, trap_bci, reason);
   1.267 +    }
   1.268 +  }
   1.269 +}
   1.270 +
   1.271 +// Assume the compiler is (or will be) interested in this event.
   1.272 +// If necessary, create an MDO to hold the information, and record it.
   1.273 +void InterpreterRuntime::note_trap(JavaThread* thread, int reason, TRAPS) {
   1.274 +  assert(ProfileTraps, "call me only if profiling");
   1.275 +  methodHandle trap_method(thread, method(thread));
   1.276 +  int trap_bci = trap_method->bci_from(bcp(thread));
   1.277 +  note_trap_inner(thread, reason, trap_method, trap_bci, THREAD);
   1.278 +}
   1.279 +
   1.280 +#ifdef CC_INTERP
   1.281 +// As legacy note_trap, but we have more arguments.
   1.282 +IRT_ENTRY(void, InterpreterRuntime::note_trap(JavaThread* thread, int reason, Method *method, int trap_bci))
   1.283 +  methodHandle trap_method(method);
   1.284 +  note_trap_inner(thread, reason, trap_method, trap_bci, THREAD);
   1.285 +IRT_END
   1.286 +
   1.287 +// Class Deoptimization is not visible in BytecodeInterpreter, so we need a wrapper
   1.288 +// for each exception.
   1.289 +void InterpreterRuntime::note_nullCheck_trap(JavaThread* thread, Method *method, int trap_bci)
   1.290 +  { if (ProfileTraps) note_trap(thread, Deoptimization::Reason_null_check, method, trap_bci); }
   1.291 +void InterpreterRuntime::note_div0Check_trap(JavaThread* thread, Method *method, int trap_bci)
   1.292 +  { if (ProfileTraps) note_trap(thread, Deoptimization::Reason_div0_check, method, trap_bci); }
   1.293 +void InterpreterRuntime::note_rangeCheck_trap(JavaThread* thread, Method *method, int trap_bci)
   1.294 +  { if (ProfileTraps) note_trap(thread, Deoptimization::Reason_range_check, method, trap_bci); }
   1.295 +void InterpreterRuntime::note_classCheck_trap(JavaThread* thread, Method *method, int trap_bci)
   1.296 +  { if (ProfileTraps) note_trap(thread, Deoptimization::Reason_class_check, method, trap_bci); }
   1.297 +void InterpreterRuntime::note_arrayCheck_trap(JavaThread* thread, Method *method, int trap_bci)
   1.298 +  { if (ProfileTraps) note_trap(thread, Deoptimization::Reason_array_check, method, trap_bci); }
   1.299 +#endif // CC_INTERP
   1.300 +
   1.301 +
   1.302 +static Handle get_preinitialized_exception(Klass* k, TRAPS) {
   1.303 +  // get klass
   1.304 +  InstanceKlass* klass = InstanceKlass::cast(k);
   1.305 +  assert(klass->is_initialized(),
   1.306 +         "this klass should have been initialized during VM initialization");
   1.307 +  // create instance - do not call constructor since we may have no
   1.308 +  // (java) stack space left (should assert constructor is empty)
   1.309 +  Handle exception;
   1.310 +  oop exception_oop = klass->allocate_instance(CHECK_(exception));
   1.311 +  exception = Handle(THREAD, exception_oop);
   1.312 +  if (StackTraceInThrowable) {
   1.313 +    java_lang_Throwable::fill_in_stack_trace(exception);
   1.314 +  }
   1.315 +  return exception;
   1.316 +}
   1.317 +
   1.318 +// Special handling for stack overflow: since we don't have any (java) stack
   1.319 +// space left we use the pre-allocated & pre-initialized StackOverflowError
   1.320 +// klass to create an stack overflow error instance.  We do not call its
   1.321 +// constructor for the same reason (it is empty, anyway).
   1.322 +IRT_ENTRY(void, InterpreterRuntime::throw_StackOverflowError(JavaThread* thread))
   1.323 +  Handle exception = get_preinitialized_exception(
   1.324 +                                 SystemDictionary::StackOverflowError_klass(),
   1.325 +                                 CHECK);
   1.326 +  THROW_HANDLE(exception);
   1.327 +IRT_END
   1.328 +
   1.329 +
   1.330 +IRT_ENTRY(void, InterpreterRuntime::create_exception(JavaThread* thread, char* name, char* message))
   1.331 +  // lookup exception klass
   1.332 +  TempNewSymbol s = SymbolTable::new_symbol(name, CHECK);
   1.333 +  if (ProfileTraps) {
   1.334 +    if (s == vmSymbols::java_lang_ArithmeticException()) {
   1.335 +      note_trap(thread, Deoptimization::Reason_div0_check, CHECK);
   1.336 +    } else if (s == vmSymbols::java_lang_NullPointerException()) {
   1.337 +      note_trap(thread, Deoptimization::Reason_null_check, CHECK);
   1.338 +    }
   1.339 +  }
   1.340 +  // create exception
   1.341 +  Handle exception = Exceptions::new_exception(thread, s, message);
   1.342 +  thread->set_vm_result(exception());
   1.343 +IRT_END
   1.344 +
   1.345 +
   1.346 +IRT_ENTRY(void, InterpreterRuntime::create_klass_exception(JavaThread* thread, char* name, oopDesc* obj))
   1.347 +  ResourceMark rm(thread);
   1.348 +  const char* klass_name = obj->klass()->external_name();
   1.349 +  // lookup exception klass
   1.350 +  TempNewSymbol s = SymbolTable::new_symbol(name, CHECK);
   1.351 +  if (ProfileTraps) {
   1.352 +    note_trap(thread, Deoptimization::Reason_class_check, CHECK);
   1.353 +  }
   1.354 +  // create exception, with klass name as detail message
   1.355 +  Handle exception = Exceptions::new_exception(thread, s, klass_name);
   1.356 +  thread->set_vm_result(exception());
   1.357 +IRT_END
   1.358 +
   1.359 +
   1.360 +IRT_ENTRY(void, InterpreterRuntime::throw_ArrayIndexOutOfBoundsException(JavaThread* thread, char* name, jint index))
   1.361 +  char message[jintAsStringSize];
   1.362 +  // lookup exception klass
   1.363 +  TempNewSymbol s = SymbolTable::new_symbol(name, CHECK);
   1.364 +  if (ProfileTraps) {
   1.365 +    note_trap(thread, Deoptimization::Reason_range_check, CHECK);
   1.366 +  }
   1.367 +  // create exception
   1.368 +  sprintf(message, "%d", index);
   1.369 +  THROW_MSG(s, message);
   1.370 +IRT_END
   1.371 +
   1.372 +IRT_ENTRY(void, InterpreterRuntime::throw_ClassCastException(
   1.373 +  JavaThread* thread, oopDesc* obj))
   1.374 +
   1.375 +  ResourceMark rm(thread);
   1.376 +  char* message = SharedRuntime::generate_class_cast_message(
   1.377 +    thread, obj->klass()->external_name());
   1.378 +
   1.379 +  if (ProfileTraps) {
   1.380 +    note_trap(thread, Deoptimization::Reason_class_check, CHECK);
   1.381 +  }
   1.382 +
   1.383 +  // create exception
   1.384 +  THROW_MSG(vmSymbols::java_lang_ClassCastException(), message);
   1.385 +IRT_END
   1.386 +
   1.387 +// exception_handler_for_exception(...) returns the continuation address,
   1.388 +// the exception oop (via TLS) and sets the bci/bcp for the continuation.
   1.389 +// The exception oop is returned to make sure it is preserved over GC (it
   1.390 +// is only on the stack if the exception was thrown explicitly via athrow).
   1.391 +// During this operation, the expression stack contains the values for the
   1.392 +// bci where the exception happened. If the exception was propagated back
   1.393 +// from a call, the expression stack contains the values for the bci at the
   1.394 +// invoke w/o arguments (i.e., as if one were inside the call).
   1.395 +IRT_ENTRY(address, InterpreterRuntime::exception_handler_for_exception(JavaThread* thread, oopDesc* exception))
   1.396 +
   1.397 +  Handle             h_exception(thread, exception);
   1.398 +  methodHandle       h_method   (thread, method(thread));
   1.399 +  constantPoolHandle h_constants(thread, h_method->constants());
   1.400 +  bool               should_repeat;
   1.401 +  int                handler_bci;
   1.402 +  int                current_bci = bci(thread);
   1.403 +
   1.404 +  // Need to do this check first since when _do_not_unlock_if_synchronized
   1.405 +  // is set, we don't want to trigger any classloading which may make calls
   1.406 +  // into java, or surprisingly find a matching exception handler for bci 0
   1.407 +  // since at this moment the method hasn't been "officially" entered yet.
   1.408 +  if (thread->do_not_unlock_if_synchronized()) {
   1.409 +    ResourceMark rm;
   1.410 +    assert(current_bci == 0,  "bci isn't zero for do_not_unlock_if_synchronized");
   1.411 +    thread->set_vm_result(exception);
   1.412 +#ifdef CC_INTERP
   1.413 +    return (address) -1;
   1.414 +#else
   1.415 +    return Interpreter::remove_activation_entry();
   1.416 +#endif
   1.417 +  }
   1.418 +
   1.419 +  do {
   1.420 +    should_repeat = false;
   1.421 +
   1.422 +    // assertions
   1.423 +#ifdef ASSERT
   1.424 +    assert(h_exception.not_null(), "NULL exceptions should be handled by athrow");
   1.425 +    assert(h_exception->is_oop(), "just checking");
   1.426 +    // Check that exception is a subclass of Throwable, otherwise we have a VerifyError
   1.427 +    if (!(h_exception->is_a(SystemDictionary::Throwable_klass()))) {
   1.428 +      if (ExitVMOnVerifyError) vm_exit(-1);
   1.429 +      ShouldNotReachHere();
   1.430 +    }
   1.431 +#endif
   1.432 +
   1.433 +    // tracing
   1.434 +    if (TraceExceptions) {
   1.435 +      ttyLocker ttyl;
   1.436 +      ResourceMark rm(thread);
   1.437 +      tty->print_cr("Exception <%s> (" INTPTR_FORMAT ")", h_exception->print_value_string(), (address)h_exception());
   1.438 +      tty->print_cr(" thrown in interpreter method <%s>", h_method->print_value_string());
   1.439 +      tty->print_cr(" at bci %d for thread " INTPTR_FORMAT, current_bci, thread);
   1.440 +    }
   1.441 +// Don't go paging in something which won't be used.
   1.442 +//     else if (extable->length() == 0) {
   1.443 +//       // disabled for now - interpreter is not using shortcut yet
   1.444 +//       // (shortcut is not to call runtime if we have no exception handlers)
   1.445 +//       // warning("performance bug: should not call runtime if method has no exception handlers");
   1.446 +//     }
   1.447 +    // for AbortVMOnException flag
   1.448 +    NOT_PRODUCT(Exceptions::debug_check_abort(h_exception));
   1.449 +
   1.450 +    // exception handler lookup
   1.451 +    KlassHandle h_klass(THREAD, h_exception->klass());
   1.452 +    handler_bci = Method::fast_exception_handler_bci_for(h_method, h_klass, current_bci, THREAD);
   1.453 +    if (HAS_PENDING_EXCEPTION) {
   1.454 +      // We threw an exception while trying to find the exception handler.
   1.455 +      // Transfer the new exception to the exception handle which will
   1.456 +      // be set into thread local storage, and do another lookup for an
   1.457 +      // exception handler for this exception, this time starting at the
   1.458 +      // BCI of the exception handler which caused the exception to be
   1.459 +      // thrown (bug 4307310).
   1.460 +      h_exception = Handle(THREAD, PENDING_EXCEPTION);
   1.461 +      CLEAR_PENDING_EXCEPTION;
   1.462 +      if (handler_bci >= 0) {
   1.463 +        current_bci = handler_bci;
   1.464 +        should_repeat = true;
   1.465 +      }
   1.466 +    }
   1.467 +  } while (should_repeat == true);
   1.468 +
   1.469 +  // notify JVMTI of an exception throw; JVMTI will detect if this is a first
   1.470 +  // time throw or a stack unwinding throw and accordingly notify the debugger
   1.471 +  if (JvmtiExport::can_post_on_exceptions()) {
   1.472 +    JvmtiExport::post_exception_throw(thread, h_method(), bcp(thread), h_exception());
   1.473 +  }
   1.474 +
   1.475 +#ifdef CC_INTERP
   1.476 +  address continuation = (address)(intptr_t) handler_bci;
   1.477 +#else
   1.478 +  address continuation = NULL;
   1.479 +#endif
   1.480 +  address handler_pc = NULL;
   1.481 +  if (handler_bci < 0 || !thread->reguard_stack((address) &continuation)) {
   1.482 +    // Forward exception to callee (leaving bci/bcp untouched) because (a) no
   1.483 +    // handler in this method, or (b) after a stack overflow there is not yet
   1.484 +    // enough stack space available to reprotect the stack.
   1.485 +#ifndef CC_INTERP
   1.486 +    continuation = Interpreter::remove_activation_entry();
   1.487 +#endif
   1.488 +    // Count this for compilation purposes
   1.489 +    h_method->interpreter_throwout_increment(THREAD);
   1.490 +  } else {
   1.491 +    // handler in this method => change bci/bcp to handler bci/bcp and continue there
   1.492 +    handler_pc = h_method->code_base() + handler_bci;
   1.493 +#ifndef CC_INTERP
   1.494 +    set_bcp_and_mdp(handler_pc, thread);
   1.495 +    continuation = Interpreter::dispatch_table(vtos)[*handler_pc];
   1.496 +#endif
   1.497 +  }
   1.498 +  // notify debugger of an exception catch
   1.499 +  // (this is good for exceptions caught in native methods as well)
   1.500 +  if (JvmtiExport::can_post_on_exceptions()) {
   1.501 +    JvmtiExport::notice_unwind_due_to_exception(thread, h_method(), handler_pc, h_exception(), (handler_pc != NULL));
   1.502 +  }
   1.503 +
   1.504 +  thread->set_vm_result(h_exception());
   1.505 +  return continuation;
   1.506 +IRT_END
   1.507 +
   1.508 +
   1.509 +IRT_ENTRY(void, InterpreterRuntime::throw_pending_exception(JavaThread* thread))
   1.510 +  assert(thread->has_pending_exception(), "must only ne called if there's an exception pending");
   1.511 +  // nothing to do - eventually we should remove this code entirely (see comments @ call sites)
   1.512 +IRT_END
   1.513 +
   1.514 +
   1.515 +IRT_ENTRY(void, InterpreterRuntime::throw_AbstractMethodError(JavaThread* thread))
   1.516 +  THROW(vmSymbols::java_lang_AbstractMethodError());
   1.517 +IRT_END
   1.518 +
   1.519 +
   1.520 +IRT_ENTRY(void, InterpreterRuntime::throw_IncompatibleClassChangeError(JavaThread* thread))
   1.521 +  THROW(vmSymbols::java_lang_IncompatibleClassChangeError());
   1.522 +IRT_END
   1.523 +
   1.524 +
   1.525 +//------------------------------------------------------------------------------------------------------------------------
   1.526 +// Fields
   1.527 +//
   1.528 +
   1.529 +IRT_ENTRY(void, InterpreterRuntime::resolve_get_put(JavaThread* thread, Bytecodes::Code bytecode))
   1.530 +  // resolve field
   1.531 +  fieldDescriptor info;
   1.532 +  constantPoolHandle pool(thread, method(thread)->constants());
   1.533 +  bool is_put    = (bytecode == Bytecodes::_putfield  || bytecode == Bytecodes::_putstatic);
   1.534 +  bool is_static = (bytecode == Bytecodes::_getstatic || bytecode == Bytecodes::_putstatic);
   1.535 +
   1.536 +  {
   1.537 +    JvmtiHideSingleStepping jhss(thread);
   1.538 +    LinkResolver::resolve_field_access(info, pool, get_index_u2_cpcache(thread, bytecode),
   1.539 +                                       bytecode, CHECK);
   1.540 +  } // end JvmtiHideSingleStepping
   1.541 +
   1.542 +  // check if link resolution caused cpCache to be updated
   1.543 +  if (already_resolved(thread)) return;
   1.544 +
   1.545 +  // compute auxiliary field attributes
   1.546 +  TosState state  = as_TosState(info.field_type());
   1.547 +
   1.548 +  // We need to delay resolving put instructions on final fields
   1.549 +  // until we actually invoke one. This is required so we throw
   1.550 +  // exceptions at the correct place. If we do not resolve completely
   1.551 +  // in the current pass, leaving the put_code set to zero will
   1.552 +  // cause the next put instruction to reresolve.
   1.553 +  Bytecodes::Code put_code = (Bytecodes::Code)0;
   1.554 +
   1.555 +  // We also need to delay resolving getstatic instructions until the
   1.556 +  // class is intitialized.  This is required so that access to the static
   1.557 +  // field will call the initialization function every time until the class
   1.558 +  // is completely initialized ala. in 2.17.5 in JVM Specification.
   1.559 +  InstanceKlass* klass = InstanceKlass::cast(info.field_holder());
   1.560 +  bool uninitialized_static = ((bytecode == Bytecodes::_getstatic || bytecode == Bytecodes::_putstatic) &&
   1.561 +                               !klass->is_initialized());
   1.562 +  Bytecodes::Code get_code = (Bytecodes::Code)0;
   1.563 +
   1.564 +  if (!uninitialized_static) {
   1.565 +    get_code = ((is_static) ? Bytecodes::_getstatic : Bytecodes::_getfield);
   1.566 +    if (is_put || !info.access_flags().is_final()) {
   1.567 +      put_code = ((is_static) ? Bytecodes::_putstatic : Bytecodes::_putfield);
   1.568 +    }
   1.569 +  }
   1.570 +
   1.571 +  cache_entry(thread)->set_field(
   1.572 +    get_code,
   1.573 +    put_code,
   1.574 +    info.field_holder(),
   1.575 +    info.index(),
   1.576 +    info.offset(),
   1.577 +    state,
   1.578 +    info.access_flags().is_final(),
   1.579 +    info.access_flags().is_volatile(),
   1.580 +    pool->pool_holder()
   1.581 +  );
   1.582 +IRT_END
   1.583 +
   1.584 +
   1.585 +//------------------------------------------------------------------------------------------------------------------------
   1.586 +// Synchronization
   1.587 +//
   1.588 +// The interpreter's synchronization code is factored out so that it can
   1.589 +// be shared by method invocation and synchronized blocks.
   1.590 +//%note synchronization_3
   1.591 +
   1.592 +//%note monitor_1
   1.593 +IRT_ENTRY_NO_ASYNC(void, InterpreterRuntime::monitorenter(JavaThread* thread, BasicObjectLock* elem))
   1.594 +#ifdef ASSERT
   1.595 +  thread->last_frame().interpreter_frame_verify_monitor(elem);
   1.596 +#endif
   1.597 +  if (PrintBiasedLockingStatistics) {
   1.598 +    Atomic::inc(BiasedLocking::slow_path_entry_count_addr());
   1.599 +  }
   1.600 +  Handle h_obj(thread, elem->obj());
   1.601 +  assert(Universe::heap()->is_in_reserved_or_null(h_obj()),
   1.602 +         "must be NULL or an object");
   1.603 +  if (UseBiasedLocking) {
   1.604 +    // Retry fast entry if bias is revoked to avoid unnecessary inflation
   1.605 +    ObjectSynchronizer::fast_enter(h_obj, elem->lock(), true, CHECK);
   1.606 +  } else {
   1.607 +    ObjectSynchronizer::slow_enter(h_obj, elem->lock(), CHECK);
   1.608 +  }
   1.609 +  assert(Universe::heap()->is_in_reserved_or_null(elem->obj()),
   1.610 +         "must be NULL or an object");
   1.611 +#ifdef ASSERT
   1.612 +  thread->last_frame().interpreter_frame_verify_monitor(elem);
   1.613 +#endif
   1.614 +IRT_END
   1.615 +
   1.616 +
   1.617 +//%note monitor_1
   1.618 +IRT_ENTRY_NO_ASYNC(void, InterpreterRuntime::monitorexit(JavaThread* thread, BasicObjectLock* elem))
   1.619 +#ifdef ASSERT
   1.620 +  thread->last_frame().interpreter_frame_verify_monitor(elem);
   1.621 +#endif
   1.622 +  Handle h_obj(thread, elem->obj());
   1.623 +  assert(Universe::heap()->is_in_reserved_or_null(h_obj()),
   1.624 +         "must be NULL or an object");
   1.625 +  if (elem == NULL || h_obj()->is_unlocked()) {
   1.626 +    THROW(vmSymbols::java_lang_IllegalMonitorStateException());
   1.627 +  }
   1.628 +  ObjectSynchronizer::slow_exit(h_obj(), elem->lock(), thread);
   1.629 +  // Free entry. This must be done here, since a pending exception might be installed on
   1.630 +  // exit. If it is not cleared, the exception handling code will try to unlock the monitor again.
   1.631 +  elem->set_obj(NULL);
   1.632 +#ifdef ASSERT
   1.633 +  thread->last_frame().interpreter_frame_verify_monitor(elem);
   1.634 +#endif
   1.635 +IRT_END
   1.636 +
   1.637 +
   1.638 +IRT_ENTRY(void, InterpreterRuntime::throw_illegal_monitor_state_exception(JavaThread* thread))
   1.639 +  THROW(vmSymbols::java_lang_IllegalMonitorStateException());
   1.640 +IRT_END
   1.641 +
   1.642 +
   1.643 +IRT_ENTRY(void, InterpreterRuntime::new_illegal_monitor_state_exception(JavaThread* thread))
   1.644 +  // Returns an illegal exception to install into the current thread. The
   1.645 +  // pending_exception flag is cleared so normal exception handling does not
   1.646 +  // trigger. Any current installed exception will be overwritten. This
   1.647 +  // method will be called during an exception unwind.
   1.648 +
   1.649 +  assert(!HAS_PENDING_EXCEPTION, "no pending exception");
   1.650 +  Handle exception(thread, thread->vm_result());
   1.651 +  assert(exception() != NULL, "vm result should be set");
   1.652 +  thread->set_vm_result(NULL); // clear vm result before continuing (may cause memory leaks and assert failures)
   1.653 +  if (!exception->is_a(SystemDictionary::ThreadDeath_klass())) {
   1.654 +    exception = get_preinitialized_exception(
   1.655 +                       SystemDictionary::IllegalMonitorStateException_klass(),
   1.656 +                       CATCH);
   1.657 +  }
   1.658 +  thread->set_vm_result(exception());
   1.659 +IRT_END
   1.660 +
   1.661 +
   1.662 +//------------------------------------------------------------------------------------------------------------------------
   1.663 +// Invokes
   1.664 +
   1.665 +IRT_ENTRY(Bytecodes::Code, InterpreterRuntime::get_original_bytecode_at(JavaThread* thread, Method* method, address bcp))
   1.666 +  return method->orig_bytecode_at(method->bci_from(bcp));
   1.667 +IRT_END
   1.668 +
   1.669 +IRT_ENTRY(void, InterpreterRuntime::set_original_bytecode_at(JavaThread* thread, Method* method, address bcp, Bytecodes::Code new_code))
   1.670 +  method->set_orig_bytecode_at(method->bci_from(bcp), new_code);
   1.671 +IRT_END
   1.672 +
   1.673 +IRT_ENTRY(void, InterpreterRuntime::_breakpoint(JavaThread* thread, Method* method, address bcp))
   1.674 +  JvmtiExport::post_raw_breakpoint(thread, method, bcp);
   1.675 +IRT_END
   1.676 +
   1.677 +IRT_ENTRY(void, InterpreterRuntime::resolve_invoke(JavaThread* thread, Bytecodes::Code bytecode)) {
   1.678 +  // extract receiver from the outgoing argument list if necessary
   1.679 +  Handle receiver(thread, NULL);
   1.680 +  if (bytecode == Bytecodes::_invokevirtual || bytecode == Bytecodes::_invokeinterface) {
   1.681 +    ResourceMark rm(thread);
   1.682 +    methodHandle m (thread, method(thread));
   1.683 +    Bytecode_invoke call(m, bci(thread));
   1.684 +    Symbol* signature = call.signature();
   1.685 +    receiver = Handle(thread,
   1.686 +                  thread->last_frame().interpreter_callee_receiver(signature));
   1.687 +    assert(Universe::heap()->is_in_reserved_or_null(receiver()),
   1.688 +           "sanity check");
   1.689 +    assert(receiver.is_null() ||
   1.690 +           !Universe::heap()->is_in_reserved(receiver->klass()),
   1.691 +           "sanity check");
   1.692 +  }
   1.693 +
   1.694 +  // resolve method
   1.695 +  CallInfo info;
   1.696 +  constantPoolHandle pool(thread, method(thread)->constants());
   1.697 +
   1.698 +  {
   1.699 +    JvmtiHideSingleStepping jhss(thread);
   1.700 +    LinkResolver::resolve_invoke(info, receiver, pool,
   1.701 +                                 get_index_u2_cpcache(thread, bytecode), bytecode, CHECK);
   1.702 +    if (JvmtiExport::can_hotswap_or_post_breakpoint()) {
   1.703 +      int retry_count = 0;
   1.704 +      while (info.resolved_method()->is_old()) {
   1.705 +        // It is very unlikely that method is redefined more than 100 times
   1.706 +        // in the middle of resolve. If it is looping here more than 100 times
   1.707 +        // means then there could be a bug here.
   1.708 +        guarantee((retry_count++ < 100),
   1.709 +                  "Could not resolve to latest version of redefined method");
   1.710 +        // method is redefined in the middle of resolve so re-try.
   1.711 +        LinkResolver::resolve_invoke(info, receiver, pool,
   1.712 +                                     get_index_u2_cpcache(thread, bytecode), bytecode, CHECK);
   1.713 +      }
   1.714 +    }
   1.715 +  } // end JvmtiHideSingleStepping
   1.716 +
   1.717 +  // check if link resolution caused cpCache to be updated
   1.718 +  if (already_resolved(thread)) return;
   1.719 +
   1.720 +  if (bytecode == Bytecodes::_invokeinterface) {
   1.721 +    if (TraceItables && Verbose) {
   1.722 +      ResourceMark rm(thread);
   1.723 +      tty->print_cr("Resolving: klass: %s to method: %s", info.resolved_klass()->name()->as_C_string(), info.resolved_method()->name()->as_C_string());
   1.724 +    }
   1.725 +  }
   1.726 +#ifdef ASSERT
   1.727 +  if (bytecode == Bytecodes::_invokeinterface) {
   1.728 +    if (info.resolved_method()->method_holder() ==
   1.729 +                                            SystemDictionary::Object_klass()) {
   1.730 +      // NOTE: THIS IS A FIX FOR A CORNER CASE in the JVM spec
   1.731 +      // (see also CallInfo::set_interface for details)
   1.732 +      assert(info.call_kind() == CallInfo::vtable_call ||
   1.733 +             info.call_kind() == CallInfo::direct_call, "");
   1.734 +      methodHandle rm = info.resolved_method();
   1.735 +      assert(rm->is_final() || info.has_vtable_index(),
   1.736 +             "should have been set already");
   1.737 +    } else if (!info.resolved_method()->has_itable_index()) {
   1.738 +      // Resolved something like CharSequence.toString.  Use vtable not itable.
   1.739 +      assert(info.call_kind() != CallInfo::itable_call, "");
   1.740 +    } else {
   1.741 +      // Setup itable entry
   1.742 +      assert(info.call_kind() == CallInfo::itable_call, "");
   1.743 +      int index = info.resolved_method()->itable_index();
   1.744 +      assert(info.itable_index() == index, "");
   1.745 +    }
   1.746 +  } else {
   1.747 +    assert(info.call_kind() == CallInfo::direct_call ||
   1.748 +           info.call_kind() == CallInfo::vtable_call, "");
   1.749 +  }
   1.750 +#endif
   1.751 +  switch (info.call_kind()) {
   1.752 +  case CallInfo::direct_call:
   1.753 +    cache_entry(thread)->set_direct_call(
   1.754 +      bytecode,
   1.755 +      info.resolved_method());
   1.756 +    break;
   1.757 +  case CallInfo::vtable_call:
   1.758 +    cache_entry(thread)->set_vtable_call(
   1.759 +      bytecode,
   1.760 +      info.resolved_method(),
   1.761 +      info.vtable_index());
   1.762 +    break;
   1.763 +  case CallInfo::itable_call:
   1.764 +    cache_entry(thread)->set_itable_call(
   1.765 +      bytecode,
   1.766 +      info.resolved_method(),
   1.767 +      info.itable_index());
   1.768 +    break;
   1.769 +  default:  ShouldNotReachHere();
   1.770 +  }
   1.771 +}
   1.772 +IRT_END
   1.773 +
   1.774 +
   1.775 +// First time execution:  Resolve symbols, create a permanent MethodType object.
   1.776 +IRT_ENTRY(void, InterpreterRuntime::resolve_invokehandle(JavaThread* thread)) {
   1.777 +  assert(EnableInvokeDynamic, "");
   1.778 +  const Bytecodes::Code bytecode = Bytecodes::_invokehandle;
   1.779 +
   1.780 +  // resolve method
   1.781 +  CallInfo info;
   1.782 +  constantPoolHandle pool(thread, method(thread)->constants());
   1.783 +
   1.784 +  {
   1.785 +    JvmtiHideSingleStepping jhss(thread);
   1.786 +    LinkResolver::resolve_invoke(info, Handle(), pool,
   1.787 +                                 get_index_u2_cpcache(thread, bytecode), bytecode, CHECK);
   1.788 +  } // end JvmtiHideSingleStepping
   1.789 +
   1.790 +  cache_entry(thread)->set_method_handle(pool, info);
   1.791 +}
   1.792 +IRT_END
   1.793 +
   1.794 +
   1.795 +// First time execution:  Resolve symbols, create a permanent CallSite object.
   1.796 +IRT_ENTRY(void, InterpreterRuntime::resolve_invokedynamic(JavaThread* thread)) {
   1.797 +  assert(EnableInvokeDynamic, "");
   1.798 +  const Bytecodes::Code bytecode = Bytecodes::_invokedynamic;
   1.799 +
   1.800 +  //TO DO: consider passing BCI to Java.
   1.801 +  //  int caller_bci = method(thread)->bci_from(bcp(thread));
   1.802 +
   1.803 +  // resolve method
   1.804 +  CallInfo info;
   1.805 +  constantPoolHandle pool(thread, method(thread)->constants());
   1.806 +  int index = get_index_u4(thread, bytecode);
   1.807 +  {
   1.808 +    JvmtiHideSingleStepping jhss(thread);
   1.809 +    LinkResolver::resolve_invoke(info, Handle(), pool,
   1.810 +                                 index, bytecode, CHECK);
   1.811 +  } // end JvmtiHideSingleStepping
   1.812 +
   1.813 +  ConstantPoolCacheEntry* cp_cache_entry = pool->invokedynamic_cp_cache_entry_at(index);
   1.814 +  cp_cache_entry->set_dynamic_call(pool, info);
   1.815 +}
   1.816 +IRT_END
   1.817 +
   1.818 +
   1.819 +//------------------------------------------------------------------------------------------------------------------------
   1.820 +// Miscellaneous
   1.821 +
   1.822 +
   1.823 +nmethod* InterpreterRuntime::frequency_counter_overflow(JavaThread* thread, address branch_bcp) {
   1.824 +  nmethod* nm = frequency_counter_overflow_inner(thread, branch_bcp);
   1.825 +  assert(branch_bcp != NULL || nm == NULL, "always returns null for non OSR requests");
   1.826 +  if (branch_bcp != NULL && nm != NULL) {
   1.827 +    // This was a successful request for an OSR nmethod.  Because
   1.828 +    // frequency_counter_overflow_inner ends with a safepoint check,
   1.829 +    // nm could have been unloaded so look it up again.  It's unsafe
   1.830 +    // to examine nm directly since it might have been freed and used
   1.831 +    // for something else.
   1.832 +    frame fr = thread->last_frame();
   1.833 +    Method* method =  fr.interpreter_frame_method();
   1.834 +    int bci = method->bci_from(fr.interpreter_frame_bcp());
   1.835 +    nm = method->lookup_osr_nmethod_for(bci, CompLevel_none, false);
   1.836 +  }
   1.837 +#ifndef PRODUCT
   1.838 +  if (TraceOnStackReplacement) {
   1.839 +    if (nm != NULL) {
   1.840 +      tty->print("OSR entry @ pc: " INTPTR_FORMAT ": ", nm->osr_entry());
   1.841 +      nm->print();
   1.842 +    }
   1.843 +  }
   1.844 +#endif
   1.845 +  return nm;
   1.846 +}
   1.847 +
   1.848 +IRT_ENTRY(nmethod*,
   1.849 +          InterpreterRuntime::frequency_counter_overflow_inner(JavaThread* thread, address branch_bcp))
   1.850 +  // use UnlockFlagSaver to clear and restore the _do_not_unlock_if_synchronized
   1.851 +  // flag, in case this method triggers classloading which will call into Java.
   1.852 +  UnlockFlagSaver fs(thread);
   1.853 +
   1.854 +  frame fr = thread->last_frame();
   1.855 +  assert(fr.is_interpreted_frame(), "must come from interpreter");
   1.856 +  methodHandle method(thread, fr.interpreter_frame_method());
   1.857 +  const int branch_bci = branch_bcp != NULL ? method->bci_from(branch_bcp) : InvocationEntryBci;
   1.858 +  const int bci = branch_bcp != NULL ? method->bci_from(fr.interpreter_frame_bcp()) : InvocationEntryBci;
   1.859 +
   1.860 +  assert(!HAS_PENDING_EXCEPTION, "Should not have any exceptions pending");
   1.861 +  nmethod* osr_nm = CompilationPolicy::policy()->event(method, method, branch_bci, bci, CompLevel_none, NULL, thread);
   1.862 +  assert(!HAS_PENDING_EXCEPTION, "Event handler should not throw any exceptions");
   1.863 +
   1.864 +  if (osr_nm != NULL) {
   1.865 +    // We may need to do on-stack replacement which requires that no
   1.866 +    // monitors in the activation are biased because their
   1.867 +    // BasicObjectLocks will need to migrate during OSR. Force
   1.868 +    // unbiasing of all monitors in the activation now (even though
   1.869 +    // the OSR nmethod might be invalidated) because we don't have a
   1.870 +    // safepoint opportunity later once the migration begins.
   1.871 +    if (UseBiasedLocking) {
   1.872 +      ResourceMark rm;
   1.873 +      GrowableArray<Handle>* objects_to_revoke = new GrowableArray<Handle>();
   1.874 +      for( BasicObjectLock *kptr = fr.interpreter_frame_monitor_end();
   1.875 +           kptr < fr.interpreter_frame_monitor_begin();
   1.876 +           kptr = fr.next_monitor_in_interpreter_frame(kptr) ) {
   1.877 +        if( kptr->obj() != NULL ) {
   1.878 +          objects_to_revoke->append(Handle(THREAD, kptr->obj()));
   1.879 +        }
   1.880 +      }
   1.881 +      BiasedLocking::revoke(objects_to_revoke);
   1.882 +    }
   1.883 +  }
   1.884 +  return osr_nm;
   1.885 +IRT_END
   1.886 +
   1.887 +IRT_LEAF(jint, InterpreterRuntime::bcp_to_di(Method* method, address cur_bcp))
   1.888 +  assert(ProfileInterpreter, "must be profiling interpreter");
   1.889 +  int bci = method->bci_from(cur_bcp);
   1.890 +  MethodData* mdo = method->method_data();
   1.891 +  if (mdo == NULL)  return 0;
   1.892 +  return mdo->bci_to_di(bci);
   1.893 +IRT_END
   1.894 +
   1.895 +IRT_ENTRY(void, InterpreterRuntime::profile_method(JavaThread* thread))
   1.896 +  // use UnlockFlagSaver to clear and restore the _do_not_unlock_if_synchronized
   1.897 +  // flag, in case this method triggers classloading which will call into Java.
   1.898 +  UnlockFlagSaver fs(thread);
   1.899 +
   1.900 +  assert(ProfileInterpreter, "must be profiling interpreter");
   1.901 +  frame fr = thread->last_frame();
   1.902 +  assert(fr.is_interpreted_frame(), "must come from interpreter");
   1.903 +  methodHandle method(thread, fr.interpreter_frame_method());
   1.904 +  Method::build_interpreter_method_data(method, THREAD);
   1.905 +  if (HAS_PENDING_EXCEPTION) {
   1.906 +    assert((PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())), "we expect only an OOM error here");
   1.907 +    CLEAR_PENDING_EXCEPTION;
   1.908 +    // and fall through...
   1.909 +  }
   1.910 +IRT_END
   1.911 +
   1.912 +
   1.913 +#ifdef ASSERT
   1.914 +IRT_LEAF(void, InterpreterRuntime::verify_mdp(Method* method, address bcp, address mdp))
   1.915 +  assert(ProfileInterpreter, "must be profiling interpreter");
   1.916 +
   1.917 +  MethodData* mdo = method->method_data();
   1.918 +  assert(mdo != NULL, "must not be null");
   1.919 +
   1.920 +  int bci = method->bci_from(bcp);
   1.921 +
   1.922 +  address mdp2 = mdo->bci_to_dp(bci);
   1.923 +  if (mdp != mdp2) {
   1.924 +    ResourceMark rm;
   1.925 +    ResetNoHandleMark rnm; // In a LEAF entry.
   1.926 +    HandleMark hm;
   1.927 +    tty->print_cr("FAILED verify : actual mdp %p   expected mdp %p @ bci %d", mdp, mdp2, bci);
   1.928 +    int current_di = mdo->dp_to_di(mdp);
   1.929 +    int expected_di  = mdo->dp_to_di(mdp2);
   1.930 +    tty->print_cr("  actual di %d   expected di %d", current_di, expected_di);
   1.931 +    int expected_approx_bci = mdo->data_at(expected_di)->bci();
   1.932 +    int approx_bci = -1;
   1.933 +    if (current_di >= 0) {
   1.934 +      approx_bci = mdo->data_at(current_di)->bci();
   1.935 +    }
   1.936 +    tty->print_cr("  actual bci is %d  expected bci %d", approx_bci, expected_approx_bci);
   1.937 +    mdo->print_on(tty);
   1.938 +    method->print_codes();
   1.939 +  }
   1.940 +  assert(mdp == mdp2, "wrong mdp");
   1.941 +IRT_END
   1.942 +#endif // ASSERT
   1.943 +
   1.944 +IRT_ENTRY(void, InterpreterRuntime::update_mdp_for_ret(JavaThread* thread, int return_bci))
   1.945 +  assert(ProfileInterpreter, "must be profiling interpreter");
   1.946 +  ResourceMark rm(thread);
   1.947 +  HandleMark hm(thread);
   1.948 +  frame fr = thread->last_frame();
   1.949 +  assert(fr.is_interpreted_frame(), "must come from interpreter");
   1.950 +  MethodData* h_mdo = fr.interpreter_frame_method()->method_data();
   1.951 +
   1.952 +  // Grab a lock to ensure atomic access to setting the return bci and
   1.953 +  // the displacement.  This can block and GC, invalidating all naked oops.
   1.954 +  MutexLocker ml(RetData_lock);
   1.955 +
   1.956 +  // ProfileData is essentially a wrapper around a derived oop, so we
   1.957 +  // need to take the lock before making any ProfileData structures.
   1.958 +  ProfileData* data = h_mdo->data_at(h_mdo->dp_to_di(fr.interpreter_frame_mdp()));
   1.959 +  RetData* rdata = data->as_RetData();
   1.960 +  address new_mdp = rdata->fixup_ret(return_bci, h_mdo);
   1.961 +  fr.interpreter_frame_set_mdp(new_mdp);
   1.962 +IRT_END
   1.963 +
   1.964 +IRT_ENTRY(MethodCounters*, InterpreterRuntime::build_method_counters(JavaThread* thread, Method* m))
   1.965 +  MethodCounters* mcs = Method::build_method_counters(m, thread);
   1.966 +  if (HAS_PENDING_EXCEPTION) {
   1.967 +    assert((PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())), "we expect only an OOM error here");
   1.968 +    CLEAR_PENDING_EXCEPTION;
   1.969 +  }
   1.970 +  return mcs;
   1.971 +IRT_END
   1.972 +
   1.973 +
   1.974 +IRT_ENTRY(void, InterpreterRuntime::at_safepoint(JavaThread* thread))
   1.975 +  // We used to need an explict preserve_arguments here for invoke bytecodes. However,
   1.976 +  // stack traversal automatically takes care of preserving arguments for invoke, so
   1.977 +  // this is no longer needed.
   1.978 +
   1.979 +  // IRT_END does an implicit safepoint check, hence we are guaranteed to block
   1.980 +  // if this is called during a safepoint
   1.981 +
   1.982 +  if (JvmtiExport::should_post_single_step()) {
   1.983 +    // We are called during regular safepoints and when the VM is
   1.984 +    // single stepping. If any thread is marked for single stepping,
   1.985 +    // then we may have JVMTI work to do.
   1.986 +    JvmtiExport::at_single_stepping_point(thread, method(thread), bcp(thread));
   1.987 +  }
   1.988 +IRT_END
   1.989 +
   1.990 +IRT_ENTRY(void, InterpreterRuntime::post_field_access(JavaThread *thread, oopDesc* obj,
   1.991 +ConstantPoolCacheEntry *cp_entry))
   1.992 +
   1.993 +  // check the access_flags for the field in the klass
   1.994 +
   1.995 +  InstanceKlass* ik = InstanceKlass::cast(cp_entry->f1_as_klass());
   1.996 +  int index = cp_entry->field_index();
   1.997 +  if ((ik->field_access_flags(index) & JVM_ACC_FIELD_ACCESS_WATCHED) == 0) return;
   1.998 +
   1.999 +  switch(cp_entry->flag_state()) {
  1.1000 +    case btos:    // fall through
  1.1001 +    case ctos:    // fall through
  1.1002 +    case stos:    // fall through
  1.1003 +    case itos:    // fall through
  1.1004 +    case ftos:    // fall through
  1.1005 +    case ltos:    // fall through
  1.1006 +    case dtos:    // fall through
  1.1007 +    case atos: break;
  1.1008 +    default: ShouldNotReachHere(); return;
  1.1009 +  }
  1.1010 +  bool is_static = (obj == NULL);
  1.1011 +  HandleMark hm(thread);
  1.1012 +
  1.1013 +  Handle h_obj;
  1.1014 +  if (!is_static) {
  1.1015 +    // non-static field accessors have an object, but we need a handle
  1.1016 +    h_obj = Handle(thread, obj);
  1.1017 +  }
  1.1018 +  instanceKlassHandle h_cp_entry_f1(thread, (Klass*)cp_entry->f1_as_klass());
  1.1019 +  jfieldID fid = jfieldIDWorkaround::to_jfieldID(h_cp_entry_f1, cp_entry->f2_as_index(), is_static);
  1.1020 +  JvmtiExport::post_field_access(thread, method(thread), bcp(thread), h_cp_entry_f1, h_obj, fid);
  1.1021 +IRT_END
  1.1022 +
  1.1023 +IRT_ENTRY(void, InterpreterRuntime::post_field_modification(JavaThread *thread,
  1.1024 +  oopDesc* obj, ConstantPoolCacheEntry *cp_entry, jvalue *value))
  1.1025 +
  1.1026 +  Klass* k = (Klass*)cp_entry->f1_as_klass();
  1.1027 +
  1.1028 +  // check the access_flags for the field in the klass
  1.1029 +  InstanceKlass* ik = InstanceKlass::cast(k);
  1.1030 +  int index = cp_entry->field_index();
  1.1031 +  // bail out if field modifications are not watched
  1.1032 +  if ((ik->field_access_flags(index) & JVM_ACC_FIELD_MODIFICATION_WATCHED) == 0) return;
  1.1033 +
  1.1034 +  char sig_type = '\0';
  1.1035 +
  1.1036 +  switch(cp_entry->flag_state()) {
  1.1037 +    case btos: sig_type = 'Z'; break;
  1.1038 +    case ctos: sig_type = 'C'; break;
  1.1039 +    case stos: sig_type = 'S'; break;
  1.1040 +    case itos: sig_type = 'I'; break;
  1.1041 +    case ftos: sig_type = 'F'; break;
  1.1042 +    case atos: sig_type = 'L'; break;
  1.1043 +    case ltos: sig_type = 'J'; break;
  1.1044 +    case dtos: sig_type = 'D'; break;
  1.1045 +    default:  ShouldNotReachHere(); return;
  1.1046 +  }
  1.1047 +  bool is_static = (obj == NULL);
  1.1048 +
  1.1049 +  HandleMark hm(thread);
  1.1050 +  instanceKlassHandle h_klass(thread, k);
  1.1051 +  jfieldID fid = jfieldIDWorkaround::to_jfieldID(h_klass, cp_entry->f2_as_index(), is_static);
  1.1052 +  jvalue fvalue;
  1.1053 +#ifdef _LP64
  1.1054 +  fvalue = *value;
  1.1055 +#else
  1.1056 +  // Long/double values are stored unaligned and also noncontiguously with
  1.1057 +  // tagged stacks.  We can't just do a simple assignment even in the non-
  1.1058 +  // J/D cases because a C++ compiler is allowed to assume that a jvalue is
  1.1059 +  // 8-byte aligned, and interpreter stack slots are only 4-byte aligned.
  1.1060 +  // We assume that the two halves of longs/doubles are stored in interpreter
  1.1061 +  // stack slots in platform-endian order.
  1.1062 +  jlong_accessor u;
  1.1063 +  jint* newval = (jint*)value;
  1.1064 +  u.words[0] = newval[0];
  1.1065 +  u.words[1] = newval[Interpreter::stackElementWords]; // skip if tag
  1.1066 +  fvalue.j = u.long_value;
  1.1067 +#endif // _LP64
  1.1068 +
  1.1069 +  Handle h_obj;
  1.1070 +  if (!is_static) {
  1.1071 +    // non-static field accessors have an object, but we need a handle
  1.1072 +    h_obj = Handle(thread, obj);
  1.1073 +  }
  1.1074 +
  1.1075 +  JvmtiExport::post_raw_field_modification(thread, method(thread), bcp(thread), h_klass, h_obj,
  1.1076 +                                           fid, sig_type, &fvalue);
  1.1077 +IRT_END
  1.1078 +
  1.1079 +IRT_ENTRY(void, InterpreterRuntime::post_method_entry(JavaThread *thread))
  1.1080 +  JvmtiExport::post_method_entry(thread, InterpreterRuntime::method(thread), InterpreterRuntime::last_frame(thread));
  1.1081 +IRT_END
  1.1082 +
  1.1083 +
  1.1084 +IRT_ENTRY(void, InterpreterRuntime::post_method_exit(JavaThread *thread))
  1.1085 +  JvmtiExport::post_method_exit(thread, InterpreterRuntime::method(thread), InterpreterRuntime::last_frame(thread));
  1.1086 +IRT_END
  1.1087 +
  1.1088 +IRT_LEAF(int, InterpreterRuntime::interpreter_contains(address pc))
  1.1089 +{
  1.1090 +  return (Interpreter::contains(pc) ? 1 : 0);
  1.1091 +}
  1.1092 +IRT_END
  1.1093 +
  1.1094 +
  1.1095 +// Implementation of SignatureHandlerLibrary
  1.1096 +
  1.1097 +address SignatureHandlerLibrary::set_handler_blob() {
  1.1098 +  BufferBlob* handler_blob = BufferBlob::create("native signature handlers", blob_size);
  1.1099 +  if (handler_blob == NULL) {
  1.1100 +    return NULL;
  1.1101 +  }
  1.1102 +  address handler = handler_blob->code_begin();
  1.1103 +  _handler_blob = handler_blob;
  1.1104 +  _handler = handler;
  1.1105 +  return handler;
  1.1106 +}
  1.1107 +
  1.1108 +void SignatureHandlerLibrary::initialize() {
  1.1109 +  if (_fingerprints != NULL) {
  1.1110 +    return;
  1.1111 +  }
  1.1112 +  if (set_handler_blob() == NULL) {
  1.1113 +    vm_exit_out_of_memory(blob_size, OOM_MALLOC_ERROR, "native signature handlers");
  1.1114 +  }
  1.1115 +
  1.1116 +  BufferBlob* bb = BufferBlob::create("Signature Handler Temp Buffer",
  1.1117 +                                      SignatureHandlerLibrary::buffer_size);
  1.1118 +  _buffer = bb->code_begin();
  1.1119 +
  1.1120 +  _fingerprints = new(ResourceObj::C_HEAP, mtCode)GrowableArray<uint64_t>(32, true);
  1.1121 +  _handlers     = new(ResourceObj::C_HEAP, mtCode)GrowableArray<address>(32, true);
  1.1122 +}
  1.1123 +
  1.1124 +address SignatureHandlerLibrary::set_handler(CodeBuffer* buffer) {
  1.1125 +  address handler   = _handler;
  1.1126 +  int     insts_size = buffer->pure_insts_size();
  1.1127 +  if (handler + insts_size > _handler_blob->code_end()) {
  1.1128 +    // get a new handler blob
  1.1129 +    handler = set_handler_blob();
  1.1130 +  }
  1.1131 +  if (handler != NULL) {
  1.1132 +    memcpy(handler, buffer->insts_begin(), insts_size);
  1.1133 +    pd_set_handler(handler);
  1.1134 +    ICache::invalidate_range(handler, insts_size);
  1.1135 +    _handler = handler + insts_size;
  1.1136 +  }
  1.1137 +  return handler;
  1.1138 +}
  1.1139 +
  1.1140 +void SignatureHandlerLibrary::add(methodHandle method) {
  1.1141 +  if (method->signature_handler() == NULL) {
  1.1142 +    // use slow signature handler if we can't do better
  1.1143 +    int handler_index = -1;
  1.1144 +    // check if we can use customized (fast) signature handler
  1.1145 +    if (UseFastSignatureHandlers && method->size_of_parameters() <= Fingerprinter::max_size_of_parameters) {
  1.1146 +      // use customized signature handler
  1.1147 +      MutexLocker mu(SignatureHandlerLibrary_lock);
  1.1148 +      // make sure data structure is initialized
  1.1149 +      initialize();
  1.1150 +      // lookup method signature's fingerprint
  1.1151 +      uint64_t fingerprint = Fingerprinter(method).fingerprint();
  1.1152 +      handler_index = _fingerprints->find(fingerprint);
  1.1153 +      // create handler if necessary
  1.1154 +      if (handler_index < 0) {
  1.1155 +        ResourceMark rm;
  1.1156 +        ptrdiff_t align_offset = (address)
  1.1157 +          round_to((intptr_t)_buffer, CodeEntryAlignment) - (address)_buffer;
  1.1158 +        CodeBuffer buffer((address)(_buffer + align_offset),
  1.1159 +                          SignatureHandlerLibrary::buffer_size - align_offset);
  1.1160 +        InterpreterRuntime::SignatureHandlerGenerator(method, &buffer).generate(fingerprint);
  1.1161 +        // copy into code heap
  1.1162 +        address handler = set_handler(&buffer);
  1.1163 +        if (handler == NULL) {
  1.1164 +          // use slow signature handler
  1.1165 +        } else {
  1.1166 +          // debugging suppport
  1.1167 +          if (PrintSignatureHandlers) {
  1.1168 +            tty->cr();
  1.1169 +            tty->print_cr("argument handler #%d for: %s %s (fingerprint = " UINT64_FORMAT ", %d bytes generated)",
  1.1170 +                          _handlers->length(),
  1.1171 +                          (method->is_static() ? "static" : "receiver"),
  1.1172 +                          method->name_and_sig_as_C_string(),
  1.1173 +                          fingerprint,
  1.1174 +                          buffer.insts_size());
  1.1175 +            Disassembler::decode(handler, handler + buffer.insts_size());
  1.1176 +#ifndef PRODUCT
  1.1177 +            tty->print_cr(" --- associated result handler ---");
  1.1178 +            address rh_begin = Interpreter::result_handler(method()->result_type());
  1.1179 +            address rh_end = rh_begin;
  1.1180 +            while (*(int*)rh_end != 0) {
  1.1181 +              rh_end += sizeof(int);
  1.1182 +            }
  1.1183 +            Disassembler::decode(rh_begin, rh_end);
  1.1184 +#endif
  1.1185 +          }
  1.1186 +          // add handler to library
  1.1187 +          _fingerprints->append(fingerprint);
  1.1188 +          _handlers->append(handler);
  1.1189 +          // set handler index
  1.1190 +          assert(_fingerprints->length() == _handlers->length(), "sanity check");
  1.1191 +          handler_index = _fingerprints->length() - 1;
  1.1192 +        }
  1.1193 +      }
  1.1194 +      // Set handler under SignatureHandlerLibrary_lock
  1.1195 +    if (handler_index < 0) {
  1.1196 +      // use generic signature handler
  1.1197 +      method->set_signature_handler(Interpreter::slow_signature_handler());
  1.1198 +    } else {
  1.1199 +      // set handler
  1.1200 +      method->set_signature_handler(_handlers->at(handler_index));
  1.1201 +    }
  1.1202 +    } else {
  1.1203 +      CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops());
  1.1204 +      // use generic signature handler
  1.1205 +      method->set_signature_handler(Interpreter::slow_signature_handler());
  1.1206 +    }
  1.1207 +  }
  1.1208 +#ifdef ASSERT
  1.1209 +  int handler_index = -1;
  1.1210 +  int fingerprint_index = -2;
  1.1211 +  {
  1.1212 +    // '_handlers' and '_fingerprints' are 'GrowableArray's and are NOT synchronized
  1.1213 +    // in any way if accessed from multiple threads. To avoid races with another
  1.1214 +    // thread which may change the arrays in the above, mutex protected block, we
  1.1215 +    // have to protect this read access here with the same mutex as well!
  1.1216 +    MutexLocker mu(SignatureHandlerLibrary_lock);
  1.1217 +    if (_handlers != NULL) {
  1.1218 +    handler_index = _handlers->find(method->signature_handler());
  1.1219 +    fingerprint_index = _fingerprints->find(Fingerprinter(method).fingerprint());
  1.1220 +  }
  1.1221 +  }
  1.1222 +  assert(method->signature_handler() == Interpreter::slow_signature_handler() ||
  1.1223 +         handler_index == fingerprint_index, "sanity check");
  1.1224 +#endif // ASSERT
  1.1225 +}
  1.1226 +
  1.1227 +
  1.1228 +BufferBlob*              SignatureHandlerLibrary::_handler_blob = NULL;
  1.1229 +address                  SignatureHandlerLibrary::_handler      = NULL;
  1.1230 +GrowableArray<uint64_t>* SignatureHandlerLibrary::_fingerprints = NULL;
  1.1231 +GrowableArray<address>*  SignatureHandlerLibrary::_handlers     = NULL;
  1.1232 +address                  SignatureHandlerLibrary::_buffer       = NULL;
  1.1233 +
  1.1234 +
  1.1235 +IRT_ENTRY(void, InterpreterRuntime::prepare_native_call(JavaThread* thread, Method* method))
  1.1236 +  methodHandle m(thread, method);
  1.1237 +  assert(m->is_native(), "sanity check");
  1.1238 +  // lookup native function entry point if it doesn't exist
  1.1239 +  bool in_base_library;
  1.1240 +  if (!m->has_native_function()) {
  1.1241 +    NativeLookup::lookup(m, in_base_library, CHECK);
  1.1242 +  }
  1.1243 +  // make sure signature handler is installed
  1.1244 +  SignatureHandlerLibrary::add(m);
  1.1245 +  // The interpreter entry point checks the signature handler first,
  1.1246 +  // before trying to fetch the native entry point and klass mirror.
  1.1247 +  // We must set the signature handler last, so that multiple processors
  1.1248 +  // preparing the same method will be sure to see non-null entry & mirror.
  1.1249 +IRT_END
  1.1250 +
  1.1251 +#if defined(IA32) || defined(AMD64) || defined(ARM)
  1.1252 +IRT_LEAF(void, InterpreterRuntime::popframe_move_outgoing_args(JavaThread* thread, void* src_address, void* dest_address))
  1.1253 +  if (src_address == dest_address) {
  1.1254 +    return;
  1.1255 +  }
  1.1256 +  ResetNoHandleMark rnm; // In a LEAF entry.
  1.1257 +  HandleMark hm;
  1.1258 +  ResourceMark rm;
  1.1259 +  frame fr = thread->last_frame();
  1.1260 +  assert(fr.is_interpreted_frame(), "");
  1.1261 +  jint bci = fr.interpreter_frame_bci();
  1.1262 +  methodHandle mh(thread, fr.interpreter_frame_method());
  1.1263 +  Bytecode_invoke invoke(mh, bci);
  1.1264 +  ArgumentSizeComputer asc(invoke.signature());
  1.1265 +  int size_of_arguments = (asc.size() + (invoke.has_receiver() ? 1 : 0)); // receiver
  1.1266 +  Copy::conjoint_jbytes(src_address, dest_address,
  1.1267 +                       size_of_arguments * Interpreter::stackElementSize);
  1.1268 +IRT_END
  1.1269 +#endif
  1.1270 +
  1.1271 +#if INCLUDE_JVMTI
  1.1272 +// This is a support of the JVMTI PopFrame interface.
  1.1273 +// Make sure it is an invokestatic of a polymorphic intrinsic that has a member_name argument
  1.1274 +// and return it as a vm_result so that it can be reloaded in the list of invokestatic parameters.
  1.1275 +// The dmh argument is a reference to a DirectMethoHandle that has a member name field.
  1.1276 +IRT_ENTRY(void, InterpreterRuntime::member_name_arg_or_null(JavaThread* thread, address dmh,
  1.1277 +                                                            Method* method, address bcp))
  1.1278 +  Bytecodes::Code code = Bytecodes::code_at(method, bcp);
  1.1279 +  if (code != Bytecodes::_invokestatic) {
  1.1280 +    return;
  1.1281 +  }
  1.1282 +  ConstantPool* cpool = method->constants();
  1.1283 +  int cp_index = Bytes::get_native_u2(bcp + 1) + ConstantPool::CPCACHE_INDEX_TAG;
  1.1284 +  Symbol* cname = cpool->klass_name_at(cpool->klass_ref_index_at(cp_index));
  1.1285 +  Symbol* mname = cpool->name_ref_at(cp_index);
  1.1286 +
  1.1287 +  if (MethodHandles::has_member_arg(cname, mname)) {
  1.1288 +    oop member_name = java_lang_invoke_DirectMethodHandle::member((oop)dmh);
  1.1289 +    thread->set_vm_result(member_name);
  1.1290 +  }
  1.1291 +IRT_END
  1.1292 +#endif // INCLUDE_JVMTI

mercurial