From: Michael Starzinger Date: Mon, 2 Nov 2009 16:00:57 +0000 (+0100) Subject: * src/vm/method.cpp (method_load): Loads LocalVariableTable attribute. X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;ds=sidebyside;h=1486e5bffbd83ac200f8fa1612bb5dcab6deb7f7;p=cacao.git * src/vm/method.cpp (method_load): Loads LocalVariableTable attribute. * src/vm/method.hpp (methodinfo): Added localvarcount and localvars field. * src/vm/utf8.c (utf_LocalVariableTable): Added global variable * src/vm/utf8.h: Likewise. --- diff --git a/src/vm/method.cpp b/src/vm/method.cpp index 6e7827f2d..a0c3a4ab2 100644 --- a/src/vm/method.cpp +++ b/src/vm/method.cpp @@ -127,6 +127,19 @@ void method_init(void) } line_number_table[line_number_table_length]; } + LocalVariableTable_attribute { + u2 attribute_name_index; + u4 attribute_length; + u2 local_variable_table_length; + { + u2 start_pc; + u2 length; + u2 name_index; + u2 descriptor_index; + u2 index; + } local_variable_table[local_variable_table_length]; + } + *******************************************************************************/ bool method_load(classbuffer *cb, methodinfo *m, descriptor_pool *descpool) @@ -433,7 +446,48 @@ bool method_load(classbuffer *cb, methodinfo *m, descriptor_pool *descpool) if (!stackmap_load_attribute_stackmaptable(cb, m)) return false; } -#endif +# if defined(ENABLE_JVMTI) + else if (code_attribute_name == utf_LocalVariableTable) { + /* LocalVariableTable */ + + if (m->localvars != NULL) { + exceptions_throw_classformaterror(c, "Multiple LocalVariableTable attributes"); + return false; + } + + if (!suck_check_classbuffer_size(cb, 4 + 2)) + return false; + + // Attribute length. + (void) suck_u4(cb); + + m->localvarcount = suck_u2(cb); + + if (!suck_check_classbuffer_size(cb, 10 * m->localvarcount)) + return false; + + m->localvars = MNEW(localvarinfo, m->localvarcount); + + for (l = 0; l < m->localvarcount; l++) { + m->localvars[l].start_pc = suck_u2(cb); + m->localvars[l].length = suck_u2(cb); + + uint16_t name_index = suck_u2(cb); + if (!(m->localvars[l].name = (utf*) class_getconstant(c, name_index, CONSTANT_Utf8))) + return false; + + uint16_t descriptor_index = suck_u2(cb); + if (!(m->localvars[l].descriptor = (utf*) class_getconstant(c, descriptor_index, CONSTANT_Utf8))) + return false; + + m->localvars[l].index = suck_u2(cb); + + // XXX Check if index is in range. + // XXX Check if index already taken. + } + } +# endif /* defined(ENABLE_JVMTI) */ +#endif /* defined(ENABLE_JAVASE) */ else { /* unknown code attribute */ @@ -479,7 +533,7 @@ bool method_load(classbuffer *cb, methodinfo *m, descriptor_pool *descpool) return false; } -#if defined(ENABLE_ANNOTATIONS) +# if defined(ENABLE_ANNOTATIONS) else if (attribute_name == utf_RuntimeVisibleAnnotations) { /* RuntimeVisibleAnnotations */ if (!annotation_load_method_attribute_runtimevisibleannotations(cb, m)) @@ -505,7 +559,7 @@ bool method_load(classbuffer *cb, methodinfo *m, descriptor_pool *descpool) if (!annotation_load_method_attribute_annotationdefault(cb, m)) return false; } -#endif +# endif #endif else { /* unknown attribute */ diff --git a/src/vm/method.hpp b/src/vm/method.hpp index 7d3b81a47..6ab842c92 100644 --- a/src/vm/method.hpp +++ b/src/vm/method.hpp @@ -30,7 +30,8 @@ typedef struct methodinfo methodinfo; typedef struct raw_exception_entry raw_exception_entry; -typedef struct lineinfo lineinfo; +typedef struct lineinfo lineinfo; +typedef struct localvarinfo localvarinfo; typedef struct method_assumption method_assumption; typedef struct method_worklist method_worklist; typedef struct codeinfo codeinfo; @@ -73,7 +74,7 @@ struct methodinfo { /* method structure */ #endif methoddesc *parseddesc; /* parsed descriptor */ - + classinfo *clazz; /* class, the method belongs to */ s4 vftblindex; /* index of method in virtual function */ /* table (if it is a virtual method) */ @@ -91,6 +92,11 @@ struct methodinfo { /* method structure */ u2 linenumbercount; /* number of linenumber attributes */ lineinfo *linenumbers; /* array of lineinfo items */ +#if defined(ENABLE_JAVASE) && defined(ENABLE_JVMTI) + uint16_t localvarcount; /* number of local variable attributes */ + localvarinfo* localvars; /* array of localvarinfo items */ +#endif + u1 *stubroutine; /* stub for compiling or calling natives */ codeinfo *code; /* current code of this method */ @@ -160,6 +166,17 @@ struct lineinfo { }; +/* localvarinfo ***************************************************************/ + +struct localvarinfo { + uint16_t start_pc; + uint16_t length; + utf* name; + utf* descriptor; + uint16_t index; +}; + + /* global variables ***********************************************************/ extern methodinfo *method_java_lang_reflect_Method_invoke; diff --git a/src/vm/utf8.c b/src/vm/utf8.c index ccc5e0f74..7afcb2ce1 100644 --- a/src/vm/utf8.c +++ b/src/vm/utf8.c @@ -152,13 +152,17 @@ utf *utf_EnclosingMethod; utf *utf_Signature; utf *utf_StackMapTable; -#if defined(ENABLE_ANNOTATIONS) +# if defined(ENABLE_JVMTI) +utf *utf_LocalVariableTable; +# endif + +# if defined(ENABLE_ANNOTATIONS) utf *utf_RuntimeVisibleAnnotations; /* RuntimeVisibleAnnotations */ utf *utf_RuntimeInvisibleAnnotations; /* RuntimeInvisibleAnnotations */ utf *utf_RuntimeVisibleParameterAnnotations; /* RuntimeVisibleParameterAnnotations */ utf *utf_RuntimeInvisibleParameterAnnotations; /* RuntimeInvisibleParameterAnnotations */ utf *utf_AnnotationDefault; /* AnnotationDefault */ -#endif +# endif #endif utf *utf_init; /* */ @@ -414,6 +418,10 @@ void utf8_init(void) utf_Signature = utf_new_char("Signature"); utf_StackMapTable = utf_new_char("StackMapTable"); +# if defined(ENABLE_JVMTI) + utf_LocalVariableTable = utf_new_char("LocalVariableTable"); +# endif + # if defined(ENABLE_ANNOTATIONS) utf_RuntimeVisibleAnnotations = utf_new_char("RuntimeVisibleAnnotations"); utf_RuntimeInvisibleAnnotations = utf_new_char("RuntimeInvisibleAnnotations"); diff --git a/src/vm/utf8.h b/src/vm/utf8.h index 8a1197ebf..b60111dc4 100644 --- a/src/vm/utf8.h +++ b/src/vm/utf8.h @@ -149,13 +149,17 @@ extern utf *utf_EnclosingMethod; extern utf *utf_Signature; extern utf *utf_StackMapTable; -#if defined(ENABLE_ANNOTATIONS) +# if defined(ENABLE_JVMTI) +extern utf *utf_LocalVariableTable; +# endif + +# if defined(ENABLE_ANNOTATIONS) extern utf *utf_RuntimeVisibleAnnotations; extern utf *utf_RuntimeInvisibleAnnotations; extern utf *utf_RuntimeVisibleParameterAnnotations; extern utf *utf_RuntimeInvisibleParameterAnnotations; extern utf *utf_AnnotationDefault; -#endif +# endif #endif extern utf *utf_init;