src/share/vm/interpreter/interpreterRuntime.cpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 1
2d8a650513c2
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

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

mercurial