Skip to content

Commit

Permalink
Backport 4676b40f17dd18941f5883cb9b989ad639992a50
Browse files Browse the repository at this point in the history
  • Loading branch information
cost0much committed Aug 23, 2024
1 parent 828d645 commit 7e9fb1f
Showing 1 changed file with 36 additions and 39 deletions.
75 changes: 36 additions & 39 deletions test/hotspot/jtreg/runtime/logging/ClassLoadUnloadTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@
import java.util.List;

public class ClassLoadUnloadTest {
private static OutputAnalyzer out;
private static ProcessBuilder pb;
private static class ClassUnloadTestMain {
public static void main(String... args) throws Exception {
String className = "test.Empty";
Expand All @@ -54,79 +52,78 @@ public static void main(String... args) throws Exception {
}
}

static void checkFor(String... outputStrings) throws Exception {
out = new OutputAnalyzer(pb.start());
static void checkFor(OutputAnalyzer output, String... outputStrings) throws Exception {
for (String s: outputStrings) {
out.shouldContain(s);
output.shouldContain(s);
}
out.shouldHaveExitValue(0);
}

static void checkAbsent(String... outputStrings) throws Exception {
out = new OutputAnalyzer(pb.start());
static void checkAbsent(OutputAnalyzer output, String... outputStrings) throws Exception {
for (String s: outputStrings) {
out.shouldNotContain(s);
output.shouldNotContain(s);
}
out.shouldHaveExitValue(0);
}

// Use the same command-line heap size setting as ../ClassUnload/UnloadTest.java
static ProcessBuilder exec(String... args) throws Exception {
static OutputAnalyzer exec(String... args) throws Exception {
List<String> argsList = new ArrayList<>();
Collections.addAll(argsList, args);
Collections.addAll(argsList, "-Xmn8m");
Collections.addAll(argsList, "-Dtest.class.path=" + System.getProperty("test.class.path", "."));
Collections.addAll(argsList, "-XX:+ClassUnloading");
Collections.addAll(argsList, ClassUnloadTestMain.class.getName());
return ProcessTools.createJavaProcessBuilder(argsList);
Collections.addAll(argsList, "-Xmn8m", "-Dtest.class.path=" + System.getProperty("test.class.path", "."),
"-XX:+ClassUnloading", ClassUnloadTestMain.class.getName());
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(argsList);
OutputAnalyzer output = new OutputAnalyzer(pb.start());
output.shouldHaveExitValue(0);
return output;
}

public static void main(String... args) throws Exception {

OutputAnalyzer output;

// -Xlog:class+unload=info
pb = exec("-Xlog:class+unload=info");
checkFor("[class,unload]", "unloading class");
output = exec("-Xlog:class+unload=info");
checkFor(output, "[class,unload]", "unloading class");

// -Xlog:class+unload=off
pb = exec("-Xlog:class+unload=off");
checkAbsent("[class,unload]");
output = exec("-Xlog:class+unload=off");
checkAbsent(output,"[class,unload]");

// -XX:+TraceClassUnloading
pb = exec("-XX:+TraceClassUnloading");
checkFor("[class,unload]", "unloading class");
output = exec("-XX:+TraceClassUnloading");
checkFor(output, "[class,unload]", "unloading class");

// -XX:-TraceClassUnloading
pb = exec("-XX:-TraceClassUnloading");
checkAbsent("[class,unload]");
output = exec("-XX:-TraceClassUnloading");
checkAbsent(output, "[class,unload]");

// -Xlog:class+load=info
pb = exec("-Xlog:class+load=info");
checkFor("[class,load]", "java.lang.Object", "source:");
output = exec("-Xlog:class+load=info");
checkFor(output,"[class,load]", "java.lang.Object", "source:");

// -Xlog:class+load=debug
pb = exec("-Xlog:class+load=debug");
checkFor("[class,load]", "java.lang.Object", "source:", "klass:", "super:", "loader:", "bytes:");
output = exec("-Xlog:class+load=debug");
checkFor(output,"[class,load]", "java.lang.Object", "source:", "klass:", "super:", "loader:", "bytes:");

// -Xlog:class+load=off
pb = exec("-Xlog:class+load=off");
checkAbsent("[class,load]");
output = exec("-Xlog:class+load=off");
checkAbsent(output,"[class,load]");

// -XX:+TraceClassLoading
pb = exec("-XX:+TraceClassLoading");
checkFor("[class,load]", "java.lang.Object", "source:");
output = exec("-XX:+TraceClassLoading");
checkFor(output, "[class,load]", "java.lang.Object", "source:");

// -XX:-TraceClassLoading
pb = exec("-XX:-TraceClassLoading");
checkAbsent("[class,load]");
output = exec("-XX:-TraceClassLoading");
checkAbsent(output, "[class,load]");

// -verbose:class
pb = exec("-verbose:class");
checkFor("[class,load]", "java.lang.Object", "source:");
checkFor("[class,unload]", "unloading class");
output = exec("-verbose:class");
checkFor(output,"[class,load]", "java.lang.Object", "source:");
checkFor(output,"[class,unload]", "unloading class");

// -Xlog:class+loader+data=trace
pb = exec("-Xlog:class+loader+data=trace");
checkFor("[class,loader,data]", "create loader data");
output = exec("-Xlog:class+loader+data=trace");
checkFor(output, "[class,loader,data]", "create loader data");

}
}

0 comments on commit 7e9fb1f

Please sign in to comment.