AnnotationType alternative patch
Peter Levart
peter.levart at gmail.com
Fri Feb 1 22:23:01 UTC 2013
Hello Joel and the list,
While revisiting the patch that I proposed a couple of months ago:
http://mail.openjdk.java.net/pipermail/core-libs-dev/2012-December/012630.html
...and which also includes some other things besides the main fix for
scalability and dead-locks, I tried to see what It would take to modify
the annotation parsing logic in a way that would make construction of
AnnotationType instance infinite-recursion-free without resorting to
publishing the reference to the instance in the middle of the
constructor. As it turns out the changes are quite simple:
http://freeweb.t-2.net/peter_levart/jdk8-tl/AnnotationType/webrev.01/index.html
I added an overloaded method to AnnotationParser which only parses
select annotations (quickly skipping the rest of raw annotation bytes)
and implicitly considers those annotations as having RUNTIME retention.
This method is used inside the constructor of AnnotationType just for
parsing the @Retention and @Inherited meta annotations for annotation class.
This way the infinite recursion is broken and there's no need to publish
the half-constructed instance just to prevent it. Everything else is
easy: the AnnotationType class is now immutable (all fields final) and
can be published to other threads via data race (removed synchronized
from AnnotationType.getInstance()). Scalability is infinite and
dead-locks are eliminated.
This patch also fixes inconsistent behavior when we have two mutually
recursive RUNTIME annotations and one's scope is changed to CLASS and
separately compiled - the situation that I described in above-mentioned
message.
Regards, Peter
More information about the core-libs-dev
mailing list