Invariant Specification and Multi-Staging using Java Annotations

Poster

Java annotations allow programmers to attach metadata to programs. During normal execution, the annotations are ignored, but in contrast to comments in the source code, annotations can be manipulated programmatically at compile- or run-time. We propose two extensions -- subtyping and expression annotations -- for consideration in the Java specification request for annotations, and show how annotations can be used to express program invariants and multi-stage programs.

I've Read This
  • 58 Views
Invariant Specification and Multi-Staging using Java Annotations
    Java Annotations
      Attach meta-data to program constructs  Data about the program, not data in the program Formerly often specified as comments  Can now be checked and processed automatically  Avoids parsing of source code or strings  Annotations act as “smart comments” Annotations are product types (“structs”) composed of constants  primitives (int, double, etc.)  enums  strings  class constants (Integer.class)  other annotations  arrays of the above @interface OnlyRunByThread { String value; } @interface NonNull { } @OnlyRunByThread(”main”) class MyClass { @NonNull Object field; MyClass(@NonNull Object param) { field = param; } @NonNull Object method() { @NonNull Object localVar = field; return localVar; } }
    
    Corky Cartwright Mathias Ricken Walid Taha
    
    // annotation definition // string member // “marker” annotation def. // class annotation // field annotation // parameter annotation // method annotation // local variable annotation
    
    
    
    Subtyping
    
    Invariant Specification
     Program invariants can be encoded as annotations and checked automatically  Similar to assert statements, but inherited into subclasses  Generates log file instead of terminating program  Simple generation of invariant index using Javadoc tool
    
     
    
    Annotations in Java do not have a common supertype  Cannot define an annotation that can contain ANY other annotation Added subtyping for annotations to Java  Minimal changes to compiler, no changes to class file format  Minor changes to reflection API to support additional features Integrates well with existing code  Improves @DefaultQualifier annotation, which currently uses a string
    
    
    
    interface TableModel { // invariant: must be called from within event thread @OnlyEventThread void setValueAt(...); } class MyTableModel implements TableModel { void setValueAt(...) { /* invariant automatically inherited */ } } // from outside event thread... TableModel m = new MyTableModel(...); m.setValueAt(...); // invariant violation, generates log entry
    
    // former way to specify more than one default qualifier @interface DefaultQualifier { String value; } @interface DefaultQualifiers { DefaultQualifier[] value; } @interface NonNull { } @interface Interned { } @DefaultQualifiers({@DefaultQualifier(”NonNull”), // use of strings! @DefaultQualifier(”Interned”)}) class MyClass { ... } // specifying more than one default qualifier with subtyping @interface Annotation { } @interface DefaultQualifier { Annotation[] value; } @interface NonNull extends Annotation { } // subtyping @interface Interned extends Annotation { } // subtyping @DefaultQualifier({@NonNull, @Interned}} class MyClass { ... } 
    
    Multi-Staging
    Multi-stage programming (MSP) is a paradigm for developing generic software witout paying a runtime penalty for this generality  “Staging” moves computations into a code generation step before runtime  Genericly written code (e.g. power) is optimized for special cases (e.g. square) Use annotations to mark how expressions and statements should be staged  @Code code to be generated (.. in MetaOCaml, ”brackets”)  @Escape code to be spliced together (.~x in MetaOCaml)  @Run run generated code (.!x in MetaOCaml) Staging annotations can be ignored to yield unstaged program // staged power function in Java @Code double power(@Code double x, int n) { if (n==0) return @Code (1.0); else return @Code (@Escape (x) * @Escape (power(x, n-1))); } double square(double x) { return @Run (power(@Code (x), 2)); } let rec power (x, n) = (* staged power function in MetaOCaml *) match n with 0 -> .<1>. | n -> .<.~x * .~(power (x, n-1))>.;; let square = .! . .~(power (.., 2))>.;;
    
    
    
    Additional Targets
     Annotations in Java cannot be attached to statements or expressions  Allow additional targets for annotations  block statements  parenthetical expressions @Contained { // block annotation // block of code that does not spawn async. tasks (”contained”) } int i = -5; int j = @AlwaysPositive (i*i); // paren. expression annotation
    
    

Readers

Recent searches finding this paper
java annotation block via Google
java annotations logging via Google
logging annotation java 6 via Google
invariant java via Google
java program to find x^n via Google
x to the power of n java via Google
add logging to java methods using annotations via Google
java log enter exit method annotation via Google
How to annotate java expressions via Google
java annotation logger via Google
java annotation logging via Google
add logging to java methods using annotations via Google
logging with java annotations @log via Google
add logging to java methods using annotations via Google
google java annotation via Google
java annotation local variable via Google
java program to find x^n via Google
file logging using java annotations via Google
Key words for Java Annotation paper via Google
java annotations logging via Google
java annotation for logging via Google
java annotate code block via Google
using java annotations for logging via Google
java annotations programmatic via Google
Google annotation java via Google
finding n to the power n in java via Google
java annotation block via Google
java annotation multi extends via Google
apply annotations to block of code via Google
2 to the power of x java sample code via Google
multi method annotation java via Google
rice multi methods in java via Google
2 power n java program via Google
using annotation logging via Google
using arrays in interface annotations via Google
java annotation invariant via Google
java annotation invariant via Google
java annotation invariant via Google
java Java program to compute the result of x to the power of n. via Google
java annotation to log entry to method via Google
java download programming OF A INTEGER X WHOSE POWER IS N via Google
attach database Annotation in java code via Google
annotate java block via Google
java annotation block via Google
java annotation block via Google
computer science + programming + invariants + university via Google
java staging via Google
programming invariant functions -mathematics via Google
"n to the power of n" via Google
logging using java annotations via Google
staging concurrent programming via Google
software generation of invariant via Google
java program to find x power n via Google
java annotation programmatic via Google
java annotation @Log via Google
java annotation @Log via Google
how to attach metadata to java class via Google
annotation for block java via Google
java annotation block via Google
java annotation block via Google
university using java edu via Google
java annotation logging via Google
multistaging in java via Google
java block annotations via Google
java annotation invariant via Google
java annotation invariant via Google
specification RICE via Google
java annotation interface via Google
java annotation block via Google
"annotations ignored" via Google
programming + function invariant via Google
java annotation block of code via Google
"n to the power of n" via Google
Is java annotation supports on block of code? via Google
program of a to the power n in java via Google
Java invariants via Google
"n to the power of n" via Google
@logentry java annotation via Google
java annotation logging method via Google
ricken java via Google
java annotation log via Google
java annotations block via Google
return object +java +annotations via Google
"Java Parenthetical Expressions" via Google
locale variable annotation java via Google
java code for power function via Google
program to find x^n in java via Google
java annotations for block via Google
are java annotations ignored via Google
java class to find power of x via Google
n to the power of n in java via Google
Java annotation logging via Google
java annotations ignored via Google
java annotation ignored via Google
java class to find power of x via Google
match metaocaml via Google
what is staging in java via Google
java annotations cannot be in if block via Google
java annotations to log method entry via Google
StegPngGUI in java via Google
 

Academia © 2009