# HG changeset patch # User Doug Simon # Date 1349300678 -7200 # Node ID 1ecf984d490c5c964baa7e1b5f820fe91fa73658 # Parent cc863a159645c80816b2a39506e78ca1a63be199 fixed an ordering issue in the initialization and retrieval of the platform specific HotSpotGraalRuntime instance diff -r cc863a159645 -r 1ecf984d490c graal/com.oracle.graal.api.test/src/com/oracle/graal/api/GraalTest.java --- a/graal/com.oracle.graal.api.test/src/com/oracle/graal/api/GraalTest.java Wed Oct 03 20:43:44 2012 +0200 +++ b/graal/com.oracle.graal.api.test/src/com/oracle/graal/api/GraalTest.java Wed Oct 03 23:44:38 2012 +0200 @@ -38,5 +38,6 @@ @Test public void testRuntimeNamed() { assertNotNull(Graal.getRuntime().getName()); + System.out.println(Graal.getRuntime().getName()); } } diff -r cc863a159645 -r 1ecf984d490c graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotGraalRuntime.java --- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotGraalRuntime.java Wed Oct 03 20:43:44 2012 +0200 +++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotGraalRuntime.java Wed Oct 03 23:44:38 2012 +0200 @@ -36,11 +36,13 @@ } /** - * Called from native code. + * Called from C++ code to retrieve the singleton instance, creating it first if necessary. */ - @SuppressWarnings("unused") - private static HotSpotGraalRuntime initialize() { - return new AMD64HotSpotGraalRuntime(); + public static HotSpotGraalRuntime makeInstance() { + if (getInstance() == null) { + setInstance(new AMD64HotSpotGraalRuntime()); + } + return getInstance(); } @Override @@ -59,6 +61,4 @@ protected HotSpotRuntime createRuntime() { return new AMD64HotSpotRuntime(config, this); } - - } diff -r cc863a159645 -r 1ecf984d490c graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java Wed Oct 03 20:43:44 2012 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java Wed Oct 03 23:44:38 2012 +0200 @@ -38,35 +38,40 @@ * Singleton class holding the instance of the {@link GraalRuntime}. * * The platform specific subclass is created by a call from - * the native HotSpot code. + * the C++ HotSpot code. */ public abstract class HotSpotGraalRuntime implements GraalRuntime { private static HotSpotGraalRuntime instance; + /** + * Gets the singleton runtime instance object. + */ public static HotSpotGraalRuntime getInstance() { return instance; } - private final CompilerToVM compilerToVm; - private final VMToCompiler vmToCompiler; + /** + * Called by the platform specific class exactly once to register the singleton instance. + */ + protected static void setInstance(HotSpotGraalRuntime runtime) { + assert instance == null : "runtime already registered"; + instance = runtime; + } + + protected final CompilerToVM compilerToVm; + protected final VMToCompiler vmToCompiler; protected final HotSpotRuntime runtime; protected final GraalCompiler compiler; protected final TargetDescription target; + private HotSpotRuntimeInterpreterInterface runtimeInterpreterInterface; private volatile HotSpotGraphCache cache; protected final HotSpotVMConfig config; - public HotSpotVMConfig getConfig() { - return config; - } - - public HotSpotGraalRuntime() { - assert instance == null; - instance = this; - + protected HotSpotGraalRuntime() { CompilerToVM toVM = new CompilerToVMImpl(); // initialize VmToCompiler @@ -119,6 +124,10 @@ protected abstract HotSpotBackend createBackend(); protected abstract HotSpotRuntime createRuntime(); + public HotSpotVMConfig getConfig() { + return config; + } + public TargetDescription getTarget() { return target; } @@ -199,7 +208,7 @@ @Override public String getName() { - return "HotSpotGraalRuntime"; + return getClass().getSimpleName(); } @SuppressWarnings("unchecked") diff -r cc863a159645 -r 1ecf984d490c src/share/vm/classfile/vmSymbols.hpp --- a/src/share/vm/classfile/vmSymbols.hpp Wed Oct 03 20:43:44 2012 +0200 +++ b/src/share/vm/classfile/vmSymbols.hpp Wed Oct 03 23:44:38 2012 +0200 @@ -351,6 +351,7 @@ template(getVMToCompiler_name, "getVMToCompiler") \ template(getVMToCompiler_signature, "()Lcom/oracle/graal/hotspot/bridge/VMToCompiler;") \ template(getInstance_name, "getInstance") \ + template(makeInstance_name, "makeInstance") \ template(initialize_name, "initialize") \ template(getInstance_signature, "()Lcom/oracle/graal/hotspot/HotSpotGraalRuntime;") \ template(forObject_name, "forObject") \ diff -r cc863a159645 -r 1ecf984d490c src/share/vm/graal/graalRuntime.cpp --- a/src/share/vm/graal/graalRuntime.cpp Wed Oct 03 20:43:44 2012 +0200 +++ b/src/share/vm/graal/graalRuntime.cpp Wed Oct 03 23:44:38 2012 +0200 @@ -27,6 +27,5 @@ // JVM_InitializeGraalRuntime JVM_ENTRY(jobject, JVM_InitializeGraalRuntime(JNIEnv *env, jclass graalclass)) - VMToCompiler::compilerInstance(); - return VMToCompiler::compilerPermObject(); -JVM_END \ No newline at end of file + return VMToCompiler::graalRuntimePermObject(); +JVM_END diff -r cc863a159645 -r 1ecf984d490c src/share/vm/graal/graalVMToCompiler.cpp --- a/src/share/vm/graal/graalVMToCompiler.cpp Wed Oct 03 20:43:44 2012 +0200 +++ b/src/share/vm/graal/graalVMToCompiler.cpp Wed Oct 03 23:44:38 2012 +0200 @@ -25,7 +25,7 @@ #include "graal/graalVMToCompiler.hpp" // this is a *global* handle -jobject VMToCompiler::_compilerPermObject = NULL; +jobject VMToCompiler::_graalRuntimePermObject = NULL; jobject VMToCompiler::_vmToCompilerPermObject = NULL; jobject VMToCompiler::_vmToCompilerPermKlass = NULL; @@ -46,19 +46,19 @@ return KlassHandle((klassOop)JNIHandles::resolve_non_null(_vmToCompilerPermKlass)); } -Handle VMToCompiler::compilerInstance() { - if (JNIHandles::resolve(_compilerPermObject) == NULL) { +Handle VMToCompiler::graalRuntime() { + if (JNIHandles::resolve(_graalRuntimePermObject) == NULL) { #ifdef AMD64 Symbol* name = vmSymbols::com_oracle_graal_hotspot_amd64_AMD64HotSpotGraalRuntime(); #endif KlassHandle klass = loadClass(name); JavaValue result(T_OBJECT); - JavaCalls::call_static(&result, klass, vmSymbols::initialize_name(), vmSymbols::getInstance_signature(), Thread::current()); + JavaCalls::call_static(&result, klass, vmSymbols::makeInstance_name(), vmSymbols::getInstance_signature(), Thread::current()); check_pending_exception("Couldn't initialize HotSpotGraalRuntime"); - _compilerPermObject = JNIHandles::make_global((oop) result.get_jobject()); + _graalRuntimePermObject = JNIHandles::make_global((oop) result.get_jobject()); } - return Handle(JNIHandles::resolve_non_null(_compilerPermObject)); + return Handle(JNIHandles::resolve_non_null(_graalRuntimePermObject)); } Handle VMToCompiler::instance() { @@ -67,7 +67,7 @@ JavaValue result(T_OBJECT); JavaCallArguments args; - args.set_receiver(compilerInstance()); + args.set_receiver(graalRuntime()); JavaCalls::call_virtual(&result, compilerKlass, vmSymbols::getVMToCompiler_name(), vmSymbols::getVMToCompiler_signature(), &args, Thread::current()); check_pending_exception("Couldn't get VMToCompiler"); _vmToCompilerPermObject = JNIHandles::make_global((oop) result.get_jobject()); @@ -111,7 +111,7 @@ } void VMToCompiler::shutdownCompiler() { - if (_compilerPermObject != NULL) { + if (_graalRuntimePermObject != NULL) { HandleMark hm; JavaThread* THREAD = JavaThread::current(); JavaValue result(T_VOID); @@ -120,11 +120,11 @@ JavaCalls::call_interface(&result, vmToCompilerKlass(), vmSymbols::shutdownCompiler_name(), vmSymbols::void_method_signature(), &args, THREAD); check_pending_exception("Error while calling shutdownCompiler"); - JNIHandles::destroy_global(_compilerPermObject); + JNIHandles::destroy_global(_graalRuntimePermObject); JNIHandles::destroy_global(_vmToCompilerPermObject); JNIHandles::destroy_global(_vmToCompilerPermKlass); - _compilerPermObject = NULL; + _graalRuntimePermObject = NULL; _vmToCompilerPermObject = NULL; _vmToCompilerPermKlass = NULL; } diff -r cc863a159645 -r 1ecf984d490c src/share/vm/graal/graalVMToCompiler.hpp --- a/src/share/vm/graal/graalVMToCompiler.hpp Wed Oct 03 20:43:44 2012 +0200 +++ b/src/share/vm/graal/graalVMToCompiler.hpp Wed Oct 03 23:44:38 2012 +0200 @@ -35,7 +35,7 @@ class VMToCompiler : public AllStatic { private: - static jobject _compilerPermObject; + static jobject _graalRuntimePermObject; static jobject _vmToCompilerPermObject; static jobject _vmToCompilerPermKlass; @@ -43,10 +43,11 @@ static Handle instance(); public: - static Handle compilerInstance(); + static Handle graalRuntime(); - static jobject compilerPermObject() { - return _compilerPermObject; + static jobject graalRuntimePermObject() { + graalRuntime(); + return _graalRuntimePermObject; } // public static boolean HotSpotOptions.setOption(String option);