src/share/vm/prims/whitebox.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot Sdiff src/share/vm/prims

src/share/vm/prims/whitebox.cpp

Print this page
rev 10344 : 8150646: Add support for blocking compiles through whitebox API


  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(jboolean, WB_AddCompilerDirective(JNIEnv* env, jobject o, jstring compDirect))
1507   char* tmpstr = NULL;
1508   {
1509     // can't be in VM when we call JNI
1510     ThreadToNativeFromVM ttnfv(thread);
1511     const char* dirstr = env->GetStringUTFChars(compDirect, NULL);
1512     tmpstr = strdup(dirstr);
1513     env->ReleaseStringUTFChars(compDirect, dirstr);
1514   }
1515   return (jboolean) DirectivesParser::parse_string(tmpstr, tty);;
1516 WB_END
1517 
1518 WB_ENTRY(void, WB_RemoveCompilerDirective(JNIEnv* env, jobject o))
1519   DirectivesStack::pop();
1520 WB_END
1521 
1522 #define CC (char*)
1523 
1524 static JNINativeMethod methods[] = {
1525   {CC"getObjectAddress0",                CC"(Ljava/lang/Object;)J", (void*)&WB_GetObjectAddress  },
1526   {CC"getObjectSize0",                   CC"(Ljava/lang/Object;)J", (void*)&WB_GetObjectSize     },
1527   {CC"isObjectInOldGen0",                CC"(Ljava/lang/Object;)Z", (void*)&WB_isObjectInOldGen  },
1528   {CC"getHeapOopSize",                   CC"()I",                   (void*)&WB_GetHeapOopSize    },
1529   {CC"getVMPageSize",                    CC"()I",                   (void*)&WB_GetVMPageSize     },
1530   {CC"getVMAllocationGranularity",       CC"()J",                   (void*)&WB_GetVMAllocationGranularity },
1531   {CC"getVMLargePageSize",               CC"()J",                   (void*)&WB_GetVMLargePageSize},
1532   {CC"getHeapSpaceAlignment",            CC"()J",                   (void*)&WB_GetHeapSpaceAlignment},
1533   {CC"isClassAlive0",                    CC"(Ljava/lang/String;)Z", (void*)&WB_IsClassAlive      },
1534   {CC"parseCommandLine0",
1535       CC"(Ljava/lang/String;C[Lsun/hotspot/parser/DiagnosticCommand;)[Ljava/lang/Object;",
1536       (void*) &WB_ParseCommandLine
1537   },
1538   {CC"addToBootstrapClassLoaderSearch0", CC"(Ljava/lang/String;)V",
1539                                                       (void*)&WB_AddToBootstrapClassLoaderSearch},
1540   {CC"addToSystemClassLoaderSearch0",    CC"(Ljava/lang/String;)V",
1541                                                       (void*)&WB_AddToSystemClassLoaderSearch},


1677   {CC"encodeConstantPoolIndyIndex0",
1678       CC"(I)I",                      (void*)&WB_ConstantPoolEncodeIndyIndex},
1679   {CC"getMethodBooleanOption",
1680       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Boolean;",
1681                                                       (void*)&WB_GetMethodBooleaneOption},
1682   {CC"getMethodIntxOption",
1683       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Long;",
1684                                                       (void*)&WB_GetMethodIntxOption},
1685   {CC"getMethodUintxOption",
1686       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Long;",
1687                                                       (void*)&WB_GetMethodUintxOption},
1688   {CC"getMethodDoubleOption",
1689       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Double;",
1690                                                       (void*)&WB_GetMethodDoubleOption},
1691   {CC"getMethodStringOption",
1692       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/String;",
1693                                                       (void*)&WB_GetMethodStringOption},
1694   {CC"isShared",           CC"(Ljava/lang/Object;)Z", (void*)&WB_IsShared },
1695   {CC"areSharedStringsIgnored",           CC"()Z",    (void*)&WB_AreSharedStringsIgnored },
1696   {CC"clearInlineCaches",  CC"()V",                   (void*)&WB_ClearInlineCaches },
1697   {CC"addCompilerDirective",    CC"(Ljava/lang/String;)Z",
1698                                                       (void*)&WB_AddCompilerDirective },
1699   {CC"removeCompilerDirective", CC"()V",              (void*)&WB_RemoveCompilerDirective },
1700 };
1701 
1702 #undef CC
1703 
1704 JVM_ENTRY(void, JVM_RegisterWhiteBoxMethods(JNIEnv* env, jclass wbclass))
1705   {
1706     if (WhiteBoxAPI) {
1707       // Make sure that wbclass is loaded by the null classloader
1708       instanceKlassHandle ikh = instanceKlassHandle(JNIHandles::resolve(wbclass)->klass());
1709       Handle loader(ikh->class_loader());
1710       if (loader.is_null()) {
1711         WhiteBox::register_methods(env, wbclass, thread, methods, sizeof(methods) / sizeof(methods[0]));
1712         WhiteBox::register_extended(env, wbclass, thread);
1713         WhiteBox::set_used();
1714       }
1715     }
1716   }
1717 JVM_END
src/share/vm/prims/whitebox.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File