src/share/vm/interpreter/interpreterRuntime.cpp

Thu, 12 Oct 2017 21:27:07 +0800

author
aoqi
date
Thu, 12 Oct 2017 21:27:07 +0800
changeset 7535
7ae4e26cb1e0
parent 7419
d3f3f7677537
parent 6876
710a3c8b516e
child 7994
04ff2f6cd0eb
permissions
-rw-r--r--

merge

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

mercurial