diff mx/mx_graal.py @ 21560:a9fba0dfb155

added lower runtime overhead mechanism for setting "graal.version" system property
author Doug Simon <doug.simon@oracle.com>
date Thu, 28 May 2015 16:39:41 +0200
parents be896a1983c0
children 47bebae7454f
line wrap: on
line diff
--- a/mx/mx_graal.py	Thu May 28 15:36:48 2015 +0200
+++ b/mx/mx_graal.py	Thu May 28 16:39:41 2015 +0200
@@ -707,7 +707,26 @@
     jreJVMCIServicesDir = join(jreJVMCIDir, 'services')
     _extractJVMCIServiceFiles(jvmciJars, jreJVMCIServicesDir)
 
-
+def _patchGraalVersionConstant(dist):
+    """
+    Patches the constant "@@graal.version@@" in the constant pool of Graal.class
+    with the computed Graal version string.
+    """
+    zfOutFd, zfOutPath = tempfile.mkstemp(suffix='', prefix=basename(dist.path) + '.', dir=dirname(dist.path))
+    zfOut = zipfile.ZipFile(zfOutPath, 'w')
+    zf = zipfile.ZipFile(dist.path, 'r')
+    for zi in zf.infolist():
+        data = zf.read(zi)
+        if zi.filename == 'com/oracle/graal/api/runtime/Graal.class':
+            versionSpec = '{:' + str(len('@@graal.version@@')) + '}'
+            versionStr = versionSpec.format(graal_version())
+            assert '@@graal.version@@' in data, 'could not find "@@graal.version@@" constant in ' + dist.path + '!' + zi.filename
+            data = data.replace('@@graal.version@@', versionStr)
+        zfOut.writestr(zi, data)
+    zfOut.close()
+    os.close(zfOutFd)
+    zf.close()
+    shutil.move(zfOutPath, dist.path)
 
 def _installDistInJdks(deployableDist):
     """
@@ -717,9 +736,8 @@
     dist = mx.distribution(deployableDist.name)
 
     if dist.name == 'GRAAL':
-        zf = zipfile.ZipFile(dist.path, 'a')
-        zf.writestr('com/oracle/graal/api/runtime/graal.version', graal_version())
-        zf.close()
+        _patchGraalVersionConstant(dist)
+
     elif dist.name == 'GRAAL_TRUFFLE':
         # The content in graalRuntime.inline.hpp is generated from Graal
         # classes that contain com.oracle.jvmci.options.Option annotated fields.