[Soot-list] Fast Annotation Lookup?
Marc-Andre Laverdiere-Papineau
marc-andre.laverdiere-papineau at polymtl.ca
Mon Jan 28 18:23:37 EST 2013
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
More information about the Soot-list
mailing list