harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gshiman...@apache.org
Subject svn commit: r598968 - in /harmony/enhanced/drlvm/trunk/vm/vmcore/src/jni: jni.cpp jni_array.cpp
Date Wed, 28 Nov 2007 11:37:40 GMT
Author: gshimansky
Date: Wed Nov 28 03:37:39 2007
New Revision: 598968

URL: http://svn.apache.org/viewvc?rev=598968&view=rev
Log:
Applied patch from HARMONY-5205
[drlvm][jni] implementation of AllocObject and New<PrimitiveType>Array leaks local handles
in case of OOME.


Modified:
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/jni/jni.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/jni/jni_array.cpp

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/jni/jni.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jni/jni.cpp?rev=598968&r1=598967&r2=598968&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/jni/jni.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/jni/jni.cpp Wed Nov 28 03:37:39 2007
@@ -974,19 +974,18 @@
         return NULL;
     }
 
-    tmn_suspend_disable();       //---------------------------------v
-    ObjectHandle new_handle = oh_allocate_local_handle();
+    tmn_suspend_disable();      //---------------------------------v
     ManagedObject *new_obj = (ManagedObject *)class_alloc_new_object(clss);
     if (new_obj == NULL) {
-        tmn_suspend_enable();
+        tmn_suspend_enable();   //---------------------------------^
         return NULL;
     }
+    ObjectHandle new_handle = oh_allocate_local_handle();
     new_handle->object = (ManagedObject *)new_obj;
-    tmn_suspend_enable();        //---------------------------------^
+    tmn_suspend_enable();       //---------------------------------^
 
     return (jobject)new_handle;
 } //AllocObject
-
 
 
 jobject JNICALL NewObject(JNIEnv * jni_env,

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/jni/jni_array.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jni/jni_array.cpp?rev=598968&r1=598967&r2=598968&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/jni/jni_array.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/jni/jni_array.cpp Wed Nov 28 03:37:39 2007
@@ -226,24 +226,16 @@
 
 
 /////////////////////////////////////////////////////////////////////////////
-// begin New<Type>Array functions
+// begin New<PrimitiveType>Array functions
 
-
-
-jbooleanArray JNICALL NewBooleanArray(JNIEnv * jni_env, jsize length)
-{
-    TRACE2("jni", "NewBooleanArray called");
+static jobject NewPrimitiveArray(Class* clss, jsize length) {
     assert(hythread_is_suspend_enabled());
-    
-    Global_Env * vm_env = jni_get_vm_env(jni_env);
     if (exn_raised()) return NULL;
-    
-    Class *clss = vm_env->ArrayOfBoolean_Class;    
+
     unsigned sz = clss->calculate_array_size(length);
     if (sz == 0) return NULL;
 
     tmn_suspend_disable();       //---------------------------------v
-    ObjectHandle h = oh_allocate_local_handle();
     Vector_Handle array = gc_alloc(sz, clss->get_allocation_handle(),
         vm_get_gc_thread_local());
     if(NULL == array)
@@ -258,275 +250,71 @@
     clss->instance_allocated(sz);
 #endif //VM_STATS
 
+    ObjectHandle h = oh_allocate_local_handle();
     h->object = (ManagedObject *)array;
 
     tmn_suspend_enable();        //---------------------------------^
 
-    return (jbooleanArray)h;
-} //NewBooleanArray
+    return (jobject)h;
+}
 
 
+jbooleanArray JNICALL NewBooleanArray(JNIEnv * jni_env, jsize length)
+{
+    TRACE2("jni", "NewBooleanArray called");
+    return (jbooleanArray)NewPrimitiveArray(jni_get_vm_env(jni_env)->ArrayOfBoolean_Class,
length);
+} //NewBooleanArray
+
 
 jbyteArray JNICALL NewByteArray(JNIEnv * jni_env, jsize length)
 {
     TRACE2("jni", "NewByteArray called");
-    assert(hythread_is_suspend_enabled());
-        
-    Global_Env * vm_env = jni_get_vm_env(jni_env);
-    if (exn_raised()) return NULL;
-    
-    Class *clss = vm_env->ArrayOfByte_Class;
-    unsigned sz = clss->calculate_array_size(length);
-    if (sz == 0) return NULL;
-
-    tmn_suspend_disable();       //---------------------------------v
-    ObjectHandle h = oh_allocate_local_handle();
-    Vector_Handle array = gc_alloc(sz, clss->get_allocation_handle(),
-        vm_get_gc_thread_local());
-    if (NULL == array)
-    {
-        tmn_suspend_enable();
-        return NULL;
-    }
-
-    set_vector_length(array, length);
-
-#ifdef VM_STATS
-    clss->instance_allocated(sz);
-#endif //VM_STATS
-
-    h->object = (ManagedObject *)array;
-
-    tmn_suspend_enable();        //---------------------------------^
-
-    return (jbyteArray)h;
+    return (jbyteArray)NewPrimitiveArray(jni_get_vm_env(jni_env)->ArrayOfByte_Class, length);
 } //NewByteArray
 
 
-
 jcharArray JNICALL NewCharArray(JNIEnv * jni_env, jsize length)
 {
     TRACE2("jni", "NewCharArray called");
-    assert(hythread_is_suspend_enabled());
-    
-    Global_Env * vm_env = jni_get_vm_env(jni_env);
-    if (exn_raised()) return NULL;
-
-    Class *clss = vm_env->ArrayOfChar_Class;
-    unsigned sz = clss->calculate_array_size(length);
-    if (sz == 0) return NULL;
-
-    tmn_suspend_disable();       //---------------------------------v
-    ObjectHandle h = oh_allocate_local_handle();
-    Vector_Handle array = gc_alloc(sz, clss->get_allocation_handle(),
-        vm_get_gc_thread_local());
-    if(NULL == array)
-    {
-        tmn_suspend_enable();
-        return NULL;
-    }
-
-    set_vector_length(array, length);
-
-#ifdef VM_STATS
-    clss->instance_allocated(sz);
-#endif //VM_STATS
-
-    h->object = (ManagedObject *)array;
-
-    tmn_suspend_enable();        //---------------------------------^
-
-    return (jcharArray)h;
+    return (jcharArray)NewPrimitiveArray(jni_get_vm_env(jni_env)->ArrayOfChar_Class, length);
 } //NewCharArray
 
 
-
 jshortArray JNICALL NewShortArray(JNIEnv * jni_env, jsize length)
 {
     TRACE2("jni", "NewShortArray called");
-    assert(hythread_is_suspend_enabled());
-    
-    Global_Env * vm_env = jni_get_vm_env(jni_env);
-    if (exn_raised()) return NULL;
-    
-    Class *clss = vm_env->ArrayOfShort_Class; 
-    unsigned sz = clss->calculate_array_size(length);
-    if (sz == 0) return NULL;
-
-    tmn_suspend_disable();       //---------------------------------v
-    ObjectHandle h = oh_allocate_local_handle();
-
-    Vector_Handle array = gc_alloc(sz, clss->get_allocation_handle(),
-        vm_get_gc_thread_local());
-    if (NULL == array)
-    {
-        tmn_suspend_enable();
-        return NULL;
-    }
-
-    set_vector_length(array, length);
-
-#ifdef VM_STATS
-    clss->instance_allocated(sz);
-#endif //VM_STATS
-
-    h->object = (ManagedObject *)array;
-
-    tmn_suspend_enable();        //---------------------------------^
-
-    return (jshortArray)h;
+    return (jshortArray)NewPrimitiveArray(jni_get_vm_env(jni_env)->ArrayOfShort_Class,
length);
 } //NewShortArray
 
 
-
 jintArray JNICALL NewIntArray(JNIEnv * jni_env, jsize length)
 {
     TRACE2("jni", "NewIntArray called");
-    assert(hythread_is_suspend_enabled());
-        
-    Global_Env * vm_env = jni_get_vm_env(jni_env);
-    if (exn_raised()) return NULL;
-    
-    Class *clss = vm_env->ArrayOfInt_Class;
-    unsigned sz = clss->calculate_array_size(length);
-    if (sz == 0) return NULL;
-
-    tmn_suspend_disable();       //---------------------------------v
-    ObjectHandle h = oh_allocate_local_handle();
-    Vector_Handle array = gc_alloc(sz, clss->get_allocation_handle(),
-        vm_get_gc_thread_local());
-    if (NULL == array)
-    {
-        tmn_suspend_enable();
-        return NULL;
-    }
-
-    set_vector_length(array, length);
-
-#ifdef VM_STATS
-    clss->instance_allocated(sz);
-#endif //VM_STATS
-
-    h->object = (ManagedObject *)array;
-
-    tmn_suspend_enable();        //---------------------------------^
-
-    return (jintArray)h;
+    return (jintArray)NewPrimitiveArray(jni_get_vm_env(jni_env)->ArrayOfInt_Class, length);
 } //NewIntArray
 
 
-
 jlongArray JNICALL NewLongArray(JNIEnv * jni_env, jsize length)
 {
     TRACE2("jni", "NewLongArray called");
-    assert(hythread_is_suspend_enabled());
-    
-    Global_Env * vm_env = jni_get_vm_env(jni_env);
-    if (exn_raised()) return NULL;
-
-    Class *clss = vm_env->ArrayOfLong_Class;
-    unsigned sz = clss->calculate_array_size(length);
-    if (sz == 0) return NULL;
-
-    tmn_suspend_disable();       //---------------------------------v
-    ObjectHandle h = oh_allocate_local_handle();
-    Vector_Handle array = gc_alloc(sz, clss->get_allocation_handle(),
-        vm_get_gc_thread_local());
-    if (NULL == array)
-    {
-        tmn_suspend_enable();
-        return NULL;
-    }
-
-    set_vector_length(array, length);
-
-#ifdef VM_STATS
-    clss->instance_allocated(sz);
-#endif //VM_STATS
-
-    h->object = (ManagedObject *)array;
-
-    tmn_suspend_enable();        //---------------------------------^
-
-    return (jlongArray)h;
+    return (jlongArray)NewPrimitiveArray(jni_get_vm_env(jni_env)->ArrayOfLong_Class, length);
 } //NewLongArray
 
 
-
 jfloatArray JNICALL NewFloatArray(JNIEnv * jni_env, jsize length)
 {
     TRACE2("jni", "NewFloatArray called");
-    assert(hythread_is_suspend_enabled());
-    
-    Global_Env * vm_env = jni_get_vm_env(jni_env);
-    if (exn_raised()) return NULL;
-    
-    Class *clss = vm_env->ArrayOfFloat_Class;
-    unsigned sz = clss->calculate_array_size(length);
-    if (sz == 0) return NULL;
-
-    tmn_suspend_disable();       //---------------------------------v
-    ObjectHandle h = oh_allocate_local_handle();
-    Vector_Handle array = gc_alloc(sz, clss->get_allocation_handle(),
-        vm_get_gc_thread_local());
-    if (NULL == array)
-    {
-        tmn_suspend_enable();
-        return NULL;
-    }
-
-    set_vector_length(array, length);
-
-#ifdef VM_STATS
-    clss->instance_allocated(sz);
-#endif //VM_STATS
-
-    h->object = (ManagedObject *)array;
-
-    tmn_suspend_enable();        //---------------------------------^
-
-    return (jfloatArray)h;
+    return (jfloatArray)NewPrimitiveArray(jni_get_vm_env(jni_env)->ArrayOfFloat_Class,
length);
 } //NewFloatArray
 
 
-
 jdoubleArray JNICALL NewDoubleArray(JNIEnv * jni_env, jsize length)
 {
     TRACE2("jni", "NewDoubleArray called");
-    assert(hythread_is_suspend_enabled());
-    
-    Global_Env * vm_env = jni_get_vm_env(jni_env);
-    if (exn_raised()) return NULL;
-    
-    Class *clss = vm_env->ArrayOfDouble_Class;
-    unsigned sz = clss->calculate_array_size(length);
-    if (sz == 0) return NULL;
-
-    tmn_suspend_disable();       //---------------------------------v
-    ObjectHandle h = oh_allocate_local_handle();
-    Vector_Handle array = gc_alloc(sz, clss->get_allocation_handle(),
-        vm_get_gc_thread_local());
-    if (NULL == array)
-    {
-        tmn_suspend_enable();
-        return NULL;
-    }
-
-    set_vector_length(array, length);
-
-#ifdef VM_STATS
-    clss->instance_allocated(sz);
-#endif //VM_STATS
-
-    h->object = (ManagedObject *)array;
-
-    tmn_suspend_enable();        //---------------------------------^
-
-    return (jdoubleArray)h;
+    return (jdoubleArray)NewPrimitiveArray(jni_get_vm_env(jni_env)->ArrayOfDouble_Class,
length);
 } //NewDoubleArray
 
-
-// end New<Type>Array functions
+// end New<PrimitiveType>Array functions
 /////////////////////////////////////////////////////////////////////////////
 
 



Mime
View raw message