changeset 5523:861f8d5a5153

Added code to resolve GraalRuntime into HotSpot. Added graal.api.test project.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Fri, 08 Jun 2012 16:57:07 +0200
parents 1319b704541d
children ab6115911fe5
files graal/com.oracle.graal.api.test/src/com/oracle/graal/api/GraalTest.java graal/com.oracle.graal.api/src/com/oracle/graal/api/Graal.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java mx/projects src/share/vm/graal/graalRuntime.cpp src/share/vm/prims/nativeLookup.cpp
diffstat 6 files changed, 140 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.api.test/src/com/oracle/graal/api/GraalTest.java	Fri Jun 08 16:57:07 2012 +0200
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.oracle.graal.api;
+
+import static org.junit.Assert.*;
+
+import org.junit.*;
+
+
+public class GraalTest {
+
+    @Test
+    public void testRuntimeAvailable() {
+        assertNotNull(Graal.getRuntime());
+    }
+
+    @Test
+    public void testRuntimeNamed() {
+        assertNotNull(Graal.getRuntime().getName());
+    }
+}
--- a/graal/com.oracle.graal.api/src/com/oracle/graal/api/Graal.java	Fri Jun 08 16:07:32 2012 +0200
+++ b/graal/com.oracle.graal.api/src/com/oracle/graal/api/Graal.java	Fri Jun 08 16:57:07 2012 +0200
@@ -25,36 +25,28 @@
 
 public class Graal {
 
-    private static volatile GraalRuntime runtime;
+    private static GraalRuntime runtime;
 
     private static native GraalRuntime initializeRuntime();
 
     public static GraalRuntime getRuntime() {
-        ensureInitialized();
         return runtime;
     }
 
-    private static void ensureInitialized() {
-        GraalRuntime oldValue = runtime;
-        if (oldValue == null) {
-            synchronized (Graal.class) {
-                if (runtime == null) {
-                    try {
-                        runtime = initializeRuntime();
-                    } catch (UnsatisfiedLinkError e) {
-                        runtime = new GraalRuntime() {
-                            @Override
-                            public String getName() {
-                                return "";
-                            }
-                            @Override
-                            public <T> T getCapability(Class<T> clazz) {
-                                return null;
-                            }
-                        };
-                    }
+    static {
+        try {
+            runtime = initializeRuntime();
+        } catch (UnsatisfiedLinkError e) {
+            runtime = new GraalRuntime() {
+                @Override
+                public String getName() {
+                    return "";
                 }
-            }
+                @Override
+                public <T> T getCapability(Class<T> clazz) {
+                    return null;
+                }
+            };
         }
     }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java	Fri Jun 08 16:57:07 2012 +0200
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.oracle.graal.hotspot;
+
+import com.oracle.graal.api.*;
+
+
+public class HotSpotGraalRuntime implements GraalRuntime {
+
+    @Override
+    public String getName() {
+        return "HotSpotGraalRuntime";
+    }
+
+    @Override
+    public <T> T getCapability(Class<T> clazz) {
+        return null;
+    }
+}
--- a/mx/projects	Fri Jun 08 16:07:32 2012 +0200
+++ b/mx/projects	Fri Jun 08 16:57:07 2012 +0200
@@ -28,6 +28,13 @@
 project@com.oracle.graal.api@checkstyle=com.oracle.graal.graph
 project@com.oracle.graal.api@javaCompliance=1.7
 
+# graal.api.test
+project@com.oracle.graal.api.test@subDir=graal
+project@com.oracle.graal.api.test@sourceDirs=src
+project@com.oracle.graal.api.test@dependencies=JUNIT,com.oracle.graal.api
+project@com.oracle.graal.api.test@checkstyle=com.oracle.graal.graph
+project@com.oracle.graal.api.test@javaCompliance=1.7
+
 # graal.api.meta
 project@com.oracle.graal.api.meta@subDir=graal
 project@com.oracle.graal.api.meta@sourceDirs=src
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/vm/graal/graalRuntime.cpp	Fri Jun 08 16:57:07 2012 +0200
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#include "precompiled.hpp"
+
+// JVM_InitializeGraalRuntime
+JVM_ENTRY(jobject, JVM_InitializeGraalRuntime(JNIEnv *env, jclass graalclass))
+  ThreadToNativeFromVM ttnfv(thread);
+  jclass klass = env->FindClass("com/oracle/graal/hotspot/HotSpotGraalRuntime");
+  guarantee(klass != NULL, "Could not find class com.oracle.graal.hotspot.HotSpotGraalRuntime");
+  return env->AllocObject(klass);
+JVM_END
\ No newline at end of file
--- a/src/share/vm/prims/nativeLookup.cpp	Fri Jun 08 16:07:32 2012 +0200
+++ b/src/share/vm/prims/nativeLookup.cpp	Fri Jun 08 16:57:07 2012 +0200
@@ -121,6 +121,9 @@
   void JNICALL JVM_RegisterUnsafeMethods(JNIEnv *env, jclass unsafecls);
   void JNICALL JVM_RegisterMethodHandleMethods(JNIEnv *env, jclass unsafecls);
   void JNICALL JVM_RegisterPerfMethods(JNIEnv *env, jclass perfclass);
+#ifdef GRAAL
+  jobject JNICALL JVM_InitializeGraalRuntime(JNIEnv *env, jclass graalclass);
+#endif
 }
 
 #define CC (char*)  /* cast a literal from (const char*) */
@@ -134,6 +137,10 @@
   { CC"Java_sun_misc_Unsafe_registerNatives",                      NULL, FN_PTR(JVM_RegisterUnsafeMethods)       },
   { CC"Java_java_lang_invoke_MethodHandleNatives_registerNatives", NULL, FN_PTR(JVM_RegisterMethodHandleMethods) },
   { CC"Java_sun_misc_Perf_registerNatives",                        NULL, FN_PTR(JVM_RegisterPerfMethods)         }
+#ifdef GRAAL
+  ,
+  { CC"Java_com_oracle_graal_api_Graal_initializeRuntime",         NULL, FN_PTR(JVM_InitializeGraalRuntime)      }
+#endif
 };
 
 static address lookup_special_native(char* jni_name) {