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

JDI VirtualMachine.allClasses sometimes returns classes that have not been prepared

XMLWordPrintable

    • generic
    • generic

      Calling Field.type() which causes a JDWP ClassLoader.VisibleClasses
      command to be sent, seems to cause a following VirtualMachine.allClasses()
      call to return classes that are not prepared, as in the following example code:

       private void foo(VirtualMachine vm)
        {
          String margin "[GUS: ";
          System.err.println(margin+".................................................");
          vm.setDebugTraceMode(VirtualMachine.TRACE_ALL);
          try
          {
            for (Iterator it = vm.classesByName("gus.classloader.PolicyClassLoader").iterator(); it.hasNext(); )
            {
              ReferenceType rt = (ReferenceType)it.next();
              System.err.println(margin+"before rt.fieldByName");
              Field field = rt.fieldByName("parent");
              System.err.println(margin+"after rt.fieldByName");
              System.err.println(margin+"before field.type");
              Type type = field.type(); // This causes JDWP.ClassLoaderReference.VisibleClasses
              System.err.println(margin+"after field.type");
            }

            for (Iterator it = vm.allClasses().iterator(); it.hasNext(); )
            {
              ReferenceType rt = (ReferenceType)it.next();
              if (! rt.isPrepared())
              {
                System.err.println(margin+"rt.name(): " + rt.name());
                System.err.println(margin+"rt.isPrepared(): " + rt.isPrepared());
                System.err.println(margin+"rt.isInitialized(): " + rt.isInitialized());
                System.err.println(margin+"rt.isVerified(): " + rt.isVerified());
                System.err.println(margin+"rt.failedToInitialize(): " + rt.failedToInitialize());
                System.err.println(margin+"");
                ObjectReference or = null;
                try
                {
                  or = rt.classObject();
                  System.err.println(margin+"rt.classObject(): " + or);
                }
                catch (Exception e)
                {
                  System.err.println(margin+"rt.classObject() threw " + e);
                }
                try
                {
                  if (or != null)
                    System.err.println(margin+"or.isCollected(): " + or.isCollected());
                }
                catch (Exception e)
                {
                  System.err.println(margin+"or.isCollected() threw " + e);
                }
              }
            }
          }
          catch (Exception e)
          {
            e.printStackTrace();
          }
          vm.setDebugTraceMode(VirtualMachine.TRACE_NONE);
        }

            Unassigned Unassigned
            jjh James Holmlund (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: