# HG changeset patch # User Thomas Wuerthinger # Date 1339167427 -7200 # Node ID 861f8d5a5153ce14024e55252eef95c7ce688a16 # Parent 1319b704541dc339a86012576727b6c4c81268d3 Added code to resolve GraalRuntime into HotSpot. Added graal.api.test project. diff -r 1319b704541d -r 861f8d5a5153 graal/com.oracle.graal.api.test/src/com/oracle/graal/api/GraalTest.java --- /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()); + } +} diff -r 1319b704541d -r 861f8d5a5153 graal/com.oracle.graal.api/src/com/oracle/graal/api/Graal.java --- 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 getCapability(Class clazz) { - return null; - } - }; - } + static { + try { + runtime = initializeRuntime(); + } catch (UnsatisfiedLinkError e) { + runtime = new GraalRuntime() { + @Override + public String getName() { + return ""; } - } + @Override + public T getCapability(Class clazz) { + return null; + } + }; } } } diff -r 1319b704541d -r 861f8d5a5153 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java --- /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 getCapability(Class clazz) { + return null; + } +} diff -r 1319b704541d -r 861f8d5a5153 mx/projects --- 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 diff -r 1319b704541d -r 861f8d5a5153 src/share/vm/graal/graalRuntime.cpp --- /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 diff -r 1319b704541d -r 861f8d5a5153 src/share/vm/prims/nativeLookup.cpp --- 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) {