home *** CD-ROM | disk | FTP | other *** search
- // jviewprf.hpp
- //
- // Created 01/18/99
- //
- // (C) Copyright 1995 - 1999 Microsoft Corporation. All rights reserved.
- //
-
- #ifndef __JVIEWPRF_HPP__
- #define __JVIEWPRF_HPP__
-
- #include <jviewprf.h>
-
- #include "callprof.hpp"
- #include "calltrac.hpp"
- #include "sampler.hpp"
- #include "allocprf.hpp"
- #include "gcprof.hpp"
-
-
- //------------------------------------------------------------------------
-
-
- extern ULONG g_nMethodsToHook;
- extern PSTR *g_rgpszMethodsToHook;
- extern ULONG g_nClassesToHook;
- extern PSTR *g_rgpszClassesToHook;
-
- // -prof options that map to the flag
- // -----------------------------------
- #define OPT_PROF_CALLS 0x00000001 // calltimes, calltrace, or callparams
- #define OPT_CALL_TRACE 0x00000002 // calltrace or callparams
- #define OPT_CALL_TRACE_PARAMS 0x00000004 // callparams
- #define OPT_CALL_TIMES 0x00000008 // calltimes
- #define OPT_PROF_ALLOC 0x00000010 // permethodalloc or perclassalloc
- #define OPT_ALLOC_PER_CLASS 0x00000020 // perclassalloc
- #define OPT_ALLOC_PER_METHOD 0x00000040 // permethodalloc
- #define OPT_PROF_GC 0x00000080 // gc or heapdump
- #define OPT_DUMP_HEAP 0x00000100 // heapdump
- #define OPT_GC_SUMMARY 0x00000200 // gc
- #define OPT_SAMPLE 0x00000400 // sample
- #define OPT_VERBOSE 0x00000800 // verbose
- #define OPT_TABLE 0x00001000 // table
-
- #define OPT_NON_EVENT_OPTIONS (OPT_TABLE)
-
- // If no options besides OPT_NON_EVENT_OPTIONS are set, these are implicitly set.
- #define OPT_DEFAULT_OPTIONS (OPT_PROF_CALLS | OPT_CALL_TIMES)
-
- extern DWORD g_ProfOptions;
-
- extern ULONG g_SamplingFrequency;
-
-
- //------------------------------------------------------------------------
-
-
- VOID FatalError (UINT id, ...);
- VOID Warning (UINT id, ...);
-
- extern ULONG g_OutputWidth;
-
- // printf("Hello")
- VOID WriteOutput (PCSTR pcsz);
-
- // printf(L"Hello")
- VOID WriteOutputW (PCWSTR pcwsz);
-
- VOID WriteOutputUtf8 (PCSTR pcszUtf8);
-
- // printf("%u", 500)
- #define WRITE_MAX_SIZE_NORM_FMT 512
- VOID WriteOutputFmt (PCSTR fmt, ...);
-
- // printf("%s", foo);
- // This uses the VM's snprintf, which supports a limited subset of the format characters.
- VOID WriteOutputLongFmt (PCSTR fmt, ...);
-
- // First arg is field width.
- #define WRITE_LEFT_JUSTIFIED 0x00000001
- #define WRITE_CENTERED 0x00000002
- #define WRITE_RIGHT_JUSTIFIED 0x00000004
- #define WRITE_WRAP 0x00000008
-
- // First arg is size of fixed space, second arg is percent of remaining to use
- // as field width. With WRITE_WRAP, third arg is percent of remaining already
- // used, fourth arg is fixed space already used.
- #define WRITE_FIT 0x00000010
-
- // The maximum size of at least one of the arguments is unknown.
- #define WRITE_BIG 0x00000020
-
- // First formatted arg is a utf8 string.
- #define WRITE_UTF8 0x00000040
-
- VOID WriteOutputEx (DWORD flags, PCSTR fmt, ...);
-
-
- //------------------------------------------------------------------------
-
-
- enum VMReleases
- {
- VM_UNKNOWN,
- VM_IE40,
- VM_SDK30PR1,
- VM_SDK31,
- VM_CURRENT,
- };
-
-
- //------------------------------------------------------------------------
-
-
- struct ThreadRecord
- {
- ThreadID vmid;
- DWORD tid;
-
- AllocationProfilerThreadData allocdata;
- CallProfilerThreadData calldata;
- CallTracerThreadData tracedata;
- };
-
-
- //------------------------------------------------------------------------
-
-
- class EventMonitor : public IJavaEventMonitor2,
- public IObjectAllocationCallback,
- public IJVIEWProfiler
- {
- private:
-
- UINT m_refcount;
-
- IJavaEventMonitorIDInfo *m_monitor_info;
- IJavaEventMonitorIDInfo2 *m_monitor_info2;
- IJavaEventMonitorIDInfo3 *m_monitor_info3;
- IJavaEventMonitorIDInfo4 *m_monitor_info4;
-
- VMReleases m_VMRelease;
-
-
- CallProfiler m_callprof;
-
- CallTracer m_calltracer;
-
- SamplingProfiler m_sampler;
-
- AllocationProfiler m_allocprof;
-
- GCProfiler m_gcprof;
-
-
- BOOL m_fVMInitialized;
- BOOL m_fVMTerminated;
-
- VOID OnVMInitialization ();
-
-
- DWORD m_threadtls;
- CRITICAL_SECTION m_ThreadEventCS;
- ThreadRecord **m_rgpthreads;
- ULONG m_nthreads;
- ULONG m_maxthreads;
-
- ThreadRecord *CreateCurrentThreadRecord ();
- ThreadRecord *GetThreadRecord (ThreadID vmid, DWORD tid);
- ThreadRecord *CreateThreadRecord (ThreadID vmid, DWORD tid);
-
- ThreadRecord *GetCurrentThreadRecord ()
- {
- ThreadRecord *pThread = (ThreadRecord*)TlsGetValue(m_threadtls);
- if (pThread)
- return pThread;
- return CreateCurrentThreadRecord();
- }
-
-
- public:
-
- EventMonitor ();
- ~EventMonitor ();
-
- VOID ShutdownWorker (BOOL fNormal);
-
-
- IJavaEventMonitorIDInfo *GetVMInfoIfc ()
- {
- return m_monitor_info;
- }
-
- IJavaEventMonitorIDInfo2 *GetVMInfoIfc2 ()
- {
- return m_monitor_info2;
- }
-
- IJavaEventMonitorIDInfo3 *GetVMInfoIfc3 ()
- {
- return m_monitor_info3;
- }
-
-
- BOOL IsVMInitialized ()
- {
- return m_fVMInitialized;
- }
-
- BOOL IsVMTerminating ()
- {
- return m_fVMTerminated;
- }
-
-
- typedef VOID ThreadIterProc (ThreadRecord*, PVOID);
-
- VOID IterateThreads (ThreadIterProc *cb, PVOID token)
- {
- EnterCriticalSection(&m_ThreadEventCS);
- {
- unsigned i;
- unsigned nthreads = m_nthreads;
-
- ThreadRecord **pthreads = m_rgpthreads;
- for (i = 0; i < nthreads; i++)
- {
- (*cb)(pthreads[i], token);
- }
- }
- LeaveCriticalSection(&m_ThreadEventCS);
- }
-
-
- // IUnknown
-
- STDMETHODIMP QueryInterface(REFIID, void **);
- STDMETHODIMP_(ULONG) AddRef(void);
- STDMETHODIMP_(ULONG) Release(void);
-
- // IJavaEventMonitor
-
- STDMETHODIMP Initialize(LPCSTR pclass_file_name, IJavaEventMonitorIDInfo *pmonitor_info, DWORD java_flags, DWORD *prequested_events);
- STDMETHODIMP NotifyEvent(JVM_EVENT_TYPE event, UniqueID event_id);
- STDMETHODIMP MethodEntry(MethodID method_id, StackID stack_id);
- STDMETHODIMP MethodExit(StackID stack_id);
- STDMETHODIMP ExecuteByteCode(MethodID method_id, BYTE_CODE *pbyte_code, DWORD byte_code_offset);
- STDMETHODIMP ExecuteSourceLine(MethodID method_id, DWORD line_number);
-
- // IJavaEventMonitor2
-
- STDMETHODIMP NotifyEvent2(JVM_EVENT_TYPE2 event2, UniqueID first_event_id, UniqueID second_event_id);
- STDMETHODIMP MethodExit2(MethodID method_id, StackID stack_id);
- STDMETHODIMP GetPossibleEventCategories(DWORD *ppossible_events);
-
- // IObjectAllocationCallback
-
- STDMETHODIMP OnObjectAllocated(ObjectID oid, ClassID type);
-
- // IJVIEWProfiler
-
- STDMETHODIMP JVIEWInitialize (IJVIEWProfilerUtils *putils, DWORD *pflags);
-
- STDMETHODIMP ParseParameters (PCSTR pcszParams);
-
- STDMETHODIMP_(PSTR) GetUsageString ();
-
- STDMETHODIMP_(VOID) Shutdown ()
- {
- ShutdownWorker(TRUE);
- }
- };
-
-
-
-
- #endif /* __JVIEWPRF_HPP__ */
-
-