[Soot-list] Singleton ArrayLists
Ohad Shacham
ohad.shacham at cs.tau.ac.il
Wed Mar 4 09:01:09 EST 2009
Hi,
We recently built a tool called Chameleon (
http://www.research.ibm.com/qvm/chameleon.html) for automatically managing
collections in Java. Running Chameleon on Soot, it reported, among other
things, that in the following places a Singleton (non-modifiable) list
should be used:
soot.jimple.internal.JIfStmt - targetBoxes
soot.baf.internal.BLoadInst - useBoxes
soot.jimple.internal.JIdentityStmt - defBoxes
soot.baf.internal.BStoreInst - defBoxes
soot.baf.internal.BIdentityInst - defBoxes
Checking the code, it seems that indeed there's no reason to use a
full-fledged ArrayList in these places, as the collections are singletons
and are immutable.
For example: in soot.jimple.internal.JIfStmt
protected JIfStmt(ValueBox conditionBox, UnitBox targetBox)
{
this.conditionBox = conditionBox;
this.targetBox = targetBox;
targetBoxes = new ArrayList();
targetBoxes.add(this. targetBox);
targetBoxes = Collections.unmodifiableList(targetBoxes);
}
This ArrayList allocates a default size of 10, and will always use only 1
element in the underlying array. This might lead to significant waste of
space.
We noticed that in some other places in Soot, the constructors are already
using a SingletonList (e.g., JAssignStmt), and wondered what is the reason
that the aforementioned locations remained as using ArrayLists?
Thanks,
Ohad
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.cs.mcgill.ca/pipermail/soot-list/attachments/20090304/2097c25f/attachment.html
More information about the Soot-list
mailing list