[LLVMdev] vmkit java annotations
Alexandru Ionut Diaconescu
alexandruionutdiaconescu at gmail.com
Mon Jun 17 05:19:33 PDT 2013
Hello everyone,
I am able to work very well with annotations in C/C++, by using
__attribute__((annotate("MYANNOTATION"))) static int a; . Inside the LLVM
bytecode I have @llvm.global.annotations and @llvm.var.annotation.
However, I was trying to test annotations also in Java, with VMKit. These
are the commands that I run:
javac -Xlint -g -O Main.java
../Release+Asserts/bin/vmjc Main
../Release+Asserts/bin/j3 Main
../../llvm_new/Release+Asserts/bin/llvm-dis < Main.bc > Main_assembly
My small program is :
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Method;
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@interface Red {
String info() default "";
}
class Annotated {
@Red(info = "AWESOME")
public void foo(String myParam) {
System.out.println("This is " + myParam);
}
}
class TestAnnotationParser {
public void parse(Class clazz) throws Exception {
Method[] methods = clazz.getMethods();
for (Method method : methods) {
if (method.isAnnotationPresent(Red.class)) {
Red test = method.getAnnotation(Red.class);
String info = test.info();
if ("AWESOME".equals(info)) {
System.out.println("info is awesome!");
// try to invoke the method with param
method.invoke(
Annotated.class.newInstance(),
info
);
}
}
}
}
}
public class Main {
public static void main(String[] args) throws Exception {
TestAnnotationParser parser = new TestAnnotationParser();
parser.parse(Annotated.class);
}
}
However, I cannot find the annotations in the bytecode. It is something
that I did wrong?
Thank you in advance !
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130617/25f2d18e/attachment.html>
More information about the llvm-dev
mailing list