changeset 16623:addc0564e5b5

split com.oracle.graal.truffle.* projects into a separate graal-truffle.jar and added truffle.jar to the boot class path
author Doug Simon <doug.simon@oracle.com>
date Wed, 30 Jul 2014 18:27:06 +0200
parents faaea970b951
children c9284d733aa1
files graal/com.oracle.graal.hotspot.loader/src/com/oracle/graal/hotspot/loader/Factory.java graal/com.oracle.graal.hotspot.sourcegen/src/com/oracle/graal/hotspot/sourcegen/GenGraalRuntimeInlineHpp.java graal/com.oracle.graal.hotspot.sourcegen/src/com/oracle/graal/hotspot/sourcegen/OptionsVerifier.java mx/mx_graal.py mx/projects mxtool/mx.py src/share/vm/graal/graalRuntime.hpp src/share/vm/runtime/arguments.cpp src/share/vm/runtime/os.cpp
diffstat 9 files changed, 90 insertions(+), 51 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.hotspot.loader/src/com/oracle/graal/hotspot/loader/Factory.java	Wed Jul 30 13:42:10 2014 +0200
+++ b/graal/com.oracle.graal.hotspot.loader/src/com/oracle/graal/hotspot/loader/Factory.java	Wed Jul 30 18:27:06 2014 +0200
@@ -26,27 +26,29 @@
 import java.net.*;
 
 /**
- * Utility to create a separate class loader for loading classes in {@code graal.jar}.
+ * Utility to create a separate class loader for loading classes in {@code graal.jar} and
+ * {@code graal-truffle.jar}.
  */
 public class Factory {
 
     /**
-     * Creates a new class loader for loading classes in {@code graal.jar}.
+     * Creates a new class loader for loading classes in {@code graal.jar} and
+     * {@code graal-truffle.jar}
      *
      * Called from the VM.
      */
     @SuppressWarnings("unused")
     private static ClassLoader newClassLoader() throws MalformedURLException {
-        URL[] urls = {getGraalJarUrl()};
+        URL[] urls = {getGraalJarUrl("graal"), getGraalJarUrl("graal-truffle")};
         return URLClassLoader.newInstance(urls);
     }
 
     /**
-     * Gets the URL for {@code graal.jar}.
+     * Gets the URL for {@code base.jar}.
      */
-    private static URL getGraalJarUrl() throws MalformedURLException {
+    private static URL getGraalJarUrl(String base) throws MalformedURLException {
         File file = new File(System.getProperty("java.home"));
-        for (String name : new String[]{"lib", "graal.jar"}) {
+        for (String name : new String[]{"lib", base + ".jar"}) {
             file = new File(file, name);
         }
 
--- a/graal/com.oracle.graal.hotspot.sourcegen/src/com/oracle/graal/hotspot/sourcegen/GenGraalRuntimeInlineHpp.java	Wed Jul 30 13:42:10 2014 +0200
+++ b/graal/com.oracle.graal.hotspot.sourcegen/src/com/oracle/graal/hotspot/sourcegen/GenGraalRuntimeInlineHpp.java	Wed Jul 30 18:27:06 2014 +0200
@@ -37,26 +37,46 @@
  */
 public class GenGraalRuntimeInlineHpp {
 
-    private static final ZipFile graalJar;
+    public static class GraalJars implements Iterable<ZipEntry> {
+        private final List<ZipFile> jars = new ArrayList<>(2);
 
-    static {
-        String path = null;
-        String classPath = System.getProperty("java.class.path");
-        for (String e : classPath.split(File.pathSeparator)) {
-            if (e.endsWith("graal.jar")) {
-                path = e;
-                break;
+        public GraalJars() {
+            String classPath = System.getProperty("java.class.path");
+            for (String e : classPath.split(File.pathSeparator)) {
+                if (e.endsWith(File.separatorChar + "graal.jar") || e.endsWith(File.separatorChar + "graal-truffle.jar")) {
+                    try {
+                        jars.add(new ZipFile(e));
+                    } catch (IOException ioe) {
+                        throw new InternalError(ioe);
+                    }
+                }
+            }
+            if (jars.size() != 2) {
+                throw new InternalError("Could not find graal.jar or graal-truffle.jar on class path: " + classPath);
             }
         }
-        ZipFile zipFile = null;
-        try {
-            zipFile = new ZipFile(Objects.requireNonNull(path, "Could not find graal.jar on class path: " + classPath));
-        } catch (IOException e) {
-            throw new InternalError(e);
+
+        public Iterator<ZipEntry> iterator() {
+            List<ZipEntry> entries = new ArrayList<>();
+            for (ZipFile jar : jars) {
+                entries.addAll(Collections.list(jar.entries()));
+            }
+            return entries.iterator();
         }
-        graalJar = zipFile;
+
+        public InputStream getInputStream(String classFilePath) throws IOException {
+            for (ZipFile jar : jars) {
+                ZipEntry entry = jar.getEntry(classFilePath);
+                if (entry != null) {
+                    return jar.getInputStream(entry);
+                }
+            }
+            return null;
+        }
     }
 
+    private static final GraalJars graalJars = new GraalJars();
+
     public static void main(String[] args) {
         PrintStream out = System.out;
         try {
@@ -73,8 +93,7 @@
      */
     private static void genGetServiceImpls(PrintStream out) throws Exception {
         final List<Class<? extends Service>> services = new ArrayList<>();
-        for (final Enumeration<? extends ZipEntry> e = graalJar.entries(); e.hasMoreElements();) {
-            final ZipEntry zipEntry = e.nextElement();
+        for (ZipEntry zipEntry : graalJars) {
             String name = zipEntry.getName();
             if (name.startsWith("META-INF/services/")) {
                 String serviceName = name.substring("META-INF/services/".length());
@@ -223,7 +242,7 @@
         Set<Class<?>> checked = new HashSet<>();
         for (final OptionDescriptor option : options.values()) {
             Class<?> cls = option.getDeclaringClass();
-            OptionsVerifier.checkClass(cls, option, checked, graalJar);
+            OptionsVerifier.checkClass(cls, option, checked, graalJars);
         }
         return options;
     }
--- a/graal/com.oracle.graal.hotspot.sourcegen/src/com/oracle/graal/hotspot/sourcegen/OptionsVerifier.java	Wed Jul 30 13:42:10 2014 +0200
+++ b/graal/com.oracle.graal.hotspot.sourcegen/src/com/oracle/graal/hotspot/sourcegen/OptionsVerifier.java	Wed Jul 30 18:27:06 2014 +0200
@@ -27,11 +27,11 @@
 import java.io.*;
 import java.lang.reflect.*;
 import java.util.*;
-import java.util.zip.*;
 
 import jdk.internal.org.objectweb.asm.*;
 import jdk.internal.org.objectweb.asm.Type;
 
+import com.oracle.graal.hotspot.sourcegen.GenGraalRuntimeInlineHpp.GraalJars;
 import com.oracle.graal.options.*;
 
 /**
@@ -42,17 +42,16 @@
  */
 final class OptionsVerifier extends ClassVisitor {
 
-    public static void checkClass(Class<?> cls, OptionDescriptor option, Set<Class<?>> checked, ZipFile graalJar) throws IOException {
+    public static void checkClass(Class<?> cls, OptionDescriptor option, Set<Class<?>> checked, GraalJars graalJars) throws IOException {
         if (!checked.contains(cls)) {
             checked.add(cls);
             Class<?> superclass = cls.getSuperclass();
             if (superclass != null && !superclass.equals(Object.class)) {
-                checkClass(superclass, option, checked, graalJar);
+                checkClass(superclass, option, checked, graalJars);
             }
 
             String classFilePath = cls.getName().replace('.', '/') + ".class";
-            ZipEntry entry = Objects.requireNonNull(graalJar.getEntry(classFilePath), "Could not find class file for " + cls.getName());
-            ClassReader cr = new ClassReader(graalJar.getInputStream(entry));
+            ClassReader cr = new ClassReader(Objects.requireNonNull(graalJars.getInputStream(classFilePath), "Could not find class file for " + cls.getName()));
 
             ClassVisitor cv = new OptionsVerifier(cls, option);
             cr.accept(cv, 0);
--- a/mx/mx_graal.py	Wed Jul 30 13:42:10 2014 +0200
+++ b/mx/mx_graal.py	Wed Jul 30 18:27:06 2014 +0200
@@ -380,7 +380,7 @@
             return
     mx.abort('You need to run "mx --vm ' + vm + ' --vmbuild ' + bld + ' build" to build the selected VM')
 
-def _jdk(build='product', vmToCheck=None, create=False, installGraalJar=True):
+def _jdk(build='product', vmToCheck=None, create=False, installJars=True):
     """
     Get the JDK into which Graal is installed, creating it first if necessary.
     """
@@ -457,9 +457,11 @@
                 mx.log("The selected JDK directory does not (yet) exist: " + jdk)
             _handle_missing_VM(build, vmToCheck if vmToCheck else 'graal')
 
-    if installGraalJar:
-        _installGraalJarInJdks(mx.distribution('GRAAL'))
-        _installGraalJarInJdks(mx.distribution('GRAAL_LOADER'))
+    if installJars:
+        _installDistInJdks(mx.distribution('GRAAL'))
+        _installDistInJdks(mx.distribution('GRAAL_LOADER'))
+        _installDistInJdks(mx.distribution('TRUFFLE'))
+        _installDistInJdks(mx.distribution('GRAAL_TRUFFLE'))
 
     if vmToCheck is not None:
         jvmCfg = _vmCfgInJdk(jdk)
@@ -491,13 +493,13 @@
     return hsSrcGenDir
 
 
-def _update_graalRuntime_inline_hpp(graalJar):
+def _update_graalRuntime_inline_hpp(jars):
     p = mx.project('com.oracle.graal.hotspot.sourcegen')
     mainClass = 'com.oracle.graal.hotspot.sourcegen.GenGraalRuntimeInlineHpp'
     if exists(join(p.output_dir(), mainClass.replace('.', os.sep) + '.class')):
         graalRuntime_inline_hpp = join(_makeHotspotGeneratedSourcesDir(), 'graalRuntime.inline.hpp')
         tmp = StringIO.StringIO()
-        mx.run_java(['-cp', '{}{}{}'.format(graalJar, os.pathsep, p.output_dir()), mainClass], out=tmp.write)
+        mx.run_java(['-cp', '{}{}{}'.format(os.pathsep.join(jars), os.pathsep, p.output_dir()), mainClass], out=tmp.write)
         mx.update_file(graalRuntime_inline_hpp, tmp.getvalue())
 
 def _checkVMIsNewerThanGeneratedSources(jdk, vm, bld):
@@ -509,10 +511,15 @@
                 mx.log('The VM ' + vmLib.path + ' is older than ' + genSrc)
                 mx.abort('You need to run "mx --vm ' + vm + ' --vmbuild ' + bld + ' build"')
 
-def _installGraalJarInJdks(graalDist):
-    graalJar = graalDist.path
-    if graalJar.endswith('graal.jar'):
-        _update_graalRuntime_inline_hpp(graalJar)
+def _installDistInJdks(dist):
+    """
+    Installs the jar(s) for a given Distribution into all existing Graal JDKs
+    """
+
+    distJar = dist.path
+    if dist.name == 'GRAAL_TRUFFLE':
+        jars = [mx.distribution(d).path for d in dist.distDependencies] + [distJar]
+        _update_graalRuntime_inline_hpp(jars)
     jdks = _jdksDir()
 
     if exists(jdks):
@@ -524,7 +531,7 @@
                     dstJar = join(dstDir, name)
                     if mx.get_env('SYMLINK_GRAAL_JAR', None) == 'true':
                         # Using symlinks is much faster than copying but may
-                        # cause issues if graal.jar is being updated while
+                        # cause issues if the jar is being updated while
                         # the VM is running.
                         if not os.path.islink(dstJar) or not os.path.realpath(dstJar) == srcJar:
                             if exists(dstJar):
@@ -538,9 +545,9 @@
                         shutil.move(tmp, dstJar)
                         os.chmod(dstJar, JDK_UNIX_PERMISSIONS)
 
-                install(graalJar, jreLibDir)
-                if graalDist.sourcesPath:
-                    install(graalDist.sourcesPath, join(jdks, e))
+                install(distJar, jreLibDir)
+                if dist.sourcesPath:
+                    install(dist.sourcesPath, join(jdks, e))
 
 # run a command in the windows SDK Debug Shell
 def _runInDebugShell(cmd, workingDir, logFile=None, findInOutput=None, respondTo=None):
@@ -605,7 +612,7 @@
 def jdkhome(vm=None):
     """return the JDK directory selected for the 'vm' command"""
     build = _vmbuild if _vmSourcesAvailable else 'product'
-    return _jdk(build, installGraalJar=False)
+    return _jdk(build, installJars=False)
 
 def print_jdkhome(args, vm=None):
     """print the JDK directory selected for the 'vm' command"""
@@ -912,7 +919,7 @@
         mx.abort("conflicting working directories: do not set --vmcwd for this command")
 
     build = vmbuild if vmbuild is not None else _vmbuild if _vmSourcesAvailable else 'product'
-    jdk = _jdk(build, vmToCheck=vm, installGraalJar=False)
+    jdk = _jdk(build, vmToCheck=vm, installJars=False)
     _updateInstalledGraalOptionsFile(jdk)
     _checkVMIsNewerThanGeneratedSources(jdk, vm, build)
     mx.expand_project_in_args(args)
@@ -2234,5 +2241,7 @@
     global _vm_prefix
     _vm_prefix = opts.vm_prefix
 
-    mx.distribution('GRAAL').add_update_listener(_installGraalJarInJdks)
-    mx.distribution('GRAAL_LOADER').add_update_listener(_installGraalJarInJdks)
+    mx.distribution('GRAAL').add_update_listener(_installDistInJdks)
+    mx.distribution('GRAAL_LOADER').add_update_listener(_installDistInJdks)
+    mx.distribution('TRUFFLE').add_update_listener(_installDistInJdks)
+    mx.distribution('GRAAL_TRUFFLE').add_update_listener(_installDistInJdks)
--- a/mx/projects	Wed Jul 30 13:42:10 2014 +0200
+++ b/mx/projects	Wed Jul 30 18:27:06 2014 +0200
@@ -88,8 +88,6 @@
 distribution@GRAAL@dependencies=\
 com.oracle.graal.hotspot.amd64,\
 com.oracle.graal.hotspot.ptx,\
-com.oracle.graal.truffle,\
-com.oracle.graal.truffle.hotspot.amd64,\
 com.oracle.graal.hotspot.sparc,\
 com.oracle.graal.hotspot,\
 com.oracle.graal.hotspot.jfr,\
@@ -107,6 +105,15 @@
 distribution@TRUFFLE@dependencies=\
 com.oracle.truffle.api.dsl
 
+distribution@GRAAL_TRUFFLE@path=graal-truffle.jar
+distribution@GRAAL_TRUFFLE@subDir=graal
+distribution@GRAAL_TRUFFLE@sourcesPath=graal-truffle-sources.jar
+distribution@GRAAL_TRUFFLE@dependencies=\
+com.oracle.graal.truffle,\
+com.oracle.graal.truffle.hotspot.amd64
+distribution@GRAAL_TRUFFLE@exclude=FINDBUGS
+distribution@GRAAL_TRUFFLE@distDependencies=GRAAL,TRUFFLE
+
 distribution@TRUFFLE-DSL-PROCESSOR@path=truffle-dsl-processor.jar
 distribution@TRUFFLE-DSL-PROCESSOR@subDir=graal
 distribution@TRUFFLE-DSL-PROCESSOR@sourcesPath=truffle-dsl-processor-sources.jar
--- a/mxtool/mx.py	Wed Jul 30 13:42:10 2014 +0200
+++ b/mxtool/mx.py	Wed Jul 30 18:27:06 2014 +0200
@@ -3496,10 +3496,12 @@
         out.open('projects')
         for p in distProjects:
             out.element('project', data=p.name)
+        for d in dist.distDependencies:
+            out.element('project', data=d)
         out.close('projects')
         out.open('buildSpec')
         dist.dir = projectDir
-        dist.javaCompliance = max([p.javaCompliance for p in distProjects])
+        dist.javaCompliance = max([p.javaCompliance for p in distProjects] + [JavaCompliance('1.8')])
         _genEclipseBuilder(out, dist, 'Create' + dist.name + 'Dist', 'archive @' + dist.name, relevantResources=relevantResources, logToFile=True, refresh=False, async=True)
         out.close('buildSpec')
         out.open('natures')
--- a/src/share/vm/graal/graalRuntime.hpp	Wed Jul 30 13:42:10 2014 +0200
+++ b/src/share/vm/graal/graalRuntime.hpp	Wed Jul 30 18:27:06 2014 +0200
@@ -173,7 +173,7 @@
   static Klass* load_required_class(Symbol* name);
 
   /**
-   * Creates a separate class loader for classes in graal.jar.
+   * Creates a separate class loader for classes in graal.jar and graal-truffle.jar.
    */
   static oop compute_graal_class_loader(TRAPS);
 
--- a/src/share/vm/runtime/arguments.cpp	Wed Jul 30 13:42:10 2014 +0200
+++ b/src/share/vm/runtime/arguments.cpp	Wed Jul 30 18:27:06 2014 +0200
@@ -3252,7 +3252,7 @@
   if (!UseGraalClassLoader) {
     // Append graal.jar to boot class path
     const char* home = Arguments::get_java_home();
-    scp_p->add_suffix(os::format_boot_path("%/lib/graal.jar", home, (int)strlen(home), os::file_separator()[0], os::path_separator()[0]));
+    scp_p->add_suffix(os::format_boot_path("%/lib/graal.jar:%/lib/graal-truffle.jar", home, (int)strlen(home), os::file_separator()[0], os::path_separator()[0]));
     scp_assembly_required = true;
   }
 #endif
--- a/src/share/vm/runtime/os.cpp	Wed Jul 30 13:42:10 2014 +0200
+++ b/src/share/vm/runtime/os.cpp	Wed Jul 30 18:27:06 2014 +0200
@@ -1269,6 +1269,7 @@
 #endif
 #ifdef GRAAL
         "%/lib/graal-loader.jar:"
+        "%/lib/truffle.jar:"
 #endif
         "%/classes";
     char* sysclasspath = format_boot_path(classpath_format, home, home_len, fileSep, pathSep);