diff --git a/enhanced/drlvm/trunk/vm/interpreter/src/interpreter.cpp b/enhanced/drlvm/trunk/vm/interpreter/src/interpreter.cpp index d27bde2..6fb80c2 100644 --- a/enhanced/drlvm/trunk/vm/interpreter/src/interpreter.cpp +++ b/enhanced/drlvm/trunk/vm/interpreter/src/interpreter.cpp @@ -946,42 +946,42 @@ Opcode_LCMP(StackFrame& frame) { static bool ldc(StackFrame& frame, uint32 index) { - Class *clazz = frame.method->get_class(); - Const_Pool *cp = clazz->const_pool; + Class* clazz = frame.method->get_class(); + ConstantPool& cp = clazz->m_const_pool; #ifndef NDEBUG - switch(cp_tag(cp, index)) { + switch(cp.get_tag(index)) { case CONSTANT_String: - DEBUG_BYTECODE("#" << dec << (int)index << " String: \"" << cp[index].CONSTANT_String.string->bytes << "\""); + DEBUG_BYTECODE("#" << dec << (int)index << " String: \"" << cp.get_string_chars(index) << "\""); break; case CONSTANT_Integer: - DEBUG_BYTECODE("#" << dec << (int)index << " Integer: " << (int)cp[index].int_value); + DEBUG_BYTECODE("#" << dec << (int)index << " Integer: " << (int)cp.get_int(index)); break; case CONSTANT_Float: - DEBUG_BYTECODE("#" << dec << (int)index << " Float: " << cp[index].float_value); + DEBUG_BYTECODE("#" << dec << (int)index << " Float: " << cp.get_float(index)); break; case CONSTANT_Class: DEBUG_BYTECODE("#" << dec << (int)index << " Class: \"" << const_pool_get_class_name(clazz, index) << "\""); break; default: - DEBUG_BYTECODE("#" << dec << (int)index << " Unknown type = " << cp_tag(cp, index)); - DIE("ldc instruction: unexpected type (" << cp_tag(cp, index) + DEBUG_BYTECODE("#" << dec << (int)index << " Unknown type = " << cp.get_tag(index)); + DIE("ldc instruction: unexpected type (" << cp.get_tag(index) << ") of constant pool entry [" << index << "]"); break; } #endif frame.stack.push(); - if (cp_is_string(cp, index)) { - // FIXME: is string reference is packed?? + if(cp.is_string(index)) { + // FIXME: is string reference packed?? // possibly not - String* str = (String*) cp[index].CONSTANT_String.string; + String* str = cp.get_string(index); // FIXME: only compressed references frame.stack.pick().cr = COMPRESS_REF(vm_instantiate_cp_string_resolved(str)); frame.stack.ref() = FLAG_OBJECT; return !check_current_thread_exception(); } - else if (cp_is_class(cp, index)) + else if (cp.is_class(index)) { Class *other_class = interp_resolve_class(clazz, index); if (!other_class) { @@ -995,7 +995,7 @@ #endif return !exn_raised(); } - frame.stack.pick().u = cp[index].int_value; + frame.stack.pick().u = cp.get_4byte(index); return true; } @@ -1019,10 +1019,11 @@ Opcode_LDC2_W(StackFrame& frame) { uint32 index = read_uint16(frame.ip + 1); Class *clazz = frame.method->get_class(); - Const_Pool *cp = clazz->const_pool; + ConstantPool& cp = clazz->m_const_pool; frame.stack.push(2); Value2 val; - val.u64 = ((uint64)cp[index].CONSTANT_8byte.high_bytes << 32) | cp[index].CONSTANT_8byte.low_bytes; + val.u64 = ((uint64)cp.get_8byte_high_word(index) << 32) + | cp.get_8byte_low_word(index); frame.stack.setLong(0, val); DEBUG_BYTECODE("#" << dec << (int)index << " (val = " << hex << val.d << ")"); frame.ip += 3; diff --git a/enhanced/drlvm/trunk/vm/vmcore/include/Class.h b/enhanced/drlvm/trunk/vm/vmcore/include/Class.h index a7fb0e5..67bc7d8 100644 --- a/enhanced/drlvm/trunk/vm/vmcore/include/Class.h +++ b/enhanced/drlvm/trunk/vm/vmcore/include/Class.h @@ -56,7 +56,7 @@ struct AnnotationTable; /////////////////////////////////////////////////////////////////////////////// // Raw and compressed reference pointers /////////////////////////////////////////////////////////////////////////////// -#define RAW_REFERENCE ManagedObject * +#define RAW_REFERENCE ManagedObject* #define COMPRESSED_REFERENCE uint32 VMEXPORT bool is_compressed_reference(COMPRESSED_REFERENCE value); @@ -116,28 +116,29 @@ #define CLASSFILE_MINOR 3 // Constant pool entries. /////////////////////////////////////////////////////////////////////////////// -union Const_Pool { - unsigned char *tags; // entry 0 of const pool only +union ConstPoolEntry { + unsigned char* tags; // entry 0 of const pool only struct { // CONSTANT_Class union { Class* klass; // resolved class struct { // resolution error - Const_Pool* next; // next resolution error in this constant pool + ConstPoolEntry* next; // next resolution error in this constant pool ManagedObject* cause; } error; }; uint16 name_index; } CONSTANT_Class; struct { // CONSTANT_String - String *string; // resolved entry + String* string; // resolved entry uint16 string_index; } CONSTANT_String; struct { // CONSTANT_{Field,Method,InterfaceMethod}ref union { + Class_Member* member; // generic class member for CONSTANT_*ref Field* field; // resolved entry for CONSTANT_Fieldref - Method* method; // resolved entry for CONSTANT_{Interface}Methodref + Method* method; // resolved entry for CONSTANT_[Interface]Methodref struct { // resolution error - Const_Pool* next; // next resolution error in this constant pool + ConstPoolEntry* next; // next resolution error in this constant pool ManagedObject* cause; } error; }; @@ -146,7 +147,7 @@ union Const_Pool { } CONSTANT_ref; struct { // shortcut to resolution error in CONSTANT_Class and CONSTANT_ref - Const_Pool* next; // next resolution error in this constant pool + ConstPoolEntry* next; // next resolution error in this constant pool ManagedObject* cause; } error; @@ -159,17 +160,18 @@ union Const_Pool { // Const_Pool element of the long/double unused) } CONSTANT_8byte; struct { // CONSTANT_NameAndType - String *name; // resolved entry - String *descriptor; // resolved entry + String* name; // resolved entry + String* descriptor; // resolved entry uint16 name_index; uint16 descriptor_index; } CONSTANT_NameAndType; struct { - String *string; // CONSTANT_Utf8 + String* string; // CONSTANT_Utf8 uint16 dummy; } CONSTANT_Utf8; }; + /////////////////////////////////////////////////////////////////////////////// // Types of constant pool entries. These are defined by a seperate byte array // pointed to by the first constant pool entry. @@ -189,39 +191,439 @@ enum Const_Pool_Tags { CONSTANT_NameAndType = 12, }; + #define TAG_MASK 0x0F // 4 bits is sufficient for tag #define RESOLVED_MASK 0x80 // msb is resolved flag #define ERROR_MASK 0x40 // this entry contains resolution error information -#define cp_tag(cp,i) (cp[0].tags[i] & TAG_MASK) -#define cp_is_resolved(cp,i) (cp[0].tags[i] & RESOLVED_MASK) -#define cp_set_resolved(cp,i) (cp[0].tags[i] |= RESOLVED_MASK) -#define cp_in_error(cp, i) (cp[0].tags[i] & ERROR_MASK) -#define cp_set_error(cp, i) (cp[0].tags[i] |= ERROR_MASK) +struct ConstantPool { +private: + // constant pool size + uint16 m_size; + // constant pool entries; 0-th entry contains array of constant pool tags + // for all entries + ConstPoolEntry* m_entries; + // List of constant pool entries, which resolution had failed + // Required for fast enumeration of error objects + ConstPoolEntry* m_failedResolution; + +public: + ConstantPool() : m_size(0), m_entries(NULL) {} + ~ConstantPool() { + clear(); + } -#define cp_is_utf8(cp,i) (cp_tag(cp,i) == CONSTANT_Utf8) -#define cp_is_class(cp,i) (cp_tag(cp,i) == CONSTANT_Class) -#define cp_is_constant(cp,i) ((cp_tag(cp,i) >= CONSTANT_Integer \ - && cp_tag(cp,i) <= CONSTANT_Double) \ - || cp_tag(cp,i) == CONSTANT_String) + /// Checks that constant pool is not empty + /// @return true if constant pool contain some entries, false otherwise + bool available() const { return m_size != 0; } + /// Returns size of this constant pool + /// @return size of constant pool + uint16 get_size() const { return m_size; } + + /// Checks that index is a valid index into this constant pool + /// @param index - index into constant pool + /// @return true if index is a valid index into constant pool, false + /// otherwise + bool is_valid_index(uint16 index) const { + return /*index > 0 && */index < m_size; + } + /// Checks that constant pool entry is resolved + /// @param index - index into constant pool + /// @return true if entry is already resolved, false otherwise + bool is_entry_resolved(uint16 index) const { + assert(is_valid_index(index)); + return (m_entries[0].tags[index] & RESOLVED_MASK) != 0; + } + /// Checks that the resolution of constant pool entry had failed + /// @param index - index into constant pool + /// @return true if resolution error is recorded for the entry + bool is_entry_in_error(uint16 index) const { + assert(is_valid_index(index)); + return (m_entries[0].tags[index] & ERROR_MASK) != 0; + } + /// Checks that the constant pool entry represents utf8 string + /// @param index - index into constant pool + /// @return true if this entry is utf8 string, false otherwise + bool is_utf8(uint16 index) const { + return get_tag(index) == CONSTANT_Utf8; + } + /// Checks that the constant pool entry refers to a class + /// @param index - index into constant pool + /// @return true if this entry is a class, false otherwise + bool is_class(uint16 index) const { + return get_tag(index) == CONSTANT_Class; + } + /// Checks that the constant pool entry contains constant + /// @param index - index into constant pool + /// @return true if this entry contains constant, false otherwise + bool is_constant(uint16 index) const { + return get_tag(index) == CONSTANT_Integer + || get_tag(index) == CONSTANT_Float + || get_tag(index) == CONSTANT_Long + || get_tag(index) == CONSTANT_Double + || get_tag(index) == CONSTANT_String + || get_tag(index) == CONSTANT_Class; + } + /// Checks that the constant pool entry is literal constant + /// @param index - index into constant pool + /// @return true if this entry contains string, false otherwise + bool is_string(uint16 index) const { + return get_tag(index) == CONSTANT_String; + } + bool is_name_and_type(uint16 index) const { + return get_tag(index) == CONSTANT_NameAndType; + } + /// Checks that the constant pool entry contains reference to a field + /// @param index - index into constant pool + /// @return true if this entry contains reference to field, false otherwise + bool is_fieldref(uint16 index) const { + return get_tag(index) == CONSTANT_Fieldref; + } + /// Checks that the constant pool entry contains reference to a method + /// @param index - index into constant pool + /// @return true if this entry contains reference to method, false otherwise + bool is_methodref(uint16 index) const { + return get_tag(index) == CONSTANT_Methodref; + } + /// Checks that the constant pool entry constains reference to an + /// interface method + /// @param index - index into constant pool + /// @return true if this entry contains reference to interface method, + /// false otherwise + bool is_interfacemethodref(uint16 index) const { + return get_tag(index) == CONSTANT_InterfaceMethodref; + } + + /// Returns tag of referenced constant pool entry + /// @param index - index into constant pool + /// @return constant pool entry tag for a given index + unsigned char get_tag(uint16 index) const { + assert(is_valid_index(index)); + return m_entries[0].tags[index] & TAG_MASK; + } + /// Returns characters from utf8 string stored in constant pool + /// @param index - index into constant pool + /// @return characters from utf8 string stored in constant pool + const char* get_utf8_chars(uint16 index) const { + return get_utf8_string(index)->bytes; + } + /// Returns utf8 string stored in constant pool + /// @param index - index into constant pool + /// @return utf8 string + String* get_utf8_string(uint16 index) const { + assert(is_utf8(index)); + return m_entries[index].CONSTANT_Utf8.string; + } + /// Returns characters stored in utf8 string for CONSTANT_String entry + /// @param index - index into constant pool + /// @return utf8 string characters for this constant pool entry + const char* get_string_chars(uint16 index) const { + return get_string(index)->bytes; + } + /// Returns utf8 string stored for CONSTANT_String entry + /// @param index - index into constant pool + /// @return utf8 string stored in constant pool entry + String* get_string(uint16 index) const { + assert(is_string(index)); + return m_entries[index].CONSTANT_String.string; + } + /// Returns utf8 string representing name part of name and type + /// constant pool entry + /// @param index - index into constant pool + /// @return utf8 string with name part + String* get_name_and_type_name(uint16 index) const { + assert(is_name_and_type(index)); + assert(is_entry_resolved(index)); + return m_entries[index].CONSTANT_NameAndType.name; + } + /// Returns utf8 string representing descriptor part of name and type + /// constant pool entry + /// @param index - index into constant pool + /// @return utf8 string with descriptor part + String* get_name_and_type_descriptor(uint16 index) const { + assert(is_name_and_type(index)); + assert(is_entry_resolved(index)); + return m_entries[index].CONSTANT_NameAndType.descriptor; + } + /// Returns generic class member for CONSTANT_*ref constant pool entry + /// @param index - index into constant pool + /// @return generic class member for this constant pool entry + Class_Member* get_ref_class_member(uint16 index) const { + assert(is_fieldref(index) + || is_methodref(index) + || is_interfacemethodref(index)); + return m_entries[index].CONSTANT_ref.member; + } + /// Returns method from CONSTANT_Methodref or CONSTANT_InterfaceMethodref + /// constant pool entry + /// @param index - index into constant pool + /// @return method from this constant pool entry + Method* get_ref_method(uint16 index) const { + assert(is_methodref(index) + || is_interfacemethodref(index)); + assert(is_entry_resolved(index)); + return m_entries[index].CONSTANT_ref.method; + } + /// Returns field from CONSTANT_Fieldref constant pool entry + /// @param index - index into constant pool + /// @return field from this constant pool entry + Field* get_ref_field(uint16 index) const { + assert(is_fieldref(index)); + assert(is_entry_resolved(index)); + return m_entries[index].CONSTANT_ref.field; + } + /// Returns class for CONSTANT_Class constant pool entry + /// @param index - index into constant pool + /// @return class for this constant pool entry + Class* get_class_class(uint16 index) const { + assert(is_class(index)); + assert(is_entry_resolved(index)); + return m_entries[index].CONSTANT_Class.klass; + } + /// Returns integer value for constant stored in constant pool + /// @param index - index into constant pool + /// @return value of integer constant stored in constant pool + uint32 get_int(uint16 index) const { + assert(get_tag(index) == CONSTANT_Integer); + return m_entries[index].int_value; + } + /// Returns 32-bit value (either interger or float) + /// for constant stored in constant pool + /// @param index - index into constant pool + /// @return value of 32-bit constant stored in constant pool + uint32 get_4byte(uint16 index) const { + assert(get_tag(index) == CONSTANT_Integer + || get_tag(index) == CONSTANT_Float); + return m_entries[index].int_value; + } + /// Returns float value for constant stored in constant pool + /// @param index - index into constant pool + /// @return value of float constant stored in constant pool + float get_float(uint16 index) const { + assert(get_tag(index) == CONSTANT_Float); + return m_entries[index].float_value; + } + /// Returns low word of 64-bit constant (long or double) stored in constant pool + /// @param index - index into constant pool + /// @return value of low 32-bits of 64-bit constant + uint32 get_8byte_low_word(uint16 index) const { + assert(get_tag(index) == CONSTANT_Long + || get_tag(index) == CONSTANT_Double); + return m_entries[index].CONSTANT_8byte.low_bytes; + } + /// Returns high word of 64-bit constant (long or double) stored in constant pool + /// @param index - index into constant pool + /// @return value of high 32-bits of 64-bit constant + uint32 get_8byte_high_word(uint16 index) const { + assert(get_tag(index) == CONSTANT_Long + || get_tag(index) == CONSTANT_Double); + return m_entries[index].CONSTANT_8byte.high_bytes; + } + /// Returns address of constant stored in constant pool + /// @param index - index into constant pool + /// @return address of constant + void* get_address_of_constant(uint16 index) const { + assert(is_constant(index)); + assert(!is_string(index)); + return (void*)(m_entries + index); + } + /// Returns exception which has caused failure of + /// the referred constant pool entry + /// @param index - index into constant pool + /// @return exception object which is the cause of resolution failure + jthrowable get_error_cause(uint16 index) const { + assert(is_entry_in_error(index)); + return (jthrowable)(&(m_entries[index].error.cause)); + } + /// Returns head of single-linked list containing resolution errors + /// in this constant pool + /// @return head of signle-linked list of constant pool entries which + /// resolution had failed + ConstPoolEntry* get_error_chain() const { + return m_failedResolution; + } -#define cp_is_string(cp,i) (cp_tag(cp,i) == CONSTANT_String) -#define cp_is_fieldref(cp,i) (cp_tag(cp,i) == CONSTANT_Fieldref) -#define cp_is_methodref(cp,i) (cp_tag(cp,i) == CONSTANT_Methodref) -#define cp_is_interfacemethodref(cp,i) (cp_tag(cp,i) == CONSTANT_InterfaceMethodref) + /// Returns index in constant pool where utf8 representation + /// for CONSTANT_String is stored + /// @param index - index into constant pool for CONSTANT_String entry + /// @return index in constant pool with utf8 representation of this string + uint16 get_string_index(uint16 index) const { + assert(is_string(index)); + return m_entries[index].CONSTANT_String.string_index; + } + /// Returns index of constant pool entry containing utf8 string + /// with name part + /// @param index - index into constant pool + /// @return index in constant pool with utf8 string for name + uint16 get_name_and_type_name_index(uint16 index) const { + assert(is_name_and_type(index)); + return m_entries[index].CONSTANT_NameAndType.name_index; + } + /// Returns index of constant pool entry containing utf8 string + /// with descriptor part + /// @param index - index into constant pool + /// @return index in constant pool with utf8 string for descriptor + uint16 get_name_and_type_descriptor_index(uint16 index) const { + assert(is_name_and_type(index)); + return m_entries[index].CONSTANT_NameAndType.descriptor_index; + } + /// Returns index of constant pool entry containing class for + /// this CONSTANT_*ref entry + /// @param index - index into constant pool + /// @return index of class entry for this constant pool entry + uint16 get_ref_class_index(uint16 index) const { + assert(is_fieldref(index) + || is_methodref(index) + || is_interfacemethodref(index)); + return m_entries[index].CONSTANT_ref.class_index; + } + /// Returns index of CONSTANT_NameAndType for this constant pool entry + /// @param index - index into constant pool + /// @return index of CONSTANT_NameAndType for this constant pool entry + uint16 get_ref_name_and_type_index(uint16 index) const { + assert(is_fieldref(index) + || is_methodref(index) + || is_interfacemethodref(index)); + return m_entries[index].CONSTANT_ref.name_and_type_index; + } + /// Returns class name index in constant pool for CONSTANT_Class entry + /// @param index - index into constant pool + /// @return index of utf8 name of this class + uint16 get_class_name_index(uint16 index) const { + assert(is_class(index)); + return m_entries[index].CONSTANT_Class.name_index; + } -#define cp_resolve_to_class(cp,i,c) cp_set_resolved(cp,i); cp[i].CONSTANT_Class.klass=c; + /// Resolves entry to the class + /// @param index - index into constant pool + /// @param clss - class to resolve this entry to + void resolve_entry(uint16 index, Class* clss) { + // we do not want to resolve entry of different type + assert(is_class(index)); + set_entry_resolved(index); + m_entries[index].CONSTANT_Class.klass = clss; + } + /// Resolves entry to the field + /// @param index - index into constant pool + /// @param field - field to resolve this entry to + void resolve_entry(uint16 index, Field* field) { + // we do not want to resolve entry of different type + assert(is_fieldref(index)); + set_entry_resolved(index); + m_entries[index].CONSTANT_ref.field = field; + } + /// Resolves entry to the method + /// @param index - index into constant pool + /// @param method - method to resolve this entry to + void resolve_entry(uint16 index, Method* method) { + // we do not want to resolve entry of different type + assert(is_methodref(index) || is_interfacemethodref(index)); + set_entry_resolved(index); + m_entries[index].CONSTANT_ref.method = method; + } + /// Records resolution error into constant pool entry + /// @param index - index into constant pool + /// @param exn - cause of resolution failure + /// @note suspension must be disabled during this operation + void resolve_as_error(uint16 index, jthrowable exn) { + assert(is_class(index) + || is_fieldref(index) + || is_methodref(index) + || is_interfacemethodref(index)); + // 'if' clause is changed to 'assert' expression as this should never + // happen, i.e. class resolution should never try to resolve failing + // entry twice + // if(!cp.is_entry_in_error(cp_index)) { + assert(!is_entry_in_error(index)); + set_entry_error_state(index); + m_entries[index].error.cause = *((ManagedObject**)exn); + m_entries[index].error.next = m_failedResolution; + assert(&(m_entries[index]) != m_failedResolution); + m_failedResolution = &(m_entries[index]); + // } + } -#define cp_resolve_to_field(cp,i,f) cp_set_resolved(cp,i); cp[i].CONSTANT_ref.field=f; + /// Parses in constant pool for a class + /// @param clss - class, containing this constant pool + /// @param string_pool - reference to string pool to indern strings in + /// @param cfs - byte stream to parse constant pool from + /// @return true, if constant pool was parsed successfully, false, if + /// some error was discovered during parsing + bool parse(Class* clss, String_Pool& string_pool, ByteReader& cfs); + + /// Checks consistency of constant pool. Makes sure all indices to other + /// constant pool entries are in range. Makes sure contents of constant + /// pool entries are of the right type. Sets CONSTANT_Class entries + /// to point directly to String representing internal form of + /// fully qualified name of Class. Sets CONSTANT_String entries to point + /// directly to String representation of String. + /// Preresolves CONSTANT_NameAndType entries to signatures + /// @param clss - class this constant pool belongs to + /// @return true if constant pool of this class is valid, false otherwise + bool check(Class* clss); + + /// Clears content of constant pool: tags and entries arrays + void clear() { + if(m_size != 0) { + delete[] m_entries[0].tags; + delete[] m_entries; + } + init(); + } + /// Initializes constant pool to initial values + void init() { + m_size = 0; + m_entries = NULL; + m_failedResolution = NULL; + } +private: + /// Sets resolved flag in constant pool entry + /// @param index - index into constant pool + void set_entry_resolved(uint16 index) { + assert(is_valid_index(index)); + // we do not want to resolve one entry twice + assert(!is_entry_resolved(index)); + // we should not resolve failed entries + assert(!is_entry_in_error(index)); + m_entries[0].tags[index] |= RESOLVED_MASK; + } + /// Sets error flag in constant pool entry thus marking it failed + /// @param index - index into constant pool + void set_entry_error_state(uint16 index) { + assert(is_valid_index(index)); + // we do not want to reset resolved error + assert(!is_entry_resolved(index)); + // we do not want to reset reason of the failure + assert(!is_entry_in_error(index)); + m_entries[0].tags[index] |= ERROR_MASK; + } + /// Resolves CONSTANT_NameAndType constant pool entry to actual string values + /// @param index - index into constant pool + /// @param name - name-and-type name + /// @param descriptor - name-and-type type (descriptor) + void resolve_entry(uint16 index, String* name, String* descriptor) { + // we do not want to resolve entry of different type + assert(is_name_and_type(index)); + set_entry_resolved(index); + m_entries[index].CONSTANT_NameAndType.name = name; + m_entries[index].CONSTANT_NameAndType.descriptor = descriptor; + } + /// Resolves CONSTANT_String constant pool entry to actual string value + /// @param index - index into constant pool + /// @param str - actual string + void resolve_entry(uint16 index, String* str) { + assert(is_string(index)); + set_entry_resolved(index); + m_entries[index].CONSTANT_String.string = str; + } +}; -#define cp_resolve_to_method(cp,i,m) cp_set_resolved(cp,i); cp[i].CONSTANT_ref.method=m; /////////////////////////////////////////////////////////////////////////////// // A Java class /////////////////////////////////////////////////////////////////////////////// extern "C" { - // // state of this class // @@ -360,7 +762,6 @@ typedef struct Class { TypeDesc* array_element_type_desc; uint16 access_flags; - uint16 cp_size; uint16 n_superinterfaces; uint16 n_fields; uint16 n_static_fields; @@ -377,7 +778,7 @@ typedef struct Class { // empty string if anonymous String * simple_name; - Const_Pool *const_pool; // constant pool array; size is cp_size + ConstantPool m_const_pool; // constant pool array Field *fields; // array of fields; size is n_fields Method *methods; // array of methods; size is n_methods // @@ -547,10 +948,6 @@ #endif // class operations lock Lock_Manager* m_lock; - // List of constant pool entries, which resolution had failed - // Required for fast enumeration of error objects - Const_Pool* m_failedResolution; - // struct Class accessibility unsigned m_markBit:1; @@ -620,8 +1017,6 @@ VMEXPORT Class *class_resolve_class(Clas Boolean check_member_access(Class_Member *member, Class *other_clss); // Can "other_clss" access the "inner_clss" Boolean check_inner_class_access(Global_Env *env, Class *inner_clss, Class *other_clss); -// get class name from constant pool -extern String *cp_check_class(Const_Pool *cp, unsigned cp_size, unsigned class_index); // // parses in class description from a class file format diff --git a/enhanced/drlvm/trunk/vm/vmcore/include/class_member.h b/enhanced/drlvm/trunk/vm/vmcore/include/class_member.h index b0e3186..d148275 100644 --- a/enhanced/drlvm/trunk/vm/vmcore/include/class_member.h +++ b/enhanced/drlvm/trunk/vm/vmcore/include/class_member.h @@ -20,7 +20,7 @@ #include "String_Pool.h" #include "annotation.h" #include "jit_intf.h" -union Const_Pool; +struct ConstantPool; class ByteReader; class JIT; class CodeChunkInfo; @@ -132,7 +132,7 @@ #endif String* _signature; Class* _class; - bool parse(Class* clss, Const_Pool* cp, unsigned cp_size, ByteReader& cfs); + bool parse(Class* clss, ByteReader& cfs); /* * returns ATTR_ERROR if attribute was recognized but parsing failed; @@ -218,7 +218,7 @@ public: unsigned is_transient() {return (_access_flags&ACC_TRANSIENT);} bool is_enum() {return (_access_flags&ACC_ENUM)?true:false;} - bool parse(Class* clss, Const_Pool* cp, unsigned cp_size, ByteReader& cfs); + bool parse(Class* clss, ByteReader& cfs); unsigned calculate_size(); @@ -290,8 +290,7 @@ private: class Handler { public: Handler(); - bool parse(Const_Pool *cp, unsigned cp_size, - unsigned code_length, ByteReader &cfs); + bool parse(ConstantPool& cp, unsigned code_length, ByteReader &cfs); uint32 get_start_pc() {return _start_pc;} uint32 get_end_pc() {return _end_pc;} uint32 get_handler_pc() {return _handler_pc;} @@ -612,8 +611,7 @@ public: bool is_fake_method() {return (_intf_method_for_fake_method != NULL);} Method *get_real_intf_method() {return _intf_method_for_fake_method;} - bool parse(Global_Env& env, Class* clss, - Const_Pool* cp, unsigned cp_size, ByteReader& cfs); + bool parse(Global_Env& env, Class* clss, ByteReader& cfs); unsigned calculate_size() { unsigned size = sizeof(Class_Member) + sizeof(Method); @@ -664,12 +662,11 @@ private: // // private methods for parsing methods // - bool _parse_code(Const_Pool *cp, unsigned cp_size, unsigned code_attr_len, ByteReader &cfs); + bool _parse_code(ConstantPool& cp, unsigned code_attr_len, ByteReader &cfs); bool _parse_line_numbers(unsigned attr_len, ByteReader &cfs); - bool _parse_exceptions(Const_Pool *cp, unsigned cp_size, unsigned attr_len, - ByteReader &cfs); + bool _parse_exceptions(ConstantPool& cp, unsigned attr_len, ByteReader &cfs); void _set_nop(); @@ -680,7 +677,7 @@ private: Local_Var_Table *_local_vars_table; bool _parse_local_vars(const char* attr_name, Local_Var_Table** lvt_address, - Const_Pool *cp, unsigned cp_size, unsigned attr_len, ByteReader &cfs); + ConstantPool& cp, unsigned attr_len, ByteReader &cfs); // This is the number of breakpoints which should be set in the // method when it is compiled. This number does not reflect diff --git a/enhanced/drlvm/trunk/vm/vmcore/src/class_support/C_Interface.cpp b/enhanced/drlvm/trunk/vm/vmcore/src/class_support/C_Interface.cpp index 6b45512..4192724 100644 --- a/enhanced/drlvm/trunk/vm/vmcore/src/class_support/C_Interface.cpp +++ b/enhanced/drlvm/trunk/vm/vmcore/src/class_support/C_Interface.cpp @@ -740,28 +740,10 @@ const char *class_get_source_file_name(C } //class_get_source_file_name - -// If this function was exported through the public interface, we should -// change the return type to something like String_Handle. -String *class_get_const_string_handle(Class_Handle cl, unsigned index) -{ - assert(cl); - Class *clss = (Class *)cl; - String *str = 0; - assert(index < clss->cp_size); - Const_Pool *cp = clss->const_pool; - str = cp[index].CONSTANT_String.string; - return str; -} //class_get_const_string_handle - - - -const char *class_get_const_string(Class_Handle cl, unsigned index) +const char* class_get_const_string(Class_Handle cl, unsigned index) { assert(cl); - String *str = class_get_const_string_handle(cl, index); - assert(str); - return str->bytes; + return cl->m_const_pool.get_string_chars(index); } //class_get_const_string @@ -773,7 +755,7 @@ void *class_get_const_string_intern_addr { assert(cl); Global_Env *env = VM_Global_State::loader_env; - String *str = class_get_const_string_handle(cl, index); + String* str = cl->m_const_pool.get_string(index); assert(str); bool must_instantiate; @@ -791,7 +773,6 @@ void *class_get_const_string_intern_addr vm_instantiate_cp_string_resolved(str); END_RAISE_AREA; tmn_suspend_enable(); - } if (env->compress_references) { @@ -805,23 +786,21 @@ void *class_get_const_string_intern_addr const char* class_get_cp_entry_signature(Class_Handle src_class, unsigned short index) { Class* clss = (Class*)src_class; - // TODO: check that index is valid for src_class; assert for now - assert(index < clss->cp_size); - assert(cp_is_methodref(clss->const_pool, index) - || cp_is_interfacemethodref(clss->const_pool, index) - || cp_is_fieldref(clss->const_pool, index)); - - index = clss->const_pool[index].CONSTANT_ref.name_and_type_index; - index = clss->const_pool[index].CONSTANT_NameAndType.descriptor_index; - return clss->const_pool[index].CONSTANT_Utf8.string->bytes; + ConstantPool& cp = src_class->m_const_pool; + + assert(cp.is_fieldref(index) + || cp.is_methodref(index) + || cp.is_interfacemethodref(index)); + + index = cp.get_ref_name_and_type_index(index); + index = cp.get_name_and_type_descriptor_index(index); + return cp.get_utf8_chars(index); } // class_get_cp_entry_signature VM_Data_Type class_get_cp_field_type(Class_Handle src_class, unsigned short cp_index) { - // TODO: check that cp_index is valid for src_class; assert for now - assert(cp_index < ((Class*)src_class)->cp_size); - assert(cp_is_fieldref(((Class*)src_class)->const_pool, cp_index)); + assert(src_class->m_const_pool.is_fieldref(cp_index)); char class_id = (class_get_cp_entry_signature(src_class, cp_index))[0]; switch(class_id) @@ -1047,148 +1026,148 @@ Class_Handle class_find_class_from_loade // The following do not cause constant pools to be resolve, if they are not // resolved already // -const char *const_pool_get_field_name(Class_Handle cl, unsigned index) +const char* const_pool_get_field_name(Class_Handle cl, unsigned index) { assert(cl); - Const_Pool *const_pool = ((Class *)cl)->const_pool; - if (!cp_is_fieldref(const_pool,index)) { + ConstantPool& const_pool = cl->m_const_pool; + if(!const_pool.is_fieldref(index)) { ABORT("Wrong index"); return 0; } - index = const_pool[index].CONSTANT_ref.name_and_type_index; - index = const_pool[index].CONSTANT_NameAndType.name_index; - return const_pool[index].CONSTANT_Utf8.string->bytes; -} //const_pool_get_field_name + index = const_pool.get_ref_name_and_type_index(index); + index = const_pool.get_name_and_type_name_index(index); + return const_pool.get_utf8_chars(index); +} // const_pool_get_field_name -const char *const_pool_get_field_class_name(Class_Handle cl, unsigned index) +const char* const_pool_get_field_class_name(Class_Handle cl, unsigned index) { assert(cl); - Const_Pool *const_pool = ((Class *)cl)->const_pool; - if (!cp_is_fieldref(const_pool,index)) { + ConstantPool& const_pool = cl->m_const_pool; + if(!const_pool.is_fieldref(index)) { ABORT("Wrong index"); return 0; } - index = const_pool[index].CONSTANT_ref.class_index; - return const_pool_get_class_name(cl,index); + index = const_pool.get_ref_class_index(index); + return const_pool_get_class_name(cl, index); } //const_pool_get_field_class_name -const char *const_pool_get_field_descriptor(Class_Handle cl, unsigned index) +const char* const_pool_get_field_descriptor(Class_Handle cl, unsigned index) { assert(cl); - Const_Pool *const_pool = ((Class *)cl)->const_pool; - if (!cp_is_fieldref(const_pool,index)) { + ConstantPool& const_pool = cl->m_const_pool; + if (!const_pool.is_fieldref(index)) { ABORT("Wrong index"); return 0; } - index = const_pool[index].CONSTANT_ref.name_and_type_index; - index = const_pool[index].CONSTANT_NameAndType.descriptor_index; - return const_pool[index].CONSTANT_Utf8.string->bytes; -} //const_pool_get_field_descriptor + index = const_pool.get_ref_name_and_type_index(index); + index = const_pool.get_name_and_type_descriptor_index(index); + return const_pool.get_utf8_chars(index); +} // const_pool_get_field_descriptor -const char *const_pool_get_method_name(Class_Handle cl, unsigned index) +const char* const_pool_get_method_name(Class_Handle cl, unsigned index) { assert(cl); - Const_Pool *const_pool = ((Class *)cl)->const_pool; - if (!cp_is_methodref(const_pool,index)) { + ConstantPool& const_pool = cl->m_const_pool; + if (!const_pool.is_methodref(index)) { ABORT("Wrong index"); return 0; } - index = const_pool[index].CONSTANT_ref.name_and_type_index; - index = const_pool[index].CONSTANT_NameAndType.name_index; - return const_pool[index].CONSTANT_Utf8.string->bytes; -} //const_pool_get_method_name + index = const_pool.get_ref_name_and_type_index(index); + index = const_pool.get_name_and_type_name_index(index); + return const_pool.get_utf8_chars(index); +} // const_pool_get_method_name const char *const_pool_get_method_class_name(Class_Handle cl, unsigned index) { assert(cl); - Const_Pool *const_pool = ((Class *)cl)->const_pool; - if (!cp_is_methodref(const_pool,index)) { + ConstantPool& const_pool = cl->m_const_pool; + if (!const_pool.is_methodref(index)) { ABORT("Wrong index"); return 0; } - index = const_pool[index].CONSTANT_ref.class_index; + index = const_pool.get_ref_class_index(index); return const_pool_get_class_name(cl,index); } //const_pool_get_method_class_name -const char *const_pool_get_interface_method_name(Class_Handle cl, unsigned index) +const char* const_pool_get_interface_method_name(Class_Handle cl, unsigned index) { assert(cl); - Const_Pool *const_pool = ((Class *)cl)->const_pool; - if (!cp_is_interfacemethodref(const_pool,index)) { + ConstantPool& const_pool = cl->m_const_pool; + if(!const_pool.is_interfacemethodref(index)) { ABORT("Wrong index"); return 0; } - index = const_pool[index].CONSTANT_ref.name_and_type_index; - index = const_pool[index].CONSTANT_NameAndType.name_index; - return const_pool[index].CONSTANT_Utf8.string->bytes; -} //const_pool_get_interface_method_name + index = const_pool.get_ref_name_and_type_index(index); + index = const_pool.get_name_and_type_name_index(index); + return const_pool.get_utf8_chars(index); +} // const_pool_get_interface_method_name -const char *const_pool_get_interface_method_class_name(Class_Handle cl, unsigned index) +const char* const_pool_get_interface_method_class_name(Class_Handle cl, unsigned index) { assert(cl); - Const_Pool *const_pool = ((Class *)cl)->const_pool; - if (!cp_is_interfacemethodref(const_pool,index)) { + ConstantPool& const_pool = cl->m_const_pool; + if (!const_pool.is_interfacemethodref(index)) { ABORT("Wrong index"); return 0; } - index = const_pool[index].CONSTANT_ref.class_index; + index = const_pool.get_ref_class_index(index); return const_pool_get_class_name(cl,index); } //const_pool_get_interface_method_class_name -const char *const_pool_get_method_descriptor(Class_Handle cl, unsigned index) +const char* const_pool_get_method_descriptor(Class_Handle cl, unsigned index) { assert(cl); - Const_Pool *const_pool = ((Class *)cl)->const_pool; - if (!cp_is_methodref(const_pool,index)) { + ConstantPool& const_pool = cl->m_const_pool; + if (!const_pool.is_methodref(index)) { ABORT("Wrong index"); return 0; } - index = const_pool[index].CONSTANT_ref.name_and_type_index; - index = const_pool[index].CONSTANT_NameAndType.descriptor_index; - return const_pool[index].CONSTANT_Utf8.string->bytes; -} //const_pool_get_method_descriptor + index = const_pool.get_ref_name_and_type_index(index); + index = const_pool.get_name_and_type_descriptor_index(index); + return const_pool.get_utf8_chars(index); +} // const_pool_get_method_descriptor -const char *const_pool_get_interface_method_descriptor(Class_Handle cl, unsigned index) +const char* const_pool_get_interface_method_descriptor(Class_Handle cl, unsigned index) { assert(cl); - Const_Pool *const_pool = ((Class *)cl)->const_pool; - if (!cp_is_interfacemethodref(const_pool,index)) { + ConstantPool& const_pool = cl->m_const_pool; + if (!const_pool.is_interfacemethodref(index)) { ABORT("Wrong index"); return 0; } - index = const_pool[index].CONSTANT_ref.name_and_type_index; - index = const_pool[index].CONSTANT_NameAndType.descriptor_index; - return const_pool[index].CONSTANT_Utf8.string->bytes; -} //const_pool_get_interface_method_descriptor + index = const_pool.get_ref_name_and_type_index(index); + index = const_pool.get_name_and_type_descriptor_index(index); + return const_pool.get_utf8_chars(index); +} // const_pool_get_interface_method_descriptor -const char *const_pool_get_class_name(Class_Handle cl, unsigned index) +const char* const_pool_get_class_name(Class_Handle cl, unsigned index) { assert(cl); - Const_Pool *const_pool = ((Class *)cl)->const_pool; - if (!cp_is_class(const_pool,index)) { + ConstantPool& const_pool = cl->m_const_pool; + if (!const_pool.is_class(index)) { ABORT("Wrong index"); return 0; } - return const_pool[const_pool[index].CONSTANT_Class.name_index].CONSTANT_Utf8.string->bytes; -} //const_pool_get_class_name + return const_pool.get_utf8_chars(const_pool.get_class_name_index(index)); +} // const_pool_get_class_name unsigned method_number_throws(Method_Handle m) diff --git a/enhanced/drlvm/trunk/vm/vmcore/src/class_support/Class.cpp b/enhanced/drlvm/trunk/vm/vmcore/src/class_support/Class.cpp index 4f6b51d..e07b7a0 100644 --- a/enhanced/drlvm/trunk/vm/vmcore/src/class_support/Class.cpp +++ b/enhanced/drlvm/trunk/vm/vmcore/src/class_support/Class.cpp @@ -454,7 +454,8 @@ void set_struct_Class_field_in_java_lang void class_report_failure(Class* target, uint16 cp_index, jthrowable exn) { - assert(cp_index > 0 && cp_index < target->cp_size); + ConstantPool& cp = target->m_const_pool; + assert(cp.is_valid_index(cp_index)); assert(hythread_is_suspend_enabled()); if (exn_raised()) { TRACE2("classloader.error", "runtime exception in classloading"); @@ -465,13 +466,7 @@ void class_report_failure(Class* target, tmn_suspend_disable(); target->m_lock->_lock(); // vvv - This should be atomic change - if (!cp_in_error(target->const_pool, cp_index)) { - cp_set_error(target->const_pool, cp_index); - target->const_pool[cp_index].error.cause = ((ObjectHandle)exn)->object; - target->const_pool[cp_index].error.next = target->m_failedResolution; - assert(&(target->const_pool[cp_index]) != target->m_failedResolution); - target->m_failedResolution = &(target->const_pool[cp_index]); - } + cp.resolve_as_error(cp_index, exn); // ^^^ target->m_lock->_unlock(); tmn_suspend_enable(); @@ -480,8 +475,8 @@ void class_report_failure(Class* target, jthrowable class_get_linking_error(Class* clss, unsigned index) { - assert(cp_in_error(clss->const_pool, index)); - return (jthrowable)(&(clss->const_pool[index].error.cause)); + assert(clss->m_const_pool.is_entry_in_error(index)); + return clss->m_const_pool.get_error_cause(index); } String* class_get_java_name(Class* clss, Global_Env* env) diff --git a/enhanced/drlvm/trunk/vm/vmcore/src/class_support/Class_File_Loader.cpp b/enhanced/drlvm/trunk/vm/vmcore/src/class_support/Class_File_Loader.cpp index d2c1ed3..6d4f963 100644 --- a/enhanced/drlvm/trunk/vm/vmcore/src/class_support/Class_File_Loader.cpp +++ b/enhanced/drlvm/trunk/vm/vmcore/src/class_support/Class_File_Loader.cpp @@ -28,6 +28,7 @@ #include #include "environment.h" #include "classloader.h" #include "Class.h" +#include "class_member.h" #include "vm_strings.h" #include "open/vm_util.h" #include "bytereader.h" @@ -65,33 +66,29 @@ #define REPORT_FAILED_CLASS_FORMAT(klass } #define valid_cpi(clss, idx, type) \ - (idx < clss->cp_size && cp_tag(clss->const_pool, idx) == type) + (clss->m_const_pool.is_valid_index(idx) && clss->m_const_pool.get_tag(idx) == type) -String *cp_check_utf8(Const_Pool *cp, - unsigned cp_size, - unsigned utf8_index) +String* cp_check_utf8(ConstantPool& cp, unsigned utf8_index) { - if(utf8_index >= cp_size || !cp_is_utf8(cp, utf8_index)) { + if(!cp.is_valid_index(utf8_index) || !cp.is_utf8(utf8_index)) { return NULL; } - return cp[utf8_index].CONSTANT_Utf8.string; -} //cp_check_utf8 + return cp.get_utf8_string(utf8_index); +} // cp_check_utf8 -String *cp_check_class(Const_Pool *cp, - unsigned cp_size, - unsigned class_index) +String* cp_check_class(ConstantPool& cp, unsigned class_index) { - if (class_index >= cp_size || !cp_is_class(cp,class_index)) { + if(!cp.is_valid_index(class_index) || !cp.is_class(class_index)) { #ifdef _DEBUG WARN("cp_check_class: illegal const pool class index" << class_index); #endif return NULL; } - return cp[cp[class_index].CONSTANT_Class.name_index].CONSTANT_Utf8.string; + return cp.get_utf8_string(cp.get_class_name_index(class_index)); } //cp_check_class @@ -215,7 +212,7 @@ String* parse_signature_attr(ByteReader "cannot parse Signature index"); return NULL; } - String* sig = cp_check_utf8(clss->const_pool, clss->cp_size, idx); + String* sig = cp_check_utf8(clss->m_const_pool, idx); if(!sig) { REPORT_FAILED_CLASS_FORMAT(clss, "invalid Signature index : " << idx); } @@ -224,8 +221,7 @@ String* parse_signature_attr(ByteReader Attributes parse_attribute(ByteReader &cfs, - Const_Pool *cp, - unsigned cp_size, + ConstantPool& cp, String *attr_strings[], Attributes attrs[], uint32 *attr_len, @@ -242,7 +238,7 @@ Attributes parse_attribute(ByteReader &c if (!result) return ATTR_ERROR; - String *attr_name = cp_check_utf8(cp,cp_size,attr_name_index); + String* attr_name = cp_check_utf8(cp, attr_name_index); if (attr_name == NULL) { #ifdef _DEBUG WARN("parse_attribute: illegal const pool attr_name_index"); @@ -293,7 +289,7 @@ uint32 parse_annotation(Annotation** val "cannot parse type index of annotation"); return 0; } - String* type = cp_check_utf8(clss->const_pool, clss->cp_size, type_idx); + String* type = cp_check_utf8(clss->m_const_pool, type_idx); if (type == NULL) { REPORT_FAILED_CLASS_FORMAT(clss, "invalid type index of annotation : " << type_idx); @@ -324,7 +320,7 @@ uint32 parse_annotation(Annotation** val "cannot parse element_name_index of annotation element"); return 0; } - antn->elements[j].name = cp_check_utf8(clss->const_pool, clss->cp_size, name_idx); + antn->elements[j].name = cp_check_utf8(clss->m_const_pool, name_idx); if (antn->elements[j].name == NULL) { REPORT_FAILED_CLASS_FORMAT(clss, "invalid element_name_index of annotation : " << name_idx); @@ -353,8 +349,8 @@ uint32 parse_annotation_value(Annotation value.tag = (AnnotationValueType)tag; uint32 read_len = 1; - Const_Pool *cp = clss->const_pool; - unsigned cp_size = clss->cp_size; + ConstantPool& cp = clss->m_const_pool; + unsigned cp_size = cp.get_size(); char ctag = (char)tag; switch(ctag) { @@ -381,29 +377,29 @@ uint32 parse_annotation_value(Annotation case AVT_CHAR: case AVT_INT: if (valid_cpi(clss, const_idx, CONSTANT_Integer)) { - value.const_value.i = cp[const_idx].int_value; + value.const_value.i = cp.get_int(const_idx); break; } case AVT_FLOAT: if (valid_cpi(clss, const_idx, CONSTANT_Float)) { - value.const_value.f = cp[const_idx].float_value; + value.const_value.f = cp.get_float(const_idx); break; } case AVT_LONG: if (valid_cpi(clss, const_idx, CONSTANT_Long)) { - value.const_value.l.lo_bytes = cp[const_idx].CONSTANT_8byte.low_bytes; - value.const_value.l.hi_bytes = cp[const_idx].CONSTANT_8byte.high_bytes; + value.const_value.l.lo_bytes = cp.get_8byte_low_word(const_idx); + value.const_value.l.hi_bytes = cp.get_8byte_high_word(const_idx); break; } case AVT_DOUBLE: if (valid_cpi(clss, const_idx, CONSTANT_Double)) { - value.const_value.l.lo_bytes = cp[const_idx].CONSTANT_8byte.low_bytes; - value.const_value.l.hi_bytes = cp[const_idx].CONSTANT_8byte.high_bytes; + value.const_value.l.lo_bytes = cp.get_8byte_low_word(const_idx); + value.const_value.l.hi_bytes = cp.get_8byte_high_word(const_idx); break; } case AVT_STRING: if (valid_cpi(clss, const_idx, CONSTANT_Utf8)) { - value.const_value.string = cp[const_idx].CONSTANT_Utf8.string; + value.const_value.string = cp.get_utf8_string(const_idx); break; } default: @@ -424,7 +420,7 @@ uint32 parse_annotation_value(Annotation "cannot parse class_info_index of annotation value"); return 0; } - value.class_name = cp_check_utf8(cp, cp_size, class_idx); + value.class_name = cp_check_utf8(cp, class_idx); if (value.class_name == NULL) { REPORT_FAILED_CLASS_FORMAT(clss, "invalid class_info_index of annotation value: " << class_idx); @@ -442,7 +438,7 @@ uint32 parse_annotation_value(Annotation "cannot parse type_name_index of annotation enum value"); return 0; } - value.enum_const.type = cp_check_utf8(cp, cp_size, type_idx); + value.enum_const.type = cp_check_utf8(cp, type_idx); if (value.enum_const.type == NULL) { REPORT_FAILED_CLASS_FORMAT(clss, "invalid type_name_index of annotation enum value: " << type_idx); @@ -454,7 +450,7 @@ uint32 parse_annotation_value(Annotation "cannot parse const_name_index of annotation enum value"); return 0; } - value.enum_const.name = cp_check_utf8(cp, cp_size, name_idx); + value.enum_const.name = cp_check_utf8(cp, name_idx); if (value.enum_const.name == NULL) { REPORT_FAILED_CLASS_FORMAT(clss, "invalid const_name_index of annotation enum value: " << name_idx); @@ -610,7 +606,7 @@ void* Class_Member::Alloc(size_t size) { } -bool Class_Member::parse(Class *clss, Const_Pool *cp, unsigned cp_size, ByteReader &cfs) +bool Class_Member::parse(Class *clss, ByteReader &cfs) { if (!cfs.parse_u2_be(&_access_flags)) { REPORT_FAILED_CLASS_FORMAT(clss, "cannot parse member access flags"); @@ -630,12 +626,13 @@ bool Class_Member::parse(Class *clss, Co return false; } + ConstantPool& cp = clss->m_const_pool; // // look up the name_index and descriptor_index // utf8 string const pool entries // - String *name = cp_check_utf8(cp,cp_size,name_index); - String *descriptor = cp_check_utf8(cp,cp_size,descriptor_index); + String* name = cp_check_utf8(cp, name_index); + String* descriptor = cp_check_utf8(cp, descriptor_index); if (name == NULL || descriptor == NULL) { REPORT_FAILED_CLASS_FORMAT(clss, "some of member name or descriptor indexes is not CONSTANT_Utf8 entry : " @@ -739,9 +736,9 @@ check_field_descriptor( const char *desc // DIE( "unreachable code!" ); // exclude remark #111: statement is unreachable } -bool Field::parse(Class *clss, Const_Pool *cp, unsigned cp_size, ByteReader &cfs) +bool Field::parse(Class *clss, ByteReader &cfs) { - if(!Class_Member::parse(clss, cp, cp_size, cfs)) + if(!Class_Member::parse(clss, cfs)) return false; if(!check_field_name(_name)) { @@ -750,7 +747,7 @@ bool Field::parse(Class *clss, Const_Poo } // check field descriptor - const char *next; + const char* next; if(!check_field_descriptor(_descriptor->bytes, &next, false) || *next != '\0') { REPORT_FAILED_CLASS_FORMAT(clss, "illegal field descriptor : " << _descriptor->bytes); return false; @@ -789,9 +786,11 @@ bool Field::parse(Class *clss, Const_Poo uint32 attr_len = 0; + ConstantPool& cp = clss->m_const_pool; + for (unsigned j=0; j= cp_size) { + if(_const_value_index == 0 || _const_value_index >= cp.get_size()) { REPORT_FAILED_CLASS_CLASS(clss->class_loader, clss, "java/lang/ClassFormatError", clss->name->bytes << ": invalid ConstantValue index for field " << get_name()); return false; } // type of constant must match field's type - Const_Pool_Tags tag = (Const_Pool_Tags)cp_tag(cp, _const_value_index); + Const_Pool_Tags tag = (Const_Pool_Tags)cp.get_tag(_const_value_index); Java_Type java_type = get_java_type(); @@ -837,8 +836,8 @@ bool Field::parse(Class *clss, Const_Poo << get_name()); return false; } - const_value.l.lo_bytes = cp[_const_value_index].CONSTANT_8byte.low_bytes; - const_value.l.hi_bytes = cp[_const_value_index].CONSTANT_8byte.high_bytes; + const_value.l.lo_bytes = cp.get_8byte_low_word(_const_value_index); + const_value.l.hi_bytes = cp.get_8byte_high_word(_const_value_index); break; } case CONSTANT_Float: @@ -850,7 +849,7 @@ bool Field::parse(Class *clss, Const_Poo << get_name()); return false; } - const_value.f = cp[_const_value_index].float_value; + const_value.f = cp.get_float(_const_value_index); break; } case CONSTANT_Double: @@ -862,8 +861,8 @@ bool Field::parse(Class *clss, Const_Poo << get_name()); return false; } - const_value.l.lo_bytes = cp[_const_value_index].CONSTANT_8byte.low_bytes; - const_value.l.hi_bytes = cp[_const_value_index].CONSTANT_8byte.high_bytes; + const_value.l.lo_bytes = cp.get_8byte_low_word(_const_value_index); + const_value.l.hi_bytes = cp.get_8byte_high_word(_const_value_index); break; } case CONSTANT_Integer: @@ -880,7 +879,7 @@ bool Field::parse(Class *clss, Const_Poo << get_name()); return false; } - const_value.i = cp[_const_value_index].int_value; + const_value.i = cp.get_int(_const_value_index); break; } case CONSTANT_String: @@ -892,7 +891,7 @@ bool Field::parse(Class *clss, Const_Poo << get_name()); return false; } - const_value.string = cp[_const_value_index].CONSTANT_String.string; + const_value.string = cp.get_string(_const_value_index); break; } default: @@ -941,8 +940,8 @@ bool Field::parse(Class *clss, Const_Poo } //Field::parse -bool Handler::parse(Const_Pool* cp, unsigned cp_size, unsigned code_length, - ByteReader &cfs) +bool Handler::parse(ConstantPool& cp, unsigned code_length, + ByteReader& cfs) { uint16 start = 0; if(!cfs.parse_u2_be(&start)) @@ -981,7 +980,7 @@ bool Handler::parse(Const_Pool* cp, unsi if (catch_index == 0) { _catch_type = NULL; } else { - _catch_type = cp_check_class(cp,cp_size,catch_index); + _catch_type = cp_check_class(cp, catch_index); if (_catch_type == NULL) return false; } @@ -1037,8 +1036,8 @@ #define REPORT_FAILED_METHOD(msg) REPORT << _name->bytes << _descriptor->bytes); -bool Method::_parse_exceptions(Const_Pool *cp, unsigned cp_size, unsigned attr_len, - ByteReader &cfs) +bool Method::_parse_exceptions(ConstantPool& cp, unsigned attr_len, + ByteReader& cfs) { if(!cfs.parse_u2_be(&_n_exceptions)) { REPORT_FAILED_CLASS_CLASS(_class->class_loader, _class, "java/lang/ClassFormatError", @@ -1058,7 +1057,7 @@ bool Method::_parse_exceptions(Const_Poo return false; } - _exceptions[i] = cp_check_class(cp,cp_size,index); + _exceptions[i] = cp_check_class(cp, index); if (_exceptions[i] == NULL) { REPORT_FAILED_CLASS_CLASS(_class->class_loader, _class, "java/lang/ClassFormatError", _class->name->bytes << ": exception class index " @@ -1128,7 +1127,7 @@ bool Method::_parse_line_numbers(unsigne bool Method::_parse_local_vars(const char* attr_name, Local_Var_Table** lvt_address, - Const_Pool *cp, unsigned cp_size, unsigned attr_len, ByteReader &cfs) + ConstantPool& cp, unsigned attr_len, ByteReader &cfs) { uint16 n_local_vars; if(!cfs.parse_u2_be(&n_local_vars)) { @@ -1189,14 +1188,14 @@ bool Method::_parse_local_vars(const cha return false; } - String* name = cp_check_utf8(cp,cp_size,name_index); + String* name = cp_check_utf8(cp, name_index); if(name == NULL) { REPORT_FAILED_METHOD("name index is not valid CONSTANT_Utf8 entry " "in " << attr_name << " attribute"); return false; } - String* descriptor = cp_check_utf8(cp,cp_size,descriptor_index); + String* descriptor = cp_check_utf8(cp, descriptor_index); if(descriptor == NULL) { REPORT_FAILED_METHOD("descriptor index is not valid CONSTANT_Utf8 entry " "in " << attr_name << " attribute"); @@ -1232,7 +1231,8 @@ bool Method::_parse_local_vars(const cha } //Method::_parse_local_vars -bool Method::_parse_code( Const_Pool *cp, unsigned cp_size, unsigned code_attr_len, ByteReader &cfs) +bool Method::_parse_code(ConstantPool& cp, unsigned code_attr_len, + ByteReader& cfs) { unsigned real_code_attr_len = 0; if(!cfs.parse_u2_be(&_max_stack)) { @@ -1311,7 +1311,7 @@ bool Method::_parse_code( Const_Pool *cp // ppervov: FIXME: should throw OOME for (i=0; i<_n_handlers; i++) { - if(!_handlers[i].parse(cp, cp_size, _byte_code_length, cfs)) { + if(!_handlers[i].parse(cp, _byte_code_length, cfs)) { REPORT_FAILED_CLASS_CLASS(_class->class_loader, _class, "java/lang/ClassFormatError", _class->name->bytes << ": could not parse exceptions for method " << _name->bytes << _descriptor->bytes); @@ -1337,7 +1337,7 @@ bool Method::_parse_code( Const_Pool *cp uint32 attr_len = 0; for (i=0; im_const_pool; for (unsigned j=0; jconst_pool, clss->cp_size, cfs)) + if(!fd.parse(clss, cfs)) return false; if(fd.is_static()) { clss->fields[clss->n_static_fields] = fd; @@ -1803,7 +1804,7 @@ static bool class_parse_methods(Class *c _total_method_bytes += sizeof(Method)*clss->n_methods; for (unsigned i=0; i < clss->n_methods; i++) { - if (!clss->methods[i].parse(*env, clss, clss->const_pool, clss->cp_size, cfs)) + if(!clss->methods[i].parse(*env, clss, cfs)) return false; Method *m = &clss->methods[i]; @@ -1825,7 +1826,7 @@ static bool class_parse_methods(Class *c } //class_parse_methods -static String* const_pool_parse_utf8data(String_Pool& string_pool, ByteReader& cfs, +static String* class_file_parse_utf8data(String_Pool& string_pool, ByteReader& cfs, uint16 len) { // buffer ends before len @@ -1846,38 +1847,38 @@ static String* const_pool_parse_utf8data } -static String* const_pool_parse_utf8(String_Pool& string_pool, +static String* class_file_parse_utf8(String_Pool& string_pool, ByteReader& cfs) { uint16 len; if(!cfs.parse_u2_be(&len)) return false; - return const_pool_parse_utf8data(string_pool, cfs, len); + return class_file_parse_utf8data(string_pool, cfs, len); } -static bool class_parse_const_pool(Class *clss, - String_Pool& string_pool, - ByteReader &cfs) +bool ConstantPool::parse(Class* clss, + String_Pool& string_pool, + ByteReader& cfs) { - if(!cfs.parse_u2_be(&clss->cp_size)) { + if(!cfs.parse_u2_be(&m_size)) { REPORT_FAILED_CLASS_CLASS(clss->class_loader, clss, "java/lang/ClassFormatError", clss->name->bytes << ": could not parse constant pool size"); return false; } - unsigned char *cp_tags = new unsigned char[clss->cp_size]; + unsigned char* cp_tags = new unsigned char[m_size]; // ppervov: FIXME: should throw OOME - clss->const_pool = new Const_Pool[clss->cp_size]; + m_entries = new ConstPoolEntry[m_size]; // ppervov: FIXME: should throw OOME // // 0'th constant pool entry is a pointer to the tags array // - clss->const_pool[0].tags = cp_tags; + m_entries[0].tags = cp_tags; cp_tags[0] = CONSTANT_Tags; - for (unsigned i=1; icp_size; i++) { + for(unsigned i = 1; i < m_size; i++) { // parse tag into tag array uint8 tag; if(!cfs.parse_u1(&tag)) { @@ -1886,9 +1887,9 @@ static bool class_parse_const_pool(Class return false; } - switch (cp_tags[i] = tag) { + switch(cp_tags[i] = tag) { case CONSTANT_Class: - if(!cfs.parse_u2_be(&clss->const_pool[i].CONSTANT_Class.name_index)) { + if(!cfs.parse_u2_be(&m_entries[i].CONSTANT_Class.name_index)) { REPORT_FAILED_CLASS_CLASS(clss->class_loader, clss, "java/lang/ClassFormatError", clss->name->bytes << ": could not parse name index " "for CONSTANT_Class entry"); @@ -1899,12 +1900,12 @@ static bool class_parse_const_pool(Class case CONSTANT_Methodref: case CONSTANT_Fieldref: case CONSTANT_InterfaceMethodref: - if(!cfs.parse_u2_be(&clss->const_pool[i].CONSTANT_ref.class_index)) { + if(!cfs.parse_u2_be(&m_entries[i].CONSTANT_ref.class_index)) { REPORT_FAILED_CLASS_CLASS(clss->class_loader, clss, "java/lang/ClassFormatError", clss->name->bytes << ": could not parse class index for CONSTANT_*ref entry"); return false; } - if(!cfs.parse_u2_be(&clss->const_pool[i].CONSTANT_ref.name_and_type_index)) { + if(!cfs.parse_u2_be(&m_entries[i].CONSTANT_ref.name_and_type_index)) { REPORT_FAILED_CLASS_CLASS(clss->class_loader, clss, "java/lang/ClassFormatError", clss->name->bytes << ": could not parse name-and-type index for CONSTANT_*ref entry"); return false; @@ -1912,7 +1913,7 @@ static bool class_parse_const_pool(Class break; case CONSTANT_String: - if(!cfs.parse_u2_be(&clss->const_pool[i].CONSTANT_String.string_index)) { + if(!cfs.parse_u2_be(&m_entries[i].CONSTANT_String.string_index)) { REPORT_FAILED_CLASS_CLASS(clss->class_loader, clss, "java/lang/ClassFormatError", clss->name->bytes << ": could not parse string index for CONSTANT_String entry"); return false; @@ -1921,7 +1922,7 @@ static bool class_parse_const_pool(Class case CONSTANT_Float: case CONSTANT_Integer: - if(!cfs.parse_u4_be(&clss->const_pool[i].int_value)) { + if(!cfs.parse_u4_be(&m_entries[i].int_value)) { REPORT_FAILED_CLASS_CLASS(clss->class_loader, clss, "java/lang/ClassFormatError", clss->name->bytes << ": could not parse value for " << (tag==CONSTANT_Integer?"CONSTANT_Integer":"CONSTANT_Float") << " entry"); @@ -1933,13 +1934,13 @@ static bool class_parse_const_pool(Class case CONSTANT_Long: // longs and doubles take up two entries // on both IA32 & IPF, first constant pool element is used, second element - unused - if(!cfs.parse_u4_be(&clss->const_pool[i].CONSTANT_8byte.high_bytes)) { + if(!cfs.parse_u4_be(&m_entries[i].CONSTANT_8byte.high_bytes)) { REPORT_FAILED_CLASS_CLASS(clss->class_loader, clss, "java/lang/ClassFormatError", clss->name->bytes << ": could not parse high four bytes for " << (tag==CONSTANT_Long?"CONSTANT_Integer":"CONSTANT_Float") << " entry"); return false; } - if(!cfs.parse_u4_be(&clss->const_pool[i].CONSTANT_8byte.low_bytes)) { + if(!cfs.parse_u4_be(&m_entries[i].CONSTANT_8byte.low_bytes)) { REPORT_FAILED_CLASS_CLASS(clss->class_loader, clss, "java/lang/ClassFormatError", clss->name->bytes << ": could not parse low four bytes for " << (tag==CONSTANT_Long?"CONSTANT_Long":"CONSTANT_Double") << " entry"); @@ -1951,13 +1952,13 @@ static bool class_parse_const_pool(Class break; case CONSTANT_NameAndType: - if(!cfs.parse_u2_be(&clss->const_pool[i].CONSTANT_NameAndType.name_index)) { + if(!cfs.parse_u2_be(&m_entries[i].CONSTANT_NameAndType.name_index)) { REPORT_FAILED_CLASS_CLASS(clss->class_loader, clss, "java/lang/ClassFormatError", clss->name->bytes << ": could not parse name index " "for CONSTANT_NameAndType entry"); return false; } - if(!cfs.parse_u2_be(&clss->const_pool[i].CONSTANT_NameAndType.descriptor_index)) { + if(!cfs.parse_u2_be(&m_entries[i].CONSTANT_NameAndType.descriptor_index)) { REPORT_FAILED_CLASS_CLASS(clss->class_loader, clss, "java/lang/ClassFormatError", clss->name->bytes << ": could not parse descriptor index " "for CONSTANT_NameAndType entry"); @@ -1968,13 +1969,13 @@ static bool class_parse_const_pool(Class case CONSTANT_Utf8: { // parse and insert string into string table - String* str = const_pool_parse_utf8(string_pool, cfs); + String* str = class_file_parse_utf8(string_pool, cfs); if(!str) { REPORT_FAILED_CLASS_CLASS(clss->class_loader, clss, "java/lang/ClassFormatError", clss->name->bytes << ": could not parse CONTANT_Utf8 entry"); return false; } - clss->const_pool[i].CONSTANT_Utf8.string = str; + m_entries[i].CONSTANT_Utf8.string = str; } break; default: @@ -1984,36 +1985,18 @@ static bool class_parse_const_pool(Class } } return true; -} //class_parse_const_pool +} // ConstantPool::parse -// -// check consistency of constant pool -// -// make sure all indices to other constant pool entries are in range -// make sure contents of constant pool entries are of the right type -// -// Set CONSTANT_Class entries to point directly to String representing -// internal form of fully qualified name of Class. -// -// Set CONSTANT_String entries to point directly to String representation -// of String. -// -// Peresolve CONSTANT_NameAndType entries to signature -// -static bool check_const_pool(Class* clss, - Const_Pool *cp, - unsigned cp_size) +bool ConstantPool::check(Class* clss) { - unsigned char *cp_tags = cp[0].tags; - for (unsigned i=1; i= cp_size || - cp_tag(cp,name_index) != CONSTANT_Utf8) { + unsigned name_index = get_class_name_index(i); + if (!is_valid_index(name_index) || !is_utf8(name_index)) { // illegal name index REPORT_FAILED_CLASS_CLASS(clss->class_loader, clss, "java/lang/ClassFormatError", clss->name->bytes << ": wrong name index for CONSTANT_Class entry"); @@ -2025,16 +2008,14 @@ static bool check_const_pool(Class* clss case CONSTANT_Fieldref: case CONSTANT_InterfaceMethodref: { - unsigned class_index = cp[i].CONSTANT_ref.class_index; - unsigned name_type_index = cp[i].CONSTANT_ref.name_and_type_index; - if (class_index >= cp_size || - cp_tag(cp,class_index) != CONSTANT_Class) { + unsigned class_index = get_ref_class_index(i); + unsigned name_type_index = get_ref_name_and_type_index(i); + if (!is_valid_index(class_index) || !is_class(class_index)) { REPORT_FAILED_CLASS_CLASS(clss->class_loader, clss, "java/lang/ClassFormatError", clss->name->bytes << ": wrong class index for CONSTANT_*ref entry"); return false; } - if (name_type_index >= cp_size || - cp_tag(cp,name_type_index) != CONSTANT_NameAndType) { + if (!is_valid_index(name_type_index) || !is_name_and_type(name_type_index)) { REPORT_FAILED_CLASS_CLASS(clss->class_loader, clss, "java/lang/ClassFormatError", clss->name->bytes << ": wrong name-and-type index for CONSTANT_*ref entry"); return false; @@ -2043,16 +2024,15 @@ static bool check_const_pool(Class* clss } case CONSTANT_String: { - unsigned string_index = cp[i].CONSTANT_String.string_index; - if (string_index >= cp_size || - cp_tag(cp,string_index) != CONSTANT_Utf8) { + unsigned string_index = get_string_index(i); + if (!is_valid_index(string_index) || !is_utf8(string_index)) { // illegal string index REPORT_FAILED_CLASS_CLASS(clss->class_loader, clss, "java/lang/ClassFormatError", clss->name->bytes << ": wrong string index for CONSTANT_String entry"); return false; } // set entry to the actual string - cp[i].CONSTANT_String.string = cp[string_index].CONSTANT_Utf8.string; + resolve_entry(i, get_utf8_string(string_index)); break; } case CONSTANT_Integer: @@ -2063,23 +2043,19 @@ static bool check_const_pool(Class* clss break; case CONSTANT_NameAndType: { - unsigned name_index = cp[i].CONSTANT_NameAndType.name_index; - unsigned descriptor_index = cp[i].CONSTANT_NameAndType.descriptor_index; - if (name_index >= cp_size || - cp_tag(cp,name_index) != CONSTANT_Utf8) { + unsigned name_index = get_name_and_type_name_index(i); + unsigned descriptor_index = get_name_and_type_descriptor_index(i); + if(!is_valid_index(name_index) || !is_utf8(name_index)) { REPORT_FAILED_CLASS_CLASS(clss->class_loader, clss, "java/lang/ClassFormatError", clss->name->bytes << ": wrong name index for CONSTANT_NameAndType entry"); return false; } - if (descriptor_index >= cp_size || - cp_tag(cp,descriptor_index) != CONSTANT_Utf8) { + if (!is_valid_index(descriptor_index) || !is_utf8(descriptor_index)) { REPORT_FAILED_CLASS_CLASS(clss->class_loader, clss, "java/lang/ClassFormatError", clss->name->bytes << ": wrong descriptor index for CONSTANT_NameAndType entry"); return false; } - cp[i].CONSTANT_NameAndType.name = cp[name_index].CONSTANT_Utf8.string; - cp[i].CONSTANT_NameAndType.descriptor = cp[descriptor_index].CONSTANT_Utf8.string; - cp_set_resolved(cp,i); + resolve_entry(i, get_utf8_string(name_index), get_utf8_string(descriptor_index)); break; } case CONSTANT_Utf8: @@ -2087,12 +2063,12 @@ static bool check_const_pool(Class* clss break; default: REPORT_FAILED_CLASS_CLASS(clss->class_loader, clss, "java/lang/ClassFormatError", - clss->name->bytes << ": wrong constant pool tag"); + clss->name->bytes << ": wrong constant pool tag " << get_tag(i)); return false; } } return true; -} //check_const_pool +} // ConstantPool::check static bool class_parse_interfaces(Class *clss, ByteReader &cfs) @@ -2116,7 +2092,7 @@ static bool class_parse_interfaces(Class // // verify that entry in constant pool is of type CONSTANT_Class // - clss->superinterfaces[i].name = cp_check_class(clss->const_pool,clss->cp_size,interface_index); + clss->superinterfaces[i].name = cp_check_class(clss->m_const_pool, interface_index); if (clss->superinterfaces[i].name == NULL) { REPORT_FAILED_CLASS_CLASS(clss->class_loader, clss, "java/lang/ClassFormatError", clss->name->bytes << ": constant pool index " << i << " is not CONSTANT_Class entry" @@ -2201,14 +2177,13 @@ bool class_parse(Global_Env* env, /* * allocate and parse constant pool */ - if (!class_parse_const_pool(clss, env->string_pool, cfs)) { + if(!clss->m_const_pool.parse(clss, env->string_pool, cfs)) return false; - } /* * check and preprocess the constant pool */ - if (!check_const_pool(clss, clss->const_pool, clss->cp_size)) + if(!clss->m_const_pool.check(clss)) return false; if(!cfs.parse_u2_be(&clss->access_flags)) { @@ -2235,7 +2210,7 @@ bool class_parse(Global_Env* env, return false; } - String *name = cp_check_class(clss->const_pool, clss->cp_size, this_class); + String *name = cp_check_class(clss->m_const_pool, this_class); if (name == NULL) { REPORT_FAILED_CLASS_CLASS(clss->class_loader, clss, "java/lang/ClassFormatError", clss->name->bytes << ": this_class constant pool entry " @@ -2261,7 +2236,7 @@ bool class_parse(Global_Env* env, /* * Mark the current class as resolved. */ - cp_resolve_to_class(clss->const_pool, this_class, clss); + clss->m_const_pool.resolve_entry(this_class, clss); /* * parse the super class name @@ -2287,7 +2262,7 @@ bool class_parse(Global_Env* env, } clss->super_name = NULL; } else { - clss->super_name = cp_check_class(clss->const_pool, clss->cp_size, super_class); + clss->super_name = cp_check_class(clss->m_const_pool, super_class); if (clss->super_name == NULL) { REPORT_FAILED_CLASS_CLASS(clss->class_loader, clss, "java/lang/ClassFormatError", clss->name->bytes << ": super_class constant pool entry " @@ -2331,7 +2306,7 @@ bool class_parse(Global_Env* env, uint32 attr_len = 0; for (unsigned i=0; iconst_pool, clss->cp_size, class_attr_strings, class_attrs, &attr_len); + Attributes cur_attr = parse_attribute(cfs, clss->m_const_pool, class_attr_strings, class_attrs, &attr_len); switch(cur_attr){ case ATTR_SourceFile: { @@ -2359,7 +2334,7 @@ bool class_parse(Global_Env* env, return false; } - clss->src_file_name = cp_check_utf8(clss->const_pool,clss->cp_size,filename_index); + clss->src_file_name = cp_check_utf8(clss->m_const_pool, filename_index); if (clss->src_file_name == NULL) { REPORT_FAILED_CLASS_CLASS(clss->class_loader, clss, "java/lang/ClassFormatError", clss->name->bytes << ": filename index points to incorrect constant pool entry" @@ -2410,7 +2385,8 @@ bool class_parse(Global_Env* env, return false; } if(inner_clss_info_idx - && cp_tag(clss->const_pool,inner_clss_info_idx) != CONSTANT_Class) + && (!clss->m_const_pool.is_valid_index(inner_clss_info_idx) + || !clss->m_const_pool.is_class(inner_clss_info_idx))) { REPORT_FAILED_CLASS_CLASS(clss->class_loader, clss, "java/lang/ClassFormatError", clss->name->bytes << ": inner class info index points to incorrect constant pool entry" @@ -2419,7 +2395,7 @@ bool class_parse(Global_Env* env, } if(!found_myself){ - String *clssname = cp_check_class(clss->const_pool, clss->cp_size, inner_clss_info_idx); + String* clssname = cp_check_class(clss->m_const_pool, inner_clss_info_idx); // Only handle this class if(clss->name == clssname) found_myself = 1; @@ -2435,11 +2411,12 @@ bool class_parse(Global_Env* env, return false; } if(outer_clss_info_idx - && cp_tag(clss->const_pool,outer_clss_info_idx) != CONSTANT_Class) + && (!clss->m_const_pool.is_valid_index(outer_clss_info_idx) + || !clss->m_const_pool.is_class(outer_clss_info_idx))) { REPORT_FAILED_CLASS_CLASS(clss->class_loader, clss, "java/lang/ClassFormatError", clss->name->bytes << ": outer class info index points to incorrect constant pool entry" - << " while parsing InnerClasses attribute"); + << outer_clss_info_idx << " while parsing InnerClasses attribute"); return false; } if(found_myself == 1 && outer_clss_info_idx){ @@ -2461,7 +2438,7 @@ bool class_parse(Global_Env* env, } if(found_myself == 1 /*&& outer_clss_info_idx*/){ if (inner_name_idx) { - clss->simple_name = clss->const_pool[inner_name_idx].CONSTANT_Utf8.string; + clss->simple_name = clss->m_const_pool.get_utf8_string(inner_name_idx); } else { //anonymous class clss->simple_name = env->string_pool.lookup(""); @@ -2496,7 +2473,7 @@ bool class_parse(Global_Env* env, // cfs is at debug_extension[] which is: // The debug_extension array holds a string, which must be in UTF-8 format. // There is no terminating zero byte. - clss->sourceDebugExtension = const_pool_parse_utf8data(env->string_pool, cfs, attr_len); + clss->sourceDebugExtension = class_file_parse_utf8data(env->string_pool, cfs, attr_len); if (!clss->sourceDebugExtension) { REPORT_FAILED_CLASS_FORMAT(clss, "invalid SourceDebugExtension attribute"); return false; @@ -2810,7 +2787,7 @@ const String* class_extract_name(Global_ if(!cfs.parse_u1(&tag) && tag != CONSTANT_Utf8) return NULL; // parse class name - const String* class_name = const_pool_parse_utf8(env->string_pool, cfs); + const String* class_name = class_file_parse_utf8(env->string_pool, cfs); return class_name; } @@ -2908,7 +2885,7 @@ unsigned class_calculate_size(const Clas unsigned size = 0; size += sizeof(Class); size += klass->n_innerclasses*sizeof(uint16); - size += klass->cp_size*sizeof(Const_Pool); + size += klass->m_const_pool.get_size()*sizeof(ConstPoolEntry); for(unsigned i = 0; i < klass->n_fields; i++) { size += klass->fields[i].calculate_size(); } diff --git a/enhanced/drlvm/trunk/vm/vmcore/src/class_support/Resolve.cpp b/enhanced/drlvm/trunk/vm/vmcore/src/class_support/Resolve.cpp index 77d5b6e..ad9b125 100644 --- a/enhanced/drlvm/trunk/vm/vmcore/src/class_support/Resolve.cpp +++ b/enhanced/drlvm/trunk/vm/vmcore/src/class_support/Resolve.cpp @@ -18,8 +18,6 @@ * @version $Revision: 1.1.2.6.4.5 $ */ - - // // exceptions that can be thrown during class resolution: // @@ -133,27 +131,25 @@ static Class* _resolve_class(Global_Env unsigned cp_index) { assert(hythread_is_suspend_enabled()); - Const_Pool *cp = clss->const_pool; + ConstantPool& cp = clss->m_const_pool; clss->m_lock->_lock(); - if(cp_in_error(cp, cp_index)) { + if(cp.is_entry_in_error(cp_index)) { TRACE2("resolve:testing", "Constant pool entry " << cp_index << " already contains error."); clss->m_lock->_unlock(); return NULL; } - if(cp_is_resolved(cp, cp_index)) { + if(cp.is_entry_resolved(cp_index)) { clss->m_lock->_unlock(); - return cp[cp_index].CONSTANT_Class.klass; + return cp.get_class_class(cp_index); } - String *classname = cp[cp[cp_index].CONSTANT_Class.name_index].CONSTANT_Utf8.string; + const String* classname = cp.get_utf8_string(cp.get_class_name_index(cp_index)); clss->m_lock->_unlock(); // load the class in - Class *other_clss; - - other_clss = clss->class_loader->LoadVerifyAndPrepareClass(env, classname); + Class* other_clss = clss->class_loader->LoadVerifyAndPrepareClass(env, classname); if(other_clss == NULL) { jthrowable exn = class_get_error(clss->class_loader, classname->bytes); @@ -178,7 +174,7 @@ static Class* _resolve_class(Global_Env || clss->is_not_verified) { clss->m_lock->_lock(); - cp_resolve_to_class(cp, cp_index, other_clss); + cp.resolve_entry(cp_index, other_clss); clss->m_lock->_unlock(); return other_clss; } @@ -189,7 +185,7 @@ static Class* _resolve_class(Global_Env && check_inner_class_access(env, other_clss, clss)) { clss->m_lock->_lock(); - cp_resolve_to_class(cp, cp_index, other_clss); + cp.resolve_entry(cp_index, other_clss); clss->m_lock->_unlock(); return other_clss; } @@ -391,44 +387,42 @@ check_inner_class_access(Global_Env *env */ static Field* _resolve_field(Global_Env *env, Class *clss, unsigned cp_index) { - Const_Pool *cp = clss->const_pool; + ConstantPool& cp = clss->m_const_pool; clss->m_lock->_lock(); - if(cp_in_error(cp, cp_index)) { + if(cp.is_entry_in_error(cp_index)) { TRACE2("resolve.testing", "Constant pool entry " << cp_index << " already contains error."); clss->m_lock->_unlock(); return NULL; } - if (cp_is_resolved(cp, cp_index)) { + if (cp.is_entry_resolved(cp_index)) { clss->m_lock->_unlock(); - return cp[cp_index].CONSTANT_ref.field; + return cp.get_ref_field(cp_index); } // // constant pool entry hasn't been resolved yet // - unsigned other_index = cp[cp_index].CONSTANT_ref.class_index; + unsigned other_index = cp.get_ref_class_index(cp_index); clss->m_lock->_unlock(); // // check error condition from resolve class // - Class *other_clss = _resolve_class(env, clss, other_index); + Class* other_clss = _resolve_class(env, clss, other_index); if(!other_clss) { - if(cp_in_error(clss->const_pool, other_index)) { - class_report_failure(clss, cp_index, - (jthrowable)(&(clss->const_pool[other_index].error.cause))); + if(cp.is_entry_in_error(other_index)) { + class_report_failure(clss, cp_index, + cp.get_error_cause(other_index)); } else { assert(exn_raised()); } return NULL; } - String* name = cp[cp[cp_index].CONSTANT_ref.name_and_type_index] - .CONSTANT_NameAndType.name; - String* desc = cp[cp[cp_index].CONSTANT_ref.name_and_type_index] - .CONSTANT_NameAndType.descriptor; - + uint16 name_and_type_index = cp.get_ref_name_and_type_index(cp_index); + String* name = cp.get_name_and_type_name(name_and_type_index); + String* desc = cp.get_name_and_type_descriptor(name_and_type_index); Field* field = class_lookup_field_recursive(other_clss, name, desc); if (field == NULL) { @@ -459,7 +453,7 @@ static Field* _resolve_field(Global_Env return NULL; } clss->m_lock->_lock(); - cp_resolve_to_field(cp, cp_index, field); + cp.resolve_entry(cp_index, field); clss->m_lock->_unlock(); return field; @@ -537,24 +531,24 @@ static Field* _resolve_nonstatic_field(G */ static Method* _resolve_method(Global_Env *env, Class *clss, unsigned cp_index) { - Const_Pool *cp = clss->const_pool; + ConstantPool& cp = clss->m_const_pool; clss->m_lock->_lock(); - if(cp_in_error(cp, cp_index)) { + if(cp.is_entry_in_error(cp_index)) { TRACE2("resolve:testing", "Constant pool entry " << cp_index << " already contains error."); clss->m_lock->_unlock(); return NULL; } - if (cp_is_resolved(cp,cp_index)) { + if (cp.is_entry_resolved(cp_index)) { clss->m_lock->_unlock(); - return cp[cp_index].CONSTANT_ref.method; + return cp.get_ref_method(cp_index); } // // constant pool entry hasn't been resolved yet // unsigned other_index; - other_index = cp[cp_index].CONSTANT_ref.class_index; + other_index = cp.get_ref_class_index(cp_index); clss->m_lock->_unlock(); // @@ -562,24 +556,22 @@ static Method* _resolve_method(Global_En // Class *other_clss = _resolve_class(env, clss, other_index); if(!other_clss) { - if(cp_in_error(clss->const_pool, other_index)) { + if(cp.is_entry_in_error(other_index)) { class_report_failure(clss, cp_index, - (jthrowable)(&(clss->const_pool[other_index].error.cause))); + cp.get_error_cause(other_index)); } else { assert(exn_raised()); } return NULL; } - String* name = cp[cp[cp_index].CONSTANT_ref.name_and_type_index]. - CONSTANT_NameAndType.name; - - String* desc = cp[cp[cp_index].CONSTANT_ref.name_and_type_index]. - CONSTANT_NameAndType.descriptor; + uint16 name_and_type_index = cp.get_ref_name_and_type_index(cp_index); + String* name = cp.get_name_and_type_name(name_and_type_index); + String* desc = cp.get_name_and_type_descriptor(name_and_type_index); // CONSTANT_Methodref must refer to a class, not an interface, and // CONSTANT_InterfaceMethodref must refer to an interface (vm spec 4.4.2) - if (cp_is_methodref(cp, cp_index) && class_is_interface(other_clss)) { + if(cp.is_methodref(cp_index) && class_is_interface(other_clss)) { CLASS_REPORT_FAILURE(clss, cp_index, "java/lang/IncompatibleClassChangeError", other_clss->name->bytes << " while resolving constant pool entry " << cp_index @@ -587,7 +579,7 @@ static Method* _resolve_method(Global_En return NULL; } - if(cp_is_interfacemethodref(cp, cp_index) && !class_is_interface(other_clss)) { + if(cp.is_interfacemethodref(cp_index) && !class_is_interface(other_clss)) { CLASS_REPORT_FAILURE(clss, cp_index, "java/lang/IncompatibleClassChangeError", other_clss->name->bytes << " while resolving constant pool entry " << cp_index @@ -627,7 +619,7 @@ static Method* _resolve_method(Global_En } clss->m_lock->_lock(); - cp_resolve_to_method(cp,cp_index,method); + cp.resolve_entry(cp_index, method); clss->m_lock->_unlock(); return method; @@ -770,9 +762,10 @@ static bool method_can_link_special(Clas { ASSERT_RAISE_AREA; - unsigned class_idx = clss->const_pool[index].CONSTANT_ref.class_index; - unsigned class_name_idx = clss->const_pool[class_idx].CONSTANT_Class.name_index; - String* ref_class_name = clss->const_pool[class_name_idx].CONSTANT_String.string; + ConstantPool& cp = clss->m_const_pool; + unsigned class_idx = cp.get_ref_class_index(index); + unsigned class_name_idx = cp.get_class_name_index(class_idx); + String* ref_class_name = cp.get_utf8_string(class_name_idx); if(method->get_name() == VM_Global_State::loader_env->Init_String && method->get_class()->name != ref_class_name) @@ -917,46 +910,46 @@ void class_throw_linking_error(Class_Han { ASSERT_RAISE_AREA; - Const_Pool* cp = ch->const_pool; - if(cp_in_error(cp, index)) { - exn_raise_object((jthrowable)(&(cp[index].error.cause))); + ConstantPool& cp = ch->m_const_pool; + if(cp.is_entry_in_error(index)) { + exn_raise_object(cp.get_error_cause(index)); return; // will return in interpreter mode } switch(opcode) { case OPCODE_NEW: - class_can_instantiate(cp[index].CONSTANT_Class.klass, LINK_THROW_ERRORS); + class_can_instantiate(cp.get_class_class(index), LINK_THROW_ERRORS); break; case OPCODE_PUTFIELD: - field_can_link(ch, cp[index].CONSTANT_ref.field, + field_can_link(ch, cp.get_ref_field(index), CAN_LINK_FROM_FIELD, LINK_WRITE_ACCESS, LINK_THROW_ERRORS); break; case OPCODE_GETFIELD: - field_can_link(ch, cp[index].CONSTANT_ref.field, + field_can_link(ch, cp.get_ref_field(index), CAN_LINK_FROM_FIELD, LINK_READ_ACCESS, LINK_THROW_ERRORS); break; case OPCODE_PUTSTATIC: - field_can_link(ch, cp[index].CONSTANT_ref.field, + field_can_link(ch, cp.get_ref_field(index), CAN_LINK_FROM_STATIC, LINK_WRITE_ACCESS, LINK_THROW_ERRORS); break; case OPCODE_GETSTATIC: - field_can_link(ch, cp[index].CONSTANT_ref.field, + field_can_link(ch, cp.get_ref_field(index), CAN_LINK_FROM_STATIC, LINK_READ_ACCESS, LINK_THROW_ERRORS); break; case OPCODE_INVOKEINTERFACE: - method_can_link_interface(ch, index, cp[index].CONSTANT_ref.method, + method_can_link_interface(ch, index, cp.get_ref_method(index), LINK_THROW_ERRORS); break; case OPCODE_INVOKESPECIAL: - method_can_link_special(ch, index, cp[index].CONSTANT_ref.method, + method_can_link_special(ch, index, cp.get_ref_method(index), LINK_THROW_ERRORS); break; case OPCODE_INVOKESTATIC: - method_can_link_static(ch, index, cp[index].CONSTANT_ref.method, + method_can_link_static(ch, index, cp.get_ref_method(index), LINK_THROW_ERRORS); break; case OPCODE_INVOKEVIRTUAL: - method_can_link_virtual(ch, index, cp[index].CONSTANT_ref.method, + method_can_link_virtual(ch, index, cp.get_ref_method(index), LINK_THROW_ERRORS); break; default: @@ -1022,16 +1015,14 @@ Class_Handle class_get_array_of_class(Cl } //class_get_array_of_class -static bool resolve_const_pool_item(Global_Env *env, Class *clss, unsigned cp_index) +static bool resolve_const_pool_item(Global_Env* env, Class* clss, unsigned cp_index) { - Const_Pool *cp = clss->const_pool; - unsigned char *cp_tags = cp[0].tags; + ConstantPool& cp = clss->m_const_pool; - if (cp_is_resolved(cp, cp_index)) { + if(cp.is_entry_resolved(cp_index)) return true; - } - switch (cp_tags[cp_index]) { + switch(cp.get_tag(cp_index)) { case CONSTANT_Class: return _resolve_class(env, clss, cp_index); case CONSTANT_Fieldref: @@ -1059,12 +1050,12 @@ static bool resolve_const_pool_item(Glob * Resolve whole constant pool */ unsigned resolve_const_pool(Global_Env& env, Class *clss) { - Const_Pool *cp = clss->const_pool; + ConstantPool& cp = clss->m_const_pool; // It's possible that cp is null when defining class on the fly - if (!cp) return true; - unsigned cp_size = clss->cp_size; + if(!cp.available()) return true; + unsigned cp_size = cp.get_size(); for (unsigned i = 1; i < cp_size; i++) { if(!resolve_const_pool_item(&env, clss, i)) { return i; diff --git a/enhanced/drlvm/trunk/vm/vmcore/src/class_support/class_impl.cpp b/enhanced/drlvm/trunk/vm/vmcore/src/class_support/class_impl.cpp index 57e66c5..5fcd180 100644 --- a/enhanced/drlvm/trunk/vm/vmcore/src/class_support/class_impl.cpp +++ b/enhanced/drlvm/trunk/vm/vmcore/src/class_support/class_impl.cpp @@ -202,9 +202,9 @@ class_get_method( class_handler klass, u unsigned short class_get_cp_size( class_handler klass ) { - assert( klass ); - Class *clss = (Class*)klass; - return clss->cp_size; + assert(klass); + Class* clss = (Class*)klass; + return clss->m_const_pool.get_size(); } // class_get_cp_size /** @@ -214,9 +214,9 @@ unsigned char class_get_cp_tag( class_handler klass, unsigned short index ) { assert( klass ); - Class *clss = (Class*)klass; - assert( index < clss->cp_size ); - return (unsigned char)cp_tag( clss->const_pool, index ); + Class* clss = (Class*)klass; + assert( index < clss->m_const_pool.get_size() ); + return clss->m_const_pool.get_tag(index); } // class_get_cp_tag /** @@ -226,10 +226,8 @@ unsigned short class_get_cp_class_name_index( class_handler klass, unsigned short index ) { assert( klass ); - Class *clss = (Class*)klass; - assert( index < clss->cp_size ); - assert( cp_is_class( clss->const_pool, index ) ); - return clss->const_pool[index].CONSTANT_Class.name_index; + Class* clss = (Class*)klass; + return clss->m_const_pool.get_class_name_index(index); } // class_get_cp_class_name_index /** @@ -240,11 +238,7 @@ class_get_cp_ref_class_index( class_hand { assert( klass ); Class *clss = (Class*)klass; - assert( index < clss->cp_size ); - assert( cp_is_fieldref( clss->const_pool, index ) - || cp_is_methodref( clss->const_pool, index ) - || cp_is_interfacemethodref( clss->const_pool, index ) ); - return clss->const_pool[index].CONSTANT_ref.class_index; + return clss->m_const_pool.get_ref_class_index(index); } // class_get_cp_ref_class_index /** @@ -255,24 +249,18 @@ class_get_cp_ref_name_and_type_index( cl { assert( klass ); Class *clss = (Class*)klass; - assert( index < clss->cp_size ); - assert( cp_is_fieldref( clss->const_pool, index ) - || cp_is_methodref( clss->const_pool, index ) - || cp_is_interfacemethodref( clss->const_pool, index ) ); - return clss->const_pool[index].CONSTANT_ref.name_and_type_index; + return clss->m_const_pool.get_ref_name_and_type_index(index); } // class_get_cp_ref_name_and_type_index /** * Function returns string entry index in constant pool. */ unsigned short -class_get_cp_string_index( class_handler klass, unsigned short index ) +class_get_cp_string_index(class_handler klass, unsigned short index) { - assert( klass ); - Class *clss = (Class*)klass; - assert( index < clss->cp_size ); - assert( cp_is_string( clss->const_pool, index ) ); - return clss->const_pool[index].CONSTANT_String.string_index; + assert(klass); + Class* clss = (Class*)klass; + return clss->m_const_pool.get_string_index(index); } // class_get_cp_string_index /** @@ -282,10 +270,8 @@ unsigned short class_get_cp_name_index( class_handler klass, unsigned short index ) { assert( klass ); - Class *clss = (Class*)klass; - assert( index < clss->cp_size ); - assert( cp_tag( clss->const_pool, index ) == CONSTANT_NameAndType ); - return clss->const_pool[index].CONSTANT_NameAndType.name_index; + Class* clss = (Class*)klass; + return clss->m_const_pool.get_name_and_type_name_index(index); } // class_get_cp_name_index /** @@ -295,23 +281,19 @@ unsigned short class_get_cp_descriptor_index( class_handler klass, unsigned short index ) { assert( klass ); - Class *clss = (Class*)klass; - assert( index < clss->cp_size ); - assert( cp_tag( clss->const_pool, index ) == CONSTANT_NameAndType ); - return clss->const_pool[index].CONSTANT_NameAndType.descriptor_index; + Class* clss = (Class*)klass; + return clss->m_const_pool.get_name_and_type_descriptor_index(index); } // class_get_cp_descriptor_index /** * Function returns bytes for UTF8 constant pool entry. */ -const char * +const char* class_get_cp_utf8_bytes( class_handler klass, unsigned short index ) { assert( klass ); - Class *clss = (Class*)klass; - assert( index < clss->cp_size ); - assert( cp_tag( clss->const_pool, index ) == CONSTANT_Utf8 ); - return clss->const_pool[index].CONSTANT_Utf8.string->bytes; + Class* clss = (Class*)klass; + return clss->m_const_pool.get_utf8_chars(index); } // class_get_cp_utf8_bytes /** diff --git a/enhanced/drlvm/trunk/vm/vmcore/src/class_support/classloader.cpp b/enhanced/drlvm/trunk/vm/vmcore/src/class_support/classloader.cpp index d41afa6..dd88201 100644 --- a/enhanced/drlvm/trunk/vm/vmcore/src/class_support/classloader.cpp +++ b/enhanced/drlvm/trunk/vm/vmcore/src/class_support/classloader.cpp @@ -478,8 +478,8 @@ bool ClassLoader::FinishLoadingClass(Glo // super class was successfully loaded clss->super_class = superClass; - if( super_class_cp_index && *super_class_cp_index ) { - cp_resolve_to_class( clss->const_pool, *super_class_cp_index, superClass ); + if(super_class_cp_index && *super_class_cp_index) { + clss->m_const_pool.resolve_entry(*super_class_cp_index, superClass); } // if it's an interface, its superclass must be java/lang/Object @@ -1149,6 +1149,9 @@ #endif clss->id = class_next_id++; clss->name = name; clss->class_loader = this; + + clss->m_const_pool.init(); + clss->state = ST_Start; clss->m_lock = new Lock_Manager(); @@ -1173,13 +1176,7 @@ void ClassLoader::ClassClearInternals(Cl delete []clss->methods; clss->methods = NULL; } - if (clss->const_pool != NULL) - { - if (clss->const_pool[0].tags) - delete []clss->const_pool[0].tags; - delete []clss->const_pool; - clss->const_pool = NULL; - } + clss->m_const_pool.clear(); if (clss->vtable_descriptors) delete []clss->vtable_descriptors; diff --git a/enhanced/drlvm/trunk/vm/vmcore/src/gc/root_set_enum_common.cpp b/enhanced/drlvm/trunk/vm/vmcore/src/gc/root_set_enum_common.cpp index b809b1e..9194e87 100644 --- a/enhanced/drlvm/trunk/vm/vmcore/src/gc/root_set_enum_common.cpp +++ b/enhanced/drlvm/trunk/vm/vmcore/src/gc/root_set_enum_common.cpp @@ -87,7 +87,7 @@ vm_enumerate_static_fields() (void**)&c->p_error ,FALSE); } vm_enumerate_root_reference((void**)ppc, FALSE); - Const_Pool* cp = c->m_failedResolution; + ConstPoolEntry* cp = c->m_const_pool.get_error_chain(); while(cp) { vm_enumerate_root_reference((void**)(&(cp->error.cause)), FALSE); cp = cp->error.next; diff --git a/enhanced/drlvm/trunk/vm/vmcore/src/init/vm.cpp b/enhanced/drlvm/trunk/vm/vmcore/src/init/vm.cpp index 62253b8..8f4b0b8 100644 --- a/enhanced/drlvm/trunk/vm/vmcore/src/init/vm.cpp +++ b/enhanced/drlvm/trunk/vm/vmcore/src/init/vm.cpp @@ -120,8 +120,9 @@ Class *class_resolve_class(Class *clss, // a constant of type Class, String, Integer, Float, Long or Double. Java_Type class_get_cp_const_type(Class *clss, unsigned cp_index) { - Const_Pool *cp = clss->const_pool; - switch(cp_tag(cp, cp_index)) { + ConstantPool& cp = clss->m_const_pool; + assert(cp.is_constant(cp_index)); + switch(cp.get_tag(cp_index)) { case CONSTANT_String: return JAVA_TYPE_STRING; case CONSTANT_Integer: @@ -135,7 +136,7 @@ Java_Type class_get_cp_const_type(Class case CONSTANT_Class: return JAVA_TYPE_CLASS; default: - DIE("non-constant type is requested from constant pool : " << cp_tag(cp, cp_index)); + DIE("non-constant type is requested from constant pool : " << cp.get_tag(cp_index)); } return JAVA_TYPE_INVALID; } //class_get_cp_const_type @@ -143,13 +144,10 @@ Java_Type class_get_cp_const_type(Class // Returns an address of an int, float, etc. -// For a string it returns a pointer to the utf8 representation of the string. -const void *class_get_addr_of_constant(Class *clss, unsigned cp_index) +const void* class_get_addr_of_constant(Class* clss, unsigned cp_index) { - Const_Pool *cp = clss->const_pool; - assert(cp_tag(cp, cp_index) != CONSTANT_String); - - return (void *)(cp + cp_index); + ConstantPool& cp = clss->m_const_pool; + return cp.get_address_of_constant(cp_index); } //class_get_addr_of_constant ///////////////////////////////////////////////////////////////// diff --git a/enhanced/drlvm/trunk/vm/vmcore/src/jit/jit_runtime_support.cpp b/enhanced/drlvm/trunk/vm/vmcore/src/jit/jit_runtime_support.cpp index ea07768..cab98bf 100644 --- a/enhanced/drlvm/trunk/vm/vmcore/src/jit/jit_runtime_support.cpp +++ b/enhanced/drlvm/trunk/vm/vmcore/src/jit/jit_runtime_support.cpp @@ -156,12 +156,12 @@ static NativeCodePtr rth_get_lil_multian static ManagedObject * rth_ldc_ref_helper(Class *c, unsigned cp_index) { ASSERT_THROW_AREA; - Const_Pool *cp = c->const_pool; - if (cp_is_string(cp, cp_index)) + ConstantPool& cp = c->m_const_pool; + if (cp.is_string(cp_index)) { return vm_instantiate_cp_string_slow(c, cp_index); } - else if (cp_is_class(cp, cp_index)) + else if (cp.is_class(cp_index)) { assert(!hythread_is_suspend_enabled()); hythread_suspend_enable(); diff --git a/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_break_intf.cpp b/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_break_intf.cpp index b401291..b5d7aa6 100644 --- a/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_break_intf.cpp +++ b/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_break_intf.cpp @@ -33,6 +33,8 @@ #include "exceptions.h" #include "m2n.h" #include "stack_iterator.h" #include "open/bytecodes.h" +#include "cci.h" + #include "jvmti_break_intf.h" diff --git a/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_step.cpp b/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_step.cpp index 595426a..b8bebc2 100644 --- a/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_step.cpp +++ b/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_step.cpp @@ -316,13 +316,13 @@ jvmti_SingleStepLocation( VM_thread* thr { unsigned short index = jvmti_GetHalfWordValue( bytecode, location + 1 ); Class *klass = method_get_class( method ); - assert( cp_is_resolved(klass->const_pool, index) ); + assert(klass->m_const_pool.is_entry_resolved(index)); - if( !method_is_native( klass->const_pool[index].CONSTANT_ref.method ) ) { + if(!method_is_native(klass->m_const_pool.get_ref_method(index))) { *count = 1; error = _allocate( sizeof(jvmti_StepLocation), (unsigned char**)next_step ); assert( error == JVMTI_ERROR_NONE ); - (*next_step)->method = klass->const_pool[index].CONSTANT_ref.method; + (*next_step)->method = klass->m_const_pool.get_ref_method(index); (*next_step)->location = 0; (*next_step)->native_location = NULL; (*next_step)->no_event = false; diff --git a/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_VMClassRegistry.cpp b/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_VMClassRegistry.cpp index 331255c..6143d79 100644 --- a/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_VMClassRegistry.cpp +++ b/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_VMClassRegistry.cpp @@ -603,15 +603,15 @@ (JNIEnv *jenv, jclass, jclass jclazz) { assert(jclazz); Class* clazz = jclass_to_struct_Class(jclazz); - unsigned m_idx = clazz->enclosing_method_index; - if (m_idx) { + unsigned method_idx = clazz->enclosing_method_index; + if (method_idx) { unsigned c_idx = clazz->enclosing_class_index; ASSERT(c_idx, "No class for enclosing method"); Class* outer_clss = class_resolve_class(clazz, c_idx); if (outer_clss) { - String* name = clazz->const_pool[m_idx].CONSTANT_NameAndType.name; - String* desc = clazz->const_pool[m_idx].CONSTANT_NameAndType.descriptor; + String* name = clazz->m_const_pool.get_name_and_type_name(method_idx); + String* desc = clazz->m_const_pool.get_name_and_type_descriptor(method_idx); TRACE("Looking for enclosing method: class="<name->bytes <<"; name="<bytes<<"; desc="<bytes); diff --git a/enhanced/drlvm/trunk/vm/vmcore/src/util/vm_strings.cpp b/enhanced/drlvm/trunk/vm/vmcore/src/util/vm_strings.cpp index b0dc667..81eae0a 100644 --- a/enhanced/drlvm/trunk/vm/vmcore/src/util/vm_strings.cpp +++ b/enhanced/drlvm/trunk/vm/vmcore/src/util/vm_strings.cpp @@ -588,20 +588,17 @@ jstring String_to_interned_jstring(Strin } -Java_java_lang_String * -vm_instantiate_cp_string_slow(Class *c, unsigned cp_index) +Java_java_lang_String* +vm_instantiate_cp_string_slow(Class* c, unsigned cp_index) { ASSERT_THROW_AREA; #ifdef VM_STATS VM_Statistics::get_vm_stats().num_instantiate_cp_string_slow++; #endif - Java_java_lang_String *result; - assert(cp_index < c->cp_size); - Const_Pool *cp = c->const_pool; - - String *str = cp[cp_index].CONSTANT_String.string; - assert(cp_is_constant(cp, cp_index)); + Java_java_lang_String* result; + ConstantPool& cp = c->m_const_pool; + String* str = cp.get_string(cp_index); BEGIN_RAISE_AREA; result = vm_instantiate_cp_string_resolved(str);