The function didn't work properly with multidimensional arrays
of primitive types. This caused the following SIGSEGV when
running scimark:

[main] SIGSEGV at EIP 08074f73 while accessing memory address 6530f357.
[main] Registers:
[main]  eax: 6530f357   ebx: 00000000   ecx: 00000000   edx: 0894d668
[main]  esi: 0894d668   edi: 00000000   ebp: bf8ae198   esp: bf8ae170
[main] Native and Java stack trace:
[main]  [<08074f73>] native     : vm_object_check_array+f 
(/home/tomek/projects/jato/jato/vm/object.c:394)
[main]  [<a7cbc6ff>] jit        : 
jnt/scimark2/kernel.RandomMatrix(kernel.java:253)
[main]  [<a7cbc3e3>] jit        : jnt/scimark2/kernel.measureSOR(kernel.java:43)
[main]  [<a7ca6f84>] jit        : 
jnt/scimark2/commandline.main(commandline.java:71)
[main]  [<08070fe2>] native     : do_main_class+110 
(/home/tomek/projects/jato/jato/vm/jato.c:1264)
[main]  [<080713ce>] native     : <unknown>
[main]  [<b7cb960b>] native     : <unknown>
[main]  [<08054800>] native     : <unknown>

Signed-off-by: Tomek Grabiec <tgrab...@gmail.com>
---
 vm/object.c |   30 ++++++++++++++----------------
 1 files changed, 14 insertions(+), 16 deletions(-)

diff --git a/vm/object.c b/vm/object.c
index 0946c8d..c8ed0fe 100644
--- a/vm/object.c
+++ b/vm/object.c
@@ -126,14 +126,19 @@ struct vm_object *vm_object_alloc_primitive_array(int 
type, int count)
 struct vm_object *vm_object_alloc_multi_array(struct vm_class *class,
        int nr_dimensions, int *counts)
 {
+       struct vm_class *elem_class;
+       struct vm_object *res;
+       int elem_size;
+
        assert(nr_dimensions > 0);
 
        if (vm_class_ensure_init(class))
                return NULL;
 
-       struct vm_object *res;
+       elem_class = vm_class_get_array_element_class(class);
+       elem_size  = get_vmtype_size(vm_class_get_storage_vmtype(elem_class));
 
-       res = zalloc(sizeof(*res) + sizeof(struct vm_object *) * counts[0]);
+       res = zalloc(sizeof(*res) + elem_size * counts[0]);
        if (!res) {
                NOT_IMPLEMENTED;
                return NULL;
@@ -145,25 +150,18 @@ struct vm_object *vm_object_alloc_multi_array(struct 
vm_class *class,
        }
 
        res->array_length = counts[0];
+       res->class = class;
 
-       struct vm_object **elems = (struct vm_object **) (res + 1);
+       if (nr_dimensions == 1)
+               return res;
 
-       if (nr_dimensions == 1) {
-               for (int i = 0; i < counts[0]; ++i)
-                       elems[i] = NULL;
-       } else {
-               struct vm_class *elem_class;
-
-               elem_class = vm_class_get_array_element_class(class);
+       struct vm_object **elems = (struct vm_object **) (res + 1);
 
-               for (int i = 0; i < counts[0]; ++i) {
-                       elems[i] = vm_object_alloc_multi_array(elem_class,
-                               nr_dimensions - 1, counts + 1);
-               }
+       for (int i = 0; i < counts[0]; ++i) {
+               elems[i] = vm_object_alloc_multi_array(elem_class,
+                                               nr_dimensions - 1, counts + 1);
        }
 
-       res->class = class;
-
        return res;
 }
 
-- 
1.6.0.6


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Jatovm-devel mailing list
Jatovm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jatovm-devel

Reply via email to