From 30db38ebd6ec4cea831d7ffcbbae540b17eb314a Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Wed, 16 Dec 2009 19:25:03 -0700 Subject: [PATCH] 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. --- classpath/java-io.cpp | 8 ++++---- classpath/java-lang.cpp | 14 +++++++------- classpath/java-nio.cpp | 8 ++++---- readme.txt | 22 ++++++++++------------ src/main.cpp | 10 +++++----- 5 files changed, 30 insertions(+), 32 deletions(-) diff --git a/classpath/java-io.cpp b/classpath/java-io.cpp index f83e39ff47..e639bf9963 100644 --- a/classpath/java-io.cpp +++ b/classpath/java-io.cpp @@ -170,7 +170,7 @@ map(JNIEnv* e, const char* path) void* data = MapViewOfFile(mapping, FILE_MAP_READ, 0, 0, 0); if (data) { void* p = allocate(e, sizeof(Mapping)); - if (not e->ExceptionOccurred()) { + if (not e->ExceptionCheck()) { result = new (p) Mapping(static_cast(data), size, file, mapping); } @@ -186,7 +186,7 @@ map(JNIEnv* e, const char* path) CloseHandle(file); } } - if (result == 0 and not e->ExceptionOccurred()) { + if (result == 0 and not e->ExceptionCheck()) { throwNew(e, "java/io/IOException", "%d", GetLastError()); } 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); if (data) { void* p = allocate(e, sizeof(Mapping)); - if (not e->ExceptionOccurred()) { + if (not e->ExceptionCheck()) { result = new (p) Mapping(static_cast(data), s.st_size); } } } close(fd); } - if (result == 0 and not e->ExceptionOccurred()) { + if (result == 0 and not e->ExceptionCheck()) { throwNewErrno(e, "java/io/IOException"); } return result; diff --git a/classpath/java-lang.cpp b/classpath/java-lang.cpp index 8fdced256c..8303e3e4e1 100644 --- a/classpath/java-lang.cpp +++ b/classpath/java-lang.cpp @@ -167,17 +167,17 @@ Java_java_lang_Runtime_exec(JNIEnv* e, jclass, makePipe(e, in); SetHandleInformation(in[0], HANDLE_FLAG_INHERIT, 0); jlong inDescriptor = static_cast(descriptor(e, in[0])); - if(e->ExceptionOccurred()) return; + if(e->ExceptionCheck()) return; e->SetLongArrayRegion(process, 1, 1, &inDescriptor); makePipe(e, out); SetHandleInformation(out[1], HANDLE_FLAG_INHERIT, 0); jlong outDescriptor = static_cast(descriptor(e, out[1])); - if(e->ExceptionOccurred()) return; + if(e->ExceptionCheck()) return; e->SetLongArrayRegion(process, 2, 1, &outDescriptor); makePipe(e, err); SetHandleInformation(err[0], HANDLE_FLAG_INHERIT, 0); jlong errDescriptor = static_cast(descriptor(e, err[0])); - if(e->ExceptionOccurred()) return; + if(e->ExceptionCheck()) return; e->SetLongArrayRegion(process, 3, 1, &errDescriptor); PROCESS_INFORMATION pi; @@ -249,19 +249,19 @@ Java_java_lang_Runtime_exec(JNIEnv* e, jclass, int msg[] = { -1, -1 }; makePipe(e, in); - if(e->ExceptionOccurred()) return; + if(e->ExceptionCheck()) return; jlong inDescriptor = static_cast(in[0]); e->SetLongArrayRegion(process, 1, 1, &inDescriptor); makePipe(e, out); - if(e->ExceptionOccurred()) return; + if(e->ExceptionCheck()) return; jlong outDescriptor = static_cast(out[1]); e->SetLongArrayRegion(process, 1, 1, &outDescriptor); makePipe(e, err); - if(e->ExceptionOccurred()) return; + if(e->ExceptionCheck()) return; jlong errDescriptor = static_cast(err[0]); e->SetLongArrayRegion(process, 1, 1, &errDescriptor); makePipe(e, msg); - if(e->ExceptionOccurred()) return; + if(e->ExceptionCheck()) return; if(fcntl(msg[1], F_SETFD, FD_CLOEXEC) != 0) { throwNewErrno(e, "java/io/IOException"); return; diff --git a/classpath/java-nio.cpp b/classpath/java-nio.cpp index 4b63139432..f11e40ca0d 100644 --- a/classpath/java-nio.cpp +++ b/classpath/java-nio.cpp @@ -332,11 +332,11 @@ Java_java_nio_channels_ServerSocketChannel_natDoListen(JNIEnv *e, { int s = makeSocket(e); if (s < 0) return s; - if (e->ExceptionOccurred()) return 0; + if (e->ExceptionCheck()) return 0; sockaddr_in address; init(e, &address, host, port); - if (e->ExceptionOccurred()) return 0; + if (e->ExceptionCheck()) return 0; ::doListen(e, s, &address); return s; @@ -369,13 +369,13 @@ Java_java_nio_channels_SocketChannel_natDoConnect(JNIEnv *e, jbooleanArray retVal) { int s = makeSocket(e); - if (e->ExceptionOccurred()) return 0; + if (e->ExceptionCheck()) return 0; setBlocking(e, s, blocking); sockaddr_in address; init(e, &address, host, port); - if (e->ExceptionOccurred()) return 0; + if (e->ExceptionCheck()) return 0; jboolean connected = ::doConnect(e, s, &address); e->SetBooleanArrayRegion(retVal, 0, 1, &connected); diff --git a/readme.txt b/readme.txt index 4bb7a0f79c..2d4fd83c7e 100644 --- a/readme.txt +++ b/readme.txt @@ -12,14 +12,12 @@ on Mac OS X: $ build/darwin-i386/avian -cp build/test Hello on Windows (MSYS): - $ git clone git://oss.readytalk.com/win32.git ../win32 $ export JAVA_HOME="C:/Program Files/Java/jdk1.6.0_07" $ make $ build/windows-i386/avian -cp build/test Hello on Windows (Cygwin): - $ git clone git://oss.readytalk.com/win32.git ../win32 $ export JAVA_HOME="/cygdrive/c/Program Files/Java/jdk1.6.0_07" $ make @@ -308,13 +306,13 @@ main(int ac, const char** av) JNIEnv* e = static_cast(env); jclass c = e->FindClass("Hello"); - if (not e->ExceptionOccurred()) { + if (not e->ExceptionCheck()) { 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"); - if (not e->ExceptionOccurred()) { + if (not e->ExceptionCheck()) { jobjectArray a = e->NewObjectArray(ac-1, stringClass, 0); - if (not e->ExceptionOccurred()) { + if (not e->ExceptionCheck()) { for (int i = 1; i < ac; ++i) { e->SetObjectArrayElement(a, i-1, e->NewStringUTF(av[i])); } @@ -326,7 +324,7 @@ main(int ac, const char** av) } int exitCode = 0; - if (e->ExceptionOccurred()) { + if (e->ExceptionCheck()) { exitCode = -1; e->ExceptionDescribe(); } @@ -510,13 +508,13 @@ main(int ac, const char** av) JNIEnv* e = static_cast(env); jclass c = e->FindClass("Hello"); - if (not e->ExceptionOccurred()) { + if (not e->ExceptionCheck()) { 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"); - if (not e->ExceptionOccurred()) { + if (not e->ExceptionCheck()) { jobjectArray a = e->NewObjectArray(ac-1, stringClass, 0); - if (not e->ExceptionOccurred()) { + if (not e->ExceptionCheck()) { for (int i = 1; i < ac; ++i) { e->SetObjectArrayElement(a, i-1, e->NewStringUTF(av[i])); } @@ -528,7 +526,7 @@ main(int ac, const char** av) } int exitCode = 0; - if (e->ExceptionOccurred()) { + if (e->ExceptionCheck()) { exitCode = -1; e->ExceptionDescribe(); } diff --git a/src/main.cpp b/src/main.cpp index eb472374db..383e324a3c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -178,13 +178,13 @@ main(int ac, const char** av) JNIEnv* e = static_cast(env); jclass c = e->FindClass(class_); - if (not e->ExceptionOccurred()) { + if (not e->ExceptionCheck()) { 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"); - if (not e->ExceptionOccurred()) { + if (not e->ExceptionCheck()) { jobjectArray a = e->NewObjectArray(argc, stringClass, 0); - if (not e->ExceptionOccurred()) { + if (not e->ExceptionCheck()) { for (int i = 0; i < argc; ++i) { e->SetObjectArrayElement(a, i, e->NewStringUTF(argv[i])); } @@ -196,7 +196,7 @@ main(int ac, const char** av) } int exitCode = 0; - if (e->ExceptionOccurred()) { + if (e->ExceptionCheck()) { exitCode = -1; e->ExceptionDescribe(); }