8067223: [TESTBUG] Rename Whitebox API package

Reviewed-by: dholmes, kvn
This commit is contained in:
Igor Ignatyev 2021-08-02 20:44:18 +00:00
parent f8fb571307
commit ada58d13f7
36 changed files with 1394 additions and 72 deletions

View File

@ -244,6 +244,7 @@ static JNINativeMethod lookup_special_native_methods[] = {
{ CC"Java_jdk_internal_invoke_NativeEntryPoint_registerNatives", NULL, FN_PTR(JVM_RegisterNativeEntryPointMethods) },
{ CC"Java_jdk_internal_perf_Perf_registerNatives", NULL, FN_PTR(JVM_RegisterPerfMethods) },
{ CC"Java_sun_hotspot_WhiteBox_registerNatives", NULL, FN_PTR(JVM_RegisterWhiteBoxMethods) },
{ CC"Java_jdk_test_whitebox_WhiteBox_registerNatives", NULL, FN_PTR(JVM_RegisterWhiteBoxMethods) },
{ CC"Java_jdk_internal_vm_vector_VectorSupport_registerNatives", NULL, FN_PTR(JVM_RegisterVectorSupportMethods)},
#if INCLUDE_JVMCI
{ CC"Java_jdk_vm_ci_runtime_JVMCI_initializeRuntime", NULL, FN_PTR(JVM_GetJVMCIRuntime) },

View File

@ -50,7 +50,7 @@
* This method Returns a char* representation of that enum value.
*/
static const char* lookup_diagnosticArgumentEnum(const char* field_name, oop object) {
const char* enum_sig = "Lsun/hotspot/parser/DiagnosticCommand$DiagnosticArgumentType;";
const char* enum_sig = "Ljdk/test/whitebox/parser/DiagnosticCommand$DiagnosticArgumentType;";
TempNewSymbol enumSigSymbol = SymbolTable::new_symbol(enum_sig);
int offset = WhiteBox::offset_for_field(field_name, object, enumSigSymbol);
oop enumOop = object->obj_field(offset);

View File

@ -2151,6 +2151,9 @@ bool WhiteBox::lookup_bool(const char* field_name, oop object) {
void WhiteBox::register_methods(JNIEnv* env, jclass wbclass, JavaThread* thread, JNINativeMethod* method_array, int method_count) {
ResourceMark rm;
Klass* klass = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(wbclass));
const char* klass_name = klass->external_name();
ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI
// one by one registration natives for exception catching
@ -2166,13 +2169,13 @@ void WhiteBox::register_methods(JNIEnv* env, jclass wbclass, JavaThread* thread,
if (env->IsInstanceOf(throwable_obj, no_such_method_error_klass)) {
// NoSuchMethodError is thrown when a method can't be found or a method is not native.
// Ignoring the exception since it is not preventing use of other WhiteBox methods.
tty->print_cr("Warning: 'NoSuchMethodError' on register of sun.hotspot.WhiteBox::%s%s",
method_array[i].name, method_array[i].signature);
tty->print_cr("Warning: 'NoSuchMethodError' on register of %s::%s%s",
klass_name, method_array[i].name, method_array[i].signature);
}
} else {
// Registration failed unexpectedly.
tty->print_cr("Warning: unexpected error on register of sun.hotspot.WhiteBox::%s%s. All methods will be unregistered",
method_array[i].name, method_array[i].signature);
tty->print_cr("Warning: unexpected error on register of %s::%s%s. All methods will be unregistered",
klass_name, method_array[i].name, method_array[i].signature);
env->UnregisterNatives(wbclass);
break;
}
@ -2387,7 +2390,7 @@ static JNINativeMethod methods[] = {
{CC"countAliveClasses0", CC"(Ljava/lang/String;)I", (void*)&WB_CountAliveClasses },
{CC"getSymbolRefcount", CC"(Ljava/lang/String;)I", (void*)&WB_GetSymbolRefcount },
{CC"parseCommandLine0",
CC"(Ljava/lang/String;C[Lsun/hotspot/parser/DiagnosticCommand;)[Ljava/lang/Object;",
CC"(Ljava/lang/String;C[Ljdk/test/whitebox/parser/DiagnosticCommand;)[Ljava/lang/Object;",
(void*) &WB_ParseCommandLine
},
{CC"addToBootstrapClassLoaderSearch0", CC"(Ljava/lang/String;)V",

View File

@ -40,7 +40,7 @@ groups=TEST.groups TEST.quick-groups
# to determine additional characteristics of the system for use with the @requires tag.
# Note: compiled bootlibs classes will be added to BCP.
requires.extraPropDefns = ../../jtreg-ext/requires/VMProps.java
requires.extraPropDefns.bootlibs = ../../lib/sun
requires.extraPropDefns.bootlibs = ../../lib/jdk/test/whitebox
requires.extraPropDefns.libs = \
../../lib/jdk/test/lib/Platform.java \
../../lib/jdk/test/lib/Container.java

View File

@ -37,9 +37,9 @@
* jdk.internal.vm.ci/jdk.vm.ci.runtime
*
* @build jdk.internal.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper
* sun.hotspot.WhiteBox sun.hotspot.parser.DiagnosticCommand
* sun.hotspot.WhiteBox jdk.test.whitebox.parser.DiagnosticCommand
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
* sun.hotspot.parser.DiagnosticCommand
* jdk.test.whitebox.parser.DiagnosticCommand
* @run main/othervm -Xbootclasspath/a:.
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
* -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI

View File

@ -131,14 +131,19 @@ public class JarBuilder {
}
// Add commonly used inner classes that are often omitted by mistake. Currently
// we support only sun/hotspot/WhiteBox$WhiteBoxPermission. See JDK-8199290
// we support only jdk/test/whitebox/WhiteBox$WhiteBoxPermission and
// sun/hotspot/WhiteBox$WhiteBoxPermission. See JDK-8199290
private static String[] addInnerClasses(String[] classes, int startIdx) {
boolean seenWB = false;
boolean seenWBInner = false;
boolean seenNewWb = false;
boolean seenNewWbInner = false;
boolean seenOldWb = false;
boolean seenOldWbInner = false;
// This method is different than ClassFileInstaller.addInnerClasses which
// uses "." as the package delimiter :-(
final String wb = "sun/hotspot/WhiteBox";
final String wbInner = "sun/hotspot/WhiteBox$WhiteBoxPermission";
final String newWb = "jdk/test/whitebox/WhiteBox";
final String newWbInner = newWb + "$WhiteBoxPermission";
final String oldWb = "sun/hotspot/WhiteBox";
final String oldWbInner = oldWb + "$WhiteBoxPermission";
ArrayList<String> list = new ArrayList<>();
@ -146,12 +151,17 @@ public class JarBuilder {
String cls = classes[i];
list.add(cls);
switch (cls) {
case wb: seenWB = true; break;
case wbInner: seenWBInner = true; break;
case newWb: seenNewWb = true; break;
case newWbInner: seenNewWbInner = true; break;
case oldWb: seenOldWb = true; break;
case oldWbInner: seenOldWbInner = true; break;
}
}
if (seenWB && !seenWBInner) {
list.add(wbInner);
if (seenNewWb && !seenNewWbInner) {
list.add(newWbInner);
}
if (seenOldWb && !seenOldWbInner) {
list.add(oldWbInner);
}
String[] array = new String[list.size()];

View File

@ -33,8 +33,8 @@
import java.math.BigInteger;
import sun.hotspot.parser.DiagnosticCommand;
import sun.hotspot.parser.DiagnosticCommand.DiagnosticArgumentType;
import jdk.test.whitebox.parser.DiagnosticCommand;
import jdk.test.whitebox.parser.DiagnosticCommand.DiagnosticArgumentType;
import sun.hotspot.WhiteBox;
public class ParserTest {

View File

@ -1,5 +1,5 @@
#
# Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2013, 2021, 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
@ -47,7 +47,7 @@ LIB_FILES = $(shell find $(TESTLIBRARY_DIR)/jdk/test/lib/ \
$(TESTLIBRARY_DIR)/jdk/test/lib/util \
$(TESTLIBRARY_DIR)/jtreg \
-maxdepth 1 -name '*.java')
WB_SRC_FILES = $(shell find $(TESTLIBRARY_DIR)/sun/hotspot -name '*.java')
WB_SRC_FILES = $(shell find $(TESTLIBRARY_DIR)/sun/hotspot $(TESTLIBRARY_DIR)/jdk/test/whitebox -name '*.java')
EXPORTS=--add-exports java.base/jdk.internal.jimage=ALL-UNNAMED \
--add-exports java.base/jdk.internal.misc=ALL-UNNAMED \
--add-exports java.base/jdk.internal.reflect=ALL-UNNAMED \

View File

@ -39,7 +39,7 @@ groups=TEST.groups
# to determine additional characteristics of the system for use with the @requires tag.
# Note: compiled bootlibs classes will be added to BCP.
requires.extraPropDefns = ../jtreg-ext/requires/VMProps.java
requires.extraPropDefns.bootlibs = ../lib/sun
requires.extraPropDefns.bootlibs = ../lib/jdk/test/whitebox
requires.extraPropDefns.libs = \
../lib/jdk/test/lib/Platform.java \
../lib/jdk/test/lib/Container.java

View File

@ -44,10 +44,10 @@ import java.util.function.Supplier;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import sun.hotspot.code.Compiler;
import sun.hotspot.cpuinfo.CPUInfo;
import sun.hotspot.gc.GC;
import sun.hotspot.WhiteBox;
import jdk.test.whitebox.code.Compiler;
import jdk.test.whitebox.cpuinfo.CPUInfo;
import jdk.test.whitebox.gc.GC;
import jdk.test.whitebox.WhiteBox;
import jdk.test.lib.Platform;
import jdk.test.lib.Container;

View File

@ -27,14 +27,14 @@
* @library /test/lib
* @modules java.base/jdk.internal.misc
* @modules java.management/sun.management
* @build sun.hotspot.WhiteBox
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
* @build jdk.test.whitebox.WhiteBox
* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI BlobSanityTest
* @summary sanity testing of allocateCodeBlob, freeCodeBlob and getCodeBlob
*/
import sun.hotspot.WhiteBox;
import jdk.test.whitebox.WhiteBox;
import java.util.function.Consumer;
import jdk.test.lib.Utils;

View File

@ -25,8 +25,8 @@
* @test
* @library /test/lib /
*
* @build sun.hotspot.WhiteBox
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
* @build jdk.test.whitebox.WhiteBox
* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
* -XX:+WhiteBoxAPI
* CPUInfoTest
@ -35,8 +35,8 @@
import java.util.Set;
import java.util.List;
import jdk.test.lib.Platform;
import sun.hotspot.WhiteBox;
import sun.hotspot.cpuinfo.CPUInfo;
import jdk.test.whitebox.WhiteBox;
import jdk.test.whitebox.cpuinfo.CPUInfo;
import static jdk.test.lib.Asserts.*;

View File

@ -29,11 +29,11 @@
* @modules java.base/jdk.internal.misc
* @library /test/lib
* @compile WhiteBox.java
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:-CheckIntrinsics sun.hotspot.WhiteBox
* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:-CheckIntrinsics jdk.test.whitebox.WhiteBox
*/
package sun.hotspot;
package jdk.test.whitebox;
public class WhiteBox {
@SuppressWarnings("serial")

View File

@ -0,0 +1,51 @@
/*
* Copyright (c) 2021, 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.
*/
/*
* @test id=without-inner-class
* @summary verify that sun.hotspot.WhiteBox class still can be used
* @library /test/lib
* @build sun.hotspot.WhiteBox
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI OldWhiteBox
*/
/*
* @test id=with-inner-class
* @summary verify that sun.hotspot.WhiteBox class still can be used
* @library /test/lib
* @build sun.hotspot.WhiteBox
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI OldWhiteBox
*/
import sun.hotspot.WhiteBox;
public class OldWhiteBox {
public static void main(String[] args) {
WhiteBox wb = WhiteBox.getWhiteBox();
if (wb.getHeapOopSize() < 0) {
throw new Error("wb.getHeapOopSize() < 0");
}
}
}

View File

@ -26,12 +26,12 @@
* @summary verify that whitebox functions can be linked and executed
* @modules java.base/jdk.internal.misc
* @library /test/lib
* @build sun.hotspot.WhiteBox
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
* @build jdk.test.whitebox.WhiteBox
* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI WBApi
*/
import sun.hotspot.WhiteBox;
import jdk.test.whitebox.WhiteBox;
public class WBApi {
public static void main(String... args) {
System.out.printf("args at: %x\n",WhiteBox.getWhiteBox().getObjectAddress(args));

View File

@ -29,14 +29,14 @@
* java.compiler
* java.management/sun.management
* jdk.internal.jvmstat/sun.jvmstat.monitor
* @build sun.hotspot.WhiteBox
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
* @build jdk.test.whitebox.WhiteBox
* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
* @run main/othervm/timeout=600 -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI BooleanTest
* @summary testing of WB::set/getBooleanVMFlag()
* @author igor.ignatyev@oracle.com
*/
import sun.hotspot.WhiteBox;
import jdk.test.whitebox.WhiteBox;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
import sun.management.*;

View File

@ -27,8 +27,8 @@
* @library /test/lib
* @modules java.base/jdk.internal.misc
* @modules java.management/sun.management
* @build sun.hotspot.WhiteBox
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
* @build jdk.test.whitebox.WhiteBox
* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
* @run main/othervm/timeout=600 -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI DoubleTest
* @summary testing of WB::set/getDoubleVMFlag()
* @author igor.ignatyev@oracle.com

View File

@ -27,8 +27,8 @@
* @library /test/lib
* @modules java.base/jdk.internal.misc
* @modules java.management/sun.management
* @build sun.hotspot.WhiteBox
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
* @build jdk.test.whitebox.WhiteBox
* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
* @run main/othervm/timeout=600 -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xint -XX:-ProfileInterpreter IntxTest
* @summary testing of WB::set/getIntxVMFlag()
* @author igor.ignatyev@oracle.com

View File

@ -27,8 +27,8 @@
* @library /test/lib
* @modules java.base/jdk.internal.misc
* java.management/sun.management
* @build sun.hotspot.WhiteBox
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
* @build jdk.test.whitebox.WhiteBox
* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
* @run main/othervm/timeout=600 -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:+UnlockExperimentalVMOptions SizeTTest
* @summary testing of WB::set/getSizeTVMFlag()
*/

View File

@ -27,8 +27,8 @@
* @library /test/lib
* @modules java.base/jdk.internal.misc
* @modules java.management/sun.management
* @build sun.hotspot.WhiteBox
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
* @build jdk.test.whitebox.WhiteBox
* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
* @run main/othervm/timeout=600 -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI StringTest
* @summary testing of WB::set/getStringVMFlag()
* @author igor.ignatyev@oracle.com

View File

@ -27,8 +27,8 @@
* @library /test/lib
* @modules java.base/jdk.internal.misc
* @modules java.management/sun.management
* @build sun.hotspot.WhiteBox
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
* @build jdk.test.whitebox.WhiteBox
* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
* @run main/othervm/timeout=600 -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI Uint64Test
* @summary testing of WB::set/getUint64VMFlag()
* @author igor.ignatyev@oracle.com

View File

@ -27,8 +27,8 @@
* @library /test/lib
* @modules java.base/jdk.internal.misc
* java.management/sun.management
* @build sun.hotspot.WhiteBox
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
* @build jdk.test.whitebox.WhiteBox
* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
* @run main/othervm/timeout=600 -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI UintxTest
* @summary testing of WB::set/getUintxVMFlag()
* @author igor.ignatyev@oracle.com

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2021, 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
@ -23,7 +23,7 @@
import java.util.function.BiConsumer;
import java.util.function.Function;
import sun.hotspot.WhiteBox;
import jdk.test.whitebox.WhiteBox;
import sun.management.*;
import com.sun.management.*;
import jdk.test.lib.Asserts;

View File

@ -102,12 +102,17 @@ public class ClassFileInstaller {
}
// Add commonly used inner classes that are often omitted by mistake. Currently
// we support only sun.hotspot.WhiteBox$WhiteBoxPermission. See JDK-8199290
// we support only jdk.test.whitebox.WhiteBox$WhiteBoxPermission and
// sun/hotspot/WhiteBox$WhiteBoxPermission. See JDK-8199290
private static String[] addInnerClasses(String[] classes, int startIdx) {
boolean seenWB = false;
boolean seenWBInner = false;
final String wb = "sun.hotspot.WhiteBox";
final String wbInner = "sun.hotspot.WhiteBox$WhiteBoxPermission";
boolean seenNewWb = false;
boolean seenNewWbInner = false;
boolean seenOldWb = false;
boolean seenOldWbInner = false;
final String newWb = "jdk.test.whitebox.WhiteBox";
final String newWbInner = newWb + "$WhiteBoxPermission";
final String oldWb = "sun.hotspot.WhiteBox";
final String oldWbInner = oldWb + "$WhiteBoxPermission";
ArrayList<String> list = new ArrayList<>();
@ -115,12 +120,17 @@ public class ClassFileInstaller {
String cls = classes[i];
list.add(cls);
switch (cls) {
case wb: seenWB = true; break;
case wbInner: seenWBInner = true; break;
case newWb: seenNewWb = true; break;
case newWbInner: seenNewWbInner = true; break;
case oldWb: seenOldWb = true; break;
case oldWbInner: seenOldWbInner = true; break;
}
}
if (seenWB && !seenWBInner) {
list.add(wbInner);
if (seenNewWb && !seenNewWbInner) {
list.add(newWbInner);
}
if (seenOldWb && !seenOldWbInner) {
list.add(oldWbInner);
}
String[] array = new String[list.size()];

View File

@ -0,0 +1,649 @@
/*
* Copyright (c) 2012, 2021, 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 jdk.test.whitebox;
import java.lang.management.MemoryUsage;
import java.lang.reflect.Executable;
import java.util.Arrays;
import java.util.List;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.security.BasicPermission;
import java.util.Objects;
import jdk.test.whitebox.parser.DiagnosticCommand;
public class WhiteBox {
@SuppressWarnings("serial")
public static class WhiteBoxPermission extends BasicPermission {
public WhiteBoxPermission(String s) {
super(s);
}
}
private WhiteBox() {}
private static final WhiteBox instance = new WhiteBox();
private static native void registerNatives();
/**
* Returns the singleton WhiteBox instance.
*
* The returned WhiteBox object should be carefully guarded
* by the caller, since it can be used to read and write data
* at arbitrary memory addresses. It must never be passed to
* untrusted code.
*/
public synchronized static WhiteBox getWhiteBox() {
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(new WhiteBoxPermission("getInstance"));
}
return instance;
}
static {
registerNatives();
}
// Get the maximum heap size supporting COOPs
public native long getCompressedOopsMaxHeapSize();
// Arguments
public native void printHeapSizes();
// Memory
private native long getObjectAddress0(Object o);
public long getObjectAddress(Object o) {
Objects.requireNonNull(o);
return getObjectAddress0(o);
}
public native int getHeapOopSize();
public native int getVMPageSize();
public native long getVMAllocationGranularity();
public native long getVMLargePageSize();
public native long getHeapSpaceAlignment();
public native long getHeapAlignment();
private native boolean isObjectInOldGen0(Object o);
public boolean isObjectInOldGen(Object o) {
Objects.requireNonNull(o);
return isObjectInOldGen0(o);
}
private native long getObjectSize0(Object o);
public long getObjectSize(Object o) {
Objects.requireNonNull(o);
return getObjectSize0(o);
}
// Runtime
// Make sure class name is in the correct format
public int countAliveClasses(String name) {
return countAliveClasses0(name.replace('.', '/'));
}
private native int countAliveClasses0(String name);
public boolean isClassAlive(String name) {
return countAliveClasses(name) != 0;
}
public native int getSymbolRefcount(String name);
public native boolean deflateIdleMonitors();
private native boolean isMonitorInflated0(Object obj);
public boolean isMonitorInflated(Object obj) {
Objects.requireNonNull(obj);
return isMonitorInflated0(obj);
}
public native void forceSafepoint();
private native long getConstantPool0(Class<?> aClass);
public long getConstantPool(Class<?> aClass) {
Objects.requireNonNull(aClass);
return getConstantPool0(aClass);
}
private native int getConstantPoolCacheIndexTag0();
public int getConstantPoolCacheIndexTag() {
return getConstantPoolCacheIndexTag0();
}
private native int getConstantPoolCacheLength0(Class<?> aClass);
public int getConstantPoolCacheLength(Class<?> aClass) {
Objects.requireNonNull(aClass);
return getConstantPoolCacheLength0(aClass);
}
private native int remapInstructionOperandFromCPCache0(Class<?> aClass, int index);
public int remapInstructionOperandFromCPCache(Class<?> aClass, int index) {
Objects.requireNonNull(aClass);
return remapInstructionOperandFromCPCache0(aClass, index);
}
private native int encodeConstantPoolIndyIndex0(int index);
public int encodeConstantPoolIndyIndex(int index) {
return encodeConstantPoolIndyIndex0(index);
}
// JVMTI
private native void addToBootstrapClassLoaderSearch0(String segment);
public void addToBootstrapClassLoaderSearch(String segment){
Objects.requireNonNull(segment);
addToBootstrapClassLoaderSearch0(segment);
}
private native void addToSystemClassLoaderSearch0(String segment);
public void addToSystemClassLoaderSearch(String segment) {
Objects.requireNonNull(segment);
addToSystemClassLoaderSearch0(segment);
}
// G1
public native boolean g1InConcurrentMark();
public native boolean g1HasRegionsToUncommit();
private native boolean g1IsHumongous0(Object o);
public boolean g1IsHumongous(Object o) {
Objects.requireNonNull(o);
return g1IsHumongous0(o);
}
private native boolean g1BelongsToHumongousRegion0(long adr);
public boolean g1BelongsToHumongousRegion(long adr) {
if (adr == 0) {
throw new IllegalArgumentException("adr argument should not be null");
}
return g1BelongsToHumongousRegion0(adr);
}
private native boolean g1BelongsToFreeRegion0(long adr);
public boolean g1BelongsToFreeRegion(long adr) {
if (adr == 0) {
throw new IllegalArgumentException("adr argument should not be null");
}
return g1BelongsToFreeRegion0(adr);
}
public native long g1NumMaxRegions();
public native long g1NumFreeRegions();
public native int g1RegionSize();
public native MemoryUsage g1AuxiliaryMemoryUsage();
private native Object[] parseCommandLine0(String commandline, char delim, DiagnosticCommand[] args);
public Object[] parseCommandLine(String commandline, char delim, DiagnosticCommand[] args) {
Objects.requireNonNull(args);
return parseCommandLine0(commandline, delim, args);
}
public native int g1ActiveMemoryNodeCount();
public native int[] g1MemoryNodeIds();
// Parallel GC
public native long psVirtualSpaceAlignment();
public native long psHeapGenerationAlignment();
/**
* Enumerates old regions with liveness less than specified and produces some statistics
* @param liveness percent of region's liveness (live_objects / total_region_size * 100).
* @return long[3] array where long[0] - total count of old regions
* long[1] - total memory of old regions
* long[2] - lowest estimation of total memory of old regions to be freed (non-full
* regions are not included)
*/
public native long[] g1GetMixedGCInfo(int liveness);
// NMT
public native long NMTMalloc(long size);
public native void NMTFree(long mem);
public native long NMTReserveMemory(long size);
public native long NMTAttemptReserveMemoryAt(long addr, long size);
public native void NMTCommitMemory(long addr, long size);
public native void NMTUncommitMemory(long addr, long size);
public native void NMTReleaseMemory(long addr, long size);
public native long NMTMallocWithPseudoStack(long size, int index);
public native long NMTMallocWithPseudoStackAndType(long size, int index, int type);
public native boolean NMTChangeTrackingLevel();
public native int NMTGetHashSize();
public native long NMTNewArena(long initSize);
public native void NMTFreeArena(long arena);
public native void NMTArenaMalloc(long arena, long size);
// Compiler
public native boolean isC2OrJVMCIIncluded();
public native boolean isJVMCISupportedByGC();
public native int matchesMethod(Executable method, String pattern);
public native int matchesInline(Executable method, String pattern);
public native boolean shouldPrintAssembly(Executable method, int comp_level);
public native int deoptimizeFrames(boolean makeNotEntrant);
public native boolean isFrameDeoptimized(int depth);
public native void deoptimizeAll();
public boolean isMethodCompiled(Executable method) {
return isMethodCompiled(method, false /*not osr*/);
}
private native boolean isMethodCompiled0(Executable method, boolean isOsr);
public boolean isMethodCompiled(Executable method, boolean isOsr){
Objects.requireNonNull(method);
return isMethodCompiled0(method, isOsr);
}
public boolean isMethodCompilable(Executable method) {
return isMethodCompilable(method, -1 /*any*/);
}
public boolean isMethodCompilable(Executable method, int compLevel) {
return isMethodCompilable(method, compLevel, false /*not osr*/);
}
private native boolean isMethodCompilable0(Executable method, int compLevel, boolean isOsr);
public boolean isMethodCompilable(Executable method, int compLevel, boolean isOsr) {
Objects.requireNonNull(method);
return isMethodCompilable0(method, compLevel, isOsr);
}
private native boolean isMethodQueuedForCompilation0(Executable method);
public boolean isMethodQueuedForCompilation(Executable method) {
Objects.requireNonNull(method);
return isMethodQueuedForCompilation0(method);
}
// Determine if the compiler corresponding to the compilation level 'compLevel'
// and to the compilation context 'compilation_context' provides an intrinsic
// for the method 'method'. An intrinsic is available for method 'method' if:
// - the intrinsic is enabled (by using the appropriate command-line flag) and
// - the platform on which the VM is running provides the instructions necessary
// for the compiler to generate the intrinsic code.
//
// The compilation context is related to using the DisableIntrinsic flag on a
// per-method level, see hotspot/src/share/vm/compiler/abstractCompiler.hpp
// for more details.
public boolean isIntrinsicAvailable(Executable method,
Executable compilationContext,
int compLevel) {
Objects.requireNonNull(method);
return isIntrinsicAvailable0(method, compilationContext, compLevel);
}
// If usage of the DisableIntrinsic flag is not expected (or the usage can be ignored),
// use the below method that does not require the compilation context as argument.
public boolean isIntrinsicAvailable(Executable method, int compLevel) {
return isIntrinsicAvailable(method, null, compLevel);
}
private native boolean isIntrinsicAvailable0(Executable method,
Executable compilationContext,
int compLevel);
public int deoptimizeMethod(Executable method) {
return deoptimizeMethod(method, false /*not osr*/);
}
private native int deoptimizeMethod0(Executable method, boolean isOsr);
public int deoptimizeMethod(Executable method, boolean isOsr) {
Objects.requireNonNull(method);
return deoptimizeMethod0(method, isOsr);
}
public void makeMethodNotCompilable(Executable method) {
makeMethodNotCompilable(method, -1 /*any*/);
}
public void makeMethodNotCompilable(Executable method, int compLevel) {
makeMethodNotCompilable(method, compLevel, false /*not osr*/);
}
private native void makeMethodNotCompilable0(Executable method, int compLevel, boolean isOsr);
public void makeMethodNotCompilable(Executable method, int compLevel, boolean isOsr) {
Objects.requireNonNull(method);
makeMethodNotCompilable0(method, compLevel, isOsr);
}
public int getMethodCompilationLevel(Executable method) {
return getMethodCompilationLevel(method, false /*not ost*/);
}
private native int getMethodCompilationLevel0(Executable method, boolean isOsr);
public int getMethodCompilationLevel(Executable method, boolean isOsr) {
Objects.requireNonNull(method);
return getMethodCompilationLevel0(method, isOsr);
}
private native boolean testSetDontInlineMethod0(Executable method, boolean value);
public boolean testSetDontInlineMethod(Executable method, boolean value) {
Objects.requireNonNull(method);
return testSetDontInlineMethod0(method, value);
}
public int getCompileQueuesSize() {
return getCompileQueueSize(-1 /*any*/);
}
public native int getCompileQueueSize(int compLevel);
private native boolean testSetForceInlineMethod0(Executable method, boolean value);
public boolean testSetForceInlineMethod(Executable method, boolean value) {
Objects.requireNonNull(method);
return testSetForceInlineMethod0(method, value);
}
public boolean enqueueMethodForCompilation(Executable method, int compLevel) {
return enqueueMethodForCompilation(method, compLevel, -1 /*InvocationEntryBci*/);
}
private native boolean enqueueMethodForCompilation0(Executable method, int compLevel, int entry_bci);
public boolean enqueueMethodForCompilation(Executable method, int compLevel, int entry_bci) {
Objects.requireNonNull(method);
return enqueueMethodForCompilation0(method, compLevel, entry_bci);
}
private native boolean enqueueInitializerForCompilation0(Class<?> aClass, int compLevel);
public boolean enqueueInitializerForCompilation(Class<?> aClass, int compLevel) {
Objects.requireNonNull(aClass);
return enqueueInitializerForCompilation0(aClass, compLevel);
}
private native void clearMethodState0(Executable method);
public native void markMethodProfiled(Executable method);
public void clearMethodState(Executable method) {
Objects.requireNonNull(method);
clearMethodState0(method);
}
public native void lockCompilation();
public native void unlockCompilation();
private native int getMethodEntryBci0(Executable method);
public int getMethodEntryBci(Executable method) {
Objects.requireNonNull(method);
return getMethodEntryBci0(method);
}
private native Object[] getNMethod0(Executable method, boolean isOsr);
public Object[] getNMethod(Executable method, boolean isOsr) {
Objects.requireNonNull(method);
return getNMethod0(method, isOsr);
}
public native long allocateCodeBlob(int size, int type);
public long allocateCodeBlob(long size, int type) {
int intSize = (int) size;
if ((long) intSize != size || size < 0) {
throw new IllegalArgumentException(
"size argument has illegal value " + size);
}
return allocateCodeBlob( intSize, type);
}
public native void freeCodeBlob(long addr);
public native void forceNMethodSweep();
public native Object[] getCodeHeapEntries(int type);
public native int getCompilationActivityMode();
private native long getMethodData0(Executable method);
public long getMethodData(Executable method) {
Objects.requireNonNull(method);
return getMethodData0(method);
}
public native Object[] getCodeBlob(long addr);
private native void clearInlineCaches0(boolean preserve_static_stubs);
public void clearInlineCaches() {
clearInlineCaches0(false);
}
public void clearInlineCaches(boolean preserve_static_stubs) {
clearInlineCaches0(preserve_static_stubs);
}
// Intered strings
public native boolean isInStringTable(String str);
// Memory
public native void readReservedMemory();
public native long allocateMetaspace(ClassLoader classLoader, long size);
public native long incMetaspaceCapacityUntilGC(long increment);
public native long metaspaceCapacityUntilGC();
public native long metaspaceSharedRegionAlignment();
// Metaspace Arena Tests
public native long createMetaspaceTestContext(long commit_limit, long reserve_limit);
public native void destroyMetaspaceTestContext(long context);
public native void purgeMetaspaceTestContext(long context);
public native void printMetaspaceTestContext(long context);
public native long getTotalCommittedWordsInMetaspaceTestContext(long context);
public native long getTotalUsedWordsInMetaspaceTestContext(long context);
public native long createArenaInTestContext(long context, boolean is_micro);
public native void destroyMetaspaceTestArena(long arena);
public native long allocateFromMetaspaceTestArena(long arena, long word_size);
public native void deallocateToMetaspaceTestArena(long arena, long p, long word_size);
public native long maxMetaspaceAllocationSize();
// Don't use these methods directly
// Use jdk.test.whitebox.gc.GC class instead.
public native boolean isGCSupported(int name);
public native boolean isGCSupportedByJVMCICompiler(int name);
public native boolean isGCSelected(int name);
public native boolean isGCSelectedErgonomically();
// Force Young GC
public native void youngGC();
// Force Full GC
public native void fullGC();
// Returns true if the current GC supports concurrent collection control.
public native boolean supportsConcurrentGCBreakpoints();
private void checkConcurrentGCBreakpointsSupported() {
if (!supportsConcurrentGCBreakpoints()) {
throw new UnsupportedOperationException("Concurrent GC breakpoints not supported");
}
}
private native void concurrentGCAcquireControl0();
private native void concurrentGCReleaseControl0();
private native void concurrentGCRunToIdle0();
private native boolean concurrentGCRunTo0(String breakpoint);
private static boolean concurrentGCIsControlled = false;
private void checkConcurrentGCIsControlled() {
if (!concurrentGCIsControlled) {
throw new IllegalStateException("Not controlling concurrent GC");
}
}
// All collectors supporting concurrent GC breakpoints are expected
// to provide at least the following breakpoints.
public final String AFTER_MARKING_STARTED = "AFTER MARKING STARTED";
public final String BEFORE_MARKING_COMPLETED = "BEFORE MARKING COMPLETED";
// Collectors supporting concurrent GC breakpoints that do reference
// processing concurrently should provide the following breakpoint.
public final String AFTER_CONCURRENT_REFERENCE_PROCESSING_STARTED =
"AFTER CONCURRENT REFERENCE PROCESSING STARTED";
public void concurrentGCAcquireControl() {
checkConcurrentGCBreakpointsSupported();
if (concurrentGCIsControlled) {
throw new IllegalStateException("Already controlling concurrent GC");
}
concurrentGCAcquireControl0();
concurrentGCIsControlled = true;
}
public void concurrentGCReleaseControl() {
checkConcurrentGCBreakpointsSupported();
concurrentGCReleaseControl0();
concurrentGCIsControlled = false;
}
// Keep concurrent GC idle. Release from breakpoint.
public void concurrentGCRunToIdle() {
checkConcurrentGCBreakpointsSupported();
checkConcurrentGCIsControlled();
concurrentGCRunToIdle0();
}
// Allow concurrent GC to run to breakpoint.
// Throws IllegalStateException if reached end of cycle first.
public void concurrentGCRunTo(String breakpoint) {
concurrentGCRunTo(breakpoint, true);
}
// Allow concurrent GC to run to breakpoint.
// Returns true if reached breakpoint. If reached end of cycle first,
// then throws IllegalStateException if errorIfFail is true, returning
// false otherwise.
public boolean concurrentGCRunTo(String breakpoint, boolean errorIfFail) {
checkConcurrentGCBreakpointsSupported();
checkConcurrentGCIsControlled();
if (breakpoint == null) {
throw new NullPointerException("null breakpoint");
} else if (concurrentGCRunTo0(breakpoint)) {
return true;
} else if (errorIfFail) {
throw new IllegalStateException("Missed requested breakpoint \"" + breakpoint + "\"");
} else {
return false;
}
}
// Method tries to start concurrent mark cycle.
// It returns false if CM Thread is always in concurrent cycle.
public native boolean g1StartConcMarkCycle();
// Tests on ReservedSpace/VirtualSpace classes
public native int stressVirtualSpaceResize(long reservedSpaceSize, long magnitude, long iterations);
public native void readFromNoaccessArea();
public native long getThreadStackSize();
public native long getThreadRemainingStackSize();
// CPU features
public native String getCPUFeatures();
// VM flags
public native boolean isConstantVMFlag(String name);
public native boolean isLockedVMFlag(String name);
public native void setBooleanVMFlag(String name, boolean value);
public native void setIntVMFlag(String name, long value);
public native void setUintVMFlag(String name, long value);
public native void setIntxVMFlag(String name, long value);
public native void setUintxVMFlag(String name, long value);
public native void setUint64VMFlag(String name, long value);
public native void setSizeTVMFlag(String name, long value);
public native void setStringVMFlag(String name, String value);
public native void setDoubleVMFlag(String name, double value);
public native Boolean getBooleanVMFlag(String name);
public native Long getIntVMFlag(String name);
public native Long getUintVMFlag(String name);
public native Long getIntxVMFlag(String name);
public native Long getUintxVMFlag(String name);
public native Long getUint64VMFlag(String name);
public native Long getSizeTVMFlag(String name);
public native String getStringVMFlag(String name);
public native Double getDoubleVMFlag(String name);
private final List<Function<String,Object>> flagsGetters = Arrays.asList(
this::getBooleanVMFlag, this::getIntVMFlag, this::getUintVMFlag,
this::getIntxVMFlag, this::getUintxVMFlag, this::getUint64VMFlag,
this::getSizeTVMFlag, this::getStringVMFlag, this::getDoubleVMFlag);
public Object getVMFlag(String name) {
return flagsGetters.stream()
.map(f -> f.apply(name))
.filter(x -> x != null)
.findAny()
.orElse(null);
}
// Jigsaw
public native void DefineModule(Object module, boolean is_open, String version,
String location, Object[] packages);
public native void AddModuleExports(Object from_module, String pkg, Object to_module);
public native void AddReadsModule(Object from_module, Object source_module);
public native void AddModuleExportsToAllUnnamed(Object module, String pkg);
public native void AddModuleExportsToAll(Object module, String pkg);
public native int getOffsetForName0(String name);
public int getOffsetForName(String name) throws Exception {
int offset = getOffsetForName0(name);
if (offset == -1) {
throw new RuntimeException(name + " not found");
}
return offset;
}
public native Boolean getMethodBooleanOption(Executable method, String name);
public native Long getMethodIntxOption(Executable method, String name);
public native Long getMethodUintxOption(Executable method, String name);
public native Double getMethodDoubleOption(Executable method, String name);
public native String getMethodStringOption(Executable method, String name);
private final List<BiFunction<Executable,String,Object>> methodOptionGetters
= Arrays.asList(this::getMethodBooleanOption, this::getMethodIntxOption,
this::getMethodUintxOption, this::getMethodDoubleOption,
this::getMethodStringOption);
public Object getMethodOption(Executable method, String name) {
return methodOptionGetters.stream()
.map(f -> f.apply(method, name))
.filter(x -> x != null)
.findAny()
.orElse(null);
}
// Sharing & archiving
public native String getDefaultArchivePath();
public native boolean cdsMemoryMappingFailed();
public native boolean isSharingEnabled();
public native boolean isShared(Object o);
public native boolean isSharedClass(Class<?> c);
public native boolean areSharedStringsIgnored();
public native boolean isCDSIncluded();
public native boolean isJFRIncluded();
public native boolean isJavaHeapArchiveSupported();
public native Object getResolvedReferences(Class<?> c);
public native void linkClass(Class<?> c);
public native boolean areOpenArchiveHeapObjectsMapped();
// Compiler Directive
public native int addCompilerDirective(String compDirect);
public native void removeCompilerDirective(int count);
// Handshakes
public native int handshakeWalkStack(Thread t, boolean all_threads);
public native void asyncHandshakeWalkStack(Thread t);
public native void lockAndBlock(boolean suspender);
// Returns true on linux if library has the noexecstack flag set.
public native boolean checkLibSpecifiesNoexecstack(String libfilename);
// Container testing
public native boolean isContainerized();
public native int validateCgroup(String procCgroups,
String procSelfCgroup,
String procSelfMountinfo);
public native void printOsInfo();
// Decoder
public native void disableElfSectionCache();
// Resolved Method Table
public native long resolvedMethodItemsCount();
// Protection Domain Table
public native int protectionDomainRemovedCount();
public native int getKlassMetadataSize(Class<?> c);
// ThreadSMR GC safety check for threadObj
public native void checkThreadObjOfTerminatingThread(Thread target);
// libc name
public native String getLibcName();
// Walk stack frames of current thread
public native void verifyFrames(boolean log, boolean updateRegisterMap);
public native boolean isJVMTIIncluded();
public native void waitUnsafe(int time_ms);
public native void lockCritical();
public native void unlockCritical();
}

View File

@ -0,0 +1,108 @@
/*
* Copyright (c) 2014, 2021, 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 jdk.test.whitebox.code;
import java.lang.management.ManagementFactory;
import java.lang.management.MemoryPoolMXBean;
import java.util.EnumSet;
import jdk.test.whitebox.WhiteBox;
public enum BlobType {
// Execution level 1 and 4 (non-profiled) nmethods (including native nmethods)
MethodNonProfiled(0, "CodeHeap 'non-profiled nmethods'", "NonProfiledCodeHeapSize") {
@Override
public boolean allowTypeWhenOverflow(BlobType type) {
return super.allowTypeWhenOverflow(type)
|| type == BlobType.MethodProfiled;
}
},
// Execution level 2 and 3 (profiled) nmethods
MethodProfiled(1, "CodeHeap 'profiled nmethods'", "ProfiledCodeHeapSize") {
@Override
public boolean allowTypeWhenOverflow(BlobType type) {
return super.allowTypeWhenOverflow(type)
|| type == BlobType.MethodNonProfiled;
}
},
// Non-nmethods like Buffers, Adapters and Runtime Stubs
NonNMethod(2, "CodeHeap 'non-nmethods'", "NonNMethodCodeHeapSize") {
@Override
public boolean allowTypeWhenOverflow(BlobType type) {
return super.allowTypeWhenOverflow(type)
|| type == BlobType.MethodNonProfiled
|| type == BlobType.MethodProfiled;
}
},
// All types (No code cache segmentation)
All(3, "CodeCache", "ReservedCodeCacheSize");
public final int id;
public final String sizeOptionName;
public final String beanName;
private BlobType(int id, String beanName, String sizeOptionName) {
this.id = id;
this.beanName = beanName;
this.sizeOptionName = sizeOptionName;
}
public MemoryPoolMXBean getMemoryPool() {
for (MemoryPoolMXBean bean : ManagementFactory.getMemoryPoolMXBeans()) {
String name = bean.getName();
if (beanName.equals(name)) {
return bean;
}
}
return null;
}
public boolean allowTypeWhenOverflow(BlobType type) {
return type == this;
}
public static EnumSet<BlobType> getAvailable() {
WhiteBox whiteBox = WhiteBox.getWhiteBox();
if (!whiteBox.getBooleanVMFlag("SegmentedCodeCache")) {
// only All for non segmented world
return EnumSet.of(All);
}
if (System.getProperty("java.vm.info").startsWith("interpreted ")) {
// only NonNMethod for -Xint
return EnumSet.of(NonNMethod);
}
EnumSet<BlobType> result = EnumSet.complementOf(EnumSet.of(All));
if (!whiteBox.getBooleanVMFlag("TieredCompilation")
|| whiteBox.getIntxVMFlag("TieredStopAtLevel") <= 1) {
// there is no MethodProfiled in non tiered world or pure C1
result.remove(MethodProfiled);
}
return result;
}
public long getSize() {
return WhiteBox.getWhiteBox().getUintxVMFlag(sizeOptionName);
}
}

View File

@ -0,0 +1,70 @@
/*
* Copyright (c) 2014, 2021, 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 jdk.test.whitebox.code;
import jdk.test.whitebox.WhiteBox;
public class CodeBlob {
private static final WhiteBox WB = WhiteBox.getWhiteBox();
public static CodeBlob[] getCodeBlobs(BlobType type) {
Object[] obj = WB.getCodeHeapEntries(type.id);
if (obj == null) {
return null;
}
CodeBlob[] result = new CodeBlob[obj.length];
for (int i = 0, n = result.length; i < n; ++i) {
result[i] = new CodeBlob((Object[]) obj[i]);
}
return result;
}
public static CodeBlob getCodeBlob(long addr) {
Object[] obj = WB.getCodeBlob(addr);
if (obj == null) {
return null;
}
return new CodeBlob(obj);
}
protected CodeBlob(Object[] obj) {
assert obj.length == 4;
name = (String) obj[0];
size = (Integer) obj[1];
int blob_type_index = (Integer) obj[2];
code_blob_type = BlobType.values()[blob_type_index];
assert code_blob_type.id == (Integer) obj[2];
address = (Long) obj[3];
}
public final String name;
public final int size;
public final BlobType code_blob_type;
public final long address;
@Override
public String toString() {
return "CodeBlob{"
+ "name=" + name
+ ", size=" + size
+ ", code_blob_type=" + code_blob_type
+ ", address=" + address
+ '}';
}
}

View File

@ -0,0 +1,171 @@
/*
* Copyright (c) 2018, 2021, 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 jdk.test.whitebox.code;
import java.lang.reflect.Executable;
import jdk.test.whitebox.WhiteBox;
/**
* API to obtain information about enabled JIT compilers
* retrieved from the VM with the WhiteBox API.
*/
public class Compiler {
private static final WhiteBox WB = WhiteBox.getWhiteBox();
/**
* Check if C2 or JVMCI were included in the VM build
*
* @return true if either C2 or JVMCI were included in the VM build.
*/
public static boolean isC2OrJVMCIIncluded() {
return WB.isC2OrJVMCIIncluded();
}
/**
* Check if JVMCI is enabled.
*
* @return true if JVMCI is enabled
*/
public static boolean isJVMCIEnabled() {
Boolean enableJvmci = WB.getBooleanVMFlag("EnableJVMCI");
if (enableJvmci == null || !enableJvmci) {
return false;
}
return true;
}
/**
* Check if Graal is used as JIT compiler.
*
* Graal is enabled if following conditions are true:
* - we are not in Interpreter mode
* - UseJVMCICompiler flag is true
* - jvmci.Compiler variable is equal to 'graal'
* - TieredCompilation is not used or TieredStopAtLevel is greater than 3
* No need to check client mode because it set UseJVMCICompiler to false.
*
* @return true if Graal is used as JIT compiler.
*/
public static boolean isGraalEnabled() {
Boolean useCompiler = WB.getBooleanVMFlag("UseCompiler");
if (useCompiler == null || !useCompiler) {
return false;
}
Boolean useJvmciComp = WB.getBooleanVMFlag("UseJVMCICompiler");
if (useJvmciComp == null || !useJvmciComp) {
return false;
}
Boolean tieredCompilation = WB.getBooleanVMFlag("TieredCompilation");
Long compLevel = WB.getIntxVMFlag("TieredStopAtLevel");
// if TieredCompilation is enabled and compilation level is <= 3 then no Graal is used
if (tieredCompilation != null && tieredCompilation &&
compLevel != null && compLevel <= 3) {
return false;
}
return true;
}
/**
* Check if C2 is used as JIT compiler.
*
* C2 is enabled if following conditions are true:
* - we are not in Interpreter mode
* - we are in Server compilation mode
* - TieredCompilation is not used or TieredStopAtLevel is greater than 3
* - Graal is not used
*
* @return true if C2 is used as JIT compiler.
*/
public static boolean isC2Enabled() {
Boolean useCompiler = WB.getBooleanVMFlag("UseCompiler");
if (useCompiler == null || !useCompiler) {
return false;
}
Boolean serverMode = WB.getBooleanVMFlag("ProfileInterpreter");
if (serverMode == null || !serverMode) {
return false;
}
Boolean tieredCompilation = WB.getBooleanVMFlag("TieredCompilation");
Long compLevel = WB.getIntxVMFlag("TieredStopAtLevel");
// if TieredCompilation is enabled and compilation level is <= 3 then no Graal is used
if (tieredCompilation != null && tieredCompilation &&
compLevel != null && compLevel <= 3) {
return false;
}
if (isGraalEnabled()) {
return false;
}
return true;
}
/*
* Check if C1 is used as JIT compiler.
*
* C1 is enabled if following conditions are true:
* - we are not in Interpreter mode
* - we are not in Server compilation mode
* - TieredCompilation is used in Server mode
*
* @return true if C1 is used as JIT compiler.
*/
public static boolean isC1Enabled() {
Boolean useCompiler = WB.getBooleanVMFlag("UseCompiler");
if (useCompiler == null || !useCompiler) {
return false;
}
Boolean serverMode = WB.getBooleanVMFlag("ProfileInterpreter");
if (serverMode == null || !serverMode) {
return true; // Client mode
}
Boolean tieredCompilation = WB.getBooleanVMFlag("TieredCompilation");
// C1 is not used in server mode if TieredCompilation is off.
if (tieredCompilation != null && !tieredCompilation) {
return false;
}
return true;
}
/*
* Determine if the compiler corresponding to the compilation level 'compLevel'
* provides an intrinsic for 'class'.'method'.
*/
public static boolean isIntrinsicAvailable(int compLevel, String klass, String method, Class<?>... parameterTypes) {
Executable intrinsicMethod;
try {
intrinsicMethod = Class.forName(klass).getDeclaredMethod(method, parameterTypes);
} catch (NoSuchMethodException e) {
throw new RuntimeException("Test bug, '" + method + "' method unavailable. " + e);
} catch (ClassNotFoundException e) {
throw new RuntimeException("Test bug, '" + klass + "' class unavailable. " + e);
}
return WB.isIntrinsicAvailable(intrinsicMethod, compLevel);
}
}

View File

@ -0,0 +1,58 @@
/*
* Copyright (c) 2014, 2021, 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 jdk.test.whitebox.code;
import java.lang.reflect.Executable;
import jdk.test.whitebox.WhiteBox;
public class NMethod extends CodeBlob {
private static final WhiteBox wb = WhiteBox.getWhiteBox();
public static NMethod get(Executable method, boolean isOsr) {
Object[] obj = wb.getNMethod(method, isOsr);
return obj == null ? null : new NMethod(obj);
}
private NMethod(Object[] obj) {
super((Object[])obj[0]);
assert obj.length == 5;
comp_level = (Integer) obj[1];
insts = (byte[]) obj[2];
compile_id = (Integer) obj[3];
entry_point = (Long) obj[4];
}
public final byte[] insts;
public final int comp_level;
public final int compile_id;
public final long entry_point;
@Override
public String toString() {
return "NMethod{"
+ super.toString()
+ ", insts=" + insts
+ ", comp_level=" + comp_level
+ ", compile_id=" + compile_id
+ ", entry_point=" + entry_point
+ '}';
}
}

View File

@ -0,0 +1,96 @@
/*
* Copyright (c) 2014, 2021, 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 jdk.test.whitebox.cpuinfo;
import java.util.List;
import java.util.Arrays;
import java.util.Collections;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import jdk.test.whitebox.WhiteBox;
/**
* Information about CPU on test box.
*
* CPUInfo uses WhiteBox to gather information,
* so WhiteBox class should be added to bootclasspath
* and option -XX:+WhiteBoxAPI should be explicitly
* specified on command line.
*/
public class CPUInfo {
private static final List<String> features;
private static final String additionalCPUInfo;
static {
WhiteBox wb = WhiteBox.getWhiteBox();
Pattern additionalCPUInfoRE =
Pattern.compile("([^(]*\\([^)]*\\)[^,]*),\\s*");
String cpuFeaturesString = wb.getCPUFeatures();
Matcher matcher = additionalCPUInfoRE.matcher(cpuFeaturesString);
if (matcher.find()) {
additionalCPUInfo = matcher.group(1);
} else {
additionalCPUInfo = "";
}
String splittedFeatures[] = matcher.replaceAll("").split("(, )| ");
features = Collections.unmodifiableList(Arrays.
asList(splittedFeatures));
}
/**
* Get additional information about CPU.
* For example, on X86 in will be family/model/stepping
* and number of cores.
*
* @return additional CPU info
*/
public static String getAdditionalCPUInfo() {
return additionalCPUInfo;
}
/**
* Get all known features supported by CPU.
*
* @return unmodifiable list with names of all known features
* supported by CPU.
*/
public static List<String> getFeatures() {
return features;
}
/**
* Check if some feature is supported by CPU.
*
* @param feature Name of feature to be tested.
* @return <b>true</b> if tested feature is supported by CPU.
*/
public static boolean hasFeature(String feature) {
return features.contains(feature.toLowerCase());
}
}

View File

@ -0,0 +1,91 @@
/*
* Copyright (c) 2016, 2021, 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 jdk.test.whitebox.gc;
import jdk.test.whitebox.WhiteBox;
/**
* API to obtain information about selected and supported Garbage Collectors
* retrieved from the VM with the WhiteBox API.
*/
public enum GC {
/*
* Enum values must match CollectedHeap::Name
*/
Serial(1),
Parallel(2),
G1(3),
Epsilon(4),
Z(5),
Shenandoah(6);
private static final WhiteBox WB = WhiteBox.getWhiteBox();
private final int name;
private GC(int name) {
this.name = name;
}
/**
* @return true if this GC is supported by the VM, i.e., it is built into the VM.
*/
public boolean isSupported() {
return WB.isGCSupported(name);
}
/**
* @return true if this GC is supported by the JVMCI compiler
*/
public boolean isSupportedByJVMCICompiler() {
return WB.isGCSupportedByJVMCICompiler(name);
}
/**
* @return true if this GC is currently selected/used
*/
public boolean isSelected() {
return WB.isGCSelected(name);
}
/**
* @return true if GC was selected ergonomically, as opposed
* to being explicitly specified on the command line
*/
public static boolean isSelectedErgonomically() {
return WB.isGCSelectedErgonomically();
}
/**
* @return the selected GC.
*/
public static GC selected() {
for (GC gc : values()) {
if (gc.isSelected()) {
return gc;
}
}
throw new IllegalStateException("No selected GC found");
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2021, 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
@ -21,7 +21,7 @@
* questions.
*/
package sun.hotspot.parser;
package jdk.test.whitebox.parser;
public class DiagnosticCommand {

View File

@ -32,8 +32,9 @@ import java.util.function.Function;
import java.security.BasicPermission;
import java.util.Objects;
import sun.hotspot.parser.DiagnosticCommand;
import jdk.test.whitebox.parser.DiagnosticCommand;
@Deprecated
public class WhiteBox {
@SuppressWarnings("serial")
public static class WhiteBoxPermission extends BasicPermission {
@ -58,7 +59,7 @@ public class WhiteBox {
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(new WhiteBoxPermission("getInstance"));
throw new SecurityException("can't use old whitebox with SecurityManager, please switch to jdk.test.whitebox.WhiteBox");
}
return instance;
}

View File

@ -25,6 +25,7 @@ package sun.hotspot.code;
import sun.hotspot.WhiteBox;
@Deprecated
public class CodeBlob {
private static final WhiteBox WB = WhiteBox.getWhiteBox();
public static CodeBlob[] getCodeBlobs(BlobType type) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2021, 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
@ -26,6 +26,7 @@ package sun.hotspot.code;
import java.lang.reflect.Executable;
import sun.hotspot.WhiteBox;
@Deprecated
public class NMethod extends CodeBlob {
private static final WhiteBox wb = WhiteBox.getWhiteBox();
public static NMethod get(Executable method, boolean isOsr) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2021, 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
@ -39,6 +39,7 @@ import sun.hotspot.WhiteBox;
* and option -XX:+WhiteBoxAPI should be explicitly
* specified on command line.
*/
@Deprecated
public class CPUInfo {
private static final List<String> features;