Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-5043030

(reflect) unnecessary object creation in reflection

XMLWordPrintable

    • b31
    • generic
    • solaris_8
    • Verified

        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));
            }
        }

              jfranck Joel Borggrén-Franck (Inactive)
              gafter Neal Gafter (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: