[Soot-list] Singleton ArrayLists

Eric Bodden eric.bodden at mail.mcgill.ca
Sat Mar 7 13:27:01 EST 2009


I have committed appropriate changes to Soot.

Thanks again,
Eric

2009/3/4 Patrick Lam <plam at sable.mcgill.ca>:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hi Ohad,
>
> Thanks for the note and the profiling results. There is no particular
> reason that some places in the code use singleton lists and others
> don't. I think it just depended on when each piece of code was written.
> Someone should go through and change the code to make it more
> space-efficient.
>
> pat
>
> Ohad Shacham wrote:
>> 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
>>
>>
>>
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> Soot-list mailing list
>> Soot-list at sable.mcgill.ca
>> http://mailman.cs.mcgill.ca/mailman/listinfo/soot-list
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.9 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iEYEARECAAYFAkmujJ4ACgkQNTVxnNGEyOj7cACcDlf8AJ2pXJRPBIpKtYx/l2MR
> dAUAniHuUHRnIM5VVq97pJBUapzSaAk5
> =Kohr
> -----END PGP SIGNATURE-----
> _______________________________________________
> Soot-list mailing list
> Soot-list at sable.mcgill.ca
> http://mailman.cs.mcgill.ca/mailman/listinfo/soot-list
>



-- 
Eric Bodden
Sable Research Group, McGill University
Montréal, Québec, Canada


More information about the Soot-list mailing list