comparison src/share/vm/graal/graalRuntime.cpp @ 16006:66a9286203a2

decoupled Graal runtime initialization and Graal compilation queue initialization
author Doug Simon <doug.simon@oracle.com>
date Tue, 03 Jun 2014 11:51:27 +0200
parents 6aa352b260f4
children d56a09df1a1f
comparison
equal deleted inserted replaced
16003:83433cf49019 16006:66a9286203a2
21 * questions. 21 * questions.
22 */ 22 */
23 23
24 #include "precompiled.hpp" 24 #include "precompiled.hpp"
25 #include "asm/codeBuffer.hpp" 25 #include "asm/codeBuffer.hpp"
26 #include "compiler/compileBroker.hpp"
26 #include "graal/graalRuntime.hpp" 27 #include "graal/graalRuntime.hpp"
27 #include "graal/graalVMToCompiler.hpp"
28 #include "graal/graalCompilerToVM.hpp" 28 #include "graal/graalCompilerToVM.hpp"
29 #include "graal/graalCompiler.hpp"
29 #include "graal/graalJavaAccess.hpp" 30 #include "graal/graalJavaAccess.hpp"
30 #include "graal/graalEnv.hpp" 31 #include "graal/graalEnv.hpp"
31 #include "memory/oopFactory.hpp" 32 #include "memory/oopFactory.hpp"
32 #include "prims/jvm.h" 33 #include "prims/jvm.h"
33 #include "runtime/biasedLocking.hpp" 34 #include "runtime/biasedLocking.hpp"
35 #include "runtime/arguments.hpp" 36 #include "runtime/arguments.hpp"
36 #include "runtime/reflection.hpp" 37 #include "runtime/reflection.hpp"
37 #include "utilities/debug.hpp" 38 #include "utilities/debug.hpp"
38 39
39 address GraalRuntime::_external_deopt_i2c_entry = NULL; 40 address GraalRuntime::_external_deopt_i2c_entry = NULL;
41 jobject GraalRuntime::_HotSpotGraalRuntime_instance = NULL;
40 42
41 void GraalRuntime::initialize_natives(JNIEnv *env, jclass c2vmClass) { 43 void GraalRuntime::initialize_natives(JNIEnv *env, jclass c2vmClass) {
42 uintptr_t heap_end = (uintptr_t) Universe::heap()->reserved_region().end(); 44 uintptr_t heap_end = (uintptr_t) Universe::heap()->reserved_region().end();
43 uintptr_t allocation_end = heap_end + ((uintptr_t)16) * 1024 * 1024 * 1024; 45 uintptr_t allocation_end = heap_end + ((uintptr_t)16) * 1024 * 1024 * 1024;
44 AMD64_ONLY(guarantee(heap_end < allocation_end, "heap end too close to end of address space (might lead to erroneous TLAB allocations)")); 46 AMD64_ONLY(guarantee(heap_end < allocation_end, "heap end too close to end of address space (might lead to erroneous TLAB allocations)"));
58 // Ensure _non_oop_bits is initialized 60 // Ensure _non_oop_bits is initialized
59 Universe::non_oop_word(); 61 Universe::non_oop_word();
60 62
61 env->RegisterNatives(c2vmClass, CompilerToVM_methods, CompilerToVM_methods_count()); 63 env->RegisterNatives(c2vmClass, CompilerToVM_methods, CompilerToVM_methods_count());
62 } 64 }
63 check_pending_exception("Could not register natives"); 65 GUARANTEE_NO_PENDING_EXCEPTION("Could not register natives");
64 } 66 }
65 67
66 BufferBlob* GraalRuntime::initialize_buffer_blob() { 68 BufferBlob* GraalRuntime::initialize_buffer_blob() {
67 JavaThread* THREAD = JavaThread::current(); 69 JavaThread* THREAD = JavaThread::current();
68 BufferBlob* buffer_blob = THREAD->get_buffer_blob(); 70 BufferBlob* buffer_blob = THREAD->get_buffer_blob();
636 } 638 }
637 JRT_END 639 JRT_END
638 640
639 // private static GraalRuntime Graal.initializeRuntime() 641 // private static GraalRuntime Graal.initializeRuntime()
640 JVM_ENTRY(jobject, JVM_GetGraalRuntime(JNIEnv *env, jclass c)) 642 JVM_ENTRY(jobject, JVM_GetGraalRuntime(JNIEnv *env, jclass c))
641 return VMToCompiler::get_HotSpotGraalRuntime_jobject(); 643 return GraalRuntime::get_HotSpotGraalRuntime_jobject();
642 JVM_END 644 JVM_END
643 645
644 // private static String[] Graal.getServiceImpls(Class service) 646 // private static String[] Graal.getServiceImpls(Class service)
645 JVM_ENTRY(jobject, JVM_GetGraalServiceImpls(JNIEnv *env, jclass c, jclass serviceClass)) 647 JVM_ENTRY(jobject, JVM_GetGraalServiceImpls(JNIEnv *env, jclass c, jclass serviceClass))
646 HandleMark hm; 648 HandleMark hm;
648 return JNIHandles::make_local(THREAD, GraalRuntime::get_service_impls(serviceKlass, THREAD)()); 650 return JNIHandles::make_local(THREAD, GraalRuntime::get_service_impls(serviceKlass, THREAD)());
649 JVM_END 651 JVM_END
650 652
651 // private static TruffleRuntime Truffle.createRuntime() 653 // private static TruffleRuntime Truffle.createRuntime()
652 JVM_ENTRY(jobject, JVM_CreateTruffleRuntime(JNIEnv *env, jclass c)) 654 JVM_ENTRY(jobject, JVM_CreateTruffleRuntime(JNIEnv *env, jclass c))
653 return JNIHandles::make_local(VMToCompiler::create_HotSpotTruffleRuntime()()); 655 TempNewSymbol name = SymbolTable::new_symbol("com/oracle/graal/truffle/hotspot/HotSpotTruffleRuntime", THREAD);
656 KlassHandle klass = GraalRuntime::load_required_class(name);
657
658 TempNewSymbol makeInstance = SymbolTable::new_symbol("makeInstance", THREAD);
659 TempNewSymbol sig = SymbolTable::new_symbol("()Lcom/oracle/graal/truffle/hotspot/HotSpotTruffleRuntime;", THREAD);
660 JavaValue result(T_OBJECT);
661 JavaCalls::call_static(&result, klass, makeInstance, sig, THREAD);
662 GUARANTEE_NO_PENDING_EXCEPTION("Couldn't initialize HotSpotTruffleRuntime");
663 return JNIHandles::make_local((oop) result.get_jobject());
654 JVM_END 664 JVM_END
655 665
656 // private static void HotSpotGraalRuntime.init(Class compilerToVMClass) 666 Handle GraalRuntime::get_HotSpotGraalRuntime() {
657 JVM_ENTRY(void, JVM_InitializeGraalNatives(JNIEnv *env, jclass c, jclass c2vmClass)) 667 if (JNIHandles::resolve(_HotSpotGraalRuntime_instance) == NULL) {
668 Thread* THREAD = Thread::current();
669 TempNewSymbol name = SymbolTable::new_symbol("com/oracle/graal/hotspot/HotSpotGraalRuntime", THREAD);
670 KlassHandle klass = load_required_class(name);
671 TempNewSymbol runtime = SymbolTable::new_symbol("runtime", THREAD);
672 TempNewSymbol sig = SymbolTable::new_symbol("()Lcom/oracle/graal/hotspot/HotSpotGraalRuntime;", THREAD);
673 JavaValue result(T_OBJECT);
674 JavaCalls::call_static(&result, klass, runtime, sig, THREAD);
675 GUARANTEE_NO_PENDING_EXCEPTION("Couldn't initialize HotSpotGraalRuntime");
676 _HotSpotGraalRuntime_instance = JNIHandles::make_global((oop) result.get_jobject());
677 }
678 return Handle(JNIHandles::resolve_non_null(_HotSpotGraalRuntime_instance));
679 }
680
681 // private static void CompilerToVMImpl.init()
682 JVM_ENTRY(void, JVM_InitializeGraalNatives(JNIEnv *env, jclass c2vmClass))
658 GraalRuntime::initialize_natives(env, c2vmClass); 683 GraalRuntime::initialize_natives(env, c2vmClass);
659 JVM_END 684 JVM_END
660 685
661 // private static boolean HotSpotOptions.parseVMOptions() 686 // private static boolean HotSpotOptions.parseVMOptions()
662 JVM_ENTRY(jboolean, JVM_ParseGraalOptions(JNIEnv *env, jclass c)) 687 JVM_ENTRY(jboolean, JVM_ParseGraalOptions(JNIEnv *env, jclass c))
663 HandleMark hm; 688 HandleMark hm;
664 KlassHandle hotSpotOptionsClass(THREAD, java_lang_Class::as_Klass(JNIHandles::resolve_non_null(c))); 689 KlassHandle hotSpotOptionsClass(THREAD, java_lang_Class::as_Klass(JNIHandles::resolve_non_null(c)));
665 return GraalRuntime::parse_arguments(hotSpotOptionsClass, CHECK_false); 690 return GraalRuntime::parse_arguments(hotSpotOptionsClass, CHECK_false);
666 JVM_END 691 JVM_END
692
693 #ifdef COMPILERGRAAL
694 // private static boolean CompilationQueue.printAndResetCompRate()
695 JVM_ENTRY(void, JVM_PrintAndResetGraalCompRate(JNIEnv *env, jclass c))
696 GraalCompiler* comp = GraalCompiler::instance();
697 CompileBroker::print_times(comp);
698 CompilerStatistics* stats = comp->stats();
699 stats->_standard.reset();
700 stats->_osr.reset();
701 JVM_END
702 #endif
667 703
668 bool GraalRuntime::parse_arguments(KlassHandle hotSpotOptionsClass, TRAPS) { 704 bool GraalRuntime::parse_arguments(KlassHandle hotSpotOptionsClass, TRAPS) {
669 ResourceMark rm(THREAD); 705 ResourceMark rm(THREAD);
670 706
671 // Process option overrides from graal.options first 707 // Process option overrides from graal.options first
710 THROW_MSG(vmSymbols::java_lang_InternalError(), buf); 746 THROW_MSG(vmSymbols::java_lang_InternalError(), buf);
711 } 747 }
712 } 748 }
713 749
714 if (!valid) { 750 if (!valid) {
715 VMToCompiler::setOption(hotSpotOptionsClass, name_handle, Handle(), ' ', Handle(), 0L); 751 set_option_helper(hotSpotOptionsClass, name_handle, Handle(), ' ', Handle(), 0L);
716 char buf[200]; 752 char buf[200];
717 jio_snprintf(buf, sizeof(buf), "Invalid Graal option %s", arg); 753 jio_snprintf(buf, sizeof(buf), "Invalid Graal option %s", arg);
718 THROW_MSG(vmSymbols::java_lang_InternalError(), buf); 754 THROW_MSG(vmSymbols::java_lang_InternalError(), buf);
719 } 755 }
720 } 756 }
795 char buf[200]; 831 char buf[200];
796 jio_snprintf(buf, sizeof(buf), "Invalid %s value for Graal option %s: %s", (spec == 'i' ? "numeric" : "float/double"), java_lang_String::as_utf8_string(name()), value); 832 jio_snprintf(buf, sizeof(buf), "Invalid %s value for Graal option %s: %s", (spec == 'i' ? "numeric" : "float/double"), java_lang_String::as_utf8_string(name()), value);
797 THROW_MSG_(vmSymbols::java_lang_InternalError(), buf, 0L); 833 THROW_MSG_(vmSymbols::java_lang_InternalError(), buf, 0L);
798 } 834 }
799 835
836 void GraalRuntime::set_option_helper(KlassHandle hotSpotOptionsClass, Handle name, Handle option, jchar spec, Handle stringValue, jlong primitiveValue) {
837 Thread* THREAD = Thread::current();
838 TempNewSymbol setOption = SymbolTable::new_symbol("setOption", THREAD);
839 TempNewSymbol sig = SymbolTable::new_symbol("(Ljava/lang/String;Lcom/oracle/graal/options/OptionValue;CLjava/lang/String;J)V", THREAD);
840 JavaValue result(T_VOID);
841 JavaCallArguments args;
842 args.push_oop(name());
843 args.push_oop(option());
844 args.push_int(spec);
845 args.push_oop(stringValue());
846 args.push_long(primitiveValue);
847 JavaCalls::call_static(&result, hotSpotOptionsClass, setOption, sig, &args, THREAD);
848 GUARANTEE_NO_PENDING_EXCEPTION("Error while calling set_option_helper");
849 }
850
800 Handle GraalRuntime::get_OptionValue(const char* declaringClass, const char* fieldName, const char* fieldSig, TRAPS) { 851 Handle GraalRuntime::get_OptionValue(const char* declaringClass, const char* fieldName, const char* fieldSig, TRAPS) {
801 TempNewSymbol name = SymbolTable::new_symbol(declaringClass, THREAD); 852 TempNewSymbol name = SymbolTable::new_symbol(declaringClass, THREAD);
802 Klass* klass = SystemDictionary::resolve_or_fail(name, true, CHECK_NH); 853 Klass* klass = SystemDictionary::resolve_or_fail(name, true, CHECK_NH);
803 854
804 // The class has been loaded so the field and signature should already be in the symbol 855 // The class has been loaded so the field and signature should already be in the symbol
830 instanceHandle service = klass->allocate_instance_handle(CHECK_NH); 881 instanceHandle service = klass->allocate_instance_handle(CHECK_NH);
831 JavaCalls::call_special(&result, service, klass, vmSymbols::object_initializer_name(), vmSymbols::void_method_signature(), THREAD); 882 JavaCalls::call_special(&result, service, klass, vmSymbols::object_initializer_name(), vmSymbols::void_method_signature(), THREAD);
832 return service; 883 return service;
833 } 884 }
834 885
886 void GraalRuntime::shutdown() {
887 if (_HotSpotGraalRuntime_instance != NULL) {
888 JavaThread* THREAD = JavaThread::current();
889 HandleMark hm(THREAD);
890 TempNewSymbol name = SymbolTable::new_symbol("com/oracle/graal/hotspot/HotSpotGraalRuntime", THREAD);
891 KlassHandle klass = load_required_class(name);
892 JavaValue result(T_VOID);
893 JavaCallArguments args;
894 args.push_oop(get_HotSpotGraalRuntime());
895 JavaCalls::call_special(&result, klass, vmSymbols::shutdown_method_name(), vmSymbols::void_method_signature(), &args, THREAD);
896 GUARANTEE_NO_PENDING_EXCEPTION("Error while calling shutdown");
897
898 JNIHandles::destroy_global(_HotSpotGraalRuntime_instance);
899 _HotSpotGraalRuntime_instance = NULL;
900 }
901 }
902
903 void GraalRuntime::abort_on_pending_exception(Handle exception, const char* message, bool dump_core) {
904 Thread* THREAD = Thread::current();
905 CLEAR_PENDING_EXCEPTION;
906
907 assert(exception->is_a(SystemDictionary::Throwable_klass()), "Throwable instance expected");
908 JavaValue result(T_VOID);
909 JavaCalls::call_virtual(&result,
910 exception,
911 KlassHandle(THREAD,
912 SystemDictionary::Throwable_klass()),
913 vmSymbols::printStackTrace_name(),
914 vmSymbols::void_method_signature(),
915 THREAD);
916
917 vm_abort(dump_core);
918 }
919
920 Klass* GraalRuntime::load_required_class(Symbol* name) {
921 Klass* klass = SystemDictionary::resolve_or_null(name, SystemDictionary::java_system_loader(), Handle(), Thread::current());
922 if (klass == NULL) {
923 tty->print_cr("Could not load class %s", name->as_C_string());
924 vm_abort(false);
925 }
926 return klass;
927 }
928
835 #include "graalRuntime.inline.hpp" 929 #include "graalRuntime.inline.hpp"