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