The Java VM Spec in 2.16.4 "The Classes Exception and RuntimeException"
states that: "An UnsatisfiedLinkError is thrown at run time if the
Java virtual machine cannot find an appropriate definition of a method
declared to be native."


Signed-off-by: Tomek Grabiec <tgrab...@gmail.com>
---
 jit/trampoline.c |   27 ++++++++++++++++++++++-----
 1 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/jit/trampoline.c b/jit/trampoline.c
index e5b0f55..1fe6503 100644
--- a/jit/trampoline.c
+++ b/jit/trampoline.c
@@ -30,6 +30,7 @@
 #include <jit/compiler.h>
 
 #include <vm/natives.h>
+#include <vm/string.h>
 #include <vm/method.h>
 #include <vm/buffer.h>
 #include <vm/die.h>
@@ -37,20 +38,36 @@
 
 static void *jit_native_trampoline(struct compilation_unit *cu)
 {
-       struct methodblock *method = cu->method;
        const char *method_name, *class_name;
+       struct methodblock *method;
+       struct string *msg;
        void *ret;
 
+       method = cu->method;
        class_name  = CLASS_CB(method->class)->name;
        method_name = method->name;
 
        ret = vm_lookup_native(class_name, method_name);
-       if (!ret)
-               die("no native function found for %s.%s", class_name, 
method_name);
+       if (ret) {
+               add_cu_mapping((unsigned long)ret, cu);
+               return ret;
+       }
 
-       add_cu_mapping((unsigned long)ret, cu);
+       msg = alloc_str();
+       if (!msg)
+               /* TODO: signal OutOfMemoryError */
+               die("%s: out of memory\n", __func__);
 
-       return ret;
+       str_printf(msg, "%s.%s%s", CLASS_CB(method->class)->name, method->name,
+                  method->type);
+
+       if (strcmp(class_name, "VMThrowable") == 0)
+               die("no native function found for %s", msg->value);
+
+       signal_new_exception("java/lang/UnsatisfiedLinkError", msg->value);
+       free_str(msg);
+
+       return NULL;
 }
 
 static void *jit_java_trampoline(struct compilation_unit *cu)
-- 
1.6.0.6


------------------------------------------------------------------------------
Are you an open source citizen? Join us for the Open Source Bridge conference!
Portland, OR, June 17-19. Two days of sessions, one day of unconference: $250.
Need another reason to go? 24-hour hacker lounge. Register today!
http://ad.doubleclick.net/clk;215844324;13503038;v?http://opensourcebridge.org
_______________________________________________
Jatovm-devel mailing list
Jatovm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jatovm-devel

Reply via email to