< prev index next >
test/hotspot/jtreg/runtime/MemberName/MemberNameLeak.java
Print this page
*** 32,68 ****
*/
import java.lang.invoke.*;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
!
import sun.hotspot.code.Compiler;
public class MemberNameLeak {
static class Leak {
public void callMe() {
}
public static void main(String[] args) throws Throwable {
Leak leak = new Leak();
for (int i = 0; i < 10; i++) {
MethodHandles.Lookup lookup = MethodHandles.lookup();
MethodType mt = MethodType.fromMethodDescriptorString("()V", Leak.class.getClassLoader());
// findSpecial leaks some native mem
MethodHandle mh = lookup.findSpecial(Leak.class, "callMe", mt, Leak.class);
mh.invokeExact(leak);
}
System.gc(); // make mh unused
}
}
public static void test(String gc) throws Throwable {
// Run this Leak class with logging
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
"-Xlog:membername+table=trace",
gc, Leak.class.getName());
OutputAnalyzer output = new OutputAnalyzer(pb.start());
output.shouldContain("ResolvedMethod entry added for MemberNameLeak$Leak.callMe()V");
output.shouldContain("ResolvedMethod entry found for MemberNameLeak$Leak.callMe()V");
output.shouldContain("ResolvedMethod entry removed");
--- 32,78 ----
*/
import java.lang.invoke.*;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
! import sun.hotspot.WhiteBox;
import sun.hotspot.code.Compiler;
public class MemberNameLeak {
static class Leak {
public void callMe() {
}
public static void main(String[] args) throws Throwable {
Leak leak = new Leak();
+ WhiteBox wb = WhiteBox.getWhiteBox();
+ int removedCountOrig = wb.resolvedMethodRemovedCount();
+ int removedCount;
for (int i = 0; i < 10; i++) {
MethodHandles.Lookup lookup = MethodHandles.lookup();
MethodType mt = MethodType.fromMethodDescriptorString("()V", Leak.class.getClassLoader());
// findSpecial leaks some native mem
MethodHandle mh = lookup.findSpecial(Leak.class, "callMe", mt, Leak.class);
mh.invokeExact(leak);
}
System.gc(); // make mh unused
+
+ // Wait until ServiceThread cleans ResolvedMethod table
+ do {
+ removedCount = wb.resolvedMethodRemovedCount();
+ } while (removedCountOrig == removedCount);
}
}
public static void test(String gc) throws Throwable {
// Run this Leak class with logging
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
"-Xlog:membername+table=trace",
+ "-XX:+WhiteBoxAPI",
+ "-Xbootclasspath/a:.",
gc, Leak.class.getName());
OutputAnalyzer output = new OutputAnalyzer(pb.start());
output.shouldContain("ResolvedMethod entry added for MemberNameLeak$Leak.callMe()V");
output.shouldContain("ResolvedMethod entry found for MemberNameLeak$Leak.callMe()V");
output.shouldContain("ResolvedMethod entry removed");
< prev index next >