Examples of JVMTIInterface


Examples of org.jboss.profiler.jvmti.JVMTIInterface

    }
  }
 
  public void testNotifyOnClasses()
  {
    JVMTIInterface jvmti = new JVMTIInterface();
    LocalCallbackTestOnClasses localTest = new LocalCallbackTestOnClasses();
    jvmti.notifyInventory(true,null,null,localTest);
   
    assertEquals(jvmti.getLoadedClasses().length,localTest.count);
  }
View Full Code Here

Examples of org.jboss.profiler.jvmti.JVMTIInterface

    assertEquals(jvmti.getLoadedClasses().length,localTest.count);
  }
 
  public void testInventoryReport() throws Exception
  {
    JVMTIInterface jvmti = new JVMTIInterface();
    System.out.println(jvmti.inventoryReport());
  }
View Full Code Here

Examples of org.jboss.profiler.jvmti.JVMTIInterface

    System.out.println(jvmti.inventoryReport());
  }
 
  public void testProduceInventoryMinimal() throws Exception
  {
    JVMTIInterface jvmti = new JVMTIInterface(); // The JVMTIWrapper used to produce inventories
   
    Map map = jvmti.produceInventory();
    Map map2 = jvmti.produceInventory();
    assertTrue( jvmti.compareInventories(System.out,map,map2,null,null,null));
   
  }
View Full Code Here

Examples of org.jboss.profiler.jvmti.JVMTIInterface

    class TestClass
    {
     
    }
   
    JVMTIInterface jvmti = new JVMTIInterface(); // The JVMTIWrapper used to produce inventories
   
    Map map = jvmti.produceInventory();
    Map map2 = jvmti.produceInventory();
    jvmti.compareInventories(System.out,map,map2,null,null,null);
    System.out.println("size=" + map.size());
    map=null;
    map2=null;

    TestClass keepr = new TestClass(); // at least one instance, so point2 won't be null
   
    Map firstMap = jvmti.produceInventory(); // The inventory of classes, this is HashMap<Class,InventoryDataPoint>

    TestClass [] tests = new TestClass[1000];
    for (int i=0;i<1000;i++)
    {
      tests[i] = new TestClass(); // allocating 1000 objects
    }
    
    Map secondMap = jvmti.produceInventory(); // the second inventory
   
    InventoryDataPoint point1 = (InventoryDataPoint)secondMap.get(TestClass.class);
    InventoryDataPoint point2 = (InventoryDataPoint)firstMap.get(TestClass.class);
   
    assertEquals(1000,point1.getInstances()-point2.getInstances()); // you can manually compare it
   
    assertTrue(jvmti.compareInventories(System.out,firstMap,secondMap,new Class[]{WeakHashMap.class},new String[]{"[Ljava.util.WeakHashMap$Entry;","java.lang.ref"}, new InventoryDataPoint[]{new InventoryDataPoint(TestClass.class,2000)}));
    assertFalse(jvmti.compareInventories(System.out,firstMap,secondMap,new Class[]{WeakHashMap.class},new String[]{"[Ljava.util.WeakHashMap$Entry;","java.lang.ref"}, new InventoryDataPoint[]{new InventoryDataPoint(TestClass.class,100)}));

  }
View Full Code Here

Examples of org.jboss.profiler.jvmti.JVMTIInterface

  public void testExploreObject() throws Exception
  {
    A a = new A();
    B b = a.b;
   
    JVMTIInterface jvmti = new JVMTIInterface();
    HashMap map = jvmti.createIndexMatrix();
    jvmti.exploreClassReferences(B.class.getName(),-1,true,true,true,true,false,map);
   
    System.out.println(jvmti.exploreObjectReferences(map,b,1,true));
    /*map=null;
    jvmti.releaseTags();
    System.out.println(jvmti.exploreObjectReferences(B.class.getName(),2,true)); */
   
   
 
View Full Code Here

Examples of org.jboss.profiler.jvmti.JVMTIInterface

  {
    A a = new A();
    B b = a.b;
    final ArrayList list = new ArrayList();
   
    JVMTIInterface jvmti = new JVMTIInterface();
    jvmti.notifyOnReferences("/tmp/tst.refs",new JVMTICallBack(){

      int count=0;
      public void notifyReference(long referenceHolder, long referencedObject,long classTag, long index, long method, byte referenceType)
      {
        list.add(new ReferenceDataPoint(referenceHolder, referencedObject,classTag, index, method, referenceType));
      }
      public void notifyClass(long classTag, Class clazz) {
        fail("This shouldn't be called now");
      }
      public void notifyObject(long classTag, long objectId, long bytes) {
        fail("This shouldn't be called now");
      }
    });
   
    long tag = jvmti.getTagOnObject(a);
    Object newObject = jvmti.getObjectOnTag(tag);
    assertSame(a,newObject);
   
    int count=0;
    Iterator iter = list.iterator();
    while (iter.hasNext())
    {
      ReferenceDataPoint point = (ReferenceDataPoint)iter.next();
      //System.out.println("point=" + point);
      if (point.getClassTag()!=0 )
      {
        Object obj = jvmti.getObjectOnTag(point.getClassTag());
        if (!(obj instanceof Class))
        {
          System.out.println("point=" + point);
          System.out.println("obj=" + obj);
          fail("Object was supposed to be a Class");
        }
      }
     

      if (point.getReferenceType()==JVMTICallBack.JVMTI_REFERENCE_STATIC_FIELD || point.getReferenceType()==JVMTICallBack.JVMTI_REFERENCE_FIELD)
      {
        try
        {

          Object referenced = jvmti.getObjectOnTag(point.getReferencedObject());
          Object obj = jvmti.getObjectOnTag(point.getReferenceHolder());
          Field field = jvmti.getObjectField(obj .getClass(),(int)point.getIndex());
          Class clazz = (Class)jvmti.getObjectOnTag(point.getClassTag());
          /*if (field==null)
          {
            System.out.println(point);
            System.out.println(referenced + " couldn't find field " +point.getIndex() + " on " + obj);
            Field field2 = jvmti.getObjectField(obj .getClass(),(int)point.getIndex());
          }
          assertNotNull(field);  -- I would like to enforce this, but it seems impossible due to internal classes on JVM */
        }
        catch (NullPointerException e)
        {
        }
      }
      else if (point.getReferenceType()==JVMTICallBack.THREAD_REFERENCE)
      {
        try
        {
        Object classTag = jvmti.getObjectOnTag(point.getClassTag());
        Object objReferenced = jvmti.getObjectOnTag(point.getReferencedObject());
        Object objHolder = jvmti.getObjectOnTag(point.getReferenceHolder());
       
        String methodName= jvmti.getMethodClass(point.getMethod()).getName() + "::" +
        jvmti.getMethodName(point.getMethod()) + jvmti.getMethodSignature(point.getMethod());
        //System.out.println(objReferenced + " being referenced at "+methodName);
        }
        catch (NullPointerException e)
        {
          // this can happen here;
        }
      }
     
    }
   
    System.out.println();
   
    long tagOnA = jvmti.getTagOnObject(a.b);
    iter = list.iterator();
    while (iter.hasNext())
    {
      ReferenceDataPoint point = (ReferenceDataPoint)iter.next();
     
      if (tagOnA == point.getReferencedObject() && (point.getReferenceType()==JVMTICallBack.JVMTI_REFERENCE_FIELD  || point.getReferenceType()==JVMTICallBack.JVMTI_REFERENCE_STATIC_FIELD))
      {
        Object obj = jvmti.getObjectOnTag(point.getReferenceHolder());
        Field field  = null;
       
        if (point.getReferenceType()==JVMTICallBack.JVMTI_REFERENCE_FIELD)
        {
          field  = jvmti.getObjectField((Class)obj.getClass() ,(int)point.getIndex());
        }
        else
        {
          field  = jvmti.getObjectField((Class)obj ,(int)point.getIndex());
        }
        System.out.println(obj + " being referenced at " + field);
      }
      else if (tagOnA == point.getReferencedObject() && (point.getReferenceType()==JVMTICallBack.THREAD_REFERENCE))
      {
        Object classTag = jvmti.getObjectOnTag(point.getClassTag());
        Object objReferenced = jvmti.getObjectOnTag(point.getReferencedObject());
        Object objHolder = jvmti.getObjectOnTag(point.getReferenceHolder());
       
        System.out.println("classTag=" + classTag);
        System.out.println("objReferenced=" + objReferenced);
        System.out.println("objHolder=" + objHolder);
        System.out.println("name=" +jvmti.getMethodClass(point.getMethod()).getName() + "::" +
            jvmti.getMethodName(point.getMethod()) + jvmti.getMethodSignature(point.getMethod()));
      }
    }
   
   
    try
    {
      jvmti.getObjectOnTag(0);
      fail("Supposed to throw an exception");
    }
    catch (Throwable e)
    {
    }
   
    try
    {
      jvmti.getObjectOnTag(-1);
      fail("Supposed to throw an exception");
    }
    catch (Throwable e)
    {
    }
   

   
    jvmti.releaseTags();
    assertEquals(0,jvmti.getTagOnObject(a));
   
   
  }
View Full Code Here

Examples of org.jboss.profiler.jvmti.JVMTIInterface

   
  }
 
  public void testGetReferenceHolders()
  {
    JVMTIInterface jvmti = new JVMTIInterface();
    A a = new A();
    Object[] objects = jvmti.getReferenceHolders(new Object[]{a.b});
    assertEquals(2,objects.length);
    assertSame(a,objects[0]);
  }
View Full Code Here

Examples of org.jboss.profiler.jvmti.JVMTIInterface

      }
   }

   private int countInstances(String name, boolean notSubClasses)
   {
      JVMTIInterface jvmti = new JVMTIInterface();
      Object[] objects = jvmti.getAllObjects(name);
      int subClasses = 0;
      for (int i = 0 ; i < objects.length ; i++)
      {
         if (!objects[i].getClass().getName().equals(name))
         {
View Full Code Here

Examples of org.jboss.profiler.jvmti.JVMTIInterface

      Class interceptorClass = loader.loadClass("org.jboss.test.aop.memoryleaks.TestInterceptor"); */
   }

   private void checkUnload(WeakReference weakReferenceOnLoader, String className) throws Exception
   {
      JVMTIInterface jvmti = new JVMTIInterface();
      if (jvmti.isActive())
      {
        
         //clearEverySingleFieldOnInstances("org.jboss.aop.AspectManager"); // This part is not intended to be commited. It could be used during debug, and you could use to release references on purpose, just to evaluate behavior

         jvmti.forceReleaseOnSoftReferences();
         jvmti.forceGC();
         Class clazz = jvmti.getClassByName(className);
         if (clazz!=null)
         {
            jvmti.heapSnapshot("snapshot", "mem");
            clazz=null;
           
            String report =jvmti.exploreClassReferences(className, 10, true, false, false, false, false);
           
            //System.out.println(report);
            File outputfile = new File("./leaks-report.html");
            FileOutputStream outfile = new FileOutputStream(outputfile);
            PrintStream realoutput = new PrintStream(outfile);
            realoutput.println(report);
            realoutput.close();
           
           
            jvmti.forceGC();
           
            clazz = jvmti.getClassByName(className);
           
            if (clazz==null)
            {
                System.out.println("Attention: After clearing every field on AspectManager, GC could release the classLoader");
            }
View Full Code Here

Examples of org.jboss.profiler.jvmti.JVMTIInterface

  
  
   private void clearEverySingleFieldOnInstances(String className)
   {
      System.out.println("Clearing " + className);
      JVMTIInterface jvmti = new JVMTIInterface();
      Class classes[] = jvmti.getLoadedClasses();
      Object objects[] = null;
     
      for (int i=0;i<classes.length;i++)
      {
         if (classes[i].getName().equals(className))
         {
            Field fields[] = getDeclaredFields(classes[i]);
            objects = jvmti.getAllObjects(classes[i]);
            for (int j=0;j<objects.length;j++)
            {
               resetObject(objects[j], fields);
            }
            if (objects.length==0)
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.