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