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