[Soot-list] Fast Annotation Lookup?

Eric Bodden eric.bodden at ec-spride.de
Tue Jan 29 03:21:47 EST 2013


Hi Marc-Andre.

There is no other predefined API for traversing annotations. This is
for a reason. Any auxiliary data structure there is needs to be
maintained when things change. That complicates things.

Regarding StringNumberer: There actually are cases where one needs the
number of the string. Hence it's not just doing the same as intern().
One example is if you have a number of facts associated with a finite
number of Strings. In this case you can just put all facts into an
array and use StringNumberer to address them.

Having said all that: are you sure that hashCode() is really your
bottleneck? As you said, the code is computed just once and really how
many annotations can there be? Also you can always use equals()
without using hashCode(), which should be a rather quick check in most
cases.

Cheers,
Eric

On 29 January 2013 00:23, Marc-Andre Laverdiere-Papineau
<marc-andre.laverdiere-papineau at polymtl.ca> wrote:
> Hello,
>
> I am going to do a lot of work that has to do with Java annotations.
> I have code that works right now, but it is based on a lot of string
> comparisons - so that is very slow.
>
> Pseudocode:
> for all application classes
>    get all annotations on the class
>      for all annotations in the list I care about
>        if annotation.equals(icareabout) then ...
>
> I thought of using StringNumberer to accelerate things a bit - number
> comparisons are faster. But I see that the implementation use a HashMap.
> The calculation of the hash code for a string is a O(n) operation the
> first time (See
> http://jeremymanson.blogspot.com.au/2008/12/benign-data-races-in-java.html).
>
> But if the strings are not canonical, then I have to hit that linear
> operation for the first check. The other ones are O(1), so that's a
> small improvement.
>
> So, here is a question: is Soot automatically converting strings to
> their canonical instance (see String.intern()) ? Or is Soot
> de-duplicating the strings (essentially reimplementing what
> String.intern() does) when loading bodies?
>
> Assuming that there is a proven benefit for StringNumberer, would that
> be a good way to use it?
> Pseudocode:
> precompute the NumberedString  for what I care about
> for all application classes
>    get all annotations on the class
>      compute the NumberedString for the annotation
>      for all precomputed ones
>        if (a == b) then ...
>
> Another question: what is the benefit in using StringNumberer over a
> plain comparison of hashCodes?
>
> That being said, am I reinventing the wheel?
> Has Soot already has a better/faster way to do this? Something along the
> lines of Scene.v().getMethod() and relatives?
>
>
> Regards,
> --
> Marc-André Laverdière-Papineau
> Doctorant - PhD Candidate
> _______________________________________________
> Soot-list mailing list
> Soot-list at sable.mcgill.ca
> http://mailman.cs.mcgill.ca/mailman/listinfo/soot-list



-- 
Eric Bodden, Ph.D., http://sse.ec-spride.de/ http://bodden.de/
Head of Secure Software Engineering Group at EC SPRIDE
Tel: +49 6151 16-75422    Fax: +49 6151 16-72051
Room 3.2.14, Mornewegstr. 30, 64293 Darmstadt


More information about the Soot-list mailing list