Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Niefer2009-09-01 16:02:38 +0000
committerAndrew Niefer2009-09-01 16:02:38 +0000
commit23ffb49b4a8418c17219662da0774952eb18a2ef (patch)
tree279cfcd35278f803ca6e76f94fe115d100302662 /bundles/org.eclipse.equinox.executable/library/eclipseJNI.c
parent1119fba6c9d641130b98231b8393b33f1e9c8948 (diff)
downloadrt.equinox.framework-23ffb49b4a8418c17219662da0774952eb18a2ef.tar.gz
rt.equinox.framework-23ffb49b4a8418c17219662da0774952eb18a2ef.tar.xz
rt.equinox.framework-23ffb49b4a8418c17219662da0774952eb18a2ef.zip
bug 282917 - caching java.lang.String JNI class
Diffstat (limited to 'bundles/org.eclipse.equinox.executable/library/eclipseJNI.c')
-rw-r--r--bundles/org.eclipse.equinox.executable/library/eclipseJNI.c39
1 files changed, 25 insertions, 14 deletions
diff --git a/bundles/org.eclipse.equinox.executable/library/eclipseJNI.c b/bundles/org.eclipse.equinox.executable/library/eclipseJNI.c
index f3c83924b..ae6d6cae7 100644
--- a/bundles/org.eclipse.equinox.executable/library/eclipseJNI.c
+++ b/bundles/org.eclipse.equinox.executable/library/eclipseJNI.c
@@ -44,6 +44,13 @@ void setExitData(JNIEnv *env, jstring id, jstring s);
static JavaVM * jvm = 0;
static JNIEnv *env = 0;
+/* cache String class and methods to avoid looking them up all the time */
+static jclass string_class = NULL;
+#if !defined(UNICODE) && !defined(MACOSX)
+static jmethodID string_getBytesMethod = NULL;
+static jmethodID string_ctor = NULL;
+#endif
+
/* JNI Methods
* we only want one version of the JNI functions
* Because there are potentially ANSI and UNICODE versions of everything, we need to be
@@ -187,11 +194,13 @@ static const _TCHAR * JNI_GetStringChars(JNIEnv *env, jstring str) {
#else
/* Other platforms, use java's default encoding */
_TCHAR* buffer = NULL;
- jclass stringClass = (*env)->FindClass(env, "java/lang/String");
- if (stringClass != NULL) {
- jmethodID getBytesMethod = (*env)->GetMethodID(env, stringClass, "getBytes", "()[B");
- if (getBytesMethod != NULL) {
- jbyteArray bytes = (*env)->CallObjectMethod(env, str, getBytesMethod);
+ if (string_class == NULL)
+ string_class = (*env)->FindClass(env, "java/lang/String");
+ if (string_class != NULL) {
+ if (string_getBytesMethod == NULL)
+ string_getBytesMethod = (*env)->GetMethodID(env, string_class, "getBytes", "()[B");
+ if (string_getBytesMethod != NULL) {
+ jbyteArray bytes = (*env)->CallObjectMethod(env, str, string_getBytesMethod);
if (!(*env)->ExceptionOccurred(env)) {
jsize length = (*env)->GetArrayLength(env, bytes);
buffer = malloc( (length + 1) * sizeof(_TCHAR*));
@@ -235,11 +244,13 @@ static jstring newJavaString(JNIEnv *env, _TCHAR * str)
if(bytes != NULL) {
(*env)->SetByteArrayRegion(env, bytes, 0, length, str);
if (!(*env)->ExceptionOccurred(env)) {
- jclass stringClass = (*env)->FindClass(env, "java/lang/String");
- if(stringClass != NULL) {
- jmethodID ctor = (*env)->GetMethodID(env, stringClass, "<init>", "([B)V");
- if(ctor != NULL) {
- newString = (*env)->NewObject(env, stringClass, ctor, bytes);
+ if (string_class == NULL)
+ string_class = (*env)->FindClass(env, "java/lang/String");
+ if(string_class != NULL) {
+ if (string_ctor == NULL)
+ string_ctor = (*env)->GetMethodID(env, string_class, "<init>", "([B)V");
+ if(string_ctor != NULL) {
+ newString = (*env)->NewObject(env, string_class, string_ctor, bytes);
}
}
}
@@ -255,16 +266,16 @@ static jstring newJavaString(JNIEnv *env, _TCHAR * str)
static jobjectArray createRunArgs( JNIEnv *env, _TCHAR * args[] ) {
int index = 0, length = -1;
- jclass stringClass;
jobjectArray stringArray = NULL;
jstring string;
/*count the number of elements first*/
while(args[++length] != NULL);
- stringClass = (*env)->FindClass(env, "java/lang/String");
- if(stringClass != NULL) {
- stringArray = (*env)->NewObjectArray(env, length, stringClass, 0);
+ if (string_class == NULL)
+ string_class = (*env)->FindClass(env, "java/lang/String");
+ if(string_class != NULL) {
+ stringArray = (*env)->NewObjectArray(env, length, string_class, 0);
if(stringArray != NULL) {
for( index = 0; index < length; index++) {
string = newJavaString(env, args[index]);

Back to the top