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