Optimizing Method/Constructor Calls

makeProxy(java.lang.reflect.Method object )
makeProxy(java.lang.reflect.Constructor object )

makeProxy() function creates a proxy function that calls Method or Constructor specified in the parameter, not using Reflection API. It can improve the speed of Method/Constructor calls because method/constructor selection step based on parameter types is skipped, and JIT compiler can optimize the generated code a lot more than reflection calls.

e.g.
copy = makeProxy(System.getMethod("arraycopy", [Object, int, Object, int, int]))

src = (int[])[1,2,3,4,5]
dest = int[5]

copy(src, 0, dest, 0, src.length)
dest  ==> [1,2,3,4,5]

Proxy functions for non-static methods receive the target object as the first parameter.

e.g.
hashCode = makeProxy(Object.getMethod("hashCode", []))
hashCode(Object())

Back