13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26
27 #include <new>
28
29 #include "classfile/classLoaderData.hpp"
30 #include "classfile/stringTable.hpp"
31 #include "code/codeCache.hpp"
32 #include "compiler/methodMatcher.hpp"
33 #include "jvmtifiles/jvmtiEnv.hpp"
34 #include "memory/metadataFactory.hpp"
35 #include "memory/metaspaceShared.hpp"
36 #include "memory/universe.hpp"
37 #include "oops/constantPool.hpp"
38 #include "oops/oop.inline.hpp"
39 #include "prims/wbtestmethods/parserTests.hpp"
40 #include "prims/whitebox.hpp"
41 #include "runtime/arguments.hpp"
42 #include "runtime/compilationPolicy.hpp"
43 #include "runtime/deoptimization.hpp"
44 #include "runtime/interfaceSupport.hpp"
45 #include "runtime/javaCalls.hpp"
46 #include "runtime/os.hpp"
47 #include "runtime/sweeper.hpp"
48 #include "runtime/thread.hpp"
49 #include "runtime/vm_version.hpp"
50 #include "utilities/array.hpp"
51 #include "utilities/debug.hpp"
52 #include "utilities/exceptions.hpp"
1485 jthrowable throwable_obj = env->ExceptionOccurred();
1486 if (throwable_obj != NULL) {
1487 env->ExceptionClear();
1488 if (env->IsInstanceOf(throwable_obj, no_such_method_error_klass)) {
1489 // NoSuchMethodError is thrown when a method can't be found or a method is not native.
1490 // Ignoring the exception since it is not preventing use of other WhiteBox methods.
1491 tty->print_cr("Warning: 'NoSuchMethodError' on register of sun.hotspot.WhiteBox::%s%s",
1492 method_array[i].name, method_array[i].signature);
1493 }
1494 } else {
1495 // Registration failed unexpectedly.
1496 tty->print_cr("Warning: unexpected error on register of sun.hotspot.WhiteBox::%s%s. All methods will be unregistered",
1497 method_array[i].name, method_array[i].signature);
1498 env->UnregisterNatives(wbclass);
1499 break;
1500 }
1501 }
1502 }
1503 }
1504
1505 #define CC (char*)
1506
1507 static JNINativeMethod methods[] = {
1508 {CC"getObjectAddress0", CC"(Ljava/lang/Object;)J", (void*)&WB_GetObjectAddress },
1509 {CC"getObjectSize0", CC"(Ljava/lang/Object;)J", (void*)&WB_GetObjectSize },
1510 {CC"isObjectInOldGen0", CC"(Ljava/lang/Object;)Z", (void*)&WB_isObjectInOldGen },
1511 {CC"getHeapOopSize", CC"()I", (void*)&WB_GetHeapOopSize },
1512 {CC"getVMPageSize", CC"()I", (void*)&WB_GetVMPageSize },
1513 {CC"getVMAllocationGranularity", CC"()J", (void*)&WB_GetVMAllocationGranularity },
1514 {CC"getVMLargePageSize", CC"()J", (void*)&WB_GetVMLargePageSize},
1515 {CC"getHeapSpaceAlignment", CC"()J", (void*)&WB_GetHeapSpaceAlignment},
1516 {CC"isClassAlive0", CC"(Ljava/lang/String;)Z", (void*)&WB_IsClassAlive },
1517 {CC"parseCommandLine0",
1518 CC"(Ljava/lang/String;C[Lsun/hotspot/parser/DiagnosticCommand;)[Ljava/lang/Object;",
1519 (void*) &WB_ParseCommandLine
1520 },
1521 {CC"addToBootstrapClassLoaderSearch0", CC"(Ljava/lang/String;)V",
1522 (void*)&WB_AddToBootstrapClassLoaderSearch},
1523 {CC"addToSystemClassLoaderSearch0", CC"(Ljava/lang/String;)V",
1524 (void*)&WB_AddToSystemClassLoaderSearch},
1660 {CC"encodeConstantPoolIndyIndex0",
1661 CC"(I)I", (void*)&WB_ConstantPoolEncodeIndyIndex},
1662 {CC"getMethodBooleanOption",
1663 CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Boolean;",
1664 (void*)&WB_GetMethodBooleaneOption},
1665 {CC"getMethodIntxOption",
1666 CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Long;",
1667 (void*)&WB_GetMethodIntxOption},
1668 {CC"getMethodUintxOption",
1669 CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Long;",
1670 (void*)&WB_GetMethodUintxOption},
1671 {CC"getMethodDoubleOption",
1672 CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Double;",
1673 (void*)&WB_GetMethodDoubleOption},
1674 {CC"getMethodStringOption",
1675 CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/String;",
1676 (void*)&WB_GetMethodStringOption},
1677 {CC"isShared", CC"(Ljava/lang/Object;)Z", (void*)&WB_IsShared },
1678 {CC"areSharedStringsIgnored", CC"()Z", (void*)&WB_AreSharedStringsIgnored },
1679 {CC"clearInlineCaches", CC"()V", (void*)&WB_ClearInlineCaches },
1680 };
1681
1682 #undef CC
1683
1684 JVM_ENTRY(void, JVM_RegisterWhiteBoxMethods(JNIEnv* env, jclass wbclass))
1685 {
1686 if (WhiteBoxAPI) {
1687 // Make sure that wbclass is loaded by the null classloader
1688 instanceKlassHandle ikh = instanceKlassHandle(JNIHandles::resolve(wbclass)->klass());
1689 Handle loader(ikh->class_loader());
1690 if (loader.is_null()) {
1691 WhiteBox::register_methods(env, wbclass, thread, methods, sizeof(methods) / sizeof(methods[0]));
1692 WhiteBox::register_extended(env, wbclass, thread);
1693 WhiteBox::set_used();
1694 }
1695 }
1696 }
1697 JVM_END
|
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26
27 #include <new>
28
29 #include "classfile/classLoaderData.hpp"
30 #include "classfile/stringTable.hpp"
31 #include "code/codeCache.hpp"
32 #include "compiler/methodMatcher.hpp"
33 #include "compiler/directivesParser.hpp"
34 #include "jvmtifiles/jvmtiEnv.hpp"
35 #include "memory/metadataFactory.hpp"
36 #include "memory/metaspaceShared.hpp"
37 #include "memory/universe.hpp"
38 #include "oops/constantPool.hpp"
39 #include "oops/oop.inline.hpp"
40 #include "prims/wbtestmethods/parserTests.hpp"
41 #include "prims/whitebox.hpp"
42 #include "runtime/arguments.hpp"
43 #include "runtime/compilationPolicy.hpp"
44 #include "runtime/deoptimization.hpp"
45 #include "runtime/interfaceSupport.hpp"
46 #include "runtime/javaCalls.hpp"
47 #include "runtime/os.hpp"
48 #include "runtime/sweeper.hpp"
49 #include "runtime/thread.hpp"
50 #include "runtime/vm_version.hpp"
51 #include "utilities/array.hpp"
52 #include "utilities/debug.hpp"
53 #include "utilities/exceptions.hpp"
1486 jthrowable throwable_obj = env->ExceptionOccurred();
1487 if (throwable_obj != NULL) {
1488 env->ExceptionClear();
1489 if (env->IsInstanceOf(throwable_obj, no_such_method_error_klass)) {
1490 // NoSuchMethodError is thrown when a method can't be found or a method is not native.
1491 // Ignoring the exception since it is not preventing use of other WhiteBox methods.
1492 tty->print_cr("Warning: 'NoSuchMethodError' on register of sun.hotspot.WhiteBox::%s%s",
1493 method_array[i].name, method_array[i].signature);
1494 }
1495 } else {
1496 // Registration failed unexpectedly.
1497 tty->print_cr("Warning: unexpected error on register of sun.hotspot.WhiteBox::%s%s. All methods will be unregistered",
1498 method_array[i].name, method_array[i].signature);
1499 env->UnregisterNatives(wbclass);
1500 break;
1501 }
1502 }
1503 }
1504 }
1505
1506 WB_ENTRY(jint, WB_AddCompilerDirective(JNIEnv* env, jobject o, jstring compDirect))
1507 // can't be in VM when we call JNI
1508 ThreadToNativeFromVM ttnfv(thread);
1509 const char* dir = env->GetStringUTFChars(compDirect, NULL);
1510 int ret;
1511 {
1512 ThreadInVMfromNative ttvfn(thread); // back to VM
1513 ret = DirectivesParser::parse_string(dir, tty);
1514 }
1515 env->ReleaseStringUTFChars(compDirect, dir);
1516 // -1 for error parsing directive. Return 0 as number of directives added.
1517 if (ret == -1) {
1518 ret = 0;
1519 }
1520 return (jint) ret;
1521 WB_END
1522
1523 WB_ENTRY(void, WB_RemoveCompilerDirective(JNIEnv* env, jobject o, jint count))
1524 DirectivesStack::pop(count);
1525 WB_END
1526
1527 #define CC (char*)
1528
1529 static JNINativeMethod methods[] = {
1530 {CC"getObjectAddress0", CC"(Ljava/lang/Object;)J", (void*)&WB_GetObjectAddress },
1531 {CC"getObjectSize0", CC"(Ljava/lang/Object;)J", (void*)&WB_GetObjectSize },
1532 {CC"isObjectInOldGen0", CC"(Ljava/lang/Object;)Z", (void*)&WB_isObjectInOldGen },
1533 {CC"getHeapOopSize", CC"()I", (void*)&WB_GetHeapOopSize },
1534 {CC"getVMPageSize", CC"()I", (void*)&WB_GetVMPageSize },
1535 {CC"getVMAllocationGranularity", CC"()J", (void*)&WB_GetVMAllocationGranularity },
1536 {CC"getVMLargePageSize", CC"()J", (void*)&WB_GetVMLargePageSize},
1537 {CC"getHeapSpaceAlignment", CC"()J", (void*)&WB_GetHeapSpaceAlignment},
1538 {CC"isClassAlive0", CC"(Ljava/lang/String;)Z", (void*)&WB_IsClassAlive },
1539 {CC"parseCommandLine0",
1540 CC"(Ljava/lang/String;C[Lsun/hotspot/parser/DiagnosticCommand;)[Ljava/lang/Object;",
1541 (void*) &WB_ParseCommandLine
1542 },
1543 {CC"addToBootstrapClassLoaderSearch0", CC"(Ljava/lang/String;)V",
1544 (void*)&WB_AddToBootstrapClassLoaderSearch},
1545 {CC"addToSystemClassLoaderSearch0", CC"(Ljava/lang/String;)V",
1546 (void*)&WB_AddToSystemClassLoaderSearch},
1682 {CC"encodeConstantPoolIndyIndex0",
1683 CC"(I)I", (void*)&WB_ConstantPoolEncodeIndyIndex},
1684 {CC"getMethodBooleanOption",
1685 CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Boolean;",
1686 (void*)&WB_GetMethodBooleaneOption},
1687 {CC"getMethodIntxOption",
1688 CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Long;",
1689 (void*)&WB_GetMethodIntxOption},
1690 {CC"getMethodUintxOption",
1691 CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Long;",
1692 (void*)&WB_GetMethodUintxOption},
1693 {CC"getMethodDoubleOption",
1694 CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Double;",
1695 (void*)&WB_GetMethodDoubleOption},
1696 {CC"getMethodStringOption",
1697 CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/String;",
1698 (void*)&WB_GetMethodStringOption},
1699 {CC"isShared", CC"(Ljava/lang/Object;)Z", (void*)&WB_IsShared },
1700 {CC"areSharedStringsIgnored", CC"()Z", (void*)&WB_AreSharedStringsIgnored },
1701 {CC"clearInlineCaches", CC"()V", (void*)&WB_ClearInlineCaches },
1702 {CC"addCompilerDirective", CC"(Ljava/lang/String;)I",
1703 (void*)&WB_AddCompilerDirective },
1704 {CC"removeCompilerDirective", CC"(I)V", (void*)&WB_RemoveCompilerDirective },
1705 };
1706
1707 #undef CC
1708
1709 JVM_ENTRY(void, JVM_RegisterWhiteBoxMethods(JNIEnv* env, jclass wbclass))
1710 {
1711 if (WhiteBoxAPI) {
1712 // Make sure that wbclass is loaded by the null classloader
1713 instanceKlassHandle ikh = instanceKlassHandle(JNIHandles::resolve(wbclass)->klass());
1714 Handle loader(ikh->class_loader());
1715 if (loader.is_null()) {
1716 WhiteBox::register_methods(env, wbclass, thread, methods, sizeof(methods) / sizeof(methods[0]));
1717 WhiteBox::register_extended(env, wbclass, thread);
1718 WhiteBox::set_used();
1719 }
1720 }
1721 }
1722 JVM_END
|