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