< prev index next >

src/share/vm/prims/whitebox.cpp

Print this page
rev 10354 : 8150646: Add support for blocking compiles though whitebox API
Reviewed-by: kvn, ppunegov, simonis, neliasso
Contributed-by: nils.eliasson@oracle.com, volker.simonis@gmail.com


  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   return (jint) ret;
1517 WB_END
1518 
1519 WB_ENTRY(void, WB_RemoveCompilerDirective(JNIEnv* env, jobject o, jint count))
1520   DirectivesStack::pop(count);
1521 WB_END
1522 
1523 #define CC (char*)
1524 
1525 static JNINativeMethod methods[] = {
1526   {CC"getObjectAddress0",                CC"(Ljava/lang/Object;)J", (void*)&WB_GetObjectAddress  },
1527   {CC"getObjectSize0",                   CC"(Ljava/lang/Object;)J", (void*)&WB_GetObjectSize     },
1528   {CC"isObjectInOldGen0",                CC"(Ljava/lang/Object;)Z", (void*)&WB_isObjectInOldGen  },
1529   {CC"getHeapOopSize",                   CC"()I",                   (void*)&WB_GetHeapOopSize    },
1530   {CC"getVMPageSize",                    CC"()I",                   (void*)&WB_GetVMPageSize     },
1531   {CC"getVMAllocationGranularity",       CC"()J",                   (void*)&WB_GetVMAllocationGranularity },
1532   {CC"getVMLargePageSize",               CC"()J",                   (void*)&WB_GetVMLargePageSize},
1533   {CC"getHeapSpaceAlignment",            CC"()J",                   (void*)&WB_GetHeapSpaceAlignment},
1534   {CC"isClassAlive0",                    CC"(Ljava/lang/String;)Z", (void*)&WB_IsClassAlive      },
1535   {CC"parseCommandLine0",
1536       CC"(Ljava/lang/String;C[Lsun/hotspot/parser/DiagnosticCommand;)[Ljava/lang/Object;",
1537       (void*) &WB_ParseCommandLine
1538   },
1539   {CC"addToBootstrapClassLoaderSearch0", CC"(Ljava/lang/String;)V",
1540                                                       (void*)&WB_AddToBootstrapClassLoaderSearch},
1541   {CC"addToSystemClassLoaderSearch0",    CC"(Ljava/lang/String;)V",
1542                                                       (void*)&WB_AddToSystemClassLoaderSearch},


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