# HG changeset patch # User Doug Simon # Date 1432823981 -7200 # Node ID a9fba0dfb1554d46f031678076b6326f2842aec7 # Parent be896a1983c02a6b417c8b84bb9de44dd655719a added lower runtime overhead mechanism for setting "graal.version" system property diff -r be896a1983c0 -r a9fba0dfb155 graal/com.oracle.graal.api.runtime/src/com/oracle/graal/api/runtime/Graal.java --- a/graal/com.oracle.graal.api.runtime/src/com/oracle/graal/api/runtime/Graal.java Thu May 28 15:36:48 2015 +0200 +++ b/graal/com.oracle.graal.api.runtime/src/com/oracle/graal/api/runtime/Graal.java Thu May 28 16:39:41 2015 +0200 @@ -22,7 +22,6 @@ */ package com.oracle.graal.api.runtime; -import java.io.*; import java.util.*; import sun.reflect.*; @@ -43,24 +42,14 @@ rt = factory.getRuntime(); } if (rt != null) { - updateGraalVersionProperty(); + // The constant is patched in-situ by the build system + System.setProperty("graal.version", "@@graal.version@@"); + assert !System.getProperty("graal.version").startsWith("@@") && !System.getProperty("graal.version").endsWith("@@") : "Graal version string constant was not patched by build system"; return rt; } return new InvalidGraalRuntime(); } - private static void updateGraalVersionProperty() { - try { - InputStream s = Graal.class.getResourceAsStream("graal.version"); - byte[] buf = new byte[s.available()]; - new DataInputStream(s).readFully(buf); - String version = new String(buf); - System.setProperty("graal.version", version); - } catch (IOException e) { - throw new InternalError(e); - } - } - /** * Gets the singleton {@link GraalRuntime} instance available to the application. */ diff -r be896a1983c0 -r a9fba0dfb155 mx/mx_graal.py --- 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.