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