FileDocCategorySizeDatePackage
StackMapFrame.javaAPI DocphoneME MR2 API (J2ME)5904Wed May 02 17:59:48 BST 2007components

StackMapFrame

public class StackMapFrame extends Object

Fields Summary
public static final int
ITEM_Bogus
public static final int
ITEM_Integer
public static final int
ITEM_Float
public static final int
ITEM_Double
public static final int
ITEM_Long
public static final int
ITEM_Null
public static final int
ITEM_InitObject
public static final int
ITEM_Object
public static final int
ITEM_NewObject
int
offset
ConstantObject[]
locals
ConstantObject[]
stack
Constructors Summary
StackMapFrame(DataInput in, ConstantObject[] globals)


    // Read in a frame from the specified data input stream.
        
	                
	   this.offset = in.readShort();		    
	   this.locals = readOneTable(in, globals);
	   this.stack = readOneTable(in, globals);
    
Methods Summary
public voidcountConstantReferences(boolean isRelocatable)

 
	if (isRelocatable) { 
	    // Is this the right thing??
	    for (int i = 0; i < locals.length; i++) { 
		locals[i].incReference();
	    }
	    for (int i = 0; i < stack.length; i++) { 
		stack[i].incReference();
	    }
	}
    
public voidexternalize(ConstantPool p)

	// do nothing
    
private boolean[]getBitmap(ConstantObject[] table)

 
	int extra = 0;
	// Count the actual number of values, since doubles and longs take up 
	// two slots
	for (int i = 0; i < table.length; i++) { 
	    if (table[i] instanceof SingleValueConstant) { 
		int value = ((SingleValueConstant)table[i]).value;
		if (value == ITEM_Long || value == ITEM_Double) { 
		    extra++;
		}
	    }
	} 
	boolean result[] = new boolean[table.length + extra];
	extra = 0;
	// Fill in the table
	for (int i = 0; i < table.length; i++) { 
	    if (table[i] instanceof SingleValueConstant) { 
		int value = ((SingleValueConstant)table[i]).value;
		if (value == ITEM_Long || value == ITEM_Double) { 
		    extra++;
		} else if (value < 0 || value == ITEM_InitObject) { 
		    result[i + extra] = true;
		}
	    } else if (table[i] instanceof ClassConstant) { 
		result[i + extra] = true;
	    } else { 
		throw new RuntimeException("Unknown table type");
	    }
	}
	return result;
    
public boolean[]getLocalsBitmap()

	return getBitmap(locals);
    
public intgetOffset()

 
	return offset;
    
public boolean[]getStackBitmap()

 
	return getBitmap(stack);
    
public intgetStackSize()

 
        ConstantObject table[] = stack;
        int extra = 0;
	for (int i = 0; i < table.length; i++) { 
	    if (table[i] instanceof SingleValueConstant) { 
		int value = ((SingleValueConstant)table[i]).value;
		if (value == ITEM_Long || value == ITEM_Double) { 
		    extra++;
		}
	    }
	} 
	return table.length + extra;
    
private ConstantObject[]readOneTable(java.io.DataInput in, ConstantObject[] globals)

 
	int length = in.readShort();
	ConstantObject result[] = new ConstantObject[length];
	for (int i = 0; i < length; i++) { 
	    int tag = in.readByte();
	    switch(tag) { 
	    case ITEM_Bogus:
	    case ITEM_Integer: case ITEM_Float:
	    case ITEM_Double:  case ITEM_Long:
	    case ITEM_Null:    case ITEM_InitObject:
		// Small non-negative values represent the corresponding
		// type.
		result[i] = new SingleValueConstant(tag);
		break;

	    case ITEM_Object:
		result[i] = globals[in.readShort()];
		break;

	    case ITEM_NewObject:
		// It's not really worth creating a new
		// type to represent this.  Negative numbers represent new
		// objects.
		result[i] = new SingleValueConstant(~in.readShort());
		break;

	    default:
		System.out.println("Unknown tag");
	    }
	}
	return result;
    
public intwriteData(java.io.DataOutput out)

	out.writeShort(offset);
	// Return the number of bytes that we've written
	return 2 + writeData(out, locals) + writeData(out, stack);
    
public intwriteData(java.io.DataOutput out, ConstantObject[] table)

 
	int count = 0;
	out.writeShort(table.length);
	count += 2;
	for (int i = 0; i < table.length; i++) { 
	    if (table[i] instanceof SingleValueConstant) { 
		int value = ((SingleValueConstant)table[i]).value;
		if (value < 0) { 
		    out.writeByte(ITEM_NewObject);
		    out.writeShort(~value);
		    count += 3;
		} else { 
		    out.writeShort(value);	    
		    count += 2;
		}
	    } else if (table[i] instanceof ClassConstant) { 
		out.writeByte(ITEM_Object);
		out.writeShort(((ClassConstant)table[i]).name.index);
		count += 3;
	    }
	}
	return count;