Methods Summary |
---|
public ConstantObject | add(ConstantObject s)Return the ConstantObject in constant table corresponding to
the given ConstantObject s.
Inserts s if it is not already there.
The index member of the returned value (which
may be the object s!) will be set to its index in our
table. There will be no element of index 0.
if ( s.shared && s.containingPool==this ) return s; // this is already it!
ConstantObject r = (ConstantObject)h.get( s );
if ( r == null ){
if ( locked ){
throw new Error("add on locked ConstantPool");
}
if ( s.shared ){
// already in another constant pool!
// this copy is not deep enough!!!
r = (ConstantObject) s.clone();
} else {
r = s;
}
r.externalize( this ); // Deeper copy, as required.
r.index = n;
n += r.nSlots;
r.shared = true;
r.containingPool = this;
h.put( r, r );
t.addElement( r );
for ( int i =r.nSlots; i > 1; i-- )
t.addElement( null ); // place holder.
constants = null; // mark any "constants" as obsolete!
}
return r;
|
public ConstantObject | appendElement(ConstantObject s)
ConstantObject r = (ConstantObject)h.get( s );
if ( r == null ){
if ( locked ){
throw new Error("add on locked ConstantPool");
}
r = s;
r.index = n;
n += r.nSlots;
h.put( r, r );
t.addElement( r );
for ( int i =r.nSlots; i > 1; i-- )
t.addElement( null ); // place holder.
constants = null; // mark any "constants" as obsolete!
} else {
r.ldcReferences += s.ldcReferences;
r.references += s.references;
}
return r;
|
public void | clearAllReferences()
ConstantObject c;
for( int i=1; i< n; i+=c.nSlots){
c = (ConstantObject)t.elementAt(i);
c.clearReference();
}
|
public int | doCompare(java.lang.Object o1, java.lang.Object o2)doCompare
ConstantObject obj1 = (ConstantObject) o1;
ConstantObject obj2 = (ConstantObject) o2;
if (obj1.ldcReferences < obj2.ldcReferences) {
return 1;
} else if (obj1.ldcReferences == obj2.ldcReferences)
return 0;
return -1;
|
public void | doSort()
int count = 0;
int nNew = 1;
// Retrieve the ConstantObject array from the hashtable.
Enumeration e = h.elements();
ConstantObject arr[] = new ConstantObject[h.size()];
while (e.hasMoreElements()) {
arr[count]= (ConstantObject) e.nextElement();
count++;
}
// Sorting the ConstantObject with descending reference
// count.
sun.misc.Sort.quicksort(arr, this);
t.removeAllElements();
t.addElement(null);
for (int i = 0; i < arr.length; i++) {
arr[i].index = nNew;
nNew += arr[i].nSlots;
t.addElement(arr[i]);
for (int j =arr[i].nSlots; j > 1; j-- )
t.addElement( null ); // place holder
}
constants = null;
|
public void | dump(java.io.PrintStream o)
ConstantObject c;
for( int i=1; i< n; i+=c.nSlots){
c = (ConstantObject)t.elementAt(i);
o.println("\t["+c.index+"]\t"+c.references+"\t"+c.toString() );
}
|
public ConstantObject | dup(ConstantObject s)
if ( s.shared && s.containingPool==this ) return s;
return this.add( (ConstantObject) s.clone() );
|
public ConstantObject[] | getConstants()
if ( constants != null )
return constants;
constants = new ConstantObject[ t.size() ];
t.copyInto( constants );
return constants;
|
public java.util.Enumeration | getEnumeration()
return t.elements();
|
public void | lock() locked = true;
|
public int | read(java.io.DataInput in)
int n = in.readUnsignedShort();
ConstantObject c[] = new ConstantObject[n];
for (int i = 1; i < n; i+=c[i].nSlots ){
c[i] = ConstantObject.readObject(in);
}
//System.err.println("DEBUG CONSTANTPOOL DUMP" );
//for (int i = 1; i < n; i+=c[i].nSlots ){
// System.err.println("\t#"+i+"\t"+c[i].toString() );
//}
for (int i = 1; i < n; i+=c[i].nSlots ){
c[i].resolve( c );
}
for (int i = 1; i < n; i+=c[i].nSlots ){
add( c[i] );
}
constants = c; // a hack, but a valid one.
return n;
|
public void | smashConstantPool()
int nNew = 1;
ConstantObject o;
// first, count and index.
for ( int i = 1; i < n; i += o.nSlots ){
o = (ConstantObject)t.elementAt(i);
if ( o.references == 0 ){
o.index = -1;
h.remove( o );
} else {
// we're keeping it.
o.index = nNew;
nNew += o.nSlots;
}
}
if ( nNew == n ) return; // all done!
// copy live ones from old vector to new.
Vector newConstants = new Vector( nNew );
newConstants.addElement( null );
for ( int i = 1; i < n; i += o.nSlots ){
o = (ConstantObject)t.elementAt(i);
if ( o.references != 0 ){
// we're keeping it.
newConstants.addElement(o);
for ( int j =o.nSlots; j > 1; j-- )
newConstants.addElement( null ); // place holder.
}
}
t = newConstants;
n = nNew;
constants = null; // mark as obsolete
|
public void | unlock() locked = false;
|
public int | write(java.io.DataOutput o)Write out the number of constants to write.
Then write out the constants, in order.
Returns total number of constants written.
o.writeShort(n);
ConstantObject ob;
for (int i = 1; i < n; i+=ob.nSlots ){
ob = (ConstantObject)t.elementAt(i);
if ( ob != null )
ob.write(o);
}
return n;
|