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