[PATCH 5/6] vm: Use preloaded classes for creating exceptions in VM
Signed-off-by: Tomek Grabiec --- include/jit/exception.h |2 +- include/vm/object.h |4 +--- include/vm/preload.h| 11 +++ jit/emulate.c |4 ++-- jit/exception.c |4 ++-- jit/trampoline.c|2 +- test/vm/object-stub.c |2 +- vm/jato.c | 12 ++-- vm/object.c | 27 +++ vm/preload.c| 23 ++- vm/signal.c |5 +++-- 11 files changed, 61 insertions(+), 35 deletions(-) diff --git a/include/jit/exception.h b/include/jit/exception.h index ca31cd5..83bf8bc 100644 --- a/include/jit/exception.h +++ b/include/jit/exception.h @@ -55,7 +55,7 @@ void throw_exception_from_signal(void *ctx, struct vm_object *exception); void throw_exception_from_trampoline(void *ctx, struct vm_object *exception); void unwind(void); void signal_exception(struct vm_object *obj); -void signal_new_exception(const char *class_name, const char *msg); +void signal_new_exception(struct vm_class *vmc, const char *msg); void clear_exception(void); void init_exceptions(void); void thread_init_exceptions(void); diff --git a/include/vm/object.h b/include/vm/object.h index 4196030..ead13b5 100644 --- a/include/vm/object.h +++ b/include/vm/object.h @@ -31,9 +31,7 @@ struct vm_object *vm_object_alloc_array(struct vm_class *class, int count); struct vm_object * vm_object_alloc_string_from_utf8(const uint8_t bytes[], unsigned int length); struct vm_object *vm_object_alloc_string_from_c(const char *bytes); - -struct vm_object *new_exception(const char *class_name, const char *message); - +struct vm_object *new_exception(struct vm_class *vmc, const char *message); bool vm_object_is_instance_of(const struct vm_object *obj, const struct vm_class *class); void vm_object_check_null(struct vm_object *obj); void vm_object_check_array(struct vm_object *obj, unsigned int index); diff --git a/include/vm/preload.h b/include/vm/preload.h index 4c46462..55ba334 100644 --- a/include/vm/preload.h +++ b/include/vm/preload.h @@ -9,6 +9,17 @@ extern struct vm_class *vm_java_util_Properties; extern struct vm_class *vm_java_lang_VMThrowable; extern struct vm_class *vm_java_lang_StackTraceElement; extern struct vm_class *vm_array_of_java_lang_StackTraceElement; +extern struct vm_class *vm_java_lang_Error; +extern struct vm_class *vm_java_lang_ArithmeticException; +extern struct vm_class *vm_java_lang_NullPointerException; +extern struct vm_class *vm_java_lang_NegativeArraySizeException; +extern struct vm_class *vm_java_lang_ClassCastException; +extern struct vm_class *vm_java_lang_NoClassDefFoundError; +extern struct vm_class *vm_java_lang_UnsatisfiedLinkError; +extern struct vm_class *vm_java_lang_ArrayIndexOutOfBoundsException; +extern struct vm_class *vm_java_lang_ArrayStoreException; +extern struct vm_class *vm_java_lang_RuntimeException; +extern struct vm_class *vm_java_lang_ExceptionInInitializerError; extern struct vm_class *vm_boolean_class; extern struct vm_class *vm_char_class; extern struct vm_class *vm_float_class; diff --git a/jit/emulate.c b/jit/emulate.c index 368b8b3..6c4cb93 100644 --- a/jit/emulate.c +++ b/jit/emulate.c @@ -74,7 +74,7 @@ long long emulate_ldiv(long long value1, long long value2) { if (value2 == 0) { signal_new_exception( - "java/lang/ArithmeticException", "division by zero"); + vm_java_lang_ArithmeticException, "division by zero"); throw_from_native(2 * sizeof(long long)); return 0; } @@ -86,7 +86,7 @@ long long emulate_lrem(long long value1, long long value2) { if (value2 == 0) { signal_new_exception( - "java/lang/ArithmeticException", "division by zero"); + vm_java_lang_ArithmeticException, "division by zero"); throw_from_native(2 * sizeof(long long)); return 0; } diff --git a/jit/exception.c b/jit/exception.c index 99179ae..20e2e1b 100644 --- a/jit/exception.c +++ b/jit/exception.c @@ -94,11 +94,11 @@ void signal_exception(struct vm_object *exception) exception_holder = exception; } -void signal_new_exception(const char *class_name, const char *msg) +void signal_new_exception(struct vm_class *vmc, const char *msg) { struct vm_object *e; - e = new_exception(class_name, msg); + e = new_exception(vmc, msg); signal_exception(e); } diff --git a/jit/trampoline.c b/jit/trampoline.c index c0ce053..faee0c4 100644 --- a/jit/trampoline.c +++ b/jit/trampoline.c @@ -70,7 +70,7 @@ static void *jit_native_trampoline(struct compilation_unit *cu) if (strcmp(class_name, "VMThrowable") == 0) die("no native function found for %s", msg->value); - signal_new_exception("java/lang/UnsatisfiedLinkError", msg->value); + signal_new_exception(vm_java_lang_UnsatisfiedLinkErr
[PATCH 6/6] vm: handle exceptions in class initialization correctly
The procedure is described in JVM spec: http://java.sun.com/docs/books/jvms/second_edition/html/Concepts.doc.html#24237 Signed-off-by: Tomek Grabiec --- arch/x86/emit-code.c| 13 - include/jit/exception.h |3 +++ include/vm/class.h |1 + include/vm/preload.h|1 + include/vm/signal.h |1 + include/vm/static.h |4 ++-- jit/exception.c | 21 + test/arch-x86/Makefile |1 + test/jit/Makefile |1 + test/vm/preload-stub.c |2 ++ test/vm/signal-stub.c |6 ++ vm/class.c | 27 ++- vm/jato.c |3 +++ vm/object.c | 16 vm/preload.c|8 vm/signal.c |3 +-- vm/static.c |4 +++- 17 files changed, 92 insertions(+), 23 deletions(-) create mode 100644 test/vm/signal-stub.c create mode 100644 vm/tmp diff --git a/arch/x86/emit-code.c b/arch/x86/emit-code.c index 20fc9a8..fe4e231 100644 --- a/arch/x86/emit-code.c +++ b/arch/x86/emit-code.c @@ -1273,12 +1273,12 @@ struct emitter emitters[] = { DECL_EMITTER(INSN_XOR_XMM_REG_REG, emit_xor_xmm_reg_reg, TWO_OPERANDS), }; -void fixup_static(struct vm_class *vmc) +int fixup_static(struct vm_class *vmc) { struct static_fixup_site *this, *next; if (vm_class_ensure_init(vmc)) - die("class wouldn't initialize.. oops"); + return -1; list_for_each_entry_safe(this, next, &vmc->static_fixup_site_list, vmc_node) @@ -1294,9 +1294,11 @@ void fixup_static(struct vm_class *vmc) list_del(&this->cu_node); free(this); } + + return 0; } -void fixup_static_at(unsigned long addr) +int fixup_static_at(unsigned long addr) { struct compilation_unit *cu; struct static_fixup_site *this; @@ -1310,10 +1312,11 @@ void fixup_static_at(unsigned long addr) + this->insn->mach_offset; if ((unsigned long) site_addr == addr) { - fixup_static(this->vmf->class); - return; + return fixup_static(this->vmf->class); } } + + return 0; } void emit_trampoline(struct compilation_unit *cu, diff --git a/include/jit/exception.h b/include/jit/exception.h index 83bf8bc..d5f5dc0 100644 --- a/include/jit/exception.h +++ b/include/jit/exception.h @@ -56,6 +56,9 @@ void throw_exception_from_trampoline(void *ctx, struct vm_object *exception); void unwind(void); void signal_exception(struct vm_object *obj); void signal_new_exception(struct vm_class *vmc, const char *msg); +void signal_new_exception_with_cause(struct vm_class *vmc, +struct vm_object *cause, +const char *msg); void clear_exception(void); void init_exceptions(void); void thread_init_exceptions(void); diff --git a/include/vm/class.h b/include/vm/class.h index a54321e..c8b9020 100644 --- a/include/vm/class.h +++ b/include/vm/class.h @@ -15,6 +15,7 @@ enum vm_class_state { VM_CLASS_LOADED, VM_CLASS_LINKED, VM_CLASS_INITIALIZING, + VM_CLASS_ERRONEOUS, VM_CLASS_INITIALIZED, }; diff --git a/include/vm/preload.h b/include/vm/preload.h index 55ba334..1f3a2e9 100644 --- a/include/vm/preload.h +++ b/include/vm/preload.h @@ -37,6 +37,7 @@ extern struct vm_field *vm_java_lang_Throwable_detailMessage; extern struct vm_field *vm_java_lang_VMThrowable_vmdata; extern struct vm_method *vm_java_util_Properties_setProperty; +extern struct vm_method *vm_java_lang_Throwable_initCause; int preload_vm_classes(void); diff --git a/include/vm/signal.h b/include/vm/signal.h index a188daf..55795e1 100644 --- a/include/vm/signal.h +++ b/include/vm/signal.h @@ -10,5 +10,6 @@ typedef unsigned long (*signal_bh_fn)(unsigned long); void setup_signal_handlers(void); int install_signal_bh(void *ctx, signal_bh_fn bh); +unsigned long throw_from_signal_bh(unsigned long jit_addr); #endif /* VM_SIGNAL_H */ diff --git a/include/vm/static.h b/include/vm/static.h index d41711d..e7e6104 100644 --- a/include/vm/static.h +++ b/include/vm/static.h @@ -28,8 +28,8 @@ int add_getstatic_fixup_site(struct insn *insn, int add_putstatic_fixup_site(struct insn *insn, struct vm_field *vmf, struct compilation_unit *cu); -void fixup_static(struct vm_class *vmc); -void fixup_static_at(unsigned long addr); +int fixup_static(struct vm_class *vmc); +int fixup_static_at(unsigned long addr); extern unsigned long static_field_signal_bh(unsigned long ret); diff --git a/jit/exception.c b/jit/exception.c index 20e2e1b..a0a26cb 100644 --- a/jit/exception.c +++ b/jit/exception.c @@ -39,6 +39,7 @@ #include #include #include +#include #include #include @@ -102,6 +103,26 @@ void signal_new_exception(struct vm_class *vmc, const char *msg)
[PATCH 4/6] vm: fix warnings in jit/trace-jit.c
Signed-off-by: Tomek Grabiec --- jit/trace-jit.c |2 ++ test/jit/trace-stub.c |2 ++ 2 files changed, 4 insertions(+), 0 deletions(-) diff --git a/jit/trace-jit.c b/jit/trace-jit.c index bfcce4e..87176b6 100644 --- a/jit/trace-jit.c +++ b/jit/trace-jit.c @@ -26,6 +26,8 @@ #include #include +#include + #include #include #include diff --git a/test/jit/trace-stub.c b/test/jit/trace-stub.c index 08bb9fc..0f1466e 100644 --- a/test/jit/trace-stub.c +++ b/test/jit/trace-stub.c @@ -1,5 +1,7 @@ #include +#include "arch/stack-frame.h" + struct compilation_unit; bool opt_trace_invoke = false; -- 1.6.0.6 -- ___ Jatovm-devel mailing list Jatovm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jatovm-devel
[PATCH 2/6] vm: convert vm/stack-trace.c to new JatoVM interface
Cleanup fallouts from JamVM and re-enable natives for VMThrowable.fillInStackTrace() and VMThrowable.getStackTrace(). Signed-off-by: Tomek Grabiec --- include/vm/java_lang.h |5 ++- include/vm/object.h | 12 + include/vm/stack-trace.h |5 +- vm/jato.c| 24 -- vm/stack-trace.c | 117 + 5 files changed, 72 insertions(+), 91 deletions(-) diff --git a/include/vm/java_lang.h b/include/vm/java_lang.h index 06ed716..cb9d150 100644 --- a/include/vm/java_lang.h +++ b/include/vm/java_lang.h @@ -6,7 +6,9 @@ extern struct vm_class *vm_java_lang_Class; extern struct vm_class *vm_java_lang_String; extern struct vm_class *vm_java_lang_Throwable; extern struct vm_class *vm_java_util_Properties; - +extern struct vm_class *vm_java_lang_VMThrowable; +extern struct vm_class *vm_java_lang_StackTraceElement; +extern struct vm_class *vm_array_of_java_lang_StackTraceElement; extern struct vm_class *vm_boolean_class; extern struct vm_class *vm_char_class; extern struct vm_class *vm_float_class; @@ -21,6 +23,7 @@ extern struct vm_field *vm_java_lang_String_offset; extern struct vm_field *vm_java_lang_String_count; extern struct vm_field *vm_java_lang_String_value; extern struct vm_field *vm_java_lang_Throwable_detailMessage; +extern struct vm_field *vm_java_lang_VMThrowable_vmdata; extern struct vm_method *vm_java_util_Properties_setProperty; diff --git a/include/vm/object.h b/include/vm/object.h index a38a1d3..4196030 100644 --- a/include/vm/object.h +++ b/include/vm/object.h @@ -84,4 +84,16 @@ array_get_field_char(struct vm_object *obj, int index) return *(uint16_t *) &obj->fields[index * get_vmtype_size(J_CHAR)]; } +static inline void +array_set_field_ptr(struct vm_object *obj, int index, void *value) +{ + *(void **) &obj->fields[index * get_vmtype_size(J_REFERENCE)] = value; +} + +static inline void * +array_get_field_ptr(struct vm_object *obj, int index) +{ + return *(void **) &obj->fields[index * get_vmtype_size(J_REFERENCE)]; +} + #endif diff --git a/include/vm/stack-trace.h b/include/vm/stack-trace.h index 8759ced..953afc8 100644 --- a/include/vm/stack-trace.h +++ b/include/vm/stack-trace.h @@ -41,9 +41,8 @@ struct vm_object *get_stack_trace(struct stack_trace_elem *); struct vm_object *get_stack_trace_from_ctx(void *ctx); struct vm_object *convert_stack_trace(struct vm_object *vmthrowable); struct vm_object *new_stack_trace_element(struct vm_method *, unsigned long); -struct vm_object * __vm_native vm_throwable_fill_in_stack_trace(struct vm_object *); -struct vm_object * __vm_native vm_throwable_get_stack_trace(struct vm_object *, struct vm_object *); -void set_throwable_vmstate(struct vm_object *throwable, struct vm_object *vmstate); +struct vm_object * __vm_native native_vmthrowable_fill_in_stack_trace(struct vm_object *); +struct vm_object * __vm_native native_vmthrowable_get_stack_trace(struct vm_object *, struct vm_object *); bool called_from_jit_trampoline(struct native_stack_frame *frame); void vm_print_exception(struct vm_object *exception); diff --git a/vm/jato.c b/vm/jato.c index 439c237..2567ad7 100644 --- a/vm/jato.c +++ b/vm/jato.c @@ -156,19 +156,6 @@ static int32_t __vm_native native_vmsystem_identityhashcode(struct vm_object *ob return (int32_t) obj; } -/* - * This stub is needed by java.lang.VMThrowable constructor to work. It should - * return java.lang.VMState instance, or null in which case no stack trace will - * be printed by printStackTrace() method. - */ -static struct vm_object * __vm_native -native_vmthrowable_fill_in_stack_trace(struct vm_object *message) -{ - NOT_IMPLEMENTED; - - return NULL; -} - static struct vm_object * __vm_native native_vmobject_getclass(struct vm_object *object) { @@ -220,6 +207,7 @@ static struct vm_native natives[] = { DEFINE_NATIVE("java/lang/VMSystem", "arraycopy", &native_vmsystem_arraycopy), DEFINE_NATIVE("java/lang/VMSystem", "identityHashCode", &native_vmsystem_identityhashcode), DEFINE_NATIVE("java/lang/VMThrowable", "fillInStackTrace", &native_vmthrowable_fill_in_stack_trace), + DEFINE_NATIVE("java/lang/VMThrowable", "getStackTrace", &native_vmthrowable_get_stack_trace), }; static void jit_init_natives(void) @@ -240,7 +228,9 @@ struct vm_class *vm_java_lang_Class; struct vm_class *vm_java_lang_String; struct vm_class *vm_java_lang_Throwable; struct vm_class *vm_java_util_Properties; - +struct vm_class *vm_java_lang_VMThrowable; +struct vm_class *vm_java_lang_StackTraceElement; +struct vm_class *vm_array_of_java_lang_StackTraceElement; struct vm_class *vm_boolean_class; struct vm_class *vm_char_class; struct vm_class *vm_float_class; @@ -256,6 +246,10 @@ static const struct preload_entry preload_entries[] = { { "java/lang/String", &vm_java_lang_String }, { "java/lang/Throwable",&vm_java_lang_Throwable },
[PATCH 1/6] test: fix 'make test' breakage
Introduced by commit "x86 implement INT -> CHAR conversion" Signed-off-by: Tomek Grabiec --- test/arch-x86/emit-code-test_32.c |6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/arch-x86/emit-code-test_32.c b/test/arch-x86/emit-code-test_32.c index f024f62..64ea6cc 100644 --- a/test/arch-x86/emit-code-test_32.c +++ b/test/arch-x86/emit-code-test_32.c @@ -288,10 +288,10 @@ void test_emit_mov_reg_reg(void) assert_emit_insn_2(0x89, 0xd9, reg_reg_insn(INSN_MOV_REG_REG, &VAR_EBX, &VAR_ECX)); } -void test_emit_movsx_reg_reg(void) +void test_emit_movsx_8_reg_reg(void) { - assert_emit_insn_3(0x0f, 0xbe, 0xc2, reg_reg_insn(INSN_MOVSX_REG_REG, &VAR_EDX, &VAR_EAX)); - assert_emit_insn_3(0x0f, 0xbe, 0xcb, reg_reg_insn(INSN_MOVSX_REG_REG, &VAR_EBX, &VAR_ECX)); + assert_emit_insn_3(0x0f, 0xbe, 0xc2, reg_reg_insn(INSN_MOVSX_8_REG_REG, &VAR_EDX, &VAR_EAX)); + assert_emit_insn_3(0x0f, 0xbe, 0xcb, reg_reg_insn(INSN_MOVSX_8_REG_REG, &VAR_EBX, &VAR_ECX)); } void test_emit_adc_disp_reg(void) { -- 1.6.0.6 -- ___ Jatovm-devel mailing list Jatovm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jatovm-devel
[PATCH 3/6] vm: move preloading code to vm/preload.c
Rename include/vm/java_lang.h to include/vm/preload.h Signed-off-by: Tomek Grabiec --- Makefile |3 +- include/vm/java_lang.h | 30 include/vm/preload.h | 32 jit/emulate.c|1 + jit/trace-jit.c |2 +- jit/trampoline.c |1 + test/arch-x86/Makefile |2 +- test/vm/java_lang-stub.c | 11 --- test/vm/preload-stub.c | 23 ++ vm/class.c |2 +- vm/classloader.c |2 +- vm/jato.c| 148 +-- vm/object.c |2 +- vm/preload.c | 177 ++ vm/stack-trace.c |2 +- 15 files changed, 243 insertions(+), 195 deletions(-) delete mode 100644 include/vm/java_lang.h create mode 100644 include/vm/preload.h delete mode 100644 test/vm/java_lang-stub.c create mode 100644 test/vm/preload-stub.c create mode 100644 vm/preload.c diff --git a/Makefile b/Makefile index 73df9b4..640e2dd 100644 --- a/Makefile +++ b/Makefile @@ -106,7 +106,8 @@ VM_OBJS = \ vm/static.o \ vm/types.o \ vm/utf8.o \ - vm/zalloc.o + vm/zalloc.o \ + vm/preload.o LIB_OBJS = \ lib/bitset.o\ diff --git a/include/vm/java_lang.h b/include/vm/java_lang.h deleted file mode 100644 index cb9d150..000 --- a/include/vm/java_lang.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef _VM_JAVA_LANG_H -#define _VM_JAVA_LANG_H - -extern struct vm_class *vm_java_lang_Object; -extern struct vm_class *vm_java_lang_Class; -extern struct vm_class *vm_java_lang_String; -extern struct vm_class *vm_java_lang_Throwable; -extern struct vm_class *vm_java_util_Properties; -extern struct vm_class *vm_java_lang_VMThrowable; -extern struct vm_class *vm_java_lang_StackTraceElement; -extern struct vm_class *vm_array_of_java_lang_StackTraceElement; -extern struct vm_class *vm_boolean_class; -extern struct vm_class *vm_char_class; -extern struct vm_class *vm_float_class; -extern struct vm_class *vm_double_class; -extern struct vm_class *vm_byte_class; -extern struct vm_class *vm_short_class; -extern struct vm_class *vm_int_class; -extern struct vm_class *vm_long_class; - -extern struct vm_field *vm_java_lang_Class_vmdata; -extern struct vm_field *vm_java_lang_String_offset; -extern struct vm_field *vm_java_lang_String_count; -extern struct vm_field *vm_java_lang_String_value; -extern struct vm_field *vm_java_lang_Throwable_detailMessage; -extern struct vm_field *vm_java_lang_VMThrowable_vmdata; - -extern struct vm_method *vm_java_util_Properties_setProperty; - -#endif diff --git a/include/vm/preload.h b/include/vm/preload.h new file mode 100644 index 000..4c46462 --- /dev/null +++ b/include/vm/preload.h @@ -0,0 +1,32 @@ +#ifndef _VM_JAVA_LANG_H +#define _VM_JAVA_LANG_H + +extern struct vm_class *vm_java_lang_Object; +extern struct vm_class *vm_java_lang_Class; +extern struct vm_class *vm_java_lang_String; +extern struct vm_class *vm_java_lang_Throwable; +extern struct vm_class *vm_java_util_Properties; +extern struct vm_class *vm_java_lang_VMThrowable; +extern struct vm_class *vm_java_lang_StackTraceElement; +extern struct vm_class *vm_array_of_java_lang_StackTraceElement; +extern struct vm_class *vm_boolean_class; +extern struct vm_class *vm_char_class; +extern struct vm_class *vm_float_class; +extern struct vm_class *vm_double_class; +extern struct vm_class *vm_byte_class; +extern struct vm_class *vm_short_class; +extern struct vm_class *vm_int_class; +extern struct vm_class *vm_long_class; + +extern struct vm_field *vm_java_lang_Class_vmdata; +extern struct vm_field *vm_java_lang_String_offset; +extern struct vm_field *vm_java_lang_String_count; +extern struct vm_field *vm_java_lang_String_value; +extern struct vm_field *vm_java_lang_Throwable_detailMessage; +extern struct vm_field *vm_java_lang_VMThrowable_vmdata; + +extern struct vm_method *vm_java_util_Properties_setProperty; + +int preload_vm_classes(void); + +#endif diff --git a/jit/emulate.c b/jit/emulate.c index d64eaa2..368b8b3 100644 --- a/jit/emulate.c +++ b/jit/emulate.c @@ -28,6 +28,7 @@ #include #include #include +#include int emulate_lcmp(long long value1, long long value2) { diff --git a/jit/trace-jit.c b/jit/trace-jit.c index 89158e2..bfcce4e 100644 --- a/jit/trace-jit.c +++ b/jit/trace-jit.c @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include diff --git a/jit/trampoline.c b/jit/trampoline.c index 40c8eca..c0ce053 100644 --- a/jit/trampoline.c +++ b/jit/trampoline.c @@ -29,6 +29,7 @@ #include #include +#include #include #include #include diff --git a/test/arch-x86/Makefile b/test/arch-x86/Makefile index 21d039c..2470e2d 100644 --- a/test/arch-x86/Makefile +++ b/test/arch-x86/Makefile @@ -79,7 +79,7 @@ OBJS = \ ../jit/trace-stub.o \ ../libharness/libharness.o \
Re: [PATCH 2/2] vm: set java.io.tmpdir property to /tmp
2009/7/3 Tomek Grabiec : > > Signed-off-by: Tomek Grabiec > --- > vm/jato.c | 4 > 1 files changed, 4 insertions(+), 0 deletions(-) > > diff --git a/vm/jato.c b/vm/jato.c > index 739093f..5652d50 100644 > --- a/vm/jato.c > +++ b/vm/jato.c > @@ -78,6 +78,10 @@ static void __vm_native > native_vmsystemproperties_preinit(struct vm_object *p) > = > vm_method_trampoline_ptr(vm_java_util_Properties_setProperty); > > trampoline(p, key, value); > + > + key = vm_object_alloc_string_from_c("java.io.tmpdir"); > + value = vm_object_alloc_string_from_c("/tmp"); > + trampoline(p, key, value); > } Note (mostly to self): I would like to see this implemented with a table instead. Will try to fix that once I've run out of other things to do ;-) [Not that it should be very difficult or anything...] Vegard -- ___ Jatovm-devel mailing list Jatovm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jatovm-devel
[PATCH 2/2] vm: set java.io.tmpdir property to /tmp
Signed-off-by: Tomek Grabiec --- vm/jato.c |4 1 files changed, 4 insertions(+), 0 deletions(-) diff --git a/vm/jato.c b/vm/jato.c index 739093f..5652d50 100644 --- a/vm/jato.c +++ b/vm/jato.c @@ -78,6 +78,10 @@ static void __vm_native native_vmsystemproperties_preinit(struct vm_object *p) = vm_method_trampoline_ptr(vm_java_util_Properties_setProperty); trampoline(p, key, value); + + key = vm_object_alloc_string_from_c("java.io.tmpdir"); + value = vm_object_alloc_string_from_c("/tmp"); + trampoline(p, key, value); } static void __vm_native native_vmruntime_exit(int status) -- 1.6.0.6 -- ___ Jatovm-devel mailing list Jatovm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jatovm-devel
[PATCH 1/2] x86 implement INT -> CHAR conversion
Signed-off-by: Tomek Grabiec --- arch/x86/emit-code.c| 12 ++-- arch/x86/include/arch/instruction.h |3 ++- arch/x86/insn-selector_32.brg |6 +- arch/x86/lir-printer.c | 12 ++-- arch/x86/use-def.c |3 ++- 5 files changed, 29 insertions(+), 7 deletions(-) diff --git a/arch/x86/emit-code.c b/arch/x86/emit-code.c index 2a63e50..20fc9a8 100644 --- a/arch/x86/emit-code.c +++ b/arch/x86/emit-code.c @@ -604,13 +604,20 @@ static void emit_mov_reg_reg(struct buffer *buf, struct operand *src, __emit_mov_reg_reg(buf, mach_reg(&src->reg), mach_reg(&dest->reg)); } -static void emit_movsx_reg_reg(struct buffer *buf, struct operand *src, +static void emit_movsx_8_reg_reg(struct buffer *buf, struct operand *src, struct operand *dest) { emit(buf, 0x0f); __emit_reg_reg(buf, 0xbe, mach_reg(&dest->reg), mach_reg(&src->reg)); } +static void emit_movsx_16_reg_reg(struct buffer *buf, struct operand *src, +struct operand *dest) +{ + emit(buf, 0x0f); + __emit_reg_reg(buf, 0xbf, mach_reg(&dest->reg), mach_reg(&src->reg)); +} + static void emit_mov_memlocal_reg(struct buffer *buf, struct operand *src, struct operand *dest) { @@ -1237,7 +1244,8 @@ struct emitter emitters[] = { DECL_EMITTER(INSN_MOV_REG_MEMLOCAL, emit_mov_reg_memlocal, TWO_OPERANDS), DECL_EMITTER(INSN_MOV_FREG_MEMLOCAL, emit_mov_freg_memlocal, TWO_OPERANDS), DECL_EMITTER(INSN_MOV_REG_REG, emit_mov_reg_reg, TWO_OPERANDS), - DECL_EMITTER(INSN_MOVSX_REG_REG, emit_movsx_reg_reg, TWO_OPERANDS), + DECL_EMITTER(INSN_MOVSX_8_REG_REG, emit_movsx_8_reg_reg, TWO_OPERANDS), + DECL_EMITTER(INSN_MOVSX_16_REG_REG, emit_movsx_16_reg_reg, TWO_OPERANDS), DECL_EMITTER(INSN_MUL_MEMBASE_EAX, emit_mul_membase_eax, TWO_OPERANDS), DECL_EMITTER(INSN_MUL_REG_EAX, emit_mul_reg_eax, TWO_OPERANDS), DECL_EMITTER(INSN_MUL_REG_REG, emit_mul_reg_reg, TWO_OPERANDS), diff --git a/arch/x86/include/arch/instruction.h b/arch/x86/include/arch/instruction.h index 42c3fbb..c852bd3 100644 --- a/arch/x86/include/arch/instruction.h +++ b/arch/x86/include/arch/instruction.h @@ -101,7 +101,8 @@ enum insn_type { INSN_MOV_REG_REG, INSN_MOV_MEMBASE_XMM, INSN_MOV_XMM_MEMBASE, - INSN_MOVSX_REG_REG, + INSN_MOVSX_8_REG_REG, + INSN_MOVSX_16_REG_REG, INSN_MUL_MEMBASE_EAX, INSN_MUL_REG_EAX, INSN_MUL_REG_REG, diff --git a/arch/x86/insn-selector_32.brg b/arch/x86/insn-selector_32.brg index 4d582a0..02e0cf2 100644 --- a/arch/x86/insn-selector_32.brg +++ b/arch/x86/insn-selector_32.brg @@ -1291,7 +1291,11 @@ reg: EXPR_CONVERSION(reg) } else if (src->vm_type == J_INT && expr->vm_type == J_BYTE) { state->reg1 = get_var(s->b_parent); - select_insn(s, tree, reg_reg_insn(INSN_MOVSX_REG_REG, state->left->reg1, state->reg1)); + select_insn(s, tree, reg_reg_insn(INSN_MOVSX_8_REG_REG, state->left->reg1, state->reg1)); + } else if (src->vm_type == J_INT && expr->vm_type == J_CHAR) { + state->reg1 = get_var(s->b_parent); + + select_insn(s, tree, reg_reg_insn(INSN_MOVSX_16_REG_REG, state->left->reg1, state->reg1)); } else { printf("%d to %d\n", src->vm_type, expr->vm_type); assert(!"conversion not implemented"); diff --git a/arch/x86/lir-printer.c b/arch/x86/lir-printer.c index ba0d276..b5abf63 100644 --- a/arch/x86/lir-printer.c +++ b/arch/x86/lir-printer.c @@ -460,13 +460,20 @@ static int print_mov_reg_reg(struct string *str, struct insn *insn) return print_reg_reg(str, insn); } -static int print_movsx_reg_reg(struct string *str, struct insn *insn) +static int print_movsx_8_reg_reg(struct string *str, struct insn *insn) { print_func_name(str); print_reg_reg(str, insn); return str_append(str, "(8bit->32bit)"); } +static int print_movsx_16_reg_reg(struct string *str, struct insn *insn) +{ + print_func_name(str); + print_reg_reg(str, insn); + return str_append(str, "(16bit->32bit)"); +} + static int print_mul_membase_eax(struct string *str, struct insn *insn) { print_func_name(str); @@ -672,7 +679,8 @@ static print_insn_fn insn_printers[] = { [INSN_MOV_REG_MEMLOCAL] = print_mov_reg_memlocal, [INSN_MOV_FREG_MEMLOCAL] = print_mov_freg_memlocal, [INSN_MOV_REG_REG] = print_mov_reg_reg, - [INSN_MOVSX_REG_REG] = print_movsx_reg_reg, + [INSN_MOVSX_8_REG_REG] = print_movsx_8_reg_reg, + [INSN_MOVSX_16_REG_REG] = print_movsx_16_reg_reg, [INSN_MUL_MEMBASE_EAX] = print_mul_membase_eax, [INSN_MUL_REG_EAX] = print_mul_reg_eax, [INSN_MUL_REG_REG] = print_mul_reg_reg, diff --git a/arch/x86/use-def.c b/arch/x86/use-def.c index 6e5a02c..10c2dcf 100644 --- a/arch/x86/
Re: [PATCH] x86: factorize code for INVOKE and FINVOKE
applied -- ___ Jatovm-devel mailing list Jatovm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jatovm-devel
Re: [PATCH] x86: factorize code for INVOKEVIRTUAL and FINVOKEVIRTUAL
applied -- ___ Jatovm-devel mailing list Jatovm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jatovm-devel
Re: [PATCH] Makefile: remove .class files from runtime/ on 'make clean'
applied -- ___ Jatovm-devel mailing list Jatovm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jatovm-devel
[PATCH] Makefile: remove .class files from runtime/ on 'make clean'
Signed-off-by: Tomek Grabiec --- Makefile |1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/Makefile b/Makefile index dd2febe..73df9b4 100644 --- a/Makefile +++ b/Makefile @@ -271,6 +271,7 @@ clean: $(Q) - rm -f $(REGRESSION_TEST_SUITE_CLASSES) $(Q) - rm -f $(RUNTIME_CLASSES) $(Q) - find regression/ -name "*.class" | xargs rm -f + $(Q) - find runtime/ -name "*.class" | xargs rm -f $(Q) - rm -f tags $(Q) - rm -f include/arch $(Q) - make -C monoburg/ clean -- 1.6.0.6 -- ___ Jatovm-devel mailing list Jatovm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jatovm-devel
[PATCH] x86: floating point returning is now ABI conformant
We use the top of the x87 stack as is specified by the i386 SystemV ABI. Signed-off-by: Arthur Huillet --- arch/x86/emit-code.c| 12 +++ arch/x86/include/arch/instruction.h |3 + arch/x86/insn-selector_32.brg | 126 ++- arch/x86/instruction.c | 10 +++ arch/x86/lir-printer.c | 14 arch/x86/use-def.c |2 + include/jit/expression.h|8 ++- jit/expression.c| 20 ++ jit/invoke-bc.c | 18 - jit/tree-printer.c |2 + 10 files changed, 210 insertions(+), 5 deletions(-) diff --git a/arch/x86/emit-code.c b/arch/x86/emit-code.c index bb5b299..2a63e50 100644 --- a/arch/x86/emit-code.c +++ b/arch/x86/emit-code.c @@ -894,6 +894,16 @@ static void emit_fdiv_reg_reg(struct buffer *buf, emit_reg_reg(buf, 0x5e, dest, src); } +static void emit_fld_membase(struct buffer *buf, struct operand *src) +{ + __emit_membase(buf, 0xd9, mach_reg(&src->base_reg), src->disp, 0); +} + +static void emit_fstp_membase(struct buffer *buf, struct operand *dest) +{ + __emit_membase(buf, 0xd9, mach_reg(&dest->base_reg), dest->disp, 3); +} + static void emit_add_membase_reg(struct buffer *buf, struct operand *src, struct operand *dest) { @@ -1207,6 +1217,8 @@ struct emitter emitters[] = { DECL_EMITTER(INSN_FSUB_REG_REG, emit_fsub_reg_reg, TWO_OPERANDS), DECL_EMITTER(INSN_FMUL_REG_REG, emit_fmul_reg_reg, TWO_OPERANDS), DECL_EMITTER(INSN_FDIV_REG_REG, emit_fdiv_reg_reg, TWO_OPERANDS), + DECL_EMITTER(INSN_FLD_MEMBASE, emit_fld_membase, TWO_OPERANDS), + DECL_EMITTER(INSN_FSTP_MEMBASE, emit_fstp_membase, TWO_OPERANDS), DECL_EMITTER(INSN_CONV_GPR_TO_FPU, emit_conv_gpr_to_fpu, TWO_OPERANDS), DECL_EMITTER(INSN_CONV_FPU_TO_GPR, emit_conv_fpu_to_gpr, TWO_OPERANDS), DECL_EMITTER(INSN_MOV_MEMBASE_XMM, emit_mov_membase_xmm, TWO_OPERANDS), diff --git a/arch/x86/include/arch/instruction.h b/arch/x86/include/arch/instruction.h index 056480f..42c3fbb 100644 --- a/arch/x86/include/arch/instruction.h +++ b/arch/x86/include/arch/instruction.h @@ -74,6 +74,8 @@ enum insn_type { INSN_FMUL_REG_REG, INSN_FDIV_REG_REG, INSN_FSUB_REG_REG, + INSN_FLD_MEMBASE, + INSN_FSTP_MEMBASE, INSN_CONV_FPU_TO_GPR, INSN_CONV_GPR_TO_FPU, INSN_JE_BRANCH, @@ -197,6 +199,7 @@ struct insn *imm_insn(enum insn_type, unsigned long); struct insn *rel_insn(enum insn_type, unsigned long); struct insn *branch_insn(enum insn_type, struct basic_block *); struct insn *memlocal_insn(enum insn_type, struct stack_slot *); +struct insn *membase_insn(enum insn_type, struct var_info *, long); /* * These functions are used by generic code to insert spill/reload diff --git a/arch/x86/insn-selector_32.brg b/arch/x86/insn-selector_32.brg index 86d81b9..1ba67b9 100644 --- a/arch/x86/insn-selector_32.brg +++ b/arch/x86/insn-selector_32.brg @@ -705,6 +705,63 @@ reg: EXPR_INVOKE(arg) 1 select_insn(s, tree, reg_reg_insn(INSN_MOV_REG_REG, edx, state->reg2)); } +freg: EXPR_FINVOKE(arg) 1 +{ + struct compilation_unit *cu; + struct vm_method *method; + struct expression *expr; + struct insn *call_insn; + bool is_compiled; + void *target; + struct var_info *esp; + + expr= to_expr(tree); + method = expr->target_method; + cu = method->compilation_unit; + + if (cu == s->b_parent) { + /* +* This is a recursive method invocation. Threfore, we are +* already holding cu->mutex here because we entered +* instruction selection through jit_magic_trampoline(). +*/ + is_compiled = false; + target = vm_method_trampoline_ptr(method); + } else { + pthread_mutex_lock(&cu->mutex); + is_compiled = cu->is_compiled; + + if (is_compiled) + target = vm_method_native_ptr(method); + else + target = vm_method_trampoline_ptr(method); + + pthread_mutex_unlock(&cu->mutex); + } + + state->reg1 = get_fpu_var(s->b_parent); + + call_insn = rel_insn(INSN_CALL_REL, (unsigned long) target); + select_insn(s, tree, call_insn); + + if (!is_compiled) { + struct fixup_site *fixup; + + fixup = alloc_fixup_site(); + fixup->cu = s->b_parent; + fixup->relcall_insn = call_insn; + + trampoline_add_fixup_site(method->trampoline, fixup); + } + + if (method->args_count) + method_args_cleanup(s, tree, method->args_count); + + esp = get_fixed_var(s->b_parent, REG_ESP); + select_insn(s, tree, membase_insn(INSN_FSTP_MEMBASE, es
[PATCH] x86: factorize code for INVOKE and FINVOKE
Signed-off-by: Arthur Huillet --- arch/x86/insn-selector_32.brg | 125 - 1 files changed, 48 insertions(+), 77 deletions(-) diff --git a/arch/x86/insn-selector_32.brg b/arch/x86/insn-selector_32.brg index 35d9ecb..857f2a9 100644 --- a/arch/x86/insn-selector_32.brg +++ b/arch/x86/insn-selector_32.brg @@ -669,34 +669,11 @@ reg: EXPR_INVOKE(arg) 1 struct compilation_unit *cu; struct vm_method *method; struct expression *expr; - struct insn *call_insn; - bool is_compiled; - void *target; expr= to_expr(tree); method = expr->target_method; cu = method->compilation_unit; - if (cu == s->b_parent) { - /* -* This is a recursive method invocation. Threfore, we are -* already holding cu->mutex here because we entered -* instruction selection through jit_magic_trampoline(). -*/ - is_compiled = false; - target = vm_method_trampoline_ptr(method); - } else { - pthread_mutex_lock(&cu->mutex); - is_compiled = cu->is_compiled; - - if (is_compiled) - target = vm_method_native_ptr(method); - else - target = vm_method_trampoline_ptr(method); - - pthread_mutex_unlock(&cu->mutex); - } - eax = get_fixed_var(s->b_parent, REG_EAX); state->reg1 = get_var(s->b_parent); @@ -705,21 +682,7 @@ reg: EXPR_INVOKE(arg) 1 state->reg2 = get_var(s->b_parent); } - call_insn = rel_insn(INSN_CALL_REL, (unsigned long) target); - select_insn(s, tree, call_insn); - - if (!is_compiled) { - struct fixup_site *fixup; - - fixup = alloc_fixup_site(); - fixup->cu = s->b_parent; - fixup->relcall_insn = call_insn; - - trampoline_add_fixup_site(method->trampoline, fixup); - } - - if (method->args_count) - method_args_cleanup(s, tree, method->args_count); + invoke(s, tree, cu, method); select_insn(s, tree, reg_reg_insn(INSN_MOV_REG_REG, eax, state->reg1)); if (edx != NULL) @@ -731,52 +694,15 @@ freg: EXPR_FINVOKE(arg) 1 struct compilation_unit *cu; struct vm_method *method; struct expression *expr; - struct insn *call_insn; - bool is_compiled; - void *target; struct var_info *esp; expr= to_expr(tree); method = expr->target_method; cu = method->compilation_unit; - if (cu == s->b_parent) { - /* -* This is a recursive method invocation. Threfore, we are -* already holding cu->mutex here because we entered -* instruction selection through jit_magic_trampoline(). -*/ - is_compiled = false; - target = vm_method_trampoline_ptr(method); - } else { - pthread_mutex_lock(&cu->mutex); - is_compiled = cu->is_compiled; - - if (is_compiled) - target = vm_method_native_ptr(method); - else - target = vm_method_trampoline_ptr(method); - - pthread_mutex_unlock(&cu->mutex); - } - state->reg1 = get_fpu_var(s->b_parent); - - call_insn = rel_insn(INSN_CALL_REL, (unsigned long) target); - select_insn(s, tree, call_insn); - - if (!is_compiled) { - struct fixup_site *fixup; - - fixup = alloc_fixup_site(); - fixup->cu = s->b_parent; - fixup->relcall_insn = call_insn; - - trampoline_add_fixup_site(method->trampoline, fixup); - } - - if (method->args_count) - method_args_cleanup(s, tree, method->args_count); + + invoke(s, tree, cu, method); esp = get_fixed_var(s->b_parent, REG_ESP); select_insn(s, tree, membase_insn(INSN_FSTP_MEMBASE, esp, -4)); @@ -1869,6 +1795,51 @@ emulate_op_64(struct _MBState *state, struct basic_block *s, select_insn(s, tree, reg_reg_insn(INSN_MOV_REG_REG, edx, state->reg2)); } +static void invoke(struct basic_block *s, struct tree_node *tree, struct compilation_unit *cu, struct vm_method *method) +{ + bool is_compiled; + struct insn *call_insn; + void *target; + + if (cu == s->b_parent) { + /* +* This is a recursive method invocation. Threfore, we are +* already holding cu->mutex here because we entered +* instruction selection through jit_magic_trampoline(). +*/ + is_compiled = false; + target = vm_method_trampoline_ptr(method); + } else { + pthread_mutex_lock(&cu->mutex)
[PATCH] x86: factorize code for INVOKEVIRTUAL and FINVOKEVIRTUAL
Signed-off-by: Arthur Huillet --- arch/x86/insn-selector_32.brg | 108 +++-- 1 files changed, 40 insertions(+), 68 deletions(-) diff --git a/arch/x86/insn-selector_32.brg b/arch/x86/insn-selector_32.brg index 0e8e84f..35d9ecb 100644 --- a/arch/x86/insn-selector_32.brg +++ b/arch/x86/insn-selector_32.brg @@ -786,19 +786,11 @@ freg: EXPR_FINVOKE(arg) 1 reg: EXPR_INVOKEVIRTUAL(arg) 1 { struct var_info *eax, *edx = NULL; - struct expression *objectref_expr; - struct var_info *call_target; - struct compilation_unit *cu; - unsigned long method_offset; struct vm_method *method; - unsigned long args_count; struct expression *expr; expr= to_expr(tree); method = expr->target_method; - cu = method->compilation_unit; - - method_offset = expr_method_index(expr) * sizeof(void *); eax = get_fixed_var(s->b_parent, REG_EAX); state->reg1 = get_var(s->b_parent); @@ -808,31 +800,7 @@ reg: EXPR_INVOKEVIRTUAL(arg) 1 state->reg2 = get_var(s->b_parent); } - /* object reference */ - objectref_expr = get_first_arg(expr->args_list); - - if (expr_type(objectref_expr) == EXPR_VALUE) { - call_target = get_var(s->b_parent); - select_insn(s, tree, imm_reg_insn(INSN_MOV_IMM_REG, objectref_expr->value, call_target)); - } else { - call_target = state->left->reg1; - } - - /* object class */ - select_insn(s, tree, membase_reg_insn(INSN_MOV_MEMBASE_REG, call_target, offsetof(struct vm_object, class), call_target)); - - /* vtable */ - select_insn(s, tree, membase_reg_insn(INSN_MOV_MEMBASE_REG, call_target, offsetof(struct vm_class, vtable), call_target)); - - /* native ptr */ - select_insn(s, tree, imm_reg_insn(INSN_ADD_IMM_REG, method_offset, call_target)); - - /* invoke method */ - select_insn(s, tree, reg_insn(INSN_CALL_REG, call_target)); - - args_count = nr_args(to_expr(expr->args_list)); - if (args_count) - method_args_cleanup(s, tree, args_count); + invokevirtual(state, s, tree); select_insn(s, tree, reg_reg_insn(INSN_MOV_REG_REG, eax, state->reg1)); if (edx != NULL) @@ -842,47 +810,13 @@ reg: EXPR_INVOKEVIRTUAL(arg) 1 freg: EXPR_FINVOKEVIRTUAL(arg) 1 { struct var_info *esp; - struct expression *objectref_expr; - struct var_info *call_target; - struct compilation_unit *cu; - unsigned long method_offset; - struct vm_method *method; - unsigned long args_count; struct expression *expr; expr= to_expr(tree); - method = expr->target_method; - cu = method->compilation_unit; - - method_offset = expr_method_index(expr) * sizeof(void *); state->reg1 = get_fpu_var(s->b_parent); - /* object reference */ - objectref_expr = get_first_arg(expr->args_list); - - if (expr_type(objectref_expr) == EXPR_VALUE) { - call_target = get_var(s->b_parent); - select_insn(s, tree, imm_reg_insn(INSN_MOV_IMM_REG, objectref_expr->value, call_target)); - } else { - call_target = state->left->reg1; - } - - /* object class */ - select_insn(s, tree, membase_reg_insn(INSN_MOV_MEMBASE_REG, call_target, offsetof(struct vm_object, class), call_target)); - - /* vtable */ - select_insn(s, tree, membase_reg_insn(INSN_MOV_MEMBASE_REG, call_target, offsetof(struct vm_class, vtable), call_target)); - - /* native ptr */ - select_insn(s, tree, imm_reg_insn(INSN_ADD_IMM_REG, method_offset, call_target)); - - /* invoke method */ - select_insn(s, tree, reg_insn(INSN_CALL_REG, call_target)); - - args_count = nr_args(to_expr(expr->args_list)); - if (args_count) - method_args_cleanup(s, tree, args_count); + invokevirtual(state, s, tree); esp = get_fixed_var(s->b_parent, REG_ESP); select_insn(s, tree, membase_insn(INSN_FSTP_MEMBASE, esp, -4)); @@ -1935,6 +1869,44 @@ emulate_op_64(struct _MBState *state, struct basic_block *s, select_insn(s, tree, reg_reg_insn(INSN_MOV_REG_REG, edx, state->reg2)); } +static void invokevirtual(struct _MBState *state, struct basic_block *s, struct tree_node *tree) +{ + struct expression *expr; + struct expression *objectref_expr; + struct var_info *call_target; + unsigned long method_offset; + unsigned long args_count; + + expr= to_expr(tree); + method_offset = expr_method_index(expr) * sizeof(void *); + + /* object reference */ + objectref_expr = get_first_arg(expr->args_list); + + if (expr_type(objectref_expr) == EXPR_VALUE) { + call_target = get_var(s->b_parent); + select_insn(s, tree, imm_reg_in
Re: [PATCH] x86: floating point returning is now ABI conformant
applied -- ___ Jatovm-devel mailing list Jatovm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jatovm-devel
[PATCH] x86: implement OP_FREM
This calls the C function fmodf() as the VM Spec suggests. Signed-off-by: Arthur Huillet --- arch/x86/insn-selector_32.brg | 21 + regression/jvm/FloatArithmeticTest.java |9 +++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/arch/x86/insn-selector_32.brg b/arch/x86/insn-selector_32.brg index 1ba67b9..0e8e84f 100644 --- a/arch/x86/insn-selector_32.brg +++ b/arch/x86/insn-selector_32.brg @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -447,6 +448,26 @@ reg: OP_REM(reg, reg) 1 select_insn(s, tree, reg_reg_insn(INSN_DIV_REG_REG, state->right->reg1, eax)); } +freg: OP_FREM(freg, freg) 1 +{ + struct var_info *esp, *eax; + + state->reg1 = get_fpu_var(s->b_parent); + + esp = get_fixed_var(s->b_parent, REG_ESP); + eax = get_fixed_var(s->b_parent, REG_EAX); + + select_insn(s, tree, reg_membase_insn(INSN_MOV_XMM_MEMBASE, state->left->reg1, esp, -8)); + select_insn(s, tree, reg_membase_insn(INSN_MOV_XMM_MEMBASE, state->right->reg1, esp, -4)); + select_insn(s, tree, imm_reg_insn(INSN_SUB_IMM_REG, 8, esp)); + + select_insn(s, tree, rel_insn(INSN_CALL_REL, (unsigned long)fmodf)); + method_args_cleanup(s, tree, 2); + + select_insn(s, tree, membase_insn(INSN_FSTP_MEMBASE, esp, -4)); + select_insn(s, tree, membase_reg_insn(INSN_MOV_MEMBASE_XMM, esp, -4, state->reg1)); +} + reg: OP_REM_64(reg, reg) 1 { emulate_op_64(state, s, tree, emulate_lrem, J_LONG); diff --git a/regression/jvm/FloatArithmeticTest.java b/regression/jvm/FloatArithmeticTest.java index 711710a..3a44995 100644 --- a/regression/jvm/FloatArithmeticTest.java +++ b/regression/jvm/FloatArithmeticTest.java @@ -97,6 +97,12 @@ public class FloatArithmeticTest extends TestCase { return dividend / divisor; } + public static void testFloatRemainder() { +assertEquals(2.0f, rem(6.0f, 4.0f)); +assertEquals(1.5f, rem(1.5f, 10001.5f)); +assertEquals(1.0f, rem(10002.5f, 10001.5f)); + } + public static float rem(float dividend, float divisor) { return dividend % divisor; } @@ -133,8 +139,7 @@ public class FloatArithmeticTest extends TestCase { testFloatSubtractionImmediateLocal(); testFloatMultiplication(); testFloatDivision(); -// FIXME -// testFloatRemainder(); +testFloatRemainder(); testFloatNegation(); testFloatIntConversion(); exit(); -- 1.6.3.3 -- ___ Jatovm-devel mailing list Jatovm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jatovm-devel
Re: [PATCH] x86: implement OP_FREM
applied -- ___ Jatovm-devel mailing list Jatovm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jatovm-devel
Re: [PATCH] vm: part 1 of itables (interface method tables)
2009/7/3 Pekka Enberg : > On Thu, 2009-07-02 at 21:43 +0200, Vegard Nossum wrote: >> This patch adds: >> >> 1. A space in the class struct where we can store the itable >> 2. Collecting the interface methods implemented by the class and its >> superclasses >> 3. Tracing (debug output) of the collected itable >> >> Signed-off-by: Vegard Nossum > > Looks good to me but I'd rather wait for "part 2" before merging. Are > you OK with that? It's fine. Though I really hate out-of-tree development since you-know-when.. ;-) (I do understand your concern, though. You probably want to make sure that we actually end up _using_ this part 1 and not rewrite it because it turns out to be wrong or useless.) Vegard -- ___ Jatovm-devel mailing list Jatovm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jatovm-devel
Re: [PATCH] vm: part 1 of itables (interface method tables)
On Thu, 2009-07-02 at 21:43 +0200, Vegard Nossum wrote: > This patch adds: > > 1. A space in the class struct where we can store the itable > 2. Collecting the interface methods implemented by the class and its > superclasses > 3. Tracing (debug output) of the collected itable > > Signed-off-by: Vegard Nossum Looks good to me but I'd rather wait for "part 2" before merging. Are you OK with that? Pekka -- ___ Jatovm-devel mailing list Jatovm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jatovm-devel
[PATCH] x86: implement f2i and i2f
This is done by extending the HIR with two new EXPR_CONVERSION : EXPR_CONVERSION_{TO,FROM}_FLOAT. Signed-off-by: Arthur Huillet --- arch/x86/insn-selector_32.brg | 38 ++ include/jit/expression.h|4 +++ jit/expression.c| 22 ++ jit/tree-printer.c |2 + jit/typeconv-bc.c |8 +- regression/jvm/FloatArithmeticTest.java |2 +- 6 files changed, 69 insertions(+), 7 deletions(-) diff --git a/arch/x86/insn-selector_32.brg b/arch/x86/insn-selector_32.brg index 3103aa7..86d81b9 100644 --- a/arch/x86/insn-selector_32.brg +++ b/arch/x86/insn-selector_32.brg @@ -1164,12 +1164,40 @@ reg:EXPR_CONVERSION(reg) state->reg1 = get_var(s->b_parent); select_insn(s, tree, reg_reg_insn(INSN_MOVSX_REG_REG, state->left->reg1, state->reg1)); - } else if (src->vm_type == J_INT && expr->vm_type == J_FLOAT) { - NOT_IMPLEMENTED; - state->reg1 = get_var(s->b_parent); - } else if (src->vm_type == J_FLOAT && expr->vm_type == J_INT) { - NOT_IMPLEMENTED; + } else { + printf("%d to %d\n", src->vm_type, expr->vm_type); + assert(!"conversion not implemented"); + } +} + +freg: EXPR_CONVERSION_TO_FLOAT(reg) +{ + struct expression *expr, *src; + + expr = to_expr(tree); + src = to_expr(expr->from_expression); + + if (src->vm_type == J_INT && expr->vm_type == J_FLOAT) { + state->reg1 = get_fpu_var(s->b_parent); + + select_insn(s, tree, reg_reg_insn(INSN_CONV_GPR_TO_FPU, state->left->reg1, state->reg1)); + } else { + printf("%d to %d\n", src->vm_type, expr->vm_type); + assert(!"conversion not implemented"); + } +} + +reg: EXPR_CONVERSION_FROM_FLOAT(freg) +{ + struct expression *expr, *src; + + expr = to_expr(tree); + src = to_expr(expr->from_expression); + + if (src->vm_type == J_FLOAT && expr->vm_type == J_INT) { state->reg1 = get_var(s->b_parent); + + select_insn(s, tree, reg_reg_insn(INSN_CONV_FPU_TO_GPR, state->left->reg1, state->reg1)); } else { printf("%d to %d\n", src->vm_type, expr->vm_type); assert(!"conversion not implemented"); diff --git a/include/jit/expression.h b/include/jit/expression.h index d9c0b71..8f179c2 100644 --- a/include/jit/expression.h +++ b/include/jit/expression.h @@ -23,6 +23,8 @@ enum expression_type { EXPR_BINOP, EXPR_UNARY_OP, EXPR_CONVERSION, + EXPR_CONVERSION_FROM_FLOAT, + EXPR_CONVERSION_TO_FLOAT, EXPR_CLASS_FIELD, EXPR_INSTANCE_FIELD, EXPR_INVOKE, @@ -301,6 +303,8 @@ struct expression *array_deref_expr(enum vm_type, struct expression *, struct ex struct expression *binop_expr(enum vm_type, enum binary_operator, struct expression *, struct expression *); struct expression *unary_op_expr(enum vm_type, enum unary_operator, struct expression *); struct expression *conversion_expr(enum vm_type, struct expression *); +struct expression *conversion_from_float_expr(enum vm_type, struct expression *); +struct expression *conversion_to_float_expr(enum vm_type, struct expression *); struct expression *class_field_expr(enum vm_type, struct vm_field *); struct expression *instance_field_expr(enum vm_type, struct vm_field *, struct expression *); struct expression *invoke_expr(struct vm_method *); diff --git a/jit/expression.c b/jit/expression.c index a660f05..1f6727a 100644 --- a/jit/expression.c +++ b/jit/expression.c @@ -28,6 +28,8 @@ int expr_nr_kids(struct expression *expr) return 2; case EXPR_UNARY_OP: case EXPR_CONVERSION: + case EXPR_CONVERSION_TO_FLOAT: + case EXPR_CONVERSION_FROM_FLOAT: case EXPR_INSTANCE_FIELD: case EXPR_INVOKE: case EXPR_INVOKEVIRTUAL: @@ -75,6 +77,8 @@ int expr_is_pure(struct expression *expr) case EXPR_ARGS_LIST: case EXPR_UNARY_OP: case EXPR_CONVERSION: + case EXPR_CONVERSION_TO_FLOAT: + case EXPR_CONVERSION_FROM_FLOAT: case EXPR_ARG: case EXPR_ARRAYLENGTH: case EXPR_INSTANCEOF: @@ -263,6 +267,24 @@ struct expression *conversion_expr(enum vm_type vm_type, return expr; } +struct expression *conversion_to_float_expr(enum vm_type vm_type, + struct expression *from_expression) +{ + struct expression *expr = alloc_expression(EXPR_CONVERSION_TO_FLOAT, vm_type); + if (expr) + expr->from_expression = &from_expression->node; + return expr; +} + +struct expression *conversion_from_float_expr(enum vm_type vm_type, + struct expression *from_expression) +{ + struct expression *expr = alloc_expression(EXPR_CONVERSION_FROM
Re: [PATCH] x86: float remainder is FREM in the HIR
both patches applied -- ___ Jatovm-devel mailing list Jatovm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jatovm-devel
[PATCH] regression: add integer<->float conversion tests
Disabled until conversion is implemented. Signed-off-by: Arthur Huillet --- regression/jvm/FloatArithmeticTest.java | 18 +- 1 files changed, 17 insertions(+), 1 deletions(-) diff --git a/regression/jvm/FloatArithmeticTest.java b/regression/jvm/FloatArithmeticTest.java index edd6c14..30ac318 100644 --- a/regression/jvm/FloatArithmeticTest.java +++ b/regression/jvm/FloatArithmeticTest.java @@ -111,6 +111,21 @@ public class FloatArithmeticTest extends TestCase { return -n; } + public static float i2f(int val) { + return (float) val; + } + + public static int f2i(float val) { + return (int) val; + } + + public static void testFloatIntConversion() { + assertEquals(2, f2i(2.5f)); + assertEquals(-1000, f2i(-1000.0101f)); + assertEquals(2.0f, i2f(2)); + assertEquals(-3000f, i2f(-3000)); + } + public static void main(String[] args) { testFloatAddition(); @@ -119,8 +134,9 @@ public class FloatArithmeticTest extends TestCase { testFloatSubtractionImmediateLocal(); testFloatMultiplication(); testFloatDivision(); +//TODO testFloatRemainder(); testFloatNegation(); - +// testFloatIntConversion(); exit(); } } -- 1.6.3.3 -- ___ Jatovm-devel mailing list Jatovm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jatovm-devel
[PATCH] x86: float remainder is FREM in the HIR
Not implemented for now because the emulation function returns float, and we cannot talk to functions returning floats that respect the ABI for now. Signed-off-by: Arthur Huillet --- include/jit/expression.h |1 + jit/arithmetic-bc.c |2 +- jit/tree-printer.c|1 + test/jit/arithmetic-bc-test.c |2 +- 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/include/jit/expression.h b/include/jit/expression.h index 916eac6..d9c0b71 100644 --- a/include/jit/expression.h +++ b/include/jit/expression.h @@ -79,6 +79,7 @@ enum binary_operator { OP_FSUB, OP_FMUL, OP_FDIV, + OP_FREM, BINOP_LAST, /* Not a real operator. Keep this last. */ }; diff --git a/jit/arithmetic-bc.c b/jit/arithmetic-bc.c index 32720fb..eb05952 100644 --- a/jit/arithmetic-bc.c +++ b/jit/arithmetic-bc.c @@ -125,7 +125,7 @@ int convert_lrem(struct parse_context *ctx) int convert_frem(struct parse_context *ctx) { - return convert_binop(ctx, J_FLOAT, OP_REM); + return convert_binop(ctx, J_FLOAT, OP_FREM); } int convert_drem(struct parse_context *ctx) diff --git a/jit/tree-printer.c b/jit/tree-printer.c index f125575..55b3adb 100644 --- a/jit/tree-printer.c +++ b/jit/tree-printer.c @@ -410,6 +410,7 @@ static const char *op_names[] = { [OP_FMUL] = "fmul", [OP_FNEG] = "fneg", [OP_FDIV] = "fdiv", + [OP_FREM] = "frem", [OP_SHL] = "shl", [OP_SHL_64] = "shl64", [OP_SHR] = "shr", diff --git a/test/jit/arithmetic-bc-test.c b/test/jit/arithmetic-bc-test.c index 056071b..463ad3c 100644 --- a/test/jit/arithmetic-bc-test.c +++ b/test/jit/arithmetic-bc-test.c @@ -96,7 +96,7 @@ void test_convert_rem(void) { assert_convert_binop(J_INT, OP_REM, OPC_IREM); assert_convert_binop(J_LONG, OP_REM_64, OPC_LREM); - assert_convert_binop(J_FLOAT, OP_REM, OPC_FREM); + assert_convert_binop(J_FLOAT, OP_FREM, OPC_FREM); assert_convert_binop(J_DOUBLE, OP_REM, OPC_DREM); } -- 1.6.3.3 -- ___ Jatovm-devel mailing list Jatovm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jatovm-devel
Re: [PATCH 1/2] x86: fix cvtsi2ss and cvtss2si code emission
On Fri, 2009-07-03 at 02:05 +0200, Arthur Huillet wrote: > source and destination registers were swapped > > Signed-off-by: Arthur Huillet Applied, thanks! -- ___ Jatovm-devel mailing list Jatovm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jatovm-devel
Re: [PATCH] x86: fix FMUL FDIV FCMPL, implement FNEG, enable FloatArithmeticTest
Applied, thanks! -- ___ Jatovm-devel mailing list Jatovm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jatovm-devel
Re: [PATCH] vm: allocate enough memory for inherited fields, amendment #2
On Thu, 2009-07-02 at 21:43 +0200, Vegard Nossum wrote: > Allocate just the right amount of memory that we need for this class's > static fields, including fields inherited from the superclass. > > Signed-off-by: Vegard Nossum Applied, thanks! -- ___ Jatovm-devel mailing list Jatovm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jatovm-devel
[PATCH 2/2] x86: improve FPU support
- fix moving floats between GPR and XMM registers - implemented FSUB FMUL and FDIV, cannot be fully tested yet - implemented FCMPL - missing : FNEG, FREM, and more importantly functions returning float are not doing it properly yet. Signed-off-by: Arthur Huillet --- arch/x86/emit-code.c| 93 +++ arch/x86/include/arch/instruction.h |9 +++- arch/x86/insn-selector_32.brg | 65 arch/x86/lir-printer.c | 43 +++-- arch/x86/use-def.c |9 +++- test/arch-x86/emit-code-test_32.c |2 +- 6 files changed, 170 insertions(+), 51 deletions(-) diff --git a/arch/x86/emit-code.c b/arch/x86/emit-code.c index a348ab3..bed1900 100644 --- a/arch/x86/emit-code.c +++ b/arch/x86/emit-code.c @@ -532,7 +532,9 @@ __emit_membase(struct buffer *buf, unsigned char opc, else rm = __encode_reg(base_reg); - if (is_imm_8(disp)) + if (disp == 0) + mod = 0x00; + else if (is_imm_8(disp)) mod = 0x01; else mod = 0x02; @@ -543,7 +545,8 @@ __emit_membase(struct buffer *buf, unsigned char opc, if (needs_sib) emit(buf, encode_sib(0x00, 0x04, __encode_reg(base_reg))); - emit_imm(buf, disp); + if (disp) + emit_imm(buf, disp); } static void @@ -680,17 +683,7 @@ static void emit_mov_imm_reg(struct buffer *buf, struct operand *src, static void emit_mov_imm_membase(struct buffer *buf, struct operand *src, struct operand *dest) { - unsigned long mod = 0x00; - - emit(buf, 0xc7); - - if (dest->disp != 0) - mod = 0x01; - - emit(buf, encode_modrm(mod, 0x00, encode_reg(&dest->base_reg))); - - if (dest->disp != 0) - emit(buf, dest->disp); + __emit_membase(buf, 0xc7, mach_reg(&dest->base_reg), dest->disp, 0); emit_imm32(buf, src->imm); } @@ -698,17 +691,7 @@ static void emit_mov_imm_membase(struct buffer *buf, struct operand *src, static void emit_mov_reg_membase(struct buffer *buf, struct operand *src, struct operand *dest) { - int mod; - - if (is_imm_8(dest->disp)) - mod = 0x01; - else - mod = 0x02; - - emit(buf, 0x89); - emit(buf, encode_modrm(mod, encode_reg(&src->reg), encode_reg(&dest->base_reg))); - - emit_imm(buf, dest->disp); + __emit_membase(buf, 0x89, mach_reg(&dest->base_reg), dest->disp, encode_reg(&src->reg)); } static void emit_mov_reg_memlocal(struct buffer *buf, struct operand *src, @@ -889,6 +872,28 @@ static void emit_fadd_reg_reg(struct buffer *buf, emit_reg_reg(buf, 0x58, dest, src); } +static void emit_fsub_reg_reg(struct buffer *buf, +struct operand *src, struct operand *dest) +{ + emit(buf, 0xf3); + emit(buf, 0x0f); + emit_reg_reg(buf, 0x5c, dest, src); +} +static void emit_fmul_reg_reg(struct buffer *buf, +struct operand *src, struct operand *dest) +{ + emit(buf, 0xf3); + emit(buf, 0x0f); + emit_reg_reg(buf, 0x59, dest, src); +} +static void emit_fdiv_reg_reg(struct buffer *buf, +struct operand *src, struct operand *dest) +{ + emit(buf, 0xf3); + emit(buf, 0x0f); + emit_reg_reg(buf, 0x5e, dest, src); +} + static void emit_add_membase_reg(struct buffer *buf, struct operand *src, struct operand *dest) { @@ -1142,20 +1147,36 @@ static void emit_exception_test(struct buffer *buf, enum machine_reg reg) __emit_test_membase_reg(buf, reg, 0, reg); } -static void emit_mov_gpr_to_xmm(struct buffer *buf, struct operand *src, +static void emit_conv_gpr_to_fpu(struct buffer *buf, struct operand *src, + struct operand *dest) +{ + emit(buf, 0xf3); + emit(buf, 0x0f); + emit_reg_reg(buf, 0x2a, src, dest); +} + +static void emit_conv_fpu_to_gpr(struct buffer *buf, struct operand *src, struct operand *dest) { emit(buf, 0xf3); emit(buf, 0x0f); - emit_reg_reg(buf, 0x2a, dest, src); + emit_reg_reg(buf, 0x2d, src, dest); } -static void emit_mov_xmm_to_gpr(struct buffer *buf, struct operand *src, +static void emit_mov_membase_xmm(struct buffer *buf, struct operand *src, struct operand *dest) { emit(buf, 0xf3); emit(buf, 0x0f); - emit_reg_reg(buf, 0x2d, dest, src); + emit_membase_reg(buf, 0x10, src, dest); +} + +static void emit_mov_xmm_membase(struct buffer *buf, struct operand *src, + struct operand *dest) +{ + emit(buf, 0xf3); + emit(buf, 0x0f); + emit_membase_reg(buf, 0x11, dest, src); } struct emitter emitters[] = { @@ -1176,8 +1197,13 @@ struct emitter emitters[]