[Jsr308-statements] Prototype of loop annotation compiler

Eugene Kuleshov eu at javatx.org
Fri Feb 9 12:11:06 EST 2007


Trevor,

  This is cool stuff and really great start!

  On a side note, I think that such annotations should be written as 
code attributes, especially because they have references to the offset.

  regards,
  Eugene


Trevor Harmon wrote:
> Last week I started working on modifying the javac compiler to support 
> loop annotations. I need this for a WCET analysis tool I'm building 
> for my research, and also I want to help JSR-308 bring loop annotation 
> support to Java 7. Toward that end, I'm posting the modifications I've 
> made here:
>
> http://vocaro.com/trevor/files/javac-loop-annotations.patch
>
> The above is a patch against the current javac repo in OpenJDK. It 
> adds support for annotations on while loops, for loops, and for-each 
> loops. (I didn't bother with do/while loops for the moment.)
>
> I should point out that I'm not a compiler expert, and I'm new to the 
> javac code, so the patch is simplistic. I changed just enough to get 
> loop annotations working. In particular, my handling of writing out 
> the loop annotations as attribute data is somewhat awkward. (Part of 
> the problem is that javac seems to have been designed without 
> anticipating future annotation formats. I'm guessing it will need to 
> be refactored a fair bit in order to support the JSR-308 annotations.) 
> Still, the resulting compiler is entirely useable and should be 
> helpful to anyone who wants to play around with loop annotations.
>
> A few words on implementation... The annotations are written out as 
> method attributes called RuntimeVisibleLoopAnnotations and 
> RuntimeInvisibleLoopAnnotations. The format is identical to 
> RuntimeVisibleAnnotations/RuntimeInvisibleAnnotations except that an 
> additional field has been added following "u2 type_index":
>
> u4 pc;  // Code offset to the start of the loop
>
> To verify that my patch works, I also created a utility that will dump 
> a class's annotations to the console:
>
> http://vocaro.com/trevor/files/dump-annotations.tar.gz
>
> It displays them in the same struct-like format as the VM spec, making 
> the data easy to read. It can be extended without much effort to dump 
> any annotation format, so it should be useful to other folks working 
> on JSR-308, too. To try it out with loop annotations, first install 
> javac with the above patch applied, specify the location of this javac 
> in the build file, then run "ant dump". This will print the results of 
> a simple test case.
>
> Hopefully this effort will help move the JSR-308 project closer to 
> enabling loop annotations in Java.
>
> Let me know what you think. I can talk more about the specific changes 
> I made if anyone has questions about that.
>
> Trevor
>
>
> _______________________________________________
> Jsr308-statements mailing list
> Jsr308-statements at lists.csail.mit.edu
> https://lists.csail.mit.edu/mailman/listinfo/jsr308-statements




More information about the Jsr308-statements mailing list