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

Memory leak in JceSecurity

    XMLWordPrintable

Details

    • b23
    • generic
    • generic
    • Verified

    Backports

      Description

        FULL PRODUCT VERSION :
        Issue exists since Java 1.5

        ADDITIONAL OS VERSION INFORMATION :
        All Platforms

        A DESCRIPTION OF THE PROBLEM :
        javax.crypto.JceSecurity holds a static map of all Provider instances ever inspected for code integrity. This leaks memory when Provider instances are continuously, created, used, and de-referenced in application code.

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        In a tight loop, create a new Provider, do some operation with it that ensures verification, and then de-reference it in application code. This will eventually lead to an OutOfMemoryError.

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        No OutOfMemoryError
        ACTUAL -
        OutOfMemoryError

        ERROR MESSAGES/STACK TRACES THAT OCCUR :
        java.lang.OutOfMemoryError: GC overhead limit exceeded


        REPRODUCIBILITY :
        This bug can be reproduced often.

        ---------- BEGIN SOURCE ----------
        with Xmx=256m, this will throw an OutOfMemoryError:

        for (int i = 0; i < 10000; i++) {
            SunJCE jceProvider = new SunJCE();
            Cipher c = Cipher.getInstance("AES", jceProvider);
        }

        ---------- END SOURCE ----------

        CUSTOMER SUBMITTED WORKAROUND :
            Map<Provider, Object> map = Collections.synchronizedMap(new WeakHashMap<>());

            Class cl = Class.forName("javax.crypto.JceSecurity");
            Field field = cl.getDeclaredField("verificationResults");
            field.setAccessible(true);

            Field modifiersField = Field.class.getDeclaredField( "modifiers" );
            modifiersField.setAccessible( true );
            modifiersField.setInt( field, field.getModifiers() & ~Modifier.FINAL );

            Map<Provider, Object> verificationResults = (Map<Provider, Object>) field.get(null);
            map.putAll(verificationResults);
            field.set(null, map);

        Attachments

          1. 9044691.patch
            3 kB
            Bradford Wetmore
          2. JI9044691.java
            0.4 kB
            Pallavi Sonal

          Issue Links

            Activity

              People

                valeriep Valerie Peng
                webbuggrp Webbug Group
                Votes:
                0 Vote for this issue
                Watchers:
                9 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: