Tiger introduces a cache of commonly used wrapper instances, and a static
factory for returning them. The language requires caching Integers in the
range -128 to 127. But this cache is not used in the reflection
implementation, resulting in much unnecessary object creation when running
reflective code.
Here is a test case that illustrates the problem:
/////////////////////////////////////////////////////////
import java.lang.reflect.*;
class Main {
public static int f() { return 0; }
public static void main(String[] args) throws Exception {
Method m = Main.class.getMethod("f");
Object o1 = m.invoke(null);
Object o2 = m.invoke(null);
if (o1 != o2)
throw new Error(System.identityHashCode(o1) +
" " + System.identityHashCode(o2));
}
}