FileDocCategorySizeDatePackage
ClassClass.javaAPI DocphoneME MR2 API (J2ME)11322Wed May 02 17:59:48 BST 2007vm

ClassClass

public class ClassClass extends Object

Fields Summary
public ClassInfo
ci
public InterfaceMethodTable
inf
public boolean
impureConstants
public int
nGCStatics
public boolean
hasStaticInitializer
protected static int
finalizerID
private static ClassClass[]
cvector
private static int
cindex
private static VMClassFactory
classFactory
Constructors Summary
Methods Summary
public voidadjustSymbolicConstants()
In the current definition of module (.mclass) files, many sorts of constants are put in the shared constant pool, and never in the per-class constant pool. This includes Unicode constants and NameAndType constants. This is fine as long as all symbols in the per-class constant pools get resolved, as they won't be missed. However, if we wish to process classes with symbol references that are not fully resolved, we will have to add such elements into the constant pool. We do this by sweeping over the per-class constants, looking for method, field, and class references that are not resolved, and adding the necessary entries.

	ConstantObject consts[] = ci.constants;
	if (!isPartiallyResolved(consts)) {
	    return;
	}
	//
	// we have work to do. This is unfortunate.
	// we use a LocalConstantPool to manage the pool we're re-building.
	// Because order matters, we collect the new entries to add at end.
	//
	//System.err.println(Localizer.getString("classclass.warning_class_has_an_impure_constant_pool", ci.className));
	ci.constants = makeResolvable(consts).getConstants(); 
	impureConstants = true;
    
public static voidappendClassElement(ClassInfo c)

	// foo. Have a cvector in place, must now 
	// add a new entry at the end. "c" is it.
	if ( cvector == null ) return; // ...never mind
	ClassClass[] oldCvector = cvector;
	cvector = new ClassClass[ cindex+1 ];
	System.arraycopy( oldCvector, 0, cvector,0, cindex );
	cvector[ cindex ] = classFactory.newVMClass( c );
    
public MethodConstantfindFinalizer()


       
	if ( ci == null ) return null;
	if ( ci.refMethodtable == null ) return null;
	int n = ci.refMethodtable.length;
	for ( int i = 0; i < n ; i++ ){
	    MethodConstant mc= ci.refMethodtable[i];
	    if ( mc.getID() == finalizerID ){
		if ( mc.find().parent.superClass == null ){
		    /*
		     * since we know that java.lang.Object's
		     * finalizer does nothing, we can ignore
		     * its existence!
		     */
		    return null;
		}
		return mc;
	    }
	}
	return null;
    
public static vm.ClassClass[]getClassVector(VMClassFactory ftry)

	if ( cvector != null ) return cvector; // just once, at most.
	classFactory = ftry;
	cvector = new ClassClass[ ClassInfo.nClasses() ];
	cindex  = 0;
	Enumeration classlist = ClassInfo.allClasses();
	while( classlist.hasMoreElements() ){
	    ClassInfo e =  (ClassInfo)classlist.nextElement();
	    if (e.vmClass == null) insertClassElement( e );
	}
	return cvector;
    
public booleanhasMethodtable()

	return ((!isInterface()) && (ci.refMethodtable != null));
    
private static voidinsertClassElement(ClassInfo e)

	if ( e.vmClass != null ) return; // already in place.
	ClassInfo sup = e.superClassInfo;
	// make sure our super precedes us.
	if ( (sup != null) && (sup.vmClass == null) ) insertClassElement( sup );
	ClassClass newVmClass = classFactory.newVMClass( e );
	cvector[ cindex++ ] = newVmClass;
	//
	// If the superclass of class C has a <clinit> method, C must
	// be marked as having a static initializer too.
	//
	if (!newVmClass.hasStaticInitializer &&
	    (sup != null) && sup.vmClass.hasStaticInitializer) {
	    newVmClass.hasStaticInitializer = true;
	}
    
public intinstanceSize()
Size of an instance in WORDS.

	FieldConstant rft[] = ci.refFieldtable;
	if ( rft == null || rft.length == 0 ) return 0;
	FieldInfo lastField = rft[rft.length-1].find();
	return (lastField.instanceOffset+lastField.nSlots);
    
public booleanisArrayClass()

	return (ci instanceof ArrayClassInfo);
    
public booleanisInterface()

	return (ci.access&Const.ACC_INTERFACE) != 0;
    
public static booleanisPartiallyResolved(ConstantObject[] consts)

        if ( consts == null ) return false; // no const!
        int nconst = consts.length;
        if ( nconst == 0 ) return false; // no const!

        // first see if we have anything that needs our attention.
        int nsymbolic = 0;
        for( int i = 1; i < nconst; i += consts[i].nSlots ){
            ConstantObject o = consts[i];
            if (!o.isResolved()) {
                return true;
	    }
        }
	return false;
    
public booleanisPrimitiveClass()

 
	return (ci instanceof PrimitiveClassInfo);
    
public static ConstantPoolmakeResolvable(ConstantPool cp)

	//
        // we use a LocalConstantPool to manage the pool we're re-building.
        // Because order matters, we collect the new entries to add at end.
        //
        System.err.println(Localizer.getString("classclass.warning_it_has_an_impure_shared_constant_pool"));
	return makeResolvable(cp.getConstants());
    
private static ConstantPoolmakeResolvable(ConstantObject[] consts)

 

        LocalConstantPool newPool    = new LocalConstantPool();
        Vector            newEntries = new Vector();
        int               nconst = consts.length;
        for( int i = 1; i < nconst; i += consts[i].nSlots ){
            ConstantObject o;
            o = consts[i];
            newPool.append(o);
            if ( ! o.isResolved() )
                newEntries.addElement( o );
        }
        Enumeration newlist = newEntries.elements();
        while( newlist.hasMoreElements() ){
            ConstantObject o = (ConstantObject)newlist.nextElement();
            switch( o.tag ){
            case Const.CONSTANT_CLASS:
                ClassConstant co = (ClassConstant)o;
                System.err.println(Localizer.getString("classclass.class", co.name.string));
                co.name = (UnicodeConstant)newPool.add( co.name );
                continue;
            case Const.CONSTANT_FIELD:
            case Const.CONSTANT_METHOD:
            case Const.CONSTANT_INTERFACEMETHOD:
                FMIrefConstant fo = (FMIrefConstant)o;
                if ( fo.clas.isResolved() && false ){
                    // This is a missing member of a resolved class.
                    // Print this out
                    // To print all the references to a totally missing
                    // class would be redundant and noisy.
                    if ( fo.tag == Const.CONSTANT_FIELD ){
                        System.err.print(Localizer.getString("classclass.field"));
                    } else {
                        System.err.print(Localizer.getString("classclass.method"));
                    }
                    System.err.println(Localizer.getString(
					"classclass.of_class", 
					fo.sig.name.string, 
					fo.sig.type.string, 
					fo.clas.name.string));
                }
                // as NameAndTypeConstant entries are always "resolved",
                // the strings they nominally point to need not be present:
                // they will get written out as a hash ID.
                fo.sig = (NameAndTypeConstant)newPool.add( fo.sig );
                fo.clas.name = (UnicodeConstant)newPool.add( fo.clas.name );
                fo.clas = (ClassConstant)newPool.add( fo.clas );
                continue;
            }
        }
	newPool.impureConstants = true;
	return newPool;
    
public intnfields()

	return (ci.fields==null)  ? 0 : ci.fields.length;
    
public intnmethods()

	return (ci.methods==null) ? 0 : ci.methods.length;
    
public static voidsetTypes()

	classFactory.setTypes();