changeset 4155:394404b2d9bd

Removed strict requirement for GRAAL environment variable. It only needs to be set now if the graal directory is not in the directory hierarchy of GraalVM JDK.
author Doug Simon <doug.simon@oracle.com>
date Wed, 21 Dec 2011 11:25:27 +0100
parents 9a4f210abb5e
children 843c8d6720da
files mx/commands.py src/share/vm/runtime/arguments.cpp
diffstat 2 files changed, 90 insertions(+), 64 deletions(-) [+]
line wrap: on
line diff
--- a/mx/commands.py	Tue Dec 20 15:59:32 2011 +0100
+++ b/mx/commands.py	Wed Dec 21 11:25:27 2011 +0100
@@ -107,32 +107,48 @@
             mx.abort("Sanity checks FAILED")
     mx.log("Sanity checks PASSED")
     
-def _jdk7(build='product', create=False):
-    jdk7 = join(_graal_home, 'jdk1.7.0')
-    if not exists(jdk7):
-        # Assume we are running with a JDK7
-        assert mx.java().version.startswith('1.7')
+def _jdk(build='product', create=False):
+    """
+    Get the JDK into which Graal is installed, creating it first if necessary.
+    """
+    jdk = join(_graal_home, 'jdk' + mx.java().version)
+    if not exists(jdk):
         srcJdk = mx.java().jdk
-        mx.log('Creating ' + jdk7 + ' from ' + srcJdk)
-        os.mkdir(jdk7)
+        mx.log('Creating ' + jdk + ' from ' + srcJdk)
+        os.mkdir(jdk)
         for d in ['bin', 'db', 'include', 'jre', 'lib', 'man']:
             src = join(srcJdk, d)
-            dst = join(jdk7, d)
+            dst = join(jdk, d)
             if not exists(src):
-                mx.abort('Host JDK 7 directory is missing: ' + src)
+                mx.abort('Host JDK directory is missing: ' + src)
             shutil.copytree(src, dst)
     
+    jvmCfg = join(jdk, 'jre', 'lib', 'amd64', 'jvm.cfg')
+    found = False
+    if not exists(jvmCfg):
+        mx.abort(jvmCfg + ' does not exist')
+        
+    with open(jvmCfg) as f:
+        for line in f:
+            if '-graal KNOWN' in line:
+                found = True
+                break
+    if not found:
+        mx.log('Appending "-graal KNOWN" to ' + jvmCfg)
+        with open(jvmCfg, 'a') as f:
+            f.write('-graal KNOWN\n')
+    
     if build == 'product':
-        return jdk7
+        return jdk
     elif build in ['debug', 'fastdebug', 'optimized']:
-        res = join(jdk7, build)
+        res = join(jdk, build)
         if not exists(res):
             if not create:
                 mx.abort('The ' + build + ' VM has not been created - run \'mx clean; mx make ' + build + '\'') 
             mx.log('Creating ' + res)
             os.mkdir(res)
             for d in ['bin', 'db', 'include', 'jre', 'lib', 'man']:
-                shutil.copytree(join(jdk7, d), join(res, d))
+                shutil.copytree(join(jdk, d), join(res, d))
         return res
     else:
         mx.abort('Unknown build type: ' + build)
@@ -149,30 +165,11 @@
     # Call mx.build to compile the Java sources        
     mx.build(args + ['--source', '1.7'])
 
-    def fix_jvm_cfg(jdk):
-        jvmCfg = join(jdk, 'jre', 'lib', 'amd64', 'jvm.cfg')
-        found = False
-        if not exists(jvmCfg):
-            mx.abort(jvmCfg + ' does not exist')
-            
-        with open(jvmCfg) as f:
-            for line in f:
-                if '-graal KNOWN' in line:
-                    found = True
-                    break
-        if not found:
-            mx.log('Appending "-graal KNOWN" to ' + jvmCfg)
-            with open(jvmCfg, 'a') as f:
-                f.write('-graal KNOWN\n')
-
-    
-    jdk7 = _jdk7(build, True)
+    jdk = _jdk(build, True)
     if build == 'debug':
         build = 'jvmg'
     
-    fix_jvm_cfg(jdk7)
-
-    graalVmDir = join(jdk7, 'jre', 'lib', 'amd64', 'graal')
+    graalVmDir = join(jdk, 'jre', 'lib', 'amd64', 'graal')
     if not exists(graalVmDir):
         mx.log('Creating Graal directory in JDK7: ' + graalVmDir)
         os.makedirs(graalVmDir)
@@ -181,7 +178,7 @@
         if not 'Xusage.txt' in line:
             sys.stderr.write(line + os.linesep)
             
-    os.environ.update(ARCH_DATA_MODEL='64', LANG='C', HOTSPOT_BUILD_JOBS='3', ALT_BOOTDIR=jdk7, INSTALL='y')
+    os.environ.update(ARCH_DATA_MODEL='64', LANG='C', HOTSPOT_BUILD_JOBS='3', ALT_BOOTDIR=jdk, INSTALL='y')
     mx.run([mx.gmake_cmd(), build + 'graal'], cwd=join(_graal_home, 'make'), err=filterXusage)
     
 def vm(args, vm='-graal', nonZeroIsFatal=True, out=None, err=None, cwd=None):
@@ -190,8 +187,7 @@
     build = _vmbuild
     if mx.java().debug:
         args = ['-Xdebug', '-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000'] + args
-    os.environ['GRAAL'] = join(_graal_home, 'graal')
-    exe = join(_jdk7(build), 'bin', mx.exe_suffix('java'))
+    exe = join(_jdk(build), 'bin', mx.exe_suffix('java'))
     return mx.run([exe, vm] + args, nonZeroIsFatal=nonZeroIsFatal, out=out, err=err, cwd=cwd)
 
 def ideinit(args):
--- a/src/share/vm/runtime/arguments.cpp	Tue Dec 20 15:59:32 2011 +0100
+++ b/src/share/vm/runtime/arguments.cpp	Wed Dec 21 11:25:27 2011 +0100
@@ -2011,6 +2011,45 @@
 
 // Parse JavaVMInitArgs structure
 
+static void prepend_to_graal_classpath(SysClassPath &cp, const char* graal_dir, const char* project) {
+  const int BUFFER_SIZE = 1024;
+  char path[BUFFER_SIZE];
+
+  sprintf(path, "%s/%s/bin", graal_dir, project);
+  DIR* dir = os::opendir(path);
+  if (dir == NULL) {
+    jio_fprintf(defaultStream::output_stream(), "Error while starting Graal VM: The Graal class directory %s could not be opened.\n", path);
+    vm_exit(1);
+  }
+  os::closedir(dir);
+  cp.add_prefix(path);
+}
+
+// Walk up the directory hierarchy starting from JAVA_HOME looking
+// for a directory named "graal". If found, then the full path to
+// this directory is returned in graal_dir.
+static bool find_graal_dir(char* graal_dir) {
+  strcpy(graal_dir, Arguments::get_java_home());
+  char* end = graal_dir + strlen(graal_dir);
+  while (end != graal_dir) {
+    strcat(graal_dir, "/graal");
+    DIR* dir = os::opendir(graal_dir);
+    if (dir != NULL) {
+      os::closedir(dir);
+      return true;
+    }
+    *end = 0;
+    while (end != graal_dir) {
+      if (*end == '/') {
+        *end = 0;
+        break;
+      }
+      end--;
+    }
+  }
+  return false;
+}
+
 jint Arguments::parse_vm_init_args(const JavaVMInitArgs* args) {
   // For components of the system classpath.
   SysClassPath scp(Arguments::get_sysclasspath());
@@ -2043,37 +2082,28 @@
     }
     const int BUFFER_SIZE = 1024;
     char graal_dir[BUFFER_SIZE];
-    char temp[BUFFER_SIZE];
     if (!os::getenv("GRAAL", graal_dir, sizeof(graal_dir))) {
-      jio_fprintf(defaultStream::output_stream(), "Error while starting Graal VM: The GRAAL environment variable needs to point to the directory containing the Graal projects.\n");
-      vm_exit(0);
+      if (find_graal_dir(graal_dir) == false) {
+        jio_fprintf(defaultStream::output_stream(), "Error while starting Graal VM: The GRAAL environment variable needs to point to the directory containing the Graal projects.\n");
+        vm_exit(0);
+      }
     }
     if (PrintVMOptions) tty->print_cr("GRAAL=%s", graal_dir);
-      SysClassPath scp_compiler(Arguments::get_sysclasspath());
-      sprintf(temp, "%s/com.oracle.max.cri/bin", graal_dir);
-      scp_compiler.add_prefix(temp);
-      sprintf(temp, "%s/com.oracle.max.criutils/bin", graal_dir);
-      scp_compiler.add_prefix(temp);
-      sprintf(temp, "%s/com.oracle.max.base/bin", graal_dir);
-      scp_compiler.add_prefix(temp);
-      sprintf(temp, "%s/com.oracle.max.asmdis/bin", graal_dir);
-      scp_compiler.add_prefix(temp);
-      sprintf(temp, "%s/com.oracle.max.asm/bin", graal_dir);
-      scp_compiler.add_prefix(temp);
-      sprintf(temp, "%s/com.oracle.max.graal.graph/bin", graal_dir);
-      scp_compiler.add_prefix(temp);
-      sprintf(temp, "%s/com.oracle.max.graal.compiler/bin", graal_dir);
-      scp_compiler.add_prefix(temp);
-      sprintf(temp, "%s/com.oracle.max.graal.nodes/bin", graal_dir);
-      scp_compiler.add_prefix(temp);
-      sprintf(temp, "%s/com.oracle.max.graal.snippets/bin", graal_dir);
-      scp_compiler.add_prefix(temp);
-      sprintf(temp, "%s/com.oracle.max.graal.criutils/bin", graal_dir);
-      scp_compiler.add_prefix(temp);
-      sprintf(temp, "%s/com.oracle.max.graal.hotspot/bin", graal_dir);
-      scp_compiler.add_prefix(temp);
-      scp_compiler.expand_endorsed();
-      Arguments::set_compilerclasspath(scp_compiler.combined_path());
+
+    SysClassPath scp_compiler(Arguments::get_sysclasspath());
+    prepend_to_graal_classpath(scp_compiler, graal_dir, "com.oracle.max.cri");
+    prepend_to_graal_classpath(scp_compiler, graal_dir, "com.oracle.max.criutils");
+    prepend_to_graal_classpath(scp_compiler, graal_dir, "com.oracle.max.base");
+    prepend_to_graal_classpath(scp_compiler, graal_dir, "com.oracle.max.asmdis");
+    prepend_to_graal_classpath(scp_compiler, graal_dir, "com.oracle.max.asm");
+    prepend_to_graal_classpath(scp_compiler, graal_dir, "com.oracle.max.graal.graph");
+    prepend_to_graal_classpath(scp_compiler, graal_dir, "com.oracle.max.graal.compiler");
+    prepend_to_graal_classpath(scp_compiler, graal_dir, "com.oracle.max.graal.nodes");
+    prepend_to_graal_classpath(scp_compiler, graal_dir, "com.oracle.max.graal.snippets");
+    prepend_to_graal_classpath(scp_compiler, graal_dir, "com.oracle.max.graal.hotspot");
+    scp_compiler.expand_endorsed();
+
+    Arguments::set_compilerclasspath(scp_compiler.combined_path());
   }
 
   if (AggressiveOpts) {