6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 package compiler.aot;
25
26 import jdk.test.lib.process.OutputAnalyzer;
27 import java.io.File;
28 import java.io.IOException;
29 import java.nio.file.Files;
30 import java.nio.file.Path;
31 import java.nio.file.Paths;
32 import java.nio.file.StandardOpenOption;
33 import java.util.ArrayList;
34 import java.util.Arrays;
35 import java.util.List;
36 import jdk.test.lib.JDKToolLauncher;
37 import jdk.test.lib.Utils;
38
39 /**
40 * A simple class calling AOT compiler over requested items
41 */
42 public class AotCompiler {
43
44 private final static String METHODS_LIST_FILENAME = "methodsList.txt";
45
46 public static void main(String args[]) {
47 String className = null;
48 List<String> compileList = new ArrayList<>();
49 String libName = null;
50 List<String> extraopts = new ArrayList<>();
51 for (int i = 0; i < args.length; i++) {
52 switch (args[i]) {
53 case "-class":
54 className = args[++i];
55 break;
56 case "-compile":
57 compileList.add("compileOnly " + args[++i]);
85 List<String> compList) {
86 Path file = null;
87 if (compList != null && !compList.isEmpty()) {
88 file = Paths.get(METHODS_LIST_FILENAME);
89 try {
90 Files.write(file, compList, StandardOpenOption.CREATE);
91 } catch (IOException e) {
92 throw new Error("Couldn't write " + METHODS_LIST_FILENAME + " " + e, e);
93 }
94 }
95 List<String> args = new ArrayList<>();
96 args.add("--compile-with-assertions");
97 args.add("--output");
98 args.add(libName);
99 if (file != null) {
100 args.add("--compile-commands");
101 args.add(file.toString());
102 }
103 args.add("--class-name");
104 args.add(item);
105 return launchJaotc(args, extraopts);
106 }
107
108 private static OutputAnalyzer launchJaotc(List<String> args, List<String> extraVmOpts) {
109 JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jaotc");
110 for (String vmOpt : Utils.getTestJavaOpts()) {
111 launcher.addVMArg(vmOpt);
112 }
113 if (extraVmOpts != null) {
114 for (String vmOpt : extraVmOpts) {
115 launcher.addVMArg(vmOpt);
116 }
117 }
118 for (String arg : args) {
119 launcher.addToolArg(arg);
120 }
121 try {
122 return new OutputAnalyzer(new ProcessBuilder(launcher.getCommand()).inheritIO().start());
123 } catch (IOException e) {
124 throw new Error("Can't start test process: " + e, e);
125 }
126 }
127
128 public static void printUsage() {
129 System.err.println("Usage: " + AotCompiler.class.getName()
130 + " -class <class> -libname <.so name>"
131 + " [-compile <compileItems>]* [-extraopt <java option>]*");
132 }
133 }
|
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 package compiler.aot;
25
26 import jdk.test.lib.Platform;
27 import jdk.test.lib.artifacts.Artifact;
28 import jdk.test.lib.artifacts.ArtifactResolver;
29 import jdk.test.lib.process.OutputAnalyzer;
30 import java.io.File;
31 import java.io.FileNotFoundException;
32 import java.io.IOException;
33 import java.lang.annotation.Annotation;
34 import java.nio.file.Files;
35 import java.nio.file.Path;
36 import java.nio.file.Paths;
37 import java.nio.file.StandardOpenOption;
38 import java.util.ArrayList;
39 import java.util.Arrays;
40 import java.util.List;
41 import jdk.test.lib.JDKToolLauncher;
42 import jdk.test.lib.Utils;
43 import jdk.test.lib.process.ProcessTools;
44
45 /**
46 * A simple class calling AOT compiler over requested items
47 */
48 public class AotCompiler {
49
50 private final static String METHODS_LIST_FILENAME = "methodsList.txt";
51
52 public static void main(String args[]) {
53 String className = null;
54 List<String> compileList = new ArrayList<>();
55 String libName = null;
56 List<String> extraopts = new ArrayList<>();
57 for (int i = 0; i < args.length; i++) {
58 switch (args[i]) {
59 case "-class":
60 className = args[++i];
61 break;
62 case "-compile":
63 compileList.add("compileOnly " + args[++i]);
91 List<String> compList) {
92 Path file = null;
93 if (compList != null && !compList.isEmpty()) {
94 file = Paths.get(METHODS_LIST_FILENAME);
95 try {
96 Files.write(file, compList, StandardOpenOption.CREATE);
97 } catch (IOException e) {
98 throw new Error("Couldn't write " + METHODS_LIST_FILENAME + " " + e, e);
99 }
100 }
101 List<String> args = new ArrayList<>();
102 args.add("--compile-with-assertions");
103 args.add("--output");
104 args.add(libName);
105 if (file != null) {
106 args.add("--compile-commands");
107 args.add(file.toString());
108 }
109 args.add("--class-name");
110 args.add(item);
111 String linker = resolveLinker();
112 if (linker != null) {
113 args.add("--linker-path");
114 args.add(linker);
115 }
116 return launchJaotc(args, extraopts);
117 }
118
119 private static OutputAnalyzer launchJaotc(List<String> args, List<String> extraVmOpts) {
120 JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jaotc");
121 for (String vmOpt : Utils.getTestJavaOpts()) {
122 launcher.addVMArg(vmOpt);
123 }
124 if (extraVmOpts != null) {
125 for (String vmOpt : extraVmOpts) {
126 launcher.addVMArg(vmOpt);
127 }
128 }
129 for (String arg : args) {
130 launcher.addToolArg(arg);
131 }
132 try {
133 return ProcessTools.executeCommand(new ProcessBuilder(launcher.getCommand()).redirectErrorStream(true));
134 } catch (Throwable e) {
135 throw new Error("Can't start test process: " + e, e);
136 }
137 }
138
139 public static void printUsage() {
140 System.err.println("Usage: " + AotCompiler.class.getName()
141 + " -class <class> -libname <.so name>"
142 + " [-compile <compileItems>]* [-extraopt <java option>]*");
143 }
144
145 public static String resolveLinker() {
146 Path linker = null;
147 // 1st, check if PATH has ld
148 for (String path : System.getenv("PATH").split(File.pathSeparator)) {
149 if (Files.exists(Paths.get(path).resolve("ld"))) {
150 // there is ld in PATH, jaotc is supposed to find it by its own
151 return null;
152 }
153 }
154 // there is no ld in PATH, will use ld from devkit
155 // artifacts are got from common/conf/jib-profiles.js
156 try {
157 if (Platform.isWindows()) {
158 if (Platform.isX64()) {
159 @Artifact(organization = "jpg.infra.builddeps",
160 name = "devkit-windows_x64",
161 revision = "VS2013SP4+1.0",
162 extension = "tar.gz")
163 class DevkitWindowsX64 { }
164 String artifactName = "jpg.infra.builddeps."
165 + "devkit-windows_x64-"
166 + "VS2013SP4+1.0";
167 Path devkit = ArtifactResolver.resolve(DevkitWindowsX64.class)
168 .get(artifactName);
169 linker = devkit.resolve("VC")
170 .resolve("bin")
171 .resolve("amd64")
172 .resolve("link.exe");
173 }
174 } else if (Platform.isOSX()) {
175 @Artifact(organization = "jpg.infra.builddeps",
176 name = "devkit-macosx_x64",
177 revision = "Xcode6.3-MacOSX10.9+1.0",
178 extension = "tar.gz")
179 class DevkitMacosx { }
180 String artifactName = "jpg.infra.builddeps."
181 + "devkit-macosx_x64-"
182 + "Xcode6.3-MacOSX10.9+1.0";
183 Path devkit = ArtifactResolver.resolve(DevkitMacosx.class)
184 .get(artifactName);
185 linker = devkit.resolve("Xcode.app")
186 .resolve("Contents")
187 .resolve("Developer")
188 .resolve("Toolchains")
189 .resolve("XcodeDefault.xctoolchain")
190 .resolve("usr")
191 .resolve("bin")
192 .resolve("ld");
193 } else if (Platform.isSolaris()) {
194 if (Platform.isSparc()) {
195 @Artifact(organization = "jpg.infra.builddeps",
196 name = "devkit-solaris_sparcv9",
197 revision = "SS12u4-Solaris11u1+1.0",
198 extension = "tar.gz")
199 class DevkitSolarisSparc { }
200
201 String artifactName = "jpg.infra.builddeps."
202 + "devkit-solaris_sparcv9-"
203 + "SS12u4-Solaris11u1+1.0";
204 Path devkit = ArtifactResolver.resolve(DevkitSolarisSparc.class)
205 .get(artifactName);
206 linker = devkit.resolve("SS12u4-Solaris11u1")
207 .resolve("gnu")
208 .resolve("bin")
209 .resolve("ld");
210 } else if (Platform.isX64()) {
211 @Artifact(organization = "jpg.infra.builddeps",
212 name = "devkit-solaris_x64",
213 revision = "SS12u4-Solaris11u1+1.0",
214 extension = "tar.gz")
215 class DevkitSolarisX64 { }
216
217 String artifactName = "jpg.infra.builddeps."
218 + "devkit-solaris_x64-"
219 + "SS12u4-Solaris11u1+1.0";
220 Path devkit = ArtifactResolver.resolve(DevkitSolarisX64.class)
221 .get(artifactName);
222 linker = devkit.resolve("SS12u4-Solaris11u1")
223 .resolve("bin")
224 .resolve("amd64")
225 .resolve("ld");
226 }
227 } else if (Platform.isLinux()) {
228 if (Platform.isAArch64()) {
229 @Artifact(organization = "jpg.infra.builddeps",
230 name = "devkit-linux_aarch64",
231 revision = "gcc-linaro-aarch64-linux-gnu-4.8-2013.11_linux+1.0",
232 extension = "tar.gz")
233 class DevkitLinuxAArch64 { }
234
235 String artifactName = "jpg.infra.builddeps."
236 + "devkit-linux_aarch64-"
237 + "gcc-linaro-aarch64-linux-gnu-4.8-2013.11_linux+1.0";
238 Path devkit = ArtifactResolver.resolve(DevkitLinuxAArch64.class)
239 .get(artifactName);
240 linker = devkit.resolve("aarch64-linux-gnu")
241 .resolve("bin")
242 .resolve("ld");
243 } else if (Platform.isARM()) {
244 @Artifact(organization = "jpg.infra.builddeps",
245 name = "devkit-linux_arm",
246 revision = "gcc-linaro-arm-linux-gnueabihf-raspbian-2012.09-20120921_linux+1.0",
247 extension = "tar.gz")
248 class DevkitLinuxARM { }
249
250 String artifactName = "jpg.infra.builddeps."
251 + "devkit-linux_arm-"
252 + "gcc-linaro-arm-linux-gnueabihf-raspbian-2012.09-20120921_linux+1.0";
253 Path devkit = ArtifactResolver.resolve(DevkitLinuxARM.class)
254 .get(artifactName);
255 linker = devkit.resolve("arm-linux-gnueabihf")
256 .resolve("bin")
257 .resolve("ld");
258 } else if (Platform.isX64()) {
259 @Artifact(organization = "jpg.infra.builddeps",
260 name = "devkit-linux_x64",
261 revision = "gcc4.9.2-OEL6.4+1.1",
262 extension = "tar.gz")
263 class DevkitLinuxX64 { }
264
265 String artifactName = "jpg.infra.builddeps."
266 + "devkit-linux_x64-"
267 + "gcc4.9.2-OEL6.4+1.1";
268 Path devkit = ArtifactResolver.resolve(DevkitLinuxX64.class)
269 .get(artifactName);
270 linker = devkit.resolve("bin")
271 .resolve("ld");
272 }
273 }
274 } catch (FileNotFoundException e) {
275 throw new Error("artifact resolution error: " + e, e);
276 }
277 if (linker != null) {
278 return linker.toAbsolutePath().toString();
279 }
280 return null;
281 }
282 }
|