[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.15-1-40151-g37bb677

rjw rjw at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 08:22:27 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit 474464427c4ca96a66ff2aa1e4feb32242b0b4c2
Author: rjw <rjw at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Fri Jan 16 01:58:05 2004 +0000

    	Fixed 3530401.  JNI doesn't cleanup local refs created on the
    	main thread.   IMO this is a bad bug in our JMI implementation.
    
    	To work-around the problem I explicitly delete all local refs.
    	Further, I've added Push/PopLocalFrame calls to catch any refs
    	that I may have missed.  This will guarantee that we don't leak
    	any Java references.
    
            Reviewed by John.
    
            * bindings/jni/jni_class.cpp:
            (JavaClass::_commonInit):
            (JavaClass::JavaClass):
            * bindings/jni/jni_instance.cpp:
            (JavaInstance::begin):
            (JavaInstance::end):
            * bindings/jni/jni_instance.h:
            * bindings/jni/jni_runtime.cpp:
            (JavaConstructor::JavaConstructor):
            (JavaMethod::JavaMethod):
            * bindings/jni_jsobject.cpp:
            (JSObject::listFromJArray):
            * bindings/runtime.h:
            (KJS::Bindings::Instance::begin):
            (KJS::Bindings::Instance::end):
            * bindings/runtime_object.cpp:
            (RuntimeObjectImp::get):
            (RuntimeObjectImp::put):
            (RuntimeObjectImp::canPut):
            (RuntimeObjectImp::hasProperty):
            (RuntimeObjectImp::defaultValue):
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@5917 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/JavaScriptCore/ChangeLog b/JavaScriptCore/ChangeLog
index 3fa1868..6974e08 100644
--- a/JavaScriptCore/ChangeLog
+++ b/JavaScriptCore/ChangeLog
@@ -1,3 +1,37 @@
+2004-01-15  Richard Williamson   <rjw at apple.com>
+
+	Fixed 3530401.  JNI doesn't cleanup local refs created on the
+	main thread.   IMO this is a bad bug in our JMI implementation.
+
+	To work-around the problem I explicitly delete all local refs.
+	Further, I've added Push/PopLocalFrame calls to catch any refs
+	that I may have missed.  This will guarantee that we don't leak
+	any Java references.
+
+        Reviewed by John.
+
+        * bindings/jni/jni_class.cpp:
+        (JavaClass::_commonInit):
+        (JavaClass::JavaClass):
+        * bindings/jni/jni_instance.cpp:
+        (JavaInstance::begin):
+        (JavaInstance::end):
+        * bindings/jni/jni_instance.h:
+        * bindings/jni/jni_runtime.cpp:
+        (JavaConstructor::JavaConstructor):
+        (JavaMethod::JavaMethod):
+        * bindings/jni_jsobject.cpp:
+        (JSObject::listFromJArray):
+        * bindings/runtime.h:
+        (KJS::Bindings::Instance::begin):
+        (KJS::Bindings::Instance::end):
+        * bindings/runtime_object.cpp:
+        (RuntimeObjectImp::get):
+        (RuntimeObjectImp::put):
+        (RuntimeObjectImp::canPut):
+        (RuntimeObjectImp::hasProperty):
+        (RuntimeObjectImp::defaultValue):
+
 2004-01-15  Vicki Murley  <vicki at apple.com>
 
         Reviewed by Darin.
diff --git a/JavaScriptCore/bindings/jni/jni_class.cpp b/JavaScriptCore/bindings/jni/jni_class.cpp
index 3b31771..0185d4f 100644
--- a/JavaScriptCore/bindings/jni/jni_class.cpp
+++ b/JavaScriptCore/bindings/jni/jni_class.cpp
@@ -45,6 +45,7 @@ void JavaClass::_commonInit (jobject aClass)
         CFStringRef fieldName = CFStringCreateWithCString(NULL, aField->name(), kCFStringEncodingASCII);
         CFDictionaryAddValue ((CFMutableDictionaryRef)_fields, fieldName, aField);
         CFRelease (fieldName);
+        env->DeleteLocalRef (aJField);
     }
     
     // Get the methods
@@ -57,6 +58,7 @@ void JavaClass::_commonInit (jobject aClass)
         CFStringRef methodName = CFStringCreateWithCString(NULL, aMethod->name(), kCFStringEncodingASCII);
         CFDictionaryAddValue ((CFMutableDictionaryRef)_methods, methodName, aMethod);
         CFRelease (methodName);
+        env->DeleteLocalRef (aJMethod);
     }
 
     // Get the constructors
@@ -66,6 +68,7 @@ void JavaClass::_commonInit (jobject aClass)
     for (i = 0; i < _numConstructors; i++) {
         jobject aConstructor = env->GetObjectArrayElement ((jobjectArray)constructors, i);
         _constructors[i] = JavaConstructor (env, aConstructor);
+        env->DeleteLocalRef (aConstructor);
     }
 }
 
@@ -83,6 +86,8 @@ JavaClass::JavaClass (const char *className)
     }
 
     _commonInit (aClass);
+
+    env->DeleteLocalRef (aClass);
 }
 
 JavaClass::JavaClass (jobject aClass)
diff --git a/JavaScriptCore/bindings/jni/jni_instance.cpp b/JavaScriptCore/bindings/jni/jni_instance.cpp
index 7f7ef58..f15fb08 100644
--- a/JavaScriptCore/bindings/jni/jni_instance.cpp
+++ b/JavaScriptCore/bindings/jni/jni_instance.cpp
@@ -60,6 +60,18 @@ JavaInstance::JavaInstance (const JavaInstance &other) : Instance()
     _class = other._class;
 };
 
+#define NUM_LOCAL_REFS 64
+
+void JavaInstance::begin()
+{
+    getJNIEnv()->PushLocalFrame (NUM_LOCAL_REFS);
+}
+
+void JavaInstance::end()
+{
+    getJNIEnv()->PopLocalFrame (NULL);
+}
+
 Class *JavaInstance::getClass() const 
 {
     if (_class == 0)
diff --git a/JavaScriptCore/bindings/jni/jni_instance.h b/JavaScriptCore/bindings/jni/jni_instance.h
index c6edfff..d08e294 100644
--- a/JavaScriptCore/bindings/jni/jni_instance.h
+++ b/JavaScriptCore/bindings/jni/jni_instance.h
@@ -87,6 +87,9 @@ public:
         return *this;
     };
 
+    virtual void begin();
+    virtual void end();
+    
     virtual KJS::Value valueOf() const;
     virtual KJS::Value defaultValue (KJS::Type hint) const;
 
diff --git a/JavaScriptCore/bindings/jni/jni_runtime.cpp b/JavaScriptCore/bindings/jni/jni_runtime.cpp
index 733bcb0..babdbce 100644
--- a/JavaScriptCore/bindings/jni/jni_runtime.cpp
+++ b/JavaScriptCore/bindings/jni/jni_runtime.cpp
@@ -183,6 +183,8 @@ JavaConstructor::JavaConstructor (JNIEnv *env, jobject aConstructor)
         jobject aParameter = env->GetObjectArrayElement ((jobjectArray)jparameters, i);
         jstring parameterName = (jstring)callJNIObjectMethod (aParameter, "getName", "()Ljava/lang/String;");
         _parameters[i] = JavaParameter(env, parameterName);
+        env->DeleteLocalRef (aParameter);
+        env->DeleteLocalRef (parameterName);
     }
 }
 
@@ -193,10 +195,13 @@ JavaMethod::JavaMethod (JNIEnv *env, jobject aMethod)
     jstring returnTypeName = (jstring)callJNIObjectMethod (returnType, "getName", "()Ljava/lang/String;");
     _returnType =JavaString (env, returnTypeName);
     _JNIReturnType = JNITypeFromClassName (_returnType.UTF8String());
+    env->DeleteLocalRef (returnType);
+    env->DeleteLocalRef (returnTypeName);
 
     // Get method name
     jstring methodName = (jstring)callJNIObjectMethod (aMethod, "getName", "()Ljava/lang/String;");
     _name = JavaString (env, methodName);
+    env->DeleteLocalRef (methodName);
 
     // Get parameters
     jarray jparameters = (jarray)callJNIObjectMethod (aMethod, "getParameterTypes", "()[Ljava/lang/Class;");
@@ -208,7 +213,10 @@ JavaMethod::JavaMethod (JNIEnv *env, jobject aMethod)
         jobject aParameter = env->GetObjectArrayElement ((jobjectArray)jparameters, i);
         jstring parameterName = (jstring)callJNIObjectMethod (aParameter, "getName", "()Ljava/lang/String;");
         _parameters[i] = JavaParameter(env, parameterName);
+        env->DeleteLocalRef (aParameter);
+        env->DeleteLocalRef (parameterName);
     }
+    env->DeleteLocalRef (jparameters);
 
     // Created lazily.
     _signature = 0;
diff --git a/JavaScriptCore/bindings/jni_jsobject.cpp b/JavaScriptCore/bindings/jni_jsobject.cpp
index b23c385..200a6f0 100644
--- a/JavaScriptCore/bindings/jni_jsobject.cpp
+++ b/JavaScriptCore/bindings/jni_jsobject.cpp
@@ -691,6 +691,7 @@ KJS::List JSObject::listFromJArray(jobjectArray jArray) const
     for (i = 0; i < numObjects; i++) {
         jobject anObject = env->GetObjectArrayElement ((jobjectArray)jArray, i);
         aList.append (convertJObjectToValue(anObject));
+        env->DeleteLocalRef (anObject);
     }
     return aList;
 }
diff --git a/JavaScriptCore/bindings/runtime.h b/JavaScriptCore/bindings/runtime.h
index f4dfa34..afabd46 100644
--- a/JavaScriptCore/bindings/runtime.h
+++ b/JavaScriptCore/bindings/runtime.h
@@ -107,6 +107,12 @@ public:
 
     static Instance *createBindingForLanguageInstance (BindingLanguage language, void *instance);
 
+    // These functions are called before and after the main entry points into
+    // the native implementations.  They can be used to establish and cleanup
+    // any needed state.
+    virtual void begin() {};
+    virtual void end() {};
+    
     virtual Class *getClass() const = 0;
     
     virtual KJS::Value getValueOfField (const Field *aField) const;
diff --git a/JavaScriptCore/bindings/runtime_object.cpp b/JavaScriptCore/bindings/runtime_object.cpp
index 1513626..bacca7f 100644
--- a/JavaScriptCore/bindings/runtime_object.cpp
+++ b/JavaScriptCore/bindings/runtime_object.cpp
@@ -62,6 +62,8 @@ RuntimeObjectImp::RuntimeObjectImp(Bindings::Instance *i, bool oi) : ObjectImp (
 
 Value RuntimeObjectImp::get(ExecState *exec, const Identifier &propertyName) const
 {
+    instance->begin();
+    
     // See if the instance have a field with the specified name.
     Field *aField = instance->getClass()->fieldNamed(propertyName.ascii());
     if (aField) {
@@ -72,36 +74,55 @@ Value RuntimeObjectImp::get(ExecState *exec, const Identifier &propertyName) con
     // that method.
     Method *aMethod = instance->getClass()->methodNamed(propertyName.ascii());
     if (aMethod) {
+        instance->end();
         return Object (new RuntimeMethodImp(exec, propertyName, aMethod));
     }
     
+    instance->end();
+    
     return Undefined();
 }
 
 void RuntimeObjectImp::put(ExecState *exec, const Identifier &propertyName,
                     const Value &value, int attr)
 {
+    instance->begin();
+
     // Set the value of the property.
     Field *aField = instance->getClass()->fieldNamed(propertyName.ascii());
     if (aField) {
         getInternalInstance()->setValueOfField(exec, aField, value);
     }
+
+    instance->end();
 }
 
 bool RuntimeObjectImp::canPut(ExecState *exec, const Identifier &propertyName) const
 {
+    instance->begin();
+
     Field *aField = instance->getClass()->fieldNamed(propertyName.ascii());
+
+    instance->end();
+
     return aField ? true : false;
 }
 
 bool RuntimeObjectImp::hasProperty(ExecState *exec,
                             const Identifier &propertyName) const
 {
+    instance->begin();
+
     Field *aField = instance->getClass()->fieldNamed(propertyName.ascii());
-    if (aField)
+    if (aField) {
+        instance->end();
         return true;
+    }
         
     Method *aMethod = instance->getClass()->methodNamed(propertyName.ascii());
+
+    instance->end();
+
     if (aMethod)
         return true;
         
@@ -117,7 +138,13 @@ bool RuntimeObjectImp::deleteProperty(ExecState *exec,
 
 Value RuntimeObjectImp::defaultValue(ExecState *exec, Type hint) const
 {
-    return getInternalInstance()->defaultValue(hint);
+    instance->begin();
+
+    Value aValue = getInternalInstance()->defaultValue(hint);
+    
+    instance->end();
+    
+    return aValue;
 }
     
 void RuntimeObjectImp::_initializeClassInfoFromInstance()

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list