Update of /cvsroot/javaprofiler/jpiimpl/net/sourceforge/javaprofiler/jpiimpl/realtime In directory usw-pr-cvs1:/tmp/cvs-serv12442/realtime Added Files: AllocTraceR.java AllocTypeMethodR.java AllocTypeR.java AllocTypeThreadR.java AllocTypeTraceR.java CPUTraceR.java ClassR.java DataR.java FieldR.java FrameR.java ImageR.java Location.java MethodR.java MonTraceR.java ThreadGroupR.java ThreadR.java Log Message: First version of realtime. Not yet complete. --- NEW FILE: AllocTraceR.java --- /* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"); you may not use this file except * in compliance with the License. A copy of the License is available * at http://www.sun.com/ * * The Original Code is the Java Profiler module. The Initial Developers * of the Original Code are Jan Stola, Pavel Vacha, Michal Pise, Petr Luner, * Lukas Petru and Marek Przeczek. * * Portions created by Jan Stola are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Pavel Vacha are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Michal Pise are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Petr Luner are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Lukas Petru are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Marek Przeczek are Copyright (C) 2000-2001. * All Rights Reserved. * * Contributors: Jan Stola, Pavel Vacha, Michal Pise, Petr Luner, * Lukas Petru and Marek Przeczek. */ package net.sourceforge.javaprofiler.jpiimpl.realtime; import java.util.*; import net.sourceforge.javaprofiler.api.*; import net.sourceforge.javaprofiler.api.Class; import net.sourceforge.javaprofiler.api.ThreadGroup; import net.sourceforge.javaprofiler.jpiimpl.commun.IProf; import net.sourceforge.javaprofiler.jpiimpl.commun.IProfException; /** Implementation of API AllocTrace * @author Lukas Petru */ public class AllocTraceR extends Location implements AllocTrace { /** Tells if any data was loaded from profiled VM about this Type. */ private boolean isReady; /** VM Image that constructed this object. */ private ImageR image; /** Object identification. */ private Integer objId; // all Lists should be synchronized for implementation be thread-safe // private data accessible via getter methods private final List frames=new ArrayList(0); private final List roFrames=Collections.unmodifiableList(frames); // memory info private long numLiveInstances; private long numTotalInstances; private long sizeLiveInstances; private long sizeTotalInstances; // lists for children private final List allocTypeTraces=new ArrayList(0); // unmodifiable variants of lists for children private final List roAllocTypeTraces=Collections.unmodifiableList( allocTypeTraces); /** Constructs new object with info. * @param sid Object with data from communication layer. * @param RtImage <code>VirtualMachineImage</code> object to which this * object shall belong */ AllocTraceR(IProf.sID sid, ImageR RtImage) { image = RtImage; objId = new Integer(sid.objId); construct((IProf.sTraceInfo) sid.info); } /** Creates object with only Id and no info / data. * @param oId Identification of object as assigned by communication layer. * @param RtImage <code>VirtualMachineImage</code> object to which this * object shall belong */ AllocTraceR(Integer oId, ImageR RtImage) { objId = oId; image = RtImage; } // info getter methods public List getFrames() { needConstructed(); return roFrames; } public Method getParentMethod() { needConstructed(); return ((Frame) frames.get(0)).getMethod(); } // children lists getter methods public List getAllocThreadTraces() { return Collections.EMPTY_LIST; } public void refreshAllocTypeTraces() { image.extractMultiRoot(this, IProf.ALLOC_TRACE_OBJECTS, image.allocTypeTraceFactory); } public List getAllocTypeTraces() { if ( image.getAlwaysRefresh() ) refreshAllocTypeTraces(); return roAllocTypeTraces; } // image getter method public VirtualMachineImage getVirtualMachineImage() { return image; } public VirtualMachineImage getParentVirtualMachineImage() { return image; } // statistics getter methods public long getNumOfLiveInstances() { conditionalRefresh(); return numLiveInstances; } public long getTotalNumOfInstances() { conditionalRefresh(); return numTotalInstances; } public long getSizeOfLiveInstances() { conditionalRefresh(); return sizeLiveInstances; } public long getTotalSizeOfInstances() { conditionalRefresh(); return sizeTotalInstances; } // refresh /** Refreshes statistics. */ public void refresh() { // method should synchronize on image to be thread-safe IProf.sData data; try { data = image.getIProf().getData(objId.intValue(), IProf.ALLOC_DATA); } catch (IProfException e) { throw new RuntimeException(e); } setData((IProf.sAllocStatData) data.statData); } // package / private void addAllocTypeTrace(AllocTypeTrace o) { allocTypeTraces.add(o); } // roots /** Returns AllocType root of multi-rooted object. Returns <code>null * </code> if this root is N / A. */ public AllocTypeR getAllocType() { return null; } /** Returns Thread root of multi-rooted object. Returns <code>null * </code> if this root is N / A. */ public ThreadR getThread() { return null; } /** Returns Location root of multi-rooted object. Returns <code>null * </code> if this root is N / A. */ public Location getLocation() { return this; } /** Finishes object construction with info gained from profiled VM. * @param sid Object info. */ void construct(IProf.sID sid) { // method should be synchronized to be thread-safe (because of // isReady) if (!isReady) construct((IProf.sTraceInfo) sid.info); } /** Finishes object construction. * @param info <code>sTraceInfo</code> object with data from * communication layer. */ private void construct (IProf.sTraceInfo info) { Frame caller=null; int i; for (i=info.numFrames-1; i>=0; i--) { caller=new FrameR(info.frames[i], caller, image); frames.add(caller); } isReady = true; ((MethodR) getParentMethod()).addAllocTrace(this); } /** Tests if object needs to load its info and does, if so. */ private void needConstructed() { // method should be synchronized to be thread-safe (because of // isReady) if (!isReady) { IProf.sTraceInfo info; try { info = (IProf.sTraceInfo) image.getIProf(). getInfo(objId.intValue(), IProf.TRACE_INFO); } catch (IProfException e) { throw new RuntimeException(e); } construct(info); } } /** Determines whether refresh should be done and does, if so. */ private void conditionalRefresh() { if (image.getAlwaysRefresh()) refresh(); } /** Fills object with data gained from profiled VM. * @param data Data. */ void setData(IProf.sAllocStatData allocData) { numLiveInstances=allocData.allocNumInstancesLive; numTotalInstances=allocData.allocNumInstancesTotal; sizeLiveInstances=allocData.allocSizeInstancesLive; sizeTotalInstances=allocData.allocSizeInstancesTotal; } /** Fills object with data gained from profiled VM. * @param sid Object info and data. */ void setData(IProf.sID sid) { setData(sid.alloc); } /** Returns number that identifies object for profiler library. */ Integer getId() { return objId; } public String toString() { return "trace of " + getParentMethod(); } } --- NEW FILE: AllocTypeMethodR.java --- /* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"); you may not use this file except * in compliance with the License. A copy of the License is available * at http://www.sun.com/ * * The Original Code is the Java Profiler module. The Initial Developers * of the Original Code are Jan Stola, Pavel Vacha, Michal Pise, Petr Luner, * Lukas Petru and Marek Przeczek. * * Portions created by Jan Stola are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Pavel Vacha are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Michal Pise are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Petr Luner are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Lukas Petru are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Marek Przeczek are Copyright (C) 2000-2001. * All Rights Reserved. * * Contributors: Jan Stola, Pavel Vacha, Michal Pise, Petr Luner, * Lukas Petru and Marek Przeczek. */ package net.sourceforge.javaprofiler.jpiimpl.realtime; import java.util.*; import net.sourceforge.javaprofiler.api.*; import net.sourceforge.javaprofiler.api.Class; import net.sourceforge.javaprofiler.jpiimpl.commun.IProf; import net.sourceforge.javaprofiler.jpiimpl.commun.IProfException; /** Implementation of API AllocTypeMethod * @author Lukas Petru */ public class AllocTypeMethodR extends DataR implements AllocTypeMethod { /** Tells if any data was loaded from profiled VM about this Type. */ private boolean isReady; /** VM Image that constructed this object. */ private ImageR image; /** Object identification. */ private final Integer objId; // roots to which this object is linked private AllocTypeR type; private MethodR location; // memory info private long numLiveInstances; private long numTotalInstances; private long sizeLiveInstances; private long sizeTotalInstances; // lists for children private final List allocTypeTraces=new ArrayList(0); // unmodifiable variants of lists for children private final List roAllocTypeTraces=Collections.unmodifiableList( allocTypeTraces); /** Constructs multi-rooted object * @param typeId Identification of <code>AllocTypeR</code> object. Should * be null if N/A. * @param threadId Identification of <code>ThreadR</code> object. Should * be null if N/A. * @param locationId Identification of <code>Location</code> object. * Should be null if N/A. * @param sid Object with data from communication layer. * @param RtImage <code>VirtualMachineImage</code> object to which this * object shall belong */ AllocTypeMethodR(Integer typeId, Integer threadId, Integer locationId, IProf.sID sid, ImageR RtImage) { image=RtImage; objId=new Integer(sid.objId); // resolve roots type=image.resolveAllocType(typeId); location=image.resolveMethod(locationId); isReady=true; // add to parents' lists type.addAllocTypeMethod(this); location.addAllocTypeMethod(this); } /** Constructs object with only <code>ID</code>. * @param oId Object identification. * @param RtImage <code>VirtualMachineImage</code> object to which this * object shall belong */ AllocTypeMethodR(Integer oId, ImageR RtImage) { image=RtImage; objId=oId; } // ---------- return parents public AllocType getParentAllocType() { needConstructed(); return type; } public Method getParentMethod() { needConstructed(); return location; } public Method getMethod() { needConstructed(); return location; } // ---------- return roots of this object /** Returns AllocType root of multi-rooted object. Returns <code>null * </code> if this root is N / A. */ public AllocTypeR getAllocType() { needConstructed(); return type; } /** Returns Thread root of multi-rooted object. Returns <code>null * </code> if this root is N / A. */ public ThreadR getThread() { return null; } /** Returns Location root of multi-rooted object. Returns <code>null * </code> if this root is N / A. */ public Location getLocation() { needConstructed(); return location; } // ---------- return child Lists public void refreshAllocTypeTraces() { image.extractMultiRoot(this, IProf.ALLOC_OBJECT_METHOD_TRACES, image.allocTypeTraceFactory); } public List getAllocTypeTraces() { if ( image.getAlwaysRefresh() ) refreshAllocTypeTraces(); return roAllocTypeTraces; } public List getAllocTypeThreadMethods() { //PENDING return Collections.EMPTY_LIST; } // ---------- profiler statistic public long getNumOfLiveInstances() { conditionalRefresh(); return numLiveInstances; } public long getTotalNumOfInstances() { conditionalRefresh(); return numTotalInstances; } public long getSizeOfLiveInstances() { conditionalRefresh(); return sizeLiveInstances; } public long getTotalSizeOfInstances() { conditionalRefresh(); return sizeTotalInstances; } // ---------- refresh /** Refreshes statistics. */ public void refresh() { IProf.sData data; try { data = image.getIProf().getData(objId.intValue(), IProf.ALLOC_DATA); } catch (IProfException e) { throw new RuntimeException(e); } setData((IProf.sAllocStatData) data.statData); } // ---------- private / package void addAllocTypeTrace(AllocTypeTrace o) { allocTypeTraces.add(o); } /** Determines whether refresh should be done and does, if so. */ private void conditionalRefresh() { if (image.getAlwaysRefresh()) refresh(); } private void needConstructed() { if (!isReady) { IProf.sParents parents; try { parents=image.getIProf().getParents(objId.intValue()); } catch (IProfException e) { throw new RuntimeException(e); } // resolve roots type=image.resolveAllocType(new Integer(parents.parentUpObjId)); location=image.resolveMethod(new Integer(parents.parentLeftObjId)); isReady=true; // add to parents' lists type.addAllocTypeMethod(this); location.addAllocTypeMethod(this); } } /** Finishes object construction with info gained from profiled VM. * @param sid Object info. */ void construct(IProf.sID sid) { // not yet determined, how to use this method } /** Fills object with data gained from profiled VM. * @param data Data. */ void setData(IProf.sAllocStatData allocData) { numLiveInstances=allocData.allocNumInstancesLive; numTotalInstances=allocData.allocNumInstancesTotal; sizeLiveInstances=allocData.allocSizeInstancesLive; sizeTotalInstances=allocData.allocSizeInstancesTotal; } /** Fills object with data gained from profiled VM. * @param sid Object info and data. */ void setData(IProf.sID sid) { setData(sid.alloc); } /** Returns number that identifies object for profiler library. */ Integer getId() { return objId; } public String toString() { return getAllocType() + "-" + getLocation(); } } --- NEW FILE: AllocTypeR.java --- /* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"); you may not use this file except * in compliance with the License. A copy of the License is available * at http://www.sun.com/ * * The Original Code is the Java Profiler module. The Initial Developers * of the Original Code are Jan Stola, Pavel Vacha, Michal Pise, Petr Luner, * Lukas Petru and Marek Przeczek. * * Portions created by Jan Stola are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Pavel Vacha are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Michal Pise are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Petr Luner are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Lukas Petru are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Marek Przeczek are Copyright (C) 2000-2001. * All Rights Reserved. * * Contributors: Jan Stola, Pavel Vacha, Michal Pise, Petr Luner, * Lukas Petru and Marek Przeczek. */ package net.sourceforge.javaprofiler.jpiimpl.realtime; import java.util.*; import net.sourceforge.javaprofiler.api.*; import net.sourceforge.javaprofiler.api.Class; import net.sourceforge.javaprofiler.api.ThreadGroup; import net.sourceforge.javaprofiler.jpiimpl.commun.IProf; import net.sourceforge.javaprofiler.jpiimpl.commun.IProfException; /** Implementation of API AllocType * @author Lukas Petru */ public class AllocTypeR extends DataR implements AllocType { /** Tells if any data was loaded from profiled VM about this Type. */ private boolean isReady; /** VM Image that constructed this object. */ private ImageR image; /** Object identification. */ private Integer objId; // private data accessible via getter methods private String name; private boolean isArray; private boolean isPrimitiveArray; private ClassR componentClass; // memory info private long numLiveInstances; private long numTotalInstances; private long sizeLiveInstances; private long sizeTotalInstances; // lists for children private final List allocTypeMethods=new ArrayList(0); private final List allocTypeTraces=new ArrayList(0); private final List allocTypeThreads=new ArrayList(0); // unmodifiable variants of lists for children private final List roAllocTypeMethods=Collections.unmodifiableList( allocTypeMethods); private final List roAllocTypeTraces=Collections.unmodifiableList( allocTypeTraces); private final List roAllocTypeThreads=Collections.unmodifiableList( allocTypeThreads); /** This constructor will find it's component class on its own through * RtImage. * @param sid Object with data from communication layer. * @param RtImage <code>VirtualMachineImage</code> object to which this * object shall belong */ AllocTypeR(IProf.sID sid, ImageR RtImage) { image = RtImage; objId = new Integer(sid.objId); construct((IProf.sObjectInfo) sid.info); } /** Creates object with only Id and no data. * @param oId Identification of object as assigned by communication layer. * @param RtImage <code>VirtualMachineImage</code> object to which this * object shall belong */ AllocTypeR(Integer oId, ImageR RtImage) { objId = oId; image = RtImage; } // info getter methods /** Returns name of a type. */ public String getName() { needConstructed(); return name; } /** Returns component class of this type. */ public Class getComponentClass() { needConstructed(); return componentClass; } /** Returns true, if this type is an array. */ public boolean isArray() { needConstructed(); return isArray; } /** Returns true, if this type is an array of primitive component type. */ public boolean isArrayOfPrimitives() { needConstructed(); return isPrimitiveArray; } // children lists getter methods public void refreshAllocTypeTraces() { if (! image.getAlwaysRefresh()) refreshAllocTypeMethods(); Iterator it=getAllocTypeMethods().iterator(); while (it.hasNext()) { AllocTypeMethodR o=(AllocTypeMethodR) it.next(); o.refreshAllocTypeTraces(); } } public List getAllocTypeTraces() { if ( image.getAlwaysRefresh() ) refreshAllocTypeTraces(); return roAllocTypeTraces; } public void refreshAllocTypeMethods() { image.extractMultiRoot(this, IProf.ALLOC_OBJECT_METHODS, image.allocTypeMethodFactory); } public List getAllocTypeMethods() { if ( image.getAlwaysRefresh() ) refreshAllocTypeMethods(); return roAllocTypeMethods; } public void refreshAllocTypeThreads() { image.extractMultiRoot(this, IProf.ALLOC_OBJECT_THREADS, image.allocTypeThreadFactory); } public List getAllocTypeThreads() { if ( image.getAlwaysRefresh() ) refreshAllocTypeThreads(); return roAllocTypeThreads; } // image getter method public VirtualMachineImage getVirtualMachineImage () { return image; } public VirtualMachineImage getParentVirtualMachineImage () { return image; } // statistics getter methods public long getNumOfLiveInstances() { conditionalRefresh(); return numLiveInstances; } public long getTotalNumOfInstances() { conditionalRefresh(); return numTotalInstances; } public long getSizeOfLiveInstances() { conditionalRefresh(); return sizeLiveInstances; } public long getTotalSizeOfInstances() { conditionalRefresh(); return sizeTotalInstances; } // refresh /** Refreshes statistics. */ public void refresh() { // method should synchronize on image to be thread-safe IProf.sData data; try { data = image.getIProf().getData(objId.intValue(), IProf.ALLOC_DATA); } catch (IProfException e) { throw new RuntimeException(e); } setData((IProf.sAllocStatData) data.statData); } // roots public AllocTypeR getAllocType() { return this; } public ThreadR getThread() { return null; } public Location getLocation() { return null; } // private / package void addAllocTypeMethod(AllocTypeMethod o) { allocTypeMethods.add(o); } void addAllocTypeTrace(AllocTypeTrace o) { allocTypeTraces.add(o); } void addAllocTypeThread(AllocTypeThread o) { allocTypeThreads.add(o); } /** Finishes object construction with info gained from profiled VM. * @param sid Object info. */ void construct(IProf.sID sid) { // method should be synchronized to be thread-safe (because of // isReady) if (!isReady) construct((IProf.sObjectInfo) sid.info); } /** Finishes object construction. * @param info <code>sObjectInfo</code> object with data from communication layer. * @param component <code>Class</code> object to which this objects links. */ private void construct (IProf.sObjectInfo info, ClassR component) { isArray = true; isPrimitiveArray = component == null; componentClass = component; switch (info.isArray) { case IProf.JVMPI_NORMAL_OBJECT: name = component.getName(); isArray = false; break; case IProf.JVMPI_CLASS: name = component.getName() + "[]"; break; case IProf.JVMPI_BOOLEAN: name = "boolean[]"; //[Z break; case IProf.JVMPI_BYTE: name = "byte[]"; //[B break; case IProf.JVMPI_CHAR: name = "char[]"; //[C break; case IProf.JVMPI_SHORT: name = "short[]"; //[S break; case IProf.JVMPI_INT: name = "int[]"; //[I break; case IProf.JVMPI_LONG: name = "long[]";//[J break; case IProf.JVMPI_FLOAT: name = "float[]"; //[F break; case IProf.JVMPI_DOUBLE: name = "double[]"; //[D break; default: name = ""; } isReady = true; } /** Finishes Type object construction. This method will find component * class of object on its own through image. * @param info <code>sObjectInfo</code> object with data from * communication layer. */ private void construct(IProf.sObjectInfo info) { // resolve component class ClassR component; Integer clId = new Integer(info.classObjId); if (clId.intValue() != 0) component = image.resolveClass(clId); else component = null; construct(info, component); } /** Tests if object needs to load its info and does, if so. */ private void needConstructed() { // method should be synchronized to be thread-safe (because of // isReady) if (!isReady) { IProf.sObjectInfo info; try { info = (IProf.sObjectInfo) image.getIProf(). getInfo(objId.intValue(), IProf.OBJECT_INFO); } catch (IProfException e) { throw new RuntimeException(e); } construct(info); } } /** Determines whether refresh should be done and does, if so. */ private void conditionalRefresh() { if (image.getAlwaysRefresh()) refresh(); } /** Fills object with data gained from profiled VM. * @param data Data. */ void setData(IProf.sAllocStatData allocData) { numLiveInstances=allocData.allocNumInstancesLive; numTotalInstances=allocData.allocNumInstancesTotal; sizeLiveInstances=allocData.allocSizeInstancesLive; sizeTotalInstances=allocData.allocSizeInstancesTotal; } /** Fills object with data gained from profiled VM. * @param sid Object info and data. */ void setData(IProf.sID sid) { setData(sid.alloc); } /** Returns number that identifies object for profiler library. */ Integer getId() { return objId; } public String toString () { return getName(); } } --- NEW FILE: AllocTypeThreadR.java --- /* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"); you may not use this file except * in compliance with the License. A copy of the License is available * at http://www.sun.com/ * * The Original Code is the Java Profiler module. The Initial Developers * of the Original Code are Jan Stola, Pavel Vacha, Michal Pise, Petr Luner, * Lukas Petru and Marek Przeczek. * * Portions created by Jan Stola are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Pavel Vacha are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Michal Pise are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Petr Luner are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Lukas Petru are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Marek Przeczek are Copyright (C) 2000-2001. * All Rights Reserved. * * Contributors: Jan Stola, Pavel Vacha, Michal Pise, Petr Luner, * Lukas Petru and Marek Przeczek. */ package net.sourceforge.javaprofiler.jpiimpl.realtime; import java.util.*; import net.sourceforge.javaprofiler.api.*; import net.sourceforge.javaprofiler.api.Class; import net.sourceforge.javaprofiler.api.Thread; import net.sourceforge.javaprofiler.api.ThreadGroup; import net.sourceforge.javaprofiler.jpiimpl.commun.IProf; import net.sourceforge.javaprofiler.jpiimpl.commun.IProfException; /** Implementation of API AllocTypeThread * @author Lukas Petru */ public class AllocTypeThreadR extends DataR implements AllocTypeThread { /** Tells if any data was loaded from profiled VM about this Type. */ private boolean isReady; /** VM Image that constructed this object. */ private ImageR image; /** Object identification. */ private final Integer objId; // roots to which this object is linked private AllocTypeR type; private ThreadR thread; // memory info private long numLiveInstances; private long numTotalInstances; private long sizeLiveInstances; private long sizeTotalInstances; // lists for children private final List allocTypeThreadMethods=new ArrayList(0); private final List allocTypeThreadTraces=new ArrayList(0); // unmodifiable variants of lists for children private final List roAllocTypeThreadMethods=Collections.unmodifiableList( allocTypeThreadMethods); private final List roAllocTypeThreadTraces=Collections.unmodifiableList( allocTypeThreadTraces); /** Constructs multi-rooted object * @param typeId Identification of <code>AllocTypeR</code> object. Should * be null if N/A. * @param threadId Identification of <code>ThreadR</code> object. Should * be null if N/A. * @param locationId Identification of <code>Location</code> object. * Should be null if N/A. * @param sid Object with data from communication layer. * @param RtImage <code>VirtualMachineImage</code> object to which this * object shall belong */ AllocTypeThreadR(Integer typeId, Integer threadId, Integer locationId, IProf.sID sid, ImageR RtImage) { image=RtImage; objId=new Integer(sid.objId); // resolve roots type=image.resolveAllocType(typeId); thread=image.resolveThread(threadId); isReady=true; // add to parents' lists type.addAllocTypeThread(this); thread.addAllocTypeThread(this); } /** Constructs object with only <code>ID</code>. * @param oId Object identification. * @param RtImage <code>VirtualMachineImage</code> object to which this * object shall belong */ AllocTypeThreadR(Integer oId, ImageR RtImage) { image=RtImage; objId=oId; } // ---------- return parents public AllocType getParentAllocType() { needConstructed(); return type; } public Thread getParentThread() { needConstructed(); return thread; } // ---------- return roots of this object /** Returns AllocType root of multi-rooted object. Returns <code>null * </code> if this root is N / A. */ public AllocTypeR getAllocType() { needConstructed(); return type; } /** Returns Thread root of multi-rooted object. Returns <code>null * </code> if this root is N / A. */ public ThreadR getThread() { needConstructed(); return thread; } /** Returns Location root of multi-rooted object. Returns <code>null * </code> if this root is N / A. */ public Location getLocation() { needConstructed(); return null; } // ---------- return child Lists public void refreshAllocTypeThreadMethods() { //PENDING } public List getAllocTypeThreadMethods() { if ( image.getAlwaysRefresh() ) refreshAllocTypeThreadMethods(); return roAllocTypeThreadMethods; } public void refreshAllocTypeThreadTraces() { //PENDING } public List getAllocTypeThreadTraces() { if ( image.getAlwaysRefresh() ) refreshAllocTypeThreadTraces(); return roAllocTypeThreadTraces; } // ---------- profiler statistic public long getNumOfLiveInstances() { conditionalRefresh(); return numLiveInstances; } public long getTotalNumOfInstances() { conditionalRefresh(); return numTotalInstances; } public long getSizeOfLiveInstances() { conditionalRefresh(); return sizeLiveInstances; } public long getTotalSizeOfInstances() { conditionalRefresh(); return sizeTotalInstances; } // ---------- refresh /** Refreshes statistics. */ public void refresh() { IProf.sData data; try { data = image.getIProf().getData(objId.intValue(), IProf.ALLOC_DATA); } catch (IProfException e) { throw new RuntimeException(e); } setData((IProf.sAllocStatData) data.statData); } // ---------- private / package void addAllocTypeThreadMethod (AllocTypeThreadMethod o) { allocTypeThreadMethods.add(o); } void addAllocTypeThreadTrace(AllocTypeThreadTrace o) { allocTypeThreadTraces.add(o); } /** Determines whether refresh should be done and does, if so. */ private void conditionalRefresh() { if (image.getAlwaysRefresh()) refresh(); } private void needConstructed() { if (!isReady) { IProf.sParents parents; try { parents=image.getIProf().getParents(objId.intValue()); } catch (IProfException e) { throw new RuntimeException(e); } // resolve roots type=image.resolveAllocType(new Integer(parents.parentLeftObjId)); thread=image.resolveThread(new Integer(parents.parentUpObjId)); isReady=true; // add to parents' lists type.addAllocTypeThread(this); thread.addAllocTypeThread(this); } } /** Finishes object construction with info gained from profiled VM. * @param sid Object info. */ void construct(IProf.sID sid) { // not yet determined, how to use this method } /** Fills object with data gained from profiled VM. * @param data Data. */ void setData(IProf.sAllocStatData allocData) { numLiveInstances=allocData.allocNumInstancesLive; numTotalInstances=allocData.allocNumInstancesTotal; sizeLiveInstances=allocData.allocSizeInstancesLive; sizeTotalInstances=allocData.allocSizeInstancesTotal; } /** Fills object with data gained from profiled VM. * @param sid Object info and data. */ void setData(IProf.sID sid) { setData(sid.alloc); } /** Returns number that identifies object for profiler library. */ Integer getId() { return objId; } public String toString() { return getAllocType() + "-" + getThread(); } } --- NEW FILE: AllocTypeTraceR.java --- /* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"); you may not use this file except * in compliance with the License. A copy of the License is available * at http://www.sun.com/ * * The Original Code is the Java Profiler module. The Initial Developers * of the Original Code are Jan Stola, Pavel Vacha, Michal Pise, Petr Luner, * Lukas Petru and Marek Przeczek. * * Portions created by Jan Stola are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Pavel Vacha are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Michal Pise are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Petr Luner are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Lukas Petru are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Marek Przeczek are Copyright (C) 2000-2001. * All Rights Reserved. * * Contributors: Jan Stola, Pavel Vacha, Michal Pise, Petr Luner, * Lukas Petru and Marek Przeczek. */ package net.sourceforge.javaprofiler.jpiimpl.realtime; import java.util.*; import net.sourceforge.javaprofiler.api.*; import net.sourceforge.javaprofiler.api.Class; import net.sourceforge.javaprofiler.api.ThreadGroup; import net.sourceforge.javaprofiler.jpiimpl.commun.IProf; import net.sourceforge.javaprofiler.jpiimpl.commun.IProfException; /** Implementation of API AllocTypeTrace * @author Lukas Petru */ public class AllocTypeTraceR extends DataR implements AllocTypeTrace { /** Tells if any data was loaded from profiled VM about this Type. */ private boolean isReady; /** VM Image that constructed this object. */ private ImageR image; /** Object identification. */ private Integer objId; // roots to which this object is linked private AllocTypeR type; private AllocTraceR location; // parents private AllocTypeMethodR method; // memory info private long numLiveInstances; private long numTotalInstances; private long sizeLiveInstances; private long sizeTotalInstances; /** Constructs multi-rooted object * @param typeId Identification of <code>AllocTypeR</code> object. Should * be null if N/A. * @param threadId Identification of <code>ThreadR</code> object. Should * be null if N/A. * @param locationId Identification of <code>Location</code> object. * Should be null if N/A. * @param sid Object with data from communication layer. * @param RtImage <code>VirtualMachineImage</code> object to which this * object shall belong */ AllocTypeTraceR(Integer typeId, Integer threadId, Integer locationId, IProf.sID sid, ImageR RtImage) { image=RtImage; objId=new Integer(sid.objId); // resolve roots type=image.resolveAllocType(typeId); location=image.resolveAllocTrace(locationId); // resolve parent Integer methodId=new Integer(sid.parentUpObjId); if (image.containsId(methodId)) method=(AllocTypeMethodR) image.getObject(methodId); else { method=new AllocTypeMethodR(methodId, image); image.putObject(methodId, method); } isReady=true; // add to parents' lists type.addAllocTypeTrace(this); location.addAllocTypeTrace(this); method.addAllocTypeTrace(this); } /** Constructs object with only <code>ID</code>. * @param oId Object identification. * @param RtImage <code>VirtualMachineImage</code> object to which this * object shall belong */ AllocTypeTraceR(Integer oId, ImageR RtImage) { image=RtImage; objId=oId; } // ---------- return child Lists public List getAllocTypeThreadTraces() { //PENDING return Collections.EMPTY_LIST; } // ---------- return parents public AllocTypeMethod getParentAllocTypeMethod() { needConstructed(); return method; } public AllocType getParentAllocType() { needConstructed(); return type; } public AllocTrace getParentAllocTrace() { needConstructed(); return location; } // ---------- return roots of this object /** Returns AllocType root of multi-rooted object. Returns <code>null * </code> if this root is N / A. */ public AllocTypeR getAllocType() { needConstructed(); return type; } /** Returns Thread root of multi-rooted object. Returns <code>null * </code> if this root is N / A. */ public ThreadR getThread() { return null; } /** Returns Location root of multi-rooted object. Returns <code>null * </code> if this root is N / A. */ public Location getLocation() { needConstructed(); return location; } // ---------- profiler statistic public long getNumOfLiveInstances() { conditionalRefresh(); return numLiveInstances; } public long getTotalNumOfInstances() { conditionalRefresh(); return numTotalInstances; } public long getSizeOfLiveInstances() { conditionalRefresh(); return sizeLiveInstances; } public long getTotalSizeOfInstances() { conditionalRefresh(); return sizeTotalInstances; } // ---------- refresh /** Refreshes statistics. */ public void refresh() { IProf.sData data; try { data = image.getIProf().getData(objId.intValue(), IProf.ALLOC_DATA); } catch (IProfException e) { throw new RuntimeException(e); } setData((IProf.sAllocStatData) data.statData); } // ---------- private / package /** Determines whether refresh should be done and does, if so. */ private void conditionalRefresh() { if (image.getAlwaysRefresh()) refresh(); } private void needConstructed() { if (!isReady) { IProf.sParents parents; try { parents=image.getIProf().getParents(objId.intValue()); } catch (IProfException e) { throw new RuntimeException(e); } // link to parents Integer methodId=new Integer(parents.parentUpObjId); if (image.containsId(methodId)) method=(AllocTypeMethodR) image.getObject(methodId); else method=new AllocTypeMethodR(methodId, image); location=image.resolveAllocTrace(new Integer(parents. parentLeftObjId)); // get type type=method.getAllocType(); isReady=true; // add to parents' and root lists type.addAllocTypeTrace(this); location.addAllocTypeTrace(this); method.addAllocTypeTrace(this); } } /** Finishes object construction with info gained from profiled VM. * @param sid Object info. */ void construct(IProf.sID sid) { // not yet determined, how to use this method } /** Fills object with data gained from profiled VM. * @param data Data. */ void setData(IProf.sAllocStatData allocData) { numLiveInstances=allocData.allocNumInstancesLive; numTotalInstances=allocData.allocNumInstancesTotal; sizeLiveInstances=allocData.allocSizeInstancesLive; sizeTotalInstances=allocData.allocSizeInstancesTotal; } /** Fills object with data gained from profiled VM. * @param sid Object info and data. */ void setData(IProf.sID sid) { setData(sid.alloc); } /** Returns number that identifies object for profiler library. */ Integer getId() { return objId; } public String toString() { return getAllocType() + "-" + getLocation(); } } --- NEW FILE: CPUTraceR.java --- /* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"); you may not use this file except * in compliance with the License. A copy of the License is available * at http://www.sun.com/ * * The Original Code is the Java Profiler module. The Initial Developers * of the Original Code are Jan Stola, Pavel Vacha, Michal Pise, Petr Luner, * Lukas Petru and Marek Przeczek. * * Portions created by Jan Stola are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Pavel Vacha are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Michal Pise are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Petr Luner are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Lukas Petru are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Marek Przeczek are Copyright (C) 2000-2001. * All Rights Reserved. * * Contributors: Jan Stola, Pavel Vacha, Michal Pise, Petr Luner, * Lukas Petru and Marek Przeczek. */ package net.sourceforge.javaprofiler.jpiimpl.realtime; import java.util.*; import net.sourceforge.javaprofiler.api.*; import net.sourceforge.javaprofiler.api.Class; import net.sourceforge.javaprofiler.jpiimpl.commun.IProf; import net.sourceforge.javaprofiler.jpiimpl.commun.IProfException; /** Implementation of API CPUTrace * @author Lukas Petru */ public class CPUTraceR extends Location implements CPUTrace { /** Tells if any data was loaded from profiled VM about this Type. */ private boolean isReady; /** VM Image that constructed this object. */ private ImageR image; /** Object identification. */ private Integer objId; // all Lists should be synchronized for implementation be thread-safe // private data accessible via getter methods private final List frames=new ArrayList(0); private final List roFrames=Collections.unmodifiableList(frames); // CPU info private long hits; private long pureTime; // lists for children // unmodifiable variants of lists for children /** Constructs new object with info. * @param sid Object with data from communication layer. * @param RtImage <code>VirtualMachineImage</code> object to which this * object shall belong */ CPUTraceR(IProf.sID sid, ImageR RtImage) { image = RtImage; objId = new Integer(sid.objId); construct((IProf.sTraceInfo) sid.info); } /** Creates object with only Id and no info / data. * @param oId Identification of object as assigned by communication layer. * @param RtImage <code>VirtualMachineImage</code> object to which this * object shall belong */ CPUTraceR(Integer oId, ImageR RtImage) { objId = oId; image = RtImage; } // info getter methods public List getFrames() { needConstructed(); return roFrames; } public Method getParentMethod() { needConstructed(); return ((Frame) frames.get(0)).getMethod(); } // children lists getter methods public void refreshCPUThreadTraces() { } public List getCPUThreadTraces() { //PENDING return Collections.EMPTY_LIST; } // image getter method public VirtualMachineImage getVirtualMachineImage() { return image; } public VirtualMachineImage getParentVirtualMachineImage() { return image; } // statistics getter methods public long getNumOfHits() { conditionalRefresh(); return hits; } public long getPureTime() { conditionalRefresh(); return pureTime; } // refresh /** Refreshes statistics. */ public void refresh() { IProf.sData data; try { data = image.getIProf().getData(objId.intValue(), IProf.CPU_DATA); } catch (IProfException e) { throw new RuntimeException(e); } setData((IProf.sCpuStatData) data.statData); } // roots /** Returns AllocType root of multi-rooted object. Returns <code>null * </code> if this root is N / A. */ public AllocTypeR getAllocType() { return null; } /** Returns Thread root of multi-rooted object. Returns <code>null * </code> if this root is N / A. */ public ThreadR getThread() { return null; } /** Returns Location root of multi-rooted object. Returns <code>null * </code> if this root is N / A. */ public Location getLocation() { return this; } // package / private /** Finishes object construction with info gained from profiled VM. * @param sid Object info. */ void construct(IProf.sID sid) { if (!isReady) construct((IProf.sTraceInfo) sid.info); } /** Finishes object construction. * @param info <code>sTraceInfo</code> object with data from * communication layer. */ private void construct (IProf.sTraceInfo info) { Frame caller=null; int i; for (i=info.numFrames-1; i>=0; i--) { caller=new FrameR(info.frames[i], caller, image); frames.add(caller); } isReady = true; ((MethodR) getParentMethod()).addCPUTrace(this); } private void needConstructed() { // lazy object data acquirement if (!isReady) { IProf.sTraceInfo info; try { info = (IProf.sTraceInfo) image.getIProf(). getInfo(objId.intValue(), IProf.TRACE_INFO); } catch (IProfException e) { throw new RuntimeException(e); } construct(info); } } /** Determines whether refresh should be done and does, if so. */ private void conditionalRefresh() { if (image.getAlwaysRefresh()) refresh(); } /** Fills object with data gained from profiled VM. * @param data Data. */ void setData(IProf.sCpuStatData cpuData) { hits=cpuData.hits; pureTime=cpuData.pureTime; } /** Fills object with data gained from profiled VM. * @param sid Object info and data. */ void setData(IProf.sID sid) { setData(sid.cpu); } /** Returns number that identifies object for profiler library. */ Integer getId() { return objId; } public String toString() { return "trace of " + getParentMethod(); } } --- NEW FILE: ClassR.java --- /* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"); you may not use this file except * in compliance with the License. A copy of the License is available * at http://www.sun.com/ * * The Original Code is the Java Profiler module. The Initial Developers * of the Original Code are Jan Stola, Pavel Vacha, Michal Pise, Petr Luner, * Lukas Petru and Marek Przeczek. * * Portions created by Jan Stola are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Pavel Vacha are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Michal Pise are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Petr Luner are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Lukas Petru are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Marek Przeczek are Copyright (C) 2000-2001. * All Rights Reserved. * * Contributors: Jan Stola, Pavel Vacha, Michal Pise, Petr Luner, * Lukas Petru and Marek Przeczek. */ package net.sourceforge.javaprofiler.jpiimpl.realtime; import java.util.*; import net.sourceforge.javaprofiler.api.*; import net.sourceforge.javaprofiler.api.Class; import net.sourceforge.javaprofiler.jpiimpl.commun.IProf; import net.sourceforge.javaprofiler.jpiimpl.commun.IProfException; /** Implementation of API Class * @author Lukas Petru */ public class ClassR extends DataR implements Class { /** Tells if any data was loaded from profiled VM about this object. */ private boolean isReady; /** VM Image that constructed this object. */ private ImageR image; /** Object identification. */ private final Integer objId; private String name; private String sourceFilename; private int instanceSize; private List fields; private List roFields; // all Lists should be synchronized for implementation be thread-safe // memory info private long numLiveInstances; private long numTotalInstances; private long sizeLiveInstances; private long sizeTotalInstances; // lists for children private final List methods=new ArrayList(0); // unmodifiable variants of lists for children private final List roMethods=Collections.unmodifiableList( methods); /** Creates object with info. * @param sid Object with data from communication layer. * @param RtImage Object that manages this realtime set. */ ClassR(IProf.sID sid, ImageR RtImage) { image=RtImage; objId=new Integer(sid.objId); construct((IProf.sClassInfo) sid.info); } /** Creates object with only Id, no info and no data. * @param oId Identification of object as assigned by communication layer. * @param RtImage Object that manages this realtime set. */ ClassR(Integer oId, ImageR RtImage) { objId=oId; image=RtImage; } // info getter methods public String getName() { needConstructed(); return name; } public String getSourceFileName() { needConstructed(); return sourceFilename; } public int getInstanceSize() { needConstructed(); return instanceSize; } /** Returns list of <code>Field</code>. */ public List getFields() { needConstructed(); return roFields; } // children lists getter methods public void refreshMethods() { image.extractChildRoot(this.objId, IProf.CLASS_METHODS, image. methodFactory); } public List getMethods() { if ( image.getAlwaysRefresh() ) refreshMethods(); return roMethods; } // image getter method public VirtualMachineImage getVirtualMachineImage() { return image; } // statistics getter methods public long getNumOfLiveInstances() { conditionalRefresh(); return numLiveInstances; } public long getTotalNumOfInstances() { conditionalRefresh(); return numTotalInstances; } public long getSizeOfLiveInstances() { conditionalRefresh(); return sizeLiveInstances; } public long getTotalSizeOfInstances() { conditionalRefresh(); return sizeTotalInstances; } // refresh /** Refreshes statistics. */ public void refresh() { // no data from IProf } // roots /** Returns AllocType root of multi-rooted object. Returns <code>null * </code> if this root is N / A. */ public AllocTypeR getAllocType() { return null; } /** Returns Thread root of multi-rooted object. Returns <code>null * </code> if this root is N / A. */ public ThreadR getThread() { return null; } /** Returns Location root of multi-rooted object. Returns <code>null * </code> if this root is N / A. */ public Location getLocation() { return null; } // package / private void addMethod(Method o) { methods.add(o); // PENDING event } /** Finishes object construction with info gained from profiled VM. * @param sid Object info. */ void construct(IProf.sID sid) { if (!isReady) construct((IProf.sClassInfo) sid.info); } /** Finishes object construction. * @param info Object <code>sClassInfo</code> with data from * communication layer. */ private void construct(IProf.sClassInfo info) { name=info.className; sourceFilename=info.sourceName; //FIXME instanceSize=0; // fill fields list fields=new ArrayList(); roFields=Collections.unmodifiableList(fields); final int parent=objId.intValue(); Iterator itChildren; { final int direction=IProf.CLASS_FIELDS_STATICS; try { itChildren = image.getIProf().getAllThruIterator(parent, direction, true, true, IProf.NO_OPTIONAL_ARG, true); } catch (IProfException e) { throw new RuntimeException(e); } while (itChildren.hasNext()) { IProf.sID sid=(IProf.sID) itChildren.next(); fields.add(new FieldR(sid, this, true)); } } { final int direction=IProf.CLASS_FIELDS_INSTANCES; try { itChildren = image.getIProf().getAllThruIterator(parent, direction, true, true, IProf.NO_OPTIONAL_ARG, true); } catch (IProfException e) { throw new RuntimeException(e); } while (itChildren.hasNext()) { IProf.sID sid=(IProf.sID) itChildren.next(); fields.add(new FieldR(sid, this, false)); } } isReady=true; } private void needConstructed() { // lazy object data acquirement if (!isReady) { IProf.sClassInfo info; try { info = (IProf.sClassInfo) image.getIProf(). getInfo(objId.intValue(), IProf.CLASS_INFO); } catch (IProfException e) { throw new RuntimeException(e); } construct(info); } } /** Determines whether refresh should be done and does, if so. */ private void conditionalRefresh() { if (image.getAlwaysRefresh()) refresh(); } /** Fills object with data gained from profiled VM. * @param data Data. */ void setData(IProf.sAllocStatData allocData) { numLiveInstances=allocData.allocNumInstancesLive; numTotalInstances=allocData.allocNumInstancesTotal; sizeLiveInstances=allocData.allocSizeInstancesLive; sizeTotalInstances=allocData.allocSizeInstancesTotal; } /** Fills object with data gained from profiled VM. * @param sid Object info and data. */ void setData(IProf.sID sid) { // we don't get any data for Class } /** Returns number that identifies object for profiler library. */ Integer getId() { return objId; } public String toString() { return getName(); } } --- NEW FILE: DataR.java --- /* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"); you may not use this file except * in compliance with the License. A copy of the License is available * at http://www.sun.com/ * * The Original Code is the Java Profiler module. The Initial Developers * of the Original Code are Jan Stola, Pavel Vacha, Michal Pise, Petr Luner, * Lukas Petru and Marek Przeczek. * * Portions created by Jan Stola are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Pavel Vacha are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Michal Pise are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Petr Luner are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Lukas Petru are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Marek Przeczek are Copyright (C) 2000-2001. * All Rights Reserved. * * Contributors: Jan Stola, Pavel Vacha, Michal Pise, Petr Luner, * Lukas Petru and Marek Przeczek. */ package net.sourceforge.javaprofiler.jpiimpl.realtime; import net.sourceforge.... [truncated message content] |