< prev index next >

src/hotspot/share/prims/jvm.cpp

Print this page

  65 #include "runtime/handles.inline.hpp"
  66 #include "runtime/init.hpp"
  67 #include "runtime/interfaceSupport.inline.hpp"
  68 #include "runtime/deoptimization.hpp"
  69 #include "runtime/handshake.hpp"
  70 #include "runtime/java.hpp"
  71 #include "runtime/javaCalls.hpp"
  72 #include "runtime/jfieldIDWorkaround.hpp"
  73 #include "runtime/jniHandles.inline.hpp"
  74 #include "runtime/os.inline.hpp"
  75 #include "runtime/perfData.hpp"
  76 #include "runtime/reflection.hpp"
  77 #include "runtime/thread.inline.hpp"
  78 #include "runtime/threadSMR.hpp"
  79 #include "runtime/vframe.inline.hpp"
  80 #include "runtime/vmOperations.hpp"
  81 #include "runtime/vm_version.hpp"
  82 #include "services/attachListener.hpp"
  83 #include "services/management.hpp"
  84 #include "services/threadService.hpp"



  85 #include "utilities/copy.hpp"
  86 #include "utilities/defaultStream.hpp"
  87 #include "utilities/dtrace.hpp"
  88 #include "utilities/events.hpp"
  89 #include "utilities/histogram.hpp"
  90 #include "utilities/macros.hpp"
  91 #include "utilities/utf8.hpp"
  92 #if INCLUDE_CDS
  93 #include "classfile/systemDictionaryShared.hpp"
  94 #endif
  95 
  96 #include <errno.h>
  97 
  98 /*
  99   NOTE about use of any ctor or function call that can trigger a safepoint/GC:
 100   such ctors and calls MUST NOT come between an oop declaration/init and its
 101   usage because if objects are move this may cause various memory stomps, bus
 102   errors and segfaults. Here is a cookbook for causing so called "naked oop
 103   failures":
 104 

3186 
3187 
3188 JVM_ENTRY(jstring, JVM_GetSystemPackage(JNIEnv *env, jstring name))
3189   JVMWrapper("JVM_GetSystemPackage");
3190   ResourceMark rm(THREAD);
3191   JvmtiVMObjectAllocEventCollector oam;
3192   char* str = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(name));
3193   oop result = ClassLoader::get_system_package(str, CHECK_NULL);
3194   return (jstring) JNIHandles::make_local(result);
3195 JVM_END
3196 
3197 
3198 JVM_ENTRY(jobjectArray, JVM_GetSystemPackages(JNIEnv *env))
3199   JVMWrapper("JVM_GetSystemPackages");
3200   JvmtiVMObjectAllocEventCollector oam;
3201   objArrayOop result = ClassLoader::get_system_packages(CHECK_NULL);
3202   return (jobjectArray) JNIHandles::make_local(result);
3203 JVM_END
3204 
3205 









3206 // java.lang.ref.Reference ///////////////////////////////////////////////////////////////
3207 
3208 
3209 JVM_ENTRY(jobject, JVM_GetAndClearReferencePendingList(JNIEnv* env))
3210   JVMWrapper("JVM_GetAndClearReferencePendingList");
3211 
3212   MonitorLocker ml(Heap_lock);
3213   oop ref = Universe::reference_pending_list();
3214   if (ref != NULL) {
3215     Universe::set_reference_pending_list(NULL);
3216   }
3217   return JNIHandles::make_local(env, ref);
3218 JVM_END
3219 
3220 JVM_ENTRY(jboolean, JVM_HasReferencePendingList(JNIEnv* env))
3221   JVMWrapper("JVM_HasReferencePendingList");
3222   MonitorLocker ml(Heap_lock);
3223   return Universe::has_reference_pending_list();
3224 JVM_END
3225 

3408   JvmtiVMObjectAllocEventCollector oam;
3409   if (str == NULL) return NULL;
3410   oop string = JNIHandles::resolve_non_null(str);
3411   oop result = StringTable::intern(string, CHECK_NULL);
3412   return (jstring) JNIHandles::make_local(env, result);
3413 JVM_END
3414 
3415 
3416 // VM Raw monitor support //////////////////////////////////////////////////////////////////////
3417 
3418 // VM Raw monitors (not to be confused with JvmtiRawMonitors) are a simple mutual exclusion
3419 // lock (not actually monitors: no wait/notify) that is exported by the VM for use by JDK
3420 // library code. They may be used by JavaThreads and non-JavaThreads and do not participate
3421 // in the safepoint protocol, thread suspension, thread interruption, or anything of that
3422 // nature. JavaThreads will be "in native" when using this API from JDK code.
3423 
3424 
3425 JNIEXPORT void* JNICALL JVM_RawMonitorCreate(void) {
3426   VM_Exit::block_if_vm_exited();
3427   JVMWrapper("JVM_RawMonitorCreate");
3428   return new os::PlatformMutex();


3429 }
3430 
3431 
3432 JNIEXPORT void JNICALL  JVM_RawMonitorDestroy(void *mon) {
3433   VM_Exit::block_if_vm_exited();
3434   JVMWrapper("JVM_RawMonitorDestroy");

3435   delete ((os::PlatformMutex*) mon);
3436 }
3437 
3438 
3439 JNIEXPORT jint JNICALL JVM_RawMonitorEnter(void *mon) {
3440   VM_Exit::block_if_vm_exited();
3441   JVMWrapper("JVM_RawMonitorEnter");
3442   ((os::PlatformMutex*) mon)->lock();

3443   return 0;
3444 }
3445 
3446 
3447 JNIEXPORT void JNICALL JVM_RawMonitorExit(void *mon) {
3448   VM_Exit::block_if_vm_exited();
3449   JVMWrapper("JVM_RawMonitorExit");

3450   ((os::PlatformMutex*) mon)->unlock();
3451 }
3452 
3453 
3454 // Shared JNI/JVM entry points //////////////////////////////////////////////////////////////
3455 
3456 jclass find_class_from_class_loader(JNIEnv* env, Symbol* name, jboolean init,
3457                                     Handle loader, Handle protection_domain,
3458                                     jboolean throwError, TRAPS) {
3459   // Security Note:
3460   //   The Java level wrapper will perform the necessary security check allowing
3461   //   us to pass the NULL as the initiating class loader.  The VM is responsible for
3462   //   the checkPackageAccess relative to the initiating class loader via the
3463   //   protection_domain. The protection_domain is passed as NULL by the java code
3464   //   if there is no security manager in 3-arg Class.forName().
3465   Klass* klass = SystemDictionary::resolve_or_fail(name, loader, protection_domain, throwError != 0, CHECK_NULL);
3466 
3467   // Check if we should initialize the class
3468   if (init && klass->is_instance_klass()) {
3469     klass->initialize(CHECK_NULL);

  65 #include "runtime/handles.inline.hpp"
  66 #include "runtime/init.hpp"
  67 #include "runtime/interfaceSupport.inline.hpp"
  68 #include "runtime/deoptimization.hpp"
  69 #include "runtime/handshake.hpp"
  70 #include "runtime/java.hpp"
  71 #include "runtime/javaCalls.hpp"
  72 #include "runtime/jfieldIDWorkaround.hpp"
  73 #include "runtime/jniHandles.inline.hpp"
  74 #include "runtime/os.inline.hpp"
  75 #include "runtime/perfData.hpp"
  76 #include "runtime/reflection.hpp"
  77 #include "runtime/thread.inline.hpp"
  78 #include "runtime/threadSMR.hpp"
  79 #include "runtime/vframe.inline.hpp"
  80 #include "runtime/vmOperations.hpp"
  81 #include "runtime/vm_version.hpp"
  82 #include "services/attachListener.hpp"
  83 #include "services/management.hpp"
  84 #include "services/threadService.hpp"
  85 #if INCLUDE_TSAN
  86 #include "tsan/tsan.hpp"
  87 #endif  // INCLUDE_TSAN
  88 #include "utilities/copy.hpp"
  89 #include "utilities/defaultStream.hpp"
  90 #include "utilities/dtrace.hpp"
  91 #include "utilities/events.hpp"
  92 #include "utilities/histogram.hpp"
  93 #include "utilities/macros.hpp"
  94 #include "utilities/utf8.hpp"
  95 #if INCLUDE_CDS
  96 #include "classfile/systemDictionaryShared.hpp"
  97 #endif
  98 
  99 #include <errno.h>
 100 
 101 /*
 102   NOTE about use of any ctor or function call that can trigger a safepoint/GC:
 103   such ctors and calls MUST NOT come between an oop declaration/init and its
 104   usage because if objects are move this may cause various memory stomps, bus
 105   errors and segfaults. Here is a cookbook for causing so called "naked oop
 106   failures":
 107 

3189 
3190 
3191 JVM_ENTRY(jstring, JVM_GetSystemPackage(JNIEnv *env, jstring name))
3192   JVMWrapper("JVM_GetSystemPackage");
3193   ResourceMark rm(THREAD);
3194   JvmtiVMObjectAllocEventCollector oam;
3195   char* str = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(name));
3196   oop result = ClassLoader::get_system_package(str, CHECK_NULL);
3197   return (jstring) JNIHandles::make_local(result);
3198 JVM_END
3199 
3200 
3201 JVM_ENTRY(jobjectArray, JVM_GetSystemPackages(JNIEnv *env))
3202   JVMWrapper("JVM_GetSystemPackages");
3203   JvmtiVMObjectAllocEventCollector oam;
3204   objArrayOop result = ClassLoader::get_system_packages(CHECK_NULL);
3205   return (jobjectArray) JNIHandles::make_local(result);
3206 JVM_END
3207 
3208 
3209 // java.lang.ref.Finalizer ///////////////////////////////////////////////////////////////
3210 
3211 JVM_ENTRY(jboolean, JVM_GetTsanEnabled(JNIEnv *env))
3212   JVMWrapper("JVM_GetTsanEnabled");
3213   TSAN_ONLY(return ThreadSanitizer;)
3214   NOT_TSAN(return JNI_FALSE;)
3215 JVM_END
3216 
3217 
3218 // java.lang.ref.Reference ///////////////////////////////////////////////////////////////
3219 
3220 
3221 JVM_ENTRY(jobject, JVM_GetAndClearReferencePendingList(JNIEnv* env))
3222   JVMWrapper("JVM_GetAndClearReferencePendingList");
3223 
3224   MonitorLocker ml(Heap_lock);
3225   oop ref = Universe::reference_pending_list();
3226   if (ref != NULL) {
3227     Universe::set_reference_pending_list(NULL);
3228   }
3229   return JNIHandles::make_local(env, ref);
3230 JVM_END
3231 
3232 JVM_ENTRY(jboolean, JVM_HasReferencePendingList(JNIEnv* env))
3233   JVMWrapper("JVM_HasReferencePendingList");
3234   MonitorLocker ml(Heap_lock);
3235   return Universe::has_reference_pending_list();
3236 JVM_END
3237 

3420   JvmtiVMObjectAllocEventCollector oam;
3421   if (str == NULL) return NULL;
3422   oop string = JNIHandles::resolve_non_null(str);
3423   oop result = StringTable::intern(string, CHECK_NULL);
3424   return (jstring) JNIHandles::make_local(env, result);
3425 JVM_END
3426 
3427 
3428 // VM Raw monitor support //////////////////////////////////////////////////////////////////////
3429 
3430 // VM Raw monitors (not to be confused with JvmtiRawMonitors) are a simple mutual exclusion
3431 // lock (not actually monitors: no wait/notify) that is exported by the VM for use by JDK
3432 // library code. They may be used by JavaThreads and non-JavaThreads and do not participate
3433 // in the safepoint protocol, thread suspension, thread interruption, or anything of that
3434 // nature. JavaThreads will be "in native" when using this API from JDK code.
3435 
3436 
3437 JNIEXPORT void* JNICALL JVM_RawMonitorCreate(void) {
3438   VM_Exit::block_if_vm_exited();
3439   JVMWrapper("JVM_RawMonitorCreate");
3440   void *mon = new os::PlatformMutex();
3441   TSAN_RUNTIME_ONLY(TSAN_RAW_LOCK_CREATE(mon));
3442   return mon;
3443 }
3444 
3445 
3446 JNIEXPORT void JNICALL  JVM_RawMonitorDestroy(void *mon) {
3447   VM_Exit::block_if_vm_exited();
3448   JVMWrapper("JVM_RawMonitorDestroy");
3449   TSAN_RUNTIME_ONLY(TSAN_RAW_LOCK_DESTROY(mon));
3450   delete ((os::PlatformMutex*) mon);
3451 }
3452 
3453 
3454 JNIEXPORT jint JNICALL JVM_RawMonitorEnter(void *mon) {
3455   VM_Exit::block_if_vm_exited();
3456   JVMWrapper("JVM_RawMonitorEnter");
3457   ((os::PlatformMutex*) mon)->lock();
3458   TSAN_RUNTIME_ONLY(TSAN_RAW_LOCK_ACQUIRED(mon));
3459   return 0;
3460 }
3461 
3462 
3463 JNIEXPORT void JNICALL JVM_RawMonitorExit(void *mon) {
3464   VM_Exit::block_if_vm_exited();
3465   JVMWrapper("JVM_RawMonitorExit");
3466   TSAN_RUNTIME_ONLY(TSAN_RAW_LOCK_RELEASED(mon));
3467   ((os::PlatformMutex*) mon)->unlock();
3468 }
3469 
3470 
3471 // Shared JNI/JVM entry points //////////////////////////////////////////////////////////////
3472 
3473 jclass find_class_from_class_loader(JNIEnv* env, Symbol* name, jboolean init,
3474                                     Handle loader, Handle protection_domain,
3475                                     jboolean throwError, TRAPS) {
3476   // Security Note:
3477   //   The Java level wrapper will perform the necessary security check allowing
3478   //   us to pass the NULL as the initiating class loader.  The VM is responsible for
3479   //   the checkPackageAccess relative to the initiating class loader via the
3480   //   protection_domain. The protection_domain is passed as NULL by the java code
3481   //   if there is no security manager in 3-arg Class.forName().
3482   Klass* klass = SystemDictionary::resolve_or_fail(name, loader, protection_domain, throwError != 0, CHECK_NULL);
3483 
3484   // Check if we should initialize the class
3485   if (init && klass->is_instance_klass()) {
3486     klass->initialize(CHECK_NULL);
< prev index next >