harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wjwashb...@apache.org
Subject svn commit: r472771 [8/11] - in /incubator/harmony/enhanced/drlvm/trunk/vm: gc_cc/src/ gcv4/src/ include/ include/open/ interpreter/src/ jitrino/src/jet/ jitrino/src/vm/drl/ port/src/lil/ia32/pim/ port/src/lil/pim/ vmcore/include/ vmcore/src/class_supp...
Date Thu, 09 Nov 2006 04:52:17 GMT
Modified: incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/Resolve.cpp
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/Resolve.cpp?view=diff&rev=472771&r1=472770&r2=472771
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/Resolve.cpp (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/Resolve.cpp Wed Nov  8 20:52:12 2006
@@ -19,8 +19,6 @@
  * @version $Revision: 1.1.2.6.4.5 $
  */  
 
-
-
 //
 // exceptions that can be thrown during class resolution:
 //
@@ -107,13 +105,27 @@
 #include "open/vm_util.h"
 
 
-#define CLASS_REPORT_FAILURE(target, cp_index, exnclass, exnmsg)    \
-{                                                               \
-    std::stringstream ss;                                       \
-    ss << exnmsg;                                               \
-    class_report_failure(target, cp_index, exnclass, ss);       \
+static void class_report_failure(Class* target, uint16 cp_index, jthrowable exn)
+{
+    ConstantPool& cp = target->get_constant_pool();
+    assert(cp.is_valid_index(cp_index));
+    assert(hythread_is_suspend_enabled());
+    if (exn_raised()) {
+        TRACE2("classloader.error", "runtime exception in classloading");
+        return;
+    }
+    assert(exn);
+
+    tmn_suspend_disable();
+    target->lock();
+    // vvv - This should be atomic change
+    cp.resolve_as_error(cp_index, exn);
+    // ^^^
+    target->unlock();
+    tmn_suspend_enable();
 }
 
+
 static void class_report_failure(Class* target, uint16 cp_index, 
                                  const char* exnname, std::stringstream& exnmsg)
 {
@@ -123,43 +135,43 @@
     class_report_failure(target, cp_index, exn);
 }
 
-// check is class "first" in the same runtime package with class "second"
-static bool is_class_in_same_runtime_package( Class *first, Class *second)
-{
-    return first->package == second->package;
+
+#define CLASS_REPORT_FAILURE(target, cp_index, exnclass, exnmsg)    \
+{                                                                   \
+    std::stringstream ss;                                           \
+    ss << exnmsg;                                                   \
+    class_report_failure(target, cp_index, exnclass, ss);           \
 }
 
-static Class* _resolve_class(Global_Env *env,
-                             Class *clss,
+
+Class* Class::_resolve_class(Global_Env* env,
                              unsigned cp_index)
 {
     assert(hythread_is_suspend_enabled());
-    Const_Pool *cp = clss->const_pool;
+    ConstantPool& cp = m_const_pool;
 
-    clss->m_lock->_lock();
-    if(cp_in_error(cp, cp_index)) {
-        TRACE2("resolve:testing", "Constant pool entry " << cp_index << " already contains error.");
-        clss->m_lock->_unlock();
+    lock();
+    if(cp.is_entry_in_error(cp_index)) {
+        TRACE2("resolve.testing", "Constant pool entry " << cp_index << " already contains error.");
+        unlock();
         return NULL;
     }
 
-    if(cp_is_resolved(cp, cp_index)) {
-        clss->m_lock->_unlock();
-        return cp[cp_index].CONSTANT_Class.klass;
+    if(cp.is_entry_resolved(cp_index)) {
+        unlock();
+        return cp.get_class_class(cp_index);
     }
 
-    String *classname = cp[cp[cp_index].CONSTANT_Class.name_index].CONSTANT_Utf8.string;
-    clss->m_lock->_unlock();
+    const String* classname = cp.get_utf8_string(cp.get_class_name_index(cp_index));
+    unlock();
 
     // load the class in
-    Class *other_clss;
-
-    other_clss = clss->class_loader->LoadVerifyAndPrepareClass(env, classname);
+    Class* other_clss = m_class_loader->LoadVerifyAndPrepareClass(env, classname);
     if(other_clss == NULL)
     {
-        jthrowable exn = class_get_error(clss->class_loader, classname->bytes);
+        jthrowable exn = class_get_error(m_class_loader, classname->bytes);
         if (exn) {
-            class_report_failure(clss, cp_index, exn);
+            class_report_failure(this, cp_index, exn);
         } else {
             assert(exn_raised());
         }
@@ -170,116 +182,117 @@
     //   referenced class should be public,
     //   or referenced class & declaring class are the same,
     //   or referenced class & declaring class are in the same runtime package,
-    //   or declaring class not verified
+    //   or declaring class not checked
     //   (the last case is needed for certain magic classes,
     //   eg, reflection implementation)
-    if(class_is_public(other_clss)
-        || other_clss == clss
-        || is_class_in_same_runtime_package( clss, other_clss )
-        || clss->is_not_verified) 
+    if(m_can_access_all
+        || other_clss->is_public()
+        || other_clss == this
+        || m_package == other_clss->m_package)
     {
-        clss->m_lock->_lock();
-        cp_resolve_to_class(cp, cp_index, other_clss);
-        clss->m_lock->_unlock();
+        lock();
+        cp.resolve_entry(cp_index, other_clss);
+        unlock();
         return other_clss;
     }
 
     // Check access control for inner classes:
     //   access control checks is the same as for members
-    if(strrchr((char*)other_clss->name->bytes, '$') != NULL
-        && check_inner_class_access(env, other_clss, clss))
+    if(strrchr(other_clss->get_name()->bytes, '$') != NULL
+        && can_access_inner_class(env, other_clss))
     {
-        clss->m_lock->_lock();
-        cp_resolve_to_class(cp, cp_index, other_clss);
-        clss->m_lock->_unlock();
+        lock();
+        cp.resolve_entry(cp_index, other_clss);
+        unlock();
         return other_clss;
     }
 
-    CLASS_REPORT_FAILURE(clss, cp_index, "java/lang/IllegalAccessError",
-        "from " << clss->name->bytes << " to " << other_clss->name->bytes);
+    CLASS_REPORT_FAILURE(this, cp_index, "java/lang/IllegalAccessError",
+        "from " << get_name()->bytes << " to " << other_clss->get_name()->bytes);
     // IllegalAccessError
     return NULL;
-} //_resolve_class
+} // Class::_resolve_class
 
 
 static bool class_can_instantiate(Class* clss, bool _throw)
 {
     ASSERT_RAISE_AREA;
-    bool fail = class_is_abstract(clss);
+    bool fail = clss->is_abstract();
     if(fail && _throw) {
-        exn_raise_by_name("java/lang/InstantiationError", clss->name->bytes);
+        exn_raise_by_name("java/lang/InstantiationError", clss->get_name()->bytes);
     }
     return !fail;
 }
 
 
-Class* _resolve_class_new(Global_Env *env, Class *clss,
+Class* _resolve_class_new(Global_Env* env, Class* clss,
                           unsigned cp_index)
 {
     ASSERT_RAISE_AREA;
 
-    Class *new_clss = _resolve_class(env,clss,cp_index);
+    Class* new_clss = clss->_resolve_class(env, cp_index);
     if (!new_clss) return NULL;
     bool can_instantiate = class_can_instantiate(new_clss, false);
 
-    if (new_clss && !can_instantiate) {
+    if(new_clss && !can_instantiate) {
         return NULL;
     }
     return new_clss;
-} //_resolve_class_new
+} // _resolve_class_new
 
 // Can "other_clss" access the field or method "member"?
-Boolean check_member_access(Class_Member *member, Class *other_clss)
+bool Class::can_access_member(Class_Member *member)
 {
-    Class *member_clss = member->get_class();
-    const char *reflect = "java/lang/reflect/";
-
-    // check if reflection class it has full access to all fields
-    if( !strncmp( other_clss->name->bytes, reflect, strlen(reflect) ) ) {
-        return 1;
-    }
+    Class* member_clss = member->get_class();
     // check access permissions
-    if (member->is_public() || (other_clss == member_clss)) {
+    if(member->is_public() || (this == member_clss)) {
         // no problemo
-        return 1;
-    } else if (member->is_private()) {
+        return true;
+    } else if(member->is_private()) {
         // IllegalAccessError
-        return 0;
-    } else if (member->is_protected()) {
-        // When a member is protected, it can be accessed by classes 
-        // in the same runtime package. 
-        if( is_class_in_same_runtime_package( other_clss, member_clss ) )
-            return 1;
-        // Otherwise, when other_clss is not in the same package, 
+        return false;
+    } else if(member->is_protected()) {
+        // When a member is protected, it can be accessed by classes
+        // in the same runtime package
+        if(m_package == member_clss->m_package)
+            return true;
+        // Otherwise, when this class is not in the same package,
         // the class containing the member (member_clss) must be
-        // a superclass of other_clss.
-        Class *c;
-        for (c = other_clss->super_class; c != NULL; c = c->super_class) {
-            if (c == member_clss)
+        // a superclass of this class
+        // ppervov: FIXME: this can be made a method of struct Class
+        // smth. like:
+        //if(!is_extending_class(member_clss)) {
+        //    // IllegalAccessError
+        //    return false;
+        //}
+        //return true;
+        Class* c;
+        for(c = get_super_class(); c != NULL; c = c->get_super_class()) {
+            if(c == member_clss)
                 break;
         }
-        if (c == NULL) {
+        if(c == NULL) {
             // IllegalAccessError
-            return 0;
+            return false;
         }
-        return 1;
+        return true;
     } else {
-        // When a member has default (or package private) access, it can only be accessed 
-        // by classes in the same package.
-        if( is_class_in_same_runtime_package( other_clss, member_clss ) )
-            return 1;
-        return 0;
+        // When a member has default (or package private) access,
+        // it can only be accessed by classes in the same package
+        if(m_package == member_clss->m_package)
+            return true;
+        return false;
     }
-} //check_member_access
+} // Class::can_access_member
 
 inline static bool
 is_class_extended_class( Class *super_clss, 
                          Class *check_clss)
 {
-    for(; super_clss != NULL; super_clss = super_clss->super_class)
+    for(; super_clss != NULL; super_clss = super_clss->get_super_class())
     {
-        if( super_clss->class_loader == check_clss->class_loader
-            && super_clss->name == check_clss->name )
+        if( super_clss->get_class_loader() == check_clss->get_class_loader()
+            && super_clss->get_name() == check_clss->get_name() )
         {
             return true;
         }
@@ -293,14 +306,14 @@
 {
     Class *encl_clss = NULL;
 
-    if( strrchr( (char*)klass->name->bytes, '$') != NULL ) 
+    if( strrchr( klass->get_name()->bytes, '$') != NULL )
     {   // it is anonymous class
         // search "this$..." in fields and look for enclosing class
         unsigned index;
         Field *field;
-        for( index = 0, field = &klass->fields[index];
-             index < klass->n_fields;
-             index++, field = &klass->fields[index] )
+        for( index = 0, field = klass->get_field(index);
+             index < klass->get_number_of_fields();
+             index++, field = klass->get_field(index) )
         {
             if( strncmp( field->get_name()->bytes, "this$", 5 ) 
                 || !(field->get_access_flags() & ACC_FINAL)
@@ -313,54 +326,49 @@
             // get name of enclosing class
             String* name = env->string_pool.lookup(&desc->bytes[1], desc->len - 2);
             // loading enclosing class
-            encl_clss = klass->class_loader->LoadVerifyAndPrepareClass(env, name);
+            encl_clss = klass->get_class_loader()->LoadVerifyAndPrepareClass(env, name);
             break;
         }
     }
     return encl_clss;
 } // get_enclosing_class
 
-// Can "other_clss" access the "inner_clss"
-Boolean
-check_inner_class_access(Global_Env *env,
-                         Class *inner_clss,
-                         Class *other_clss)
+bool Class::can_access_inner_class(Global_Env* env, Class* inner_clss)
 {
     // check access permissions
-    if ((inner_clss->access_flags & ACC_PUBLIC) || (other_clss == inner_clss)) {
+    if (inner_clss->is_public() || (this == inner_clss)) {
         // no problemo
-        return 1;
-    } else if (inner_clss->access_flags & ACC_PRIVATE) {
+        return true;
+    } else if (inner_clss->is_private()) {
         // IllegalAccessError
-        return 0;
-    } else if (inner_clss->access_flags & ACC_PROTECTED) {
+        return false;
+    } else if (inner_clss->is_protected()) {
         // When inner class is protected, it can be accessed by classes 
         // in the same runtime package. 
-        if( is_class_in_same_runtime_package( other_clss, inner_clss ) )
-            return 1;
+        if(m_package == inner_clss->m_package)
+            return true;
         // Otherwise, when other_clss is not in the same package, 
         // inner_clss must be a superclass of other_clss.
-        for( Class *decl_other_clss = other_clss; decl_other_clss != NULL; )
+        for(Class *decl_other_clss = this; decl_other_clss != NULL;)
         {
-            for( Class *decl_inner_clss = inner_clss; decl_inner_clss != NULL; )
+            for(Class *decl_inner_clss = inner_clss; decl_inner_clss != NULL;)
             {
                 if(is_class_extended_class( decl_other_clss, decl_inner_clss ) ) {
-                    return 1;
+                    return true;
                 }
-                if( !decl_inner_clss->declaringclass_index ) {
+                if( !decl_inner_clss->is_inner_class() ) {
                     // class "decl_inner_clss" isn't inner class
                     break;
                 } else {
                     // loading declaring class
-                    if(Class* decl_inner_clss_res = _resolve_class(env, decl_inner_clss,
-                            decl_inner_clss->declaringclass_index)) {
+                    if(Class* decl_inner_clss_res = decl_inner_clss->resolve_declaring_class(env)) {
                         decl_inner_clss = decl_inner_clss_res;
                     } else {
                         break;
                     }
                 }
             }
-            if( !decl_other_clss->declaringclass_index )
+            if( !decl_other_clss->is_inner_class() )
             {
                 // class "decl_other_clss" isn't inner class
                 decl_other_clss = get_enclosing_class(env, decl_other_clss);
@@ -368,103 +376,98 @@
             } else {
                 // loading declaring class
                 if(Class* decl_other_clss_res =
-                    _resolve_class(env, decl_other_clss, decl_other_clss->declaringclass_index))
+                    decl_other_clss->resolve_declaring_class(env))
                 {
-                    decl_other_clss = decl_other_clss_res ;
+                    decl_other_clss = decl_other_clss_res;
                     continue;
                 }
             }
             break;
         }
         // IllegalAccessError
-        return 0;
+        return false;
     } else {
         // When a member has default (or package private) access,
         // it can only be accessed by classes in the same runtime package.
-        if(is_class_in_same_runtime_package(other_clss, inner_clss))
-            return 1;
-        return 0;
+        if(m_package == inner_clss->m_package)
+            return true;
+        return false;
     }
-} // check_inner_class_access
+} // Class::can_access_inner_class
 
-/**
- *
- */
-static Field* _resolve_field(Global_Env *env, Class *clss, unsigned cp_index)
+
+Field* Class::_resolve_field(Global_Env *env, unsigned cp_index)
 {
-    Const_Pool *cp = clss->const_pool;
-    clss->m_lock->_lock();
-    if(cp_in_error(cp, cp_index)) {
+    lock();
+    if(m_const_pool.is_entry_in_error(cp_index)) {
         TRACE2("resolve.testing", "Constant pool entry " << cp_index << " already contains error.");
-        clss->m_lock->_unlock();
+        unlock();
         return NULL;
     }
 
-    if (cp_is_resolved(cp, cp_index)) {
-        clss->m_lock->_unlock();
-        return cp[cp_index].CONSTANT_ref.field;
+    if(m_const_pool.is_entry_resolved(cp_index)) {
+        unlock();
+        return m_const_pool.get_ref_field(cp_index);
     }
 
     //
     // constant pool entry hasn't been resolved yet
     //
-    unsigned other_index = cp[cp_index].CONSTANT_ref.class_index;
-    clss->m_lock->_unlock();
+    unsigned other_index = m_const_pool.get_ref_class_index(cp_index);
+    unlock();
 
     //
     // check error condition from resolve class
     //
-    Class *other_clss = _resolve_class(env, clss, other_index);
+    Class* other_clss = _resolve_class(env, 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(m_const_pool.is_entry_in_error(other_index)) {
+            class_report_failure(this, cp_index,
+                m_const_pool.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;
-
-    Field* field = class_lookup_field_recursive(other_clss, name, desc);
-    if (field == NULL)
+    uint16 name_and_type_index = m_const_pool.get_ref_name_and_type_index(cp_index);
+    String* name = m_const_pool.get_name_and_type_name(name_and_type_index);
+    String* desc = m_const_pool.get_name_and_type_descriptor(name_and_type_index);
+    Field* field = other_clss->lookup_field_recursive(name, desc);
+    if(field == NULL)
     {
         //
         // NoSuchFieldError
         //
-        CLASS_REPORT_FAILURE(clss, cp_index, "java/lang/NoSuchFieldError",
-            other_clss->name->bytes << "." << name->bytes
+        CLASS_REPORT_FAILURE(this, cp_index, "java/lang/NoSuchFieldError",
+            other_clss->get_name()->bytes << "." << name->bytes
             << " of type " << desc->bytes
             << " while resolving constant pool entry at index "
-            << cp_index << " in class " << clss->name->bytes);
+            << cp_index << " in class " << get_name()->bytes);
         return NULL;
     }
 
     //
     // check access permissions
     //
-    if (check_member_access(field, clss) == 0)
+    if(!can_access_member(field))
     {
         //
         // IllegalAccessError
         //
-        CLASS_REPORT_FAILURE(clss, cp_index, "java/lang/IllegalAccessError",
-            other_clss->name->bytes << "." << name->bytes
+        CLASS_REPORT_FAILURE(this, cp_index, "java/lang/IllegalAccessError",
+            other_clss->get_name()->bytes << "." << name->bytes
             << " of type " << desc->bytes
             << " while resolving constant pool entry at index "
-            << cp_index << " in class " << clss->name->bytes);
+            << cp_index << " in class " << get_name()->bytes);
         return NULL;
     }
-    clss->m_lock->_lock();
-    cp_resolve_to_field(cp, cp_index, field);
-    clss->m_lock->_unlock();
+    lock();
+    m_const_pool.resolve_entry(cp_index, field);
+    unlock();
 
     return field;
-} //_resolve_field
+} // Class::_resolve_field
 
 
 bool field_can_link(Class* clss, Field* field, bool _static, bool putfield, bool _throw)
@@ -473,21 +476,25 @@
     if(_static?(!field->is_static()):(field->is_static())) {
         if(_throw) {
             exn_raise_by_name("java/lang/IncompatibleClassChangeError",
-                field->get_class()->name->bytes);
+                field->get_class()->get_name()->bytes);
         }
         return false;
     }
     if(putfield && field->is_final()) {
-        for(int fn = 0; fn < clss->n_fields; fn++) {
-            if(&(clss->fields[fn]) == field) {
+        for(int fn = 0; fn < clss->get_number_of_fields(); fn++) {
+            if(clss->get_field(fn) == field) {
                 return true;
             }
         }
         if(_throw) {
-            unsigned buf_size = clss->name->len + field->get_class()->name->len + field->get_name()->len + 15;
+            unsigned buf_size = clss->get_name()->len +
+                field->get_class()->get_name()->len +
+                field->get_name()->len + 15;
             char* buf = (char*)STD_ALLOCA(buf_size);
             memset(buf, 0, buf_size);
-            sprintf(buf, " from %s to %s.%s", clss->name->bytes, field->get_class()->name->bytes, field->get_name()->bytes);
+            sprintf(buf, " from %s to %s.%s", clss->get_name()->bytes,
+                field->get_class()->get_name()->bytes,
+                field->get_name()->bytes);
             jthrowable exc_object = exn_create("java/lang/IllegalAccessError", buf);
             exn_raise_object(exc_object);
         }
@@ -510,126 +517,120 @@
 {
     ASSERT_RAISE_AREA;
 
-    Field *field = _resolve_field(env,clss,cp_index);
+    Field *field = clss->_resolve_field(env, cp_index);
     if(field && !field_can_link(clss, field, CAN_LINK_FROM_STATIC, putfield, LINK_NO_THROW)) {
         return NULL;
     }
     return field;
-} //_resolve_static_field
-
+} // _resolve_static_field
 
 
-static Field* _resolve_nonstatic_field(Global_Env *env,
-                                       Class *clss,
+static Field* _resolve_nonstatic_field(Global_Env* env,
+                                       Class* clss,
                                        unsigned cp_index,
                                        unsigned putfield)
 {
     ASSERT_RAISE_AREA;
 
-    Field *field = _resolve_field(env, clss, cp_index);
+    Field *field = clss->_resolve_field(env, cp_index);
     if(field && !field_can_link(clss, field, CAN_LINK_FROM_FIELD, putfield, LINK_NO_THROW)) {
         return NULL;
     }
     return field;
-} //_resolve_nonstatic_field
+} // _resolve_nonstatic_field
 
-/**
- *
- */ 
-static Method* _resolve_method(Global_Env *env, Class *clss, unsigned cp_index)
-{
-    Const_Pool *cp = clss->const_pool;
-    clss->m_lock->_lock();
-    if(cp_in_error(cp, cp_index)) {
-        TRACE2("resolve:testing", "Constant pool entry " << cp_index << " already contains error.");
-        clss->m_lock->_unlock();
+
+Method* Class::_resolve_method(Global_Env* env, unsigned cp_index)
+{
+    lock();
+    if(m_const_pool.is_entry_in_error(cp_index)) {
+        TRACE2("resolve.testing", "Constant pool entry " << cp_index << " already contains error.");
+        unlock();
         return NULL;
     }
 
-    if (cp_is_resolved(cp,cp_index)) {
-        clss->m_lock->_unlock();
-        return cp[cp_index].CONSTANT_ref.method;
+    if(m_const_pool.is_entry_resolved(cp_index)) {
+        unlock();
+        return m_const_pool.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;
-    clss->m_lock->_unlock();
+    other_index = m_const_pool.get_ref_class_index(cp_index);
+    unlock();
 
     //
     // check error condition from resolve class
     //
-    Class *other_clss = _resolve_class(env, clss, other_index);
+    Class* other_clss = _resolve_class(env, 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(m_const_pool.is_entry_in_error(other_index)) {
+            class_report_failure(this, cp_index, 
+                m_const_pool.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 = m_const_pool.get_ref_name_and_type_index(cp_index);
+    String* name = m_const_pool.get_name_and_type_name(name_and_type_index);
+    String* desc = m_const_pool.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)) {
-        CLASS_REPORT_FAILURE(clss, cp_index, "java/lang/IncompatibleClassChangeError",
-            other_clss->name->bytes
+    if(m_const_pool.is_methodref(cp_index) && other_clss->is_interface()) {
+        CLASS_REPORT_FAILURE(this, cp_index, "java/lang/IncompatibleClassChangeError",
+            other_clss->get_name()->bytes
             << " while resolving constant pool entry " << cp_index
-            << " in class " << clss->name->bytes);
+            << " in class " << m_name->bytes);
         return NULL;
     }
 
-    if(cp_is_interfacemethodref(cp, cp_index) && !class_is_interface(other_clss)) {
-        CLASS_REPORT_FAILURE(clss, cp_index, "java/lang/IncompatibleClassChangeError",
-            other_clss->name->bytes
+    if(m_const_pool.is_interfacemethodref(cp_index) && !other_clss->is_interface()) {
+        CLASS_REPORT_FAILURE(this, cp_index, "java/lang/IncompatibleClassChangeError",
+            other_clss->get_name()->bytes
             << " while resolving constant pool entry " << cp_index
-            << " in class " << clss->name->bytes);
+            << " in class " << m_name->bytes);
         return NULL;
     }
 
     Method* method = class_lookup_method_recursive(other_clss, name, desc);
-    if (method == NULL) {
+    if(method == NULL) {
         // NoSuchMethodError
-        CLASS_REPORT_FAILURE(clss, cp_index, "java/lang/NoSuchMethodError",
-            other_clss->name->bytes << "." << name->bytes << desc->bytes
+        CLASS_REPORT_FAILURE(this, cp_index, "java/lang/NoSuchMethodError",
+            other_clss->get_name()->bytes << "." << name->bytes << desc->bytes
             << " while resolving constant pool entry at index " << cp_index
-            << " in class " << clss->name->bytes);
+            << " in class " << m_name->bytes);
         return NULL;
     }
 
-    if(method_is_abstract(method) && !class_is_abstract(other_clss)) {
+    if(method->is_abstract() && !other_clss->is_abstract()) {
         // AbstractMethodError
-        CLASS_REPORT_FAILURE(clss, cp_index, "java/lang/AbstractMethodError",
-            other_clss->name->bytes << "." << name->bytes << desc->bytes
+        CLASS_REPORT_FAILURE(this, cp_index, "java/lang/AbstractMethodError",
+            other_clss->get_name()->bytes << "." << name->bytes << desc->bytes
             << " while resolving constant pool entry at index " << cp_index
-            << " in class " << clss->name->bytes);
+            << " in class " << m_name->bytes);
         return NULL;
     }
 
     //
     // check access permissions
     //
-    if (check_member_access(method,clss) == 0) {
+    if(!can_access_member(method)) {
         // IllegalAccessError
-        CLASS_REPORT_FAILURE(clss, cp_index, "java/lang/IllegalAccessError",
-            other_clss->name->bytes << "." << name->bytes << desc->bytes
+        CLASS_REPORT_FAILURE(this, cp_index, "java/lang/IllegalAccessError",
+            other_clss->get_name()->bytes << "." << name->bytes << desc->bytes
             << " while resolving constant pool entry at index " << cp_index
-            << " in class " << clss->name->bytes);
+            << " in class " << m_name->bytes);
         return NULL; 
     }
 
-    clss->m_lock->_lock();
-    cp_resolve_to_method(cp,cp_index,method);
-    clss->m_lock->_unlock();
+    lock();
+    m_const_pool.resolve_entry(cp_index, method);
+    unlock();
 
     return method;
 } //_resolve_method
@@ -641,7 +642,7 @@
     if (!method->is_static()) {
         if(_throw) {
             exn_raise_by_name("java/lang/IncompatibleClassChangeError",
-                method->get_class()->name->bytes);
+                method->get_class()->get_name()->bytes);
         }
         return false;
     }
@@ -654,7 +655,7 @@
 {
     ASSERT_RAISE_AREA;
 
-    Method* method = _resolve_method(env, clss, cp_index);
+    Method* method = clss->_resolve_method(env, cp_index);
     if(method && !method_can_link_static(clss, cp_index, method, LINK_NO_THROW))
         return NULL;
     return method;
@@ -668,15 +669,15 @@
     if(method->is_static()) {
         if(_throw) {
             exn_raise_by_name("java/lang/IncompatibleClassChangeError",
-                method->get_class()->name->bytes);
+                method->get_class()->get_name()->bytes);
         }
         return false;
     }
-    if(class_is_interface(method->get_class())) {
+    if(method->get_class()->is_interface()) {
         if(_throw) {
-            char* buf = (char*)STD_ALLOCA(clss->name->len
+            char* buf = (char*)STD_ALLOCA(clss->get_name()->len
                 + method->get_name()->len + method->get_descriptor()->len + 2);
-            sprintf(buf, "%s.%s%s", clss->name->bytes,
+            sprintf(buf, "%s.%s%s", clss->get_name()->bytes,
                 method->get_name()->bytes, method->get_descriptor()->bytes);
             jthrowable exc_object = exn_create("java/lang/AbstractMethodError", buf);
             exn_raise_object(exc_object);
@@ -691,7 +692,7 @@
                                        Class *clss,
                                        unsigned cp_index)
 {
-    Method* method = _resolve_method(env, clss, cp_index);
+    Method* method = clss->_resolve_method(env, cp_index);
     if(method && !method_can_link_virtual(clss, cp_index, method, LINK_NO_THROW))
         return NULL;
     return method;
@@ -707,7 +708,7 @@
                                          Class *clss,
                                          unsigned cp_index)
 {
-    Method* method = _resolve_method(env, clss, cp_index);
+    Method* method = clss->_resolve_method(env, cp_index);
     if(method && !method_can_link_interface(clss, cp_index, method, LINK_NO_THROW)) {
         return NULL;
     }
@@ -719,7 +720,7 @@
                            Class_Handle c,
                            unsigned index)
 {
-    return _resolve_field(compile_handle_to_environment(h), c, index);
+    return c->_resolve_field(compile_handle_to_environment(h), index);
 } // resolve_field
 
 
@@ -751,7 +752,7 @@
 
 Method_Handle resolve_method(Compile_Handle h, Class_Handle ch, unsigned idx)
 {
-    return _resolve_method(compile_handle_to_environment(h), ch, idx);
+    return ch->_resolve_method(compile_handle_to_environment(h), idx);
 }
 
 
@@ -771,12 +772,13 @@
 {
     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->get_constant_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)
+        && method->get_class()->get_name() != ref_class_name)
     {
         if(_throw) {
             exn_raise_by_name("java/lang/NoSuchMethodError",
@@ -788,7 +790,7 @@
     {
         if(_throw) {
             exn_raise_by_name("java/lang/IncompatibleClassChangeError",
-                method->get_class()->name->bytes);
+                method->get_class()->get_name()->bytes);
         }
         return false;
     }
@@ -796,10 +798,12 @@
     {
         if(_throw) {
             tmn_suspend_enable();
-            unsigned buf_size = clss->name->len + method->get_name()->len + method->get_descriptor()->len + 5;
+            unsigned buf_size = clss->get_name()->len +
+                method->get_name()->len + method->get_descriptor()->len + 5;
             char* buf = (char*)STD_ALLOCA(buf_size);
             memset(buf, 0, buf_size);
-            sprintf(buf, "%s.%s%s", clss->name->bytes, method->get_name()->bytes, method->get_descriptor()->bytes);
+            sprintf(buf, "%s.%s%s", clss->get_name()->bytes,
+                method->get_name()->bytes, method->get_descriptor()->bytes);
             jthrowable exc_object = exn_create("java/lang/AbstractMethodError", buf);
             exn_raise_object(exc_object);
             tmn_suspend_disable();
@@ -819,18 +823,18 @@
 {
     ASSERT_RAISE_AREA;
 
-    Method* method = _resolve_method(env, curr_clss, index);
+    Method* method = curr_clss->_resolve_method(env, index);
     if(!method) {
         return NULL;
     }
-    if(class_is_super(curr_clss)
-        && is_class_extended_class(curr_clss->super_class, method->get_class())
+    if(curr_clss->is_super()
+        && is_class_extended_class(curr_clss->get_super_class(), method->get_class())
         && method->get_name() != env->Init_String)
     {
         Method* result_meth;
-        for(Class* clss = curr_clss->super_class; clss; clss = clss->super_class)
+        for(Class* clss = curr_clss->get_super_class(); clss; clss = clss->get_super_class())
         {
-            result_meth = class_lookup_method(clss, method->get_name(), method->get_descriptor());
+            result_meth = clss->lookup_method(method->get_name(), method->get_descriptor());
             if(result_meth) {
                 method = result_meth;
                 break;
@@ -910,7 +914,7 @@
                            Class_Handle c,
                            unsigned index) 
 {
-    return _resolve_class(compile_handle_to_environment(h), c, index);
+    return c->_resolve_class(compile_handle_to_environment(h), index);
 } //resolve_class
 
 
@@ -918,46 +922,46 @@
 {
     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->get_constant_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:
@@ -975,7 +979,7 @@
 {
     // If the element type is primitive, return one of the preloaded
     // classes of arrays of primitive types.
-    if (cc->is_primitive) {
+    if (cc->is_primitive()) {
         if (cc == env->Boolean_Class) {
             return env->ArrayOfBoolean_Class;
         } else if (cc == env->Byte_Class) {
@@ -995,16 +999,16 @@
         }
     }
 
-    char *array_name = (char *)STD_MALLOC(cc->name->len + 5);
-    if(cc->name->bytes[0] == '[') {
-        sprintf(array_name, "[%s", cc->name->bytes);
+    char *array_name = (char *)STD_MALLOC(cc->get_name()->len + 5);
+    if(cc->get_name()->bytes[0] == '[') {
+        sprintf(array_name, "[%s", cc->get_name()->bytes);
     } else {
-        sprintf(array_name, "[L%s;", cc->name->bytes);
+        sprintf(array_name, "[L%s;", cc->get_name()->bytes);
     }
     String *arr_str = env->string_pool.lookup(array_name);
     STD_FREE(array_name);
 
-    Class* arr_clss = cc->class_loader->LoadVerifyAndPrepareClass(env, arr_str);
+    Class* arr_clss = cc->get_class_loader()->LoadVerifyAndPrepareClass(env, arr_str);
 
     return arr_clss;
 } //resolve_class_array_of_class1
@@ -1023,24 +1027,22 @@
 } //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->get_constant_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);
+            return clss->_resolve_class(env, cp_index);
         case CONSTANT_Fieldref:
-            return _resolve_field(env, clss, cp_index);
+            return clss->_resolve_field(env, cp_index);
         case CONSTANT_Methodref:
-            return _resolve_method(env, clss, cp_index);
+            return clss->_resolve_method(env, cp_index);
         case CONSTANT_InterfaceMethodref:
-            return _resolve_method(env, clss, cp_index);
+            return clss->_resolve_method(env, cp_index);
         case CONSTANT_NameAndType: // fall through
         case CONSTANT_Utf8:
             return true;
@@ -1060,12 +1062,12 @@
  * Resolve whole constant pool
  */
 int resolve_const_pool(Global_Env& env, Class *clss) {
-    Const_Pool *cp = clss->const_pool;
+    ConstantPool& cp = clss->get_constant_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 0;
 
+    unsigned cp_size = cp.get_size();
     for (unsigned i = 1; i < cp_size; i++) {
         if(!resolve_const_pool_item(&env, clss, i)) {
             return i;

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/String_Pool.cpp
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/String_Pool.cpp?view=diff&rev=472771&r1=472770&r2=472771
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/String_Pool.cpp (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/String_Pool.cpp Wed Nov  8 20:52:12 2006
@@ -35,6 +35,7 @@
 #include "environment.h"
 #include "open/hythread.h"
 #include "open/vm_util.h"
+#include "open/gc.h"
 #include "atomics.h"
 #include "vm_strings.h"
 #include "vm_stats.h"
@@ -290,7 +291,9 @@
     // Atomically update the string structure since some other thread might be trying to make the same update.
     // The GC won't be able to enumerate here since GC is disabled, so there are no race conditions with GC.
     if (VM_Global_State::loader_env->compress_references) {
-        COMPRESSED_REFERENCE compressed_lang_string = (COMPRESSED_REFERENCE)((POINTER_SIZE_INT)lang_string - (POINTER_SIZE_INT)Class::heap_base);
+        COMPRESSED_REFERENCE compressed_lang_string =
+            (COMPRESSED_REFERENCE)((POINTER_SIZE_INT)lang_string
+            - (POINTER_SIZE_INT)VM_Global_State::loader_env->heap_base);
         assert(is_compressed_reference(compressed_lang_string));     
         assert(sizeof(LONG) == sizeof(uint32));
         uint32 result = apr_atomic_cas32(

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/Verifier_stub.cpp
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/Verifier_stub.cpp?view=diff&rev=472771&r1=472770&r2=472771
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/Verifier_stub.cpp (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/Verifier_stub.cpp Wed Nov  8 20:52:12 2006
@@ -31,101 +31,106 @@
 #include "lock_manager.h"
 
 bool
-class_verify(const Global_Env* env, Class *clss)
+Class::verify(const Global_Env* env)
 {
     // fast path
-    if(clss->is_verified)
+    if(is_at_least_prepared() || in_error())
         return true;
 
-    LMAutoUnlock aulock(clss->m_lock);
-    if(clss->is_verified)
+    LMAutoUnlock aulock(m_lock);
+    if(is_at_least_prepared() || m_state == ST_Error)
         return true;
 
     /**
      * Get verifier enable status
      */
     Boolean is_forced = env->verify_all;
-    Boolean is_bootstrap = clss->class_loader->IsBootstrap();
+    Boolean is_bootstrap = m_class_loader->IsBootstrap();
     Boolean is_enabled = vm_get_boolean_property_value_with_default("vm.use_verifier");
 
     /**
      * Verify class
      */
     if(is_enabled == TRUE
-        && !class_is_interface(clss)
-       && (is_bootstrap == FALSE || is_forced == TRUE))
+        && !is_interface()
+        && (is_bootstrap == FALSE || is_forced == TRUE))
     {
         char *error;
-        Verifier_Result result = vf_verify_class((class_handler)clss, is_forced, &error );
+        Verifier_Result result = vf_verify_class((class_handler)this, is_forced, &error);
         if( result != VER_OK ) {
             aulock.ForceUnlock();
-            REPORT_FAILED_CLASS_CLASS(clss->class_loader, clss,
+            REPORT_FAILED_CLASS_CLASS(m_class_loader, this,
                 "java/lang/VerifyError", error);
             return false;
         }
-        clss->is_verified = 1;
-    } else {
-        clss->is_verified = 2;
     }
+    m_state = ST_BytecodesVerified;
 
     return true;
-} // class_verify
+} // Class::verify
 
 
 bool
-class_verify_constraints(const Global_Env* env, Class* clss)
+Class::verify_constraints(const Global_Env* env)
 {
-    if(clss->state == ST_Error)
-        return true;
-
-    assert(clss->is_verified >= 1);
-
     // fast path
-    if(clss->is_verified == 2)
+    switch(m_state)
+    {
+    case ST_ConstraintsVerified:
+    case ST_Initializing:
+    case ST_Initialized:
+    case ST_Error:
         return true;
+    }
 
     // lock class
-    clss->m_lock->_lock();
+    lock();
 
-    // check verification stage
-    if(clss->is_verified == 2) {
-        clss->m_lock->_unlock();
+    // check verification stage again
+    switch(m_state)
+    {
+    case ST_ConstraintsVerified:
+    case ST_Initializing:
+    case ST_Initialized:
+    case ST_Error:
+        unlock();
         return true;
     }
+    assert(m_state == ST_Prepared);
 
     // get verifier enable status
     Boolean verify_all = env->verify_all;
 
-    // unlock a class before calling of verifier
-    clss->m_lock->_unlock();
+    // unlock a class before calling to verifier
+    unlock();
 
     // check method constraints
     char *error;
     Verifier_Result result =
-        vf_verify_class_constraints( (class_handler)clss, verify_all, &error );
+        vf_verify_class_constraints((class_handler)this, verify_all, &error);
 
     // lock class and check result
-    clss->m_lock->_lock();
-    if( clss->state == ST_Error ) {
-        clss->m_lock->_unlock();
+    lock();
+    if(in_error()) {
+        unlock();
         return false;
     }
     if( result != VER_OK ) {
-        clss->m_lock->_unlock();
+        unlock();
         if( result == VER_ErrorLoadClass ) {
-            REPORT_FAILED_CLASS_CLASS(clss->class_loader, clss,
+            REPORT_FAILED_CLASS_CLASS(m_class_loader, this,
             VM_Global_State::loader_env->JavaLangNoClassDefFoundError_String->bytes,
             error);
         } else {
-            REPORT_FAILED_CLASS_CLASS(clss->class_loader, clss,
+            REPORT_FAILED_CLASS_CLASS(m_class_loader, this,
                 "java/lang/VerifyError", error);
         }
         return false;
     }
-    clss->is_verified = 2;
+    m_state = ST_ConstraintsVerified;
 
     // unlock class
-    clss->m_lock->_unlock();
+    unlock();
 
     return true;
 } // class_verify_method_constraints

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/class_impl.cpp
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/class_impl.cpp?view=diff&rev=472771&r1=472770&r2=472771
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/class_impl.cpp (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/class_impl.cpp Wed Nov  8 20:52:12 2006
@@ -35,7 +35,7 @@
 {
     assert( klass );
     Class *clss = (Class*)klass;
-    return clss->name->bytes;
+    return clss->get_name()->bytes;
 } // class_get_name_bytes
 
 /** 
@@ -46,7 +46,7 @@
 {
     assert( klass );
     Class *clss = (Class*)klass;
-    return (classloader_handler)clss->class_loader;
+    return (classloader_handler)clss->get_class_loader();
 } // class_get_classloader
 
 /** 
@@ -57,7 +57,7 @@
 {
     assert( klass );
     Class *clss = (Class*)klass;
-    return (class_handler)clss->super_class;
+    return (class_handler)clss->get_super_class();
 } // class_get_super_class
 
 /** 
@@ -75,13 +75,13 @@
  * Function checks if classes have the same package.
  */
 unsigned
-class_is_same_package( class_handler klass1, class_handler klass2 )
+class_is_same_package(class_handler klass1, class_handler klass2)
 {
     assert( klass1 );
     assert( klass2 );
-    Class *clss1 = (Class*)klass1;
-    Class *clss2 = (Class*)klass2;
-    return (clss1->package == clss2->package) ? 1 : 0;
+    Class* clss1 = (Class*)klass1;
+    Class* clss2 = (Class*)klass2;
+    return (clss1->get_package() == clss2->get_package()) ? 1 : 0;
 } // class_is_same_package
 
 /**
@@ -93,7 +93,7 @@
 {
     assert( klass );
     Class *clss = (Class*)klass;
-    return class_is_interface( clss ) ? 1 : 0;
+    return clss->is_interface() ? 1 : 0;
 } // class_is_interface_
 
 /**
@@ -104,7 +104,7 @@
 {
     assert( klass );
     Class *clss = (Class*)klass;
-    return clss->is_array;
+    return clss->is_array();
 } // class_is_array
 
 /**
@@ -116,18 +116,18 @@
 {
     assert( klass );
     Class *clss = (Class*)klass;
-    return class_is_final( clss ) ? 1 : 0;
+    return clss->is_final() ? 1 : 0;
 } // class_is_final_
 
 /**
  * Function receives number of super interfaces of class.
  */
 unsigned short
-class_get_superinterface_number( class_handler klass )
+class_get_superinterface_number(class_handler klass)
 {
     assert( klass );
     Class *clss = (Class*)klass;
-    return clss->n_superinterfaces;
+    return clss->get_number_of_superinterfaces();
 } // class_get_superinterface_number
 
 /**
@@ -138,8 +138,8 @@
 {
     assert( klass );
     Class *clss = (Class*)klass;
-    assert( index < clss->n_superinterfaces );
-    return (class_handler)clss->superinterfaces[index].clss;
+    assert(index < clss->get_number_of_superinterfaces());
+    return (class_handler)clss->get_superinterface(index);
 } // class_get_superinterface
 
 /**
@@ -153,8 +153,8 @@
 {
     assert( klass );
     Class *clss = (Class*)klass;
-    assert( clss->is_array );
-    return (class_handler)clss->array_element_class;
+    assert(clss->is_array());
+    return (class_handler)clss->get_array_element_class();
 } // class_get_array_element_class
 
 /**
@@ -165,8 +165,8 @@
 {
     assert( klass );
     assert( super_name );
-    for( Class *clss = (Class*)klass; clss; clss = clss->super_class ) {
-        if( !strcmp( clss->name->bytes, super_name ) ) {
+    for( Class *clss = (Class*)klass; clss; clss = clss->get_super_class() ) {
+        if( !strcmp( clss->get_name()->bytes, super_name ) ) {
             // found class with given name
             return 1;
         }
@@ -182,7 +182,7 @@
 {
     assert( klass );
     Class *clss = (Class*)klass;
-    return clss->n_methods;
+    return clss->get_number_of_methods();
 } // class_get_method_number
 
 /** 
@@ -193,8 +193,7 @@
 {
     assert( klass );
     Class *clss = (Class*)klass;
-    assert( index < clss->n_methods );
-    return (method_handler)&clss->methods[index];
+    return (method_handler)clss->get_method(index);
 } // class_get_method
 
 /** 
@@ -203,9 +202,9 @@
 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->get_constant_pool().get_size();
 } // class_get_cp_size
 
 /** 
@@ -215,9 +214,8 @@
 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;
+    return clss->get_constant_pool().get_tag(index);
 } // class_get_cp_tag
 
 /** 
@@ -227,10 +225,8 @@
 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->get_constant_pool().get_class_name_index(index);
 } // class_get_cp_class_name_index
 
 /** 
@@ -241,11 +237,7 @@
 {
     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->get_constant_pool().get_ref_class_index(index);
 } // class_get_cp_ref_class_index
 
 /** 
@@ -256,24 +248,18 @@
 {
     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->get_constant_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->get_constant_pool().get_string_index(index);
 } // class_get_cp_string_index
 
 /** 
@@ -283,10 +269,8 @@
 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->get_constant_pool().get_name_and_type_name_index(index);
 } // class_get_cp_name_index
 
 /** 
@@ -296,46 +280,39 @@
 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->get_constant_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->get_constant_pool().get_utf8_chars(index);
 } // class_get_cp_utf8_bytes
 
 /**
  * Function sets verify data to a given class.
  */
-void
-class_set_verify_data_ptr( class_handler klass, void *data )
+void class_set_verify_data_ptr(class_handler klass, void* data)
 {
-    assert( klass );
-    Class *clss = (Class*)klass;
-    clss->verify_data = data;
-    return;
+    assert(klass);
+    Class* clss = (Class*)klass;
+    clss->set_verification_data(data);
 } // class_set_verify_data_ptr
 
 /**
  * Function returns verify data for a given class.
  */
-void *
-class_get_verify_data_ptr( class_handler klass )
+void* class_get_verify_data_ptr(class_handler klass)
 {
-    assert( klass );
-    Class *clss = (Class*)klass;
-    return clss->verify_data;
+    assert(klass);
+    Class* clss = (Class*)klass;
+    return clss->get_verification_data();
 } // class_get_verify_data_ptr
 
 /**
@@ -344,10 +321,10 @@
 method_handler
 class_resolve_method( class_handler klass, unsigned short index )
 {
-    assert( klass );
-    assert( index );
-    Class *clss = (Class*)klass;
-    Method *method = class_resolve_method( clss, index );
+    assert(klass);
+    assert(index);
+    Class* clss = (Class*)klass;
+    Method* method = clss->_resolve_method(VM_Global_State::loader_env, index);
     return (method_handler)method;
 } // class_resolve_method
 

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/classloader.cpp
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/classloader.cpp?view=diff&rev=472771&r1=472770&r2=472771
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/classloader.cpp (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/classloader.cpp Wed Nov  8 20:52:12 2006
@@ -32,7 +32,6 @@
 #include "exceptions.h"
 #include "properties.h"
 #include "vm_strings.h"
-#include "Verifier_stub.h"
 #include "nogc.h"
 #include "bytereader.h"
 #include "Package.h"
@@ -52,32 +51,16 @@
 #include "jarfile_util.h"
 #include "jni_utils.h"
 
-//
-// private static variable containing the id of the next class
-// access to this needs to be thread safe; also, this will have to 
-// change if we want to reuse class ids
-//
-// an id of 0 is reserved to mean null; therefore, ids start from 1
-//
-// ppervov: FIXME: usage of this variable is not currently thread safe
-unsigned class_next_id = 1;
-
 unsigned ClassLoader::m_capacity = 0;
 unsigned ClassLoader::m_unloadedBytes = 0;
 unsigned ClassLoader::m_nextEntry = 0;
 ClassLoader** ClassLoader::m_table = NULL;
 Lock_Manager ClassLoader::m_tableLock;
 
-void mark_classloader(ClassLoader* cl)
-{
-    if(cl->GetLoader() && cl->NotMarked()) {
-        TRACE2("classloader.unloading.markloader", "  Marking loader "
-            << cl << " (" << (void*)cl->GetLoader() << " : "
-            << ((VTable*)(*(unsigned**)(cl->GetLoader())))->clss->name->bytes << ")");
-        cl->Mark();
-    }
-}
-
+// external declaration; definition is in Class_File_Loader.cpp
+const String* class_extract_name(Global_Env* env,
+                                 uint8* buffer,
+                                 unsigned offset, unsigned length);
 
 /*VMEXPORT*/ jthrowable class_get_error(ClassLoaderHandle clh, const char* name)
 {
@@ -87,21 +70,6 @@
 }
 
 
-void class_set_error_cause(Class *clss, jthrowable exn) {
-    tmn_suspend_disable();
-    clss->m_lock->_lock();
-    clss->state = ST_Error;
-    clss->p_error = exn->object;
-    clss->m_lock->_unlock();
-    tmn_suspend_enable();
-}
-
-jthrowable class_get_error_cause(Class *clss) {
-    assert(clss->p_error);
-    return (jthrowable) &clss->p_error;
-}
-
-
 bool ClassLoader::Initialize( ManagedObject* loader )
 {
     m_loader = loader;
@@ -230,11 +198,16 @@
         assert(env->JavaLangClass_Class == NULL);
     }
 
-    clss = (Class *) Alloc(sizeof(Class));
+    clss = (Class*)Alloc(sizeof(Class));
     // ppervov: FIXME: should check that class is successfully allocated
     assert(clss);
 
-    return InitClassFields(env, clss, name);
+    clss->init_internals(env, name, this);
+
+    if(clss->get_name())
+        clss = AllocateAndReportInstance(env, clss);
+
+    return clss;
 }
 
 ManagedObject** ClassLoader::RegisterClassInstance(const String* className, ManagedObject* instance) 
@@ -294,18 +267,16 @@
         FailedLoadingClass(className);
         return NULL;
     }
-    
+
     /*
      *  Create a Class File Stream object
      */
     ByteReader cfs(bytecode, offset, length);
-    unsigned super_class_cp_index;
-    assert(clss->state == ST_Start);
-    
+
     /* 
      * now parse and verify the class data
      */
-    if(!class_parse(env, clss, &super_class_cp_index, cfs)) {
+    if(!clss->parse(env, cfs)) {
         if (NULL != redef_buf)
             _deallocate(redef_buf);
         FailedLoadingClass(className);
@@ -329,22 +300,14 @@
     }
     // XXX
 
-    //clss->class_loader = this;
-    if(!FinishLoadingClass(env, clss, &super_class_cp_index)) {
+    if(!clss->load_ancestors(env)) {
         FailedLoadingClass(className);
         return NULL;
     }
 
-    clss->package = ProvidePackage(env, className, NULL);
-
     InsertClass(clss);
     SuccessLoadingClass(className);
 
-    //bool doNotNotifyBaseClasses = // false if class is either j/l/Object, j/io/Serializable, or j/l/Class
-    //    (clss->name != env->JavaLangObject_String)
-    //    && (env->java_io_Serializable_Class != NULL && clss->name != env->java_io_Serializable_Class->name)
-    //    && (clss->name != env->JavaLangClass_String);
-    //if( this != env->bootstrap_class_loader || doNotNotifyBaseClasses )
     if(this != env->bootstrap_class_loader || !env->InBootstrap())
     {
         jvmti_send_class_load_event(env, clss);
@@ -353,32 +316,34 @@
     return clss;
 }
 
- Package* ClassLoader::ProvidePackage(Global_Env* env, const String *class_name, 
-                                     const char *jar) {
-     const char* clss = class_name->bytes;
-     const char* sep = strrchr(clss, '/');
-     const String* package_name;
-     if (!sep) {
-         // this must be the default package...
-         package_name = env->string_pool.lookup("");
-     } else {
-         package_name = env->string_pool.lookup(clss, 
+
+Package* ClassLoader::ProvidePackage(Global_Env* env, const String* class_name,
+                                     const char* jar)
+{
+    const char* clss = class_name->bytes;
+    const char* sep = strrchr(clss, '/');
+    const String* package_name;
+    if (!sep) {
+        // this must be the default package...
+        package_name = env->string_pool.lookup("");
+    } else {
+        package_name = env->string_pool.lookup(clss,
             static_cast<unsigned>(sep - clss));
-     }
-     Lock();
-     Package *package = m_package_table->lookup(package_name);
-     if (package == NULL) {
-         // create a new package
-         void* p = apr_palloc(pool, sizeof(Package));
-         const char* jar_url = jar ? 
-             apr_pstrcat(pool, "jar:file:", jar, "!/", NULL) : NULL;
-         package = new (p) Package(package_name, jar_url);
-         m_package_table->Insert(package);
-     }
-     Unlock();
- 
-     return package;
- }
+    }
+    Lock();
+    Package *package = m_package_table->lookup(package_name);
+    if (package == NULL) {
+        // create a new package
+        void* p = apr_palloc(pool, sizeof(Package));
+        const char* jar_url = jar ?
+            apr_pstrcat(pool, "jar:file:", jar, "!/", NULL) : NULL;
+        package = new (p) Package(package_name, jar_url);
+        m_package_table->Insert(package);
+    }
+    Unlock();
+
+    return package;
+}
 
 Class* ClassLoader::LoadVerifyAndPrepareClass(Global_Env* env, const String* name)
 {
@@ -386,14 +351,8 @@
 
     Class* clss = LoadClass(env, name);
     if(!clss) return NULL;
-
-    if(!class_verify(env, clss)) {
-        return NULL;
-    }
-
-    if(!class_prepare(env, clss)) {
-        return NULL;
-    }
+    if(!clss->verify(env)) return NULL;
+    if(!clss->prepare(env)) return NULL;
 
     return clss;
 }
@@ -419,8 +378,8 @@
         assert(exn_raised());
         return; // OOME
     }
-    AddFailedClass(klass->name, exn);
-    class_set_error_cause(klass, exn);
+    AddFailedClass(klass->get_name(), exn);
+    klass->set_error_cause(exn);
 }
 
 void ClassLoader::ReportFailedClass(Class* klass, const char* exnclass, std::stringstream& exnmsg)
@@ -428,8 +387,8 @@
     jthrowable exn = exn_create(exnclass, exnmsg.str().c_str());
 
     // ppervov: FIXME: should throw OOME
-    AddFailedClass(klass->name, exn);
-    class_set_error_cause(klass, exn);
+    AddFailedClass(klass->get_name(), exn);
+    klass->set_error_cause(exn);
 }
 
 
@@ -443,105 +402,6 @@
     AddFailedClass(klassName, exn);
 }
 
-bool ClassLoader::FinishLoadingClass(Global_Env* env, Class* clss, unsigned* super_class_cp_index)
-{
-    clss->state = ST_LoadingAncestors;
-
-    String* superName = clss->super_name;
-
-    if( superName == NULL ) {
-        if(env->InBootstrap() || clss->name != env->JavaLangClass_String) {
-            // This class better be java.lang.Object
-            if( clss->name != env->JavaLangObject_String ) {
-                // ClassFormatError
-                std::stringstream ss;
-                ss << clss->name->bytes << ": class does not have superclass but the class is not java.lang.Object";
-                REPORT_FAILED_CLASS_CLASS(this, clss, "java/lang/ClassFormatError", ss.str().c_str());
-                return false;
-            }
-        }
-    } else {
-        // Load super class
-        Class* superClass;
-        clss->super_class = NULL;
-        superClass = LoadClass(env, superName);
-
-        if(superClass == NULL) {
-            if(!GetClassError(clss->name->bytes)) {
-                // Don't report failed classes more than one time
-                REPORT_FAILED_CLASS_CLASS_EXN(this, clss, GetClassError(superName->bytes));
-            }
-            return false;
-        }
-        if(class_is_interface(superClass)) {
-            REPORT_FAILED_CLASS_CLASS(this, clss, "java/lang/IncompatibleClassChangeError",
-                "class " << clss->name->bytes << " has interface "
-                << superClass->name->bytes << " as super class");
-            return false;
-        }
-        if(class_is_final(superClass)) {
-            REPORT_FAILED_CLASS_CLASS(this, clss, "java/lang/VerifyError",
-                clss->name->bytes << " cannot inherit from final class "
-                << superClass->name->bytes);
-            return false;
-        }
-        if(!class_verify(env, superClass)) return false;
-        if(!class_prepare(env, superClass)) return false;
-
-        // 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 it's an interface, its superclass must be java/lang/Object
-        if(class_is_interface(clss)) {
-            if((env->JavaLangObject_Class != NULL) && (superClass != env->JavaLangObject_Class)) {
-                std::stringstream ss;
-                ss << clss->name->bytes << ": interface superclass is not java.lang.Object";
-                REPORT_FAILED_CLASS_CLASS(this, clss, "java/lang/ClassFormatError", ss.str().c_str());
-                return false;
-            }
-        }
-
-        // 2003-06-18. Update the cha_first_child and cha_next_sibling fields.
-        clss->cha_first_child = NULL;
-        if (clss->super_class != NULL)
-        {
-            clss->cha_next_sibling = clss->super_class->cha_first_child;
-            clss->super_class->cha_first_child = clss;
-        }
-        // Notify interested JITs that the superclass has been extended.
-        do_jit_extended_class_callbacks( superClass, /*new_subclass*/ clss );
-    }
-
-    //
-    // load in super interfaces
-    //
-    for( unsigned i = 0; i < clss->n_superinterfaces; i++ ) {
-        String *intfc_name = clss->superinterfaces[i].name;
-        Class* intfc = LoadVerifyAndPrepareClass(env, intfc_name);
-        if( intfc == NULL ) {
-            if(!GetClassError(clss->name->bytes)) {
-                REPORT_FAILED_CLASS_CLASS_EXN(this, clss, GetClassError(intfc_name->bytes));
-            }
-            return false;
-        }
-        if(!class_is_interface(intfc)) {
-            REPORT_FAILED_CLASS_CLASS(this, clss, "java/lang/IncompatibleClassChangeError",
-                clss->name->bytes << ": " << intfc->name->bytes << " is not an interface");
-            return false;
-        }
-
-        // superinterface was successfully loaded
-        clss->superinterfaces[i].clss = intfc;
-    }
-    // class, superclass, and superinterfaces successfully loaded
-
-    clss->state = ST_Loaded;
-
-    return true;
-}
 
 void ClassLoader::RemoveLoadingClass(const String* className, LoadingClass* loading) 
 {
@@ -641,19 +501,19 @@
         if(m_table[i]->m_unloading) {
             TRACE2("classloader.unloading.debug", "  Skipping \"unloaded\" classloader "
                 << m_table[i] << " (" << m_table[i]->m_loader << " : "
-                << ((VTable*)(*(unsigned**)(m_table[i]->m_loader)))->clss->name->bytes << ")");
+                << ((VTable*)(*(unsigned**)(m_table[i]->m_loader)))->clss->get_name()->bytes << ")");
             continue;
         }
         TRACE2("classloader.unloading.debug", "  Clearing mark bits in classloader "
             << m_table[i] << " (" << m_table[i]->m_loader << " : "
-            << ((VTable*)(*(unsigned**)(m_table[i]->m_loader)))->clss->name->bytes << ") and its classes");
+            << ((VTable*)(*(unsigned**)(m_table[i]->m_loader)))->clss->get_name()->bytes << ") and its classes");
         // clear mark bits in loader and classes
         m_table[i]->m_markBit = 0;
         for(cti = m_table[i]->m_loadedClasses->begin();
             cti != m_table[i]->m_loadedClasses->end(); cti++)
         {
-            if(cti->second->class_loader == m_table[i]) {
-                cti->second->m_markBit = 0;
+            if(cti->second->get_class_loader() == m_table[i]) {
+                cti->second->reset_reachable();
              }
          }
      }
@@ -672,16 +532,16 @@
         if(m_table[i]->m_unloading) {
             TRACE2("classloader.unloading.debug", "  Skipping \"unloaded\" classloader "
                 << m_table[i] << " (" << m_table[i]->m_loader << " : "
-                << ((VTable*)(*(unsigned**)(m_table[i]->m_loader)))->clss->name->bytes << ")");
+                << ((VTable*)(*(unsigned**)(m_table[i]->m_loader)))->clss->get_name()->bytes << ")");
             continue;
         }
         TRACE2("classloader.unloading.debug", "  Scanning loader "
             << m_table[i] << " (" << m_table[i]->m_loader << " : "
-            << ((VTable*)(*(unsigned**)(m_table[i]->m_loader)))->clss->name->bytes << ")");
+            << ((VTable*)(*(unsigned**)(m_table[i]->m_loader)))->clss->get_name()->bytes << ")");
         if(!m_table[i]->m_markBit) {
             TRACE2("classloader.unloading.stats", "  (!) Ready to unload classloader "
                 << m_table[i] << " (" << m_table[i]->m_loader << " : "
-                << ((VTable*)(*(unsigned**)(m_table[i]->m_loader)))->clss->name->bytes << ")");
+                << ((VTable*)(*(unsigned**)(m_table[i]->m_loader)))->clss->get_name()->bytes << ")");
             TRACE2("classloader.unloading.stats", "  (!) This will free "
                 << m_table[i]->GetFullSize() << " bytes in C heap");
             m_table[i]->m_unloading = true;
@@ -701,7 +561,7 @@
         if(m_table[i]->m_unloading) {
             TRACE2("classloader.unloading.stats", "  Class loader "
                 << m_table[i] << " (" << m_table[i]->m_loader << " : "
-                << ((VTable*)(*(unsigned**)(m_table[i]->m_loader)))->clss->name->bytes
+                << ((VTable*)(*(unsigned**)(m_table[i]->m_loader)))->clss->get_name()->bytes
                 << ") contains " << m_table[i]->GetFullSize() << " bytes in C heap");
         }
     }
@@ -733,7 +593,7 @@
     ClassLoader* cl = new UserDefinedClassLoader();
     TRACE2("classloader.unloading.add", "Adding class loader "
         << cl << " (" << loader << " : "
-        << ((VTable*)(*(unsigned**)(loader)))->clss->name->bytes << ")");
+        << ((VTable*)(*(unsigned**)(loader)))->clss->get_name()->bytes << ")");
     cl->Initialize( loader );
     if( m_capacity <= m_nextEntry )
         ReallocateTable( m_capacity?(2*m_capacity):32 );
@@ -782,10 +642,10 @@
         {
             klass = *pklass;
             // class has already been loaded
-            if(klass->state == ST_LoadingAncestors) {
+            if(klass->get_state() == ST_LoadingAncestors) {
                 // there is a circularity in the class hierarchy
                 aulock.ForceUnlock();
-                REPORT_FAILED_CLASS_CLASS(this, klass, "java/lang/ClassCircularityError", klass->name->bytes);
+                REPORT_FAILED_CLASS_CLASS(this, klass, "java/lang/ClassCircularityError", klass->get_name()->bytes);
                 return NULL;
             }
             return klass;
@@ -860,8 +720,8 @@
     for(cti = m_loadedClasses->begin();
         cti != m_loadedClasses->end(); cti++)
     {
-        if(cti->second->class_loader == this) {
-            m_fullSize += class_calculate_size(cti->second);
+        if(cti->second->get_class_loader() == this) {
+            m_fullSize += cti->second->calculate_size();
         }
     }
     return m_fullSize;
@@ -925,7 +785,7 @@
             // We only have to report current error condition and do not need
             // to record error state in the class...
             std::stringstream ss;
-            ss << "class " << clss->name->bytes << " is defined second time";
+            ss << "class " << clss->get_name()->bytes << " is defined second time";
             jthrowable exn = exn_create("java/lang/LinkageError", ss.str().c_str());
             exn_raise_object(exn);
             return NULL;
@@ -1011,7 +871,7 @@
             className);
         return NULL;
     }
-    ClassLoader* baseLoader = baseClass->class_loader;
+    ClassLoader* baseLoader = baseClass->get_class_loader();
     Class* elementClass = baseClass;
     if(n_dimensions > 1) {
         elementClass = baseLoader->LoadVerifyAndPrepareClass(env, env->string_pool.lookup(&className[1]));
@@ -1053,49 +913,11 @@
         }
 
         // setup array-related fields
-        klass->is_array = 1;
-        klass->n_dimensions = (unsigned char)n_dimensions;
-        if(n_dimensions == 1) {
-            klass->is_array_of_primitives = isArrayOfPrimitives;
-        } else {
-            klass->is_array_of_primitives = false;
-        }
-        klass->array_element_class = elementClass;
-        klass->array_base_class = baseClass;
-        klass->is_verified = 2;
-
-        assert(elementClass);
-        klass->array_element_type_desc = type_desc_create_from_class(elementClass);
-
-        // insert Java field, required by spec - 'length'
-        klass->n_fields = 1;
-        klass->fields = new Field[1];
-        klass->fields[0].set(klass, env->Length_String,
-            env->string_pool.lookup("I"), ACC_PUBLIC|ACC_FINAL);
-        klass->fields[0].set_field_type_desc(
-            type_desc_create_from_java_descriptor("I", NULL));
-        klass->fields[0].set_injected();
-
-        klass->super_name = env->JavaLangObject_String;
-
-        // set array access flags the same as its base class
-        klass->access_flags = (ACC_FINAL | ACC_ABSTRACT);
-        if(isArrayOfPrimitives) {
-            klass->access_flags |= ACC_PUBLIC;
-        } else {
-            klass->access_flags = (uint16)(klass->access_flags | (baseClass->access_flags
-                & (ACC_PUBLIC | ACC_PRIVATE | ACC_PROTECTED) ));
-        }
-        klass->package = elementClass->package;
-
-        // array classes implement two interfaces: Cloneable and Serializable
-        klass->superinterfaces = (Class_Superinterface*) Alloc(2 * sizeof(Class_Superinterface));
-        klass->superinterfaces[0].name = env->Clonable_String;
-        klass->superinterfaces[1].name = env->Serializable_String;
-        klass->n_superinterfaces = 2;
+        klass->setup_as_array(env, n_dimensions, isArrayOfPrimitives,
+            baseClass, elementClass);
     }
 
-    if(!FinishLoadingClass(env, klass, NULL)) {
+    if(!klass->load_ancestors(env)) {
         FailedLoadingClass(classNameString);
         return NULL;
     }
@@ -1106,24 +928,39 @@
     return klass;
 } // ClassLoader::SetupAsArray
 
+
+static void set_struct_Class_field_in_java_lang_Class(const Global_Env* env, ManagedObject** jlc, Class *clss)
+{
+    assert(managed_object_is_java_lang_class(*jlc));
+    assert(env->vm_class_offset != 0);
+
+    Class** vm_class_ptr = (Class **)(((Byte *)(*jlc)) + env->vm_class_offset);
+    *vm_class_ptr = clss;
+} // set_struct_Class_field_in_java_lang_Class
+
+
 /** Adds Class* pointer to m_reportedClasses HashTable. 
-*   clss->name must not be NULL.
+*   clss->m_name must not be NULL.
 */
 Class* ClassLoader::AllocateAndReportInstance(const Global_Env* env, Class* clss)
 {
-    const String* name = clss->name;
+    const String* name = clss->get_name();
     assert(name);
 
     if (env->InBootstrap()) {
-        clss->class_handle = NULL;
+        // Make sure we are bootstrapping initial VM classes
+        assert((name == env->JavaLangObject_String)
+             || (strcmp(name->bytes, "java/io/Serializable") == 0)
+             || (name == env->JavaLangClass_String)
+             || (strcmp(name->bytes, "java/lang/reflect/AnnotatedElement") == 0)
+             || (strcmp(name->bytes, "java/lang/reflect/GenericDeclaration") == 0)
+             || (strcmp(name->bytes, "java/lang/reflect/Type") == 0));
     } else {
         Class* root_class = env->JavaLangClass_Class;
         assert(root_class != NULL);
 
         tmn_suspend_disable(); // -----------------vvv
-        ManagedObject* new_java_lang_Class =
-            (ManagedObject*) vm_alloc_and_report_ti(root_class->instance_data_size,
-                root_class->allocation_handle, vm_get_gc_thread_local(), root_class);
+        ManagedObject* new_java_lang_Class = root_class->allocate_instance();
         if(new_java_lang_Class == NULL)
         {
             tmn_suspend_enable();
@@ -1135,91 +972,24 @@
         }
         // add newly created java_lang_Class to reportable collection
         LMAutoUnlock aulock(&m_lock);
-        clss->class_handle = m_reportedClasses->Insert(name, new_java_lang_Class);
+        clss->set_class_handle(m_reportedClasses->Insert(name, new_java_lang_Class));
         aulock.ForceUnlock();
         TRACE("NewClass inserting class \"" << name->bytes
             << "\" with key " << name << " and object " << new_java_lang_Class);
-        assert(new_java_lang_Class == *(clss->class_handle));
-#ifdef VM_STATS
-        root_class->num_allocations++;
-        root_class->num_bytes_allocated += root_class->instance_data_size;
-#endif //VM_STATS
+        assert(new_java_lang_Class == *(clss->get_class_handle()));
 
         assert(env->vm_class_offset);
-        set_struct_Class_field_in_java_lang_Class(env, clss->class_handle, clss);
+        set_struct_Class_field_in_java_lang_Class(env, clss->get_class_handle(), clss);
         tmn_suspend_enable(); // -----------------^^^
     }
 
     return clss;
 }
 
-Class* ClassLoader::InitClassFields(const Global_Env* env, Class* clss, const String* name)
-{
-    memset(clss, 0, sizeof(Class));
-
-#ifdef POINTER64
-    clss->alignment = ((GC_OBJECT_ALIGNMENT<8)?8:GC_OBJECT_ALIGNMENT);;
-#else
-    clss->alignment = GC_OBJECT_ALIGNMENT;
-#endif
- 
-    clss->id = class_next_id++;
-    clss->name = name;
-    clss->class_loader = this;
-    clss->state = ST_Start;
-
-    clss->m_lock = new Lock_Manager();
-
-    // Special case: ClassLoader.defineClass() call with null classname value.
-    // Calling AddToReported() only if real class name is already known.
-    if (clss->name != NULL)
-        clss = AllocateAndReportInstance(env, clss);
-
-    return clss;
-}
 
 void ClassLoader::ClassClearInternals(Class* clss)
 {
-    FieldClearInternals(clss);
-
-    if (clss->methods != NULL)
-    {
-        for (int i = 0; i < clss->n_methods; i++){
-            clss->methods[i].MethodClearInternals();
-        }
-        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;
-    }
-    if (clss->vtable_descriptors)
-        delete []clss->vtable_descriptors;
-    
-    if (clss->static_method_block)
-        delete []clss->static_method_block;
-
-    if (clss->m_lock)
-        delete clss->m_lock;
-
-    if (clss->array_element_type_desc)
-    {
-        delete clss->array_element_type_desc;
-        clss->array_element_type_desc = NULL;
-    }
-}
-
-void ClassLoader::FieldClearInternals(Class* clss)
-{
-    if (clss->fields != NULL)
-    {
-        delete []clss->fields;   
-        clss->fields = NULL;
-    }
+    clss->clear_internals();
 }
 
 
@@ -1312,7 +1082,7 @@
     Class* klass = method->get_class();
 
     // get class name, method name and method descriptor
-    const String* class_name = klass->name;
+    const String* class_name = klass->get_name();
     const String* method_name = method->get_name();
     const String* method_desc = method->get_descriptor();
 
@@ -1835,10 +1605,10 @@
             Class *exn_class = jobject_to_struct_Class(exn);
 
             INFO("Loading of " << className->bytes << " class failed due to "
-                << exn_class->name->bytes);
+                << exn_class->get_name()->bytes);
 
             while(exn_class && exn_class != NotFoundExn_class) {
-                exn_class = exn_class->super_class;
+                exn_class = exn_class->get_super_class();
             }
 
             if (exn_class == NotFoundExn_class) {
@@ -1878,8 +1648,8 @@
     Class* clss = java_lang_Class_to_struct_Class(oh->object);
     tmn_suspend_enable();
 
-    assert(clss->class_loader != NULL);
-    if(clss->class_loader != this) {
+    assert(clss->get_class_loader() != NULL);
+    if(clss->get_class_loader() != this) {
         // if loading of this class was delegated to some other CL
         //      signal successful loading for our CL
         SuccessLoadingClass(className);
@@ -2006,7 +1776,7 @@
     // define class
     Class* clss = DefineClass(m_env, class_name->bytes, buf, 0, buf_len); 
     if(clss) {
-        clss->class_file_name = m_env->string_pool.lookup(full_name);
+        clss->set_class_file_name(m_env->string_pool.lookup(full_name));
     }
     apr_pool_destroy(local_pool);
 
@@ -2035,14 +1805,14 @@
         return NULL;
     }
 
-    // set class into package collection
+    // create package information with jar source
     ProvidePackage(m_env, class_name, jar_file->GetName());
 
     // define class
     Class *clss = DefineClass(m_env, class_name->bytes, buffer, 0, size, NULL);
     if(clss) {
         // set class file name
-        clss->class_file_name = m_env->string_pool.lookup(jar_file->GetName());
+        clss->set_class_file_name(m_env->string_pool.lookup(jar_file->GetName()));
     }
 
     return clss;

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/java_type.cpp
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/java_type.cpp?view=diff&rev=472771&r1=472770&r2=472771
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/java_type.cpp (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/java_type.cpp Wed Nov  8 20:52:12 2006
@@ -88,22 +88,23 @@
 
 TypeDesc* type_desc_create_from_java_class(Class* c)
 {
-    if(c->is_array)
-        return type_desc_create_from_java_descriptor(c->name->bytes, c->class_loader);
-    assert(!c->is_primitive);
+    const String* cname = c->get_name();
+    if(c->is_array())
+        return type_desc_create_from_java_descriptor(cname->bytes, c->get_class_loader());
+    assert(!c->is_primitive());
     
-    c->class_loader->LockTypesCache();
-    TypeDesc** tdres = c->class_loader->GetJavaTypes()->Lookup(c->name);
+    c->get_class_loader()->LockTypesCache();
+    TypeDesc** tdres = c->get_class_loader()->GetJavaTypes()->Lookup(cname);
     if (tdres)
     {
         assert (*tdres);
-        c->class_loader->UnlockTypesCache();
+        c->get_class_loader()->UnlockTypesCache();
         return *tdres;
     }
-    TypeDesc* td = new TypeDesc(K_Object, NULL, NULL, c->name, c->class_loader, NULL);
+    TypeDesc* td = new TypeDesc(K_Object, NULL, NULL, cname, c->get_class_loader(), NULL);
     assert(td);
-    c->class_loader->GetJavaTypes()->Insert(c->name, td);
-    c->class_loader->UnlockTypesCache();
+    c->get_class_loader()->GetJavaTypes()->Insert(cname, td);
+    c->get_class_loader()->UnlockTypesCache();
     return td;
 }
 

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/method.cpp
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/method.cpp?view=diff&rev=472771&r1=472770&r2=472771
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/method.cpp (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/method.cpp Wed Nov  8 20:52:12 2006
@@ -31,6 +31,7 @@
 #include "open/vm_util.h"
 #include "jit_intf_cpp.h"
 #include "atomics.h"
+#include "cci.h"
 
 #ifdef _IPF_
 #include "vm_ipf.h"
@@ -77,7 +78,7 @@
         n = env->string_pool.lookup(name, len);
     }
     Class* clss = ((Method *)m)->get_class();
-    Class* c = clss->class_loader->LoadClass(env, n);
+    Class* c = clss->get_class_loader()->LoadClass(env, n);
     return c;
 } //get_curr_arg_class
 
@@ -104,19 +105,6 @@
     return iter;
 } //advance_arg_iterator
 
-
-// Return the return type of this method.
-VMEXPORT // temporary solution for interpreter unplug
-Java_Type Method::get_return_java_type()
-{
-    const char *descr = get_descriptor()->bytes;
-    while(*descr != ')')
-        descr++;
-    return (Java_Type)*(descr + 1);
-} //Method::get_return_java_type
-
-
-
 Class_Handle method_get_return_type_class(Method_Handle m)
 {
     assert(hythread_is_suspend_enabled());
@@ -138,7 +126,7 @@
     }
 
     Class *clss = method->get_class();
-    Class *c = clss->class_loader->LoadVerifyAndPrepareClass(env, n);
+    Class *c = clss->get_class_loader()->LoadVerifyAndPrepareClass(env, n);
     return c;
 } //method_get_return_type_class
 
@@ -164,24 +152,6 @@
 } //Handler::Handler
 
 
-VMEXPORT // temporary solution for interpreter unplug
-unsigned Method::num_bc_exception_handlers()
-{
-    return _n_handlers;
-} //Method::num_bc_exception_handlers
-
-
-
-VMEXPORT // temporary solution for interpreter unplug
-Handler *
-Method::get_bc_exception_handler_info(unsigned eh_number)
-{
-    assert(eh_number < _n_handlers);
-    return _handlers + eh_number;
-} //Method::get_bc_exception_handler_info
-
-
-
 void Method::set_num_target_exception_handlers(JIT *jit, unsigned n)
 {
     CodeChunkInfo *jit_info = get_chunk_info_mt(jit, CodeChunkInfo::main_code_chunk_id);
@@ -231,20 +201,11 @@
 } //Method::get_target_exception_handler_info
 
 
-
-VMEXPORT // temporary solution for interpreter unplug
-Arg_List_Iterator Method::get_argument_list()
-{
-    return initialize_arg_list_iterator(get_descriptor()->bytes);
-} //Method::get_argument_list
-
-
-VMEXPORT // temporary solution for interpreter unplug
-unsigned Method::get_num_arg_bytes()
+void Method::calculate_arguments_size()
 {
-    // Use this old scheme until we can use the new JIT interface's methods to inspect the types of
-    // each method argument. This requires that these methods support Java, and that
-    // they work during VM's bootstrapping.
+    // Use this old scheme until we can use the new JIT interface's methods
+    // to inspect the types of each method argument. This requires that these
+    // methods support Java, and that they work during VM's bootstrapping.
     unsigned nb = 0;
     if (!is_static()) {
         nb = 4;
@@ -263,8 +224,8 @@
         }
         iter = advance_arg_iterator(iter);
     }
-    return nb;
-} //Method::get_num_arg_bytes
+    _arguments_size = nb;
+} // Method::get_num_arg_bytes
 
 
 
@@ -780,7 +741,7 @@
     Byte *bc = _byte_codes;
     Nop_Stack_State stack_state = NS_StackEmpty;
     if(verbose) {
-        printf("=========== nop[%d]: %s.%s%s\n", len, get_class()->name->bytes, get_name()->bytes, get_descriptor()->bytes);
+        printf("=========== nop[%d]: %s.%s%s\n", len, get_class()->get_name()->bytes, get_name()->bytes, get_descriptor()->bytes);
     }
     for (unsigned idx = 0; idx < len; idx++) {
         Byte b = bc[idx];
@@ -789,7 +750,7 @@
         }
         if(b == 0xb1) {   // return
             if(verbose) {
-                printf("+++++++ nop: %s.%s%s\n", get_class()->name->bytes, get_name()->bytes, get_descriptor()->bytes);
+                printf("+++++++ nop: %s.%s%s\n", get_class()->get_name()->bytes, get_name()->bytes, get_descriptor()->bytes);
             }
             _flags.is_nop = TRUE;
             return;
@@ -830,7 +791,7 @@
                         return;
                     }
                     if(verbose) {
-                        printf("invokespecial: %s.%s%s\n", callee->get_class()->name->bytes, callee->get_name()->bytes, callee->get_descriptor()->bytes);
+                        printf("invokespecial: %s.%s%s\n", callee->get_class()->get_name()->bytes, callee->get_name()->bytes, callee->get_descriptor()->bytes);
                     }
                     if(!callee->is_nop()) {
                         return;
@@ -840,7 +801,7 @@
                         return;
                     }
                     if(verbose) {
-                        printf("invokespecial nop: %s.%s%s\n", callee->get_class()->name->bytes, callee->get_name()->bytes, callee->get_descriptor()->bytes);
+                        printf("invokespecial nop: %s.%s%s\n", callee->get_class()->get_name()->bytes, callee->get_name()->bytes, callee->get_descriptor()->bytes);
                     }
                 }
                 stack_state = NS_StackEmpty;



Mime
View raw message