Hi Tomek,
Tomek Grabiec wrote:
> @@ -36,3 +43,30 @@ unsigned char *throw_exception(struct compilation_unit *cu,
>
> return throw_exception_from(cu, frame, native_ptr, exception);
> }
> +
> +void throw_exception_from_signal(void *ctx, struct object *exception)
> +{
> + ucontext_t *_ctx = (ucontext_t*)ctx;
You don't need to explicitly cast from or to a void pointer.
Also, please rename _ctx to "uc" or something. Underscores in variable
names hurt readability.
> + struct jit_stack_frame *frame;
> + struct compilation_unit *cu;
> + unsigned long source_addr;
> + void *eh;
> +
> + source_addr = _ctx->uc_mcontext.gregs[REG_EIP];
> + cu = get_cu_from_native_addr(source_addr);
> + frame = (struct jit_stack_frame*)_ctx->uc_mcontext.gregs[REG_EBP];
> +
> + eh = throw_exception_from(cu, frame, (unsigned char*)source_addr,
> + exception);
> +
> + if (eh == NULL) {
> + _ctx->uc_mcontext.gregs[REG_EIP] =
> (int)bb_native_ptr(cu->exit_bb);
> + } else {
> + _ctx->uc_mcontext.gregs[REG_EIP] = (int)eh;
Please use unsigned long here, int is not 64-bit safe.
> +
> + /* push exception object reference on stack */
> + _ctx->uc_mcontext.gregs[REG_ESP] -= sizeof(exception);
> + cpu_write_u32((unsigned char*)_ctx->uc_mcontext.gregs[REG_ESP],
> + (uint32_t)exception);
> + }
> +}
> diff --git a/arch/x86/signal.c b/arch/x86/signal.c
> new file mode 100644
> index 0000000..5bad631
> --- /dev/null
> +++ b/arch/x86/signal.c
> @@ -0,0 +1,39 @@
> +/*
> + * 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 <signal.h>
> +#include <arch/signal.h>
> +#include <arch/stack-frame.h>
> +
> +#define __USE_GNU
> +#include <ucontext.h>
> +
> +bool signal_from_jit_method(void *ctx)
> +{
> + ucontext_t *_ctx = (ucontext_t*)ctx;
> +
> + return is_jit_method(_ctx->uc_mcontext.gregs[REG_EIP]);
> +}
I think you need to pull REG_IP definition to a header file. This code
will be shared by the 64-bit implementation, after all.
> diff --git a/arch/x86/use-def.c b/arch/x86/use-def.c
> index 8463128..ef47f59 100644
> --- a/arch/x86/use-def.c
> +++ b/arch/x86/use-def.c
> @@ -6,6 +6,7 @@
> */
>
> #include <jit/compilation-unit.h>
> +#include <arch/instruction.h>
>
> enum {
> DEF_DST = 1,
> diff --git a/include/jit/compilation-unit.h b/include/jit/compilation-unit.h
> index 88d87b1..4b1891c 100644
> --- a/include/jit/compilation-unit.h
> +++ b/include/jit/compilation-unit.h
> @@ -7,12 +7,13 @@
> #include <vm/stack.h>
>
> #include <arch/stack-frame.h>
> -#include <arch/instruction.h>
>
> #include <stdbool.h>
> #include <pthread.h>
>
> struct buffer;
> +struct insn;
> +enum machine_reg;
>
> struct compilation_unit {
> struct methodblock *method;
What are these changes doing here?
> diff --git a/include/jit/exception.h b/include/jit/exception.h
> index 10e88fd..96483c1 100644
> --- a/include/jit/exception.h
> +++ b/include/jit/exception.h
> @@ -1,11 +1,12 @@
> #ifndef _JIT_EXCEPTION_H
> #define _JIT_EXCEPTION_H
>
> -#include <jit/compilation-unit.h>
> #include <vm/vm.h>
> #include <arch/stack-frame.h>
> +#include <stdbool.h>
>
> struct jit_stack_frame;
> +struct compilation_unit;
>
> struct exception_table_entry *exception_find_entry(struct methodblock *,
> unsigned long);
> diff --git a/include/vm/class.h b/include/vm/class.h
> index 4ca0274..063498c 100644
> --- a/include/vm/class.h
> +++ b/include/vm/class.h
> @@ -3,6 +3,7 @@
>
> #include <vm/vm.h>
>
> +struct object *create_null_pointer_exception();
Missing "void" argument specifier.
> unsigned long is_object_instance_of(struct object *obj, struct object *type);
> void check_null(struct object *obj);
> void check_array(struct object *obj, unsigned int index);
> diff --git a/jit/fixup-site.c b/jit/fixup-site.c
> index 9a63f28..51b3edb 100644
> --- a/jit/fixup-site.c
> +++ b/jit/fixup-site.c
> @@ -25,6 +25,7 @@
> */
>
> #include <jit/compiler.h>
> +#include <arch/instruction.h>
> #include <memory.h>
> #include <malloc.h>
>
What are these changes for?
> diff --git a/jit/liveness.c b/jit/liveness.c
> index 74b656a..820d79d 100644
> --- a/jit/liveness.c
> +++ b/jit/liveness.c
> @@ -9,6 +9,7 @@
> #include <jit/compilation-unit.h>
> #include <jit/vars.h>
> #include <vm/bitset.h>
> +#include <arch/instruction.h>
>
> #include <errno.h>
> #include <stdlib.h>
> diff --git a/jit/spill-reload.c b/jit/spill-reload.c
> index f8d3230..ff74c33 100644
> --- a/jit/spill-reload.c
> +++ b/jit/spill-reload.c
> @@ -26,6 +26,7 @@
>
> #include <jit/compilation-unit.h>
> #include <jit/stack-slot.h>
> +#include <arch/instruction.h>
> #include <errno.h>
>
> static struct insn *last_insn(struct live_interval *interval)
> @@ -27,6 +27,20 @@
> #include <vm/vm.h>
> #include <stdlib.h>
>
> +struct object *create_null_pointer_exception()
You need 'void' here.
> +{
> + Class *exception = findSystemClass("java/lang/NullPointerException");
> + struct object *exp = allocObject(exception);
> + MethodBlock *init = lookupMethod(exception, "<init>",
> + "()V");
Please separate variable definitions and initialization.
> + if(exp && init)
> + executeMethod(exp, init);
> + else
> + abort(); /* TODO */
> +
> + return exp;
> +}
> +
> unsigned long is_object_instance_of(struct object *obj, struct object *type)
> {
> if (!obj)
------------------------------------------------------------------------------
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 asthey present alongside digital heavyweights like Barbarian
Group, R/GA, & Big Spaceship. http://www.creativitycat.com
_______________________________________________
Jatovm-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jatovm-devel