@RuntimeType
public static Object intercept(@Origin Method m, @SuperCall Callable<?> zuper) throws Exception {
try {
System.out.println("before call");
return zuper.call();
}
finally
{
System.out.println("after call);
}
}
for (Field f : zuper.getClass().getDeclaredFields()) {
f.setAccessible(true);
System.out.println("** >> " + f.get(zuper.getClass()));
}java.lang.IllegalArgumentException: Can not set Calculator field Calculator$auxiliary$P2q1d35m.argument0 to java.lang.Class
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:164)
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:168)
at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:55)
at sun.reflect.UnsafeObjectFieldAccessorImpl.get(UnsafeObjectFieldAccessorImpl.java:36)
at java.lang.reflect.Field.get(Field.java:379)
at MethodProfiler.intercept(MethodProfiler.java:44)@RuntimeType
public static Object intercept(@Origin Method m, @SuperCall Callable<?> zuper, @This Object thiz) throws Exception {
for (Field f : m.getDeclaringClass().getDeclaredFields()) {
f.setAccessible(true);
System.out.println (f.getName() + " : " + f.get(thiz));
}
return zuper.call();
}
field1 : 1
field2 : 2
cachedValue$KS3GfOdY$35112437 : public java.lang.String java.lang.Object.toString()
cachedValue$KS3GfOdY$1381757894 : public native int java.lang.Object.hashCode()
cachedValue$KS3GfOdY$1690562568 : public int Calculator.sum(Product)
cachedValue$KS3GfOdY$1214606314 : public boolean java.lang.Object.equals(java.lang.Object)
cachedValue$KS3GfOdY$651330760 : protected native java.lang.Object java.lang.Object.clone() throws java.lang.CloneNotSupportedException
You can use the @FieldValue annotation. There is no good way for getting all fields as you attempt it, unfortunately.
Thanks Rafael. Yes, there is a isSynthetic() method on the Field to simply filter out such fields.
BTW, you mentioned that getting a method reference is expensive. Is there any other (less expensive) alternative to access the fields?
--