vmkit java annotations

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 !

Hello Alexandru,

No you did nothing wrong.

We are using our own data structure to describe annotations in J3. So it is normal that you can not see your Java annotations inside the LLVM bytecode produced.
If I remember well, our implementation of annotations do not rely on LLVM annotations.

Regards,

Harris Bakiras

Hello Harris,

Thank you for your answer. So it is there a way of annotating variables in Java Code, so I can see them into LLVM bytecode?

Thank you !

What classpath implementation are you using ? GNUClasspath or OpenJDK ?

Harris Bakiras

Hello,

I am using GNU classpath-0.97.2.