changeset 23255:77feea4fe00c

re-added JVMCI library and generate it JVMCI classes in JDK9
author Doug Simon <doug.simon@oracle.com>
date Mon, 04 Jan 2016 13:48:37 +0100
parents dba757ef0c79
children 907a1859f51d
files mx.graal/mx_graal_9.py mx.graal/suite.py
diffstat 2 files changed, 116 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/mx.graal/mx_graal_9.py	Mon Jan 04 12:17:38 2016 +0100
+++ b/mx.graal/mx_graal_9.py	Mon Jan 04 13:48:37 2016 +0100
@@ -25,7 +25,7 @@
 # ----------------------------------------------------------------------------------------------------
 
 import os
-from os.path import join
+from os.path import join, exists, abspath
 from argparse import ArgumentParser
 import sanitycheck
 import re
@@ -334,6 +334,13 @@
 
     args = ['-Xbootclasspath/p:' + os.pathsep.join(bcp)] + args
 
+    # Remove JVMCI from class path. It's only there to support compilation.
+    cpIndex, cp = mx.find_classpath_arg(args)
+    if cp:
+        jvmciLib = mx.library('JVMCI').path
+        cp = os.pathsep.join([e for e in cp.split(os.pathsep) if e != jvmciLib])
+        args[cpIndex] = cp
+
     # Set the default JVMCI compiler
     jvmciCompiler = _compilers[-1]
     args = ['-Djvmci.compiler=' + jvmciCompiler] + args
@@ -418,3 +425,69 @@
         _vm.update(opts.jvmci_mode)
     for dist in [d.dist() for d in _bootClasspathDists]:
         dist.set_archiveparticipant(GraalArchiveParticipant(dist))
+
+def _update_JVMCI_library():
+    """
+    Updates the "path" and "sha1" attributes of the "JVMCI" library to
+    refer to a jvmci.jar created from the JVMCI classes in JDK9.
+    """
+    suiteDict = _suite.suiteDict
+    jvmciLib = suiteDict['libraries']['JVMCI']
+    d = join(_suite.get_output_root(), abspath(_jdk.home)[1:])
+    path = join(d, 'jvmci.jar')
+    if not exists(path):
+        explodedModule = join(_jdk.home, 'modules', 'jdk.vm.ci')
+        if exists(explodedModule):
+            with mx.Archiver(path, kind='zip') as arc:
+                for root, _, files in os.walk(explodedModule):
+                    relpath = root[len(explodedModule) + 1:]
+                    for f in files:
+                        arcname = join(relpath, f).replace(os.sep, '/')
+                        with open(join(root, f), 'rb') as fp:
+                            contents = fp.read()
+                            arc.zf.writestr(arcname, contents)
+        else:
+            # Use the jdk.internal.jimage utility since it's the only way
+            # (currently) to read .jimage files and unfortunately the
+            # JDK9 jimage tool does not support partial extraction.
+            bootmodules = join(_jdk.home, 'lib', 'modules', 'bootmodules.jimage')
+            if not exists(bootmodules):
+                mx.abort('Could not find JVMCI classes at ' + bootmodules + ' or ' + explodedModule)
+            mx.ensure_dir_exists(d)
+            javaSource = join(d, 'ExtractJVMCI.java')
+            with open(javaSource, 'w') as fp:
+                print >> fp, """import java.io.FileOutputStream;
+import java.util.jar.JarEntry;
+import java.util.jar.JarOutputStream;
+import jdk.internal.jimage.BasicImageReader;
+
+public class ExtractJVMCI {
+    public static void main(String[] args) throws Exception {
+        BasicImageReader image = BasicImageReader.open(args[0]);
+        String[] names = image.getEntryNames();
+        if (names.length == 0) {
+            return;
+        }
+        try (JarOutputStream jos = new JarOutputStream(new FileOutputStream(args[1]))) {
+            for (String name : names) {
+                if (name.startsWith("/jdk.vm.ci/")) {
+                    String ename = name.substring("/jdk.vm.ci/".length());
+                    JarEntry je = new JarEntry(ename);
+                    jos.putNextEntry(je);
+                    jos.write(image.getResource(name));
+                    jos.closeEntry();
+                }
+            }
+        }
+    }
+}
+"""
+            mx.run([_jdk.javac, '-d', d, javaSource])
+            mx.run([_jdk.java, '-cp', d, 'ExtractJVMCI', bootmodules, path])
+            if not exists(path):
+                mx.abort('Could not find the JVMCI classes in ' + bootmodules)
+
+    jvmciLib['path'] = path
+    jvmciLib['sha1'] = mx.sha1OfFile(path)
+
+_update_JVMCI_library()
--- a/mx.graal/suite.py	Mon Jan 04 12:17:38 2016 +0100
+++ b/mx.graal/suite.py	Mon Jan 04 13:48:37 2016 +0100
@@ -2,8 +2,29 @@
 JDK9 = mx.get_jdk(tag='default').javaCompliance >= "1.9"
 
 def deps(l):
-    """ Filters out dependencies starting with 'jvmci:' if using JDK9. """
-    return [d for d in l if not JDK9 or not d.startswith("jvmci:")]
+    """
+    If using JDK9, replaces dependencies starting with 'jvmci:' with 'JVMCI'.
+    Otherwise, excludes "JVMCI".
+    """
+    if JDK9:
+        res = []
+        for e in l:
+            if e.startswith("jvmci:"):
+                if not "JVMCI" in res:
+                    res.append("JVMCI")
+            else:
+                res.append(e)
+        return res
+    else:
+        return [d for d in l if d != "JVMCI"]
+
+def libs(d):
+    """
+    If not using JDK9, excludes "JVMCI" library.
+    """
+    if not JDK9:
+        del d["JVMCI"]
+    return d
 
 def suites(l):
     """ Filters out suites named 'jvmci' if using JDK9. """
@@ -37,7 +58,7 @@
 
   "defaultLicense" : "GPLv2-CPE",
 
-  "libraries" : {
+  "libraries" : libs({
 
     # ------------- Libraries -------------
 
@@ -69,7 +90,16 @@
       "sourceSha1" : "12a67f0dcdfe7e43218bf38c1d7fd766122a3dc7",
       "sourceUrls" : ["https://lafo.ssw.uni-linz.ac.at/pub/jmh/jmh-runner-1.11.2-sources.jar"],
     },
-  },
+
+    # This is a library synthesized from the JVMCI classes in JDK9.
+    # It enables Graal to be compiled against JVMCI when targeting JDK8.
+    # (i.e., compiled with javac option -target 1.8).
+    # The "path" and "sha1" attributes are added when mx_graal_9 is loaded
+    # (see mx_graal_9._update_JVMCI_library()).
+    "JVMCI" : {
+        "license" : "GPLv2-CPE",
+     },
+  }),
 
   "projects" : {
 
@@ -782,8 +812,8 @@
       "subDir" : "graal",
       "sourceDirs" : ["src"],
       "dependencies" : [
-	 "com.oracle.graal.loop",
-	 "com.oracle.graal.phases.common",
+     "com.oracle.graal.loop",
+     "com.oracle.graal.phases.common",
        ],
       "annotationProcessors" : ["GRAAL_OPTIONS_PROCESSOR"],
       "checkstyle" : "com.oracle.graal.graph",
@@ -1138,6 +1168,7 @@
         "com.oracle.graal.api.runtime",
         "com.oracle.graal.graph",
       ],
+      "exclude" : deps(["JVMCI"]),
       "distDependencies" : deps([
         "jvmci:JVMCI_API",
         "GRAAL_NODEINFO",
@@ -1150,6 +1181,7 @@
       "dependencies" : [
         "com.oracle.graal.compiler",
       ],
+      "exclude" : deps(["JVMCI"]),
       "distDependencies" : [
         "GRAAL_API",
         "GRAAL_SERVICEPROVIDER",
@@ -1171,6 +1203,7 @@
         "com.oracle.graal.replacements.sparc",
         "com.oracle.graal.salver",
       ],
+      "exclude" : deps(["JVMCI"]),
       "distDependencies" : [
         "GRAAL_API",
         "GRAAL_COMPILER",
@@ -1185,6 +1218,7 @@
         "com.oracle.graal.hotspot.sparc",
         "com.oracle.graal.hotspot",
       ],
+      "exclude" : deps(["JVMCI"]),
       "distDependencies" : deps([
         "jvmci:JVMCI_HOTSPOT",
         "GRAAL_COMPILER",
@@ -1218,6 +1252,7 @@
       "exclude" : deps([
         "mx:JUNIT",
         "JAVA_ALLOCATION_INSTRUMENTER",
+        "JVMCI"
       ]),
     },
 
@@ -1344,6 +1379,7 @@
         "com.oracle.graal.truffle.hotspot.amd64",
         "com.oracle.graal.truffle.hotspot.sparc"
       ],
+      "exclude" : ["JVMCI"],
       "distDependencies" : [
         "truffle:TRUFFLE_API",
       ],