changeset 15873:6dcf8ab4ad86

HotSpotOptions.inline.hpp generator writes to System.out to make generator errors more visible (they will show up when compiling the generated source)
author Doug Simon <doug.simon@oracle.com>
date Sat, 24 May 2014 00:46:33 +0200
parents b7fc7cdb9005
children 70bb12bdd178
files graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotOptionsLoader.java mx/mx_graal.py
diffstat 2 files changed, 33 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotOptionsLoader.java	Sat May 24 00:25:29 2014 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotOptionsLoader.java	Sat May 24 00:46:33 2014 +0200
@@ -58,30 +58,31 @@
     }
 
     /**
-     * Command line utility for generating the source code of GraalRuntime::set_option().
-     *
-     * @param args one element array with the path of the source file to be created
+     * Command line utility for generating the source code of GraalRuntime::set_option() which is
+     * written {@link System#out}.
      */
-    public static void main(String[] args) throws Exception {
-        File outputFile = new File(args[0]);
-        PrintStream out = new PrintStream(outputFile);
-        Set<Integer> lengths = new TreeSet<>();
-        for (String s : options.keySet()) {
-            lengths.add(s.length());
+    public static void main(String[] args) {
+        PrintStream out = System.out;
+        try {
+            Set<Integer> lengths = new TreeSet<>();
+            for (String s : options.keySet()) {
+                lengths.add(s.length());
+            }
+            lengths.add("PrintFlags".length());
+
+            out.println("bool GraalRuntime::set_option(KlassHandle hotSpotOptionsClass, const char* name, int name_len, Handle name_handle, const char* value, TRAPS) {");
+            out.println("  if (value[0] == '+' || value[0] == '-') {");
+            out.println("    // boolean options");
+            genMatchers(out, lengths, true);
+            out.println("  } else {");
+            out.println("    // non-boolean options");
+            genMatchers(out, lengths, false);
+            out.println("  }");
+            out.println("  return false;");
+            out.println("}");
+        } catch (Throwable t) {
+            t.printStackTrace(out);
         }
-        lengths.add("PrintFlags".length());
-
-        out.println("bool GraalRuntime::set_option(KlassHandle hotSpotOptionsClass, const char* name, int name_len, Handle name_handle, const char* value, TRAPS) {");
-        out.println("  if (value[0] == '+' || value[0] == '-') {");
-        out.println("    // boolean options");
-        genMatchers(out, lengths, true);
-        out.println("  } else {");
-        out.println("    // non-boolean options");
-        genMatchers(out, lengths, false);
-        out.println("  }");
-        out.println("  return false;");
-        out.println("}");
-
         out.flush();
     }
 
--- a/mx/mx_graal.py	Sat May 24 00:25:29 2014 +0200
+++ b/mx/mx_graal.py	Sat May 24 00:46:33 2014 +0200
@@ -491,23 +491,16 @@
     hsSrcGenDir = join(p.source_gen_dir(), 'hotspot')
     if not exists(hsSrcGenDir):
         os.makedirs(hsSrcGenDir)
-    path = join(hsSrcGenDir, 'HotSpotOptions.inline.hpp')
-    fd, tmp = tempfile.mkstemp(suffix='', prefix='HotSpotOptions.inline.hpp', dir=hsSrcGenDir)
-    os.close(fd)
-    try:
-        retcode = mx.run_java(['-cp', graalJar, mainClass, tmp], nonZeroIsFatal=False)
-        if retcode != 0:
-            # Suppress the error if it's because the utility class isn't compiled yet
-            with zipfile.ZipFile(graalJar, 'r') as zf:
-                mainClassFile = mainClass.replace('.', '/') + '.class'
-                if mainClassFile not in zf.namelist():
-                    return
-            mx.abort(retcode)
-        with open(tmp) as fp:
-            content = fp.read()
-        mx.update_file(path, content)
-    finally:
-        os.remove(tmp)
+    tmp = StringIO.StringIO()
+    retcode = mx.run_java(['-cp', graalJar, mainClass], out=tmp.write, nonZeroIsFatal=False)
+    if retcode != 0:
+        # Suppress the error if it's because the utility class isn't compiled yet
+        with zipfile.ZipFile(graalJar, 'r') as zf:
+            mainClassFile = mainClass.replace('.', '/') + '.class'
+            if mainClassFile not in zf.namelist():
+                return
+        mx.abort(retcode)
+    mx.update_file(join(hsSrcGenDir, 'HotSpotOptions.inline.hpp'), tmp.getvalue())
 
 def _installGraalJarInJdks(graalDist):
     graalJar = graalDist.path