X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=src%2Fvm%2Fmethod.cpp;h=337eb27bcd4e7e14339e206977677d4ca8637127;hb=4e25f6be9878154a9a7ae28917ed34427cb8ca6a;hp=b25fd91e6fe862d58d5df031d85ed12d1d60701a;hpb=10d583ff3381b14794158fa492fd1d3b5d9f4891;p=cacao.git diff --git a/src/vm/method.cpp b/src/vm/method.cpp index b25fd91e6..337eb27bc 100644 --- a/src/vm/method.cpp +++ b/src/vm/method.cpp @@ -1,6 +1,6 @@ /* src/vm/method.cpp - method functions - Copyright (C) 1996-2005, 2006, 2007, 2008 + Copyright (C) 1996-2011 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO This file is part of CACAO. @@ -31,7 +31,7 @@ #include "vm/types.h" -#include "mm/memory.h" +#include "mm/memory.hpp" #include "native/llni.h" @@ -43,7 +43,7 @@ #include "vm/exceptions.hpp" #include "vm/global.h" #include "vm/globals.hpp" -#include "vm/linker.h" +#include "vm/linker.hpp" #include "vm/loader.hpp" #include "vm/method.hpp" #include "vm/options.h" @@ -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) @@ -201,7 +214,15 @@ bool method_load(classbuffer *cb, methodinfo *m, descriptor_pool *descpool) } } #endif /* ENABLE_VERIFIER */ - + + /* Ignore flags for class initializer according to section 4.6 + of "The Java Virtual Machine Specification, 2nd Edition" (see PR125). */ + + if (m->name == utf_clinit) { + m->flags &= ACC_STRICT; + m->flags |= ACC_STATIC; + } + if (!(m->flags & ACC_STATIC)) argcount++; /* count the 'this' argument */ @@ -425,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 */ @@ -471,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)) @@ -497,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 */ @@ -551,6 +613,9 @@ void method_free(methodinfo *m) CompilerStub::remove(m->stubroutine); } } + + if (m->breakpoints) + delete m->breakpoints; } @@ -657,7 +722,7 @@ methodinfo *method_vftbl_lookup(vftbl_t *vftbl, methodinfo* m) m........the method of which the parameters should be counted RETURN VALUE: - The parameter count or -1 on error. + The parameter count. *******************************************************************************/ @@ -670,11 +735,7 @@ int32_t method_get_parametercount(methodinfo *m) /* is the descriptor fully parsed? */ - if (md->params == NULL) { - if (!descriptor_params_from_paramtypes(md, m->flags)) { - return -1; - } - } + descriptor_params_from_paramtypes(md, m->flags); paramcount = md->paramcount; @@ -699,20 +760,17 @@ int32_t method_get_parametercount(methodinfo *m) java_handle_objectarray_t *method_get_parametertypearray(methodinfo *m) { - methoddesc *md; - typedesc *paramtypes; - int32_t paramcount; - java_handle_objectarray_t *oa; - int32_t i; - classinfo *c; + methoddesc* md; + typedesc* paramtypes; + int32_t paramcount; + int32_t i; + classinfo* c; md = m->parseddesc; /* is the descriptor fully parsed? */ - if (m->parseddesc->params == NULL) - if (!descriptor_params_from_paramtypes(md, m->flags)) - return NULL; + descriptor_params_from_paramtypes(md, m->flags); paramtypes = md->paramtypes; paramcount = md->paramcount; @@ -726,9 +784,9 @@ java_handle_objectarray_t *method_get_parametertypearray(methodinfo *m) /* create class-array */ - oa = builtin_anewarray(paramcount, class_java_lang_Class); + ClassArray ca(paramcount); - if (oa == NULL) + if (ca.is_null()) return NULL; /* get classes */ @@ -737,10 +795,10 @@ java_handle_objectarray_t *method_get_parametertypearray(methodinfo *m) if (!resolve_class_from_typedesc(¶mtypes[i], true, false, &c)) return NULL; - LLNI_array_direct(oa, i) = (java_object_t *) c; + ca.set_element(i, c); } - return oa; + return ca.get_handle(); } @@ -752,15 +810,14 @@ java_handle_objectarray_t *method_get_parametertypearray(methodinfo *m) java_handle_objectarray_t *method_get_exceptionarray(methodinfo *m) { - java_handle_objectarray_t *oa; - classinfo *c; - s4 i; + classinfo* c; + s4 i; /* create class-array */ - oa = builtin_anewarray(m->thrownexceptionscount, class_java_lang_Class); + ClassArray ca(m->thrownexceptionscount); - if (oa == NULL) + if (ca.is_null()) return NULL; /* iterate over all exceptions and store the class in the array */ @@ -771,10 +828,10 @@ java_handle_objectarray_t *method_get_exceptionarray(methodinfo *m) if (c == NULL) return NULL; - LLNI_array_direct(oa, i) = (java_object_t *) c; + ca.set_element(i, c); } - return oa; + return ca.get_handle(); } @@ -864,26 +921,24 @@ java_handle_bytearray_t *method_get_annotations(methodinfo *m) #if defined(ENABLE_ANNOTATIONS) classinfo *c; /* methods' declaring class */ int slot; /* methods' slot */ - java_handle_t *annotations; /* methods' unparsed annotations */ java_handle_t *method_annotations; /* all methods' unparsed annotations */ /* of the declaring class */ - c = m->clazz; - slot = m - c->methods; - annotations = NULL; + c = m->clazz; + slot = m - c->methods; LLNI_classinfo_field_get(c, method_annotations, method_annotations); + ObjectArray oa((java_handle_objectarray_t*) method_annotations); + /* the method_annotations array might be shorter then the method * count if the methods above a certain index have no annotations. */ - if (method_annotations != NULL && - array_length_get(method_annotations) > slot) { - annotations = array_objectarray_element_get( - (java_handle_objectarray_t*)method_annotations, slot); + if (method_annotations != NULL && oa.get_length() > slot) { + return (java_handle_bytearray_t*) oa.get_element(slot); + } else { + return NULL; } - - return (java_handle_bytearray_t*)annotations; #else return NULL; #endif @@ -910,30 +965,26 @@ java_handle_bytearray_t *method_get_parameterannotations(methodinfo *m) #if defined(ENABLE_ANNOTATIONS) classinfo *c; /* methods' declaring class */ int slot; /* methods' slot */ - java_handle_t *parameterAnnotations; /* methods' unparsed */ - /* parameter annotations */ java_handle_t *method_parameterannotations; /* all methods' unparsed */ /* parameter annotations of */ /* the declaring class */ - c = m->clazz; - slot = m - c->methods; - parameterAnnotations = NULL; + c = m->clazz; + slot = m - c->methods; LLNI_classinfo_field_get( c, method_parameterannotations, method_parameterannotations); + ObjectArray oa((java_handle_objectarray_t*) method_parameterannotations); + /* the method_annotations array might be shorter then the method * count if the methods above a certain index have no annotations. */ - if (method_parameterannotations != NULL && - array_length_get(method_parameterannotations) > slot) { - parameterAnnotations = array_objectarray_element_get( - (java_handle_objectarray_t*)method_parameterannotations, - slot); + if (method_parameterannotations != NULL && oa.get_length() > slot) { + return (java_handle_bytearray_t*) oa.get_element(slot); + } else { + return NULL; } - - return (java_handle_bytearray_t*)parameterAnnotations; #else return NULL; #endif @@ -959,29 +1010,26 @@ java_handle_bytearray_t *method_get_annotationdefault(methodinfo *m) #if defined(ENABLE_ANNOTATIONS) classinfo *c; /* methods' declaring class */ int slot; /* methods' slot */ - java_handle_t *annotationDefault; /* methods' unparsed */ - /* annotation default value */ java_handle_t *method_annotationdefaults; /* all methods' unparsed */ /* annotation default values of */ /* the declaring class */ - c = m->clazz; - slot = m - c->methods; - annotationDefault = NULL; + c = m->clazz; + slot = m - c->methods; LLNI_classinfo_field_get( c, method_annotationdefaults, method_annotationdefaults); + ObjectArray oa((java_handle_objectarray_t*) method_annotationdefaults); + /* the method_annotations array might be shorter then the method * count if the methods above a certain index have no annotations. - */ - if (method_annotationdefaults != NULL && - array_length_get(method_annotationdefaults) > slot) { - annotationDefault = array_objectarray_element_get( - (java_handle_objectarray_t*)method_annotationdefaults, slot); + */ + if (method_annotationdefaults != NULL && oa.get_length() > slot) { + return (java_handle_bytearray_t*) oa.get_element(slot); + } else { + return NULL; } - - return (java_handle_bytearray_t*)annotationDefault; #else return NULL; #endif