This patch introduces a gc_malloc() entry point. It's a simple wrapper
on top of kzalloc() for now.

Cc: Vegard Nossum <vegard.nos...@gmail.com>
Signed-off-by: Pekka Enberg <penb...@cs.helsinki.fi>
---
 include/vm/gc.h   |    2 ++
 test/vm/gc-stub.c |    6 ++++++
 vm/gc.c           |    6 ++++++
 vm/object.c       |    9 +++++----
 4 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/include/vm/gc.h b/include/vm/gc.h
index 05e324c..a9bfae9 100644
--- a/include/vm/gc.h
+++ b/include/vm/gc.h
@@ -5,6 +5,8 @@ extern void *gc_safepoint_page;
 
 void gc_init(void);
 
+void *gc_alloc(size_t size);
+
 void gc_attach_thread(void);
 void gc_detach_thread(void);
 
diff --git a/test/vm/gc-stub.c b/test/vm/gc-stub.c
index fe8cc14..cfdd7db 100644
--- a/test/vm/gc-stub.c
+++ b/test/vm/gc-stub.c
@@ -1,7 +1,13 @@
+#include "vm/stdlib.h"
 #include "vm/gc.h"
 
 void *gc_safepoint_page;
 
+void *gc_alloc(size_t size)
+{
+       return zalloc(size);
+}
+
 void gc_attach_thread(void)
 {
 }
diff --git a/vm/gc.c b/vm/gc.c
index 37a2143..28d2340 100644
--- a/vm/gc.c
+++ b/vm/gc.c
@@ -5,6 +5,7 @@
 
 #include "lib/guard-page.h"
 #include "vm/thread.h"
+#include "vm/stdlib.h"
 #include "vm/die.h"
 #include "vm/gc.h"
 
@@ -30,6 +31,11 @@ void gc_init(void)
                die("Couldn't allocate GC safepoint guard page");
 }
 
+void *gc_alloc(size_t size)
+{
+       return zalloc(size);
+}
+
 void gc_attach_thread(void)
 {
 }
diff --git a/vm/object.c b/vm/object.c
index 36e60c1..913458d 100644
--- a/vm/object.c
+++ b/vm/object.c
@@ -18,6 +18,7 @@
 #include "vm/string.h"
 #include "vm/types.h"
 #include "vm/utf8.h"
+#include "vm/gc.h"
 
 #include "lib/string.h"
 
@@ -46,7 +47,7 @@ struct vm_object *vm_object_alloc(struct vm_class *class)
        if (vm_class_ensure_init(class))
                return NULL;
 
-       res = zalloc(sizeof(*res) + class->object_size);
+       res = gc_alloc(sizeof(*res) + class->object_size);
        if (!res) {
                NOT_IMPLEMENTED;
                return NULL;
@@ -70,7 +71,7 @@ struct vm_object *vm_object_alloc_primitive_array(int type, 
int count)
        vm_type = bytecode_type_to_vmtype(type);
        assert(vm_type != J_VOID);
 
-       res = zalloc(sizeof(*res) + get_vmtype_size(vm_type) * count);
+       res = gc_alloc(sizeof(*res) + get_vmtype_size(vm_type) * count);
        if (!res) {
                NOT_IMPLEMENTED;
                return NULL;
@@ -138,7 +139,7 @@ struct vm_object *vm_object_alloc_multi_array(struct 
vm_class *class,
        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) + elem_size * counts[0]);
+       res = gc_alloc(sizeof(*res) + elem_size * counts[0]);
        if (!res) {
                NOT_IMPLEMENTED;
                return NULL;
@@ -172,7 +173,7 @@ struct vm_object *vm_object_alloc_array(struct vm_class 
*class, int count)
        if (vm_class_ensure_init(class))
                return NULL;
 
-       res = zalloc(sizeof(*res) + sizeof(struct vm_object *) * count);
+       res = gc_alloc(sizeof(*res) + sizeof(struct vm_object *) * count);
        if (!res) {
                NOT_IMPLEMENTED;
                return NULL;
-- 
1.5.6.3


------------------------------------------------------------------------------
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