Signed-off-by: Tomek Grabiec <tgrab...@gmail.com>
---
 include/vm/call.h  |    3 +++
 vm/call.c          |   37 +++++++++++++++++++++++++++++++++++++
 vm/jni-interface.c |   25 ++++++++++++++++++++++++-
 3 files changed, 64 insertions(+), 1 deletions(-)

diff --git a/include/vm/call.h b/include/vm/call.h
index 557fb86..71531db 100644
--- a/include/vm/call.h
+++ b/include/vm/call.h
@@ -10,6 +10,9 @@ struct vm_method;
 struct vm_object;
 
 unsigned long vm_call_method_v(struct vm_method *method, va_list args);
+unsigned long vm_call_method_this_v(struct vm_method *method,
+                                   struct vm_object *this,
+                                   va_list args);
 
 #define DECLARE_VM_CALL_METHOD(type, suffix)                           \
        static inline type                                              \
diff --git a/vm/call.c b/vm/call.c
index 11c9dca..76fc83e 100644
--- a/vm/call.c
+++ b/vm/call.c
@@ -101,6 +101,26 @@ vm_call_jni_method_v(struct vm_method *method, va_list 
args)
        return vm_call_method_a(method, args_array);
 }
 
+static unsigned long
+vm_call_jni_method_this_v(struct vm_method *method, struct vm_object *this,
+                         va_list args)
+{
+       unsigned long args_array[method->args_count];
+       int i;
+
+       i = 0;
+       args_array[i++] = (unsigned long)vm_jni_get_jni_env();
+
+       assert(!vm_method_is_static(method));
+
+       args_array[i++] = (unsigned long) this;
+
+       while (i < method->args_count)
+               args_array[i++] = va_arg(args, long);
+
+       return vm_call_method_a(method, args_array);
+}
+
 unsigned long vm_call_method_v(struct vm_method *method, va_list args)
 {
        unsigned long args_array[method->args_count];
@@ -113,3 +133,20 @@ unsigned long vm_call_method_v(struct vm_method *method, 
va_list args)
 
        return vm_call_method_a(method, args_array);
 }
+
+unsigned long vm_call_method_this_v(struct vm_method *method,
+                                   struct vm_object *this,
+                                   va_list args)
+{
+       unsigned long args_array[method->args_count];
+
+       if (vm_method_is_jni(method))
+               return vm_call_jni_method_this_v(method, this, args);
+
+       args_array[0] = (unsigned long) this;
+
+       for (int i = 1; i < method->args_count; i++)
+               args_array[i] = va_arg(args, unsigned long);
+
+       return vm_call_method_a(method, args_array);
+}
diff --git a/vm/jni-interface.c b/vm/jni-interface.c
index 50c1c62..44efde2 100644
--- a/vm/jni-interface.c
+++ b/vm/jni-interface.c
@@ -497,6 +497,29 @@ static jint vm_jni_monitor_exit(struct vm_jni_env *env, 
jobject obj)
        return err;
 }
 
+static jobject vm_jni_new_object(struct vm_jni_env *env, jobject clazz,
+                                jmethodID method, ...)
+{
+       va_list args;
+
+       enter_vm_from_jni();
+
+       struct vm_object *obj;
+       struct vm_class *class;
+
+       if (!vm_object_is_instance_of(clazz, vm_java_lang_Class))
+               return NULL;
+
+       class = vm_class_get_class_from_class_object(clazz);
+       obj = vm_object_alloc(class);
+
+       va_start(args, method);
+       vm_call_method_this_v(method, obj, args);
+       va_end(args);
+
+       return obj;
+}
+
 /*
  * The JNI native interface table.
  * See: http://java.sun.com/j2se/1.4.2/docs/guide/jni/spec/functions.html
@@ -541,7 +564,7 @@ void *vm_jni_native_interface[] = {
        NULL,
        NULL,
        NULL, /* AllocObject */
-       NULL, /* NewObject */
+       vm_jni_new_object, /* NewObject */
        NULL, /* NewObjectV */
 
        /* 30 */
-- 
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