2017-05-27 13:21:01 +00:00
|
|
|
/*
|
2018-04-18 16:06:53 +00:00
|
|
|
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
|
2017-05-27 13:21:01 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @test
|
2018-11-13 10:45:16 +00:00
|
|
|
* @bug 8174749 8213307
|
2017-05-27 13:21:01 +00:00
|
|
|
* @summary MemberNameTable should reuse entries
|
2018-11-13 10:45:16 +00:00
|
|
|
* @requires vm.gc == "null"
|
2017-05-27 13:21:01 +00:00
|
|
|
* @library /test/lib
|
2018-06-08 00:38:34 +00:00
|
|
|
* @build sun.hotspot.WhiteBox
|
|
|
|
* @run driver ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
|
|
|
|
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. MemberNameLeak
|
2017-05-27 13:21:01 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
import java.lang.invoke.*;
|
|
|
|
import jdk.test.lib.process.OutputAnalyzer;
|
|
|
|
import jdk.test.lib.process.ProcessTools;
|
2018-08-29 14:46:59 +00:00
|
|
|
import sun.hotspot.WhiteBox;
|
2018-06-08 00:38:34 +00:00
|
|
|
import sun.hotspot.code.Compiler;
|
|
|
|
|
2017-05-27 13:21:01 +00:00
|
|
|
public class MemberNameLeak {
|
|
|
|
static class Leak {
|
|
|
|
public void callMe() {
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void main(String[] args) throws Throwable {
|
|
|
|
Leak leak = new Leak();
|
2018-08-29 14:46:59 +00:00
|
|
|
WhiteBox wb = WhiteBox.getWhiteBox();
|
|
|
|
int removedCountOrig = wb.resolvedMethodRemovedCount();
|
|
|
|
int removedCount;
|
2017-05-27 13:21:01 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2018-08-29 14:46:59 +00:00
|
|
|
// Wait until ServiceThread cleans ResolvedMethod table
|
2018-09-11 17:34:13 +00:00
|
|
|
int cnt = 0;
|
|
|
|
while (true) {
|
|
|
|
if (cnt++ % 30 == 0) {
|
|
|
|
System.gc(); // make mh unused
|
|
|
|
}
|
2018-08-29 14:46:59 +00:00
|
|
|
removedCount = wb.resolvedMethodRemovedCount();
|
2018-09-11 17:34:13 +00:00
|
|
|
if (removedCountOrig != removedCount) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
Thread.sleep(100);
|
|
|
|
}
|
2017-05-27 13:21:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-13 10:45:16 +00:00
|
|
|
public static void test(String gc, boolean doConcurrent) throws Throwable {
|
2018-09-11 17:34:13 +00:00
|
|
|
// Run this Leak class with logging
|
2017-05-27 13:21:01 +00:00
|
|
|
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
|
|
|
|
"-Xlog:membername+table=trace",
|
2018-09-11 17:34:13 +00:00
|
|
|
"-XX:+UnlockDiagnosticVMOptions",
|
2018-08-29 14:46:59 +00:00
|
|
|
"-XX:+WhiteBoxAPI",
|
|
|
|
"-Xbootclasspath/a:.",
|
2018-11-13 10:45:16 +00:00
|
|
|
doConcurrent ? "-XX:+ExplicitGCInvokesConcurrent" : "-XX:-ExplicitGCInvokesConcurrent",
|
|
|
|
"-XX:+ClassUnloading",
|
|
|
|
"-XX:+ClassUnloadingWithConcurrentMark",
|
2017-05-27 13:21:01 +00:00
|
|
|
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");
|
2018-04-18 16:06:53 +00:00
|
|
|
output.shouldContain("ResolvedMethod entry removed");
|
2017-05-27 13:21:01 +00:00
|
|
|
output.shouldHaveExitValue(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void main(java.lang.String[] unused) throws Throwable {
|
2018-11-13 10:45:16 +00:00
|
|
|
test("-XX:+UseG1GC", false);
|
|
|
|
test("-XX:+UseG1GC", true);
|
|
|
|
|
|
|
|
test("-XX:+UseParallelGC", false);
|
|
|
|
test("-XX:+UseSerialGC", false);
|
2018-06-08 00:38:34 +00:00
|
|
|
if (!Compiler.isGraalEnabled()) { // Graal does not support CMS
|
2018-11-13 10:45:16 +00:00
|
|
|
test("-XX:+UseConcMarkSweepGC", false);
|
|
|
|
test("-XX:+UseConcMarkSweepGC", true);
|
2018-06-08 00:38:34 +00:00
|
|
|
}
|
2017-05-27 13:21:01 +00:00
|
|
|
}
|
|
|
|
}
|