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

Change in class loading/unloading behavior between 1.0.2 and 1.1.3

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Won't Fix
    • Affects Version/s: 1.1.3
    • Fix Version/s: None
    • Component/s: hotspot
    • Labels:
      None
    • Subcomponent:
    • CPU:
      sparc
    • OS:
      solaris_2.5.1

      Description

      "Charlie McDowell" <###@###.###> writes:
       
      I believe that the way you do class unloading is incorrect. The
      attached example demonstrates how a program gets different behavior
      when GC is called which causes a class with a static field to be
      unloaded. Try it with and then without the System.gc line.

      class Example
      {
          public static void main(String[] args)
          throws java.io.IOException, ClassNotFoundException,
          IllegalAccessException, InstantiationException
          {
              int count = 0;
              SomeInterface class_one_object;

              /* load the class ClassOne and instantiate an instance of it */
              /* ClassOne uses ClassTwo which will thus get loaded also */
              Class theClass = Class.forName("ClassOne");
              class_one_object = (SomeInterface)theClass.newInstance();

              /* remove all references to the class and the instance */
              class_one_object = null;
              theClass = null;

      System.gc(); /* force garbage collection which also unloads classes */
              
              /*loads and instantiates ClassOne again. ClassTwo also gets reloaded*/
              class_one_object = (SomeInterface)new ClassOne();
          }
      }
      // File ClassOne.java:
      // public class ClassOne implements SomeInterface{
      // public ClassOne(){
      // new ClassTwo();
      // }
      // }

      // File SomeInterface.java:
      // public interface SomeInterface {
      // }

      // File ClassTwo.java:
      // public class ClassTwo {
      // static int counter=0;
      // public ClassTwo(){
      // counter++;
      // System.out.println("ClassTwo has counter = " + counter);
      // }
      // }

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              sliangsunw Sheng Liang (Inactive)
              Reporter:
              tbell Tim Bell
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: