home *** CD-ROM | disk | FTP | other *** search
- // gcprof.hpp
- //
- // Created 01/19/99
- //
- // (C) Copyright 1995 - 1999 Microsoft Corporation. All rights reserved.
- //
-
- #ifndef __GCPROF_HPP__
- #define __GCPROF_HPP__
-
- #include <jevmon.h>
-
- #include "timer.hpp"
-
- class EventMonitor;
-
-
- class GCProfiler : private IHeapInfoCallback
- {
- ULONG m_refcount;
-
- EventMonitor *m_pmon;
- IJavaHeapMonitor *m_heapmon;
-
- DWORD m_nGCs;
-
- struct GCProfilerEntry
- {
- ClassID id;
-
- ULONG nlive;
- size_t cblive;
- ULONG totalage;
-
- __int64 lastcount;
-
- GCProfilerEntry *next;
- };
-
- GCProfilerEntry *m_hash[293];
-
- CRITICAL_SECTION m_cs;
-
- PROFTIME m_StartTime;
-
- CONTAINER_TYPE m_CurrentContainer;
-
- PSTR m_pszLastObjectClassName;
- BOOL m_fLastObjectClassNameIsUtf8;
-
- ULONG m_nObjects;
- size_t m_cbObjects;
- ULONG m_nOrphans;
-
- unsigned m_iField;
- BOOL m_fInHeap;
-
-
- GCProfilerEntry *LookupObject (ClassID id)
- {
- GCProfilerEntry *cur;
-
- unsigned ibucket = ((unsigned)id % ARRAY_ELEMENTS(m_hash));
- GCProfilerEntry **prev;
-
- prev = &m_hash[ibucket];
- for (;;)
- {
- cur = *prev;
- if (!cur)
- break;
-
- if (cur->id == id)
- {
- *prev = cur->next;
- cur->next = m_hash[ibucket];
- m_hash[ibucket] = cur;
- return cur;
- }
-
- prev = &cur->next;
- }
-
- EnterCriticalSection(&m_cs);
- {
- prev = &m_hash[ibucket];
- for (;;)
- {
- cur = *prev;
- if (!cur)
- break;
-
- if (cur->id == id)
- {
- *prev = cur->next;
- cur->next = m_hash[ibucket];
- m_hash[ibucket] = cur;
- return cur;
- }
-
- prev = &cur->next;
- }
-
- if ((cur = new GCProfilerEntry()) != NULL)
- {
- ZeroMemory(cur, sizeof(*cur));
- cur->id = id;
- cur->next = m_hash[ibucket];
- m_hash[ibucket] = cur;
- }
- }
- LeaveCriticalSection(&m_cs);
-
- return cur;
- }
-
-
- typedef int (GCProfiler::*POBJITERFN) (GCProfilerEntry *ent, PVOID token);
-
- int Iterate (POBJITERFN fn, PVOID token = NULL);
-
-
- int DeleteCB (GCProfilerEntry *ent, PVOID token);
- int InstanceDiscoveryCompletedCB (GCProfilerEntry *cur, PVOID token);
-
- VOID DumpRef (ObjectID objid, DWORD objflags);
-
-
- VOID InstanceDiscovered (ClassID clsid, size_t size, ULONG age)
- {
- GCProfilerEntry *ent = LookupObject(clsid);
- if (ent)
- {
- ent->nlive++;
- ent->cblive += size;
- ent->totalage += age;
- }
-
- m_nObjects++;
- m_cbObjects += size;
- }
-
- VOID InstanceDiscoveryCompleted ();
-
-
- // *** IUnknown interface
-
- STDMETHODIMP QueryInterface(REFIID, void **);
- STDMETHODIMP_(ULONG) AddRef(void);
- STDMETHODIMP_(ULONG) Release(void);
-
- // *** IHeapInfoCallback interface
-
- STDMETHODIMP BeginContainer(CONTAINER_TYPE type, UniqueID id1, UniqueID id2);
- STDMETHODIMP RootReferences(const ObjectID *prefs, unsigned nrefs, const DWORD *pflags);
- STDMETHODIMP ObjectReferences(ObjectID id, DWORD flags, const ObjectID *prefs, unsigned nrefs, const DWORD *pflags);
-
-
- public:
-
- GCProfiler ()
- {
- m_refcount = 1;
-
- m_pmon = NULL;
- m_heapmon = NULL;
-
- m_nGCs = 0;
-
- ZeroMemory(&m_hash, sizeof(m_hash));
-
- InitializeCriticalSection(&m_cs);
- }
-
- HRESULT Initialize (EventMonitor *pmon);
-
- VOID Destruct ();
-
-
- VOID GCStarted ();
- VOID GCFinished ();
- };
-
-
- #endif /* __GCPROF_HPP__ */
-
-