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