Signed-off-by: Tomek Grabiec <[email protected]>
---
regression/jvm/ExceptionsTest.java | 59 ++++++++++++++++++++++++++++++++++++
vm/signal.c | 25 +++++++++++++++
2 files changed, 84 insertions(+), 0 deletions(-)
diff --git a/regression/jvm/ExceptionsTest.java
b/regression/jvm/ExceptionsTest.java
index 41dc8ad..54535ac 100644
--- a/regression/jvm/ExceptionsTest.java
+++ b/regression/jvm/ExceptionsTest.java
@@ -41,6 +41,9 @@ public class ExceptionsTest extends TestCase {
public static void takeInt(int val) {
}
+ public static void takeLong(long val) {
+ }
+
public static void testTryBlockDoesNotThrowAnything() {
boolean caught;
try {
@@ -254,6 +257,58 @@ public class ExceptionsTest extends TestCase {
assertTrue(catched);
}
+ public static void testIdiv() {
+ boolean catched = false;
+ int denominator = 0;
+
+ try {
+ takeInt(1 / denominator);
+ } catch (ArithmeticException e) {
+ catched = true;
+ }
+
+ assertTrue(catched);
+ }
+
+ public static void testIrem() {
+ boolean catched = false;
+ int denominator = 0;
+
+ try {
+ takeInt(1 % denominator);
+ } catch (ArithmeticException e) {
+ catched = true;
+ }
+
+ assertTrue(catched);
+ }
+
+ public static void testLdiv() {
+ boolean catched = false;
+ long denominator = 0;
+
+ try {
+ takeLong(1L / denominator);
+ } catch (ArithmeticException e) {
+ catched = true;
+ }
+
+ assertTrue(catched);
+ }
+
+ public static void testLrem() {
+ boolean catched = false;
+ long denominator = 0;
+
+ try {
+ takeLong(1L % denominator);
+ } catch (ArithmeticException e) {
+ catched = true;
+ }
+
+ assertTrue(catched);
+ }
+
public static void main(String args[]) {
testTryBlockDoesNotThrowAnything();
testThrowAndCatchInTheSameMethod();
@@ -273,6 +328,10 @@ public class ExceptionsTest extends TestCase {
testPutfield();
testMonitorenter();
/* no test for Monitorexit */
+ testIdiv();
+ testIrem();
+ /* testLdiv(); */
+ /* testLrem(); */
exit();
}
diff --git a/vm/signal.c b/vm/signal.c
index 32db706..1a032d2 100644
--- a/vm/signal.c
+++ b/vm/signal.c
@@ -32,6 +32,28 @@
#include <unistd.h>
#include <ucontext.h>
+static void sigfpe_handler(int sig, siginfo_t *si, void *ctx)
+{
+ if (signal_from_jit_method(ctx) && si->si_code == FPE_INTDIV) {
+ struct object *exception;
+
+ /* TODO: exception's stack trace should be filled using ctx */
+ exception = new_exception("java/lang/ArithmeticException",
+ "/ by zero");
+ if (exception == NULL) {
+ /* TODO: throw OutOfMemoryError */
+ fprintf(stderr, "%s: Out of memory\n", __FUNCTION__);
+ goto exit;
+ }
+
+ throw_exception_from_signal(ctx, exception);
+ return;
+ }
+
+ exit:
+ print_backtrace_and_die(sig, si, ctx);
+}
+
static void sigsegv_handler(int sig, siginfo_t *si, void *ctx)
{
/* Assume that zero-page access is caused by dereferencing a
@@ -71,6 +93,9 @@ void setup_signal_handlers(void)
sa.sa_sigaction = sigsegv_handler;
sigaction(SIGSEGV, &sa, NULL);
+ sa.sa_sigaction = sigfpe_handler;
+ sigaction(SIGFPE, &sa, NULL);
+
sa.sa_sigaction = signal_handler;
sigaction(SIGUSR1, &sa, NULL);
}
--
1.6.0.6
------------------------------------------------------------------------------
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT
is a gathering of tech-side developers & brand creativity professionals. Meet
the minds behind Google Creative Lab, Visual Complexity, Processing, &
iPhoneDevCamp as they present alongside digital heavyweights like Barbarian
Group, R/GA, & Big Spaceship. http://p.sf.net/sfu/creativitycat-com
_______________________________________________
Jatovm-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jatovm-devel