< prev index next >

src/share/vm/prims/whitebox.cpp

Print this page




  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 "jvmtifiles/jvmtiEnv.hpp"
  33 #include "memory/metadataFactory.hpp"

  34 #include "memory/universe.hpp"
  35 #include "oops/oop.inline.hpp"
  36 #include "prims/wbtestmethods/parserTests.hpp"
  37 #include "prims/whitebox.hpp"
  38 #include "runtime/arguments.hpp"
  39 #include "runtime/compilationPolicy.hpp"
  40 #include "runtime/deoptimization.hpp"
  41 #include "runtime/interfaceSupport.hpp"
  42 #include "runtime/javaCalls.hpp"
  43 #include "runtime/os.hpp"
  44 #include "runtime/sweeper.hpp"
  45 #include "runtime/thread.hpp"
  46 #include "runtime/vm_version.hpp"
  47 #include "utilities/array.hpp"
  48 #include "utilities/debug.hpp"
  49 #include "utilities/exceptions.hpp"
  50 #include "utilities/macros.hpp"
  51 #if INCLUDE_ALL_GCS
  52 #include "gc/g1/concurrentMark.hpp"
  53 #include "gc/g1/concurrentMarkThread.hpp"


1162   if (GetMethodOption <double> (thread, env, method, name, &result)) {
1163     // can't be in VM when we call JNI
1164     ThreadToNativeFromVM ttnfv(thread);
1165     return doubleBox(thread, env, result);
1166   }
1167   return NULL;
1168 WB_END
1169 
1170 WB_ENTRY(jobject, WB_GetMethodStringOption(JNIEnv* env, jobject wb, jobject method, jstring name))
1171   ccstr ccstrResult;
1172   if (GetMethodOption <ccstr> (thread, env, method, name, &ccstrResult)) {
1173     // can't be in VM when we call JNI
1174     ThreadToNativeFromVM ttnfv(thread);
1175     jstring result = env->NewStringUTF(ccstrResult);
1176     CHECK_JNI_EXCEPTION_(env, NULL);
1177     return result;
1178   }
1179   return NULL;
1180 WB_END
1181 





1182 //Some convenience methods to deal with objects from java
1183 int WhiteBox::offset_for_field(const char* field_name, oop object,
1184     Symbol* signature_symbol) {
1185   assert(field_name != NULL && strlen(field_name) > 0, "Field name not valid");
1186   Thread* THREAD = Thread::current();
1187 
1188   //Get the class of our object
1189   Klass* arg_klass = object->klass();
1190   //Turn it into an instance-klass
1191   InstanceKlass* ik = InstanceKlass::cast(arg_klass);
1192 
1193   //Create symbols to look for in the class
1194   TempNewSymbol name_symbol = SymbolTable::lookup(field_name, (int) strlen(field_name),
1195       THREAD);
1196 
1197   //To be filled in with an offset of the field we're looking for
1198   fieldDescriptor fd;
1199 
1200   Klass* res = ik->find_field(name_symbol, signature_symbol, &fd);
1201   if (res == NULL) {


1380   {CC"getThreadStackSize", CC"()J",                   (void*)&WB_GetThreadStackSize },
1381   {CC"getThreadRemainingStackSize", CC"()J",          (void*)&WB_GetThreadRemainingStackSize },
1382   {CC"assertMatchingSafepointCalls", CC"(ZZ)V",       (void*)&WB_AssertMatchingSafepointCalls },
1383   {CC"isMonitorInflated0",  CC"(Ljava/lang/Object;)Z", (void*)&WB_IsMonitorInflated  },
1384   {CC"forceSafepoint",     CC"()V",                   (void*)&WB_ForceSafepoint     },
1385   {CC"getMethodBooleanOption",
1386       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Boolean;",
1387                                                       (void*)&WB_GetMethodBooleaneOption},
1388   {CC"getMethodIntxOption",
1389       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Long;",
1390                                                       (void*)&WB_GetMethodIntxOption},
1391   {CC"getMethodUintxOption",
1392       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Long;",
1393                                                       (void*)&WB_GetMethodUintxOption},
1394   {CC"getMethodDoubleOption",
1395       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Double;",
1396                                                       (void*)&WB_GetMethodDoubleOption},
1397   {CC"getMethodStringOption",
1398       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/String;",
1399                                                       (void*)&WB_GetMethodStringOption},

1400 };
1401 
1402 #undef CC
1403 
1404 JVM_ENTRY(void, JVM_RegisterWhiteBoxMethods(JNIEnv* env, jclass wbclass))
1405   {
1406     if (WhiteBoxAPI) {
1407       // Make sure that wbclass is loaded by the null classloader
1408       instanceKlassHandle ikh = instanceKlassHandle(JNIHandles::resolve(wbclass)->klass());
1409       Handle loader(ikh->class_loader());
1410       if (loader.is_null()) {
1411         WhiteBox::register_methods(env, wbclass, thread, methods, sizeof(methods) / sizeof(methods[0]));
1412         WhiteBox::register_extended(env, wbclass, thread);
1413         WhiteBox::set_used();
1414       }
1415     }
1416   }
1417 JVM_END


  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 "jvmtifiles/jvmtiEnv.hpp"
  33 #include "memory/metadataFactory.hpp"
  34 #include "memory/metaspaceShared.hpp"
  35 #include "memory/universe.hpp"
  36 #include "oops/oop.inline.hpp"
  37 #include "prims/wbtestmethods/parserTests.hpp"
  38 #include "prims/whitebox.hpp"
  39 #include "runtime/arguments.hpp"
  40 #include "runtime/compilationPolicy.hpp"
  41 #include "runtime/deoptimization.hpp"
  42 #include "runtime/interfaceSupport.hpp"
  43 #include "runtime/javaCalls.hpp"
  44 #include "runtime/os.hpp"
  45 #include "runtime/sweeper.hpp"
  46 #include "runtime/thread.hpp"
  47 #include "runtime/vm_version.hpp"
  48 #include "utilities/array.hpp"
  49 #include "utilities/debug.hpp"
  50 #include "utilities/exceptions.hpp"
  51 #include "utilities/macros.hpp"
  52 #if INCLUDE_ALL_GCS
  53 #include "gc/g1/concurrentMark.hpp"
  54 #include "gc/g1/concurrentMarkThread.hpp"


1163   if (GetMethodOption <double> (thread, env, method, name, &result)) {
1164     // can't be in VM when we call JNI
1165     ThreadToNativeFromVM ttnfv(thread);
1166     return doubleBox(thread, env, result);
1167   }
1168   return NULL;
1169 WB_END
1170 
1171 WB_ENTRY(jobject, WB_GetMethodStringOption(JNIEnv* env, jobject wb, jobject method, jstring name))
1172   ccstr ccstrResult;
1173   if (GetMethodOption <ccstr> (thread, env, method, name, &ccstrResult)) {
1174     // can't be in VM when we call JNI
1175     ThreadToNativeFromVM ttnfv(thread);
1176     jstring result = env->NewStringUTF(ccstrResult);
1177     CHECK_JNI_EXCEPTION_(env, NULL);
1178     return result;
1179   }
1180   return NULL;
1181 WB_END
1182 
1183 WB_ENTRY(jboolean, WB_IsShared(JNIEnv* env, jobject wb, jobject obj))
1184   oop obj_oop = JNIHandles::resolve(obj);
1185   return MetaspaceShared::is_in_shared_space((void*)obj_oop);
1186 WB_END
1187 
1188 //Some convenience methods to deal with objects from java
1189 int WhiteBox::offset_for_field(const char* field_name, oop object,
1190     Symbol* signature_symbol) {
1191   assert(field_name != NULL && strlen(field_name) > 0, "Field name not valid");
1192   Thread* THREAD = Thread::current();
1193 
1194   //Get the class of our object
1195   Klass* arg_klass = object->klass();
1196   //Turn it into an instance-klass
1197   InstanceKlass* ik = InstanceKlass::cast(arg_klass);
1198 
1199   //Create symbols to look for in the class
1200   TempNewSymbol name_symbol = SymbolTable::lookup(field_name, (int) strlen(field_name),
1201       THREAD);
1202 
1203   //To be filled in with an offset of the field we're looking for
1204   fieldDescriptor fd;
1205 
1206   Klass* res = ik->find_field(name_symbol, signature_symbol, &fd);
1207   if (res == NULL) {


1386   {CC"getThreadStackSize", CC"()J",                   (void*)&WB_GetThreadStackSize },
1387   {CC"getThreadRemainingStackSize", CC"()J",          (void*)&WB_GetThreadRemainingStackSize },
1388   {CC"assertMatchingSafepointCalls", CC"(ZZ)V",       (void*)&WB_AssertMatchingSafepointCalls },
1389   {CC"isMonitorInflated0",  CC"(Ljava/lang/Object;)Z", (void*)&WB_IsMonitorInflated  },
1390   {CC"forceSafepoint",     CC"()V",                   (void*)&WB_ForceSafepoint     },
1391   {CC"getMethodBooleanOption",
1392       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Boolean;",
1393                                                       (void*)&WB_GetMethodBooleaneOption},
1394   {CC"getMethodIntxOption",
1395       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Long;",
1396                                                       (void*)&WB_GetMethodIntxOption},
1397   {CC"getMethodUintxOption",
1398       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Long;",
1399                                                       (void*)&WB_GetMethodUintxOption},
1400   {CC"getMethodDoubleOption",
1401       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Double;",
1402                                                       (void*)&WB_GetMethodDoubleOption},
1403   {CC"getMethodStringOption",
1404       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/String;",
1405                                                       (void*)&WB_GetMethodStringOption},
1406   {CC"isShared",           CC"(Ljava/lang/Object;)Z", (void*)&WB_IsShared },
1407 };
1408 
1409 #undef CC
1410 
1411 JVM_ENTRY(void, JVM_RegisterWhiteBoxMethods(JNIEnv* env, jclass wbclass))
1412   {
1413     if (WhiteBoxAPI) {
1414       // Make sure that wbclass is loaded by the null classloader
1415       instanceKlassHandle ikh = instanceKlassHandle(JNIHandles::resolve(wbclass)->klass());
1416       Handle loader(ikh->class_loader());
1417       if (loader.is_null()) {
1418         WhiteBox::register_methods(env, wbclass, thread, methods, sizeof(methods) / sizeof(methods[0]));
1419         WhiteBox::register_extended(env, wbclass, thread);
1420         WhiteBox::set_used();
1421       }
1422     }
1423   }
1424 JVM_END
< prev index next >