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