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