Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8312049: runtime/logging/ClassLoadUnloadTest can be improved #2920

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");

}
}