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