1 /* 2 * Copyright (c) 1998, 2023, 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/vmClasses.hpp" 27 #include "classfile/vmSymbols.hpp" 28 #include "code/codeCache.hpp" 29 #include "code/compiledMethod.inline.hpp" 30 #include "code/compiledIC.hpp" 31 #include "code/icBuffer.hpp" 32 #include "code/nmethod.hpp" 33 #include "code/pcDesc.hpp" 34 #include "code/scopeDesc.hpp" 35 #include "code/vtableStubs.hpp" 36 #include "compiler/compileBroker.hpp" 37 #include "compiler/oopMap.hpp" 38 #include "gc/g1/heapRegion.hpp" 39 #include "gc/shared/barrierSet.hpp" 40 #include "gc/shared/collectedHeap.hpp" 41 #include "gc/shared/gcLocker.hpp" 42 #include "interpreter/bytecode.hpp" 43 #include "interpreter/interpreter.hpp" 44 #include "interpreter/linkResolver.hpp" 45 #include "logging/log.hpp" 46 #include "logging/logStream.hpp" 47 #include "memory/oopFactory.hpp" 48 #include "memory/resourceArea.hpp" 49 #include "oops/objArrayKlass.hpp" 50 #include "oops/klass.inline.hpp" 51 #include "oops/oop.inline.hpp" 52 #include "oops/typeArrayOop.inline.hpp" 53 #include "opto/ad.hpp" 54 #include "opto/addnode.hpp" 55 #include "opto/callnode.hpp" 56 #include "opto/cfgnode.hpp" 57 #include "opto/graphKit.hpp" 58 #include "opto/machnode.hpp" 59 #include "opto/matcher.hpp" 60 #include "opto/memnode.hpp" 61 #include "opto/mulnode.hpp" 62 #include "opto/output.hpp" 63 #include "opto/runtime.hpp" 64 #include "opto/subnode.hpp" 65 #include "prims/jvmtiExport.hpp" 66 #include "runtime/atomic.hpp" 67 #include "runtime/frame.inline.hpp" 68 #include "runtime/handles.inline.hpp" 69 #include "runtime/interfaceSupport.inline.hpp" 70 #include "runtime/javaCalls.hpp" 71 #include "runtime/sharedRuntime.hpp" 72 #include "runtime/signature.hpp" 73 #include "runtime/stackWatermarkSet.hpp" 74 #include "runtime/synchronizer.hpp" 75 #include "runtime/threadCritical.hpp" 76 #include "runtime/threadWXSetters.inline.hpp" 77 #include "runtime/vframe.hpp" 78 #include "runtime/vframeArray.hpp" 79 #include "runtime/vframe_hp.hpp" 80 #include "utilities/copy.hpp" 81 #include "utilities/preserveException.hpp" 82 83 84 // For debugging purposes: 85 // To force FullGCALot inside a runtime function, add the following two lines 86 // 87 // Universe::release_fullgc_alot_dummy(); 88 // MarkSweep::invoke(0, "Debugging"); 89 // 90 // At command line specify the parameters: -XX:+FullGCALot -XX:FullGCALotStart=100000000 91 92 93 94 95 // Compiled code entry points 96 address OptoRuntime::_new_instance_Java = nullptr; 97 address OptoRuntime::_new_array_Java = nullptr; 98 address OptoRuntime::_new_array_nozero_Java = nullptr; 99 address OptoRuntime::_multianewarray2_Java = nullptr; 100 address OptoRuntime::_multianewarray3_Java = nullptr; 101 address OptoRuntime::_multianewarray4_Java = nullptr; 102 address OptoRuntime::_multianewarray5_Java = nullptr; 103 address OptoRuntime::_multianewarrayN_Java = nullptr; 104 address OptoRuntime::_vtable_must_compile_Java = nullptr; 105 address OptoRuntime::_complete_monitor_locking_Java = nullptr; 106 address OptoRuntime::_monitor_notify_Java = nullptr; 107 address OptoRuntime::_monitor_notifyAll_Java = nullptr; 108 address OptoRuntime::_rethrow_Java = nullptr; 109 110 address OptoRuntime::_slow_arraycopy_Java = nullptr; 111 address OptoRuntime::_register_finalizer_Java = nullptr; 112 #if INCLUDE_JVMTI 113 address OptoRuntime::_notify_jvmti_vthread_start = nullptr; 114 address OptoRuntime::_notify_jvmti_vthread_end = nullptr; 115 address OptoRuntime::_notify_jvmti_vthread_mount = nullptr; 116 address OptoRuntime::_notify_jvmti_vthread_unmount = nullptr; 117 #endif 118 119 ExceptionBlob* OptoRuntime::_exception_blob; 120 121 // This should be called in an assertion at the start of OptoRuntime routines 122 // which are entered from compiled code (all of them) 123 #ifdef ASSERT 124 static bool check_compiled_frame(JavaThread* thread) { 125 assert(thread->last_frame().is_runtime_frame(), "cannot call runtime directly from compiled code"); 126 RegisterMap map(thread, 127 RegisterMap::UpdateMap::skip, 128 RegisterMap::ProcessFrames::include, 129 RegisterMap::WalkContinuation::skip); 130 frame caller = thread->last_frame().sender(&map); 131 assert(caller.is_compiled_frame(), "not being called from compiled like code"); 132 return true; 133 } 134 #endif // ASSERT 135 136 137 #define gen(env, var, type_func_gen, c_func, fancy_jump, pass_tls, return_pc) \ 138 var = generate_stub(env, type_func_gen, CAST_FROM_FN_PTR(address, c_func), #var, fancy_jump, pass_tls, return_pc); \ 139 if (var == nullptr) { return false; } 140 141 bool OptoRuntime::generate(ciEnv* env) { 142 143 generate_exception_blob(); 144 145 // Note: tls: Means fetching the return oop out of the thread-local storage 146 // 147 // variable/name type-function-gen , runtime method ,fncy_jp, tls,retpc 148 // ------------------------------------------------------------------------------------------------------------------------------- 149 gen(env, _new_instance_Java , new_instance_Type , new_instance_C , 0 , true, false); 150 gen(env, _new_array_Java , new_array_Type , new_array_C , 0 , true, false); 151 gen(env, _new_array_nozero_Java , new_array_Type , new_array_nozero_C , 0 , true, false); 152 gen(env, _multianewarray2_Java , multianewarray2_Type , multianewarray2_C , 0 , true, false); 153 gen(env, _multianewarray3_Java , multianewarray3_Type , multianewarray3_C , 0 , true, false); 154 gen(env, _multianewarray4_Java , multianewarray4_Type , multianewarray4_C , 0 , true, false); 155 gen(env, _multianewarray5_Java , multianewarray5_Type , multianewarray5_C , 0 , true, false); 156 gen(env, _multianewarrayN_Java , multianewarrayN_Type , multianewarrayN_C , 0 , true, false); 157 #if INCLUDE_JVMTI 158 gen(env, _notify_jvmti_vthread_start , notify_jvmti_vthread_Type , SharedRuntime::notify_jvmti_vthread_start, 0, true, false); 159 gen(env, _notify_jvmti_vthread_end , notify_jvmti_vthread_Type , SharedRuntime::notify_jvmti_vthread_end, 0, true, false); 160 gen(env, _notify_jvmti_vthread_mount , notify_jvmti_vthread_Type , SharedRuntime::notify_jvmti_vthread_mount, 0, true, false); 161 gen(env, _notify_jvmti_vthread_unmount , notify_jvmti_vthread_Type , SharedRuntime::notify_jvmti_vthread_unmount, 0, true, false); 162 #endif 163 gen(env, _complete_monitor_locking_Java , complete_monitor_enter_Type , SharedRuntime::complete_monitor_locking_C, 0, false, false); 164 gen(env, _monitor_notify_Java , monitor_notify_Type , monitor_notify_C , 0 , false, false); 165 gen(env, _monitor_notifyAll_Java , monitor_notify_Type , monitor_notifyAll_C , 0 , false, false); 166 gen(env, _rethrow_Java , rethrow_Type , rethrow_C , 2 , true , true ); 167 168 gen(env, _slow_arraycopy_Java , slow_arraycopy_Type , SharedRuntime::slow_arraycopy_C , 0 , false, false); 169 gen(env, _register_finalizer_Java , register_finalizer_Type , register_finalizer , 0 , false, false); 170 171 return true; 172 } 173 174 #undef gen 175 176 177 // Helper method to do generation of RunTimeStub's 178 address OptoRuntime::generate_stub(ciEnv* env, 179 TypeFunc_generator gen, address C_function, 180 const char *name, int is_fancy_jump, 181 bool pass_tls, 182 bool return_pc) { 183 184 // Matching the default directive, we currently have no method to match. 185 DirectiveSet* directive = DirectivesStack::getDefaultDirective(CompileBroker::compiler(CompLevel_full_optimization)); 186 ResourceMark rm; 187 Compile C(env, gen, C_function, name, is_fancy_jump, pass_tls, return_pc, directive); 188 DirectivesStack::release(directive); 189 return C.stub_entry_point(); 190 } 191 192 const char* OptoRuntime::stub_name(address entry) { 193 #ifndef PRODUCT 194 CodeBlob* cb = CodeCache::find_blob(entry); 195 RuntimeStub* rs =(RuntimeStub *)cb; 196 assert(rs != nullptr && rs->is_runtime_stub(), "not a runtime stub"); 197 return rs->name(); 198 #else 199 // Fast implementation for product mode (maybe it should be inlined too) 200 return "runtime stub"; 201 #endif 202 } 203 204 205 //============================================================================= 206 // Opto compiler runtime routines 207 //============================================================================= 208 209 210 //=============================allocation====================================== 211 // We failed the fast-path allocation. Now we need to do a scavenge or GC 212 // and try allocation again. 213 214 // object allocation 215 JRT_BLOCK_ENTRY(void, OptoRuntime::new_instance_C(Klass* klass, JavaThread* current)) 216 JRT_BLOCK; 217 #ifndef PRODUCT 218 SharedRuntime::_new_instance_ctr++; // new instance requires GC 219 #endif 220 assert(check_compiled_frame(current), "incorrect caller"); 221 222 // These checks are cheap to make and support reflective allocation. 223 int lh = klass->layout_helper(); 224 if (Klass::layout_helper_needs_slow_path(lh) || !InstanceKlass::cast(klass)->is_initialized()) { 225 Handle holder(current, klass->klass_holder()); // keep the klass alive 226 klass->check_valid_for_instantiation(false, THREAD); 227 if (!HAS_PENDING_EXCEPTION) { 228 InstanceKlass::cast(klass)->initialize(THREAD); 229 } 230 } 231 232 if (!HAS_PENDING_EXCEPTION) { 233 // Scavenge and allocate an instance. 234 Handle holder(current, klass->klass_holder()); // keep the klass alive 235 oop result = InstanceKlass::cast(klass)->allocate_instance(THREAD); 236 current->set_vm_result(result); 237 238 // Pass oops back through thread local storage. Our apparent type to Java 239 // is that we return an oop, but we can block on exit from this routine and 240 // a GC can trash the oop in C's return register. The generated stub will 241 // fetch the oop from TLS after any possible GC. 242 } 243 244 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION); 245 JRT_BLOCK_END; 246 247 // inform GC that we won't do card marks for initializing writes. 248 SharedRuntime::on_slowpath_allocation_exit(current); 249 JRT_END 250 251 252 // array allocation 253 JRT_BLOCK_ENTRY(void, OptoRuntime::new_array_C(Klass* array_type, int len, JavaThread* current)) 254 JRT_BLOCK; 255 #ifndef PRODUCT 256 SharedRuntime::_new_array_ctr++; // new array requires GC 257 #endif 258 assert(check_compiled_frame(current), "incorrect caller"); 259 260 // Scavenge and allocate an instance. 261 oop result; 262 263 if (array_type->is_typeArray_klass()) { 264 // The oopFactory likes to work with the element type. 265 // (We could bypass the oopFactory, since it doesn't add much value.) 266 BasicType elem_type = TypeArrayKlass::cast(array_type)->element_type(); 267 result = oopFactory::new_typeArray(elem_type, len, THREAD); 268 } else { 269 // Although the oopFactory likes to work with the elem_type, 270 // the compiler prefers the array_type, since it must already have 271 // that latter value in hand for the fast path. 272 Handle holder(current, array_type->klass_holder()); // keep the array klass alive 273 Klass* elem_type = ObjArrayKlass::cast(array_type)->element_klass(); 274 result = oopFactory::new_objArray(elem_type, len, THREAD); 275 } 276 277 // Pass oops back through thread local storage. Our apparent type to Java 278 // is that we return an oop, but we can block on exit from this routine and 279 // a GC can trash the oop in C's return register. The generated stub will 280 // fetch the oop from TLS after any possible GC. 281 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION); 282 current->set_vm_result(result); 283 JRT_BLOCK_END; 284 285 // inform GC that we won't do card marks for initializing writes. 286 SharedRuntime::on_slowpath_allocation_exit(current); 287 JRT_END 288 289 // array allocation without zeroing 290 JRT_BLOCK_ENTRY(void, OptoRuntime::new_array_nozero_C(Klass* array_type, int len, JavaThread* current)) 291 JRT_BLOCK; 292 #ifndef PRODUCT 293 SharedRuntime::_new_array_ctr++; // new array requires GC 294 #endif 295 assert(check_compiled_frame(current), "incorrect caller"); 296 297 // Scavenge and allocate an instance. 298 oop result; 299 300 assert(array_type->is_typeArray_klass(), "should be called only for type array"); 301 // The oopFactory likes to work with the element type. 302 BasicType elem_type = TypeArrayKlass::cast(array_type)->element_type(); 303 result = oopFactory::new_typeArray_nozero(elem_type, len, THREAD); 304 305 // Pass oops back through thread local storage. Our apparent type to Java 306 // is that we return an oop, but we can block on exit from this routine and 307 // a GC can trash the oop in C's return register. The generated stub will 308 // fetch the oop from TLS after any possible GC. 309 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION); 310 current->set_vm_result(result); 311 JRT_BLOCK_END; 312 313 314 // inform GC that we won't do card marks for initializing writes. 315 SharedRuntime::on_slowpath_allocation_exit(current); 316 317 oop result = current->vm_result(); 318 if ((len > 0) && (result != nullptr) && 319 is_deoptimized_caller_frame(current)) { 320 // Zero array here if the caller is deoptimized. 321 const size_t size = TypeArrayKlass::cast(array_type)->oop_size(result); 322 BasicType elem_type = TypeArrayKlass::cast(array_type)->element_type(); 323 size_t hs_bytes = arrayOopDesc::base_offset_in_bytes(elem_type); 324 assert(is_aligned(hs_bytes, BytesPerInt), "must be 4 byte aligned"); 325 HeapWord* obj = cast_from_oop<HeapWord*>(result); 326 if (!is_aligned(hs_bytes, BytesPerLong)) { 327 *reinterpret_cast<jint*>(reinterpret_cast<char*>(obj) + hs_bytes) = 0; 328 hs_bytes += BytesPerInt; 329 } 330 331 // Optimized zeroing. 332 assert(is_aligned(hs_bytes, BytesPerLong), "must be 8-byte aligned"); 333 const size_t aligned_hs = hs_bytes / BytesPerLong; 334 Copy::fill_to_aligned_words(obj+aligned_hs, size-aligned_hs); 335 } 336 337 JRT_END 338 339 // Note: multianewarray for one dimension is handled inline by GraphKit::new_array. 340 341 // multianewarray for 2 dimensions 342 JRT_ENTRY(void, OptoRuntime::multianewarray2_C(Klass* elem_type, int len1, int len2, JavaThread* current)) 343 #ifndef PRODUCT 344 SharedRuntime::_multi2_ctr++; // multianewarray for 1 dimension 345 #endif 346 assert(check_compiled_frame(current), "incorrect caller"); 347 assert(elem_type->is_klass(), "not a class"); 348 jint dims[2]; 349 dims[0] = len1; 350 dims[1] = len2; 351 Handle holder(current, elem_type->klass_holder()); // keep the klass alive 352 oop obj = ArrayKlass::cast(elem_type)->multi_allocate(2, dims, THREAD); 353 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION); 354 current->set_vm_result(obj); 355 JRT_END 356 357 // multianewarray for 3 dimensions 358 JRT_ENTRY(void, OptoRuntime::multianewarray3_C(Klass* elem_type, int len1, int len2, int len3, JavaThread* current)) 359 #ifndef PRODUCT 360 SharedRuntime::_multi3_ctr++; // multianewarray for 1 dimension 361 #endif 362 assert(check_compiled_frame(current), "incorrect caller"); 363 assert(elem_type->is_klass(), "not a class"); 364 jint dims[3]; 365 dims[0] = len1; 366 dims[1] = len2; 367 dims[2] = len3; 368 Handle holder(current, elem_type->klass_holder()); // keep the klass alive 369 oop obj = ArrayKlass::cast(elem_type)->multi_allocate(3, dims, THREAD); 370 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION); 371 current->set_vm_result(obj); 372 JRT_END 373 374 // multianewarray for 4 dimensions 375 JRT_ENTRY(void, OptoRuntime::multianewarray4_C(Klass* elem_type, int len1, int len2, int len3, int len4, JavaThread* current)) 376 #ifndef PRODUCT 377 SharedRuntime::_multi4_ctr++; // multianewarray for 1 dimension 378 #endif 379 assert(check_compiled_frame(current), "incorrect caller"); 380 assert(elem_type->is_klass(), "not a class"); 381 jint dims[4]; 382 dims[0] = len1; 383 dims[1] = len2; 384 dims[2] = len3; 385 dims[3] = len4; 386 Handle holder(current, elem_type->klass_holder()); // keep the klass alive 387 oop obj = ArrayKlass::cast(elem_type)->multi_allocate(4, dims, THREAD); 388 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION); 389 current->set_vm_result(obj); 390 JRT_END 391 392 // multianewarray for 5 dimensions 393 JRT_ENTRY(void, OptoRuntime::multianewarray5_C(Klass* elem_type, int len1, int len2, int len3, int len4, int len5, JavaThread* current)) 394 #ifndef PRODUCT 395 SharedRuntime::_multi5_ctr++; // multianewarray for 1 dimension 396 #endif 397 assert(check_compiled_frame(current), "incorrect caller"); 398 assert(elem_type->is_klass(), "not a class"); 399 jint dims[5]; 400 dims[0] = len1; 401 dims[1] = len2; 402 dims[2] = len3; 403 dims[3] = len4; 404 dims[4] = len5; 405 Handle holder(current, elem_type->klass_holder()); // keep the klass alive 406 oop obj = ArrayKlass::cast(elem_type)->multi_allocate(5, dims, THREAD); 407 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION); 408 current->set_vm_result(obj); 409 JRT_END 410 411 JRT_ENTRY(void, OptoRuntime::multianewarrayN_C(Klass* elem_type, arrayOopDesc* dims, JavaThread* current)) 412 assert(check_compiled_frame(current), "incorrect caller"); 413 assert(elem_type->is_klass(), "not a class"); 414 assert(oop(dims)->is_typeArray(), "not an array"); 415 416 ResourceMark rm; 417 jint len = dims->length(); 418 assert(len > 0, "Dimensions array should contain data"); 419 jint *c_dims = NEW_RESOURCE_ARRAY(jint, len); 420 ArrayAccess<>::arraycopy_to_native<>(dims, typeArrayOopDesc::element_offset<jint>(0), 421 c_dims, len); 422 423 Handle holder(current, elem_type->klass_holder()); // keep the klass alive 424 oop obj = ArrayKlass::cast(elem_type)->multi_allocate(len, c_dims, THREAD); 425 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION); 426 current->set_vm_result(obj); 427 JRT_END 428 429 JRT_BLOCK_ENTRY(void, OptoRuntime::monitor_notify_C(oopDesc* obj, JavaThread* current)) 430 431 // Very few notify/notifyAll operations find any threads on the waitset, so 432 // the dominant fast-path is to simply return. 433 // Relatedly, it's critical that notify/notifyAll be fast in order to 434 // reduce lock hold times. 435 if (!SafepointSynchronize::is_synchronizing()) { 436 if (ObjectSynchronizer::quick_notify(obj, current, false)) { 437 return; 438 } 439 } 440 441 // This is the case the fast-path above isn't provisioned to handle. 442 // The fast-path is designed to handle frequently arising cases in an efficient manner. 443 // (The fast-path is just a degenerate variant of the slow-path). 444 // Perform the dreaded state transition and pass control into the slow-path. 445 JRT_BLOCK; 446 Handle h_obj(current, obj); 447 ObjectSynchronizer::notify(h_obj, CHECK); 448 JRT_BLOCK_END; 449 JRT_END 450 451 JRT_BLOCK_ENTRY(void, OptoRuntime::monitor_notifyAll_C(oopDesc* obj, JavaThread* current)) 452 453 if (!SafepointSynchronize::is_synchronizing() ) { 454 if (ObjectSynchronizer::quick_notify(obj, current, true)) { 455 return; 456 } 457 } 458 459 // This is the case the fast-path above isn't provisioned to handle. 460 // The fast-path is designed to handle frequently arising cases in an efficient manner. 461 // (The fast-path is just a degenerate variant of the slow-path). 462 // Perform the dreaded state transition and pass control into the slow-path. 463 JRT_BLOCK; 464 Handle h_obj(current, obj); 465 ObjectSynchronizer::notifyall(h_obj, CHECK); 466 JRT_BLOCK_END; 467 JRT_END 468 469 const TypeFunc *OptoRuntime::new_instance_Type() { 470 // create input type (domain) 471 const Type **fields = TypeTuple::fields(1); 472 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Klass to be allocated 473 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields); 474 475 // create result type (range) 476 fields = TypeTuple::fields(1); 477 fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL; // Returned oop 478 479 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields); 480 481 return TypeFunc::make(domain, range); 482 } 483 484 #if INCLUDE_JVMTI 485 const TypeFunc *OptoRuntime::notify_jvmti_vthread_Type() { 486 // create input type (domain) 487 const Type **fields = TypeTuple::fields(2); 488 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // VirtualThread oop 489 fields[TypeFunc::Parms+1] = TypeInt::BOOL; // jboolean 490 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields); 491 492 // no result type needed 493 fields = TypeTuple::fields(1); 494 fields[TypeFunc::Parms+0] = nullptr; // void 495 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields); 496 497 return TypeFunc::make(domain,range); 498 } 499 #endif 500 501 const TypeFunc *OptoRuntime::athrow_Type() { 502 // create input type (domain) 503 const Type **fields = TypeTuple::fields(1); 504 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Klass to be allocated 505 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields); 506 507 // create result type (range) 508 fields = TypeTuple::fields(0); 509 510 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields); 511 512 return TypeFunc::make(domain, range); 513 } 514 515 516 const TypeFunc *OptoRuntime::new_array_Type() { 517 // create input type (domain) 518 const Type **fields = TypeTuple::fields(2); 519 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // element klass 520 fields[TypeFunc::Parms+1] = TypeInt::INT; // array size 521 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields); 522 523 // create result type (range) 524 fields = TypeTuple::fields(1); 525 fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL; // Returned oop 526 527 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields); 528 529 return TypeFunc::make(domain, range); 530 } 531 532 const TypeFunc *OptoRuntime::multianewarray_Type(int ndim) { 533 // create input type (domain) 534 const int nargs = ndim + 1; 535 const Type **fields = TypeTuple::fields(nargs); 536 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // element klass 537 for( int i = 1; i < nargs; i++ ) 538 fields[TypeFunc::Parms + i] = TypeInt::INT; // array size 539 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+nargs, fields); 540 541 // create result type (range) 542 fields = TypeTuple::fields(1); 543 fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL; // Returned oop 544 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields); 545 546 return TypeFunc::make(domain, range); 547 } 548 549 const TypeFunc *OptoRuntime::multianewarray2_Type() { 550 return multianewarray_Type(2); 551 } 552 553 const TypeFunc *OptoRuntime::multianewarray3_Type() { 554 return multianewarray_Type(3); 555 } 556 557 const TypeFunc *OptoRuntime::multianewarray4_Type() { 558 return multianewarray_Type(4); 559 } 560 561 const TypeFunc *OptoRuntime::multianewarray5_Type() { 562 return multianewarray_Type(5); 563 } 564 565 const TypeFunc *OptoRuntime::multianewarrayN_Type() { 566 // create input type (domain) 567 const Type **fields = TypeTuple::fields(2); 568 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // element klass 569 fields[TypeFunc::Parms+1] = TypeInstPtr::NOTNULL; // array of dim sizes 570 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields); 571 572 // create result type (range) 573 fields = TypeTuple::fields(1); 574 fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL; // Returned oop 575 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields); 576 577 return TypeFunc::make(domain, range); 578 } 579 580 const TypeFunc *OptoRuntime::uncommon_trap_Type() { 581 // create input type (domain) 582 const Type **fields = TypeTuple::fields(1); 583 fields[TypeFunc::Parms+0] = TypeInt::INT; // trap_reason (deopt reason and action) 584 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields); 585 586 // create result type (range) 587 fields = TypeTuple::fields(0); 588 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields); 589 590 return TypeFunc::make(domain, range); 591 } 592 593 //----------------------------------------------------------------------------- 594 // Monitor Handling 595 const TypeFunc *OptoRuntime::complete_monitor_enter_Type() { 596 // create input type (domain) 597 const Type **fields = TypeTuple::fields(2); 598 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Object to be Locked 599 fields[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // Address of stack location for lock 600 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields); 601 602 // create result type (range) 603 fields = TypeTuple::fields(0); 604 605 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields); 606 607 return TypeFunc::make(domain,range); 608 } 609 610 611 //----------------------------------------------------------------------------- 612 const TypeFunc *OptoRuntime::complete_monitor_exit_Type() { 613 // create input type (domain) 614 const Type **fields = TypeTuple::fields(3); 615 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Object to be Locked 616 fields[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // Address of stack location for lock - BasicLock 617 fields[TypeFunc::Parms+2] = TypeRawPtr::BOTTOM; // Thread pointer (Self) 618 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+3, fields); 619 620 // create result type (range) 621 fields = TypeTuple::fields(0); 622 623 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields); 624 625 return TypeFunc::make(domain, range); 626 } 627 628 const TypeFunc *OptoRuntime::monitor_notify_Type() { 629 // create input type (domain) 630 const Type **fields = TypeTuple::fields(1); 631 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Object to be Locked 632 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields); 633 634 // create result type (range) 635 fields = TypeTuple::fields(0); 636 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields); 637 return TypeFunc::make(domain, range); 638 } 639 640 const TypeFunc* OptoRuntime::flush_windows_Type() { 641 // create input type (domain) 642 const Type** fields = TypeTuple::fields(1); 643 fields[TypeFunc::Parms+0] = nullptr; // void 644 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms, fields); 645 646 // create result type 647 fields = TypeTuple::fields(1); 648 fields[TypeFunc::Parms+0] = nullptr; // void 649 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms, fields); 650 651 return TypeFunc::make(domain, range); 652 } 653 654 const TypeFunc* OptoRuntime::l2f_Type() { 655 // create input type (domain) 656 const Type **fields = TypeTuple::fields(2); 657 fields[TypeFunc::Parms+0] = TypeLong::LONG; 658 fields[TypeFunc::Parms+1] = Type::HALF; 659 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields); 660 661 // create result type (range) 662 fields = TypeTuple::fields(1); 663 fields[TypeFunc::Parms+0] = Type::FLOAT; 664 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields); 665 666 return TypeFunc::make(domain, range); 667 } 668 669 const TypeFunc* OptoRuntime::modf_Type() { 670 const Type **fields = TypeTuple::fields(2); 671 fields[TypeFunc::Parms+0] = Type::FLOAT; 672 fields[TypeFunc::Parms+1] = Type::FLOAT; 673 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields); 674 675 // create result type (range) 676 fields = TypeTuple::fields(1); 677 fields[TypeFunc::Parms+0] = Type::FLOAT; 678 679 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields); 680 681 return TypeFunc::make(domain, range); 682 } 683 684 const TypeFunc *OptoRuntime::Math_D_D_Type() { 685 // create input type (domain) 686 const Type **fields = TypeTuple::fields(2); 687 // Symbol* name of class to be loaded 688 fields[TypeFunc::Parms+0] = Type::DOUBLE; 689 fields[TypeFunc::Parms+1] = Type::HALF; 690 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields); 691 692 // create result type (range) 693 fields = TypeTuple::fields(2); 694 fields[TypeFunc::Parms+0] = Type::DOUBLE; 695 fields[TypeFunc::Parms+1] = Type::HALF; 696 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+2, fields); 697 698 return TypeFunc::make(domain, range); 699 } 700 701 const TypeFunc *OptoRuntime::Math_Vector_Vector_Type(uint num_arg, const TypeVect* in_type, const TypeVect* out_type) { 702 // create input type (domain) 703 const Type **fields = TypeTuple::fields(num_arg); 704 // Symbol* name of class to be loaded 705 assert(num_arg > 0, "must have at least 1 input"); 706 for (uint i = 0; i < num_arg; i++) { 707 fields[TypeFunc::Parms+i] = in_type; 708 } 709 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+num_arg, fields); 710 711 // create result type (range) 712 const uint num_ret = 1; 713 fields = TypeTuple::fields(num_ret); 714 fields[TypeFunc::Parms+0] = out_type; 715 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+num_ret, fields); 716 717 return TypeFunc::make(domain, range); 718 } 719 720 const TypeFunc* OptoRuntime::Math_DD_D_Type() { 721 const Type **fields = TypeTuple::fields(4); 722 fields[TypeFunc::Parms+0] = Type::DOUBLE; 723 fields[TypeFunc::Parms+1] = Type::HALF; 724 fields[TypeFunc::Parms+2] = Type::DOUBLE; 725 fields[TypeFunc::Parms+3] = Type::HALF; 726 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+4, fields); 727 728 // create result type (range) 729 fields = TypeTuple::fields(2); 730 fields[TypeFunc::Parms+0] = Type::DOUBLE; 731 fields[TypeFunc::Parms+1] = Type::HALF; 732 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+2, fields); 733 734 return TypeFunc::make(domain, range); 735 } 736 737 //-------------- currentTimeMillis, currentTimeNanos, etc 738 739 const TypeFunc* OptoRuntime::void_long_Type() { 740 // create input type (domain) 741 const Type **fields = TypeTuple::fields(0); 742 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+0, fields); 743 744 // create result type (range) 745 fields = TypeTuple::fields(2); 746 fields[TypeFunc::Parms+0] = TypeLong::LONG; 747 fields[TypeFunc::Parms+1] = Type::HALF; 748 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+2, fields); 749 750 return TypeFunc::make(domain, range); 751 } 752 753 const TypeFunc* OptoRuntime::void_void_Type() { 754 // create input type (domain) 755 const Type **fields = TypeTuple::fields(0); 756 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+0, fields); 757 758 // create result type (range) 759 fields = TypeTuple::fields(0); 760 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields); 761 return TypeFunc::make(domain, range); 762 } 763 764 const TypeFunc* OptoRuntime::jfr_write_checkpoint_Type() { 765 // create input type (domain) 766 const Type **fields = TypeTuple::fields(0); 767 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms, fields); 768 769 // create result type (range) 770 fields = TypeTuple::fields(0); 771 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms, fields); 772 return TypeFunc::make(domain, range); 773 } 774 775 776 // arraycopy stub variations: 777 enum ArrayCopyType { 778 ac_fast, // void(ptr, ptr, size_t) 779 ac_checkcast, // int(ptr, ptr, size_t, size_t, ptr) 780 ac_slow, // void(ptr, int, ptr, int, int) 781 ac_generic // int(ptr, int, ptr, int, int) 782 }; 783 784 static const TypeFunc* make_arraycopy_Type(ArrayCopyType act) { 785 // create input type (domain) 786 int num_args = (act == ac_fast ? 3 : 5); 787 int num_size_args = (act == ac_fast ? 1 : act == ac_checkcast ? 2 : 0); 788 int argcnt = num_args; 789 LP64_ONLY(argcnt += num_size_args); // halfwords for lengths 790 const Type** fields = TypeTuple::fields(argcnt); 791 int argp = TypeFunc::Parms; 792 fields[argp++] = TypePtr::NOTNULL; // src 793 if (num_size_args == 0) { 794 fields[argp++] = TypeInt::INT; // src_pos 795 } 796 fields[argp++] = TypePtr::NOTNULL; // dest 797 if (num_size_args == 0) { 798 fields[argp++] = TypeInt::INT; // dest_pos 799 fields[argp++] = TypeInt::INT; // length 800 } 801 while (num_size_args-- > 0) { 802 fields[argp++] = TypeX_X; // size in whatevers (size_t) 803 LP64_ONLY(fields[argp++] = Type::HALF); // other half of long length 804 } 805 if (act == ac_checkcast) { 806 fields[argp++] = TypePtr::NOTNULL; // super_klass 807 } 808 assert(argp == TypeFunc::Parms+argcnt, "correct decoding of act"); 809 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields); 810 811 // create result type if needed 812 int retcnt = (act == ac_checkcast || act == ac_generic ? 1 : 0); 813 fields = TypeTuple::fields(1); 814 if (retcnt == 0) 815 fields[TypeFunc::Parms+0] = nullptr; // void 816 else 817 fields[TypeFunc::Parms+0] = TypeInt::INT; // status result, if needed 818 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+retcnt, fields); 819 return TypeFunc::make(domain, range); 820 } 821 822 const TypeFunc* OptoRuntime::fast_arraycopy_Type() { 823 // This signature is simple: Two base pointers and a size_t. 824 return make_arraycopy_Type(ac_fast); 825 } 826 827 const TypeFunc* OptoRuntime::checkcast_arraycopy_Type() { 828 // An extension of fast_arraycopy_Type which adds type checking. 829 return make_arraycopy_Type(ac_checkcast); 830 } 831 832 const TypeFunc* OptoRuntime::slow_arraycopy_Type() { 833 // This signature is exactly the same as System.arraycopy. 834 // There are no intptr_t (int/long) arguments. 835 return make_arraycopy_Type(ac_slow); 836 } 837 838 const TypeFunc* OptoRuntime::generic_arraycopy_Type() { 839 // This signature is like System.arraycopy, except that it returns status. 840 return make_arraycopy_Type(ac_generic); 841 } 842 843 844 const TypeFunc* OptoRuntime::array_fill_Type() { 845 const Type** fields; 846 int argp = TypeFunc::Parms; 847 // create input type (domain): pointer, int, size_t 848 fields = TypeTuple::fields(3 LP64_ONLY( + 1)); 849 fields[argp++] = TypePtr::NOTNULL; 850 fields[argp++] = TypeInt::INT; 851 fields[argp++] = TypeX_X; // size in whatevers (size_t) 852 LP64_ONLY(fields[argp++] = Type::HALF); // other half of long length 853 const TypeTuple *domain = TypeTuple::make(argp, fields); 854 855 // create result type 856 fields = TypeTuple::fields(1); 857 fields[TypeFunc::Parms+0] = nullptr; // void 858 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms, fields); 859 860 return TypeFunc::make(domain, range); 861 } 862 863 // for aescrypt encrypt/decrypt operations, just three pointers returning void (length is constant) 864 const TypeFunc* OptoRuntime::aescrypt_block_Type() { 865 // create input type (domain) 866 int num_args = 3; 867 int argcnt = num_args; 868 const Type** fields = TypeTuple::fields(argcnt); 869 int argp = TypeFunc::Parms; 870 fields[argp++] = TypePtr::NOTNULL; // src 871 fields[argp++] = TypePtr::NOTNULL; // dest 872 fields[argp++] = TypePtr::NOTNULL; // k array 873 assert(argp == TypeFunc::Parms+argcnt, "correct decoding"); 874 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields); 875 876 // no result type needed 877 fields = TypeTuple::fields(1); 878 fields[TypeFunc::Parms+0] = nullptr; // void 879 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields); 880 return TypeFunc::make(domain, range); 881 } 882 883 /** 884 * int updateBytesCRC32(int crc, byte* b, int len) 885 */ 886 const TypeFunc* OptoRuntime::updateBytesCRC32_Type() { 887 // create input type (domain) 888 int num_args = 3; 889 int argcnt = num_args; 890 const Type** fields = TypeTuple::fields(argcnt); 891 int argp = TypeFunc::Parms; 892 fields[argp++] = TypeInt::INT; // crc 893 fields[argp++] = TypePtr::NOTNULL; // src 894 fields[argp++] = TypeInt::INT; // len 895 assert(argp == TypeFunc::Parms+argcnt, "correct decoding"); 896 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields); 897 898 // result type needed 899 fields = TypeTuple::fields(1); 900 fields[TypeFunc::Parms+0] = TypeInt::INT; // crc result 901 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+1, fields); 902 return TypeFunc::make(domain, range); 903 } 904 905 /** 906 * int updateBytesCRC32C(int crc, byte* buf, int len, int* table) 907 */ 908 const TypeFunc* OptoRuntime::updateBytesCRC32C_Type() { 909 // create input type (domain) 910 int num_args = 4; 911 int argcnt = num_args; 912 const Type** fields = TypeTuple::fields(argcnt); 913 int argp = TypeFunc::Parms; 914 fields[argp++] = TypeInt::INT; // crc 915 fields[argp++] = TypePtr::NOTNULL; // buf 916 fields[argp++] = TypeInt::INT; // len 917 fields[argp++] = TypePtr::NOTNULL; // table 918 assert(argp == TypeFunc::Parms+argcnt, "correct decoding"); 919 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields); 920 921 // result type needed 922 fields = TypeTuple::fields(1); 923 fields[TypeFunc::Parms+0] = TypeInt::INT; // crc result 924 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+1, fields); 925 return TypeFunc::make(domain, range); 926 } 927 928 /** 929 * int updateBytesAdler32(int adler, bytes* b, int off, int len) 930 */ 931 const TypeFunc* OptoRuntime::updateBytesAdler32_Type() { 932 // create input type (domain) 933 int num_args = 3; 934 int argcnt = num_args; 935 const Type** fields = TypeTuple::fields(argcnt); 936 int argp = TypeFunc::Parms; 937 fields[argp++] = TypeInt::INT; // crc 938 fields[argp++] = TypePtr::NOTNULL; // src + offset 939 fields[argp++] = TypeInt::INT; // len 940 assert(argp == TypeFunc::Parms+argcnt, "correct decoding"); 941 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields); 942 943 // result type needed 944 fields = TypeTuple::fields(1); 945 fields[TypeFunc::Parms+0] = TypeInt::INT; // crc result 946 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+1, fields); 947 return TypeFunc::make(domain, range); 948 } 949 950 // for cipherBlockChaining calls of aescrypt encrypt/decrypt, four pointers and a length, returning int 951 const TypeFunc* OptoRuntime::cipherBlockChaining_aescrypt_Type() { 952 // create input type (domain) 953 int num_args = 5; 954 int argcnt = num_args; 955 const Type** fields = TypeTuple::fields(argcnt); 956 int argp = TypeFunc::Parms; 957 fields[argp++] = TypePtr::NOTNULL; // src 958 fields[argp++] = TypePtr::NOTNULL; // dest 959 fields[argp++] = TypePtr::NOTNULL; // k array 960 fields[argp++] = TypePtr::NOTNULL; // r array 961 fields[argp++] = TypeInt::INT; // src len 962 assert(argp == TypeFunc::Parms+argcnt, "correct decoding"); 963 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields); 964 965 // returning cipher len (int) 966 fields = TypeTuple::fields(1); 967 fields[TypeFunc::Parms+0] = TypeInt::INT; 968 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+1, fields); 969 return TypeFunc::make(domain, range); 970 } 971 972 // for electronicCodeBook calls of aescrypt encrypt/decrypt, three pointers and a length, returning int 973 const TypeFunc* OptoRuntime::electronicCodeBook_aescrypt_Type() { 974 // create input type (domain) 975 int num_args = 4; 976 int argcnt = num_args; 977 const Type** fields = TypeTuple::fields(argcnt); 978 int argp = TypeFunc::Parms; 979 fields[argp++] = TypePtr::NOTNULL; // src 980 fields[argp++] = TypePtr::NOTNULL; // dest 981 fields[argp++] = TypePtr::NOTNULL; // k array 982 fields[argp++] = TypeInt::INT; // src len 983 assert(argp == TypeFunc::Parms + argcnt, "correct decoding"); 984 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + argcnt, fields); 985 986 // returning cipher len (int) 987 fields = TypeTuple::fields(1); 988 fields[TypeFunc::Parms + 0] = TypeInt::INT; 989 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms + 1, fields); 990 return TypeFunc::make(domain, range); 991 } 992 993 //for counterMode calls of aescrypt encrypt/decrypt, four pointers and a length, returning int 994 const TypeFunc* OptoRuntime::counterMode_aescrypt_Type() { 995 // create input type (domain) 996 int num_args = 7; 997 int argcnt = num_args; 998 const Type** fields = TypeTuple::fields(argcnt); 999 int argp = TypeFunc::Parms; 1000 fields[argp++] = TypePtr::NOTNULL; // src 1001 fields[argp++] = TypePtr::NOTNULL; // dest 1002 fields[argp++] = TypePtr::NOTNULL; // k array 1003 fields[argp++] = TypePtr::NOTNULL; // counter array 1004 fields[argp++] = TypeInt::INT; // src len 1005 fields[argp++] = TypePtr::NOTNULL; // saved_encCounter 1006 fields[argp++] = TypePtr::NOTNULL; // saved used addr 1007 assert(argp == TypeFunc::Parms + argcnt, "correct decoding"); 1008 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + argcnt, fields); 1009 // returning cipher len (int) 1010 fields = TypeTuple::fields(1); 1011 fields[TypeFunc::Parms + 0] = TypeInt::INT; 1012 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms + 1, fields); 1013 return TypeFunc::make(domain, range); 1014 } 1015 1016 //for counterMode calls of aescrypt encrypt/decrypt, four pointers and a length, returning int 1017 const TypeFunc* OptoRuntime::galoisCounterMode_aescrypt_Type() { 1018 // create input type (domain) 1019 int num_args = 8; 1020 int argcnt = num_args; 1021 const Type** fields = TypeTuple::fields(argcnt); 1022 int argp = TypeFunc::Parms; 1023 fields[argp++] = TypePtr::NOTNULL; // byte[] in + inOfs 1024 fields[argp++] = TypeInt::INT; // int len 1025 fields[argp++] = TypePtr::NOTNULL; // byte[] ct + ctOfs 1026 fields[argp++] = TypePtr::NOTNULL; // byte[] out + outOfs 1027 fields[argp++] = TypePtr::NOTNULL; // byte[] key from AESCrypt obj 1028 fields[argp++] = TypePtr::NOTNULL; // long[] state from GHASH obj 1029 fields[argp++] = TypePtr::NOTNULL; // long[] subkeyHtbl from GHASH obj 1030 fields[argp++] = TypePtr::NOTNULL; // byte[] counter from GCTR obj 1031 1032 assert(argp == TypeFunc::Parms + argcnt, "correct decoding"); 1033 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + argcnt, fields); 1034 // returning cipher len (int) 1035 fields = TypeTuple::fields(1); 1036 fields[TypeFunc::Parms + 0] = TypeInt::INT; 1037 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms + 1, fields); 1038 return TypeFunc::make(domain, range); 1039 } 1040 1041 /* 1042 * void implCompress(byte[] buf, int ofs) 1043 */ 1044 const TypeFunc* OptoRuntime::digestBase_implCompress_Type(bool is_sha3) { 1045 // create input type (domain) 1046 int num_args = is_sha3 ? 3 : 2; 1047 int argcnt = num_args; 1048 const Type** fields = TypeTuple::fields(argcnt); 1049 int argp = TypeFunc::Parms; 1050 fields[argp++] = TypePtr::NOTNULL; // buf 1051 fields[argp++] = TypePtr::NOTNULL; // state 1052 if (is_sha3) fields[argp++] = TypeInt::INT; // block_size 1053 assert(argp == TypeFunc::Parms+argcnt, "correct decoding"); 1054 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields); 1055 1056 // no result type needed 1057 fields = TypeTuple::fields(1); 1058 fields[TypeFunc::Parms+0] = nullptr; // void 1059 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields); 1060 return TypeFunc::make(domain, range); 1061 } 1062 1063 /* 1064 * int implCompressMultiBlock(byte[] b, int ofs, int limit) 1065 */ 1066 const TypeFunc* OptoRuntime::digestBase_implCompressMB_Type(bool is_sha3) { 1067 // create input type (domain) 1068 int num_args = is_sha3 ? 5 : 4; 1069 int argcnt = num_args; 1070 const Type** fields = TypeTuple::fields(argcnt); 1071 int argp = TypeFunc::Parms; 1072 fields[argp++] = TypePtr::NOTNULL; // buf 1073 fields[argp++] = TypePtr::NOTNULL; // state 1074 if (is_sha3) fields[argp++] = TypeInt::INT; // block_size 1075 fields[argp++] = TypeInt::INT; // ofs 1076 fields[argp++] = TypeInt::INT; // limit 1077 assert(argp == TypeFunc::Parms+argcnt, "correct decoding"); 1078 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields); 1079 1080 // returning ofs (int) 1081 fields = TypeTuple::fields(1); 1082 fields[TypeFunc::Parms+0] = TypeInt::INT; // ofs 1083 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+1, fields); 1084 return TypeFunc::make(domain, range); 1085 } 1086 1087 const TypeFunc* OptoRuntime::multiplyToLen_Type() { 1088 // create input type (domain) 1089 int num_args = 6; 1090 int argcnt = num_args; 1091 const Type** fields = TypeTuple::fields(argcnt); 1092 int argp = TypeFunc::Parms; 1093 fields[argp++] = TypePtr::NOTNULL; // x 1094 fields[argp++] = TypeInt::INT; // xlen 1095 fields[argp++] = TypePtr::NOTNULL; // y 1096 fields[argp++] = TypeInt::INT; // ylen 1097 fields[argp++] = TypePtr::NOTNULL; // z 1098 fields[argp++] = TypeInt::INT; // zlen 1099 assert(argp == TypeFunc::Parms+argcnt, "correct decoding"); 1100 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields); 1101 1102 // no result type needed 1103 fields = TypeTuple::fields(1); 1104 fields[TypeFunc::Parms+0] = nullptr; 1105 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields); 1106 return TypeFunc::make(domain, range); 1107 } 1108 1109 const TypeFunc* OptoRuntime::squareToLen_Type() { 1110 // create input type (domain) 1111 int num_args = 4; 1112 int argcnt = num_args; 1113 const Type** fields = TypeTuple::fields(argcnt); 1114 int argp = TypeFunc::Parms; 1115 fields[argp++] = TypePtr::NOTNULL; // x 1116 fields[argp++] = TypeInt::INT; // len 1117 fields[argp++] = TypePtr::NOTNULL; // z 1118 fields[argp++] = TypeInt::INT; // zlen 1119 assert(argp == TypeFunc::Parms+argcnt, "correct decoding"); 1120 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields); 1121 1122 // no result type needed 1123 fields = TypeTuple::fields(1); 1124 fields[TypeFunc::Parms+0] = nullptr; 1125 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields); 1126 return TypeFunc::make(domain, range); 1127 } 1128 1129 // for mulAdd calls, 2 pointers and 3 ints, returning int 1130 const TypeFunc* OptoRuntime::mulAdd_Type() { 1131 // create input type (domain) 1132 int num_args = 5; 1133 int argcnt = num_args; 1134 const Type** fields = TypeTuple::fields(argcnt); 1135 int argp = TypeFunc::Parms; 1136 fields[argp++] = TypePtr::NOTNULL; // out 1137 fields[argp++] = TypePtr::NOTNULL; // in 1138 fields[argp++] = TypeInt::INT; // offset 1139 fields[argp++] = TypeInt::INT; // len 1140 fields[argp++] = TypeInt::INT; // k 1141 assert(argp == TypeFunc::Parms+argcnt, "correct decoding"); 1142 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields); 1143 1144 // returning carry (int) 1145 fields = TypeTuple::fields(1); 1146 fields[TypeFunc::Parms+0] = TypeInt::INT; 1147 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+1, fields); 1148 return TypeFunc::make(domain, range); 1149 } 1150 1151 const TypeFunc* OptoRuntime::montgomeryMultiply_Type() { 1152 // create input type (domain) 1153 int num_args = 7; 1154 int argcnt = num_args; 1155 const Type** fields = TypeTuple::fields(argcnt); 1156 int argp = TypeFunc::Parms; 1157 fields[argp++] = TypePtr::NOTNULL; // a 1158 fields[argp++] = TypePtr::NOTNULL; // b 1159 fields[argp++] = TypePtr::NOTNULL; // n 1160 fields[argp++] = TypeInt::INT; // len 1161 fields[argp++] = TypeLong::LONG; // inv 1162 fields[argp++] = Type::HALF; 1163 fields[argp++] = TypePtr::NOTNULL; // result 1164 assert(argp == TypeFunc::Parms+argcnt, "correct decoding"); 1165 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields); 1166 1167 // result type needed 1168 fields = TypeTuple::fields(1); 1169 fields[TypeFunc::Parms+0] = TypePtr::NOTNULL; 1170 1171 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields); 1172 return TypeFunc::make(domain, range); 1173 } 1174 1175 const TypeFunc* OptoRuntime::montgomerySquare_Type() { 1176 // create input type (domain) 1177 int num_args = 6; 1178 int argcnt = num_args; 1179 const Type** fields = TypeTuple::fields(argcnt); 1180 int argp = TypeFunc::Parms; 1181 fields[argp++] = TypePtr::NOTNULL; // a 1182 fields[argp++] = TypePtr::NOTNULL; // n 1183 fields[argp++] = TypeInt::INT; // len 1184 fields[argp++] = TypeLong::LONG; // inv 1185 fields[argp++] = Type::HALF; 1186 fields[argp++] = TypePtr::NOTNULL; // result 1187 assert(argp == TypeFunc::Parms+argcnt, "correct decoding"); 1188 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields); 1189 1190 // result type needed 1191 fields = TypeTuple::fields(1); 1192 fields[TypeFunc::Parms+0] = TypePtr::NOTNULL; 1193 1194 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields); 1195 return TypeFunc::make(domain, range); 1196 } 1197 1198 const TypeFunc * OptoRuntime::bigIntegerShift_Type() { 1199 int argcnt = 5; 1200 const Type** fields = TypeTuple::fields(argcnt); 1201 int argp = TypeFunc::Parms; 1202 fields[argp++] = TypePtr::NOTNULL; // newArr 1203 fields[argp++] = TypePtr::NOTNULL; // oldArr 1204 fields[argp++] = TypeInt::INT; // newIdx 1205 fields[argp++] = TypeInt::INT; // shiftCount 1206 fields[argp++] = TypeInt::INT; // numIter 1207 assert(argp == TypeFunc::Parms + argcnt, "correct decoding"); 1208 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + argcnt, fields); 1209 1210 // no result type needed 1211 fields = TypeTuple::fields(1); 1212 fields[TypeFunc::Parms + 0] = nullptr; 1213 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields); 1214 return TypeFunc::make(domain, range); 1215 } 1216 1217 const TypeFunc* OptoRuntime::vectorizedMismatch_Type() { 1218 // create input type (domain) 1219 int num_args = 4; 1220 int argcnt = num_args; 1221 const Type** fields = TypeTuple::fields(argcnt); 1222 int argp = TypeFunc::Parms; 1223 fields[argp++] = TypePtr::NOTNULL; // obja 1224 fields[argp++] = TypePtr::NOTNULL; // objb 1225 fields[argp++] = TypeInt::INT; // length, number of elements 1226 fields[argp++] = TypeInt::INT; // log2scale, element size 1227 assert(argp == TypeFunc::Parms + argcnt, "correct decoding"); 1228 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + argcnt, fields); 1229 1230 //return mismatch index (int) 1231 fields = TypeTuple::fields(1); 1232 fields[TypeFunc::Parms + 0] = TypeInt::INT; 1233 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms + 1, fields); 1234 return TypeFunc::make(domain, range); 1235 } 1236 1237 // GHASH block processing 1238 const TypeFunc* OptoRuntime::ghash_processBlocks_Type() { 1239 int argcnt = 4; 1240 1241 const Type** fields = TypeTuple::fields(argcnt); 1242 int argp = TypeFunc::Parms; 1243 fields[argp++] = TypePtr::NOTNULL; // state 1244 fields[argp++] = TypePtr::NOTNULL; // subkeyH 1245 fields[argp++] = TypePtr::NOTNULL; // data 1246 fields[argp++] = TypeInt::INT; // blocks 1247 assert(argp == TypeFunc::Parms+argcnt, "correct decoding"); 1248 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields); 1249 1250 // result type needed 1251 fields = TypeTuple::fields(1); 1252 fields[TypeFunc::Parms+0] = nullptr; // void 1253 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields); 1254 return TypeFunc::make(domain, range); 1255 } 1256 1257 // ChaCha20 Block function 1258 const TypeFunc* OptoRuntime::chacha20Block_Type() { 1259 int argcnt = 2; 1260 1261 const Type** fields = TypeTuple::fields(argcnt); 1262 int argp = TypeFunc::Parms; 1263 fields[argp++] = TypePtr::NOTNULL; // state 1264 fields[argp++] = TypePtr::NOTNULL; // result 1265 1266 assert(argp == TypeFunc::Parms + argcnt, "correct decoding"); 1267 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + argcnt, fields); 1268 1269 // result type needed 1270 fields = TypeTuple::fields(1); 1271 fields[TypeFunc::Parms + 0] = TypeInt::INT; // key stream outlen as int 1272 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms + 1, fields); 1273 return TypeFunc::make(domain, range); 1274 } 1275 1276 // Base64 encode function 1277 const TypeFunc* OptoRuntime::base64_encodeBlock_Type() { 1278 int argcnt = 6; 1279 1280 const Type** fields = TypeTuple::fields(argcnt); 1281 int argp = TypeFunc::Parms; 1282 fields[argp++] = TypePtr::NOTNULL; // src array 1283 fields[argp++] = TypeInt::INT; // offset 1284 fields[argp++] = TypeInt::INT; // length 1285 fields[argp++] = TypePtr::NOTNULL; // dest array 1286 fields[argp++] = TypeInt::INT; // dp 1287 fields[argp++] = TypeInt::BOOL; // isURL 1288 assert(argp == TypeFunc::Parms + argcnt, "correct decoding"); 1289 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields); 1290 1291 // result type needed 1292 fields = TypeTuple::fields(1); 1293 fields[TypeFunc::Parms + 0] = nullptr; // void 1294 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields); 1295 return TypeFunc::make(domain, range); 1296 } 1297 // Base64 decode function 1298 const TypeFunc* OptoRuntime::base64_decodeBlock_Type() { 1299 int argcnt = 7; 1300 1301 const Type** fields = TypeTuple::fields(argcnt); 1302 int argp = TypeFunc::Parms; 1303 fields[argp++] = TypePtr::NOTNULL; // src array 1304 fields[argp++] = TypeInt::INT; // src offset 1305 fields[argp++] = TypeInt::INT; // src length 1306 fields[argp++] = TypePtr::NOTNULL; // dest array 1307 fields[argp++] = TypeInt::INT; // dest offset 1308 fields[argp++] = TypeInt::BOOL; // isURL 1309 fields[argp++] = TypeInt::BOOL; // isMIME 1310 assert(argp == TypeFunc::Parms + argcnt, "correct decoding"); 1311 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields); 1312 1313 // result type needed 1314 fields = TypeTuple::fields(1); 1315 fields[TypeFunc::Parms + 0] = TypeInt::INT; // count of bytes written to dst 1316 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms + 1, fields); 1317 return TypeFunc::make(domain, range); 1318 } 1319 1320 // Poly1305 processMultipleBlocks function 1321 const TypeFunc* OptoRuntime::poly1305_processBlocks_Type() { 1322 int argcnt = 4; 1323 1324 const Type** fields = TypeTuple::fields(argcnt); 1325 int argp = TypeFunc::Parms; 1326 fields[argp++] = TypePtr::NOTNULL; // input array 1327 fields[argp++] = TypeInt::INT; // input length 1328 fields[argp++] = TypePtr::NOTNULL; // accumulator array 1329 fields[argp++] = TypePtr::NOTNULL; // r array 1330 assert(argp == TypeFunc::Parms + argcnt, "correct decoding"); 1331 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields); 1332 1333 // result type needed 1334 fields = TypeTuple::fields(1); 1335 fields[TypeFunc::Parms + 0] = nullptr; // void 1336 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields); 1337 return TypeFunc::make(domain, range); 1338 } 1339 1340 //------------- Interpreter state access for on stack replacement 1341 const TypeFunc* OptoRuntime::osr_end_Type() { 1342 // create input type (domain) 1343 const Type **fields = TypeTuple::fields(1); 1344 fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // OSR temp buf 1345 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields); 1346 1347 // create result type 1348 fields = TypeTuple::fields(1); 1349 // fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // locked oop 1350 fields[TypeFunc::Parms+0] = nullptr; // void 1351 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms, fields); 1352 return TypeFunc::make(domain, range); 1353 } 1354 1355 //------------------------------------------------------------------------------------- 1356 // register policy 1357 1358 bool OptoRuntime::is_callee_saved_register(MachRegisterNumbers reg) { 1359 assert(reg >= 0 && reg < _last_Mach_Reg, "must be a machine register"); 1360 switch (register_save_policy[reg]) { 1361 case 'C': return false; //SOC 1362 case 'E': return true ; //SOE 1363 case 'N': return false; //NS 1364 case 'A': return false; //AS 1365 } 1366 ShouldNotReachHere(); 1367 return false; 1368 } 1369 1370 //----------------------------------------------------------------------- 1371 // Exceptions 1372 // 1373 1374 static void trace_exception(outputStream* st, oop exception_oop, address exception_pc, const char* msg); 1375 1376 // The method is an entry that is always called by a C++ method not 1377 // directly from compiled code. Compiled code will call the C++ method following. 1378 // We can't allow async exception to be installed during exception processing. 1379 JRT_ENTRY_NO_ASYNC(address, OptoRuntime::handle_exception_C_helper(JavaThread* current, nmethod* &nm)) 1380 // The frame we rethrow the exception to might not have been processed by the GC yet. 1381 // The stack watermark barrier takes care of detecting that and ensuring the frame 1382 // has updated oops. 1383 StackWatermarkSet::after_unwind(current); 1384 1385 // Do not confuse exception_oop with pending_exception. The exception_oop 1386 // is only used to pass arguments into the method. Not for general 1387 // exception handling. DO NOT CHANGE IT to use pending_exception, since 1388 // the runtime stubs checks this on exit. 1389 assert(current->exception_oop() != nullptr, "exception oop is found"); 1390 address handler_address = nullptr; 1391 1392 Handle exception(current, current->exception_oop()); 1393 address pc = current->exception_pc(); 1394 1395 // Clear out the exception oop and pc since looking up an 1396 // exception handler can cause class loading, which might throw an 1397 // exception and those fields are expected to be clear during 1398 // normal bytecode execution. 1399 current->clear_exception_oop_and_pc(); 1400 1401 LogTarget(Info, exceptions) lt; 1402 if (lt.is_enabled()) { 1403 ResourceMark rm; 1404 LogStream ls(lt); 1405 trace_exception(&ls, exception(), pc, ""); 1406 } 1407 1408 // for AbortVMOnException flag 1409 Exceptions::debug_check_abort(exception); 1410 1411 #ifdef ASSERT 1412 if (!(exception->is_a(vmClasses::Throwable_klass()))) { 1413 // should throw an exception here 1414 ShouldNotReachHere(); 1415 } 1416 #endif 1417 1418 // new exception handling: this method is entered only from adapters 1419 // exceptions from compiled java methods are handled in compiled code 1420 // using rethrow node 1421 1422 nm = CodeCache::find_nmethod(pc); 1423 assert(nm != nullptr, "No NMethod found"); 1424 if (nm->is_native_method()) { 1425 fatal("Native method should not have path to exception handling"); 1426 } else { 1427 // we are switching to old paradigm: search for exception handler in caller_frame 1428 // instead in exception handler of caller_frame.sender() 1429 1430 if (JvmtiExport::can_post_on_exceptions()) { 1431 // "Full-speed catching" is not necessary here, 1432 // since we're notifying the VM on every catch. 1433 // Force deoptimization and the rest of the lookup 1434 // will be fine. 1435 deoptimize_caller_frame(current); 1436 } 1437 1438 // Check the stack guard pages. If enabled, look for handler in this frame; 1439 // otherwise, forcibly unwind the frame. 1440 // 1441 // 4826555: use default current sp for reguard_stack instead of &nm: it's more accurate. 1442 bool force_unwind = !current->stack_overflow_state()->reguard_stack(); 1443 bool deopting = false; 1444 if (nm->is_deopt_pc(pc)) { 1445 deopting = true; 1446 RegisterMap map(current, 1447 RegisterMap::UpdateMap::skip, 1448 RegisterMap::ProcessFrames::include, 1449 RegisterMap::WalkContinuation::skip); 1450 frame deoptee = current->last_frame().sender(&map); 1451 assert(deoptee.is_deoptimized_frame(), "must be deopted"); 1452 // Adjust the pc back to the original throwing pc 1453 pc = deoptee.pc(); 1454 } 1455 1456 // If we are forcing an unwind because of stack overflow then deopt is 1457 // irrelevant since we are throwing the frame away anyway. 1458 1459 if (deopting && !force_unwind) { 1460 handler_address = SharedRuntime::deopt_blob()->unpack_with_exception(); 1461 } else { 1462 1463 handler_address = 1464 force_unwind ? nullptr : nm->handler_for_exception_and_pc(exception, pc); 1465 1466 if (handler_address == nullptr) { 1467 bool recursive_exception = false; 1468 handler_address = SharedRuntime::compute_compiled_exc_handler(nm, pc, exception, force_unwind, true, recursive_exception); 1469 assert (handler_address != nullptr, "must have compiled handler"); 1470 // Update the exception cache only when the unwind was not forced 1471 // and there didn't happen another exception during the computation of the 1472 // compiled exception handler. Checking for exception oop equality is not 1473 // sufficient because some exceptions are pre-allocated and reused. 1474 if (!force_unwind && !recursive_exception) { 1475 nm->add_handler_for_exception_and_pc(exception,pc,handler_address); 1476 } 1477 } else { 1478 #ifdef ASSERT 1479 bool recursive_exception = false; 1480 address computed_address = SharedRuntime::compute_compiled_exc_handler(nm, pc, exception, force_unwind, true, recursive_exception); 1481 vmassert(recursive_exception || (handler_address == computed_address), "Handler address inconsistency: " PTR_FORMAT " != " PTR_FORMAT, 1482 p2i(handler_address), p2i(computed_address)); 1483 #endif 1484 } 1485 } 1486 1487 current->set_exception_pc(pc); 1488 current->set_exception_handler_pc(handler_address); 1489 1490 // Check if the exception PC is a MethodHandle call site. 1491 current->set_is_method_handle_return(nm->is_method_handle_return(pc)); 1492 } 1493 1494 // Restore correct return pc. Was saved above. 1495 current->set_exception_oop(exception()); 1496 return handler_address; 1497 1498 JRT_END 1499 1500 // We are entering here from exception_blob 1501 // If there is a compiled exception handler in this method, we will continue there; 1502 // otherwise we will unwind the stack and continue at the caller of top frame method 1503 // Note we enter without the usual JRT wrapper. We will call a helper routine that 1504 // will do the normal VM entry. We do it this way so that we can see if the nmethod 1505 // we looked up the handler for has been deoptimized in the meantime. If it has been 1506 // we must not use the handler and instead return the deopt blob. 1507 address OptoRuntime::handle_exception_C(JavaThread* current) { 1508 // 1509 // We are in Java not VM and in debug mode we have a NoHandleMark 1510 // 1511 #ifndef PRODUCT 1512 SharedRuntime::_find_handler_ctr++; // find exception handler 1513 #endif 1514 debug_only(NoHandleMark __hm;) 1515 nmethod* nm = nullptr; 1516 address handler_address = nullptr; 1517 { 1518 // Enter the VM 1519 1520 ResetNoHandleMark rnhm; 1521 handler_address = handle_exception_C_helper(current, nm); 1522 } 1523 1524 // Back in java: Use no oops, DON'T safepoint 1525 1526 // Now check to see if the handler we are returning is in a now 1527 // deoptimized frame 1528 1529 if (nm != nullptr) { 1530 RegisterMap map(current, 1531 RegisterMap::UpdateMap::skip, 1532 RegisterMap::ProcessFrames::skip, 1533 RegisterMap::WalkContinuation::skip); 1534 frame caller = current->last_frame().sender(&map); 1535 #ifdef ASSERT 1536 assert(caller.is_compiled_frame(), "must be"); 1537 #endif // ASSERT 1538 if (caller.is_deoptimized_frame()) { 1539 handler_address = SharedRuntime::deopt_blob()->unpack_with_exception(); 1540 } 1541 } 1542 return handler_address; 1543 } 1544 1545 //------------------------------rethrow---------------------------------------- 1546 // We get here after compiled code has executed a 'RethrowNode'. The callee 1547 // is either throwing or rethrowing an exception. The callee-save registers 1548 // have been restored, synchronized objects have been unlocked and the callee 1549 // stack frame has been removed. The return address was passed in. 1550 // Exception oop is passed as the 1st argument. This routine is then called 1551 // from the stub. On exit, we know where to jump in the caller's code. 1552 // After this C code exits, the stub will pop his frame and end in a jump 1553 // (instead of a return). We enter the caller's default handler. 1554 // 1555 // This must be JRT_LEAF: 1556 // - caller will not change its state as we cannot block on exit, 1557 // therefore raw_exception_handler_for_return_address is all it takes 1558 // to handle deoptimized blobs 1559 // 1560 // However, there needs to be a safepoint check in the middle! So compiled 1561 // safepoints are completely watertight. 1562 // 1563 // Thus, it cannot be a leaf since it contains the NoSafepointVerifier. 1564 // 1565 // *THIS IS NOT RECOMMENDED PROGRAMMING STYLE* 1566 // 1567 address OptoRuntime::rethrow_C(oopDesc* exception, JavaThread* thread, address ret_pc) { 1568 // ret_pc will have been loaded from the stack, so for AArch64 will be signed. 1569 AARCH64_PORT_ONLY(ret_pc = pauth_strip_verifiable(ret_pc)); 1570 1571 #ifndef PRODUCT 1572 SharedRuntime::_rethrow_ctr++; // count rethrows 1573 #endif 1574 assert (exception != nullptr, "should have thrown a NullPointerException"); 1575 #ifdef ASSERT 1576 if (!(exception->is_a(vmClasses::Throwable_klass()))) { 1577 // should throw an exception here 1578 ShouldNotReachHere(); 1579 } 1580 #endif 1581 1582 thread->set_vm_result(exception); 1583 // Frame not compiled (handles deoptimization blob) 1584 return SharedRuntime::raw_exception_handler_for_return_address(thread, ret_pc); 1585 } 1586 1587 1588 const TypeFunc *OptoRuntime::rethrow_Type() { 1589 // create input type (domain) 1590 const Type **fields = TypeTuple::fields(1); 1591 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Exception oop 1592 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1,fields); 1593 1594 // create result type (range) 1595 fields = TypeTuple::fields(1); 1596 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Exception oop 1597 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields); 1598 1599 return TypeFunc::make(domain, range); 1600 } 1601 1602 1603 void OptoRuntime::deoptimize_caller_frame(JavaThread *thread, bool doit) { 1604 // Deoptimize the caller before continuing, as the compiled 1605 // exception handler table may not be valid. 1606 if (!StressCompiledExceptionHandlers && doit) { 1607 deoptimize_caller_frame(thread); 1608 } 1609 } 1610 1611 void OptoRuntime::deoptimize_caller_frame(JavaThread *thread) { 1612 // Called from within the owner thread, so no need for safepoint 1613 RegisterMap reg_map(thread, 1614 RegisterMap::UpdateMap::include, 1615 RegisterMap::ProcessFrames::include, 1616 RegisterMap::WalkContinuation::skip); 1617 frame stub_frame = thread->last_frame(); 1618 assert(stub_frame.is_runtime_frame() || exception_blob()->contains(stub_frame.pc()), "sanity check"); 1619 frame caller_frame = stub_frame.sender(®_map); 1620 1621 // Deoptimize the caller frame. 1622 Deoptimization::deoptimize_frame(thread, caller_frame.id()); 1623 } 1624 1625 1626 bool OptoRuntime::is_deoptimized_caller_frame(JavaThread *thread) { 1627 // Called from within the owner thread, so no need for safepoint 1628 RegisterMap reg_map(thread, 1629 RegisterMap::UpdateMap::include, 1630 RegisterMap::ProcessFrames::include, 1631 RegisterMap::WalkContinuation::skip); 1632 frame stub_frame = thread->last_frame(); 1633 assert(stub_frame.is_runtime_frame() || exception_blob()->contains(stub_frame.pc()), "sanity check"); 1634 frame caller_frame = stub_frame.sender(®_map); 1635 return caller_frame.is_deoptimized_frame(); 1636 } 1637 1638 1639 const TypeFunc *OptoRuntime::register_finalizer_Type() { 1640 // create input type (domain) 1641 const Type **fields = TypeTuple::fields(1); 1642 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // oop; Receiver 1643 // // The JavaThread* is passed to each routine as the last argument 1644 // fields[TypeFunc::Parms+1] = TypeRawPtr::NOTNULL; // JavaThread *; Executing thread 1645 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1,fields); 1646 1647 // create result type (range) 1648 fields = TypeTuple::fields(0); 1649 1650 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields); 1651 1652 return TypeFunc::make(domain,range); 1653 } 1654 1655 #if INCLUDE_JFR 1656 const TypeFunc *OptoRuntime::class_id_load_barrier_Type() { 1657 // create input type (domain) 1658 const Type **fields = TypeTuple::fields(1); 1659 fields[TypeFunc::Parms+0] = TypeInstPtr::KLASS; 1660 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms + 1, fields); 1661 1662 // create result type (range) 1663 fields = TypeTuple::fields(0); 1664 1665 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms + 0, fields); 1666 1667 return TypeFunc::make(domain,range); 1668 } 1669 #endif 1670 1671 //----------------------------------------------------------------------------- 1672 // Dtrace support. entry and exit probes have the same signature 1673 const TypeFunc *OptoRuntime::dtrace_method_entry_exit_Type() { 1674 // create input type (domain) 1675 const Type **fields = TypeTuple::fields(2); 1676 fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // Thread-local storage 1677 fields[TypeFunc::Parms+1] = TypeMetadataPtr::BOTTOM; // Method*; Method we are entering 1678 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields); 1679 1680 // create result type (range) 1681 fields = TypeTuple::fields(0); 1682 1683 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields); 1684 1685 return TypeFunc::make(domain,range); 1686 } 1687 1688 const TypeFunc *OptoRuntime::dtrace_object_alloc_Type() { 1689 // create input type (domain) 1690 const Type **fields = TypeTuple::fields(2); 1691 fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // Thread-local storage 1692 fields[TypeFunc::Parms+1] = TypeInstPtr::NOTNULL; // oop; newly allocated object 1693 1694 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields); 1695 1696 // create result type (range) 1697 fields = TypeTuple::fields(0); 1698 1699 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields); 1700 1701 return TypeFunc::make(domain,range); 1702 } 1703 1704 1705 JRT_ENTRY_NO_ASYNC(void, OptoRuntime::register_finalizer(oopDesc* obj, JavaThread* current)) 1706 assert(oopDesc::is_oop(obj), "must be a valid oop"); 1707 assert(obj->klass()->has_finalizer(), "shouldn't be here otherwise"); 1708 InstanceKlass::register_finalizer(instanceOop(obj), CHECK); 1709 JRT_END 1710 1711 //----------------------------------------------------------------------------- 1712 1713 NamedCounter * volatile OptoRuntime::_named_counters = nullptr; 1714 1715 // 1716 // dump the collected NamedCounters. 1717 // 1718 void OptoRuntime::print_named_counters() { 1719 int total_lock_count = 0; 1720 int eliminated_lock_count = 0; 1721 1722 NamedCounter* c = _named_counters; 1723 while (c) { 1724 if (c->tag() == NamedCounter::LockCounter || c->tag() == NamedCounter::EliminatedLockCounter) { 1725 int count = c->count(); 1726 if (count > 0) { 1727 bool eliminated = c->tag() == NamedCounter::EliminatedLockCounter; 1728 if (Verbose) { 1729 tty->print_cr("%d %s%s", count, c->name(), eliminated ? " (eliminated)" : ""); 1730 } 1731 total_lock_count += count; 1732 if (eliminated) { 1733 eliminated_lock_count += count; 1734 } 1735 } 1736 #if INCLUDE_RTM_OPT 1737 } else if (c->tag() == NamedCounter::RTMLockingCounter) { 1738 RTMLockingCounters* rlc = ((RTMLockingNamedCounter*)c)->counters(); 1739 if (rlc->nonzero()) { 1740 tty->print_cr("%s", c->name()); 1741 rlc->print_on(tty); 1742 } 1743 #endif 1744 } 1745 c = c->next(); 1746 } 1747 if (total_lock_count > 0) { 1748 tty->print_cr("dynamic locks: %d", total_lock_count); 1749 if (eliminated_lock_count) { 1750 tty->print_cr("eliminated locks: %d (%d%%)", eliminated_lock_count, 1751 (int)(eliminated_lock_count * 100.0 / total_lock_count)); 1752 } 1753 } 1754 } 1755 1756 // 1757 // Allocate a new NamedCounter. The JVMState is used to generate the 1758 // name which consists of method@line for the inlining tree. 1759 // 1760 1761 NamedCounter* OptoRuntime::new_named_counter(JVMState* youngest_jvms, NamedCounter::CounterTag tag) { 1762 int max_depth = youngest_jvms->depth(); 1763 1764 // Visit scopes from youngest to oldest. 1765 bool first = true; 1766 stringStream st; 1767 for (int depth = max_depth; depth >= 1; depth--) { 1768 JVMState* jvms = youngest_jvms->of_depth(depth); 1769 ciMethod* m = jvms->has_method() ? jvms->method() : nullptr; 1770 if (!first) { 1771 st.print(" "); 1772 } else { 1773 first = false; 1774 } 1775 int bci = jvms->bci(); 1776 if (bci < 0) bci = 0; 1777 if (m != nullptr) { 1778 st.print("%s.%s", m->holder()->name()->as_utf8(), m->name()->as_utf8()); 1779 } else { 1780 st.print("no method"); 1781 } 1782 st.print("@%d", bci); 1783 // To print linenumbers instead of bci use: m->line_number_from_bci(bci) 1784 } 1785 NamedCounter* c; 1786 if (tag == NamedCounter::RTMLockingCounter) { 1787 c = new RTMLockingNamedCounter(st.freeze()); 1788 } else { 1789 c = new NamedCounter(st.freeze(), tag); 1790 } 1791 1792 // atomically add the new counter to the head of the list. We only 1793 // add counters so this is safe. 1794 NamedCounter* head; 1795 do { 1796 c->set_next(nullptr); 1797 head = _named_counters; 1798 c->set_next(head); 1799 } while (Atomic::cmpxchg(&_named_counters, head, c) != head); 1800 return c; 1801 } 1802 1803 int trace_exception_counter = 0; 1804 static void trace_exception(outputStream* st, oop exception_oop, address exception_pc, const char* msg) { 1805 trace_exception_counter++; 1806 stringStream tempst; 1807 1808 tempst.print("%d [Exception (%s): ", trace_exception_counter, msg); 1809 exception_oop->print_value_on(&tempst); 1810 tempst.print(" in "); 1811 CodeBlob* blob = CodeCache::find_blob(exception_pc); 1812 if (blob->is_compiled()) { 1813 CompiledMethod* cm = blob->as_compiled_method_or_null(); 1814 cm->method()->print_value_on(&tempst); 1815 } else if (blob->is_runtime_stub()) { 1816 tempst.print("<runtime-stub>"); 1817 } else { 1818 tempst.print("<unknown>"); 1819 } 1820 tempst.print(" at " INTPTR_FORMAT, p2i(exception_pc)); 1821 tempst.print("]"); 1822 1823 st->print_raw_cr(tempst.freeze()); 1824 }