|
From: Pavel V. <va...@us...> - 2002-09-07 19:46:48
|
Update of /cvsroot/javaprofiler/jpiimpl/net/sourceforge/javaprofiler/jpiimpl/data
In directory usw-pr-cvs1:/tmp/cvs-serv3595
Modified Files:
SnapshotImpl.java
Log Message:
implementation of difference snapshot
supports only Alloc,
includes Methods, AllocTraces
not much tested
Index: SnapshotImpl.java
===================================================================
RCS file: /cvsroot/javaprofiler/jpiimpl/net/sourceforge/javaprofiler/jpiimpl/data/SnapshotImpl.java,v
retrieving revision 1.33
retrieving revision 1.34
diff -C2 -r1.33 -r1.34
*** SnapshotImpl.java 2 Sep 2002 15:28:02 -0000 1.33
--- SnapshotImpl.java 7 Sep 2002 19:46:43 -0000 1.34
***************
*** 29,32 ****
--- 29,34 ----
import net.sourceforge.javaprofiler.jpiimpl.data.*;
+ import java.lang.reflect.*;
+
/**
***************
*** 185,196 ****
/**
! *Creates completely empty snapshot, only configuration is stored. You
! * can fill snapshot with whatever you want.
! * It's used by {@link #diffenceTo }
*
! *@param conf determines the types of object that will be included in this snapshot
*/
! private SnapshotImpl( Configuration conf ) {
! this.conf = conf;
}
//////////////////////////////////////////////////////////////////////////
--- 187,206 ----
/**
! * Creates difference snapshot, same as {@link #diffenceTo }.
*
! * @param conf determines the types of object that will be included in this snapshot
! * @param a first operand in substraction
! * @param b second operand in substraction
*/
! public SnapshotImpl( SnapshotImpl a, Snapshot b, Configuration conf ) {
! try {
! libIDs = new HashMap();
! this.conf = (Configuration) conf.clone();
! makeDiffSnapshot( conf, a, b );
! libIDs = null;
! }
! catch ( CloneNotSupportedException e ) {
! throw new RuntimeException( e.getMessage() );
! }
}
//////////////////////////////////////////////////////////////////////////
***************
*** 732,737 ****
*@see SnapshotImpl#extract()
*/
! private IDObjectData createAndPutIn( int whatType, IProf.sID sid,
! IDObjectData refObj, List postOpLst) {
switch ( whatType ) {
case IProf.CLASSES: {
--- 742,746 ----
*@see SnapshotImpl#extract()
*/
! private IDObjectData createAndPutIn(int whatType, IProf.sID sid, IDObjectData refObj, List postOpLst) {
switch ( whatType ) {
case IProf.CLASSES: {
***************
*** 1150,1154 ****
* Confiduration object also defines what infomation are significan for
* defenition of equality.
! *
*
* @param b secand operand in substraction
--- 1159,1163 ----
* Confiduration object also defines what infomation are significan for
* defenition of equality.
! * Now it supports only Alloc.
*
* @param b secand operand in substraction
***************
*** 1161,1168 ****
confA.withAlloc = true;
confA.withTypes = true;
confA.withArenas = false;
confA.withAllocThreads = false;
- confA.withAllocTraces = false;
confA.withCPU = false;
confA.withCPUThreads = false;
--- 1170,1177 ----
confA.withAlloc = true;
confA.withTypes = true;
+ confA.withAllocTraces = true;
confA.withArenas = false;
confA.withAllocThreads = false;
confA.withCPU = false;
confA.withCPUThreads = false;
***************
*** 1175,1179 ****
confA.withMonTraces = false;
! SnapshotImpl snap = new SnapshotImpl( confA );
Map objMap = new HashMap(); //mapping objects from source (this) to
// its copies in result
--- 1184,1227 ----
confA.withMonTraces = false;
! SnapshotImpl snap = new SnapshotImpl( this, b, confA );
! return snap;
! }
!
! /** Creates new snapshot that contains <code>this - B </code>
! * Difference means that result contains all objects that
! * are in <code>this</code> and are not in <code> B </code>.
! * Now it supports only Alloc.
! *
! * @param b secand operand in substraction
! */
! public Snapshot differenceTo(Snapshot b) {
! //TODO: all, now it contains only ALLOC_TYPES
! Configuration confA = new Configuration();
! confA.withAlloc = true;
! confA.withTypes = true;
! confA.withAllocTraces = true;
!
! confA.withArenas = false;
! confA.withAllocThreads = false;
! confA.withCPU = false;
! confA.withCPUThreads = false;
! confA.withCPUTraces = false;
! confA.withCallTree = false;
! confA.withFields = false;
! confA.withGC = false;
! confA.withMon = false;
! confA.withMonThreads = false;
! confA.withMonTraces = false;
!
! SnapshotImpl snap = new SnapshotImpl( this, b, confA );
! return snap;
! }
!
! /**Now it supports only Alloc.
! *
! *@see #differenceTo
! */
! private void makeDiffSnapshot( Configuration conf, Snapshot a, Snapshot b )
! {
Map objMap = new HashMap(); //mapping objects from source (this) to
// its copies in result
***************
*** 1193,1244 ****
boolean eqL;
//temporary solution //FIXME
! if ( confA.withAlloc ) {
! ListIterator it1, it2;
!
! TypeData type1;
! TypeRef type2;
! TypeData typeA;
! ClassData classA;
! ClassRef class1;
!
! it1 = this.types.listIterator();
! it2 = b.getTypes().listIterator();
! while( it1.hasNext() ) {
! type1 = (TypeData) it1.next();
while ( it2.hasNext() ) {
! type2 = (TypeRef) it2.next();
eqL = false;
//test of equality
! eqL = (type1.getLiveInstancesCount() == type2.getLiveInstancesCount());
! //creation
if ( eqL ) {
! class1 = type1.getComponentClass();
! obj = objMap.get( class1 );
! if ( obj == null ) {
! classA = new ClassData( (ClassData) class1 );
! objMap.put( class1, classA );
! snap.classes.add( classA );
! }
! else {
! classA = (ClassData) obj;
! }
! typeA = new TypeData( type1, classA, this );
! snap.types.add( typeA );
! }
}
}
!
! //reletad work TODO:
! //copy constructor to toher objects not only TypaData
! //copy stat method to CPU, MON id objects
!
}
- return snap;
}
}
//TODO:
/// write exception handling code properly
--- 1241,1526 ----
boolean eqL;
+ List sourceLst1, sourceLst2;
//temporary solution //FIXME
! if ( conf.withAlloc ) {
! List[] result;
! sourceLst1 = new ArrayList(1);
! sourceLst1.add(this);
! sourceLst2 = new ArrayList(1);
! sourceLst2.add(b);
! //sideEftect creates appropriate ClassData instasnces
! result = AddDiffOfCildrenLists( sourceLst1, sourceLst2, "getTypes" );
! sourceLst1 = result[0];
! sourceLst2 = result[1];
! //sideEffect creates appropriate MethodData instances
! //this way was choosen because of effectvity
! result = AddDiffOfCildrenLists( sourceLst1, sourceLst2, "getMethods" );
! if ( conf.withAllocTraces ) {
! sourceLst1 = result[0];
! sourceLst2 = result[1];
! //sideEffect creates appropriate AllocTraceData instances
! result = AddDiffOfCildrenLists( sourceLst1, sourceLst2, "getTraces" );
! }
! }
! }
!
! /** Takes one object from <code> sourceLst1 </code> and one from <code> sourceLst2 </code>.
! * Using java reflection and <code> getMethod </code> acquires lists of chidlren (<code> list1 </code>
! * and <code>list2 </code> and adds diffence of these lists.
! * Lists <code> sourceLst1 </code> and <code> sourceLst2 </code> MUST have same size.
! *
! *@see #AddDiffOfLists
! *@return result of <code> AddDiffOfLists </code>
! */
! private List[] AddDiffOfCildrenLists( List sourceLst1, List sourceLst2,
! String getChildrenMethod )
! {
! List[] result = new List[] { new ArrayList(), new ArrayList() };
! if ( sourceLst1.size() != sourceLst2.size() ) {
! throw new RuntimeException(" Source lits don't have same size: "
! + sourceLst1.size() + " " + sourceLst2.size() );
! }
! if ( sourceLst1.size() == 0 ) {
! return new List[] { Collections.EMPTY_LIST, Collections.EMPTY_LIST } ;
! }
!
! Class clazz = sourceLst1.get(0).getClass();
! Method callMethod;
! try {
! callMethod = clazz.getMethod( getChildrenMethod, null );
! } catch ( NoSuchMethodException e ) {
! throw new RuntimeException( "AddDiffOfCildrenLists - getMethod:" + e.toString()
! + " getChildrenMethod:" + getChildrenMethod + " Class:" + clazz.toString() );
! }
!
! ListIterator itS1, itS2;
! itS1 = sourceLst1.listIterator();
! itS2 = sourceLst2.listIterator();
! while ( itS1.hasNext() ) {
! Object S1 = itS1.next();
! Object S2 = itS2.next();
! List list1, list2;
! try {
! list1 = (List) callMethod.invoke( S1, null );
! list2 = (List) callMethod.invoke( S2, null );
! }
! catch ( IllegalAccessException e ) {
! throw new RuntimeException( "AddDiffOfCildrenLists - invoke:"
! + e.toString() + " getChildrenMethod:" + getChildrenMethod + " Class:" + clazz.toString() );
! }
! catch ( InvocationTargetException e ) {
! throw new RuntimeException( "AddDiffOfCildrenLists - invoke:"
! + e.toString() + " getChildrenMethod:" + getChildrenMethod + " Class:" + clazz.toString() );
! }
! //now I have lists to diff
! AddDiffOfLists( list1, list2, result );
! }
! return result;
! }
!
! /** Makes difference on Lists. If objects is in the first list and not in the second list
! * that copy of this object are added into <code> this </code>. Objects are treated as equal if
! * they have same <code> getLiveInstancesCount() </code>. Complexity: n*m;
! * Now it supports only Alloc.
! *
! * Appropriate not existing parent objects are created in <code> target </code>.
! * <code> result[0] </code> contains objects from <code> list1 </code>
! * <code> result[1] </code> contains objects from <code> list2 </code>
! * Equal objects that are included in <code> list1 </code> and in <code> list2 </code>
! * are added into the result.
! */
! private void AddDiffOfLists( List sourceLst1, List sourceLst2, List[] result )
! {
! boolean eqL = false;
!
! AllocStat alloc1, alloc2;
! AllocStatData allocStatA;
! ListIterator it1, it2;
! it1 = sourceLst1.listIterator();
! it2 = sourceLst2.listIterator();
! while( it1.hasNext() ) {
! alloc1 = (AllocStat) it1.next();
while ( it2.hasNext() ) {
! alloc2 = (AllocStat) it2.next();
!
eqL = false;
//test of equality
! eqL = (alloc1.getLiveInstancesCount() == alloc2.getLiveInstancesCount());
if ( eqL ) {
! result[0].add( alloc1 );
! result[1].add( alloc2 );
!
! //creation
! allocStatA = (AllocStatData) copyAndPutIn( alloc1 );
!
! //difference
! allocStatA.setAllocStat(
! alloc1.getLiveInstancesCount() - alloc2.getLiveInstancesCount(),
! alloc1.getTotalInstancesCount() - alloc2.getTotalInstancesCount(),
! alloc1.getLiveInstancesSize() - alloc2.getLiveInstancesSize(),
! alloc1.getTotalInstancesSize() - alloc2.getTotalInstancesSize()
! );
! }
}
+ }
+ }
+
+ /**
+ */
+ private Object copyAndPutIn( Object source )
+ {
+ Object obj;
+ //temporary //FIXME
+ if ( source instanceof ClassData ) {
+ ClassData class1 = (ClassData) source;
+ //------------creation
+ ClassData classA = new ClassData( class1 );
+ this.libIDs.put( class1.getID(), classA );
+ this.classes.add( classA );
+ return classA;
+ }
+
+ else if ( source instanceof TypeData ) {
+ TypeData type1 = (TypeData) source;
+ ClassData class1 = (ClassData) type1.getComponentClass();
+ ClassData classA;
+ if ( (obj = libIDs.get( class1.getID() )) == null ) {
+ classA = (ClassData) copyAndPutIn( class1 );
}
! else {
! classA = (ClassData) obj;
! }
! //------------creation
! TypeData typeA = new TypeData( type1, classA, this );
! //classA.addType( typeA );
! this.libIDs.put( type1.getID(), typeA );
! this.types.add( typeA );
! return typeA;
! }
!
! else if ( source instanceof MethodData ) {
! MethodData method1 = (MethodData) source;
! ClassData class1 = (ClassData) method1.getParentClass();
! ClassData classA;
! if ( (obj = libIDs.get( class1.getID() )) == null ) {
! classA = (ClassData) copyAndPutIn( class1 );
! }
! else {
! classA = (ClassData) obj;
! }
! //------------creation
! MethodData methodA = new MethodData( method1, classA, this );
! classA.addMethod( methodA );
! this.libIDs.put( method1.getID(), methodA );
! this.methods.add( methodA );
! return methodA;
! }
!
! else if ( source instanceof AllocTraceData ) {
! AllocTraceData allocTrace1 = (AllocTraceData) source;
! MethodData method1 = (MethodData) allocTrace1.getMethod();
! MethodData methodA;
! if ( (obj = libIDs.get( method1.getID() )) == null ) {
! methodA = (MethodData) copyAndPutIn( method1 );
! }
! else {
! methodA = (MethodData) obj;
! }
! //------------creation
! List framesA = copyFramesAndPutIn( allocTrace1.getFrames() );
! AllocTraceData allocTraceA = new AllocTraceData( allocTrace1, methodA, framesA );
! methodA.addAllocTrace( allocTraceA );
! this.libIDs.put( allocTrace1.getID(), allocTraceA );
! this.allocTraces.add( allocTraceA );
! return allocTraceA;
! }
!
! else if ( source instanceof AllocTypeMethodData ) {
! AllocTypeMethodData allocTypeMethod1 = (AllocTypeMethodData) source;
! MethodData method1 = (MethodData) allocTypeMethod1.getMethod();
! MethodData methodA;
! if ( (obj = libIDs.get( method1.getID() )) == null ) {
! methodA = (MethodData) copyAndPutIn( method1 );
! }
! else {
! methodA = (MethodData) obj;
! }
! TypeData type1 = (TypeData) allocTypeMethod1.getType();
! TypeData typeA;
! if ( (obj = libIDs.get( type1.getID() )) == null ) {
! typeA = (TypeData) copyAndPutIn( type1 );
! }
! else {
! typeA = (TypeData) obj;
! }
! //------------creation
! AllocTypeMethodData allocTypeMethodA =
! new AllocTypeMethodData( allocTypeMethod1, typeA, methodA );
! methodA.addType( allocTypeMethodA );
! typeA.addMethod( allocTypeMethodA );
! this.libIDs.put( allocTypeMethod1.getID(), allocTypeMethodA );
! return allocTypeMethodA;
! }
!
! else if ( source instanceof AllocTypeTraceData ) {
! AllocTypeTraceData allocTypeTrace1 = (AllocTypeTraceData) source;
! AllocTraceData allocTrace1 = (AllocTraceData) allocTypeTrace1.getAllocTrace();
! AllocTraceData allocTraceA;
! if ( (obj = libIDs.get( allocTrace1.getID() )) == null ) {
! allocTraceA = (AllocTraceData) copyAndPutIn( allocTrace1 );
! }
! else {
! allocTraceA = (AllocTraceData) obj;
! }
! AllocTypeMethodData allocTypeMethod1 =
! (AllocTypeMethodData) allocTypeTrace1.getAllocTypeMethod();
! AllocTypeMethodData allocTypeMethodA;
! if ( (obj = libIDs.get( allocTypeMethod1.getID() )) == null ) {
! allocTypeMethodA = (AllocTypeMethodData) copyAndPutIn( allocTypeMethod1 );
! }
! else {
! allocTypeMethodA = (AllocTypeMethodData) obj;
! }
! //------------creation
! AllocTypeTraceData allocTypeTraceA =
! new AllocTypeTraceData( allocTypeTrace1, allocTypeMethodA, allocTraceA );
! allocTraceA.addType( allocTypeTraceA );
! allocTypeMethodA.addTrace( allocTypeTraceA );
! this.libIDs.put( allocTypeTrace1.getID(), allocTypeTraceA );
! return allocTypeTraceA;
! }
! else {
! throw new RuntimeException("makeCopyAndPutIt: unknow type of object: "
! + source.getClass().toString() );
}
}
+ private List copyFramesAndPutIn( List frames ) {
+ List result = new ArrayList( frames.size() );
+
+ Object obj;
+ FrameData frame1, frameA, caller = null;
+ MethodData method1, methodA;
+ for( int i=0; i < frames.size(); i++ ) {
+ frame1 = (FrameData) frames.get(i);
+ method1 = (MethodData) frame1.getMethod();
+ if ( (obj = libIDs.get( method1.getID() )) == null ) {
+ methodA = (MethodData) copyAndPutIn( method1 );
+ }
+ else {
+ methodA = (MethodData) obj;
+ }
+ //------------creation
+ frameA = new FrameData( frame1, methodA, caller );
+ result.add( frameA );
+ caller = frameA;
+ }
+ return result;
+ }
+
}
+
//TODO:
/// write exception handling code properly
***************
*** 1250,1301 ****
/*
* $Log$
* Revision 1.33 2002/09/02 15:28:02 vachis
* difference of snapshot
* very poor ipmplementation
- *
- * Revision 1.32 2002/08/28 17:55:54 petrul
- * fixed children adding to parents' lists
- *
- * Revision 1.31 2002/08/23 18:09:58 petrul
- * reversed list of frames
- *
- * Revision 1.30 2002/08/09 00:34:26 vachis
- * fix (didn't compile)
- *
- * Revision 1.29 2002/08/08 23:28:37 vachis
- * fix CreateAndPutInt - GROUP_THREADS
- *
- * Revision 1.28 2002/07/24 22:29:22 vachis
- * implements new interfaces for getting roots and info
- *
- * Revision 1.27 2002/07/17 21:37:10 vachis
- * fixed exception handling
- *
- * Revision 1.26 2002/07/11 18:21:37 vachis
- * no message
- *
- * Revision 1.25 2002/07/04 18:00:31 stolis
- * Implements Snapshot instead of VirtualMachineImageRef.
- *
- * Revision 1.24 2002/06/11 07:08:40 vachis
- * GCData renamed
- *
- * Revision 1.23 2002/05/30 22:43:05 vachis
- * interface changed to jpi
- * children listeners added
- *
- * Revision 1.22 2002/05/14 21:33:46 vachis
- * lists of traces
- *
- * Revision 1.21 2002/05/07 21:11:38 vachis
- * fix creation of fields, frames
- * CallTree new api
- *
- * Revision 1.20 2002/05/06 17:32:13 vachis
- * new api implemention
- *
- * Revision 1.18 2002/03/13 21:08:34 vachis
- * Confuguration.withFields, Confuguration.isValid()
- * added
*
* Revision 1.1 2001/11/20 22:31:45 vachis
--- 1532,1545 ----
/*
* $Log$
+ * Revision 1.34 2002/09/07 19:46:43 vachis
+ * implementation of difference snapshot
+ * supports only Alloc,
+ * includes Methods, AllocTraces
+ *
+ * not much tested
+ *
* Revision 1.33 2002/09/02 15:28:02 vachis
* difference of snapshot
* very poor ipmplementation
*
* Revision 1.1 2001/11/20 22:31:45 vachis
|