comparison src/share/vm/runtime/sharedRuntime.cpp @ 17795:a9becfeecd1b

Merge
author kvn
date Wed, 22 Jan 2014 17:42:23 -0800
parents 5da8bb64b370 7b9127b17b7a
children cf9f24de0b93
comparison
equal deleted inserted replaced
17794:3514ee402842 17795:a9becfeecd1b
492 thread->set_is_method_handle_return(nm->is_method_handle_return(return_address)); 492 thread->set_is_method_handle_return(nm->is_method_handle_return(return_address));
493 // native nmethods don't have exception handlers 493 // native nmethods don't have exception handlers
494 assert(!nm->is_native_method(), "no exception handler"); 494 assert(!nm->is_native_method(), "no exception handler");
495 assert(nm->header_begin() != nm->exception_begin(), "no exception handler"); 495 assert(nm->header_begin() != nm->exception_begin(), "no exception handler");
496 if (nm->is_deopt_pc(return_address)) { 496 if (nm->is_deopt_pc(return_address)) {
497 // If we come here because of a stack overflow, the stack may be
498 // unguarded. Reguard the stack otherwise if we return to the
499 // deopt blob and the stack bang causes a stack overflow we
500 // crash.
501 bool guard_pages_enabled = thread->stack_yellow_zone_enabled();
502 if (!guard_pages_enabled) guard_pages_enabled = thread->reguard_stack();
503 assert(guard_pages_enabled, "stack banging in deopt blob may cause crash");
497 return SharedRuntime::deopt_blob()->unpack_with_exception(); 504 return SharedRuntime::deopt_blob()->unpack_with_exception();
498 } else { 505 } else {
499 return nm->exception_begin(); 506 return nm->exception_begin();
500 } 507 }
501 } 508 }
2398 assert(ic_miss != NULL, "must have handler"); 2405 assert(ic_miss != NULL, "must have handler");
2399 2406
2400 ResourceMark rm; 2407 ResourceMark rm;
2401 2408
2402 NOT_PRODUCT(int insts_size); 2409 NOT_PRODUCT(int insts_size);
2403 AdapterBlob* B = NULL; 2410 AdapterBlob* new_adapter = NULL;
2404 AdapterHandlerEntry* entry = NULL; 2411 AdapterHandlerEntry* entry = NULL;
2405 AdapterFingerPrint* fingerprint = NULL; 2412 AdapterFingerPrint* fingerprint = NULL;
2406 { 2413 {
2407 MutexLocker mu(AdapterHandlerLibrary_lock); 2414 MutexLocker mu(AdapterHandlerLibrary_lock);
2408 // make sure data structure is initialized 2415 // make sure data structure is initialized
2430 // Lookup method signature's fingerprint 2437 // Lookup method signature's fingerprint
2431 entry = _adapters->lookup(total_args_passed, sig_bt); 2438 entry = _adapters->lookup(total_args_passed, sig_bt);
2432 2439
2433 #ifdef ASSERT 2440 #ifdef ASSERT
2434 AdapterHandlerEntry* shared_entry = NULL; 2441 AdapterHandlerEntry* shared_entry = NULL;
2435 if (VerifyAdapterSharing && entry != NULL) { 2442 // Start adapter sharing verification only after the VM is booted.
2443 if (VerifyAdapterSharing && (entry != NULL)) {
2436 shared_entry = entry; 2444 shared_entry = entry;
2437 entry = NULL; 2445 entry = NULL;
2438 } 2446 }
2439 #endif 2447 #endif
2440 2448
2446 int comp_args_on_stack = SharedRuntime::java_calling_convention(sig_bt, regs, total_args_passed, false); 2454 int comp_args_on_stack = SharedRuntime::java_calling_convention(sig_bt, regs, total_args_passed, false);
2447 2455
2448 // Make a C heap allocated version of the fingerprint to store in the adapter 2456 // Make a C heap allocated version of the fingerprint to store in the adapter
2449 fingerprint = new AdapterFingerPrint(total_args_passed, sig_bt); 2457 fingerprint = new AdapterFingerPrint(total_args_passed, sig_bt);
2450 2458
2459 // StubRoutines::code2() is initialized after this function can be called. As a result,
2460 // VerifyAdapterCalls and VerifyAdapterSharing can fail if we re-use code that generated
2461 // prior to StubRoutines::code2() being set. Checks refer to checks generated in an I2C
2462 // stub that ensure that an I2C stub is called from an interpreter frame.
2463 bool contains_all_checks = StubRoutines::code2() != NULL;
2464
2451 // Create I2C & C2I handlers 2465 // Create I2C & C2I handlers
2452
2453 BufferBlob* buf = buffer_blob(); // the temporary code buffer in CodeCache 2466 BufferBlob* buf = buffer_blob(); // the temporary code buffer in CodeCache
2454 if (buf != NULL) { 2467 if (buf != NULL) {
2455 CodeBuffer buffer(buf); 2468 CodeBuffer buffer(buf);
2456 short buffer_locs[20]; 2469 short buffer_locs[20];
2457 buffer.insts()->initialize_shared_locs((relocInfo*)buffer_locs, 2470 buffer.insts()->initialize_shared_locs((relocInfo*)buffer_locs,
2458 sizeof(buffer_locs)/sizeof(relocInfo)); 2471 sizeof(buffer_locs)/sizeof(relocInfo));
2472
2459 MacroAssembler _masm(&buffer); 2473 MacroAssembler _masm(&buffer);
2460
2461 entry = SharedRuntime::generate_i2c2i_adapters(&_masm, 2474 entry = SharedRuntime::generate_i2c2i_adapters(&_masm,
2462 total_args_passed, 2475 total_args_passed,
2463 comp_args_on_stack, 2476 comp_args_on_stack,
2464 sig_bt, 2477 sig_bt,
2465 regs, 2478 regs,
2466 fingerprint); 2479 fingerprint);
2467
2468 #ifdef ASSERT 2480 #ifdef ASSERT
2469 if (VerifyAdapterSharing) { 2481 if (VerifyAdapterSharing) {
2470 if (shared_entry != NULL) { 2482 if (shared_entry != NULL) {
2471 assert(shared_entry->compare_code(buf->code_begin(), buffer.insts_size(), total_args_passed, sig_bt), 2483 assert(shared_entry->compare_code(buf->code_begin(), buffer.insts_size()), "code must match");
2472 "code must match");
2473 // Release the one just created and return the original 2484 // Release the one just created and return the original
2474 _adapters->free_entry(entry); 2485 _adapters->free_entry(entry);
2475 return shared_entry; 2486 return shared_entry;
2476 } else { 2487 } else {
2477 entry->save_code(buf->code_begin(), buffer.insts_size(), total_args_passed, sig_bt); 2488 entry->save_code(buf->code_begin(), buffer.insts_size());
2478 } 2489 }
2479 } 2490 }
2480 #endif 2491 #endif
2481 2492
2482 B = AdapterBlob::create(&buffer); 2493 new_adapter = AdapterBlob::create(&buffer);
2483 NOT_PRODUCT(insts_size = buffer.insts_size()); 2494 NOT_PRODUCT(insts_size = buffer.insts_size());
2484 } 2495 }
2485 if (B == NULL) { 2496 if (new_adapter == NULL) {
2486 // CodeCache is full, disable compilation 2497 // CodeCache is full, disable compilation
2487 // Ought to log this but compile log is only per compile thread 2498 // Ought to log this but compile log is only per compile thread
2488 // and we're some non descript Java thread. 2499 // and we're some non descript Java thread.
2489 MutexUnlocker mu(AdapterHandlerLibrary_lock); 2500 MutexUnlocker mu(AdapterHandlerLibrary_lock);
2490 CompileBroker::handle_full_code_cache(); 2501 CompileBroker::handle_full_code_cache();
2491 return NULL; // Out of CodeCache space 2502 return NULL; // Out of CodeCache space
2492 } 2503 }
2493 entry->relocate(B->content_begin()); 2504 entry->relocate(new_adapter->content_begin());
2494 #ifndef PRODUCT 2505 #ifndef PRODUCT
2495 // debugging suppport 2506 // debugging suppport
2496 if (PrintAdapterHandlers || PrintStubCode) { 2507 if (PrintAdapterHandlers || PrintStubCode) {
2497 ttyLocker ttyl; 2508 ttyLocker ttyl;
2498 entry->print_adapter_on(tty); 2509 entry->print_adapter_on(tty);
2507 tty->cr(); 2518 tty->cr();
2508 } 2519 }
2509 } 2520 }
2510 } 2521 }
2511 #endif 2522 #endif
2512 2523 // Add the entry only if the entry contains all required checks (see sharedRuntime_xxx.cpp)
2513 _adapters->add(entry); 2524 // The checks are inserted only if -XX:+VerifyAdapterCalls is specified.
2525 if (contains_all_checks || !VerifyAdapterCalls) {
2526 _adapters->add(entry);
2527 }
2514 } 2528 }
2515 // Outside of the lock 2529 // Outside of the lock
2516 if (B != NULL) { 2530 if (new_adapter != NULL) {
2517 char blob_id[256]; 2531 char blob_id[256];
2518 jio_snprintf(blob_id, 2532 jio_snprintf(blob_id,
2519 sizeof(blob_id), 2533 sizeof(blob_id),
2520 "%s(%s)@" PTR_FORMAT, 2534 "%s(%s)@" PTR_FORMAT,
2521 B->name(), 2535 new_adapter->name(),
2522 fingerprint->as_string(), 2536 fingerprint->as_string(),
2523 B->content_begin()); 2537 new_adapter->content_begin());
2524 Forte::register_stub(blob_id, B->content_begin(), B->content_end()); 2538 Forte::register_stub(blob_id, new_adapter->content_begin(),new_adapter->content_end());
2525 2539
2526 if (JvmtiExport::should_post_dynamic_code_generated()) { 2540 if (JvmtiExport::should_post_dynamic_code_generated()) {
2527 JvmtiExport::post_dynamic_code_generated(blob_id, B->content_begin(), B->content_end()); 2541 JvmtiExport::post_dynamic_code_generated(blob_id, new_adapter->content_begin(), new_adapter->content_end());
2528 } 2542 }
2529 } 2543 }
2530 return entry; 2544 return entry;
2531 } 2545 }
2532 2546
2554 2568
2555 void AdapterHandlerEntry::deallocate() { 2569 void AdapterHandlerEntry::deallocate() {
2556 delete _fingerprint; 2570 delete _fingerprint;
2557 #ifdef ASSERT 2571 #ifdef ASSERT
2558 if (_saved_code) FREE_C_HEAP_ARRAY(unsigned char, _saved_code, mtCode); 2572 if (_saved_code) FREE_C_HEAP_ARRAY(unsigned char, _saved_code, mtCode);
2559 if (_saved_sig) FREE_C_HEAP_ARRAY(Basictype, _saved_sig, mtCode);
2560 #endif 2573 #endif
2561 } 2574 }
2562 2575
2563 2576
2564 #ifdef ASSERT 2577 #ifdef ASSERT
2565 // Capture the code before relocation so that it can be compared 2578 // Capture the code before relocation so that it can be compared
2566 // against other versions. If the code is captured after relocation 2579 // against other versions. If the code is captured after relocation
2567 // then relative instructions won't be equivalent. 2580 // then relative instructions won't be equivalent.
2568 void AdapterHandlerEntry::save_code(unsigned char* buffer, int length, int total_args_passed, BasicType* sig_bt) { 2581 void AdapterHandlerEntry::save_code(unsigned char* buffer, int length) {
2569 _saved_code = NEW_C_HEAP_ARRAY(unsigned char, length, mtCode); 2582 _saved_code = NEW_C_HEAP_ARRAY(unsigned char, length, mtCode);
2570 _code_length = length; 2583 _saved_code_length = length;
2571 memcpy(_saved_code, buffer, length); 2584 memcpy(_saved_code, buffer, length);
2572 _total_args_passed = total_args_passed; 2585 }
2573 _saved_sig = NEW_C_HEAP_ARRAY(BasicType, _total_args_passed, mtCode); 2586
2574 memcpy(_saved_sig, sig_bt, _total_args_passed * sizeof(BasicType)); 2587
2575 } 2588 bool AdapterHandlerEntry::compare_code(unsigned char* buffer, int length) {
2576 2589 if (length != _saved_code_length) {
2577
2578 bool AdapterHandlerEntry::compare_code(unsigned char* buffer, int length, int total_args_passed, BasicType* sig_bt) {
2579 if (length != _code_length) {
2580 return false; 2590 return false;
2581 } 2591 }
2582 for (int i = 0; i < length; i++) { 2592
2583 if (buffer[i] != _saved_code[i]) { 2593 return (memcmp(buffer, _saved_code, length) == 0) ? true : false;
2584 return false; 2594 }
2585 } 2595 #endif
2586 } 2596
2587 return true; 2597
2588 } 2598 /**
2589 #endif 2599 * Create a native wrapper for this native method. The wrapper converts the
2590 2600 * Java-compiled calling convention to the native convention, handles
2591 2601 * arguments, and transitions to native. On return from the native we transition
2592 // Create a native wrapper for this native method. The wrapper converts the 2602 * back to java blocking if a safepoint is in progress.
2593 // java compiled calling convention to the native convention, handlizes 2603 */
2594 // arguments, and transitions to native. On return from the native we transition 2604 void AdapterHandlerLibrary::create_native_wrapper(methodHandle method) {
2595 // back to java blocking if a safepoint is in progress.
2596 nmethod *AdapterHandlerLibrary::create_native_wrapper(methodHandle method, int compile_id) {
2597 ResourceMark rm; 2605 ResourceMark rm;
2598 nmethod* nm = NULL; 2606 nmethod* nm = NULL;
2599 2607
2600 assert(method->is_native(), "must be native"); 2608 assert(method->is_native(), "must be native");
2601 assert(method->is_method_handle_intrinsic() || 2609 assert(method->is_method_handle_intrinsic() ||
2602 method->has_native_function(), "must have something valid to call!"); 2610 method->has_native_function(), "must have something valid to call!");
2603 2611
2604 { 2612 {
2605 // perform the work while holding the lock, but perform any printing outside the lock 2613 // Perform the work while holding the lock, but perform any printing outside the lock
2606 MutexLocker mu(AdapterHandlerLibrary_lock); 2614 MutexLocker mu(AdapterHandlerLibrary_lock);
2607 // See if somebody beat us to it 2615 // See if somebody beat us to it
2608 nm = method->code(); 2616 nm = method->code();
2609 if (nm) { 2617 if (nm != NULL) {
2610 return nm; 2618 return;
2611 } 2619 }
2620
2621 const int compile_id = CompileBroker::assign_compile_id(method, CompileBroker::standard_entry_bci);
2622 assert(compile_id > 0, "Must generate native wrapper");
2623
2612 2624
2613 ResourceMark rm; 2625 ResourceMark rm;
2614
2615 BufferBlob* buf = buffer_blob(); // the temporary code buffer in CodeCache 2626 BufferBlob* buf = buffer_blob(); // the temporary code buffer in CodeCache
2616 if (buf != NULL) { 2627 if (buf != NULL) {
2617 CodeBuffer buffer(buf); 2628 CodeBuffer buffer(buf);
2618 double locs_buf[20]; 2629 double locs_buf[20];
2619 buffer.insts()->initialize_shared_locs((relocInfo*)locs_buf, sizeof(locs_buf) / sizeof(relocInfo)); 2630 buffer.insts()->initialize_shared_locs((relocInfo*)locs_buf, sizeof(locs_buf) / sizeof(relocInfo));
2641 // are just trampolines so the argument registers must be outgoing ones. 2652 // are just trampolines so the argument registers must be outgoing ones.
2642 const bool is_outgoing = method->is_method_handle_intrinsic(); 2653 const bool is_outgoing = method->is_method_handle_intrinsic();
2643 int comp_args_on_stack = SharedRuntime::java_calling_convention(sig_bt, regs, total_args_passed, is_outgoing); 2654 int comp_args_on_stack = SharedRuntime::java_calling_convention(sig_bt, regs, total_args_passed, is_outgoing);
2644 2655
2645 // Generate the compiled-to-native wrapper code 2656 // Generate the compiled-to-native wrapper code
2646 nm = SharedRuntime::generate_native_wrapper(&_masm, 2657 nm = SharedRuntime::generate_native_wrapper(&_masm, method, compile_id, sig_bt, regs, ret_type);
2647 method, 2658
2648 compile_id, 2659 if (nm != NULL) {
2649 sig_bt, 2660 method->set_code(method, nm);
2650 regs, 2661 }
2651 ret_type); 2662 }
2652 } 2663 } // Unlock AdapterHandlerLibrary_lock
2653 } 2664
2654
2655 // Must unlock before calling set_code
2656 2665
2657 // Install the generated code. 2666 // Install the generated code.
2658 if (nm != NULL) { 2667 if (nm != NULL) {
2659 if (PrintCompilation) { 2668 if (PrintCompilation) {
2660 ttyLocker ttyl; 2669 ttyLocker ttyl;
2661 CompileTask::print_compilation(tty, nm, method->is_static() ? "(static)" : ""); 2670 CompileTask::print_compilation(tty, nm, method->is_static() ? "(static)" : "");
2662 } 2671 }
2663 method->set_code(method, nm);
2664 nm->post_compiled_method_load_event(); 2672 nm->post_compiled_method_load_event();
2665 } else { 2673 } else {
2666 // CodeCache is full, disable compilation 2674 // CodeCache is full, disable compilation
2667 CompileBroker::handle_full_code_cache(); 2675 CompileBroker::handle_full_code_cache();
2668 } 2676 }
2669 return nm;
2670 } 2677 }
2671 2678
2672 JRT_ENTRY_NO_ASYNC(void, SharedRuntime::block_for_jni_critical(JavaThread* thread)) 2679 JRT_ENTRY_NO_ASYNC(void, SharedRuntime::block_for_jni_critical(JavaThread* thread))
2673 assert(thread == JavaThread::current(), "must be"); 2680 assert(thread == JavaThread::current(), "must be");
2674 // The code is about to enter a JNI lazy critical native method and 2681 // The code is about to enter a JNI lazy critical native method and