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