From: Lukas P. <pe...@us...> - 2002-04-15 20:08:08
|
Update of /cvsroot/javaprofiler/jpiimpl/net/sourceforge/javaprofiler/jpiimpl/realtime In directory usw-pr-cvs1:/tmp/cvs-serv25095 Modified Files: AllocTypeMethodR.java AllocTypeThreadR.java ImageR.java MethodR.java ThreadR.java Added Files: AllocThreadMethodR.java AllocTypeThreadMethodR.java Log Message: added classes --- NEW FILE: AllocThreadMethodR.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 AllocThreadMethod * @author Lukas Petru */ public class AllocThreadMethodR extends DataR implements AllocThreadMethod { /** 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 ThreadR thread; private MethodR location; // parents // memory info private long numLiveInstances; private long numTotalInstances; private long sizeLiveInstances; private long sizeTotalInstances; // lists for children private final List allocTypeThreadMethods=new ArrayList(0); // unmodifiable variants of lists for children private final List roAllocTypeThreadMethods=Collections.unmodifiableList( allocTypeThreadMethods); /** 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 */ AllocThreadMethodR(Integer typeId, Integer threadId, Integer locationId, IProf.sID sid, ImageR RtImage) { image=RtImage; objId=new Integer(sid.objId); // resolve roots thread=image.resolveThread(threadId); location=image.resolveMethod(locationId); // resolve parents isReady=true; // add to parents' lists thread.addAllocThreadMethod(this); location.addAllocThreadMethod(this); } /** Constructs object with only <code>ID</code>. * @param oId Object identification. * @param RtImage <code>VirtualMachineImage</code> object to which this * object shall belong */ AllocThreadMethodR(Integer oId, ImageR RtImage) { image=RtImage; objId=oId; } // ---------- return child Lists public List getAllocThreadTraces() { //PENDING return Collections.EMPTY_LIST; } public void refreshAllocTypeThreadMethods() { image.extractMultiRoot(this, IProf.ALLOC_THREAD_METHOD_OBJECTS, image.allocTypeThreadMethodFactory); } public List getAllocTypeThreadMethods() { if ( image.getAlwaysRefresh() ) refreshAllocTypeThreadMethods(); return roAllocTypeThreadMethods; } // ---------- return parents public Thread getParentThread() { needConstructed(); return thread; } public Method getParentMethod() { 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() { return null; } /** 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 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 void addAllocTypeThreadMethod(AllocTypeThreadMethod o) { allocTypeThreadMethods.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); } // link to parents Integer threadId=new Integer(parents.parentUpObjId); thread=image.resolveThread(threadId); Integer locationId=new Integer(parents.parentLeftObjId); location=image.resolveMethod(locationId); // link to roots // (same as parents) isReady=true; // add to parents' lists thread.addAllocThreadMethod(this); location.addAllocThreadMethod(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 getThread() + "-" + getLocation(); } } --- NEW FILE: AllocTypeThreadMethodR.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 AllocTypeThreadMethod * @author Lukas Petru */ public class AllocTypeThreadMethodR extends DataR implements AllocTypeThreadMethod { /** 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; private MethodR location; // parents private AllocTypeMethodR typeMethod; private AllocTypeThreadR typeThread; private AllocThreadMethodR threadMethod; // 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 */ AllocTypeThreadMethodR(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); location=image.resolveMethod(locationId); // resolve parents Integer typeMethodId=new Integer(sid.parentLeftObjId); if (image.containsId(typeMethodId)) typeMethod=(AllocTypeMethodR) image.getObject(typeMethodId); else { typeMethod=new AllocTypeMethodR(typeMethodId, image); image.putObject(typeMethodId, typeMethod); } Integer typeThreadId=new Integer(sid.parentUpObjId); if (image.containsId(typeThreadId)) typeThread=(AllocTypeThreadR) image.getObject(typeThreadId); else { typeThread=new AllocTypeThreadR(typeThreadId, image); image.putObject(typeThreadId, typeThread); } Integer threadMethodId=new Integer(sid.parentRightObjId); if (image.containsId(threadMethodId)) threadMethod=(AllocThreadMethodR) image.getObject(threadMethodId); else { threadMethod=new AllocThreadMethodR(threadMethodId, image); image.putObject(threadMethodId, threadMethod); } isReady=true; // add to parents' lists typeMethod.addAllocTypeThreadMethod(this); typeThread.addAllocTypeThreadMethod(this); threadMethod.addAllocTypeThreadMethod(this); } /** Constructs object with only <code>ID</code>. * @param oId Object identification. * @param RtImage <code>VirtualMachineImage</code> object to which this * object shall belong */ AllocTypeThreadMethodR(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 typeMethod; } public AllocThreadMethod getParentAllocThreadMethod() { needConstructed(); return threadMethod; } public AllocTypeThread getParentAllocTypeThread() { needConstructed(); return typeThread; } // ---------- 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 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 typeMethodId=new Integer(parents.parentLeftObjId); if (image.containsId(typeMethodId)) typeMethod=(AllocTypeMethodR) image.getObject(typeMethodId); else { typeMethod=new AllocTypeMethodR(typeMethodId, image); image.putObject(typeMethodId, typeMethod); } Integer typeThreadId=new Integer(parents.parentUpObjId); if (image.containsId(typeThreadId)) typeThread=(AllocTypeThreadR) image.getObject(typeThreadId); else { typeThread=new AllocTypeThreadR(typeThreadId, image); image.putObject(typeThreadId, typeThread); } Integer threadMethodId=new Integer(parents.parentRightObjId); if (image.containsId(threadMethodId)) threadMethod=(AllocThreadMethodR) image.getObject(threadMethodId); else { threadMethod=new AllocThreadMethodR(threadMethodId, image); image.putObject(threadMethodId, threadMethod); } // link to roots type=typeThread.getAllocType(); thread=typeThread.getThread(); location=(MethodR) typeMethod.getLocation(); isReady=true; // add to parents' lists typeMethod.addAllocTypeThreadMethod(this); typeThread.addAllocTypeThreadMethod(this); threadMethod.addAllocTypeThreadMethod(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() + "-" + getLocation(); } } Index: AllocTypeMethodR.java =================================================================== RCS file: /cvsroot/javaprofiler/jpiimpl/net/sourceforge/javaprofiler/jpiimpl/realtime/AllocTypeMethodR.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -r1.1 -r1.2 *** AllocTypeMethodR.java 10 Apr 2002 16:01:15 -0000 1.1 --- AllocTypeMethodR.java 15 Apr 2002 19:46:05 -0000 1.2 *************** *** 65,72 **** --- 65,75 ---- // lists for children private final List allocTypeTraces=new ArrayList(0); + private final List allocTypeThreadMethods=new ArrayList(0); // unmodifiable variants of lists for children private final List roAllocTypeTraces=Collections.unmodifiableList( allocTypeTraces); + private final List roAllocTypeThreadMethods=Collections.unmodifiableList( + allocTypeThreadMethods); /** Constructs multi-rooted object *************** *** 159,165 **** } public List getAllocTypeThreadMethods() { ! //PENDING ! return Collections.EMPTY_LIST; } --- 162,174 ---- } + public void refreshAllocTypeThreadMethods() { + image.extractMultiRoot(this, IProf.ALLOC_OBJECT_METHOD_THREADS, + image.allocTypeThreadMethodFactory); + } + public List getAllocTypeThreadMethods() { ! if ( image.getAlwaysRefresh() ) ! refreshAllocTypeThreadMethods(); ! return roAllocTypeThreadMethods; } *************** *** 205,208 **** --- 214,221 ---- void addAllocTypeTrace(AllocTypeTrace o) { allocTypeTraces.add(o); + } + + void addAllocTypeThreadMethod(AllocTypeThreadMethod o) { + allocTypeThreadMethods.add(o); } Index: AllocTypeThreadR.java =================================================================== RCS file: /cvsroot/javaprofiler/jpiimpl/net/sourceforge/javaprofiler/jpiimpl/realtime/AllocTypeThreadR.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -r1.1 -r1.2 *** AllocTypeThreadR.java 10 Apr 2002 16:01:15 -0000 1.1 --- AllocTypeThreadR.java 15 Apr 2002 19:46:06 -0000 1.2 *************** *** 151,155 **** public void refreshAllocTypeThreadMethods() { ! //PENDING } --- 151,156 ---- public void refreshAllocTypeThreadMethods() { ! image.extractMultiRoot(this, IProf.ALLOC_THREAD_OBJECT_METHODS, ! image.allocTypeThreadMethodFactory); } Index: ImageR.java =================================================================== RCS file: /cvsroot/javaprofiler/jpiimpl/net/sourceforge/javaprofiler/jpiimpl/realtime/ImageR.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -r1.1 -r1.2 *** ImageR.java 10 Apr 2002 16:01:15 -0000 1.1 --- ImageR.java 15 Apr 2002 19:46:06 -0000 1.2 *************** *** 108,111 **** --- 108,113 ---- final Constructor allocTypeTraceFactory; final Constructor allocTypeThreadFactory; + final Constructor allocThreadMethodFactory; + final Constructor allocTypeThreadMethodFactory; Set getAllFlags=new HashSet(); *************** *** 201,204 **** --- 203,212 ---- "net.sourceforge.javaprofiler.jpiimpl.realtime.AllocTypeThreadR") .getDeclaredConstructor(mrParameterTypes); + allocThreadMethodFactory=java.lang.Class.forName( + "net.sourceforge.javaprofiler.jpiimpl.realtime.AllocThreadMethodR") + .getDeclaredConstructor(mrParameterTypes); + allocTypeThreadMethodFactory=java.lang.Class.forName( + "net.sourceforge.javaprofiler.jpiimpl.realtime.AllocTypeThreadMethodR") + .getDeclaredConstructor(mrParameterTypes); } catch (ClassNotFoundException e) { throw new RuntimeException(e); *************** *** 329,332 **** --- 337,345 ---- case IProf.ALLOC_OBJECT_THREADS: return THREAD_KEY; case IProf.ALLOC_THREAD_OBJECTS: return TYPE_KEY; + case IProf.ALLOC_THREAD_METHODS: return LOCATION_KEY; + case IProf.ALLOC_METHOD_THREADS: return THREAD_KEY; + case IProf.ALLOC_OBJECT_METHOD_THREADS: return THREAD_KEY; + case IProf.ALLOC_THREAD_OBJECT_METHODS: return LOCATION_KEY; + case IProf.ALLOC_THREAD_METHOD_OBJECTS: return TYPE_KEY; default: throw new RuntimeException("No branch in switch!"); } Index: MethodR.java =================================================================== RCS file: /cvsroot/javaprofiler/jpiimpl/net/sourceforge/javaprofiler/jpiimpl/realtime/MethodR.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -r1.1 -r1.2 *** MethodR.java 10 Apr 2002 16:01:15 -0000 1.1 --- MethodR.java 15 Apr 2002 19:46:06 -0000 1.2 *************** *** 76,83 **** // lists for children ! private List cpuTraces=new ArrayList(0);; ! private List allocTraces=new ArrayList(0);; ! private List monTraces=new ArrayList(0);; ! private List allocTypeMethods=new ArrayList(0);; // unmodifiable variants of lists for children --- 76,84 ---- // lists for children ! private List cpuTraces=new ArrayList(0); ! private List allocTraces=new ArrayList(0); ! private List monTraces=new ArrayList(0); ! private List allocTypeMethods=new ArrayList(0); ! private List allocThreadMethods=new ArrayList(0); // unmodifiable variants of lists for children *************** *** 90,93 **** --- 91,96 ---- private List roAllocTypeMethods=Collections.unmodifiableList( allocTypeMethods); + private List roAllocThreadMethods=Collections.unmodifiableList( + allocThreadMethods); /** Constructs new object with info. *************** *** 179,185 **** } public List getAllocThreadMethods() { ! //PENDING ! return Collections.EMPTY_LIST; } --- 182,194 ---- } + public void refreshAllocThreadMethods() { + image.extractMultiRoot(this, IProf.ALLOC_METHOD_THREADS, + image.allocThreadMethodFactory); + } + public List getAllocThreadMethods() { ! if ( image.getAlwaysRefresh() ) ! refreshAllocThreadMethods(); ! return roAllocThreadMethods; } *************** *** 301,304 **** --- 310,317 ---- void addAllocTypeMethod(AllocTypeMethod o) { allocTypeMethods.add(o); + } + + void addAllocThreadMethod(AllocThreadMethod o) { + allocThreadMethods.add(o); } Index: ThreadR.java =================================================================== RCS file: /cvsroot/javaprofiler/jpiimpl/net/sourceforge/javaprofiler/jpiimpl/realtime/ThreadR.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -r1.1 -r1.2 *** ThreadR.java 10 Apr 2002 16:01:15 -0000 1.1 --- ThreadR.java 15 Apr 2002 19:46:06 -0000 1.2 *************** *** 78,85 **** --- 78,88 ---- // lists for children private final List allocTypeThreads=new ArrayList(0); + private final List allocThreadMethods=new ArrayList(0); // unmodifiable variants of lists for children private final List roAllocTypeThreads=Collections.unmodifiableList( allocTypeThreads); + private final List roAllocThreadMethods=Collections.unmodifiableList( + allocThreadMethods); /** Constructs new object with info. *************** *** 133,139 **** } public List getAllocThreadMethods() { ! //PENDING ! return Collections.EMPTY_LIST; } --- 136,148 ---- } + public void refreshAllocThreadMethods() { + image.extractMultiRoot(this, IProf.ALLOC_THREAD_METHODS, + image.allocThreadMethodFactory); + } + public List getAllocThreadMethods() { ! if ( image.getAlwaysRefresh() ) ! refreshAllocThreadMethods(); ! return roAllocThreadMethods; } *************** *** 252,255 **** --- 261,268 ---- void addAllocTypeThread(AllocTypeThread o) { allocTypeThreads.add(o); + } + + void addAllocThreadMethod(AllocThreadMethod o) { + allocThreadMethods.add(o); } |