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

jdb: enablegc does not work for reference, gcollection of which was disabled

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Cannot Reproduce
    • Affects Version/s: 1.3.0
    • Fix Version/s: None
    • Component/s: core-svc
    • Labels:
    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      jdb does not enable garbage collection for objects for which garbage collection was disable earlier by jdb 'disablegc' command.

      To reproduce the problem next class was used.
      Steps:
      * disablegc for created WeakReference wr.
      * enablegc for same object

      import java.lang.ref.*;

      class node {
          byte [] arr;
          node(int size){ arr = new byte[size]; }
      }


      class GC {
           
          public static void GenGarb() {
              int num = 50;
              SoftReference[] srArr = new SoftReference[num];
              WeakReference[] wrArr = new WeakReference[num];

              for (int j = 0;j < num;j++) {
                  for (int i = 0;i < num;i++) {
                      srArr[i] = new SoftReference(new node(90000));
                      wrArr[i] = new WeakReference(new node(90000));
                  }
                  System.gc();
              }
          }
          

          public static void main(String args[]) {
              Runtime rt = Runtime.getRuntime();
              Reference rc;
              ReferenceQueue rq = new ReferenceQueue();
              WeakReference wr = new WeakReference(new node(20000), rq);
              node t;
              int count = 0;
              
              try {
                  while (count++ < 10) {
                      GenGarb();
                      t = (node) wr.get();
                      if (t == null) {
                          rc = rq.poll();
                          System.out.println("Object has been cleared.");
                          wr = new WeakReference(new node(200000), rq);
                      } else {
                          rc = rq.poll();
                           System.out.println("Object is still in memory.");
                      }
                  }
              }catch (OutOfMemoryError e) {
                  System.gc();
                  System.out.println("Failed at the " + count +"th iteration.");
              }
          }
      }

        Attachments

          Activity

            People

            • Assignee:
              tbell Tim Bell
              Reporter:
              avolkovorcl Alexei Volkov (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: