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

(reflect) unnecessary object creation in reflection

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b31
    • CPU:
      generic
    • OS:
      solaris_8
    • Verification:
      Verified

      Backports

        Description

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

          Attachments

            Issue Links

              Activity

                People

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

                  Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: