home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 39 / IOPROG_39.ISO / SOFT / sdkjava40.exe / data1.cab / fg_Samples / Samples / Profiler / heapmon / hpmonmgr.hpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-04  |  19.9 KB  |  739 lines

  1. // hpmonmgr.hpp
  2. //
  3. // Created 10/04/98
  4. //
  5. // (C)Copyright 1998-1999 Microsoft Corporation, All rights reserved.
  6. //
  7.  
  8. #ifndef __HPMONMGR_HPP__
  9. #define __HPMONMGR_HPP__
  10.  
  11. #include "rootrefs.hpp"
  12. #include "gcinfo.hpp"
  13. #include "obsearch.hpp"
  14.  
  15.  
  16. #define WC_HEAPMONITOR "JavaHeapMonitorClass"
  17.  
  18. #define IDC_STATUS                  50
  19.  
  20. #define IDM_WINDOW_FIRSTCHILD       100
  21.  
  22.  
  23. enum HeapMonitorManagerMessages
  24. {
  25.     HMM_WM_FIRST = WM_USER,
  26.  
  27.     HMM_WM_ACTIVATE,
  28.  
  29.     HMM_WM_START_PROGRESS_INDICATOR,
  30.  
  31.     HMM_WM_STOP_PROGRESS_INDICATOR,
  32.  
  33.     HMM_WM_DESTROY_NOW,
  34.  
  35.     HMM_WM_LAST,
  36. };
  37.  
  38.  
  39. enum HeapMonitorManagerFlags
  40. {
  41.     // VM has fully initialized
  42.     HMM_FL_VM_INITIALIZED           = 0x00000001,
  43.     
  44.     // "Stop!" was pressed
  45.     HMM_FL_STOP                     = 0x00000002,
  46.  
  47.     // Execution was suspended by the user.
  48.     HMM_FL_STOPPED                  = 0x00000004,
  49.     
  50.     // "Go!" was pressed
  51.     HMM_FL_GO                       = 0x00000008,
  52.     
  53.     // heap exploration is in progress
  54.     HMM_FL_EXPLORING_HEAP           = 0x00000010,
  55.     
  56.     // heap was fully explored (heap dump was not aborted and C_END was received)
  57.     HMM_FL_HEAP_EXPLORED            = 0x00000020,
  58.     
  59.     // object aging was enabled
  60.     HMM_FL_OBJECT_AGING             = 0x00000040,
  61.     
  62.     // an allocation callback is active
  63.     HMM_FL_OBJECT_ALLOCS            = 0x00000080,
  64.     
  65.     // something went wrong during heap enumeration, information may not be
  66.     // accurate.  This is a per-gc indicator.
  67.     HMM_FL_INACCURATE               = 0x00000100,
  68.  
  69.     HMM_FL_ADDED_TRAY_ICON          = 0x00000200,
  70.  
  71.     // A progress indicator is in the first part of the status window.
  72.     HMM_FL_PROGRESS_INDICATOR       = 0x00000400,
  73.  
  74.     // The main window was closed.
  75.     HMM_FL_CLOSED                   = 0x00000800,
  76.  
  77.     // A HMM_WM_DESTROY_NOW message was posted.
  78.     HMM_FL_DESTRUCTION_PENDING      = 0x00001000,
  79. };
  80.  
  81.  
  82. // Main MDI frame.  Also implements the event monitor callbacks and collects
  83. // basic statistics.  Various events are pre-processed and dispatched to the
  84. // client windows.
  85.  
  86. class HeapMonitorManager : private IJavaEventMonitor2,
  87.                            private IHeapInfoCallback
  88. {
  89.     static CRITICAL_SECTION s_mgrlistcs;
  90.     static HeapMonitorManager *s_mgrlist;
  91.     HeapMonitorManager *m_next;
  92.  
  93.     ULONG m_RefCount;
  94.  
  95.     // Used to serialize access to HeapMonitorManager and IDWrapper fields
  96.     CRITICAL_SECTION m_cs;
  97. #ifdef DEBUG
  98.     DWORD m_tidCriticalSectionOwner;
  99.     ULONG m_CriticalSectionEnterCount;
  100. #endif // DEBUG
  101.  
  102.     // bitmask of HeapMonitorManagerFlags
  103.     DWORD m_flags;
  104.  
  105.     // reset while stopped, set while running
  106.     HANDLE m_hresumeevt;
  107.  
  108.     IJavaEventMonitorIDInfo2 *m_vminfo;
  109.     IJavaHeapMonitor *m_vmheapmon;
  110.     IJavaHeapMonitor2 *m_vmheapmon2;
  111.  
  112.     // IHeapInfoCallback state
  113.     CONTAINER_TYPE m_lastroottype;
  114.     UniqueID m_lastrootvmid1;
  115.     UniqueID m_lastrootvmid2;
  116.     ID m_lastrootid;
  117.     THREADID m_lastthreadid;
  118.  
  119.     RootReferencesRecorder m_rootrefs;
  120.  
  121.     // Current gc number, and information about the current gc.
  122.     // PerGCInformation contains a 'next' link, which leads to information
  123.     // about previous gc's.
  124.     ULONG m_iGC;
  125.     PerGCInformation m_gcinfo;
  126.  
  127.  
  128.     //------------------------------------------------------------------------
  129.     // Event client management
  130.  
  131. public:
  132.  
  133.     static
  134.     DWORD GetInfoNeededForEvents (DWORD EventMask)
  135.     {
  136.         DWORD InfoMask = 0;
  137.                 
  138.         if (EventMask & HMC_ROOT_EVENTS)
  139.             InfoMask |= (HMC_INFO_HEAP_ROOTS | HMC_INFO_HEAP_ROOT_REFS);
  140.  
  141.         if (EventMask & HMC_OBJECT_EVENTS)
  142.             InfoMask |= (HMC_INFO_HEAP_OBJECTS | HMC_INFO_HEAP_OBJECT_REFS);
  143.  
  144.         if (EventMask & HMC_HEAP_EVENTS)
  145.             InfoMask |= (HMC_INFO_HEAP_ROOTS | HMC_INFO_HEAP_OBJECTS);
  146.  
  147.         return InfoMask;
  148.     }
  149.  
  150.     BOOL RegisterClient (IHeapMonitorClient *newclient, HeapMonitorClientRegistrationInfo *pinfo);
  151.  
  152.     VOID UnregisterClient (IHeapMonitorClient *deadclient);
  153.  
  154. private:
  155.  
  156.     // Information about each client window, and list of active client windows
  157.     struct ClientRecord
  158.     {
  159.         ULONG refcount;
  160.         IHeapMonitorClient *client;
  161.         DWORD EventMask;
  162.         DWORD InfoMask;
  163.         DWORD StoppedEventMask;
  164.         DWORD StoppedInfoMask;
  165.         ClientRecord *next;
  166.     };
  167.     ClientRecord *m_clients;
  168.  
  169.     // Union of events required by all clients.
  170.     DWORD m_EventMaskUnion;
  171.     DWORD m_StoppedEventMaskUnion;
  172.     // Union of information required by all clients.
  173.     DWORD m_InfoMaskUnion;
  174.     DWORD m_StoppedInfoMaskUnion;
  175.  
  176.     // m_InfoMaskUnion [and m_StoppedInfoMaskUnion] at start of heap dump
  177.     DWORD m_HeapInfoNeeded;
  178.  
  179.     BOOL IsEventRequested (DWORD mask)
  180.     {
  181.         return    (m_EventMaskUnion & mask)
  182.                || (m_flags & HMM_FL_STOPPED) && (m_StoppedEventMaskUnion & mask);
  183.     }
  184.  
  185.     typedef VOID CLIENTITERFN (IHeapMonitorClient *client, PVOID token);
  186.  
  187.     VOID IterateClients (DWORD mask, CLIENTITERFN *cb, PVOID token);
  188.  
  189.  
  190.     //------------------------------------------------------------------------
  191.     // UI stuff
  192.  
  193. public:
  194.  
  195. #ifdef DEBUG
  196.     BOOL CanSendUIMessages ()
  197.     {
  198.         // Sending a synchronous message to the UI thread while inside our
  199.         // critical section can deadlock.  The UI thread may block on the
  200.         // critical section, while this thread blocks waiting for the UI
  201.         // thread to process the message.
  202.         return    GetCurrentThreadId() == m_tid
  203.                || !Entered();
  204.     }
  205. #endif
  206.  
  207.     VOID IncProgressIndicator ()
  208.     {
  209.         m_ProgressIndicator++;
  210.     }
  211.  
  212. private:
  213.  
  214.     // message pump thread
  215.     HANDLE m_hthd;
  216.     DWORD m_tid;
  217.  
  218.     static DWORD WINAPI HeapMonitorManagerMessagePumpThread (PVOID token);
  219.  
  220.     // UI elements of the main frame
  221.     HINSTANCE m_hinst;
  222.     HWND m_hwnd;
  223.     HMENU m_hmnu;
  224.     HMENU m_hmnuWindow;
  225.     HWND m_mdi;
  226.     HWND m_status;
  227.  
  228.     BOOL InitializeUI  ();
  229.  
  230.     VOID DestroyNow ();
  231.  
  232.     VOID RedrawMenuBar ();
  233.     BOOL GrayMenu (UINT idm);
  234.     BOOL ChangeMenuTextAndUngray (UINT idm, PCSTR text);
  235.  
  236.     VOID StopOrGo ();
  237.     VOID IndicateStopped ();
  238.     VOID IndicateRunning ();
  239.  
  240.     static
  241.     VOID CALLBACK HeapMonitorManager::UpdateProgressIndicator(
  242.       HWND hwnd,     // handle to window
  243.       UINT uMsg,     // WM_TIMER message
  244.       UINT idEvent,  // timer identifier
  245.       DWORD dwTime   // current system time
  246.     );
  247.  
  248.     // Status bar state.  While a heap dump is in progress, the status bar is
  249.     // segmented.  The first segment is drawn with a bitmap from this list.
  250.     HIMAGELIST m_ProgressIndicatorImages;
  251.     UINT m_ProgressIndicatorTimer;
  252.     UINT m_iProgressIndicatorImage;
  253.  
  254.     // Places that do useful work during a heap dump increment this counter.
  255.     ULONG m_ProgressIndicator;
  256.  
  257.     // Snapshots of the object count from m_gcinfo and the last progress
  258.     // counter, at the time the last bitmap was drawn.
  259.     ULONG m_LastProgressIndicator;
  260.     ULONG m_LastObjectCount;
  261.  
  262.     BOOL StartHeapDumpProgressIndicatorWorker ();
  263.     VOID StopHeapDumpProgressIndicatorWorker ();
  264.     BOOL StartHeapDumpProgressIndicator ();
  265.     VOID StopHeapDumpProgressIndicator ();
  266.  
  267.     VOID SetStatusText (PCSTR text);
  268.  
  269.     static HICON s_htrayicon;
  270.  
  271.     BOOL AddTrayIcon ();
  272.     BOOL RemoveTrayIconWorker ();
  273.     BOOL RemoveTrayIcon ();
  274.  
  275.     VOID OnCreateWindow (HWND wnd, LPCREATESTRUCT pcs);
  276.  
  277.     VOID CreateNewHeapViewer ();
  278.     VOID CreateNewClassViewer ();
  279.     VOID CreateNewGCHistoryViewer ();
  280.     VOID CreateNewTrackedObjectListViewer ();
  281.     VOID CreateNewTaggedObjectListViewer ();
  282.  
  283.     static LRESULT CALLBACK WndProc (HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam);
  284.  
  285.  
  286.     //------------------------------------------------------------------------
  287.     // ID management and UniqueID information caching
  288.  
  289. public:
  290.  
  291.     ID LookupID (UniqueID vmid)
  292.     {
  293.         return m_idmap.LookupID(vmid);
  294.     }
  295.  
  296.     PKGID LookupPackage (PKGID parentpkgid, PCWSTR pcszPackageName);
  297.  
  298.     CLASSID LookupClass (ClassID vmid);
  299.  
  300.     OBJID LookupObject (ObjectID vmid);
  301.  
  302.     THREADID LookupThread (ThreadID vmid);
  303.  
  304.     typedef int IDITERFN (ID id, PVOID cbtoken);
  305.  
  306.     int IterateIDs (IDITERFN *cb, PVOID cbtoken = NULL);
  307.  
  308.     int IterateIDs_Safe (IDITERFN *cb, PVOID cbtoken = NULL)
  309.     {
  310.         ASSERT(Entered() || GetCurrentThreadId() == m_HeapDumpThreadId);
  311.  
  312.         IDIterState state;
  313.         state.cb = cb;
  314.         state.cbtoken = cbtoken;
  315.  
  316.         return m_idmap.IterateIDs(&IterateIDsCBAdaptor, &state);
  317.     }
  318.  
  319.     typedef int IterateRootReferencesProc (ID rootid, ObjectID refid, PVOID token);
  320.  
  321.     int IterateKnownRootReferences (IterateRootReferencesProc *cb, PVOID token)
  322.     {
  323.         ASSERT(CanSendUIMessages());
  324.  
  325.         int result;
  326.     
  327.         result = m_rootrefs.Iterate(cb, token);
  328.  
  329.         return result;
  330.     }
  331.  
  332. private:
  333.  
  334.     // Maps UniqueIDs from the VM to IDWrappers
  335.     UniqueIDMap m_idmap;
  336.     ULONG m_IDMapChangeCount;
  337.  
  338.     BOOL AddID (UniqueID vmid, ID id)
  339.     {
  340.         ASSERT(Entered());
  341.         BOOL ret = m_idmap.AddID(vmid, id);
  342.         if (ret)
  343.             m_IDMapChangeCount++;
  344.         return ret;
  345.     }
  346.  
  347.     VOID DeleteID (ID id)
  348.     {
  349.         // IDs are not deleted in this fashion when execution is
  350.         // resumed....they are UniqueIDMap::Filter'd.
  351.         ASSERT(Entered());
  352.         m_idmap.DeleteID(id->vmid);
  353.         m_IDMapChangeCount++;
  354.     }
  355.  
  356.     struct IDIterState
  357.     {
  358.         IDITERFN *cb;
  359.         PVOID cbtoken;
  360.     };
  361.  
  362.     static int IterateIDsCBAdaptor (PCVOID key, PVOID value, PVOID token)
  363.     {
  364.         IDIterState *state = (IDIterState*)token;
  365.         return (*state->cb)((ID)value, state->cbtoken);
  366.     }
  367.  
  368.     static int DeleteTransientIDs (PCVOID key, PVOID value, PVOID token);
  369.  
  370.     static int ResetPerGCIDInfo (PCVOID key, PVOID val, PVOID token);
  371.  
  372.     // Maps package name to PKGID
  373.     struct PkgTokenEntry {
  374.         PWSTR name;
  375.         PKGID id;
  376.     };
  377.     DWORD m_npkgents;
  378.     PkgTokenEntry *m_pkgents;
  379.  
  380.     PkgTokenEntry *GetPackageEntry (PCWSTR pkgname);
  381.  
  382.     BOOL FetchClassInfo (CLASSID id);
  383.  
  384.     static int FetchClassInfoCB (ID id, PVOID cbtoken);
  385.  
  386.     // CONTAINER_TYPE descriptions, filled in by FetchContainerName
  387.     PSTR *m_rgpszContainerDescriptions;
  388.     PSTR *m_rgpszVerboseContainerDescriptions;
  389.  
  390.     PCSTR FetchContainerName (PSTR **prgpszDescr, CONTAINER_TYPE type, BOOL fVerbose);
  391.  
  392.  
  393.     //------------------------------------------------------------------------
  394.     // Heap graph navigation
  395.  
  396. public:
  397.  
  398.     // Returns <0 on failure, 0 to stop, or >0 to continue.
  399.     typedef int ExpandObjectAddObjectIDReferenceProc (ObjectID vmidref, PVOID token);
  400.     typedef int ExpandObjectAddOBJIDReferenceProc (OBJID idref, PVOID token);
  401.  
  402.     enum ExpandObjectResults
  403.     {
  404.         EOR_FAILED,
  405.         EOR_EXPANDED,
  406.         EOR_NO_REFERENCES,
  407.     };
  408.  
  409.     // Explores the outgoing edges of an object.
  410.     ExpandObjectResults ExpandObject (
  411.             ObjectID vmid, OBJID *pid,
  412.             ExpandObjectAddObjectIDReferenceProc *vmidcb,
  413.             ExpandObjectAddOBJIDReferenceProc *idcb,
  414.             PVOID token);
  415.  
  416.     BOOL FindObjectReferences (ObjectID vmid, SearchProc *cb, PVOID token);
  417.     BOOL FindClassInstances (CLASSID cls, SearchProc *cb, PVOID token);
  418.  
  419. private:
  420.  
  421. #ifdef DEBUG
  422.     DWORD m_HeapDumpThreadId;
  423. #endif // DEBUG
  424.  
  425.     OBJID CreateOBJID (ObjectID vmid);
  426.  
  427.     // Records an incoming edge to an object.
  428.     OBJID DiscoveredObject (ObjectID vmid);
  429.  
  430.     ID DiscoveredRoot (CONTAINER_TYPE type, UniqueID vmid, UniqueID extraid);
  431.  
  432.     SearchHeapInfoCallback *m_searchcb;
  433.  
  434.     // Requests a search operation.  The operation will be performed when any
  435.     // currently running heap dump completes.
  436.     BOOL RegisterSearchOperation (SearchOperation *searchitem);
  437.  
  438.     struct PendingHeapWalk
  439.     {
  440.         IWalkHeapCallback *cb;
  441.         DWORD HeapWalkFlags;
  442.         PendingHeapWalk *next;
  443.     };
  444.  
  445.     PendingHeapWalk *m_heapwalks;
  446.  
  447. public:
  448.  
  449.     // Requests a full heap dump.  The operation will be performed when any
  450.     // currently running heap dump completes.
  451.     BOOL RegisterHeapWalk (IWalkHeapCallback *cb, DWORD HeapWalkFlags = 0);
  452.  
  453. #ifdef DEBUG
  454.     BOOL OnHeapDumpThread ()
  455.     {
  456.         return GetCurrentThreadId() == m_HeapDumpThreadId;
  457.     }
  458. #endif // DEBUG
  459.  
  460.  
  461.     //------------------------------------------------------------------------
  462.     // OBJID operations
  463.  
  464. public:
  465.     
  466.     BOOL ToggleObjectTracking (OBJID obj, ObjectID vmid);
  467.  
  468.     BOOL SetObjectTag (OBJID obj, PCSTR newtag);
  469.  
  470.     PCSTR GetObjectTag (OBJID obj);
  471.  
  472.     ClassID GetClassOfDeadObject (OBJID obj)
  473.     {
  474.         ASSERT(obj->flags & OID_FL_DEAD);
  475.         TrackedObjectList *trkent = *FindTrackedObjectEntry(obj);
  476.         return trkent->vmclsid;
  477.     }
  478.  
  479.     typedef int SPECIALOBJITERFN (OBJID obj, PVOID token);
  480.  
  481.     // Iterates objects that are "special" to the user - tagged or tracked.
  482.     int IterateSpecialObjects (SPECIALOBJITERFN *cb, PVOID token);
  483.  
  484. private:
  485.     
  486.     struct TrackedObjectList
  487.     {
  488.         OBJID obj;
  489.         TrackedObjectList *next;
  490.  
  491.         ObjectHandleID vmhid;
  492.         PSTR tag;
  493.         ClassID vmclsid;
  494.  
  495.         BOOL fStatusChanged;
  496.     };
  497.  
  498.     TrackedObjectList *m_trackedobjs;
  499.  
  500.     TrackedObjectList **FindTrackedObjectEntry (OBJID obj);
  501.  
  502.     TrackedObjectList *CreateTrackedObjectEntry (OBJID obj);
  503.  
  504.     VOID DestroyTrackedObjectEntry (TrackedObjectList **ptrkent);
  505.  
  506.  
  507.     //------------------------------------------------------------------------
  508.     // VM event handlers
  509.  
  510. private:
  511.  
  512.     static VOID StoppedExecutionCB (IHeapMonitorClient *client, PVOID token);
  513.     VOID SendSuspendedEvent ();
  514.  
  515.     static VOID ResumeExecutionCB (IHeapMonitorClient *client, PVOID token);
  516.     VOID SendResumingEvent ();
  517.  
  518.     static VOID SendClosingEventCB (IHeapMonitorClient *client, PVOID token);
  519.     VOID SendClosingEvent ();
  520.  
  521.     static VOID SendThreadCreatedEventCB (IHeapMonitorClient *client, PVOID token);
  522.     VOID SendThreadCreatedEvent (THREADID thd);
  523.  
  524.     static VOID SendDestroyThreadEventCB (IHeapMonitorClient *client, PVOID token);
  525.     VOID SendDestroyThreadEvent (THREADID thd);
  526.  
  527.     static VOID SendPackageCreatedEventCB (IHeapMonitorClient *client, PVOID token);
  528.     VOID SendPackageCreatedEvent (PKGID newpkgid);
  529.  
  530.     static VOID SendClassLoadedEventCB (IHeapMonitorClient *client, PVOID token);
  531.     VOID SendClassLoadedEvent (CLASSID newclsid);
  532.  
  533.     static VOID SendUnloadClassEventCB (IHeapMonitorClient *client, PVOID token);
  534.     VOID SendUnloadClassEvent (CLASSID cls);
  535.  
  536.     static VOID RootReferencedCB (IHeapMonitorClient *client, PVOID token);
  537.     VOID SendRootReferencesEvent (RootReferencesEventInfo *pinfo);
  538.  
  539.     static VOID ObjectStatusChangedCB (IHeapMonitorClient *client, PVOID token);
  540.     VOID SendObjectStatusChanged (OBJID obj);
  541.  
  542.     static VOID RootDiscoveryCompleteCB (IHeapMonitorClient *client, PVOID token);
  543.     VOID SendRootDiscoveryComplete ();
  544.  
  545.     static VOID ObjectDiscoveryCompleteCB (IHeapMonitorClient *client, PVOID token);
  546.     VOID SendObjectDiscoveryComplete ();
  547.  
  548.     VOID Stopped ();
  549.  
  550.     CLASSID ClassLoaded (ClassID vmid, PWSTR name);
  551.     CLASSID ClassLoaded (ClassID vmid);
  552.     VOID ClassUnloaded (ClassID vmid);
  553.  
  554.     THREADID ThreadCreated (ThreadID vmid, BOOL ghost);
  555.     HRESULT ThreadNameChanged (ThreadID vmid, PWSTR newname);
  556.     VOID ThreadDestroyed (ThreadID vmid);
  557.  
  558.     static int MarkEmptyRootsCB (ID id, PVOID token);
  559.     static int ReportEmptyRootsCB (ID id, PVOID token);
  560.     static int ResetEmptyRootsCB (ID id, PVOID token);
  561.     
  562.  
  563.     //------------------------------------------------------------------------
  564.     // Implemented interfaces
  565.  
  566. private:
  567.  
  568.     // IJavaEventMonitor methods
  569.  
  570.     STDMETHODIMP Initialize (LPCSTR pclass_file_name, IJavaEventMonitorIDInfo *pmonitor_info, DWORD java_flags, DWORD *prequested_events);
  571.     STDMETHODIMP NotifyEvent (JVM_EVENT_TYPE event, UniqueID event_id);
  572.     STDMETHODIMP MethodEntry (MethodID method_id, StackID stack_id);
  573.     STDMETHODIMP MethodExit (StackID stack_id);
  574.     STDMETHODIMP ExecuteByteCode (MethodID method_id, BYTE_CODE *pbyte_code, DWORD byte_code_offset);
  575.     STDMETHODIMP ExecuteSourceLine (MethodID method_id, DWORD line_number);
  576.  
  577.     // IJavaEventMonitor2 methods
  578.  
  579.     STDMETHODIMP NotifyEvent2 (JVM_EVENT_TYPE2 event2, UniqueID first_event_id, UniqueID second_event_id);
  580.     STDMETHODIMP MethodExit2 (MethodID method_id, StackID stack_id);
  581.     STDMETHODIMP GetPossibleEventCategories (DWORD *ppossible_events);
  582.  
  583.     // IHeapInfoCallback
  584.  
  585.     STDMETHODIMP BeginContainer (CONTAINER_TYPE type, UniqueID id1, UniqueID id2);
  586.     STDMETHODIMP RootReferences (const ObjectID *prefs, unsigned nrefs, const DWORD *pflags);
  587.     STDMETHODIMP ObjectReferences (ObjectID vmid, DWORD flags, const ObjectID *prefs, unsigned nrefs, const DWORD *pflags);
  588.  
  589.  
  590.     //------------------------------------------------------------------------
  591.  
  592. public:
  593.  
  594.     HeapMonitorManager ();
  595.     ~HeapMonitorManager ();
  596.  
  597.     BOOL Initialize (HINSTANCE hInstance);
  598.  
  599.  
  600.     static VOID OnProcessAttach (HINSTANCE hinst);
  601.     static VOID OnProcessDetach (HINSTANCE hinst);
  602.  
  603.  
  604.     VOID Enter ()
  605.     {
  606.         EnterCriticalSection(&m_cs);
  607. #ifdef DEBUG
  608.         m_tidCriticalSectionOwner = GetCurrentThreadId();
  609.         m_CriticalSectionEnterCount++;
  610. #endif // DEBUG
  611.     }
  612.  
  613.     VOID Leave ()
  614.     {
  615. #ifdef DEBUG
  616.         ASSERT(m_CriticalSectionEnterCount);
  617.         ULONG NewEnterCount = --m_CriticalSectionEnterCount;
  618.         if (!NewEnterCount)
  619.             m_tidCriticalSectionOwner = INVALID_THREAD_ID;
  620. #endif // DEBUG
  621.         LeaveCriticalSection(&m_cs);
  622.     }
  623.  
  624. #ifdef DEBUG
  625.     BOOL Entered ()
  626.     {
  627.         return m_tidCriticalSectionOwner == GetCurrentThreadId();
  628.     }
  629. #endif // DEBUG
  630.  
  631.  
  632.     HWND GetMDIClientWindow ()
  633.     {
  634.         return m_mdi;
  635.     }
  636.  
  637.     HINSTANCE GetInstance ()
  638.     {
  639.         return m_hinst;
  640.     }
  641.  
  642.     IJavaEventMonitorIDInfo2 *GetVMInfoInterface ()
  643.     {
  644.         m_vminfo->AddRef();
  645.         return m_vminfo;
  646.     }
  647.  
  648.  
  649.     PCSTR GetContainerName (CONTAINER_TYPE type)
  650.     {
  651.         return FetchContainerName(&m_rgpszContainerDescriptions, type, FALSE);
  652.     }
  653.  
  654.     PCSTR GetVerboseContainerName (CONTAINER_TYPE type)
  655.     {
  656.         return FetchContainerName(&m_rgpszVerboseContainerDescriptions, type, TRUE);
  657.     }
  658.  
  659.     PerGCInformation *GetCurrentGCInfo ()
  660.     {
  661.         return m_gcinfo.next;
  662.     }
  663.  
  664.  
  665.     BOOL IsExecutionSuspended_Safe ()
  666.     {
  667.         ASSERT(Entered());
  668.         return !(m_flags & (HMM_FL_EXPLORING_HEAP | HMM_FL_HEAP_EXPLORED));
  669.     }
  670.  
  671.     BOOL IsExecutionSuspended ()
  672.     {
  673.         BOOL ret;
  674.         Enter();
  675.         {
  676.             ret = IsExecutionSuspended_Safe();
  677.         }
  678.         Leave();
  679.         return ret;
  680.     }
  681.  
  682.     BOOL IsRunning_Safe ()
  683.     {
  684.         ASSERT(Entered());
  685.         return !(m_flags & HMM_FL_STOPPED);
  686.     }
  687.  
  688.     BOOL IsRunning ()
  689.     {
  690.         BOOL ret;
  691.         Enter();
  692.         {
  693.             ret = IsRunning_Safe();
  694.         }
  695.         Leave();
  696.         return ret;
  697.     }
  698.  
  699.     BOOL IsStopped_Safe ()
  700.     {
  701.         return !IsRunning_Safe();
  702.     }
  703.  
  704.     BOOL IsStopped ()
  705.     {
  706.         return !IsRunning();
  707.     }
  708.     
  709.  
  710.     BOOL SupportsObjectAging ()
  711.     {
  712.         return (m_flags & HMM_FL_OBJECT_AGING);
  713.     }
  714.  
  715.     BOOL SupportsAllocatedSize ()
  716.     {
  717.         return (m_flags & HMM_FL_OBJECT_ALLOCS);
  718.     }
  719.  
  720.  
  721.     //------------------------------------------------------------------------
  722.     // ID information
  723.     
  724.     PSTR FetchIDFriendlyName (ID id);
  725.  
  726.  
  727.     //------------------------------------------------------------------------
  728.     
  729.     // IUnknown methods
  730.  
  731.     ULONG STDMETHODCALLTYPE AddRef (VOID);
  732.     ULONG STDMETHODCALLTYPE Release (VOID);
  733.     STDMETHODIMP QueryInterface(REFIID riid, PVOID *ppvObj);
  734. };
  735.  
  736.  
  737. #endif /* __HPMONMGR_HPP__ */
  738.  
  739.