home *** CD-ROM | disk | FTP | other *** search
- // findrefs.cpp
- //
- // Created 10/08/98
- //
- // (C)Copyright 1998-1999 Microsoft Corporation, All rights reserved.
- //
-
- #include "pch.hpp"
- #pragma hdrstop
-
- #include "hpmonmgr.hpp"
- #include "obsearch.hpp"
-
-
- SearchHeapInfoCallback::SearchHeapInfoCallback (HeapMonitorManager *mgr)
- {
- ASSERT(mgr);
- (m_mgr = mgr)->AddRef();
- m_RefCount = 1;
- m_workitems = NULL;
- }
-
-
- SearchHeapInfoCallback::~SearchHeapInfoCallback ()
- {
- ASSERT(!m_RefCount);
- ASSERT(!m_workitems);
-
- if (m_mgr)
- m_mgr->Release();
- }
-
-
- VOID SearchHeapInfoCallback::AddSearchOperation (SearchOperation *workitem)
- {
- ASSERT(workitem);
-
- workitem->next = m_workitems;
- m_workitems = workitem;
- }
-
-
- HRESULT SearchHeapInfoCallback::BeginDump ()
- {
- ASSERT(m_workitems != NULL);
-
- m_mgr->IterateKnownRootReferences(&FindRootRefsCB, this);
-
- return S_OK;
- }
-
-
- VOID SearchHeapInfoCallback::EndDump ()
- {
- while (m_workitems)
- {
- SearchOperation *trash = m_workitems;
- m_workitems = trash->next;
- delete(trash);
- }
- }
-
-
- //static
- int SearchHeapInfoCallback::FindRootRefsCB (ID id, ObjectID refvmid, PVOID token)
- {
- SearchHeapInfoCallback *shicb = (SearchHeapInfoCallback*)token;
-
- SearchOperation *cur = shicb->m_workitems;
- do
- {
- BOOL fFound = FALSE;
-
- switch (cur->op)
- {
- case SOP_REFERENCE_TO:
- fFound = cur->refersto.oid == refvmid;
- break;
-
- case SOP_INSTANCE_OF:
- // TODO: method frames are sort-of an instance of the class
- break;
- }
-
- if (fFound)
- (*cur->proc)(id, NULL, cur->token);
-
- cur = cur->next;
- shicb->m_mgr->IncProgressIndicator();
- }
- while (cur != NULL);
-
- return 1;
- }
-
-
- STDMETHODIMP SearchHeapInfoCallback::ObjectReferences (ObjectID vmid, DWORD flags, const ObjectID *prefs, unsigned nrefs, const DWORD *pflags)
- {
- m_mgr->IncProgressIndicator();
-
- SearchOperation *cur = m_workitems;
- while (cur != NULL)
- {
- BOOL fFound = FALSE;
-
- switch (cur->op)
- {
- case SOP_INSTANCE_OF:
- if (!(flags & JVM_OBJ_MORE_REFERENCES))
- {
- ClassID cid;
- IJavaEventMonitorIDInfo2 *pvminfo = m_mgr->GetVMInfoInterface();
- if (pvminfo->ObjectInformation(vmid, &cid) == S_OK)
- {
- fFound = (cid == cur->instanceof.cid);
- }
- pvminfo->Release();
- }
- break;
-
- case SOP_REFERENCE_TO:
- {
- const ObjectID *curref = prefs;
- const ObjectID *refsstop = prefs + nrefs;
- while (curref < refsstop)
- {
- ObjectID currefid = *curref;
- if (currefid == cur->refersto.oid)
- {
- fFound = TRUE;
- break;
- }
- curref++;
- }
- }
- break;
- }
-
- if (fFound)
- {
- (*cur->proc)(NULL, vmid, cur->token);
- }
-
- cur = cur->next;
- }
-
- return S_POSTPONE_REFERENCES;
- }
-
-
- ULONG STDMETHODCALLTYPE SearchHeapInfoCallback::AddRef (VOID)
- {
- ASSERT(m_RefCount && m_RefCount < ULONG_MAX);
-
- return InterlockedIncrement((LONG*)&m_RefCount);
- }
-
-
- ULONG STDMETHODCALLTYPE SearchHeapInfoCallback::Release (VOID)
- {
- ASSERT(m_RefCount);
-
- ULONG NewRefCount = (ULONG)InterlockedDecrement((LONG*)&m_RefCount);
- if (NewRefCount)
- return NewRefCount;
-
- delete(this);
-
- return 0;
- }
-
-
- STDMETHODIMP SearchHeapInfoCallback::QueryInterface (REFIID riid, PVOID *ppvObj)
- {
- HRESULT hr = S_OK;
-
- if (riid == IID_IUnknown || riid == IID_IHeapInfoCallback)
- {
- *ppvObj = (IHeapInfoCallback*)this;
- AddRef();
- }
- else
- {
- *ppvObj = NULL;
- hr = E_NOINTERFACE;
- }
-
- return hr;
- }
-
-