home *** CD-ROM | disk | FTP | other *** search
- // ids.hpp
- //
- // Created 10/02/98
- //
- // (C)Copyright 1998-1999 Microsoft Corporation, All rights reserved.
- //
-
- #ifndef __IDS_HPP__
- #define __IDS_HPP__
-
- #include "utils.hpp"
-
-
- // IDWrappers are wrappers for VM UniqueIDs. Their primary use is to cache
- // information from the VM. The information contained in an IDWrapper is
- // heap-monitor-client-independent. Clients keep separate maps for any
- // additional associations needed.
-
-
- enum IDType
- {
- ID_INVALID = -1,
-
- ID_PACKAGE,
- ID_CLASS,
- ID_THREAD,
- ID_GHOST_THREAD,
- ID_ROOT,
- ID_STACKFRAME,
-
- ID_OBJECT,
-
- ID_FIRST_TRANSIENT = ID_GHOST_THREAD,
- };
-
- enum IDWrapperFlags
- {
- // Discovered during root enumeration.
- ID_FL_DISCOVERED = 0x0001,
-
- ID_FL_MARKED_EMPTY_ROOT = 0x0002,
- ID_FL_REPORTED_EMPTY_ROOT = 0x0004,
-
- ALL_ID_PER_GC_FLAGS = ID_FL_DISCOVERED
- };
-
- class IDWrapper
- {
- public:
-
- IDType type;
- UniqueID vmid;
- PSTR name;
- DWORD flags;
-
- protected:
-
- IDWrapper (IDType itype)
- {
- type = itype;
- name = NULL;
- flags = 0;
- }
-
- friend class HeapMonitorManager;
-
- // NOTE: this is not virtualized, we will have lots of these and don't
- // want a vtable ptr per wrapper.
- ~IDWrapper ();
- };
- typedef IDWrapper *ID;
-
- typedef class PackageIDWrapper *PKGID;
- typedef class ClassIDWrapper *CLASSID;
- typedef class ThreadIDWrapper *THREADID;
- typedef class StackIDWrapper *STACKID;
- typedef class RootIDWrapper *ROOTID;
- typedef class ObjectIDWrapper *OBJID;
-
-
- // Packages don't have real UniqueIDs.
- class PackageIDWrapper : public IDWrapper
- {
- public:
- PKGID parent;
-
- PackageIDWrapper () : IDWrapper(ID_PACKAGE) {}
- };
-
-
- struct FieldInfo {
- FieldID id;
- PSTR name;
- DWORD flags;
- };
-
- struct FieldInfoHeader {
- ULONG nfields;
- ULONG nreffields;
- FieldInfo fldinfo[1];
- };
-
- enum {
- // Something went wrong in collecting running information about the class
- // or an instance of the class.
- CID_FL_INACCURATE = 0x00010000,
-
- // Is an array class (name starts with '[').
- CID_FL_ARRAY = 0x00020000,
-
- // Is an array of references (name starts with "[L")
- CID_FL_ARRAY_OF_OBJECTS = 0x00040000,
-
- // DescribeObject will work on instances of this class.
- CID_FL_HAS_DESCRIPTION = 0x00080000,
-
- ALL_CID_PER_GC_FLAGS = CID_FL_INACCURATE
- };
-
- class ClassIDWrapper : public IDWrapper
- {
- public:
- PKGID pkg;
- FieldInfoHeader *flds;
- ULONG liveinstances;
- ULONG totalsize;
- ULONG livesize;
- ULONG agesum;
-
- ClassIDWrapper () : IDWrapper(ID_CLASS)
- {
- flds = NULL;
- liveinstances = 0;
- totalsize = 0;
- livesize = 0;
- agesum = 0;
- }
- };
-
-
- enum {
- // The thread was destroyed while a heap dump was in progress. The ID is
- // valid until the heap dump completes.
- TID_FL_DEAD = 0x00010000,
- };
-
- class ThreadIDWrapper : public IDWrapper
- {
- public:
- STACKID curframe;
-
- ThreadIDWrapper () : IDWrapper(ID_THREAD)
- {
- curframe = NULL;
- }
- };
-
-
- enum {
- // See HeapMonitorManager::ObjectReferences.
- OID_FL_VISITED_BEFORE_REPORTED = 0x00010000,
-
- // Referenced by at least two objects (possibly including itself or only
- // itself).
- OID_FL_MULTIPLE_REFERENCES = 0x00020000,
-
- // Immediately referenced by a root (i.e. seen from RootReferences).
- OID_FL_REFERENCED_BY_ROOT = 0x00040000,
-
- // Object cannot reference any other objects (ex. a class with only
- // primitive fields, a primitive array, a 0-length object array, or a
- // variable-size class with no reported references).
- OID_FL_NO_REFERENCES = 0x00080000,
-
- // All of the object's references are null.
- OID_FL_NULL_REFERENCES = 0x00100000,
-
- // The outgoing edges of this object have been explored. The referents may or
- // may not have OBJIDs. This is used to record whether or not referents have
- // been checked for multiple references.
- OID_FL_EXPANDED = 0x00200000,
-
- // At the user's request, the OBJID will be kept across gc's.
- OID_FL_TRACKED = 0x00400000,
-
- // A user-defined string tag for the object can be retrived via HeapMonitorManager::GetObjectTag.
- OID_FL_TAGGED = 0x00800000,
-
- // The underlying object was garbage collected. (One of
- // ALL_OID_NONTRANSIENT_FLAGS must be set for this to occur.)
- OID_FL_DEAD = 0x01000000,
-
- // Flags that are cleared when the state of the heap is unknown.
- ALL_OID_TRANSIENT_FLAGS = OID_FL_VISITED_BEFORE_REPORTED
- | OID_FL_MULTIPLE_REFERENCES
- | OID_FL_REFERENCED_BY_ROOT
- | OID_FL_NULL_REFERENCES
- | OID_FL_EXPANDED,
-
- // Flags that require the OBJID to be kept across gc's (including after
- // the underlying object has been collected). A handle is allocated and
- // stored in a HeapMonitorManager::TrackedObjectList entry.
- ALL_OID_NONTRANSIENT_FLAGS = OID_FL_TRACKED
- | OID_FL_TAGGED,
- };
-
- // Proxies to an ObjectID. Unless any of ALL_OID_NONTRANSIENT_FLAGS, OBJID's
- // should not be used while execution is not suspended. The vmid field must
- // never be used while execution is not suspended. States variables:
- //
- // dead: The object was garbage collected, indicated by OID_FL_DEAD.
- // Normally, OBJIDs are simply deleted in this state. An OBJID will be kept
- // in this state if any of ALL_OID_NONTRANSIENT_FLAGS are set. The vmid field
- // is not valid in this state.
- //
- // tracked: The object is being followed by the user across gc's, indicated by
- // OID_FL_TRACKED. When a tagged ObjectID is garbage collected, the OBJID is
- // kept and OID_FL_DEAD is set.
- //
- // tagged: The object was given a description by the user, indicated by
- // OID_FL_TAGGED. When a tagged ObjectID is garbage collected, the OBJID is
- // kept and OID_FL_DEAD is set.
- //
- // Any combination of these variables can occur. In any states where
- // "!(tracked || tagged)", the OBJID will be deleted when execution resumes.
- //
- // In any states where "tracked || tagged", the vmid field will be updated
- // with the possibly-changed ObjectID when execution is suspended.
- //
- class ObjectIDWrapper : public IDWrapper
- {
- public:
- ObjectIDWrapper () : IDWrapper(ID_OBJECT)
- {
- }
-
- ObjectID GetObjectID ()
- {
- ASSERT(!(flags & OID_FL_DEAD));
- return vmid;
- }
- };
-
-
- enum
- {
- // Has references to one or more objects
- SID_FL_HAS_REFERENCES = 0x00010000,
- };
-
- class StackIDWrapper : public IDWrapper
- {
- public:
- CONTAINER_TYPE frmtype;
- THREADID thd;
- MethodID methodid;
- STACKID parent;
-
- StackIDWrapper () : IDWrapper(ID_STACKFRAME)
- {
- }
- };
-
-
- enum
- {
- // Has references to one or more objects
- RID_FL_HAS_REFERENCES = 0x00010000,
- };
-
- class RootIDWrapper : public IDWrapper {
- public:
- CONTAINER_TYPE roottype;
- UniqueID rootid1;
- UniqueID rootid2;
-
- RootIDWrapper () : IDWrapper(ID_ROOT)
- {
- }
- };
-
-
- class UniqueIDMap
- {
- private:
-
- CMapPtrToPtr m_map;
-
- public:
-
- BOOL AddID (UniqueID vmid, ID id)
- {
- BOOL result;
- ASSERT(vmid != NULL);
- ASSERT(!LookupID(vmid));
- result = SUCCEEDED(m_map.Add((PVOID)vmid, id));
- if (result)
- {
- id->vmid = vmid;
- ASSERT(LookupID(vmid) == id);
- }
-
- return result;
- }
-
- ID LookupID (UniqueID vmid)
- {
- ID id = NULL;
- m_map.Lookup((PVOID)vmid, (PVOID*)&id);
- ASSERT(id == NULL || id->vmid == vmid);
- return id;
- }
-
- VOID DeleteID (UniqueID vmid)
- {
- ASSERT(vmid != NULL);
- EVAL(SUCCEEDED(m_map.Delete((PVOID)vmid)));
- ASSERT(!LookupID(vmid));
- }
-
- VOID FilterIDs (PTRMAPENUMFN *filterfn, PVOID token)
- {
- m_map.Filter(filterfn, token);
- }
-
- int IterateIDs (PTRMAPENUMFN *iterfn, PVOID token)
- {
- return m_map.Iterate(iterfn, token);
- }
- };
-
-
- #endif /* __IDS_HPP__ */
-
-