Signed-off-by: Tomek Grabiec <[email protected]>
---
arch/x86/Makefile_32 | 1 +
arch/x86/exception_32.c | 32 ++++++++++++++++++++++++++++++++
arch/x86/include/arch/exception.h | 9 +++++++++
arch/x86/insn-selector_32.brg | 11 ++++++++++-
include/jit/statement.h | 7 +++++--
jit/bytecode-to-ir.c | 3 +++
jit/exception-bc.c | 26 +++++++++++++++++++++++++-
jit/tree-printer.c | 16 ++++++++++++++++
test/arch-x86/Makefile | 1 +
9 files changed, 102 insertions(+), 4 deletions(-)
create mode 100644 arch/x86/exception_32.c
create mode 100644 arch/x86/include/arch/exception.h
diff --git a/arch/x86/Makefile_32 b/arch/x86/Makefile_32
index 42d681c..c65c9f0 100644
--- a/arch/x86/Makefile_32
+++ b/arch/x86/Makefile_32
@@ -7,6 +7,7 @@ ARCH_OBJS = \
arch/x86/registers_32.o \
arch/x86/stack-frame.o \
arch/x86/use-def.o \
+ arch/x86/exception_32.o \
jamvm/os/$(OS)/i386/dll_md.o \
jamvm/os/$(OS)/i386/init.o \
jamvm/os/$(OS)/os.o
diff --git a/arch/x86/exception_32.c b/arch/x86/exception_32.c
new file mode 100644
index 0000000..c703859
--- /dev/null
+++ b/arch/x86/exception_32.c
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2009 Tomasz Grabiec
+ *
+ * This file is released under the GPL version 2 with the following
+ * clarification and special exception:
+ *
+ * Linking this library statically or dynamically with other modules is
+ * making a combined work based on this library. Thus, the terms and
+ * conditions of the GNU General Public License cover the whole
+ * combination.
+ *
+ * As a special exception, the copyright holders of this library give you
+ * permission to link this library with independent modules to produce an
+ * executable, regardless of the license terms of these independent
+ * modules, and to copy and distribute the resulting executable under terms
+ * of your choice, provided that you also meet, for each linked independent
+ * module, the terms and conditions of the license of that module. An
+ * independent module is a module which is not derived from or based on
+ * this library. If you modify this library, you may extend this exception
+ * to your version of the library, but you are not obligated to do so. If
+ * you do not wish to do so, delete this exception statement from your
+ * version.
+ *
+ * Please refer to the file LICENSE for details.
+ */
+
+#include <arch/exception.h>
+
+unsigned char *throw_exception(struct object *exception)
+{
+ return NULL; /* TODO */
+}
diff --git a/arch/x86/include/arch/exception.h
b/arch/x86/include/arch/exception.h
new file mode 100644
index 0000000..422321e
--- /dev/null
+++ b/arch/x86/include/arch/exception.h
@@ -0,0 +1,9 @@
+#ifndef _ARCH_EXCEPTION_H
+#define _ARCH_EXCEPTION_H
+
+#include <vm/vm.h>
+
+/* This should be called only by JIT compiled native code */
+unsigned char *throw_exception(struct object *exception);
+
+#endif
diff --git a/arch/x86/insn-selector_32.brg b/arch/x86/insn-selector_32.brg
index 70c18ef..c4d24ef 100644
--- a/arch/x86/insn-selector_32.brg
+++ b/arch/x86/insn-selector_32.brg
@@ -14,9 +14,11 @@
#include <jit/expression.h>
#include <jit/statement.h>
#include <jit/bc-offset-mapping.h>
+#include <jit/exception.h>
#include <arch/instruction.h>
#include <arch/stack-frame.h>
+#include <arch/exception.h>
#include <assert.h>
#include <errno.h>
@@ -1100,7 +1102,14 @@ stmt: STMT_STORE(reg, array_deref)
stmt: STMT_ATHROW(reg)
{
- /*TODO*/
+ struct var_info *reg_eax = get_fixed_var(s->b_parent, REG_EAX);
+
+ select_insn(s, tree, reg_insn(INSN_PUSH_REG, state->left->reg1));
+ select_insn(s, tree, rel_insn(INSN_CALL_REL, (unsigned
long)throw_exception));
+
+ /* Jump where throw_exception() told us to jump */
+ select_insn(s, tree, reg_insn(INSN_PUSH_REG, reg_eax));
+ select_insn(s, tree, insn(INSN_RET));
}
stmt: STMT_NULL_CHECK(reg)
diff --git a/include/jit/statement.h b/include/jit/statement.h
index 793e62d..9041e0d 100644
--- a/include/jit/statement.h
+++ b/include/jit/statement.h
@@ -26,8 +26,8 @@ struct statement {
union {
struct tree_node node;
- /* STMT_VOID_RETURN and STMT_ATHROW has no members in this
struct. */
-
+ /* STMT_VOID_RETURN has no members in this struct. */
+
struct /* STMT_STORE */ {
struct tree_node *store_dest;
struct tree_node *store_src;
@@ -46,6 +46,9 @@ struct statement {
struct tree_node *checkcast_ref;
struct object *checkcast_class;
};
+ struct /* STMT_ATHROW */ {
+ struct tree_node *exception_ref;
+ };
/* STMT_EXPRESSION, STMT_NULL_CHECK, STMT_ARRAY_CHECK */
struct tree_node *expression;
};
diff --git a/jit/bytecode-to-ir.c b/jit/bytecode-to-ir.c
index e6e0640..1577359 100644
--- a/jit/bytecode-to-ir.c
+++ b/jit/bytecode-to-ir.c
@@ -257,6 +257,9 @@ void convert_statement(struct parse_context *ctx, struct
statement *stmt)
case STMT_ARRAY_CHECK:
tree_patch_bc_offset(stmt->expression, bc_offset);
break;
+ case STMT_ATHROW:
+ tree_patch_bc_offset(stmt->exception_ref, bc_offset);
+ break;
default: ;
}
diff --git a/jit/exception-bc.c b/jit/exception-bc.c
index 8dac41d..fe0025f 100644
--- a/jit/exception-bc.c
+++ b/jit/exception-bc.c
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2008 Saeed Siam
+ * Copyright (c) 2009 Tomasz Grabiec
*
* This file is released under the GPL version 2 with the following
* clarification and special exception:
@@ -27,13 +28,36 @@
#include <jit/bytecode-converters.h>
#include <jit/compiler.h>
#include <jit/statement.h>
+#include <jit/expression.h>
-#include <vm/bytecodes.h>
#include <vm/stack.h>
#include <errno.h>
int convert_athrow(struct parse_context *ctx)
{
+ struct statement *stmt = alloc_statement(STMT_ATHROW);
+ struct stack *mimic_stack = ctx->bb->mimic_stack;
+ struct expression *expr;
+
+ if (!stmt)
+ return -ENOMEM;
+
+ expr = stack_pop(mimic_stack);
+ stmt->exception_ref = &expr->node;
+
+ /*
+ * According to the JVM specification athrow operation is
+ * supposed to discard the java stack and push exception
+ * reference on it. We don't do the latter because exception
+ * reference is not transferred to exception handlers in
+ * BC2IR layer.
+ */
+ while (!stack_is_empty(mimic_stack)) {
+ struct expression *e = stack_pop(mimic_stack);
+ expr_put(e);
+ }
+
+ convert_statement(ctx, stmt);
return 0;
}
diff --git a/jit/tree-printer.c b/jit/tree-printer.c
index 4d3e086..ceff2c6 100644
--- a/jit/tree-printer.c
+++ b/jit/tree-printer.c
@@ -259,6 +259,21 @@ static int print_checkcast_stmt(int lvl, struct string
*str,
return err;
}
+static int print_athrow_stmt(int lvl, struct string *str,
+ struct statement *stmt)
+{
+ int err;
+
+ err = append_formatted(lvl, str, "ATHROW:\n");
+ if (err)
+ goto out;
+
+ err = append_tree_attr(lvl + 1, str, "expression", stmt->expression);
+
+ out:
+ return err;
+}
+
typedef int (*print_stmt_fn) (int, struct string * str, struct statement *);
static print_stmt_fn stmt_printers[] = {
@@ -273,6 +288,7 @@ static print_stmt_fn stmt_printers[] = {
[STMT_MONITOR_ENTER] = print_monitor_enter_stmt,
[STMT_MONITOR_EXIT] = print_monitor_exit_stmt,
[STMT_CHECKCAST] = print_checkcast_stmt,
+ [STMT_ATHROW] = print_athrow_stmt,
};
static int print_stmt(int lvl, struct tree_node *root, struct string *str)
diff --git a/test/arch-x86/Makefile b/test/arch-x86/Makefile
index 8ab76d4..8e3b6ad 100644
--- a/test/arch-x86/Makefile
+++ b/test/arch-x86/Makefile
@@ -49,6 +49,7 @@ OBJS = \
../../arch/x86/insn-selector$(ARCH_POSTFIX).o \
../../arch/x86/stack-frame.o \
../../arch/x86/use-def.o \
+ ../../arch/x86/exception$(ARCH_POSTFIX).o \
$(TESTS)
TESTS = \
--
1.6.0.6
------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables
unlimited royalty-free distribution of the report engine
for externally facing server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Jatovm-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jatovm-devel