diff --git a/src/hotspot/share/prims/nativeLookup.cpp b/src/hotspot/share/prims/nativeLookup.cpp index 3ae101ec602..16a1041e8d7 100644 --- a/src/hotspot/share/prims/nativeLookup.cpp +++ b/src/hotspot/share/prims/nativeLookup.cpp @@ -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) }, diff --git a/src/hotspot/share/prims/wbtestmethods/parserTests.cpp b/src/hotspot/share/prims/wbtestmethods/parserTests.cpp index 32ef1653f04..c6ef6cf8296 100644 --- a/src/hotspot/share/prims/wbtestmethods/parserTests.cpp +++ b/src/hotspot/share/prims/wbtestmethods/parserTests.cpp @@ -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); diff --git a/src/hotspot/share/prims/whitebox.cpp b/src/hotspot/share/prims/whitebox.cpp index 6ef0251211c..f8beaa1c7d3 100644 --- a/src/hotspot/share/prims/whitebox.cpp +++ b/src/hotspot/share/prims/whitebox.cpp @@ -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", diff --git a/test/hotspot/jtreg/TEST.ROOT b/test/hotspot/jtreg/TEST.ROOT index a6f242b8c98..cb10a02899f 100644 --- a/test/hotspot/jtreg/TEST.ROOT +++ b/test/hotspot/jtreg/TEST.ROOT @@ -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 diff --git a/test/hotspot/jtreg/compiler/jvmci/compilerToVM/AllocateCompileIdTest.java b/test/hotspot/jtreg/compiler/jvmci/compilerToVM/AllocateCompileIdTest.java index e8bb9ca5c17..4c4804e3702 100644 --- a/test/hotspot/jtreg/compiler/jvmci/compilerToVM/AllocateCompileIdTest.java +++ b/test/hotspot/jtreg/compiler/jvmci/compilerToVM/AllocateCompileIdTest.java @@ -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 diff --git a/test/hotspot/jtreg/runtime/cds/appcds/JarBuilder.java b/test/hotspot/jtreg/runtime/cds/appcds/JarBuilder.java index 84f2242bffb..cd56e43413d 100644 --- a/test/hotspot/jtreg/runtime/cds/appcds/JarBuilder.java +++ b/test/hotspot/jtreg/runtime/cds/appcds/JarBuilder.java @@ -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 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()]; diff --git a/test/hotspot/jtreg/serviceability/ParserTest.java b/test/hotspot/jtreg/serviceability/ParserTest.java index ff9105579cd..c05b7487894 100644 --- a/test/hotspot/jtreg/serviceability/ParserTest.java +++ b/test/hotspot/jtreg/serviceability/ParserTest.java @@ -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 { diff --git a/test/hotspot/jtreg/testlibrary/ctw/Makefile b/test/hotspot/jtreg/testlibrary/ctw/Makefile index 99d1c6f801e..c2e352375a4 100644 --- a/test/hotspot/jtreg/testlibrary/ctw/Makefile +++ b/test/hotspot/jtreg/testlibrary/ctw/Makefile @@ -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 \ diff --git a/test/jdk/TEST.ROOT b/test/jdk/TEST.ROOT index 7d941b86317..6b78ca255f5 100644 --- a/test/jdk/TEST.ROOT +++ b/test/jdk/TEST.ROOT @@ -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 diff --git a/test/jtreg-ext/requires/VMProps.java b/test/jtreg-ext/requires/VMProps.java index 8f30dae8416..154adc5378e 100644 --- a/test/jtreg-ext/requires/VMProps.java +++ b/test/jtreg-ext/requires/VMProps.java @@ -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; diff --git a/test/lib-test/sun/hotspot/whitebox/BlobSanityTest.java b/test/lib-test/jdk/test/whitebox/BlobSanityTest.java similarity index 93% rename from test/lib-test/sun/hotspot/whitebox/BlobSanityTest.java rename to test/lib-test/jdk/test/whitebox/BlobSanityTest.java index bda27699991..4cc470b6179 100644 --- a/test/lib-test/sun/hotspot/whitebox/BlobSanityTest.java +++ b/test/lib-test/jdk/test/whitebox/BlobSanityTest.java @@ -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; diff --git a/test/lib-test/sun/hotspot/whitebox/CPUInfoTest.java b/test/lib-test/jdk/test/whitebox/CPUInfoTest.java similarity index 95% rename from test/lib-test/sun/hotspot/whitebox/CPUInfoTest.java rename to test/lib-test/jdk/test/whitebox/CPUInfoTest.java index 4a20b49a0b9..af1c0d18083 100644 --- a/test/lib-test/sun/hotspot/whitebox/CPUInfoTest.java +++ b/test/lib-test/jdk/test/whitebox/CPUInfoTest.java @@ -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.*; diff --git a/test/lib-test/sun/hotspot/whitebox/MismatchedWhiteBox/WhiteBox.java b/test/lib-test/jdk/test/whitebox/MismatchedWhiteBox/WhiteBox.java similarity index 92% rename from test/lib-test/sun/hotspot/whitebox/MismatchedWhiteBox/WhiteBox.java rename to test/lib-test/jdk/test/whitebox/MismatchedWhiteBox/WhiteBox.java index 2afcde8b57d..eba941c5b11 100644 --- a/test/lib-test/sun/hotspot/whitebox/MismatchedWhiteBox/WhiteBox.java +++ b/test/lib-test/jdk/test/whitebox/MismatchedWhiteBox/WhiteBox.java @@ -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") diff --git a/test/lib-test/jdk/test/whitebox/OldWhiteBox.java b/test/lib-test/jdk/test/whitebox/OldWhiteBox.java new file mode 100644 index 00000000000..677ed210f69 --- /dev/null +++ b/test/lib-test/jdk/test/whitebox/OldWhiteBox.java @@ -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"); + } + } +} diff --git a/test/lib-test/sun/hotspot/whitebox/WBApi.java b/test/lib-test/jdk/test/whitebox/WBApi.java similarity index 90% rename from test/lib-test/sun/hotspot/whitebox/WBApi.java rename to test/lib-test/jdk/test/whitebox/WBApi.java index f43a67d5d96..1a83ffc328a 100644 --- a/test/lib-test/sun/hotspot/whitebox/WBApi.java +++ b/test/lib-test/jdk/test/whitebox/WBApi.java @@ -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)); diff --git a/test/lib-test/sun/hotspot/whitebox/vm_flags/BooleanTest.java b/test/lib-test/jdk/test/whitebox/vm_flags/BooleanTest.java similarity index 95% rename from test/lib-test/sun/hotspot/whitebox/vm_flags/BooleanTest.java rename to test/lib-test/jdk/test/whitebox/vm_flags/BooleanTest.java index 914e00e5add..43ed1dfc413 100644 --- a/test/lib-test/sun/hotspot/whitebox/vm_flags/BooleanTest.java +++ b/test/lib-test/jdk/test/whitebox/vm_flags/BooleanTest.java @@ -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.*; diff --git a/test/lib-test/sun/hotspot/whitebox/vm_flags/DoubleTest.java b/test/lib-test/jdk/test/whitebox/vm_flags/DoubleTest.java similarity index 93% rename from test/lib-test/sun/hotspot/whitebox/vm_flags/DoubleTest.java rename to test/lib-test/jdk/test/whitebox/vm_flags/DoubleTest.java index 17ca502a91b..97e23b93655 100644 --- a/test/lib-test/sun/hotspot/whitebox/vm_flags/DoubleTest.java +++ b/test/lib-test/jdk/test/whitebox/vm_flags/DoubleTest.java @@ -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 diff --git a/test/lib-test/sun/hotspot/whitebox/vm_flags/IntxTest.java b/test/lib-test/jdk/test/whitebox/vm_flags/IntxTest.java similarity index 95% rename from test/lib-test/sun/hotspot/whitebox/vm_flags/IntxTest.java rename to test/lib-test/jdk/test/whitebox/vm_flags/IntxTest.java index 0a44320abce..e9a696ff514 100644 --- a/test/lib-test/sun/hotspot/whitebox/vm_flags/IntxTest.java +++ b/test/lib-test/jdk/test/whitebox/vm_flags/IntxTest.java @@ -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 diff --git a/test/lib-test/sun/hotspot/whitebox/vm_flags/SizeTTest.java b/test/lib-test/jdk/test/whitebox/vm_flags/SizeTTest.java similarity index 94% rename from test/lib-test/sun/hotspot/whitebox/vm_flags/SizeTTest.java rename to test/lib-test/jdk/test/whitebox/vm_flags/SizeTTest.java index 21468acc771..ae57d6701fd 100644 --- a/test/lib-test/sun/hotspot/whitebox/vm_flags/SizeTTest.java +++ b/test/lib-test/jdk/test/whitebox/vm_flags/SizeTTest.java @@ -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() */ diff --git a/test/lib-test/sun/hotspot/whitebox/vm_flags/StringTest.java b/test/lib-test/jdk/test/whitebox/vm_flags/StringTest.java similarity index 94% rename from test/lib-test/sun/hotspot/whitebox/vm_flags/StringTest.java rename to test/lib-test/jdk/test/whitebox/vm_flags/StringTest.java index 86bc598285b..7bd684e7f05 100644 --- a/test/lib-test/sun/hotspot/whitebox/vm_flags/StringTest.java +++ b/test/lib-test/jdk/test/whitebox/vm_flags/StringTest.java @@ -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 diff --git a/test/lib-test/sun/hotspot/whitebox/vm_flags/Uint64Test.java b/test/lib-test/jdk/test/whitebox/vm_flags/Uint64Test.java similarity index 93% rename from test/lib-test/sun/hotspot/whitebox/vm_flags/Uint64Test.java rename to test/lib-test/jdk/test/whitebox/vm_flags/Uint64Test.java index 2e703b605e7..c3f5e2daf0c 100644 --- a/test/lib-test/sun/hotspot/whitebox/vm_flags/Uint64Test.java +++ b/test/lib-test/jdk/test/whitebox/vm_flags/Uint64Test.java @@ -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 diff --git a/test/lib-test/sun/hotspot/whitebox/vm_flags/UintxTest.java b/test/lib-test/jdk/test/whitebox/vm_flags/UintxTest.java similarity index 94% rename from test/lib-test/sun/hotspot/whitebox/vm_flags/UintxTest.java rename to test/lib-test/jdk/test/whitebox/vm_flags/UintxTest.java index e7e65447ec2..7d980fc1968 100644 --- a/test/lib-test/sun/hotspot/whitebox/vm_flags/UintxTest.java +++ b/test/lib-test/jdk/test/whitebox/vm_flags/UintxTest.java @@ -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 diff --git a/test/lib-test/sun/hotspot/whitebox/vm_flags/VmFlagTest.java b/test/lib-test/jdk/test/whitebox/vm_flags/VmFlagTest.java similarity index 98% rename from test/lib-test/sun/hotspot/whitebox/vm_flags/VmFlagTest.java rename to test/lib-test/jdk/test/whitebox/vm_flags/VmFlagTest.java index 35d2ffa43a1..d48aab6cf26 100644 --- a/test/lib-test/sun/hotspot/whitebox/vm_flags/VmFlagTest.java +++ b/test/lib-test/jdk/test/whitebox/vm_flags/VmFlagTest.java @@ -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; diff --git a/test/lib/jdk/test/lib/helpers/ClassFileInstaller.java b/test/lib/jdk/test/lib/helpers/ClassFileInstaller.java index b58ff795997..3c07469b7f7 100644 --- a/test/lib/jdk/test/lib/helpers/ClassFileInstaller.java +++ b/test/lib/jdk/test/lib/helpers/ClassFileInstaller.java @@ -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 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()]; diff --git a/test/lib/jdk/test/whitebox/WhiteBox.java b/test/lib/jdk/test/whitebox/WhiteBox.java new file mode 100644 index 00000000000..b534d0d7a4f --- /dev/null +++ b/test/lib/jdk/test/whitebox/WhiteBox.java @@ -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> 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> 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(); +} diff --git a/test/lib/jdk/test/whitebox/code/BlobType.java b/test/lib/jdk/test/whitebox/code/BlobType.java new file mode 100644 index 00000000000..24ce9d96a41 --- /dev/null +++ b/test/lib/jdk/test/whitebox/code/BlobType.java @@ -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 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 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); + } +} diff --git a/test/lib/jdk/test/whitebox/code/CodeBlob.java b/test/lib/jdk/test/whitebox/code/CodeBlob.java new file mode 100644 index 00000000000..c6c23fdff0c --- /dev/null +++ b/test/lib/jdk/test/whitebox/code/CodeBlob.java @@ -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 + + '}'; + } +} diff --git a/test/lib/jdk/test/whitebox/code/Compiler.java b/test/lib/jdk/test/whitebox/code/Compiler.java new file mode 100644 index 00000000000..65c5c464d00 --- /dev/null +++ b/test/lib/jdk/test/whitebox/code/Compiler.java @@ -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); + } +} diff --git a/test/lib/jdk/test/whitebox/code/NMethod.java b/test/lib/jdk/test/whitebox/code/NMethod.java new file mode 100644 index 00000000000..6092b1037db --- /dev/null +++ b/test/lib/jdk/test/whitebox/code/NMethod.java @@ -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 + + '}'; + } +} diff --git a/test/lib/jdk/test/whitebox/cpuinfo/CPUInfo.java b/test/lib/jdk/test/whitebox/cpuinfo/CPUInfo.java new file mode 100644 index 00000000000..98ab5021727 --- /dev/null +++ b/test/lib/jdk/test/whitebox/cpuinfo/CPUInfo.java @@ -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 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 getFeatures() { + return features; + } + + /** + * Check if some feature is supported by CPU. + * + * @param feature Name of feature to be tested. + * @return true if tested feature is supported by CPU. + */ + public static boolean hasFeature(String feature) { + return features.contains(feature.toLowerCase()); + } +} diff --git a/test/lib/jdk/test/whitebox/gc/GC.java b/test/lib/jdk/test/whitebox/gc/GC.java new file mode 100644 index 00000000000..ddcb6e554d4 --- /dev/null +++ b/test/lib/jdk/test/whitebox/gc/GC.java @@ -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"); + } +} diff --git a/test/lib/sun/hotspot/parser/DiagnosticCommand.java b/test/lib/jdk/test/whitebox/parser/DiagnosticCommand.java similarity index 95% rename from test/lib/sun/hotspot/parser/DiagnosticCommand.java rename to test/lib/jdk/test/whitebox/parser/DiagnosticCommand.java index 1ad6217ad59..adb699bac6a 100644 --- a/test/lib/sun/hotspot/parser/DiagnosticCommand.java +++ b/test/lib/jdk/test/whitebox/parser/DiagnosticCommand.java @@ -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 { diff --git a/test/lib/sun/hotspot/WhiteBox.java b/test/lib/sun/hotspot/WhiteBox.java index 1dd5e2c1cb0..44c1905368c 100644 --- a/test/lib/sun/hotspot/WhiteBox.java +++ b/test/lib/sun/hotspot/WhiteBox.java @@ -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; } diff --git a/test/lib/sun/hotspot/code/CodeBlob.java b/test/lib/sun/hotspot/code/CodeBlob.java index 8050c38ef16..98076e052ce 100644 --- a/test/lib/sun/hotspot/code/CodeBlob.java +++ b/test/lib/sun/hotspot/code/CodeBlob.java @@ -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) { diff --git a/test/lib/sun/hotspot/code/NMethod.java b/test/lib/sun/hotspot/code/NMethod.java index f7ebf752299..2f870396a59 100644 --- a/test/lib/sun/hotspot/code/NMethod.java +++ b/test/lib/sun/hotspot/code/NMethod.java @@ -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) { diff --git a/test/lib/sun/hotspot/cpuinfo/CPUInfo.java b/test/lib/sun/hotspot/cpuinfo/CPUInfo.java index ae740884de6..3f1a8bdc4a0 100644 --- a/test/lib/sun/hotspot/cpuinfo/CPUInfo.java +++ b/test/lib/sun/hotspot/cpuinfo/CPUInfo.java @@ -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 features;