Package javax.tools.diagnostics.runtime.java

Examples of javax.tools.diagnostics.runtime.java.JavaReference


    while (references.hasNext()) {
      Object next = references.next();
      if (!(next instanceof JavaReference)) {
        continue;
      }
      JavaReference ref = (JavaReference)next;
      assertNotNull("Reference description is null", ref.getDescription());
    }
  }
View Full Code Here


    while (references.hasNext()) {
      Object next = references.next();
      if (!(next instanceof JavaReference)) {
        continue;
      }
      JavaReference ref = (JavaReference)next;
      Object target = ref.getTarget();
      if (!(target instanceof JavaObject)) {
        continue;
      }
      JavaObject targetObject = (JavaObject)target;
      if ("java/lang/ref/WeakReference".equals(targetObject.getJavaClass().getName())) {
        JavaReference referent = getReferent(targetObject);
        assertTrue("Reachability for weak referent different from \"Weak\"", JavaReference.REACHABILITY_WEAK == referent.getReachability());
       
       
      } else if ("java/lang/ref/SoftReference".equals(targetObject.getJavaClass().getName())) {
        JavaReference referent = getReferent(targetObject);
        assertTrue("Reachability for soft referent different from \"Soft\"", JavaReference.REACHABILITY_SOFT == referent.getReachability());
       
      } else if ("java/lang/ref/PhantomReference".equals(targetObject.getJavaClass().getName())) {
        JavaReference referent = getReferent(targetObject);
        assertTrue("Reachability for phantom referent different from \"Phantom\"", JavaReference.REACHABILITY_PHANTOM == referent.getReachability());
       
      } else if (targetObject.getJavaClass().getName().endsWith("StrongReferent")) {
        assertTrue("Reachability for strong field reference different from \"Strong\"", JavaReference.REACHABILITY_STRONG == ref.getReachability());
      }
    }
View Full Code Here

    while (references.hasNext()) {
      Object next = references.next();
      if (!(next instanceof JavaReference)) {
        continue;
      }
      JavaReference ref = (JavaReference)next;
      Object target = ref.getTarget();
      if (ref.isClassReference()) {
        assertTrue("Supposed class reference has a non-JavaClass target",target instanceof JavaClass);
      }
    }
   
  }
View Full Code Here

    while (references.hasNext()) {
      Object next = references.next();
      if (!(next instanceof JavaReference)) {
        continue;
      }
      JavaReference ref = (JavaReference)next;
      Object target = ref.getTarget();
      if (ref.isObjectReference()) {
        assertTrue("Supposed object reference has a non-JavaObject target",target instanceof JavaObject);
      }
    }
   
  }
View Full Code Here

    while (references.hasNext()) {
      Object next = references.next();
      if (!(next instanceof JavaReference)) {
        continue;
      }
      JavaReference ref = (JavaReference)next;
      int type = ref.getReferenceType();
      Object source = ref.getSource();
      Object target = ref.getTarget();
     
      switch (type) {
      case JavaReference.REFERENCE_FIELD:
        if (source instanceof JavaObject) {
          JavaObject sourceObject = (JavaObject)source;
          if (!(sourceObject.equals(thisObj))) {
            fail("Source object for a field reference not equal to this object.");
          }

          if (target instanceof JavaObject) {
            JavaObject targetObject = (JavaObject)target;
            String objectsClassName = targetObject.getJavaClass().getName();
            if (!(objectsClassName.endsWith("Reference") ||
                objectsClassName.endsWith("Referent"||
                objectsClassName.endsWith("ArrayElement;") ||
                objectsClassName.endsWith("ClassLoader"))) {
              fail("Unexpected field reference of type: "+ objectsClassName);
            }
            if (objectsClassName.endsWith("ArrayElement;") && targetObject.isArray()) {
              //found the array field.
              Iterator refs = targetObject.getReferences().iterator();
              boolean arrayElementFound = false;
              while (refs.hasNext()) {
                Object next2 = refs.next();
                if (!(next2 instanceof JavaReference)) {
                  continue;
                }
                JavaReference ref2 = (JavaReference)next2;
                int type2 = ref2.getReferenceType();
                Object target2 = ref2.getTarget();
               
                if (type2 == JavaReference.REFERENCE_ARRAY_ELEMENT) {
                  if (target2 instanceof JavaObject) {
                    JavaObject targetObject2 = (JavaObject)target2;
                    String objectsClassName2 = targetObject2.getJavaClass().getName();
                    if (objectsClassName2.endsWith("ArrayElement") && !targetObject2.isArray()) {
                      arrayElementFound = true;
                    }
                  } else {
                    fail("Target object of a REFERENCE_ARRAY_ELEMENT reference has the wrong type.");
                  }
                }
              }
              assertTrue("Array element reference not found.", arrayElementFound);
            }
         
          } else {
            fail("Target object of a REFERENCE_ARRAY_ELEMENT reference has the wrong type.");
          }
         
        } else {
          fail("Source object of a field reference is not a valid JavaObject.");
        }
        break;
      case JavaReference.REFERENCE_CLASS:
        if (source instanceof JavaObject) {
          JavaObject sourceObject = (JavaObject)source;
          if (!(sourceObject.equals(thisObj))) {
            fail("Source object for a CLASS reference not equal to this object.");
          }

          if (!(target instanceof JavaClass)) {
            fail("Target object for a CLASS reference not a JavaClass object.");
          }
          JavaClass targetClass = (JavaClass)target;
          assertTrue("Target class for the CLASS reference of this object different from expected.", targetClass.getName().endsWith("SetupJavaReferences"));
          Iterator refs = targetClass.getReferences().iterator();
          boolean classLoaderFound = false;
          while (refs.hasNext()) {
            Object next2 = refs.next();
            if (!(next2 instanceof JavaReference)) {
              continue;
            }
            JavaReference ref2 = (JavaReference)next2;
            int type2 = ref2.getReferenceType();
            Object target2 = ref2.getTarget();
           
            if (type2 == JavaReference.REFERENCE_CLASS_LOADER) {
              if (!(target2 instanceof JavaObject)) {
                fail("Target object for a CLASSLOADER reference does not represent a JavaObject.");
              }
View Full Code Here

  }
 
   
  private JavaReference getReferent (JavaObject obj) {
    Iterator references = obj.getReferences().iterator();
    JavaReference referent = null;
    while (references.hasNext() && referent == null) {
      Object next = references.next();
      if (!(next instanceof JavaReference)) {
        continue;
      }
      JavaReference ref = (JavaReference)next;
      String description = ref.getDescription();
      if (description.indexOf("referent") == -1) {
        continue;
      }
      referent = ref;
    }
View Full Code Here

        JavaObject mdObject = (JavaObject)multiDimArrayObject;
        Iterator refs = mdObject.getReferences().iterator();
        while (refs.hasNext()) {
          Object next = refs.next();
          if (next instanceof JavaReference) {
            JavaReference ref = (JavaReference) next;
            try {
              Object target = ref.getTarget();
              if (target instanceof JavaObject) {
                JavaObject targetObject = (JavaObject) target;
                System.out.println(targetObject.getJavaClass().getName());
              }
              System.out.println(ref.getDescription());
            } catch (DataUnavailable e) {
              e.printStackTrace();
            }
          } else {
            fail ("Found reference which is NOT an instance of JavaReference.");
View Full Code Here

    while (roots.hasNext()) {
      Object next = roots.next();
      if (next instanceof CorruptData) {
        continue;
      }
      JavaReference r = (JavaReference)next;
      try {
        Object root = r.getTarget();
        int type = r.getRootType();
        HeapRoot rootObject = new HeapRoot(root, type);
        rootsCheckList.put(rootObject, Boolean.FALSE);
        //System.out.println("Adding " + rootObject + " to rootCheckList" );
      } catch (DataUnavailable du) {
      } catch (CorruptDataException cde) {
View Full Code Here

      while (references.hasNext()) {
        Object instance = references.next();
        assertTrue((instance instanceof JavaReference) || (instance instanceof CorruptData));
        if (instance instanceof JavaReference) {
          // sniff these objects by getting the description
          JavaReference object = (JavaReference)instance;
          String description = object.getDescription();
          assertNotNull(description);
        }
      }
     
      // test references from an array object
      references = _array.getReferences().iterator();
      assertNotNull(references);
      while (references.hasNext()) {
        Object instance = references.next();
        assertTrue((instance instanceof JavaReference) || (instance instanceof CorruptData));
        if (instance instanceof JavaReference) {
          // sniff these objects by getting the description
          JavaReference object = (JavaReference)instance;
          String description = object.getDescription();
          assertNotNull(description);
        }
      }
    } catch (Exception e) {
      // if we caught anything else, this is a failure
View Full Code Here

    while (roots.hasNext()) {
      Object next = roots.next();
      if (next instanceof CorruptData) {
        continue;
      }
      JavaReference r = (JavaReference)next;
      try {
        Object root = r.getTarget();
        int type = r.getRootType();
        HeapRoot rootObject = new HeapRoot(root, type);
        rootsCheckList.put(rootObject, Boolean.FALSE);
        //System.out.println("Adding " + rootObject + " to rootCheckList" );
      } catch (DataUnavailable du) {
      } catch (CorruptDataException cde) {
View Full Code Here

TOP

Related Classes of javax.tools.diagnostics.runtime.java.JavaReference

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.