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