harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ge...@apache.org
Subject svn commit: r448410 - in /incubator/harmony/enhanced/drlvm/trunk: src/test/negative_array_size/ src/test/negative_array_size/NegativeArray.java vm/vmcore/src/object/vm_arrays.cpp
Date Thu, 21 Sep 2006 00:08:54 GMT
Author: geirm
Date: Wed Sep 20 17:08:54 2006
New Revision: 448410

URL: http://svn.apache.org/viewvc?view=rev&rev=448410
Log:
HARMONY-1373

Fixes for negative array size

tested, fixed. works.

ubuntu 6

Added:
    incubator/harmony/enhanced/drlvm/trunk/src/test/negative_array_size/
    incubator/harmony/enhanced/drlvm/trunk/src/test/negative_array_size/NegativeArray.java
  (with props)
Modified:
    incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/object/vm_arrays.cpp

Added: incubator/harmony/enhanced/drlvm/trunk/src/test/negative_array_size/NegativeArray.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/src/test/negative_array_size/NegativeArray.java?view=auto&rev=448410
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/src/test/negative_array_size/NegativeArray.java
(added)
+++ incubator/harmony/enhanced/drlvm/trunk/src/test/negative_array_size/NegativeArray.java
Wed Sep 20 17:08:54 2006
@@ -0,0 +1,11 @@
+public class NegativeArray {
+
+	    public static void main(String[] args) {
+	        try {
+		   int i[][] = new int [10][-10];
+	           System.out.println("Test failed");
+	        } catch (NegativeArraySizeException ex) {
+	            System.out.println("Test passed: " + ex);
+	        }
+	     }
+}

Propchange: incubator/harmony/enhanced/drlvm/trunk/src/test/negative_array_size/NegativeArray.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/object/vm_arrays.cpp
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/object/vm_arrays.cpp?view=diff&rev=448410&r1=448409&r2=448410
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/object/vm_arrays.cpp (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/object/vm_arrays.cpp Wed Sep 20 17:08:54
2006
@@ -279,61 +279,102 @@
 
 Vector_Handle
 vm_multianewarray_recursive(Class    *c,
-                             int      *dims_array,
-                             unsigned  dims)
+                            int      *dims_array,
+                            unsigned  dims)
 {
     ASSERT_RAISE_AREA;
     assert(!hythread_is_suspend_enabled());
     Global_Env *global_env = VM_Global_State::loader_env;
-    int length = *dims_array;
-    assert(length >= 0);
-    assert((length&TWO_HIGHEST_BITS_SET_MASK) == 0);
+
+    int *pos = (int*) STD_ALLOCA(sizeof(int) * dims);
+    Class **clss = (Class**) STD_ALLOCA(sizeof(Class*) * dims);
+    ObjectHandle *obj = (ObjectHandle*) STD_ALLOCA(sizeof(ObjectHandle) * dims);
+
+    unsigned max_depth = dims - 1;
+    unsigned d;
+
+    // check dimensions phase
+    for(d = 0; d < dims; d++) {
+        pos[d] = 0;
+        int len = dims_array[d];
+        if (len < 0) {
+            // The function uses gc allocation, so it is not gc safe anyway
+            tmn_suspend_enable();
+            exn_raise_by_name("java/lang/NegativeArraySizeException");
+            tmn_suspend_disable();
+            return 0;
+        }
+
+        if (len & TWO_HIGHEST_BITS_SET_MASK) {
+            // The function uses gc allocation, so it is not gc safe anyway
+            tmn_suspend_enable();
+            exn_raise_by_name("java/lang/OutOfMemoryError",
+                    "VM doesn't support arrays of the requested size");
+            tmn_suspend_disable();
+            return 0;
+        }
+
+        if (len == 0) {
+            if (d < max_depth) max_depth = d;
+        }
+        obj[d] = oh_allocate_local_handle();
+    }
+
+    // init Class* array
+    clss[0] = c;
     assert(c->name->bytes[0] == '[');
     assert(c->name->len > 1);
 
-    volatile Vector_Handle object_array = (Vector_Handle) vm_new_vector(c, length);
+    for(d = 1; d < dims; d++) {
+        c = c->array_element_class;
+        assert(c->name->bytes[0] == '[');
+        assert(c->name->len > 1);
+        clss[d] = c;
+    }
 
-    if(dims == 1) {
-        return object_array;
-    } else {
-        assert(!hythread_is_suspend_enabled());
-        // Alexei
-        // Since this function is called from a managed code
-        // generated by JIT and this is a native code,
-        // I assume that there exist an m2n frame
-        // to allocate a local handle from.
-        ObjectHandle handle = oh_convert_to_local_handle((ManagedObject*)object_array);
-
-        Class *elem_type_clss = c->array_element_class;
-        assert(elem_type_clss);
-        // ppervov: array_element_class is now prepared upon creation of an array class
-        //assert(class_prepare(elem_type_clss));
-
-        // Allocate all subarrays end store them in the parent array.
-        if (global_env->compress_references) {
-            for (int i = 0; i < length; i++) {
-                Vector_Handle elem = vm_multianewarray_recursive(elem_type_clss,
-                                                                  dims_array + 1,
-                                                                  dims - 1);
-                object_array = handle->object;
-                gc_heap_slot_write_ref_compressed((Managed_Object_Handle)object_array, 
-                                                  (uint32 *)get_vector_element_address_ref(object_array,
i), 
-                                                  (Managed_Object_Handle)elem);
-            }
-        } else {
-            for (int i = 0; i < length; i++) {
-                Vector_Handle elem = vm_multianewarray_recursive(elem_type_clss,
-                                                                  dims_array + 1,
-                                                                  dims - 1);
-                object_array = handle->object;
-                gc_heap_slot_write_ref((Managed_Object_Handle)object_array, 
-                                       (Managed_Object_Handle *)get_vector_element_address_ref(object_array,
i), 
-                                       (Managed_Object_Handle)elem);
-            }    
+    // init root element
+    ManagedObject* array = obj[0]->object = (ManagedObject*) vm_new_vector(clss[0], dims_array[0]);
+    if (!array) {
+        assert(exn_raised());
+        return 0;
+    }
+    set_vector_length(array, dims_array[0]);
+    if (max_depth == 0) return array;
+
+    d = 1;
+    // allocation dimensions
+    while(true) {
+        ManagedObject *element = (ManagedObject*) vm_new_vector(clss[d], dims_array[d]);
+        if (!element) {
+            assert(exn_raised());
+            // OutOfMemoryError occured
+            return 0;
         }
-        oh_discard_local_handle(handle);
 
-        return (Vector_Handle)object_array;
+        set_vector_length(element, dims_array[d]);
+
+        if (d != max_depth) {
+            obj[d]->object = element;
+            d++;
+            continue;
+        }
+
+        while(true) {
+            ManagedObject *subarray = obj[d - 1]->object;
+            ManagedObject **slot = get_vector_element_address_ref(subarray, pos[d-1]);
+            STORE_REFERENCE(subarray, slot, element);
+            pos[d-1]++;
+
+            if (pos[d-1] < dims_array[d-1]) {
+                break;
+            }
+
+            pos[d-1] = 0;
+            element = subarray;
+            d--;
+
+            if (d == 0) return array;
+        }
     }
 } //vm_multianewarray_recursive
 



Mime
View raw message