* src/vm/method.cpp (method_load): Loads LocalVariableTable attribute.
authorMichael Starzinger <michi@complang.tuwien.ac.at>
Mon, 2 Nov 2009 16:00:57 +0000 (17:00 +0100)
committerMichael Starzinger <michi@complang.tuwien.ac.at>
Mon, 2 Nov 2009 16:00:57 +0000 (17:00 +0100)
* src/vm/method.hpp (methodinfo): Added localvarcount and localvars field.
* src/vm/utf8.c (utf_LocalVariableTable): Added global variable
* src/vm/utf8.h: Likewise.

src/vm/method.cpp
src/vm/method.hpp
src/vm/utf8.c
src/vm/utf8.h

index 6e7827f2d8a75d9645b78e8ebcb87f632ac7ea2f..a0c3a4ab233ef65d624c22556fd50eda5f6dd81f 100644 (file)
@@ -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 */
index 7d3b81a475b9bea710b62779a1812bcd2d4ab3a0..6ab842c92f923112802a98e9a62588e10d165555 100644 (file)
@@ -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;
index ccc5e0f745e407d7aa730363b51527ce12adbd2a..7afcb2ce14d540538f992ffd5cea05ba62934c18 100644 (file)
@@ -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;                          /* <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");
index 8a1197ebf619715b50361bf5c851cea3a950dc17..b60111dc4ed9885b1bb27f4e080d006bd30f0e68 100644 (file)
@@ -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;