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 assert(!(bytecode == Bytecodes::_invokedirect && info.call_kind() != CallInfo::direct_call), 968 "the target of a invokedirect bytecode must be a direct call"); 969 970 // check if link resolution caused cpCache to be updated 971 ConstantPoolCacheEntry* cp_cache_entry = cache_entry(thread); 972 if (cp_cache_entry->is_resolved(bytecode)) return; 973 974 #ifdef ASSERT 975 if (bytecode == Bytecodes::_invokeinterface) { 976 if (info.resolved_method()->method_holder() == 977 SystemDictionary::Object_klass()) { 978 // NOTE: THIS IS A FIX FOR A CORNER CASE in the JVM spec 979 // (see also CallInfo::set_interface for details) 980 assert(info.call_kind() == CallInfo::vtable_call || 981 info.call_kind() == CallInfo::direct_call, ""); 982 methodHandle rm = info.resolved_method(); 983 assert(rm->is_final() || info.has_vtable_index(), 984 "should have been set already"); 985 } else if (!info.resolved_method()->has_itable_index()) { 986 // Resolved something like CharSequence.toString. Use vtable not itable. 987 assert(info.call_kind() != CallInfo::itable_call, ""); 988 } else { 989 // Setup itable entry 990 assert(info.call_kind() == CallInfo::itable_call, ""); 991 int index = info.resolved_method()->itable_index(); 992 assert(info.itable_index() == index, ""); 993 } 994 } else { 995 assert(info.call_kind() == CallInfo::direct_call || 996 info.call_kind() == CallInfo::vtable_call, ""); 997 } 998 #endif 999 switch (info.call_kind()) { 1000 case CallInfo::direct_call: 1001 cp_cache_entry->set_direct_call( 1002 bytecode, 1003 info.resolved_method()); 1004 break; 1005 case CallInfo::vtable_call: 1006 cp_cache_entry->set_vtable_call( 1007 bytecode, 1008 info.resolved_method(), 1009 info.vtable_index()); 1010 break; 1011 case CallInfo::itable_call: 1012 cp_cache_entry->set_itable_call( 1013 bytecode, 1014 info.resolved_method(), 1015 info.itable_index()); 1016 break; 1017 default: ShouldNotReachHere(); 1018 } 1019 } 1020 1021 1022 // First time execution: Resolve symbols, create a permanent MethodType object. 1023 void InterpreterRuntime::resolve_invokehandle(JavaThread* thread) { 1024 Thread* THREAD = thread; 1025 const Bytecodes::Code bytecode = Bytecodes::_invokehandle; 1026 1027 // resolve method 1028 CallInfo info; 1029 constantPoolHandle pool(thread, method(thread)->constants()); 1030 { 1031 JvmtiHideSingleStepping jhss(thread); 1032 LinkResolver::resolve_invoke(info, Handle(), pool, 1033 get_index_u2_cpcache(thread, bytecode), bytecode, 1034 CHECK); 1035 } // end JvmtiHideSingleStepping 1036 1037 ConstantPoolCacheEntry* cp_cache_entry = cache_entry(thread); 1038 cp_cache_entry->set_method_handle(pool, info); 1039 } 1040 1041 // First time execution: Resolve symbols, create a permanent CallSite object. 1042 void InterpreterRuntime::resolve_invokedynamic(JavaThread* thread) { 1043 Thread* THREAD = thread; 1044 const Bytecodes::Code bytecode = Bytecodes::_invokedynamic; 1045 1046 //TO DO: consider passing BCI to Java. 1047 // int caller_bci = method(thread)->bci_from(bcp(thread)); 1048 1049 // resolve method 1050 CallInfo info; 1051 constantPoolHandle pool(thread, method(thread)->constants()); 1052 int index = get_index_u4(thread, bytecode); 1053 { 1054 JvmtiHideSingleStepping jhss(thread); 1055 LinkResolver::resolve_invoke(info, Handle(), pool, 1056 index, bytecode, CHECK); 1057 } // end JvmtiHideSingleStepping 1058 1059 ConstantPoolCacheEntry* cp_cache_entry = pool->invokedynamic_cp_cache_entry_at(index); 1060 cp_cache_entry->set_dynamic_call(pool, info); 1061 } 1062 1063 // This function is the interface to the assembly code. It returns the resolved 1064 // cpCache entry. This doesn't safepoint, but the helper routines safepoint. 1065 // This function will check for redefinition! 1066 IRT_ENTRY(void, InterpreterRuntime::resolve_from_cache(JavaThread* thread, Bytecodes::Code bytecode)) { 1067 switch (bytecode) { 1068 case Bytecodes::_getstatic: 1069 case Bytecodes::_putstatic: 1070 case Bytecodes::_getfield: 1071 case Bytecodes::_putfield: 1072 case Bytecodes::_vgetfield: 1073 resolve_get_put(thread, bytecode); 1074 break; 1075 case Bytecodes::_invokevirtual: 1076 case Bytecodes::_invokedirect: 1077 case Bytecodes::_invokespecial: 1078 case Bytecodes::_invokestatic: 1079 case Bytecodes::_invokeinterface: 1080 resolve_invoke(thread, bytecode); 1081 break; 1082 case Bytecodes::_invokehandle: 1083 resolve_invokehandle(thread); 1084 break; 1085 case Bytecodes::_invokedynamic: 1086 resolve_invokedynamic(thread); 1087 break; 1088 default: 1089 fatal("unexpected bytecode: %s", Bytecodes::name(bytecode)); 1090 break; 1091 } 1092 } 1093 IRT_END 1094 1095 //------------------------------------------------------------------------------------------------------------------------ 1096 // Miscellaneous 1097 1098 1099 nmethod* InterpreterRuntime::frequency_counter_overflow(JavaThread* thread, address branch_bcp) { 1100 nmethod* nm = frequency_counter_overflow_inner(thread, branch_bcp); 1101 assert(branch_bcp != NULL || nm == NULL, "always returns null for non OSR requests"); 1102 if (branch_bcp != NULL && nm != NULL) { 1103 // This was a successful request for an OSR nmethod. Because 1104 // frequency_counter_overflow_inner ends with a safepoint check, 1105 // nm could have been unloaded so look it up again. It's unsafe 1106 // to examine nm directly since it might have been freed and used 1107 // for something else. 1108 frame fr = thread->last_frame(); 1109 Method* method = fr.interpreter_frame_method(); 1110 int bci = method->bci_from(fr.interpreter_frame_bcp()); 1111 nm = method->lookup_osr_nmethod_for(bci, CompLevel_none, false); 1112 } 1113 #ifndef PRODUCT 1114 if (TraceOnStackReplacement) { 1115 if (nm != NULL) { 1116 tty->print("OSR entry @ pc: " INTPTR_FORMAT ": ", p2i(nm->osr_entry())); 1117 nm->print(); 1118 } 1119 } 1120 #endif 1121 return nm; 1122 } 1123 1124 IRT_ENTRY(nmethod*, 1125 InterpreterRuntime::frequency_counter_overflow_inner(JavaThread* thread, address branch_bcp)) 1126 // use UnlockFlagSaver to clear and restore the _do_not_unlock_if_synchronized 1127 // flag, in case this method triggers classloading which will call into Java. 1128 UnlockFlagSaver fs(thread); 1129 1130 frame fr = thread->last_frame(); 1131 assert(fr.is_interpreted_frame(), "must come from interpreter"); 1132 methodHandle method(thread, fr.interpreter_frame_method()); 1133 const int branch_bci = branch_bcp != NULL ? method->bci_from(branch_bcp) : InvocationEntryBci; 1134 const int bci = branch_bcp != NULL ? method->bci_from(fr.interpreter_frame_bcp()) : InvocationEntryBci; 1135 1136 assert(!HAS_PENDING_EXCEPTION, "Should not have any exceptions pending"); 1137 nmethod* osr_nm = CompilationPolicy::policy()->event(method, method, branch_bci, bci, CompLevel_none, NULL, thread); 1138 assert(!HAS_PENDING_EXCEPTION, "Event handler should not throw any exceptions"); 1139 1140 if (osr_nm != NULL) { 1141 // We may need to do on-stack replacement which requires that no 1142 // monitors in the activation are biased because their 1143 // BasicObjectLocks will need to migrate during OSR. Force 1144 // unbiasing of all monitors in the activation now (even though 1145 // the OSR nmethod might be invalidated) because we don't have a 1146 // safepoint opportunity later once the migration begins. 1147 if (UseBiasedLocking) { 1148 ResourceMark rm; 1149 GrowableArray<Handle>* objects_to_revoke = new GrowableArray<Handle>(); 1150 for( BasicObjectLock *kptr = fr.interpreter_frame_monitor_end(); 1151 kptr < fr.interpreter_frame_monitor_begin(); 1152 kptr = fr.next_monitor_in_interpreter_frame(kptr) ) { 1153 if( kptr->obj() != NULL ) { 1154 objects_to_revoke->append(Handle(THREAD, kptr->obj())); 1155 } 1156 } 1157 BiasedLocking::revoke(objects_to_revoke); 1158 } 1159 } 1160 return osr_nm; 1161 IRT_END 1162 1163 IRT_LEAF(jint, InterpreterRuntime::bcp_to_di(Method* method, address cur_bcp)) 1164 assert(ProfileInterpreter, "must be profiling interpreter"); 1165 int bci = method->bci_from(cur_bcp); 1166 MethodData* mdo = method->method_data(); 1167 if (mdo == NULL) return 0; 1168 return mdo->bci_to_di(bci); 1169 IRT_END 1170 1171 IRT_ENTRY(void, InterpreterRuntime::profile_method(JavaThread* thread)) 1172 // use UnlockFlagSaver to clear and restore the _do_not_unlock_if_synchronized 1173 // flag, in case this method triggers classloading which will call into Java. 1174 UnlockFlagSaver fs(thread); 1175 1176 assert(ProfileInterpreter, "must be profiling interpreter"); 1177 frame fr = thread->last_frame(); 1178 assert(fr.is_interpreted_frame(), "must come from interpreter"); 1179 methodHandle method(thread, fr.interpreter_frame_method()); 1180 Method::build_interpreter_method_data(method, THREAD); 1181 if (HAS_PENDING_EXCEPTION) { 1182 assert((PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())), "we expect only an OOM error here"); 1183 CLEAR_PENDING_EXCEPTION; 1184 // and fall through... 1185 } 1186 IRT_END 1187 1188 1189 #ifdef ASSERT 1190 IRT_LEAF(void, InterpreterRuntime::verify_mdp(Method* method, address bcp, address mdp)) 1191 assert(ProfileInterpreter, "must be profiling interpreter"); 1192 1193 MethodData* mdo = method->method_data(); 1194 assert(mdo != NULL, "must not be null"); 1195 1196 int bci = method->bci_from(bcp); 1197 1198 address mdp2 = mdo->bci_to_dp(bci); 1199 if (mdp != mdp2) { 1200 ResourceMark rm; 1201 ResetNoHandleMark rnm; // In a LEAF entry. 1202 HandleMark hm; 1203 tty->print_cr("FAILED verify : actual mdp %p expected mdp %p @ bci %d", mdp, mdp2, bci); 1204 int current_di = mdo->dp_to_di(mdp); 1205 int expected_di = mdo->dp_to_di(mdp2); 1206 tty->print_cr(" actual di %d expected di %d", current_di, expected_di); 1207 int expected_approx_bci = mdo->data_at(expected_di)->bci(); 1208 int approx_bci = -1; 1209 if (current_di >= 0) { 1210 approx_bci = mdo->data_at(current_di)->bci(); 1211 } 1212 tty->print_cr(" actual bci is %d expected bci %d", approx_bci, expected_approx_bci); 1213 mdo->print_on(tty); 1214 method->print_codes(); 1215 } 1216 assert(mdp == mdp2, "wrong mdp"); 1217 IRT_END 1218 #endif // ASSERT 1219 1220 IRT_ENTRY(void, InterpreterRuntime::update_mdp_for_ret(JavaThread* thread, int return_bci)) 1221 assert(ProfileInterpreter, "must be profiling interpreter"); 1222 ResourceMark rm(thread); 1223 HandleMark hm(thread); 1224 frame fr = thread->last_frame(); 1225 assert(fr.is_interpreted_frame(), "must come from interpreter"); 1226 MethodData* h_mdo = fr.interpreter_frame_method()->method_data(); 1227 1228 // Grab a lock to ensure atomic access to setting the return bci and 1229 // the displacement. This can block and GC, invalidating all naked oops. 1230 MutexLocker ml(RetData_lock); 1231 1232 // ProfileData is essentially a wrapper around a derived oop, so we 1233 // need to take the lock before making any ProfileData structures. 1234 ProfileData* data = h_mdo->data_at(h_mdo->dp_to_di(fr.interpreter_frame_mdp())); 1235 RetData* rdata = data->as_RetData(); 1236 address new_mdp = rdata->fixup_ret(return_bci, h_mdo); 1237 fr.interpreter_frame_set_mdp(new_mdp); 1238 IRT_END 1239 1240 IRT_ENTRY(MethodCounters*, InterpreterRuntime::build_method_counters(JavaThread* thread, Method* m)) 1241 MethodCounters* mcs = Method::build_method_counters(m, thread); 1242 if (HAS_PENDING_EXCEPTION) { 1243 assert((PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())), "we expect only an OOM error here"); 1244 CLEAR_PENDING_EXCEPTION; 1245 } 1246 return mcs; 1247 IRT_END 1248 1249 1250 IRT_ENTRY(void, InterpreterRuntime::at_safepoint(JavaThread* thread)) 1251 // We used to need an explict preserve_arguments here for invoke bytecodes. However, 1252 // stack traversal automatically takes care of preserving arguments for invoke, so 1253 // this is no longer needed. 1254 1255 // IRT_END does an implicit safepoint check, hence we are guaranteed to block 1256 // if this is called during a safepoint 1257 1258 if (JvmtiExport::should_post_single_step()) { 1259 // We are called during regular safepoints and when the VM is 1260 // single stepping. If any thread is marked for single stepping, 1261 // then we may have JVMTI work to do. 1262 JvmtiExport::at_single_stepping_point(thread, method(thread), bcp(thread)); 1263 } 1264 IRT_END 1265 1266 IRT_ENTRY(void, InterpreterRuntime::post_field_access(JavaThread *thread, oopDesc* obj, 1267 ConstantPoolCacheEntry *cp_entry)) 1268 1269 // check the access_flags for the field in the klass 1270 1271 InstanceKlass* ik = InstanceKlass::cast(cp_entry->f1_as_klass()); 1272 int index = cp_entry->field_index(); 1273 if ((ik->field_access_flags(index) & JVM_ACC_FIELD_ACCESS_WATCHED) == 0) return; 1274 1275 bool is_static = (obj == NULL); 1276 HandleMark hm(thread); 1277 1278 Handle h_obj; 1279 if (!is_static) { 1280 // non-static field accessors have an object, but we need a handle 1281 h_obj = Handle(thread, obj); 1282 } 1283 instanceKlassHandle h_cp_entry_f1(thread, (Klass*)cp_entry->f1_as_klass()); 1284 jfieldID fid = jfieldIDWorkaround::to_jfieldID(h_cp_entry_f1, cp_entry->f2_as_index(), is_static); 1285 JvmtiExport::post_field_access(thread, method(thread), bcp(thread), h_cp_entry_f1, h_obj, fid); 1286 IRT_END 1287 1288 IRT_ENTRY(void, InterpreterRuntime::post_field_modification(JavaThread *thread, 1289 oopDesc* obj, ConstantPoolCacheEntry *cp_entry, jvalue *value)) 1290 1291 Klass* k = (Klass*)cp_entry->f1_as_klass(); 1292 1293 // check the access_flags for the field in the klass 1294 InstanceKlass* ik = InstanceKlass::cast(k); 1295 int index = cp_entry->field_index(); 1296 // bail out if field modifications are not watched 1297 if ((ik->field_access_flags(index) & JVM_ACC_FIELD_MODIFICATION_WATCHED) == 0) return; 1298 1299 char sig_type = '\0'; 1300 1301 switch(cp_entry->flag_state()) { 1302 case btos: sig_type = 'Z'; break; 1303 case ctos: sig_type = 'C'; break; 1304 case stos: sig_type = 'S'; break; 1305 case itos: sig_type = 'I'; break; 1306 case ftos: sig_type = 'F'; break; 1307 case atos: sig_type = 'L'; break; 1308 case ltos: sig_type = 'J'; break; 1309 case dtos: sig_type = 'D'; break; 1310 default: ShouldNotReachHere(); return; 1311 } 1312 bool is_static = (obj == NULL); 1313 1314 HandleMark hm(thread); 1315 instanceKlassHandle h_klass(thread, k); 1316 jfieldID fid = jfieldIDWorkaround::to_jfieldID(h_klass, cp_entry->f2_as_index(), is_static); 1317 jvalue fvalue; 1318 #ifdef _LP64 1319 fvalue = *value; 1320 #else 1321 // Long/double values are stored unaligned and also noncontiguously with 1322 // tagged stacks. We can't just do a simple assignment even in the non- 1323 // J/D cases because a C++ compiler is allowed to assume that a jvalue is 1324 // 8-byte aligned, and interpreter stack slots are only 4-byte aligned. 1325 // We assume that the two halves of longs/doubles are stored in interpreter 1326 // stack slots in platform-endian order. 1327 jlong_accessor u; 1328 jint* newval = (jint*)value; 1329 u.words[0] = newval[0]; 1330 u.words[1] = newval[Interpreter::stackElementWords]; // skip if tag 1331 fvalue.j = u.long_value; 1332 #endif // _LP64 1333 1334 Handle h_obj; 1335 if (!is_static) { 1336 // non-static field accessors have an object, but we need a handle 1337 h_obj = Handle(thread, obj); 1338 } 1339 1340 JvmtiExport::post_raw_field_modification(thread, method(thread), bcp(thread), h_klass, h_obj, 1341 fid, sig_type, &fvalue); 1342 IRT_END 1343 1344 IRT_ENTRY(void, InterpreterRuntime::post_method_entry(JavaThread *thread)) 1345 JvmtiExport::post_method_entry(thread, InterpreterRuntime::method(thread), InterpreterRuntime::last_frame(thread)); 1346 IRT_END 1347 1348 1349 IRT_ENTRY(void, InterpreterRuntime::post_method_exit(JavaThread *thread)) 1350 JvmtiExport::post_method_exit(thread, InterpreterRuntime::method(thread), InterpreterRuntime::last_frame(thread)); 1351 IRT_END 1352 1353 IRT_LEAF(int, InterpreterRuntime::interpreter_contains(address pc)) 1354 { 1355 return (Interpreter::contains(pc) ? 1 : 0); 1356 } 1357 IRT_END 1358 1359 1360 // Implementation of SignatureHandlerLibrary 1361 1362 #ifndef SHARING_FAST_NATIVE_FINGERPRINTS 1363 // Dummy definition (else normalization method is defined in CPU 1364 // dependant code) 1365 uint64_t InterpreterRuntime::normalize_fast_native_fingerprint(uint64_t fingerprint) { 1366 return fingerprint; 1367 } 1368 #endif 1369 1370 address SignatureHandlerLibrary::set_handler_blob() { 1371 BufferBlob* handler_blob = BufferBlob::create("native signature handlers", blob_size); 1372 if (handler_blob == NULL) { 1373 return NULL; 1374 } 1375 address handler = handler_blob->code_begin(); 1376 _handler_blob = handler_blob; 1377 _handler = handler; 1378 return handler; 1379 } 1380 1381 void SignatureHandlerLibrary::initialize() { 1382 if (_fingerprints != NULL) { 1383 return; 1384 } 1385 if (set_handler_blob() == NULL) { 1386 vm_exit_out_of_memory(blob_size, OOM_MALLOC_ERROR, "native signature handlers"); 1387 } 1388 1389 BufferBlob* bb = BufferBlob::create("Signature Handler Temp Buffer", 1390 SignatureHandlerLibrary::buffer_size); 1391 _buffer = bb->code_begin(); 1392 1393 _fingerprints = new(ResourceObj::C_HEAP, mtCode)GrowableArray<uint64_t>(32, true); 1394 _handlers = new(ResourceObj::C_HEAP, mtCode)GrowableArray<address>(32, true); 1395 } 1396 1397 address SignatureHandlerLibrary::set_handler(CodeBuffer* buffer) { 1398 address handler = _handler; 1399 int insts_size = buffer->pure_insts_size(); 1400 if (handler + insts_size > _handler_blob->code_end()) { 1401 // get a new handler blob 1402 handler = set_handler_blob(); 1403 } 1404 if (handler != NULL) { 1405 memcpy(handler, buffer->insts_begin(), insts_size); 1406 pd_set_handler(handler); 1407 ICache::invalidate_range(handler, insts_size); 1408 _handler = handler + insts_size; 1409 } 1410 CodeCacheExtensions::handle_generated_handler(handler, buffer->name(), _handler); 1411 return handler; 1412 } 1413 1414 void SignatureHandlerLibrary::add(const methodHandle& method) { 1415 if (method->signature_handler() == NULL) { 1416 // use slow signature handler if we can't do better 1417 int handler_index = -1; 1418 // check if we can use customized (fast) signature handler 1419 if (UseFastSignatureHandlers && CodeCacheExtensions::support_fast_signature_handlers() && method->size_of_parameters() <= Fingerprinter::max_size_of_parameters) { 1420 // use customized signature handler 1421 MutexLocker mu(SignatureHandlerLibrary_lock); 1422 // make sure data structure is initialized 1423 initialize(); 1424 // lookup method signature's fingerprint 1425 uint64_t fingerprint = Fingerprinter(method).fingerprint(); 1426 // allow CPU dependant code to optimize the fingerprints for the fast handler 1427 fingerprint = InterpreterRuntime::normalize_fast_native_fingerprint(fingerprint); 1428 handler_index = _fingerprints->find(fingerprint); 1429 // create handler if necessary 1430 if (handler_index < 0) { 1431 ResourceMark rm; 1432 ptrdiff_t align_offset = (address) 1433 round_to((intptr_t)_buffer, CodeEntryAlignment) - (address)_buffer; 1434 CodeBuffer buffer((address)(_buffer + align_offset), 1435 SignatureHandlerLibrary::buffer_size - align_offset); 1436 if (!CodeCacheExtensions::support_dynamic_code()) { 1437 // we need a name for the signature (for lookups or saving) 1438 const int SYMBOL_SIZE = 50; 1439 char *symbolName = NEW_RESOURCE_ARRAY(char, SYMBOL_SIZE); 1440 // support for named signatures 1441 jio_snprintf(symbolName, SYMBOL_SIZE, 1442 "native_" UINT64_FORMAT, fingerprint); 1443 buffer.set_name(symbolName); 1444 } 1445 InterpreterRuntime::SignatureHandlerGenerator(method, &buffer).generate(fingerprint); 1446 // copy into code heap 1447 address handler = set_handler(&buffer); 1448 if (handler == NULL) { 1449 // use slow signature handler (without memorizing it in the fingerprints) 1450 } else { 1451 // debugging suppport 1452 if (PrintSignatureHandlers && (handler != Interpreter::slow_signature_handler())) { 1453 ttyLocker ttyl; 1454 tty->cr(); 1455 tty->print_cr("argument handler #%d for: %s %s (fingerprint = " UINT64_FORMAT ", %d bytes generated)", 1456 _handlers->length(), 1457 (method->is_static() ? "static" : "receiver"), 1458 method->name_and_sig_as_C_string(), 1459 fingerprint, 1460 buffer.insts_size()); 1461 if (buffer.insts_size() > 0) { 1462 // buffer may be empty for pregenerated handlers 1463 Disassembler::decode(handler, handler + buffer.insts_size()); 1464 } 1465 #ifndef PRODUCT 1466 address rh_begin = Interpreter::result_handler(method()->result_type()); 1467 if (CodeCache::contains(rh_begin)) { 1468 // else it might be special platform dependent values 1469 tty->print_cr(" --- associated result handler ---"); 1470 address rh_end = rh_begin; 1471 while (*(int*)rh_end != 0) { 1472 rh_end += sizeof(int); 1473 } 1474 Disassembler::decode(rh_begin, rh_end); 1475 } else { 1476 tty->print_cr(" associated result handler: " PTR_FORMAT, p2i(rh_begin)); 1477 } 1478 #endif 1479 } 1480 // add handler to library 1481 _fingerprints->append(fingerprint); 1482 _handlers->append(handler); 1483 // set handler index 1484 assert(_fingerprints->length() == _handlers->length(), "sanity check"); 1485 handler_index = _fingerprints->length() - 1; 1486 } 1487 } 1488 // Set handler under SignatureHandlerLibrary_lock 1489 if (handler_index < 0) { 1490 // use generic signature handler 1491 method->set_signature_handler(Interpreter::slow_signature_handler()); 1492 } else { 1493 // set handler 1494 method->set_signature_handler(_handlers->at(handler_index)); 1495 } 1496 } else { 1497 CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops()); 1498 // use generic signature handler 1499 method->set_signature_handler(Interpreter::slow_signature_handler()); 1500 } 1501 } 1502 #ifdef ASSERT 1503 int handler_index = -1; 1504 int fingerprint_index = -2; 1505 { 1506 // '_handlers' and '_fingerprints' are 'GrowableArray's and are NOT synchronized 1507 // in any way if accessed from multiple threads. To avoid races with another 1508 // thread which may change the arrays in the above, mutex protected block, we 1509 // have to protect this read access here with the same mutex as well! 1510 MutexLocker mu(SignatureHandlerLibrary_lock); 1511 if (_handlers != NULL) { 1512 handler_index = _handlers->find(method->signature_handler()); 1513 uint64_t fingerprint = Fingerprinter(method).fingerprint(); 1514 fingerprint = InterpreterRuntime::normalize_fast_native_fingerprint(fingerprint); 1515 fingerprint_index = _fingerprints->find(fingerprint); 1516 } 1517 } 1518 assert(method->signature_handler() == Interpreter::slow_signature_handler() || 1519 handler_index == fingerprint_index, "sanity check"); 1520 #endif // ASSERT 1521 } 1522 1523 void SignatureHandlerLibrary::add(uint64_t fingerprint, address handler) { 1524 int handler_index = -1; 1525 // use customized signature handler 1526 MutexLocker mu(SignatureHandlerLibrary_lock); 1527 // make sure data structure is initialized 1528 initialize(); 1529 fingerprint = InterpreterRuntime::normalize_fast_native_fingerprint(fingerprint); 1530 handler_index = _fingerprints->find(fingerprint); 1531 // create handler if necessary 1532 if (handler_index < 0) { 1533 if (PrintSignatureHandlers && (handler != Interpreter::slow_signature_handler())) { 1534 tty->cr(); 1535 tty->print_cr("argument handler #%d at " PTR_FORMAT " for fingerprint " UINT64_FORMAT, 1536 _handlers->length(), 1537 p2i(handler), 1538 fingerprint); 1539 } 1540 _fingerprints->append(fingerprint); 1541 _handlers->append(handler); 1542 } else { 1543 if (PrintSignatureHandlers) { 1544 tty->cr(); 1545 tty->print_cr("duplicate argument handler #%d for fingerprint " UINT64_FORMAT "(old: " PTR_FORMAT ", new : " PTR_FORMAT ")", 1546 _handlers->length(), 1547 fingerprint, 1548 p2i(_handlers->at(handler_index)), 1549 p2i(handler)); 1550 } 1551 } 1552 } 1553 1554 1555 BufferBlob* SignatureHandlerLibrary::_handler_blob = NULL; 1556 address SignatureHandlerLibrary::_handler = NULL; 1557 GrowableArray<uint64_t>* SignatureHandlerLibrary::_fingerprints = NULL; 1558 GrowableArray<address>* SignatureHandlerLibrary::_handlers = NULL; 1559 address SignatureHandlerLibrary::_buffer = NULL; 1560 1561 1562 IRT_ENTRY(void, InterpreterRuntime::prepare_native_call(JavaThread* thread, Method* method)) 1563 methodHandle m(thread, method); 1564 assert(m->is_native(), "sanity check"); 1565 // lookup native function entry point if it doesn't exist 1566 bool in_base_library; 1567 if (!m->has_native_function()) { 1568 NativeLookup::lookup(m, in_base_library, CHECK); 1569 } 1570 // make sure signature handler is installed 1571 SignatureHandlerLibrary::add(m); 1572 // The interpreter entry point checks the signature handler first, 1573 // before trying to fetch the native entry point and klass mirror. 1574 // We must set the signature handler last, so that multiple processors 1575 // preparing the same method will be sure to see non-null entry & mirror. 1576 IRT_END 1577 1578 #if defined(IA32) || defined(AMD64) || defined(ARM) 1579 IRT_LEAF(void, InterpreterRuntime::popframe_move_outgoing_args(JavaThread* thread, void* src_address, void* dest_address)) 1580 if (src_address == dest_address) { 1581 return; 1582 } 1583 ResetNoHandleMark rnm; // In a LEAF entry. 1584 HandleMark hm; 1585 ResourceMark rm; 1586 frame fr = thread->last_frame(); 1587 assert(fr.is_interpreted_frame(), ""); 1588 jint bci = fr.interpreter_frame_bci(); 1589 methodHandle mh(thread, fr.interpreter_frame_method()); 1590 Bytecode_invoke invoke(mh, bci); 1591 ArgumentSizeComputer asc(invoke.signature()); 1592 int size_of_arguments = (asc.size() + (invoke.has_receiver() ? 1 : 0)); // receiver 1593 Copy::conjoint_jbytes(src_address, dest_address, 1594 size_of_arguments * Interpreter::stackElementSize); 1595 IRT_END 1596 #endif 1597 1598 #if INCLUDE_JVMTI 1599 // This is a support of the JVMTI PopFrame interface. 1600 // Make sure it is an invokestatic of a polymorphic intrinsic that has a member_name argument 1601 // and return it as a vm_result so that it can be reloaded in the list of invokestatic parameters. 1602 // The member_name argument is a saved reference (in local#0) to the member_name. 1603 // For backward compatibility with some JDK versions (7, 8) it can also be a direct method handle. 1604 // FIXME: remove DMH case after j.l.i.InvokerBytecodeGenerator code shape is updated. 1605 IRT_ENTRY(void, InterpreterRuntime::member_name_arg_or_null(JavaThread* thread, address member_name, 1606 Method* method, address bcp)) 1607 Bytecodes::Code code = Bytecodes::code_at(method, bcp); 1608 if (code != Bytecodes::_invokestatic) { 1609 return; 1610 } 1611 ConstantPool* cpool = method->constants(); 1612 int cp_index = Bytes::get_native_u2(bcp + 1) + ConstantPool::CPCACHE_INDEX_TAG; 1613 Symbol* cname = cpool->klass_name_at(cpool->klass_ref_index_at(cp_index)); 1614 Symbol* mname = cpool->name_ref_at(cp_index); 1615 1616 if (MethodHandles::has_member_arg(cname, mname)) { 1617 oop member_name_oop = (oop) member_name; 1618 if (java_lang_invoke_DirectMethodHandle::is_instance(member_name_oop)) { 1619 // FIXME: remove after j.l.i.InvokerBytecodeGenerator code shape is updated. 1620 member_name_oop = java_lang_invoke_DirectMethodHandle::member(member_name_oop); 1621 } 1622 thread->set_vm_result(member_name_oop); 1623 } else { 1624 thread->set_vm_result(NULL); 1625 } 1626 IRT_END 1627 #endif // INCLUDE_JVMTI