8261666: [mlvm] Remove WhiteBoxHelper
Reviewed-by: iignatyev
This commit is contained in:
parent
50697965cf
commit
4acb88396e
@ -62,11 +62,12 @@ import java.lang.management.ManagementFactory;
|
||||
import java.lang.management.MemoryUsage;
|
||||
import java.util.HashSet;
|
||||
|
||||
import sun.hotspot.WhiteBox;
|
||||
|
||||
import nsk.share.test.Stresser;
|
||||
import vm.mlvm.share.CustomClassLoaders;
|
||||
import vm.mlvm.share.Env;
|
||||
import vm.mlvm.share.MlvmTest;
|
||||
import vm.mlvm.share.WhiteBoxHelper;
|
||||
import vm.share.FileUtils;
|
||||
import vm.share.options.Option;
|
||||
|
||||
@ -87,6 +88,7 @@ public class Test extends MlvmTest {
|
||||
@Option(name = "iterations", default_value = "100000", description = "Iterations: each iteration loads one new class")
|
||||
private int iterations = 100_000;
|
||||
|
||||
private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
|
||||
private static final int GC_COUNT = 6;
|
||||
private static final boolean TERMINATE_ON_FULL_METASPACE = false;
|
||||
|
||||
@ -133,15 +135,6 @@ public class Test extends MlvmTest {
|
||||
return null;
|
||||
}
|
||||
|
||||
private MethodHandle getFullGCMethod() throws NoSuchMethodException, IllegalAccessException {
|
||||
try {
|
||||
return WhiteBoxHelper.getMethod("fullGC", MethodType.methodType(void.class));
|
||||
} catch (NoSuchMethodException | ClassNotFoundException | InvocationTargetException e) {
|
||||
Env.traceDebug(e, "No WhiteBox API. Will use System.gc() instead of WhiteBox.fullGC()");
|
||||
return MethodHandles.lookup().findStatic(System.class, "gc", MethodType.methodType(void.class));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean run() throws Throwable {
|
||||
setHeapDumpAfter(heapDumpOpt);
|
||||
@ -150,8 +143,6 @@ public class Test extends MlvmTest {
|
||||
final MemoryPoolMXBean classMetadataPoolMXB = getClassMetadataMemoryPoolMXBean();
|
||||
final String memPoolName = classMetadataPoolMXB == null ? "" : classMetadataPoolMXB.getName();
|
||||
|
||||
MethodHandle mhCollectHeap = getFullGCMethod();
|
||||
|
||||
int removedEntries = 0;
|
||||
|
||||
Stresser stresser = createStresser();
|
||||
@ -183,7 +174,7 @@ public class Test extends MlvmTest {
|
||||
}
|
||||
|
||||
for (int i = 0; i < GC_COUNT; ++i) {
|
||||
mhCollectHeap.invoke();
|
||||
WHITE_BOX.fullGC();
|
||||
Thread.sleep(500);
|
||||
removedEntries += removeQueuedReferences();
|
||||
}
|
||||
|
@ -1,68 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package vm.mlvm.share;
|
||||
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.invoke.MethodType;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
/**
|
||||
* WhiteBoxHelper class obtains a MethodHandle to a method defined in sun.hotspot.WhiteBox class.
|
||||
* If WhiteBox is not available or cannot be initialized, or the method is not available,
|
||||
* it throws an appropriate exception.
|
||||
*
|
||||
* This class was introduced to avoid "hard link" to WhiteBox.
|
||||
*
|
||||
*/
|
||||
public class WhiteBoxHelper {
|
||||
|
||||
/**
|
||||
* Obtains {@link java.lang.invoke.MethodHandle} to a method in sun.hotspot.WhiteBox class.
|
||||
* If there is an error obtaining method handle, an exception is thrown.
|
||||
*
|
||||
* @param name Method name
|
||||
* @type Method type
|
||||
* @return {@link java.lang.invoke.MethodHandle} to the method. You can call it directly, WhiteBox instance is already bound to the handle.
|
||||
* @throws IllegalAccessException if method cannot be accessed (see {@link java.lang.invoke.MethodHandles.Lookup#findStatic()} for details)
|
||||
* @throws NoSuchMethodException if method cannot be found (see {@link java.lang.invoke.MethodHandles.Lookup#findStatic()} for details)
|
||||
* @throws ClassNotFoundException if WhiteBox class cannot be loaded
|
||||
* @throws InvocationTargetException if WhiteBox.getWhiteBox() method throws exception for some reason
|
||||
*/
|
||||
public static MethodHandle getMethod(String name, MethodType type)
|
||||
throws IllegalAccessException, NoSuchMethodException, ClassNotFoundException, InvocationTargetException {
|
||||
|
||||
Class<?> wbClass = Class.forName("sun.hotspot.WhiteBox");
|
||||
MethodHandles.Lookup lu = MethodHandles.lookup();
|
||||
MethodHandle getWB = lu.findStatic(wbClass, "getWhiteBox", MethodType.methodType(wbClass));
|
||||
Object wb;
|
||||
try {
|
||||
wb = getWB.invoke();
|
||||
} catch (Throwable e) {
|
||||
throw new InvocationTargetException(e, "Can't obtain WhiteBox instance");
|
||||
}
|
||||
return lu.findVirtual(wbClass, name, type).bindTo(wb);
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user