< prev index next >

src/java.desktop/windows/native/libawt/windows/awt_new.cpp

Print this page




 155     }
 156 }
 157 
 158 
 159 // This function is called instead of ExceptionOccurred. It throws
 160 // std::bad_alloc if a java.lang.OutOfMemoryError is currently pending
 161 // on the calling thread.
 162 jthrowable
 163 safe_ExceptionOccurred(JNIEnv *env) throw (std::bad_alloc) {
 164     jthrowable xcp = env->ExceptionOccurred();
 165     if (xcp != NULL) {
 166         env->ExceptionClear(); // if we don't do this, isInstanceOf will fail
 167         jint isOutofmem = JNU_IsInstanceOfByName(env, xcp, "java/lang/OutOfMemoryError");
 168         if (isOutofmem > 0) {
 169             env->DeleteLocalRef(xcp);
 170             throw std::bad_alloc();
 171         } else {
 172             env->ExceptionClear();
 173             // rethrow exception
 174             env->Throw(xcp);



 175             return xcp;
 176         }
 177     }
 178 
 179     return NULL;
 180 }
 181 
 182 #ifdef OUTOFMEM_TEST
 183 
 184 #include <time.h>
 185 #include <limits.h>
 186 
 187 static void
 188 rand_alloc_fail(const char *file, int line) throw (std::bad_alloc)
 189 {
 190     if (alloc_lock == NULL) { // Not yet initialized
 191         return;
 192     }
 193 
 194     CriticalSection::Lock l(*alloc_lock);




 155     }
 156 }
 157 
 158 
 159 // This function is called instead of ExceptionOccurred. It throws
 160 // std::bad_alloc if a java.lang.OutOfMemoryError is currently pending
 161 // on the calling thread.
 162 jthrowable
 163 safe_ExceptionOccurred(JNIEnv *env) throw (std::bad_alloc) {
 164     jthrowable xcp = env->ExceptionOccurred();
 165     if (xcp != NULL) {
 166         env->ExceptionClear(); // if we don't do this, isInstanceOf will fail
 167         jint isOutofmem = JNU_IsInstanceOfByName(env, xcp, "java/lang/OutOfMemoryError");
 168         if (isOutofmem > 0) {
 169             env->DeleteLocalRef(xcp);
 170             throw std::bad_alloc();
 171         } else {
 172             env->ExceptionClear();
 173             // rethrow exception
 174             env->Throw(xcp);
 175             // temp solution to reveal all concurrency issues in jtreg and JCK
 176             // we will switch it back to silent mode before the release
 177             env->ExceptionDescribe();
 178             return xcp;
 179         }
 180     }
 181 
 182     return NULL;
 183 }
 184 
 185 #ifdef OUTOFMEM_TEST
 186 
 187 #include <time.h>
 188 #include <limits.h>
 189 
 190 static void
 191 rand_alloc_fail(const char *file, int line) throw (std::bad_alloc)
 192 {
 193     if (alloc_lock == NULL) { // Not yet initialized
 194         return;
 195     }
 196 
 197     CriticalSection::Lock l(*alloc_lock);


< prev index next >