Skip to content

Commit 314e9b3

Browse files
caojoshuaPaul Hohensee
authored andcommitted
8300829: Make CtwRunner available as an independent tool
Reviewed-by: xliu, phh
1 parent 0a34018 commit 314e9b3

File tree

3 files changed

+67
-44
lines changed

3 files changed

+67
-44
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist/

test/hotspot/jtreg/testlibrary/ctw/Makefile

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ LIB_FILES = $(shell find $(TESTLIBRARY_DIR)/jdk/test/lib/ \
4848
$(TESTLIBRARY_DIR)/jtreg \
4949
-maxdepth 1 -name '*.java')
5050
WB_SRC_FILES = $(shell find $(TESTLIBRARY_DIR)/jdk/test/lib/compiler $(TESTLIBRARY_DIR)/jdk/test/whitebox -name '*.java')
51+
WB_CLASS_FILES := $(subst $(TESTLIBRARY_DIR)/,,$(WB_SRC_FILES))
52+
WB_CLASS_FILES := $(patsubst %.java,%.class,$(WB_CLASS_FILES))
5153
EXPORTS=--add-exports java.base/jdk.internal.jimage=ALL-UNNAMED \
5254
--add-exports java.base/jdk.internal.misc=ALL-UNNAMED \
5355
--add-exports java.base/jdk.internal.module=ALL-UNNAMED \
@@ -58,7 +60,8 @@ EXPORTS=--add-exports java.base/jdk.internal.jimage=ALL-UNNAMED \
5860
--add-exports java.base/jdk.internal.classfile.java.lang.constant=ALL-UNNAMED \
5961
--add-exports java.base/jdk.internal.access=ALL-UNNAMED
6062

61-
MAIN_CLASS = sun.hotspot.tools.ctw.CompileTheWorld
63+
CTW_MAIN_CLASS = sun.hotspot.tools.ctw.CompileTheWorld
64+
CTWRUNNER_MAIN_CLASS = sun.hotspot.tools.ctw.CtwRunner
6265

6366
.PHONY: clean cleantmp
6467

@@ -78,22 +81,24 @@ $(DST_DIR)/ctw.sh: $(DST_DIR)
7881
echo '$${JAVA_HOME}/bin/java $${JAVA_OPTIONS} $(EXPORTS) -XX:-UseCounterDecay -Xbatch "-XX:CompileCommand=exclude,java/lang/invoke/MethodHandle.*" -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:wb.jar -jar ctw.jar $$@' > $@
7982
chmod a+x $@
8083

84+
$(DST_DIR)/ctwrunner.sh: $(DST_DIR)
85+
echo '$${JAVA_HOME}/bin/java $${JAVA_OPTIONS} -Dtest.jdk=$${JAVA_HOME} -cp ctw.jar $(CTWRUNNER_MAIN_CLASS) $$@' > $@
86+
chmod a+x $@
87+
8188
$(DST_DIR)/ctw.jar: filelist $(DST_DIR)/wb.jar
8289
@mkdir -p $(OUTPUT_DIR)
8390
$(JAVAC) $(EXPORTS) -sourcepath $(SRC_DIR) -d $(OUTPUT_DIR) -cp $(DST_DIR)/wb.jar @filelist
84-
$(JAR) --create --file=$@ --main-class $(MAIN_CLASS) -C $(OUTPUT_DIR) .
91+
$(JAR) --create --file=$@ --main-class $(CTW_MAIN_CLASS) -C $(OUTPUT_DIR) .
8592
@rm -rf $(OUTPUT_DIR)
8693

8794
$(DST_DIR)/wb.jar: wb_filelist $(DST_DIR)
88-
@mkdir -p $(OUTPUT_DIR)
8995
$(JAVAC) -sourcepath $(TESTLIBRARY_DIR) \
90-
-d $(OUTPUT_DIR) \
96+
-d $(DST_DIR) \
9197
-cp $(OUTPUT_DIR) \
9298
@wb_filelist
93-
$(JAR) --create --file=$@ -C $(OUTPUT_DIR) .
94-
@rm -rf $(OUTPUT_DIR)
99+
cd $(DST_DIR); $(JAR) --create --file=wb.jar $(WB_CLASS_FILES)
95100

96-
$(DST_DIR)/ctw.zip: $(DST_DIR)/ctw.sh $(DST_DIR)/wb.jar $(DST_DIR)/ctw.jar
101+
$(DST_DIR)/ctw.zip: $(DST_DIR)/ctw.sh $(DST_DIR)/ctwrunner.sh $(DST_DIR)/wb.jar $(DST_DIR)/ctw.jar $(DST_DIR)/ctwrunner.sh
97102
zip -j $@ $?
98103

99104
wb_filelist: $(WB_SRC_FILES)

test/hotspot/jtreg/testlibrary/ctw/src/sun/hotspot/tools/ctw/CtwRunner.java

Lines changed: 54 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -34,6 +34,7 @@
3434
import java.nio.file.Path;
3535
import java.nio.file.Paths;
3636
import java.util.ArrayList;
37+
import java.util.Arrays;
3738
import java.util.List;
3839
import java.util.concurrent.TimeUnit;
3940
import java.util.function.Predicate;
@@ -52,6 +53,14 @@ public class CtwRunner {
5253
private static final Predicate<String> IS_CLASS_LINE = Pattern.compile(
5354
"^\\[\\d+\\]\\s*\\S+\\s*$").asPredicate();
5455

56+
/**
57+
* Value of {@code -Dsun.hotspot.tools.ctwrunner.ctw_extra_args}. Extra
58+
* comma-separated arguments to pass to CTW subprocesses.
59+
*/
60+
private static final String CTW_EXTRA_ARGS
61+
= System.getProperty("sun.hotspot.tools.ctwrunner.ctw_extra_args", "");
62+
63+
5564
private static final String USAGE = "Usage: CtwRunner <artifact to compile> [start[%] stop[%]]";
5665

5766
public static void main(String[] args) throws Exception {
@@ -258,43 +267,51 @@ private String[] cmd(long classStart, long classStop) {
258267
String phase = phaseName(classStart);
259268
Path file = Paths.get(phase + ".cmd");
260269
var rng = Utils.getRandomInstance();
270+
271+
ArrayList<String> Args = new ArrayList<String>(Arrays.asList(
272+
"-Xbatch",
273+
"-XX:-UseCounterDecay",
274+
"-XX:-ShowMessageBoxOnError",
275+
"-XX:+UnlockDiagnosticVMOptions",
276+
// redirect VM output to cerr so it won't collide w/ ctw output
277+
"-XX:+DisplayVMOutputToStderr",
278+
// define phase start
279+
"-DCompileTheWorldStartAt=" + classStart,
280+
"-DCompileTheWorldStopAt=" + classStop,
281+
// CTW library uses WhiteBox API
282+
"-XX:+WhiteBoxAPI", "-Xbootclasspath/a:.",
283+
// export jdk.internal packages used by CTW library
284+
"--add-exports", "java.base/jdk.internal.jimage=ALL-UNNAMED",
285+
"--add-exports", "java.base/jdk.internal.misc=ALL-UNNAMED",
286+
"--add-exports", "java.base/jdk.internal.reflect=ALL-UNNAMED",
287+
"--add-exports", "java.base/jdk.internal.access=ALL-UNNAMED",
288+
// enable diagnostic logging
289+
"-XX:+LogCompilation",
290+
// use phase specific log, hs_err and ciReplay files
291+
String.format("-XX:LogFile=hotspot_%s_%%p.log", phase),
292+
String.format("-XX:ErrorFile=hs_err_%s_%%p.log", phase),
293+
String.format("-XX:ReplayDataFile=replay_%s_%%p.log", phase),
294+
// MethodHandle MUST NOT be compiled
295+
"-XX:CompileCommand=exclude,java/lang/invoke/MethodHandle.*",
296+
// Stress* are c2-specific stress flags, so IgnoreUnrecognizedVMOptions is needed
297+
"-XX:+IgnoreUnrecognizedVMOptions",
298+
"-XX:+StressLCM",
299+
"-XX:+StressGCM",
300+
"-XX:+StressIGVN",
301+
"-XX:+StressCCP",
302+
// StressSeed is uint
303+
"-XX:StressSeed=" + Math.abs(rng.nextInt())));
304+
305+
for (String arg : CTW_EXTRA_ARGS.split(",")) {
306+
Args.add(arg);
307+
}
308+
309+
// CTW entry point
310+
Args.add(CompileTheWorld.class.getName());
311+
Args.add(target);
312+
261313
try {
262-
Files.write(file, List.of(
263-
"-Xbatch",
264-
"-XX:-UseCounterDecay",
265-
"-XX:-ShowMessageBoxOnError",
266-
"-XX:+UnlockDiagnosticVMOptions",
267-
// redirect VM output to cerr so it won't collide w/ ctw output
268-
"-XX:+DisplayVMOutputToStderr",
269-
// define phase start
270-
"-DCompileTheWorldStartAt=" + classStart,
271-
"-DCompileTheWorldStopAt=" + classStop,
272-
// CTW library uses WhiteBox API
273-
"-XX:+WhiteBoxAPI", "-Xbootclasspath/a:.",
274-
// export jdk.internal packages used by CTW library
275-
"--add-exports", "java.base/jdk.internal.jimage=ALL-UNNAMED",
276-
"--add-exports", "java.base/jdk.internal.misc=ALL-UNNAMED",
277-
"--add-exports", "java.base/jdk.internal.reflect=ALL-UNNAMED",
278-
"--add-exports", "java.base/jdk.internal.access=ALL-UNNAMED",
279-
// enable diagnostic logging
280-
"-XX:+LogCompilation",
281-
// use phase specific log, hs_err and ciReplay files
282-
String.format("-XX:LogFile=hotspot_%s_%%p.log", phase),
283-
String.format("-XX:ErrorFile=hs_err_%s_%%p.log", phase),
284-
String.format("-XX:ReplayDataFile=replay_%s_%%p.log", phase),
285-
// MethodHandle MUST NOT be compiled
286-
"-XX:CompileCommand=exclude,java/lang/invoke/MethodHandle.*",
287-
// Stress* are c2-specific stress flags, so IgnoreUnrecognizedVMOptions is needed
288-
"-XX:+IgnoreUnrecognizedVMOptions",
289-
"-XX:+StressLCM",
290-
"-XX:+StressGCM",
291-
"-XX:+StressIGVN",
292-
"-XX:+StressCCP",
293-
// StressSeed is uint
294-
"-XX:StressSeed=" + Math.abs(rng.nextInt()),
295-
// CTW entry point
296-
CompileTheWorld.class.getName(),
297-
target));
314+
Files.write(file, Args);
298315
} catch (IOException e) {
299316
throw new Error("can't create " + file, e);
300317
}

0 commit comments

Comments
 (0)