< prev index next >

src/hotspot/share/prims/jni.cpp

Print this page




 257   guarantee(InstanceKlass::cast(k)->contains_field_offset(offset),
 258       "Bug in native code: jfieldID offset must address interior of object");
 259 }
 260 
 261 // Wrapper to trace JNI functions
 262 
 263 #ifdef ASSERT
 264   Histogram* JNIHistogram;
 265   static volatile int JNIHistogram_lock = 0;
 266 
 267   class JNIHistogramElement : public HistogramElement {
 268     public:
 269      JNIHistogramElement(const char* name);
 270   };
 271 
 272   JNIHistogramElement::JNIHistogramElement(const char* elementName) {
 273     _name = elementName;
 274     uintx count = 0;
 275 
 276     while (Atomic::cmpxchg(1, &JNIHistogram_lock, 0) != 0) {
 277       while (OrderAccess::load_acquire(&JNIHistogram_lock) != 0) {
 278         count +=1;
 279         if ( (WarnOnStalledSpinLock > 0)
 280           && (count % WarnOnStalledSpinLock == 0)) {
 281           warning("JNIHistogram_lock seems to be stalled");
 282         }
 283       }
 284      }
 285 
 286 
 287     if(JNIHistogram == NULL)
 288       JNIHistogram = new Histogram("JNI Call Counts",100);
 289 
 290     JNIHistogram->add_element(this);
 291     Atomic::dec(&JNIHistogram_lock);
 292   }
 293 
 294   #define JNICountWrapper(arg)                                     \
 295      static JNIHistogramElement* e = new JNIHistogramElement(arg); \
 296       /* There is a MT-race condition in VC++. So we need to make sure that that e has been initialized */ \
 297      if (e != NULL) e->increment_count()


3899     // to continue.
3900     if (Universe::is_fully_initialized()) {
3901       // otherwise no pending exception possible - VM will already have aborted
3902       JavaThread* THREAD = JavaThread::current();
3903       if (HAS_PENDING_EXCEPTION) {
3904         HandleMark hm;
3905         vm_exit_during_initialization(Handle(THREAD, PENDING_EXCEPTION));
3906       }
3907     }
3908 
3909     if (can_try_again) {
3910       // reset safe_to_recreate_vm to 1 so that retrial would be possible
3911       safe_to_recreate_vm = 1;
3912     }
3913 
3914     // Creation failed. We must reset vm_created
3915     *vm = 0;
3916     *(JNIEnv**)penv = 0;
3917     // reset vm_created last to avoid race condition. Use OrderAccess to
3918     // control both compiler and architectural-based reordering.
3919     OrderAccess::release_store(&vm_created, 0);
3920   }
3921 
3922   // Flush stdout and stderr before exit.
3923   fflush(stdout);
3924   fflush(stderr);
3925 
3926   return result;
3927 
3928 }
3929 
3930 _JNI_IMPORT_OR_EXPORT_ jint JNICALL JNI_CreateJavaVM(JavaVM **vm, void **penv, void *args) {
3931   jint result = JNI_ERR;
3932   // On Windows, let CreateJavaVM run with SEH protection
3933 #ifdef _WIN32
3934   __try {
3935 #endif
3936     result = JNI_CreateJavaVM_inner(vm, penv, args);
3937 #ifdef _WIN32
3938   } __except(topLevelExceptionFilter((_EXCEPTION_POINTERS*)_exception_info())) {
3939     // Nothing to do.




 257   guarantee(InstanceKlass::cast(k)->contains_field_offset(offset),
 258       "Bug in native code: jfieldID offset must address interior of object");
 259 }
 260 
 261 // Wrapper to trace JNI functions
 262 
 263 #ifdef ASSERT
 264   Histogram* JNIHistogram;
 265   static volatile int JNIHistogram_lock = 0;
 266 
 267   class JNIHistogramElement : public HistogramElement {
 268     public:
 269      JNIHistogramElement(const char* name);
 270   };
 271 
 272   JNIHistogramElement::JNIHistogramElement(const char* elementName) {
 273     _name = elementName;
 274     uintx count = 0;
 275 
 276     while (Atomic::cmpxchg(1, &JNIHistogram_lock, 0) != 0) {
 277       while (Atomic::load_acquire(&JNIHistogram_lock) != 0) {
 278         count +=1;
 279         if ( (WarnOnStalledSpinLock > 0)
 280           && (count % WarnOnStalledSpinLock == 0)) {
 281           warning("JNIHistogram_lock seems to be stalled");
 282         }
 283       }
 284      }
 285 
 286 
 287     if(JNIHistogram == NULL)
 288       JNIHistogram = new Histogram("JNI Call Counts",100);
 289 
 290     JNIHistogram->add_element(this);
 291     Atomic::dec(&JNIHistogram_lock);
 292   }
 293 
 294   #define JNICountWrapper(arg)                                     \
 295      static JNIHistogramElement* e = new JNIHistogramElement(arg); \
 296       /* There is a MT-race condition in VC++. So we need to make sure that that e has been initialized */ \
 297      if (e != NULL) e->increment_count()


3899     // to continue.
3900     if (Universe::is_fully_initialized()) {
3901       // otherwise no pending exception possible - VM will already have aborted
3902       JavaThread* THREAD = JavaThread::current();
3903       if (HAS_PENDING_EXCEPTION) {
3904         HandleMark hm;
3905         vm_exit_during_initialization(Handle(THREAD, PENDING_EXCEPTION));
3906       }
3907     }
3908 
3909     if (can_try_again) {
3910       // reset safe_to_recreate_vm to 1 so that retrial would be possible
3911       safe_to_recreate_vm = 1;
3912     }
3913 
3914     // Creation failed. We must reset vm_created
3915     *vm = 0;
3916     *(JNIEnv**)penv = 0;
3917     // reset vm_created last to avoid race condition. Use OrderAccess to
3918     // control both compiler and architectural-based reordering.
3919     Atomic::release_store(&vm_created, 0);
3920   }
3921 
3922   // Flush stdout and stderr before exit.
3923   fflush(stdout);
3924   fflush(stderr);
3925 
3926   return result;
3927 
3928 }
3929 
3930 _JNI_IMPORT_OR_EXPORT_ jint JNICALL JNI_CreateJavaVM(JavaVM **vm, void **penv, void *args) {
3931   jint result = JNI_ERR;
3932   // On Windows, let CreateJavaVM run with SEH protection
3933 #ifdef _WIN32
3934   __try {
3935 #endif
3936     result = JNI_CreateJavaVM_inner(vm, penv, args);
3937 #ifdef _WIN32
3938   } __except(topLevelExceptionFilter((_EXCEPTION_POINTERS*)_exception_info())) {
3939     // Nothing to do.


< prev index next >