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