Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/gc/g1/unloading/bytecode/GenClassesBuilder.java
41161 views
1
/*
2
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
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 gc.g1.unloading.bytecode;
25
26
import jdk.test.lib.JDKToolLauncher;
27
import jdk.test.lib.Utils;
28
import jdk.test.lib.process.ProcessTools;
29
30
import java.io.IOException;
31
import java.nio.file.Files;
32
import java.nio.file.Path;
33
import java.nio.file.Paths;
34
import java.util.Arrays;
35
import java.util.stream.Stream;
36
37
/**
38
* Uses {@link gc.g1.unloading.bytecode.HumongousTemplateClassGen} to generate
39
* source code of HumongousTemplateClass and compiles it to {@code test.classes}.
40
*/
41
public class GenClassesBuilder {
42
public static void main(String[] args) {
43
Path genSrc = Paths.get("genSrc").toAbsolutePath();
44
Path classesDir = Paths.get(Utils.TEST_CLASSES).toAbsolutePath();
45
generateSource(genSrc);
46
compileSource(genSrc, classesDir);
47
}
48
49
private static void compileSource(Path srcDst, Path classesDir) {
50
JDKToolLauncher javac = JDKToolLauncher.create("javac")
51
.addToolArg("-d")
52
.addToolArg(classesDir.toString())
53
.addToolArg("-cp")
54
.addToolArg(Utils.TEST_CLASS_PATH);
55
try (Stream<Path> stream = Files.walk(srcDst)) {
56
stream.map(Path::toAbsolutePath)
57
.map(Path::toString)
58
.filter(s -> s.endsWith(".java"))
59
.forEach(javac::addToolArg);
60
} catch (IOException e) {
61
throw new Error("traverse source dir " + srcDst, e);
62
}
63
String[] command = javac.getCommand();
64
try {
65
ProcessTools.executeCommand(command)
66
.shouldHaveExitValue(0);
67
} catch (Error | RuntimeException e) {
68
throw e;
69
} catch (Throwable e) {
70
throw new Error("execution of javac(" + Arrays.toString(command) + ") failed", e);
71
}
72
}
73
74
private static void generateSource(Path dir) {
75
try {
76
Files.createDirectories(dir);
77
} catch (IOException e) {
78
throw new Error("can't create dirs for" + dir, e);
79
}
80
81
try {
82
HumongousTemplateClassGen.main(new String[]{dir.toString()});
83
} catch (Exception e) {
84
throw new Error("can't generate classes", e);
85
}
86
}
87
}
88
89
90