Mercurial > hg > graal-compiler
comparison src/share/vm/graal/graalRuntime.cpp @ 19920:7366593c0610
Make the native initialization path for Graal more robust
author | Tom Rodriguez <tom.rodriguez@oracle.com> |
---|---|
date | Mon, 16 Mar 2015 17:37:32 -0700 |
parents | 9c2396ef02db |
children | b1700db197c7 |
comparison
equal
deleted
inserted
replaced
19919:df0608c34899 | 19920:7366593c0610 |
---|---|
624 SystemDictionary::initialize_wk_klasses_through(SystemDictionary::LAST_GRAAL_WKID, scan, CHECK); | 624 SystemDictionary::initialize_wk_klasses_through(SystemDictionary::LAST_GRAAL_WKID, scan, CHECK); |
625 JVM_END | 625 JVM_END |
626 | 626 |
627 // private static GraalRuntime Graal.initializeRuntime() | 627 // private static GraalRuntime Graal.initializeRuntime() |
628 JVM_ENTRY(jobject, JVM_GetGraalRuntime(JNIEnv *env, jclass c)) | 628 JVM_ENTRY(jobject, JVM_GetGraalRuntime(JNIEnv *env, jclass c)) |
629 GraalRuntime::initialize_HotSpotGraalRuntime(); | |
629 return GraalRuntime::get_HotSpotGraalRuntime_jobject(); | 630 return GraalRuntime::get_HotSpotGraalRuntime_jobject(); |
630 JVM_END | 631 JVM_END |
631 | 632 |
632 // private static String[] Graal.getServiceImpls(Class service) | 633 // private static String[] Graal.getServiceImpls(Class service) |
633 JVM_ENTRY(jobject, JVM_GetGraalServiceImpls(JNIEnv *env, jclass c, jclass serviceClass)) | 634 JVM_ENTRY(jobject, JVM_GetGraalServiceImpls(JNIEnv *env, jclass c, jclass serviceClass)) |
686 jio_snprintf(buf, sizeof(buf), "Generated sources SHA1 check failed (%s != %s) - need to rebuild the VM", value->as_C_string(), _generated_sources_sha1); | 687 jio_snprintf(buf, sizeof(buf), "Generated sources SHA1 check failed (%s != %s) - need to rebuild the VM", value->as_C_string(), _generated_sources_sha1); |
687 THROW_MSG(vmSymbols::java_lang_InternalError(), buf); | 688 THROW_MSG(vmSymbols::java_lang_InternalError(), buf); |
688 } | 689 } |
689 } | 690 } |
690 | 691 |
691 Handle GraalRuntime::get_HotSpotGraalRuntime() { | 692 Handle GraalRuntime::callInitializer(const char* className, const char* methodName, const char* returnType) { |
693 guarantee(!_HotSpotGraalRuntime_initialized, "cannot reinitialize HotSpotGraalRuntime"); | |
694 Thread* THREAD = Thread::current(); | |
695 check_generated_sources_sha1(CHECK_ABORT_(Handle())); | |
696 | |
697 TempNewSymbol name = SymbolTable::new_symbol(className, CHECK_ABORT_(Handle())); | |
698 KlassHandle klass = load_required_class(name); | |
699 TempNewSymbol runtime = SymbolTable::new_symbol(methodName, CHECK_ABORT_(Handle())); | |
700 TempNewSymbol sig = SymbolTable::new_symbol(returnType, CHECK_ABORT_(Handle())); | |
701 JavaValue result(T_OBJECT); | |
702 JavaCalls::call_static(&result, klass, runtime, sig, CHECK_ABORT_(Handle())); | |
703 return Handle((oop)result.get_jobject()); | |
704 } | |
705 | |
706 void GraalRuntime::initialize_HotSpotGraalRuntime() { | |
692 if (JNIHandles::resolve(_HotSpotGraalRuntime_instance) == NULL) { | 707 if (JNIHandles::resolve(_HotSpotGraalRuntime_instance) == NULL) { |
693 guarantee(!_HotSpotGraalRuntime_initialized, "cannot reinitialize HotSpotGraalRuntime"); | 708 #ifdef ASSERT |
709 // This should only be called in the context of the Graal class being initialized | |
694 Thread* THREAD = Thread::current(); | 710 Thread* THREAD = Thread::current(); |
695 check_generated_sources_sha1(CHECK_ABORT_(Handle())); | 711 TempNewSymbol name = SymbolTable::new_symbol("com/oracle/graal/api/runtime/Graal", CHECK_ABORT); |
696 TempNewSymbol name = SymbolTable::new_symbol("com/oracle/graal/hotspot/HotSpotGraalRuntime", CHECK_ABORT_(Handle())); | 712 instanceKlassHandle klass = InstanceKlass::cast(load_required_class(name)); |
697 KlassHandle klass = load_required_class(name); | 713 assert(klass->is_being_initialized() && klass->is_reentrant_initialization(THREAD), |
698 TempNewSymbol runtime = SymbolTable::new_symbol("runtime", CHECK_ABORT_(Handle())); | 714 "HotSpotGraalRuntime initialization should only be triggered through Graal initialization"); |
699 TempNewSymbol sig = SymbolTable::new_symbol("()Lcom/oracle/graal/hotspot/HotSpotGraalRuntime;", CHECK_ABORT_(Handle())); | 715 #endif |
700 JavaValue result(T_OBJECT); | 716 |
701 JavaCalls::call_static(&result, klass, runtime, sig, CHECK_ABORT_(Handle())); | 717 Handle result = callInitializer("com/oracle/graal/hotspot/HotSpotGraalRuntime", "runtime", |
702 _HotSpotGraalRuntime_instance = JNIHandles::make_global((oop) result.get_jobject()); | 718 "()Lcom/oracle/graal/hotspot/HotSpotGraalRuntime;"); |
703 _HotSpotGraalRuntime_initialized = true; | 719 _HotSpotGraalRuntime_initialized = true; |
704 } | 720 _HotSpotGraalRuntime_instance = JNIHandles::make_global(result()); |
705 return Handle(JNIHandles::resolve_non_null(_HotSpotGraalRuntime_instance)); | 721 } |
722 } | |
723 | |
724 void GraalRuntime::initialize_Graal() { | |
725 if (JNIHandles::resolve(_HotSpotGraalRuntime_instance) == NULL) { | |
726 callInitializer("com/oracle/graal/api/runtime/Graal", "getRuntime", "()Lcom/oracle/graal/api/runtime/GraalRuntime;"); | |
727 } | |
728 assert(_HotSpotGraalRuntime_initialized == true, "what?"); | |
706 } | 729 } |
707 | 730 |
708 // private static void CompilerToVMImpl.init() | 731 // private static void CompilerToVMImpl.init() |
709 JVM_ENTRY(void, JVM_InitializeGraalNatives(JNIEnv *env, jclass c2vmClass)) | 732 JVM_ENTRY(void, JVM_InitializeGraalNatives(JNIEnv *env, jclass c2vmClass)) |
710 GraalRuntime::initialize_natives(env, c2vmClass); | 733 GraalRuntime::initialize_natives(env, c2vmClass); |