src/share/vm/interpreter/interpreterRuntime.cpp

Sat, 24 Oct 2020 16:43:47 +0800

author
aoqi
date
Sat, 24 Oct 2020 16:43:47 +0800
changeset 10015
eb7ce841ccec
parent 9448
73d689add964
parent 9970
f614bd5c9561
permissions
-rw-r--r--

Merge

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

mercurial