# HG changeset patch # User Gilles Duboscq # Date 1432824635 -7200 # Node ID b7ac67354c14515c892a5441fce7e74fdcb60fa9 # Parent cecb4e39521ceca20ee982e16b79cffa13edf197 Remove GenGraalRuntimeInlineHpp diff -r cecb4e39521c -r b7ac67354c14 graal/com.oracle.graal.hotspot.sourcegen/src/com/oracle/graal/hotspot/sourcegen/GenGraalRuntimeInlineHpp.java --- a/graal/com.oracle.graal.hotspot.sourcegen/src/com/oracle/graal/hotspot/sourcegen/GenGraalRuntimeInlineHpp.java Wed May 27 17:40:26 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,225 +0,0 @@ -/* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.hotspot.sourcegen; - -import java.io.*; -import java.lang.reflect.*; -import java.util.*; -import java.util.stream.*; -import java.util.zip.*; - -import com.oracle.graal.api.runtime.*; -import com.oracle.graal.compiler.common.*; -import com.oracle.graal.options.*; - -/** - * Command line utility for generating the source code of {@code graalRuntime.inline.hpp}. The - * generated code is comprised of: - * - * - * The purpose of the generated code is to avoid executing Graal related Java code as much as - * possible during initialization of the Graal runtime. Future solutions such as some kind of AOT - * system may make such a mechanism redundant in terms of minimizing Graal's impact on VM startup - * time. - * - * The input for the generation is all classes that implement {@link Service} or contain fields - * annotated by {@link Option}. As such, the code generation process must be executed with a class - * path including all Graal jars that contains such classes. Currently, this is - * {@code graal-truffle.jar}. - */ -public class GenGraalRuntimeInlineHpp { - - public static class GraalJars implements Iterable { - private final List jars = new ArrayList<>(2); - - public GraalJars() { - String classPath = System.getProperty("java.class.path"); - for (String e : classPath.split(File.pathSeparator)) { - if (e.endsWith(File.separatorChar + "graal.jar") || e.endsWith(File.separatorChar + "graal-truffle.jar")) { - try { - jars.add(new ZipFile(e)); - } catch (IOException ioe) { - throw new InternalError(ioe); - } - } - } - if (jars.size() != 2) { - throw new InternalError("Could not find graal.jar or graal-truffle.jar on class path: " + classPath); - } - } - - public Iterator iterator() { - Stream entries = jars.stream().flatMap(ZipFile::stream); - return entries.iterator(); - } - - public InputStream getInputStream(String classFilePath) throws IOException { - for (ZipFile jar : jars) { - ZipEntry entry = jar.getEntry(classFilePath); - if (entry != null) { - return jar.getInputStream(entry); - } - } - return null; - } - } - - private static final GraalJars graalJars = new GraalJars(); - - public static void main(String[] args) { - PrintStream out = System.out; - try { - genSetOption(out); - } catch (Throwable t) { - t.printStackTrace(out); - } - out.flush(); - } - - /** - * Generates code for {@code GraalRuntime::set_option()} and - * {@code GraalRuntime::set_option_bool()}. - */ - private static void genSetOption(PrintStream out) throws Exception { - SortedMap options = getOptions(); - - Set lengths = new TreeSet<>(); - for (String s : options.keySet()) { - lengths.add(s.length()); - } - lengths.add("PrintFlags".length()); - - out.println("bool GraalRuntime::set_option_bool(KlassHandle hotSpotOptionsClass, char* name, size_t name_len, char value, TRAPS) {"); - out.println(" bool check_only = hotSpotOptionsClass.is_null();"); - genMatchers(out, lengths, options, true); - out.println(" return false;"); - out.println("}"); - out.println("bool GraalRuntime::set_option(KlassHandle hotSpotOptionsClass, char* name, size_t name_len, const char* value, TRAPS) {"); - out.println(" bool check_only = hotSpotOptionsClass.is_null();"); - genMatchers(out, lengths, options, false); - out.println(" return false;"); - out.println("}"); - } - - protected static void genMatchers(PrintStream out, Set lengths, SortedMap options, boolean isBoolean) throws Exception { - out.println(" switch (name_len) {"); - for (int len : lengths) { - boolean printedCase = false; - - // The use of strncmp is required (instead of strcmp) as the option name will not be - // null terminated for = style options. - if (len == "PrintFlags".length() && isBoolean) { - printedCase = true; - out.println(" case " + len + ":"); - out.printf(" if (strncmp(name, \"PrintFlags\", %d) == 0) {%n", len); - out.println(" if (value == '+') {"); - out.println(" if (check_only) {"); - out.println(" TempNewSymbol name = SymbolTable::new_symbol(\"Lcom/oracle/graal/hotspot/HotSpotOptions;\", CHECK_(true));"); - out.println(" hotSpotOptionsClass = SystemDictionary::resolve_or_fail(name, true, CHECK_(true));"); - out.println(" }"); - out.println(" set_option_helper(hotSpotOptionsClass, name, name_len, Handle(), '?', Handle(), 0L);"); - out.println(" }"); - out.println(" return true;"); - out.println(" }"); - } - for (Map.Entry e : options.entrySet()) { - OptionDescriptor desc = e.getValue(); - if (e.getKey().length() == len && ((desc.getType() == Boolean.class) == isBoolean)) { - if (!printedCase) { - printedCase = true; - out.println(" case " + len + ":"); - } - out.printf(" if (strncmp(name, \"%s\", %d) == 0) {%n", e.getKey(), len); - Class declaringClass = desc.getDeclaringClass(); - if (isBoolean) { - out.printf(" Handle option = get_OptionValue(\"L%s;\", \"%s\", \"L%s;\", CHECK_(true));%n", toInternalName(declaringClass), desc.getFieldName(), - toInternalName(getFieldType(desc))); - out.println(" if (!check_only) {"); - out.println(" set_option_helper(hotSpotOptionsClass, name, name_len, option, value, Handle(), 0L);"); - out.println(" }"); - } else if (desc.getType() == String.class) { - out.println(" check_required_value(name, name_len, value, CHECK_(true));"); - out.printf(" Handle option = get_OptionValue(\"L%s;\", \"%s\", \"L%s;\", CHECK_(true));%n", toInternalName(declaringClass), desc.getFieldName(), - toInternalName(getFieldType(desc))); - out.println(" if (!check_only) {"); - out.println(" Handle stringValue = java_lang_String::create_from_str(value, CHECK_(true));"); - out.println(" set_option_helper(hotSpotOptionsClass, name, name_len, option, 's', stringValue, 0L);"); - out.println(" }"); - } else { - char spec = getPrimitiveSpecChar(desc); - out.println(" jlong primitiveValue = parse_primitive_option_value('" + spec + "', name, name_len, value, CHECK_(true));"); - out.println(" if (!check_only) {"); - out.printf(" Handle option = get_OptionValue(\"L%s;\", \"%s\", \"L%s;\", CHECK_(true));%n", toInternalName(declaringClass), desc.getFieldName(), - toInternalName(getFieldType(desc))); - out.println(" set_option_helper(hotSpotOptionsClass, name, name_len, option, '" + spec + "', Handle(), primitiveValue);"); - out.println(" }"); - } - out.println(" return true;"); - out.println(" }"); - } - } - } - out.println(" }"); - } - - @SuppressWarnings("unchecked") - static SortedMap getOptions() throws Exception { - Field field = Class.forName("com.oracle.graal.hotspot.HotSpotOptionsLoader").getDeclaredField("options"); - field.setAccessible(true); - SortedMap options = (SortedMap) field.get(null); - - Set> checked = new HashSet<>(); - for (final OptionDescriptor option : options.values()) { - Class cls = option.getDeclaringClass(); - OptionsVerifier.checkClass(cls, option, checked, graalJars); - } - return options; - } - - private static Class getFieldType(OptionDescriptor desc) throws Exception { - return desc.getDeclaringClass().getDeclaredField(desc.getFieldName()).getType(); - } - - private static String toInternalName(Class c) { - return c.getName().replace('.', '/'); - } - - /** - * @see HotSpotOptions#setOption(String, OptionValue, char, String, long) - */ - @SuppressWarnings("javadoc") - private static char getPrimitiveSpecChar(OptionDescriptor desc) { - if (desc.getType() == Integer.class) { - return 'i'; - } - if (desc.getType() == Float.class) { - return 'f'; - } - if (desc.getType() == Double.class) { - return 'd'; - } - throw GraalInternalError.shouldNotReachHere("Unexpected primitive option type: " + desc.getType().getName()); - } -} diff -r cecb4e39521c -r b7ac67354c14 graal/com.oracle.graal.hotspot.sourcegen/src/com/oracle/graal/hotspot/sourcegen/GraalJars.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.hotspot.sourcegen/src/com/oracle/graal/hotspot/sourcegen/GraalJars.java Thu May 28 16:50:35 2015 +0200 @@ -0,0 +1,41 @@ +package com.oracle.graal.hotspot.sourcegen; + +import java.io.*; +import java.util.*; +import java.util.stream.*; +import java.util.zip.*; + +public class GraalJars implements Iterable { + private final List jars = new ArrayList<>(2); + + public GraalJars() { + String classPath = System.getProperty("java.class.path"); + for (String e : classPath.split(File.pathSeparator)) { + if (e.endsWith(File.separatorChar + "graal.jar") || e.endsWith(File.separatorChar + "graal-truffle.jar")) { + try { + jars.add(new ZipFile(e)); + } catch (IOException ioe) { + throw new InternalError(ioe); + } + } + } + if (jars.size() != 2) { + throw new InternalError("Could not find graal.jar or graal-truffle.jar on class path: " + classPath); + } + } + + public Iterator iterator() { + Stream entries = jars.stream().flatMap(ZipFile::stream); + return entries.iterator(); + } + + public InputStream getInputStream(String classFilePath) throws IOException { + for (ZipFile jar : jars) { + ZipEntry entry = jar.getEntry(classFilePath); + if (entry != null) { + return jar.getInputStream(entry); + } + } + return null; + } +} \ No newline at end of file diff -r cecb4e39521c -r b7ac67354c14 graal/com.oracle.graal.hotspot.sourcegen/src/com/oracle/graal/hotspot/sourcegen/OptionsVerifier.java --- a/graal/com.oracle.graal.hotspot.sourcegen/src/com/oracle/graal/hotspot/sourcegen/OptionsVerifier.java Wed May 27 17:40:26 2015 +0200 +++ b/graal/com.oracle.graal.hotspot.sourcegen/src/com/oracle/graal/hotspot/sourcegen/OptionsVerifier.java Thu May 28 16:50:35 2015 +0200 @@ -31,7 +31,6 @@ import jdk.internal.org.objectweb.asm.*; import jdk.internal.org.objectweb.asm.Type; -import com.oracle.graal.hotspot.sourcegen.GenGraalRuntimeInlineHpp.GraalJars; import com.oracle.graal.options.*; /** diff -r cecb4e39521c -r b7ac67354c14 mx/mx_graal.py --- a/mx/mx_graal.py Wed May 27 17:40:26 2015 +0200 +++ b/mx/mx_graal.py Thu May 28 16:50:35 2015 +0200 @@ -519,62 +519,6 @@ os.makedirs(hsSrcGenDir) return hsSrcGenDir -def _update_graalRuntime_inline_hpp(dist): - """ - (Re)generates graalRuntime.inline.hpp based on a given distribution - that transitively represents all the input for the generation process. - - A SHA1 digest is computed for all generated content and is written to - graalRuntime.inline.hpp as well as stored in a generated class - that is appended to the dist.path jar. At runtime, these two digests - are checked for consistency. - """ - - p = mx.project('com.oracle.graal.hotspot.sourcegen') - mainClass = 'com.oracle.graal.hotspot.sourcegen.GenGraalRuntimeInlineHpp' - if exists(join(p.output_dir(), mainClass.replace('.', os.sep) + '.class')): - genSrcDir = _makeHotspotGeneratedSourcesDir() - graalRuntime_inline_hpp = join(genSrcDir, 'graalRuntime.inline.hpp') - cp = os.pathsep.join([mx.distribution(d).path for d in dist.distDependencies] + [dist.path, p.output_dir()]) - tmp = StringIO.StringIO() - mx.run_java(['-cp', mx._separatedCygpathU2W(cp), mainClass], out=tmp.write) - - # Compute SHA1 for currently generated graalRuntime.inline.hpp content - # and all other generated sources in genSrcDir - d = hashlib.sha1() - d.update(tmp.getvalue()) - for e in os.listdir(genSrcDir): - if e != 'graalRuntime.inline.hpp': - with open(join(genSrcDir, e)) as fp: - d.update(fp.read()) - sha1 = d.hexdigest() - - # Add SHA1 to end of graalRuntime.inline.hpp - print >> tmp, '' - print >> tmp, 'const char* GraalRuntime::_generated_sources_sha1 = "' + sha1 + '";' - - mx.update_file(graalRuntime_inline_hpp, tmp.getvalue()) - - # Store SHA1 in generated Java class and append class to specified jar - javaPackageName = 'com.oracle.graal.hotspot.sourcegen' - javaClassName = javaPackageName + '.GeneratedSourcesSha1' - javaSource = join(_graal_home, 'GeneratedSourcesSha1.java') - javaClass = join(_graal_home, javaClassName.replace('.', os.path.sep) + '.class') - with open(javaSource, 'w') as fp: - print >> fp, 'package ' + javaPackageName + ';' - print >> fp, 'class GeneratedSourcesSha1 { private static final String value = "' + sha1 + '"; }' - subprocess.check_call([mx.java().javac, '-d', mx._cygpathU2W(_graal_home), mx._cygpathU2W(javaSource)], stderr=subprocess.PIPE, stdout=subprocess.PIPE) - zf = zipfile.ZipFile(dist.path, 'a') - with open(javaClass, 'rb') as fp: - zf.writestr(javaClassName.replace('.', '/') + '.class', fp.read()) - zf.close() - os.unlink(javaSource) - os.unlink(javaClass) - javaClassParent = os.path.dirname(javaClass) - while len(os.listdir(javaClassParent)) == 0: - os.rmdir(javaClassParent) - javaClassParent = os.path.dirname(javaClassParent) - def _copyToJdk(src, dst, permissions=JDK_UNIX_PERMISSIONS_FILE): name = os.path.basename(src) dstLib = join(dst, name) @@ -729,17 +673,7 @@ """ dist = mx.distribution(deployableDist.name) - - if dist.name == 'GRAAL_TRUFFLE': - # The content in graalRuntime.inline.hpp is generated from Graal - # classes that implement com.oracle.graal.api.runtime.Service - # or contain com.oracle.graal.options.Option annotated fields. - # Since GRAAL_TRUFFLE is the leaf most distribution containing - # such classes, the generation is triggered when GRAAL_TRUFFLE - # is (re)built. - _update_graalRuntime_inline_hpp(dist) jdks = _jdksDir() - if exists(jdks): for e in os.listdir(jdks): jdkDir = join(jdks, e) diff -r cecb4e39521c -r b7ac67354c14 src/share/vm/graal/graalRuntime.hpp --- a/src/share/vm/graal/graalRuntime.hpp Wed May 27 17:40:26 2015 +0200 +++ b/src/share/vm/graal/graalRuntime.hpp Thu May 28 16:50:35 2015 +0200 @@ -138,9 +138,6 @@ * Given an interface representing a Graal service (i.e. sub-interface of * com.oracle.graal.api.runtime.Service), gets an array of objects, one per * known implementation of the service. - * - * The definition of this method is in graalRuntime.inline.hpp - * which is generated by com.oracle.graal.hotspot.sourcegen.GenGraalRuntimeInlineHpp. */ static Handle get_service_impls(KlassHandle serviceKlass, TRAPS);