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

java GC should never unload a class that contains non-final static fields

    Details

    • Subcomponent:
    • CPU:
      generic
    • OS:
      solaris_2.5.1

      Description

      Seems to me that java GC should never unload a class that contains
      non-final static fields. If the value of a static field is modified,
      then we expect that value to hold for the rest of the session. If the
      class is unloaded and then re-loaded, the static field will be
      reintialized and modification will be lost.

      I think it could only happen when classes are loaded indirectly.

      Here's a possible scenario:
      Suppose there is a class:
      class BulletinBoard {
      boolean m_killroyWasHere;
      }

      Suppose no loaded class has code or fields that refer to
      BulletinBoard.

      Suppose there's another class:
      class Kilroy {
      public static void main (String argv[]) {
      if (!BulletinBoard.m_killroyWasHere)
      {
      // do something really big
      BulletinBoard.m_killroyWasHere = true;
      }
      }
      }

      Suppose you load Killroy from a third clas by calling
      Class.forName("Killroy"), or using a class loader or something indirect
      like that. Note that loading Killroy will cause BulletinBoard to be loaded.
      Killroy's main then returns, and the class Killroy is eventually GC'd.
      What's to stop BulletinBoard from being GC'd? By hypothesis, no loaded class refers to it (now that Killroy is gone). Now suppose you load Killroty again
      by calling Class.forName("Killroy"). Killroy's main will cause BulletinBoard
      to be loaded again, and it will see BulletinBoard.m_killroyWasHere == false -- which is incorrect.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                apalanissunw Anand Palaniswamy (Inactive)
                Reporter:
                jbenoit Jonathan Benoit (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: