replace calls to ExceptionOccurred with calls to ExceptionCheck

The latter is cheaper (avoids a state transition and possible memory
allocation) when we just want to know if an exception is thrown
without needing a handle to that exception.
This commit is contained in:
Joel Dice 2009-12-16 19:25:03 -07:00
parent 4c0ede8b9a
commit 30db38ebd6
5 changed files with 30 additions and 32 deletions

View File

@ -170,7 +170,7 @@ map(JNIEnv* e, const char* path)
void* data = MapViewOfFile(mapping, FILE_MAP_READ, 0, 0, 0); void* data = MapViewOfFile(mapping, FILE_MAP_READ, 0, 0, 0);
if (data) { if (data) {
void* p = allocate(e, sizeof(Mapping)); void* p = allocate(e, sizeof(Mapping));
if (not e->ExceptionOccurred()) { if (not e->ExceptionCheck()) {
result = new (p) result = new (p)
Mapping(static_cast<uint8_t*>(data), size, file, mapping); Mapping(static_cast<uint8_t*>(data), size, file, mapping);
} }
@ -186,7 +186,7 @@ map(JNIEnv* e, const char* path)
CloseHandle(file); CloseHandle(file);
} }
} }
if (result == 0 and not e->ExceptionOccurred()) { if (result == 0 and not e->ExceptionCheck()) {
throwNew(e, "java/io/IOException", "%d", GetLastError()); throwNew(e, "java/io/IOException", "%d", GetLastError());
} }
return result; return result;
@ -256,14 +256,14 @@ map(JNIEnv* e, const char* path)
void* data = mmap(0, s.st_size, PROT_READ, MAP_PRIVATE, fd, 0); void* data = mmap(0, s.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
if (data) { if (data) {
void* p = allocate(e, sizeof(Mapping)); void* p = allocate(e, sizeof(Mapping));
if (not e->ExceptionOccurred()) { if (not e->ExceptionCheck()) {
result = new (p) Mapping(static_cast<uint8_t*>(data), s.st_size); result = new (p) Mapping(static_cast<uint8_t*>(data), s.st_size);
} }
} }
} }
close(fd); close(fd);
} }
if (result == 0 and not e->ExceptionOccurred()) { if (result == 0 and not e->ExceptionCheck()) {
throwNewErrno(e, "java/io/IOException"); throwNewErrno(e, "java/io/IOException");
} }
return result; return result;

View File

@ -167,17 +167,17 @@ Java_java_lang_Runtime_exec(JNIEnv* e, jclass,
makePipe(e, in); makePipe(e, in);
SetHandleInformation(in[0], HANDLE_FLAG_INHERIT, 0); SetHandleInformation(in[0], HANDLE_FLAG_INHERIT, 0);
jlong inDescriptor = static_cast<jlong>(descriptor(e, in[0])); jlong inDescriptor = static_cast<jlong>(descriptor(e, in[0]));
if(e->ExceptionOccurred()) return; if(e->ExceptionCheck()) return;
e->SetLongArrayRegion(process, 1, 1, &inDescriptor); e->SetLongArrayRegion(process, 1, 1, &inDescriptor);
makePipe(e, out); makePipe(e, out);
SetHandleInformation(out[1], HANDLE_FLAG_INHERIT, 0); SetHandleInformation(out[1], HANDLE_FLAG_INHERIT, 0);
jlong outDescriptor = static_cast<jlong>(descriptor(e, out[1])); jlong outDescriptor = static_cast<jlong>(descriptor(e, out[1]));
if(e->ExceptionOccurred()) return; if(e->ExceptionCheck()) return;
e->SetLongArrayRegion(process, 2, 1, &outDescriptor); e->SetLongArrayRegion(process, 2, 1, &outDescriptor);
makePipe(e, err); makePipe(e, err);
SetHandleInformation(err[0], HANDLE_FLAG_INHERIT, 0); SetHandleInformation(err[0], HANDLE_FLAG_INHERIT, 0);
jlong errDescriptor = static_cast<jlong>(descriptor(e, err[0])); jlong errDescriptor = static_cast<jlong>(descriptor(e, err[0]));
if(e->ExceptionOccurred()) return; if(e->ExceptionCheck()) return;
e->SetLongArrayRegion(process, 3, 1, &errDescriptor); e->SetLongArrayRegion(process, 3, 1, &errDescriptor);
PROCESS_INFORMATION pi; PROCESS_INFORMATION pi;
@ -249,19 +249,19 @@ Java_java_lang_Runtime_exec(JNIEnv* e, jclass,
int msg[] = { -1, -1 }; int msg[] = { -1, -1 };
makePipe(e, in); makePipe(e, in);
if(e->ExceptionOccurred()) return; if(e->ExceptionCheck()) return;
jlong inDescriptor = static_cast<jlong>(in[0]); jlong inDescriptor = static_cast<jlong>(in[0]);
e->SetLongArrayRegion(process, 1, 1, &inDescriptor); e->SetLongArrayRegion(process, 1, 1, &inDescriptor);
makePipe(e, out); makePipe(e, out);
if(e->ExceptionOccurred()) return; if(e->ExceptionCheck()) return;
jlong outDescriptor = static_cast<jlong>(out[1]); jlong outDescriptor = static_cast<jlong>(out[1]);
e->SetLongArrayRegion(process, 1, 1, &outDescriptor); e->SetLongArrayRegion(process, 1, 1, &outDescriptor);
makePipe(e, err); makePipe(e, err);
if(e->ExceptionOccurred()) return; if(e->ExceptionCheck()) return;
jlong errDescriptor = static_cast<jlong>(err[0]); jlong errDescriptor = static_cast<jlong>(err[0]);
e->SetLongArrayRegion(process, 1, 1, &errDescriptor); e->SetLongArrayRegion(process, 1, 1, &errDescriptor);
makePipe(e, msg); makePipe(e, msg);
if(e->ExceptionOccurred()) return; if(e->ExceptionCheck()) return;
if(fcntl(msg[1], F_SETFD, FD_CLOEXEC) != 0) { if(fcntl(msg[1], F_SETFD, FD_CLOEXEC) != 0) {
throwNewErrno(e, "java/io/IOException"); throwNewErrno(e, "java/io/IOException");
return; return;

View File

@ -332,11 +332,11 @@ Java_java_nio_channels_ServerSocketChannel_natDoListen(JNIEnv *e,
{ {
int s = makeSocket(e); int s = makeSocket(e);
if (s < 0) return s; if (s < 0) return s;
if (e->ExceptionOccurred()) return 0; if (e->ExceptionCheck()) return 0;
sockaddr_in address; sockaddr_in address;
init(e, &address, host, port); init(e, &address, host, port);
if (e->ExceptionOccurred()) return 0; if (e->ExceptionCheck()) return 0;
::doListen(e, s, &address); ::doListen(e, s, &address);
return s; return s;
@ -369,13 +369,13 @@ Java_java_nio_channels_SocketChannel_natDoConnect(JNIEnv *e,
jbooleanArray retVal) jbooleanArray retVal)
{ {
int s = makeSocket(e); int s = makeSocket(e);
if (e->ExceptionOccurred()) return 0; if (e->ExceptionCheck()) return 0;
setBlocking(e, s, blocking); setBlocking(e, s, blocking);
sockaddr_in address; sockaddr_in address;
init(e, &address, host, port); init(e, &address, host, port);
if (e->ExceptionOccurred()) return 0; if (e->ExceptionCheck()) return 0;
jboolean connected = ::doConnect(e, s, &address); jboolean connected = ::doConnect(e, s, &address);
e->SetBooleanArrayRegion(retVal, 0, 1, &connected); e->SetBooleanArrayRegion(retVal, 0, 1, &connected);

View File

@ -12,14 +12,12 @@ on Mac OS X:
$ build/darwin-i386/avian -cp build/test Hello $ build/darwin-i386/avian -cp build/test Hello
on Windows (MSYS): on Windows (MSYS):
$ git clone git://oss.readytalk.com/win32.git ../win32 $ git clone git://oss.readytalk.com/win32.git ../win32
$ export JAVA_HOME="C:/Program Files/Java/jdk1.6.0_07" $ export JAVA_HOME="C:/Program Files/Java/jdk1.6.0_07"
$ make $ make
$ build/windows-i386/avian -cp build/test Hello $ build/windows-i386/avian -cp build/test Hello
on Windows (Cygwin): on Windows (Cygwin):
$ git clone git://oss.readytalk.com/win32.git ../win32 $ git clone git://oss.readytalk.com/win32.git ../win32
$ export JAVA_HOME="/cygdrive/c/Program Files/Java/jdk1.6.0_07" $ export JAVA_HOME="/cygdrive/c/Program Files/Java/jdk1.6.0_07"
$ make $ make
@ -308,13 +306,13 @@ main(int ac, const char** av)
JNIEnv* e = static_cast<JNIEnv*>(env); JNIEnv* e = static_cast<JNIEnv*>(env);
jclass c = e->FindClass("Hello"); jclass c = e->FindClass("Hello");
if (not e->ExceptionOccurred()) { if (not e->ExceptionCheck()) {
jmethodID m = e->GetStaticMethodID(c, "main", "([Ljava/lang/String;)V"); jmethodID m = e->GetStaticMethodID(c, "main", "([Ljava/lang/String;)V");
if (not e->ExceptionOccurred()) { if (not e->ExceptionCheck()) {
jclass stringClass = e->FindClass("java/lang/String"); jclass stringClass = e->FindClass("java/lang/String");
if (not e->ExceptionOccurred()) { if (not e->ExceptionCheck()) {
jobjectArray a = e->NewObjectArray(ac-1, stringClass, 0); jobjectArray a = e->NewObjectArray(ac-1, stringClass, 0);
if (not e->ExceptionOccurred()) { if (not e->ExceptionCheck()) {
for (int i = 1; i < ac; ++i) { for (int i = 1; i < ac; ++i) {
e->SetObjectArrayElement(a, i-1, e->NewStringUTF(av[i])); e->SetObjectArrayElement(a, i-1, e->NewStringUTF(av[i]));
} }
@ -326,7 +324,7 @@ main(int ac, const char** av)
} }
int exitCode = 0; int exitCode = 0;
if (e->ExceptionOccurred()) { if (e->ExceptionCheck()) {
exitCode = -1; exitCode = -1;
e->ExceptionDescribe(); e->ExceptionDescribe();
} }
@ -510,13 +508,13 @@ main(int ac, const char** av)
JNIEnv* e = static_cast<JNIEnv*>(env); JNIEnv* e = static_cast<JNIEnv*>(env);
jclass c = e->FindClass("Hello"); jclass c = e->FindClass("Hello");
if (not e->ExceptionOccurred()) { if (not e->ExceptionCheck()) {
jmethodID m = e->GetStaticMethodID(c, "main", "([Ljava/lang/String;)V"); jmethodID m = e->GetStaticMethodID(c, "main", "([Ljava/lang/String;)V");
if (not e->ExceptionOccurred()) { if (not e->ExceptionCheck()) {
jclass stringClass = e->FindClass("java/lang/String"); jclass stringClass = e->FindClass("java/lang/String");
if (not e->ExceptionOccurred()) { if (not e->ExceptionCheck()) {
jobjectArray a = e->NewObjectArray(ac-1, stringClass, 0); jobjectArray a = e->NewObjectArray(ac-1, stringClass, 0);
if (not e->ExceptionOccurred()) { if (not e->ExceptionCheck()) {
for (int i = 1; i < ac; ++i) { for (int i = 1; i < ac; ++i) {
e->SetObjectArrayElement(a, i-1, e->NewStringUTF(av[i])); e->SetObjectArrayElement(a, i-1, e->NewStringUTF(av[i]));
} }
@ -528,7 +526,7 @@ main(int ac, const char** av)
} }
int exitCode = 0; int exitCode = 0;
if (e->ExceptionOccurred()) { if (e->ExceptionCheck()) {
exitCode = -1; exitCode = -1;
e->ExceptionDescribe(); e->ExceptionDescribe();
} }

View File

@ -178,13 +178,13 @@ main(int ac, const char** av)
JNIEnv* e = static_cast<JNIEnv*>(env); JNIEnv* e = static_cast<JNIEnv*>(env);
jclass c = e->FindClass(class_); jclass c = e->FindClass(class_);
if (not e->ExceptionOccurred()) { if (not e->ExceptionCheck()) {
jmethodID m = e->GetStaticMethodID(c, "main", "([Ljava/lang/String;)V"); jmethodID m = e->GetStaticMethodID(c, "main", "([Ljava/lang/String;)V");
if (not e->ExceptionOccurred()) { if (not e->ExceptionCheck()) {
jclass stringClass = e->FindClass("java/lang/String"); jclass stringClass = e->FindClass("java/lang/String");
if (not e->ExceptionOccurred()) { if (not e->ExceptionCheck()) {
jobjectArray a = e->NewObjectArray(argc, stringClass, 0); jobjectArray a = e->NewObjectArray(argc, stringClass, 0);
if (not e->ExceptionOccurred()) { if (not e->ExceptionCheck()) {
for (int i = 0; i < argc; ++i) { for (int i = 0; i < argc; ++i) {
e->SetObjectArrayElement(a, i, e->NewStringUTF(argv[i])); e->SetObjectArrayElement(a, i, e->NewStringUTF(argv[i]));
} }
@ -196,7 +196,7 @@ main(int ac, const char** av)
} }
int exitCode = 0; int exitCode = 0;
if (e->ExceptionOccurred()) { if (e->ExceptionCheck()) {
exitCode = -1; exitCode = -1;
e->ExceptionDescribe(); e->ExceptionDescribe();
} }