diff --git a/src/share/vm/prims/whitebox.cpp b/src/share/vm/prims/whitebox.cpp index 9028a85398372d8113209aa8f76466981e30dc5e..ef5cd01d85fc3659992d853183c59371d1a09e7c 100644 --- a/src/share/vm/prims/whitebox.cpp +++ b/src/share/vm/prims/whitebox.cpp @@ -695,6 +695,12 @@ WB_END WB_ENTRY(void, WB_FullGC(JNIEnv* env, jobject o)) Universe::heap()->collector_policy()->set_should_clear_all_soft_refs(true); Universe::heap()->collect(GCCause::_last_ditch_collection); +#if INCLUDE_ALL_GCS + if (UseG1GC) { + // Needs to be cleared explicitly for G1 + Universe::heap()->collector_policy()->set_should_clear_all_soft_refs(false); + } +#endif // INCLUDE_ALL_GCS WB_END WB_ENTRY(void, WB_YoungGC(JNIEnv* env, jobject o)) @@ -838,6 +844,36 @@ bool WhiteBox::lookup_bool(const char* field_name, oop object) { return ret; } +void WhiteBox::register_methods(JNIEnv* env, jclass wbclass, JavaThread* thread, JNINativeMethod* method_array, int method_count) { + ResourceMark rm; + ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI + + // one by one registration natives for exception catching + jclass no_such_method_error_klass = env->FindClass(vmSymbols::java_lang_NoSuchMethodError()->as_C_string()); + CHECK_JNI_EXCEPTION(env); + for (int i = 0, n = method_count; i < n; ++i) { + // Skip dummy entries + if (method_array[i].fnPtr == NULL) continue; + if (env->RegisterNatives(wbclass, &method_array[i], 1) != 0) { + jthrowable throwable_obj = env->ExceptionOccurred(); + if (throwable_obj != NULL) { + env->ExceptionClear(); + 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); + } + } 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); + env->UnregisterNatives(wbclass); + break; + } + } + } +} #define CC (char*) @@ -940,35 +976,9 @@ JVM_ENTRY(void, JVM_RegisterWhiteBoxMethods(JNIEnv* env, jclass wbclass)) instanceKlassHandle ikh = instanceKlassHandle(JNIHandles::resolve(wbclass)->klass()); Handle loader(ikh->class_loader()); if (loader.is_null()) { - ResourceMark rm; - ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI - bool result = true; - // one by one registration natives for exception catching - jclass exceptionKlass = env->FindClass(vmSymbols::java_lang_NoSuchMethodError()->as_C_string()); - CHECK_JNI_EXCEPTION(env); - for (int i = 0, n = sizeof(methods) / sizeof(methods[0]); i < n; ++i) { - if (env->RegisterNatives(wbclass, methods + i, 1) != 0) { - result = false; - jthrowable throwable_obj = env->ExceptionOccurred(); - if (throwable_obj != NULL) { - env->ExceptionClear(); - if (env->IsInstanceOf(throwable_obj, exceptionKlass)) { - // j.l.NoSuchMethodError is thrown when a method can't be found or a method is not native - // ignoring the exception - tty->print_cr("Warning: 'NoSuchMethodError' on register of sun.hotspot.WhiteBox::%s%s", methods[i].name, methods[i].signature); - } - } else { - // register is failed w/o exception or w/ unexpected exception - tty->print_cr("Warning: unexpected error on register of sun.hotspot.WhiteBox::%s%s. All methods will be unregistered", methods[i].name, methods[i].signature); - env->UnregisterNatives(wbclass); - break; - } - } - } - - if (result) { - WhiteBox::set_used(); - } + WhiteBox::register_methods(env, wbclass, thread, methods, sizeof(methods) / sizeof(methods[0])); + WhiteBox::register_extended(env, wbclass, thread); + WhiteBox::set_used(); } } } diff --git a/src/share/vm/prims/whitebox.hpp b/src/share/vm/prims/whitebox.hpp index 9ab406fc67261994e4123b5008fee1e0e8091f42..6461d1eb812445c2b9adc317118317c21540ffe3 100644 --- a/src/share/vm/prims/whitebox.hpp +++ b/src/share/vm/prims/whitebox.hpp @@ -29,6 +29,8 @@ #include "memory/allocation.hpp" #include "oops/oopsHierarchy.hpp" +#include "oops/symbol.hpp" +#include "runtime/interfaceSupport.hpp" // Entry macro to transition from JNI to VM state. @@ -64,6 +66,9 @@ class WhiteBox : public AllStatic { static bool lookup_bool(const char* field_name, oop object); static int array_bytes_to_length(size_t bytes); + static void register_methods(JNIEnv* env, jclass wbclass, JavaThread* thread, + JNINativeMethod* method_array, int method_count); + static void register_extended(JNIEnv* env, jclass wbclass, JavaThread* thread); }; diff --git a/src/share/vm/prims/whitebox_ext.cpp b/src/share/vm/prims/whitebox_ext.cpp new file mode 100644 index 0000000000000000000000000000000000000000..34f191cbdb7df1c6a434a67c70d9af970ddf20e2 --- /dev/null +++ b/src/share/vm/prims/whitebox_ext.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2012, 2014, 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. + * + */ + +#include "precompiled.hpp" + +#include "prims/whitebox.hpp" + +void WhiteBox::register_extended(JNIEnv* env, jclass wbclass, JavaThread* thread) { } diff --git a/test/testlibrary/whitebox/sun/hotspot/WhiteBox.java b/test/testlibrary/whitebox/sun/hotspot/WhiteBox.java index 360d702c2792ae8ba3d12b714f3793335d9bbea0..2dfaa05fac382f5f5864988b2a83dedc4d54baba 100644 --- a/test/testlibrary/whitebox/sun/hotspot/WhiteBox.java +++ b/test/testlibrary/whitebox/sun/hotspot/WhiteBox.java @@ -30,6 +30,7 @@ import java.util.List; import java.util.function.Function; import java.util.stream.Stream; import java.security.BasicPermission; + import sun.hotspot.parser.DiagnosticCommand; public class WhiteBox { @@ -168,6 +169,12 @@ public class WhiteBox { // CPU features public native String getCPUFeatures(); + // Native extensions + public native long getHeapUsageForContext(int context); + public native long getHeapRegionCountForContext(int context); + public native int getContextForObject(Object obj); + public native void printRegionInfo(int context); + // VM flags public native void setBooleanVMFlag(String name, boolean value); public native void setIntxVMFlag(String name, long value);