Re: [PATCH 1/2] vm: parse method and field type on initialization
On Tue, 2009-10-06 at 11:45 +0200, Tomek Grabiec wrote: > struct vm_type_info is introduced to fully describe a java type of a > call argument, return type, field type, etc. Method's and field's type > strings are parsed on initialization and type information is put to > appropriate struct vm_type_infos. Type information for method > arguments is encapsulated in struct vm_method_arg and linked in a list > pointed by struct vm_method.args. > > This change removes plenty of calls to type string parsing which > should not be done at run-time but rather on method or field > initialization. > > Signed-off-by: Tomek Grabiec Nice cleanup! Applied, thanks! -- Come build with us! The BlackBerry® Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9-12, 2009. Register now! http://p.sf.net/sfu/devconf ___ Jatovm-devel mailing list Jatovm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jatovm-devel
[penberg/jato] 98b32e: vm: parse method and field type on initialization
Branch: refs/heads/master Home: http://github.com/penberg/jato Commit: 98b32ee8f4ef7d3b6ab299859151087286533462 http://github.com/penberg/jato/commit/98b32ee8f4ef7d3b6ab299859151087286533462 Author: Tomek Grabiec Date: 2009-10-06 (Tue, 06 Oct 2009) Changed paths: M include/jit/expression.h M include/vm/field.h M include/vm/method.h M include/vm/types.h M jit/invoke-bc.c M jit/trace-jit.c M test/jit/invoke-bc-test.c M test/jit/object-bc-test.c M test/jit/tree-printer-test.c M vm/class.c M vm/field.c M vm/jni-interface.c M vm/method.c M vm/reflection.c M vm/types.c Log Message: --- vm: parse method and field type on initialization struct vm_type_info is introduced to fully describe a java type of a call argument, return type, field type, etc. Method's and field's type strings are parsed on initialization and type information is put to appropriate struct vm_type_infos. Type information for method arguments is encapsulated in struct vm_method_arg and linked in a list pointed by struct vm_method.args. This change removes plenty of calls to type string parsing which should not be done at run-time but rather on method or field initialization. Signed-off-by: Tomek Grabiec Signed-off-by: Pekka Enberg Commit: fad77b2a154ac42357af3f916d7d356968b135fe http://github.com/penberg/jato/commit/fad77b2a154ac42357af3f916d7d356968b135fe Author: Tomek Grabiec Date: 2009-10-06 (Tue, 06 Oct 2009) Changed paths: M include/vm/reflection.h M vm/jato.c M vm/reflection.c Log Message: --- vm: implement java/lang/reflect/Method.getReturnType() Signed-off-by: Tomek Grabiec Signed-off-by: Pekka Enberg -- Come build with us! The BlackBerry® Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9-12, 2009. Register now! http://p.sf.net/sfu/devconf ___ Jatovm-devel mailing list Jatovm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jatovm-devel
[PATCH 1/2] vm: parse method and field type on initialization
struct vm_type_info is introduced to fully describe a java type of a call argument, return type, field type, etc. Method's and field's type strings are parsed on initialization and type information is put to appropriate struct vm_type_infos. Type information for method arguments is encapsulated in struct vm_method_arg and linked in a list pointed by struct vm_method.args. This change removes plenty of calls to type string parsing which should not be done at run-time but rather on method or field initialization. Signed-off-by: Tomek Grabiec --- include/jit/expression.h | 13 --- include/vm/field.h |4 +- include/vm/method.h |7 ++ include/vm/types.h | 32 +++- jit/invoke-bc.c |3 +- jit/trace-jit.c | 14 ++-- test/jit/invoke-bc-test.c| 11 ++- test/jit/object-bc-test.c|8 +- test/jit/tree-printer-test.c |4 +- vm/class.c |4 +- vm/field.c | 18 ++-- vm/jni-interface.c |9 +- vm/method.c | 12 +++- vm/reflection.c | 51 - vm/types.c | 173 ++ 15 files changed, 224 insertions(+), 139 deletions(-) diff --git a/include/jit/expression.h b/include/jit/expression.h index d89ff92..6fc87e8 100644 --- a/include/jit/expression.h +++ b/include/jit/expression.h @@ -349,17 +349,4 @@ unsigned long nr_args(struct expression *); int expr_nr_kids(struct expression *); int expr_is_pure(struct expression *); -static inline enum vm_type mimic_stack_type(enum vm_type type) -{ - switch (type) { - case J_BOOLEAN: - case J_BYTE: - case J_CHAR: - case J_SHORT: - return J_INT; - default: - return type; - } -} - #endif diff --git a/include/vm/field.h b/include/vm/field.h index aa4a25d..0c9d150 100644 --- a/include/vm/field.h +++ b/include/vm/field.h @@ -20,6 +20,8 @@ struct vm_field { char *name; char *type; + struct vm_type_info type_info; + unsigned int offset; }; @@ -45,7 +47,7 @@ static inline bool vm_field_is_public(const struct vm_field *vmf) static inline enum vm_type vm_field_type(const struct vm_field *vmf) { - return str_to_type(vmf->type); + return vmf->type_info.vm_type; } #endif diff --git a/include/vm/method.h b/include/vm/method.h index 54c2b94..ccf1db8 100644 --- a/include/vm/method.h +++ b/include/vm/method.h @@ -26,6 +26,11 @@ struct vm_args_map { }; #endif +struct vm_method_arg { + struct vm_type_info type_info; + struct list_head list_node; +}; + struct vm_method { struct vm_class *class; unsigned int method_index; @@ -40,6 +45,8 @@ struct vm_method { struct vm_args_map *args_map; int reg_args_count; #endif + struct list_head args; + struct vm_type_info return_type; struct cafebabe_code_attribute code_attribute; struct cafebabe_line_number_table_attribute line_number_table_attribute; diff --git a/include/vm/types.h b/include/vm/types.h index ae32f69..4695d9c 100644 --- a/include/vm/types.h +++ b/include/vm/types.h @@ -4,6 +4,11 @@ #include #include +#include "lib/list.h" + +struct vm_method; +struct vm_field; + enum vm_type { J_VOID, J_REFERENCE, @@ -25,19 +30,25 @@ enum vm_type { # define J_NATIVE_PTR J_LONG #endif +struct vm_type_info { + enum vm_type vm_type; + char *class_name; +}; + extern enum vm_type str_to_type(const char *); extern enum vm_type get_method_return_type(char *); extern unsigned int vm_type_size(enum vm_type); int skip_type(const char **type); -int count_arguments(const char *); +int count_arguments(const struct vm_method *); enum vm_type bytecode_type_to_vmtype(int); int vmtype_to_bytecode_type(enum vm_type); int get_vmtype_size(enum vm_type); const char *get_vm_type_name(enum vm_type); -const char *parse_method_args(const char *, enum vm_type *, char **); -const char *parse_type(const char *, enum vm_type *, char **); -unsigned int count_java_arguments(const char *); +int parse_type(char **, struct vm_type_info *); +unsigned int count_java_arguments(const struct vm_method *); +int parse_method_type(struct vm_method *); +int parse_field_type(struct vm_field *); static inline bool vm_type_is_float(enum vm_type type) { @@ -51,4 +62,17 @@ static inline int vm_type_slot_size(enum vm_type type) return 1; } +static inline enum vm_type mimic_stack_type(enum vm_type type) +{ + switch (type) { + case J_BOOLEAN: + case J_BYTE: + case J_CHAR: + case J_SHORT: + return J_INT; + default: + return type; + } +} + #endif diff --git a/jit/invoke-bc.c b/jit/invoke-bc.c index 698dd36..45a51f1 100644 --- a/jit/invoke-bc.c +++ b/jit/invoke-bc.c @@ -56,8 +56,7 @@ static unsigned int method_real_argument_count(struc
[PATCH 2/2] vm: implement java/lang/reflect/Method.getReturnType()
Signed-off-by: Tomek Grabiec --- include/vm/reflection.h |1 + vm/jato.c |1 + vm/reflection.c | 18 ++ 3 files changed, 20 insertions(+), 0 deletions(-) diff --git a/include/vm/reflection.h b/include/vm/reflection.h index f9c709a..c1e3aa4 100644 --- a/include/vm/reflection.h +++ b/include/vm/reflection.h @@ -39,5 +39,6 @@ native_method_invokenative(struct vm_object *method, struct vm_object *o, struct vm_object *declaringClass, jint slot); void native_field_set(struct vm_object *this, struct vm_object *o, struct vm_object *value_obj); +struct vm_object *native_method_getreturntype(struct vm_object *method); #endif /* __JATO_VM_REFLECTION_H */ diff --git a/vm/jato.c b/vm/jato.c index 332b3fb..1c84ccf 100644 --- a/vm/jato.c +++ b/vm/jato.c @@ -877,6 +877,7 @@ static struct vm_native natives[] = { DEFINE_NATIVE("java/lang/reflect/Field", "getType", &native_field_gettype), DEFINE_NATIVE("java/lang/reflect/Method", "getParameterTypes", &native_method_get_parameter_types), DEFINE_NATIVE("java/lang/reflect/Method", "invokeNative", &native_method_invokenative), + DEFINE_NATIVE("java/lang/reflect/Method", "getReturnType", &native_method_getreturntype), DEFINE_NATIVE("jato/internal/VM", "enableFault", &native_vm_enable_fault), DEFINE_NATIVE("jato/internal/VM", "disableFault", &native_vm_disable_fault), DEFINE_NATIVE("sun/misc/Unsafe", "compareAndSwapInt", native_unsafe_compare_and_swap_int), diff --git a/vm/reflection.c b/vm/reflection.c index d180634..80db700 100644 --- a/vm/reflection.c +++ b/vm/reflection.c @@ -810,3 +810,21 @@ struct vm_object *native_field_gettype(struct vm_object *this) return vmc->object; } + +struct vm_object *native_method_getreturntype(struct vm_object *method) +{ + struct vm_method *vmm = vm_object_to_vm_method(method); + if (!vmm) + return NULL; + + struct vm_class *vmc; + + vmc = vm_type_to_class(vmm->class->classloader, &vmm->return_type); + if (vmc) + vm_class_ensure_init(vmc); + + if (!vmc || exception_occurred()) + return NULL; + + return vmc->object; +} -- 1.6.0.4 -- Come build with us! The BlackBerry® Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9-12, 2009. Register now! http://p.sf.net/sfu/devconf ___ Jatovm-devel mailing list Jatovm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jatovm-devel