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