annotate graal/com.oracle.graal.hotspot.sourcegen/src/com/oracle/graal/hotspot/sourcegen/GenGraalRuntimeInlineHpp.java @ 21526:1da7aef31a08

created com.oracle.graal.hotspot.jvmci package and moved classes destined for future JVMCI module into it (JBS:GRAAL-53)
author Doug Simon <doug.simon@oracle.com>
date Tue, 19 May 2015 23:16:07 +0200
parents e1c063565b3c
children c1e2fdb5fea3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15916
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1 /*
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
4 *
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
8 *
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
13 * accompanied this code).
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
14 *
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
18 *
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
21 * questions.
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
22 */
15940
d676c4beeab8 renamed project (and package) com.oracle.graal.hotspot.codegen to com.oracle.graal.hotspot.sourcegen
Doug Simon <doug.simon@oracle.com>
parents: 15918
diff changeset
23 package com.oracle.graal.hotspot.sourcegen;
15916
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
24
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
25 import java.io.*;
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
26 import java.lang.reflect.*;
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
27 import java.util.*;
16689
2f7464a458b4 use stream API to concatenate ZipFile iterators
Doug Simon <doug.simon@oracle.com>
parents: 16623
diff changeset
28 import java.util.stream.*;
15916
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
29 import java.util.zip.*;
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
30
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
31 import com.oracle.graal.api.runtime.*;
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
32 import com.oracle.graal.compiler.common.*;
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
33 import com.oracle.graal.options.*;
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
34
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
35 /**
18709
ae5033a78f1d improved documentation around the mechanism for generating graalRuntime.inline.hpp
Doug Simon <doug.simon@oracle.com>
parents: 16876
diff changeset
36 * Command line utility for generating the source code of {@code graalRuntime.inline.hpp}. The
ae5033a78f1d improved documentation around the mechanism for generating graalRuntime.inline.hpp
Doug Simon <doug.simon@oracle.com>
parents: 16876
diff changeset
37 * generated code is comprised of:
ae5033a78f1d improved documentation around the mechanism for generating graalRuntime.inline.hpp
Doug Simon <doug.simon@oracle.com>
parents: 16876
diff changeset
38 * <ul>
ae5033a78f1d improved documentation around the mechanism for generating graalRuntime.inline.hpp
Doug Simon <doug.simon@oracle.com>
parents: 16876
diff changeset
39 * <li>{@code -G} command line option parsing {@linkplain #genSetOption(PrintStream) helper}</li>
ae5033a78f1d improved documentation around the mechanism for generating graalRuntime.inline.hpp
Doug Simon <doug.simon@oracle.com>
parents: 16876
diff changeset
40 * </ul>
ae5033a78f1d improved documentation around the mechanism for generating graalRuntime.inline.hpp
Doug Simon <doug.simon@oracle.com>
parents: 16876
diff changeset
41 *
ae5033a78f1d improved documentation around the mechanism for generating graalRuntime.inline.hpp
Doug Simon <doug.simon@oracle.com>
parents: 16876
diff changeset
42 * The purpose of the generated code is to avoid executing Graal related Java code as much as
ae5033a78f1d improved documentation around the mechanism for generating graalRuntime.inline.hpp
Doug Simon <doug.simon@oracle.com>
parents: 16876
diff changeset
43 * possible during initialization of the Graal runtime. Future solutions such as some kind of AOT
ae5033a78f1d improved documentation around the mechanism for generating graalRuntime.inline.hpp
Doug Simon <doug.simon@oracle.com>
parents: 16876
diff changeset
44 * system may make such a mechanism redundant in terms of minimizing Graal's impact on VM startup
ae5033a78f1d improved documentation around the mechanism for generating graalRuntime.inline.hpp
Doug Simon <doug.simon@oracle.com>
parents: 16876
diff changeset
45 * time.
ae5033a78f1d improved documentation around the mechanism for generating graalRuntime.inline.hpp
Doug Simon <doug.simon@oracle.com>
parents: 16876
diff changeset
46 *
ae5033a78f1d improved documentation around the mechanism for generating graalRuntime.inline.hpp
Doug Simon <doug.simon@oracle.com>
parents: 16876
diff changeset
47 * The input for the generation is all classes that implement {@link Service} or contain fields
ae5033a78f1d improved documentation around the mechanism for generating graalRuntime.inline.hpp
Doug Simon <doug.simon@oracle.com>
parents: 16876
diff changeset
48 * annotated by {@link Option}. As such, the code generation process must be executed with a class
ae5033a78f1d improved documentation around the mechanism for generating graalRuntime.inline.hpp
Doug Simon <doug.simon@oracle.com>
parents: 16876
diff changeset
49 * path including all Graal jars that contains such classes. Currently, this is
ae5033a78f1d improved documentation around the mechanism for generating graalRuntime.inline.hpp
Doug Simon <doug.simon@oracle.com>
parents: 16876
diff changeset
50 * {@code graal-truffle.jar}.
15916
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
51 */
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
52 public class GenGraalRuntimeInlineHpp {
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
53
16623
addc0564e5b5 split com.oracle.graal.truffle.* projects into a separate graal-truffle.jar and added truffle.jar to the boot class path
Doug Simon <doug.simon@oracle.com>
parents: 16428
diff changeset
54 public static class GraalJars implements Iterable<ZipEntry> {
addc0564e5b5 split com.oracle.graal.truffle.* projects into a separate graal-truffle.jar and added truffle.jar to the boot class path
Doug Simon <doug.simon@oracle.com>
parents: 16428
diff changeset
55 private final List<ZipFile> jars = new ArrayList<>(2);
16030
bddb3eb57e90 moved verification of OptionValue declaring classes from run time to build time
Doug Simon <doug.simon@oracle.com>
parents: 16006
diff changeset
56
16623
addc0564e5b5 split com.oracle.graal.truffle.* projects into a separate graal-truffle.jar and added truffle.jar to the boot class path
Doug Simon <doug.simon@oracle.com>
parents: 16428
diff changeset
57 public GraalJars() {
addc0564e5b5 split com.oracle.graal.truffle.* projects into a separate graal-truffle.jar and added truffle.jar to the boot class path
Doug Simon <doug.simon@oracle.com>
parents: 16428
diff changeset
58 String classPath = System.getProperty("java.class.path");
addc0564e5b5 split com.oracle.graal.truffle.* projects into a separate graal-truffle.jar and added truffle.jar to the boot class path
Doug Simon <doug.simon@oracle.com>
parents: 16428
diff changeset
59 for (String e : classPath.split(File.pathSeparator)) {
addc0564e5b5 split com.oracle.graal.truffle.* projects into a separate graal-truffle.jar and added truffle.jar to the boot class path
Doug Simon <doug.simon@oracle.com>
parents: 16428
diff changeset
60 if (e.endsWith(File.separatorChar + "graal.jar") || e.endsWith(File.separatorChar + "graal-truffle.jar")) {
addc0564e5b5 split com.oracle.graal.truffle.* projects into a separate graal-truffle.jar and added truffle.jar to the boot class path
Doug Simon <doug.simon@oracle.com>
parents: 16428
diff changeset
61 try {
addc0564e5b5 split com.oracle.graal.truffle.* projects into a separate graal-truffle.jar and added truffle.jar to the boot class path
Doug Simon <doug.simon@oracle.com>
parents: 16428
diff changeset
62 jars.add(new ZipFile(e));
addc0564e5b5 split com.oracle.graal.truffle.* projects into a separate graal-truffle.jar and added truffle.jar to the boot class path
Doug Simon <doug.simon@oracle.com>
parents: 16428
diff changeset
63 } catch (IOException ioe) {
addc0564e5b5 split com.oracle.graal.truffle.* projects into a separate graal-truffle.jar and added truffle.jar to the boot class path
Doug Simon <doug.simon@oracle.com>
parents: 16428
diff changeset
64 throw new InternalError(ioe);
addc0564e5b5 split com.oracle.graal.truffle.* projects into a separate graal-truffle.jar and added truffle.jar to the boot class path
Doug Simon <doug.simon@oracle.com>
parents: 16428
diff changeset
65 }
addc0564e5b5 split com.oracle.graal.truffle.* projects into a separate graal-truffle.jar and added truffle.jar to the boot class path
Doug Simon <doug.simon@oracle.com>
parents: 16428
diff changeset
66 }
addc0564e5b5 split com.oracle.graal.truffle.* projects into a separate graal-truffle.jar and added truffle.jar to the boot class path
Doug Simon <doug.simon@oracle.com>
parents: 16428
diff changeset
67 }
addc0564e5b5 split com.oracle.graal.truffle.* projects into a separate graal-truffle.jar and added truffle.jar to the boot class path
Doug Simon <doug.simon@oracle.com>
parents: 16428
diff changeset
68 if (jars.size() != 2) {
addc0564e5b5 split com.oracle.graal.truffle.* projects into a separate graal-truffle.jar and added truffle.jar to the boot class path
Doug Simon <doug.simon@oracle.com>
parents: 16428
diff changeset
69 throw new InternalError("Could not find graal.jar or graal-truffle.jar on class path: " + classPath);
16030
bddb3eb57e90 moved verification of OptionValue declaring classes from run time to build time
Doug Simon <doug.simon@oracle.com>
parents: 16006
diff changeset
70 }
bddb3eb57e90 moved verification of OptionValue declaring classes from run time to build time
Doug Simon <doug.simon@oracle.com>
parents: 16006
diff changeset
71 }
16623
addc0564e5b5 split com.oracle.graal.truffle.* projects into a separate graal-truffle.jar and added truffle.jar to the boot class path
Doug Simon <doug.simon@oracle.com>
parents: 16428
diff changeset
72
addc0564e5b5 split com.oracle.graal.truffle.* projects into a separate graal-truffle.jar and added truffle.jar to the boot class path
Doug Simon <doug.simon@oracle.com>
parents: 16428
diff changeset
73 public Iterator<ZipEntry> iterator() {
16689
2f7464a458b4 use stream API to concatenate ZipFile iterators
Doug Simon <doug.simon@oracle.com>
parents: 16623
diff changeset
74 Stream<ZipEntry> entries = jars.stream().flatMap(ZipFile::stream);
16623
addc0564e5b5 split com.oracle.graal.truffle.* projects into a separate graal-truffle.jar and added truffle.jar to the boot class path
Doug Simon <doug.simon@oracle.com>
parents: 16428
diff changeset
75 return entries.iterator();
16030
bddb3eb57e90 moved verification of OptionValue declaring classes from run time to build time
Doug Simon <doug.simon@oracle.com>
parents: 16006
diff changeset
76 }
16623
addc0564e5b5 split com.oracle.graal.truffle.* projects into a separate graal-truffle.jar and added truffle.jar to the boot class path
Doug Simon <doug.simon@oracle.com>
parents: 16428
diff changeset
77
addc0564e5b5 split com.oracle.graal.truffle.* projects into a separate graal-truffle.jar and added truffle.jar to the boot class path
Doug Simon <doug.simon@oracle.com>
parents: 16428
diff changeset
78 public InputStream getInputStream(String classFilePath) throws IOException {
addc0564e5b5 split com.oracle.graal.truffle.* projects into a separate graal-truffle.jar and added truffle.jar to the boot class path
Doug Simon <doug.simon@oracle.com>
parents: 16428
diff changeset
79 for (ZipFile jar : jars) {
addc0564e5b5 split com.oracle.graal.truffle.* projects into a separate graal-truffle.jar and added truffle.jar to the boot class path
Doug Simon <doug.simon@oracle.com>
parents: 16428
diff changeset
80 ZipEntry entry = jar.getEntry(classFilePath);
addc0564e5b5 split com.oracle.graal.truffle.* projects into a separate graal-truffle.jar and added truffle.jar to the boot class path
Doug Simon <doug.simon@oracle.com>
parents: 16428
diff changeset
81 if (entry != null) {
addc0564e5b5 split com.oracle.graal.truffle.* projects into a separate graal-truffle.jar and added truffle.jar to the boot class path
Doug Simon <doug.simon@oracle.com>
parents: 16428
diff changeset
82 return jar.getInputStream(entry);
addc0564e5b5 split com.oracle.graal.truffle.* projects into a separate graal-truffle.jar and added truffle.jar to the boot class path
Doug Simon <doug.simon@oracle.com>
parents: 16428
diff changeset
83 }
addc0564e5b5 split com.oracle.graal.truffle.* projects into a separate graal-truffle.jar and added truffle.jar to the boot class path
Doug Simon <doug.simon@oracle.com>
parents: 16428
diff changeset
84 }
addc0564e5b5 split com.oracle.graal.truffle.* projects into a separate graal-truffle.jar and added truffle.jar to the boot class path
Doug Simon <doug.simon@oracle.com>
parents: 16428
diff changeset
85 return null;
addc0564e5b5 split com.oracle.graal.truffle.* projects into a separate graal-truffle.jar and added truffle.jar to the boot class path
Doug Simon <doug.simon@oracle.com>
parents: 16428
diff changeset
86 }
16030
bddb3eb57e90 moved verification of OptionValue declaring classes from run time to build time
Doug Simon <doug.simon@oracle.com>
parents: 16006
diff changeset
87 }
bddb3eb57e90 moved verification of OptionValue declaring classes from run time to build time
Doug Simon <doug.simon@oracle.com>
parents: 16006
diff changeset
88
16623
addc0564e5b5 split com.oracle.graal.truffle.* projects into a separate graal-truffle.jar and added truffle.jar to the boot class path
Doug Simon <doug.simon@oracle.com>
parents: 16428
diff changeset
89 private static final GraalJars graalJars = new GraalJars();
addc0564e5b5 split com.oracle.graal.truffle.* projects into a separate graal-truffle.jar and added truffle.jar to the boot class path
Doug Simon <doug.simon@oracle.com>
parents: 16428
diff changeset
90
15916
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
91 public static void main(String[] args) {
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
92 PrintStream out = System.out;
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
93 try {
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
94 genSetOption(out);
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
95 } catch (Throwable t) {
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
96 t.printStackTrace(out);
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
97 }
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
98 out.flush();
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
99 }
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
100
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
101 /**
16870
11b22ccafccd Correctly parse string option values that start with + or -.
Roland Schatz <roland.schatz@oracle.com>
parents: 16689
diff changeset
102 * Generates code for {@code GraalRuntime::set_option()} and
11b22ccafccd Correctly parse string option values that start with + or -.
Roland Schatz <roland.schatz@oracle.com>
parents: 16689
diff changeset
103 * {@code GraalRuntime::set_option_bool()}.
15916
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
104 */
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
105 private static void genSetOption(PrintStream out) throws Exception {
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
106 SortedMap<String, OptionDescriptor> options = getOptions();
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
107
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
108 Set<Integer> lengths = new TreeSet<>();
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
109 for (String s : options.keySet()) {
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
110 lengths.add(s.length());
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
111 }
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
112 lengths.add("PrintFlags".length());
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
113
16876
9d4c73b0646e graalRuntime: name_len shound be a size_t
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 16870
diff changeset
114 out.println("bool GraalRuntime::set_option_bool(KlassHandle hotSpotOptionsClass, char* name, size_t name_len, char value, TRAPS) {");
16870
11b22ccafccd Correctly parse string option values that start with + or -.
Roland Schatz <roland.schatz@oracle.com>
parents: 16689
diff changeset
115 out.println(" bool check_only = hotSpotOptionsClass.is_null();");
11b22ccafccd Correctly parse string option values that start with + or -.
Roland Schatz <roland.schatz@oracle.com>
parents: 16689
diff changeset
116 genMatchers(out, lengths, options, true);
11b22ccafccd Correctly parse string option values that start with + or -.
Roland Schatz <roland.schatz@oracle.com>
parents: 16689
diff changeset
117 out.println(" return false;");
11b22ccafccd Correctly parse string option values that start with + or -.
Roland Schatz <roland.schatz@oracle.com>
parents: 16689
diff changeset
118 out.println("}");
16876
9d4c73b0646e graalRuntime: name_len shound be a size_t
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 16870
diff changeset
119 out.println("bool GraalRuntime::set_option(KlassHandle hotSpotOptionsClass, char* name, size_t name_len, const char* value, TRAPS) {");
16276
5cdcb94a7cf7 clarify option checking code from option parsing code
Doug Simon <doug.simon@oracle.com>
parents: 16270
diff changeset
120 out.println(" bool check_only = hotSpotOptionsClass.is_null();");
15916
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
121 genMatchers(out, lengths, options, false);
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
122 out.println(" return false;");
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
123 out.println("}");
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
124 }
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
125
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
126 protected static void genMatchers(PrintStream out, Set<Integer> lengths, SortedMap<String, OptionDescriptor> options, boolean isBoolean) throws Exception {
16870
11b22ccafccd Correctly parse string option values that start with + or -.
Roland Schatz <roland.schatz@oracle.com>
parents: 16689
diff changeset
127 out.println(" switch (name_len) {");
15916
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
128 for (int len : lengths) {
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
129 boolean printedCase = false;
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
130
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
131 // The use of strncmp is required (instead of strcmp) as the option name will not be
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
132 // null terminated for <name>=<value> style options.
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
133 if (len == "PrintFlags".length() && isBoolean) {
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
134 printedCase = true;
16870
11b22ccafccd Correctly parse string option values that start with + or -.
Roland Schatz <roland.schatz@oracle.com>
parents: 16689
diff changeset
135 out.println(" case " + len + ":");
11b22ccafccd Correctly parse string option values that start with + or -.
Roland Schatz <roland.schatz@oracle.com>
parents: 16689
diff changeset
136 out.printf(" if (strncmp(name, \"PrintFlags\", %d) == 0) {%n", len);
11b22ccafccd Correctly parse string option values that start with + or -.
Roland Schatz <roland.schatz@oracle.com>
parents: 16689
diff changeset
137 out.println(" if (value == '+') {");
11b22ccafccd Correctly parse string option values that start with + or -.
Roland Schatz <roland.schatz@oracle.com>
parents: 16689
diff changeset
138 out.println(" if (check_only) {");
21526
1da7aef31a08 created com.oracle.graal.hotspot.jvmci package and moved classes destined for future JVMCI module into it (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21031
diff changeset
139 out.println(" TempNewSymbol name = SymbolTable::new_symbol(\"Lcom/oracle/graal/hotspot/jvmci/HotSpotOptions;\", CHECK_(true));");
16870
11b22ccafccd Correctly parse string option values that start with + or -.
Roland Schatz <roland.schatz@oracle.com>
parents: 16689
diff changeset
140 out.println(" hotSpotOptionsClass = SystemDictionary::resolve_or_fail(name, true, CHECK_(true));");
15916
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
141 out.println(" }");
16870
11b22ccafccd Correctly parse string option values that start with + or -.
Roland Schatz <roland.schatz@oracle.com>
parents: 16689
diff changeset
142 out.println(" set_option_helper(hotSpotOptionsClass, name, name_len, Handle(), '?', Handle(), 0L);");
15916
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
143 out.println(" }");
16870
11b22ccafccd Correctly parse string option values that start with + or -.
Roland Schatz <roland.schatz@oracle.com>
parents: 16689
diff changeset
144 out.println(" return true;");
11b22ccafccd Correctly parse string option values that start with + or -.
Roland Schatz <roland.schatz@oracle.com>
parents: 16689
diff changeset
145 out.println(" }");
15916
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
146 }
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
147 for (Map.Entry<String, OptionDescriptor> e : options.entrySet()) {
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
148 OptionDescriptor desc = e.getValue();
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
149 if (e.getKey().length() == len && ((desc.getType() == Boolean.class) == isBoolean)) {
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
150 if (!printedCase) {
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
151 printedCase = true;
16870
11b22ccafccd Correctly parse string option values that start with + or -.
Roland Schatz <roland.schatz@oracle.com>
parents: 16689
diff changeset
152 out.println(" case " + len + ":");
15916
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
153 }
16870
11b22ccafccd Correctly parse string option values that start with + or -.
Roland Schatz <roland.schatz@oracle.com>
parents: 16689
diff changeset
154 out.printf(" if (strncmp(name, \"%s\", %d) == 0) {%n", e.getKey(), len);
15916
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
155 Class<?> declaringClass = desc.getDeclaringClass();
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
156 if (isBoolean) {
16870
11b22ccafccd Correctly parse string option values that start with + or -.
Roland Schatz <roland.schatz@oracle.com>
parents: 16689
diff changeset
157 out.printf(" Handle option = get_OptionValue(\"L%s;\", \"%s\", \"L%s;\", CHECK_(true));%n", toInternalName(declaringClass), desc.getFieldName(),
11b22ccafccd Correctly parse string option values that start with + or -.
Roland Schatz <roland.schatz@oracle.com>
parents: 16689
diff changeset
158 toInternalName(getFieldType(desc)));
11b22ccafccd Correctly parse string option values that start with + or -.
Roland Schatz <roland.schatz@oracle.com>
parents: 16689
diff changeset
159 out.println(" if (!check_only) {");
11b22ccafccd Correctly parse string option values that start with + or -.
Roland Schatz <roland.schatz@oracle.com>
parents: 16689
diff changeset
160 out.println(" set_option_helper(hotSpotOptionsClass, name, name_len, option, value, Handle(), 0L);");
11b22ccafccd Correctly parse string option values that start with + or -.
Roland Schatz <roland.schatz@oracle.com>
parents: 16689
diff changeset
161 out.println(" }");
11b22ccafccd Correctly parse string option values that start with + or -.
Roland Schatz <roland.schatz@oracle.com>
parents: 16689
diff changeset
162 } else if (desc.getType() == String.class) {
11b22ccafccd Correctly parse string option values that start with + or -.
Roland Schatz <roland.schatz@oracle.com>
parents: 16689
diff changeset
163 out.println(" check_required_value(name, name_len, value, CHECK_(true));");
11b22ccafccd Correctly parse string option values that start with + or -.
Roland Schatz <roland.schatz@oracle.com>
parents: 16689
diff changeset
164 out.printf(" Handle option = get_OptionValue(\"L%s;\", \"%s\", \"L%s;\", CHECK_(true));%n", toInternalName(declaringClass), desc.getFieldName(),
16270
d56a09df1a1f implemented eager checking of Graal options (GRAAL-807)
Doug Simon <doug.simon@oracle.com>
parents: 16030
diff changeset
165 toInternalName(getFieldType(desc)));
16870
11b22ccafccd Correctly parse string option values that start with + or -.
Roland Schatz <roland.schatz@oracle.com>
parents: 16689
diff changeset
166 out.println(" if (!check_only) {");
11b22ccafccd Correctly parse string option values that start with + or -.
Roland Schatz <roland.schatz@oracle.com>
parents: 16689
diff changeset
167 out.println(" Handle stringValue = java_lang_String::create_from_str(value, CHECK_(true));");
11b22ccafccd Correctly parse string option values that start with + or -.
Roland Schatz <roland.schatz@oracle.com>
parents: 16689
diff changeset
168 out.println(" set_option_helper(hotSpotOptionsClass, name, name_len, option, 's', stringValue, 0L);");
11b22ccafccd Correctly parse string option values that start with + or -.
Roland Schatz <roland.schatz@oracle.com>
parents: 16689
diff changeset
169 out.println(" }");
11b22ccafccd Correctly parse string option values that start with + or -.
Roland Schatz <roland.schatz@oracle.com>
parents: 16689
diff changeset
170 } else {
11b22ccafccd Correctly parse string option values that start with + or -.
Roland Schatz <roland.schatz@oracle.com>
parents: 16689
diff changeset
171 char spec = getPrimitiveSpecChar(desc);
11b22ccafccd Correctly parse string option values that start with + or -.
Roland Schatz <roland.schatz@oracle.com>
parents: 16689
diff changeset
172 out.println(" jlong primitiveValue = parse_primitive_option_value('" + spec + "', name, name_len, value, CHECK_(true));");
11b22ccafccd Correctly parse string option values that start with + or -.
Roland Schatz <roland.schatz@oracle.com>
parents: 16689
diff changeset
173 out.println(" if (!check_only) {");
16270
d56a09df1a1f implemented eager checking of Graal options (GRAAL-807)
Doug Simon <doug.simon@oracle.com>
parents: 16030
diff changeset
174 out.printf(" Handle option = get_OptionValue(\"L%s;\", \"%s\", \"L%s;\", CHECK_(true));%n", toInternalName(declaringClass), desc.getFieldName(),
d56a09df1a1f implemented eager checking of Graal options (GRAAL-807)
Doug Simon <doug.simon@oracle.com>
parents: 16030
diff changeset
175 toInternalName(getFieldType(desc)));
16870
11b22ccafccd Correctly parse string option values that start with + or -.
Roland Schatz <roland.schatz@oracle.com>
parents: 16689
diff changeset
176 out.println(" set_option_helper(hotSpotOptionsClass, name, name_len, option, '" + spec + "', Handle(), primitiveValue);");
11b22ccafccd Correctly parse string option values that start with + or -.
Roland Schatz <roland.schatz@oracle.com>
parents: 16689
diff changeset
177 out.println(" }");
15916
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
178 }
16870
11b22ccafccd Correctly parse string option values that start with + or -.
Roland Schatz <roland.schatz@oracle.com>
parents: 16689
diff changeset
179 out.println(" return true;");
11b22ccafccd Correctly parse string option values that start with + or -.
Roland Schatz <roland.schatz@oracle.com>
parents: 16689
diff changeset
180 out.println(" }");
15916
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
181 }
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
182 }
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
183 }
16870
11b22ccafccd Correctly parse string option values that start with + or -.
Roland Schatz <roland.schatz@oracle.com>
parents: 16689
diff changeset
184 out.println(" }");
15916
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
185 }
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
186
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
187 @SuppressWarnings("unchecked")
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
188 static SortedMap<String, OptionDescriptor> getOptions() throws Exception {
21526
1da7aef31a08 created com.oracle.graal.hotspot.jvmci package and moved classes destined for future JVMCI module into it (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21031
diff changeset
189 Field field = Class.forName("com.oracle.graal.hotspot.jvmci.HotSpotOptionsLoader").getDeclaredField("options");
15916
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
190 field.setAccessible(true);
16030
bddb3eb57e90 moved verification of OptionValue declaring classes from run time to build time
Doug Simon <doug.simon@oracle.com>
parents: 16006
diff changeset
191 SortedMap<String, OptionDescriptor> options = (SortedMap<String, OptionDescriptor>) field.get(null);
bddb3eb57e90 moved verification of OptionValue declaring classes from run time to build time
Doug Simon <doug.simon@oracle.com>
parents: 16006
diff changeset
192
bddb3eb57e90 moved verification of OptionValue declaring classes from run time to build time
Doug Simon <doug.simon@oracle.com>
parents: 16006
diff changeset
193 Set<Class<?>> checked = new HashSet<>();
bddb3eb57e90 moved verification of OptionValue declaring classes from run time to build time
Doug Simon <doug.simon@oracle.com>
parents: 16006
diff changeset
194 for (final OptionDescriptor option : options.values()) {
bddb3eb57e90 moved verification of OptionValue declaring classes from run time to build time
Doug Simon <doug.simon@oracle.com>
parents: 16006
diff changeset
195 Class<?> cls = option.getDeclaringClass();
16623
addc0564e5b5 split com.oracle.graal.truffle.* projects into a separate graal-truffle.jar and added truffle.jar to the boot class path
Doug Simon <doug.simon@oracle.com>
parents: 16428
diff changeset
196 OptionsVerifier.checkClass(cls, option, checked, graalJars);
16030
bddb3eb57e90 moved verification of OptionValue declaring classes from run time to build time
Doug Simon <doug.simon@oracle.com>
parents: 16006
diff changeset
197 }
bddb3eb57e90 moved verification of OptionValue declaring classes from run time to build time
Doug Simon <doug.simon@oracle.com>
parents: 16006
diff changeset
198 return options;
15916
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
199 }
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
200
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
201 private static Class<?> getFieldType(OptionDescriptor desc) throws Exception {
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
202 return desc.getDeclaringClass().getDeclaredField(desc.getFieldName()).getType();
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
203 }
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
204
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
205 private static String toInternalName(Class<?> c) {
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
206 return c.getName().replace('.', '/');
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
207 }
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
208
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
209 /**
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
210 * @see HotSpotOptions#setOption(String, OptionValue, char, String, long)
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
211 */
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
212 @SuppressWarnings("javadoc")
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
213 private static char getPrimitiveSpecChar(OptionDescriptor desc) {
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
214 if (desc.getType() == Integer.class) {
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
215 return 'i';
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
216 }
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
217 if (desc.getType() == Float.class) {
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
218 return 'f';
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
219 }
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
220 if (desc.getType() == Double.class) {
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
221 return 'd';
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
222 }
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
223 throw GraalInternalError.shouldNotReachHere("Unexpected primitive option type: " + desc.getType().getName());
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
224 }
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
225 }