coherence/lang/AbstractHeapAnalyzer.hpp

00001 /*
00002 * AbstractHeapAnalyzer.hpp
00003 *
00004 * Copyright 2001-2008 by Oracle. All rights reserved.
00005 *
00006 * Oracle is a registered trademarks of Oracle Corporation and/or its
00007 * affiliates.
00008 *
00009 * This software is the confidential and proprietary information of Oracle
00010 * Corporation. You shall not disclose such confidential and proprietary
00011 * information and shall use it only in accordance with the terms of the
00012 * license agreement you entered into with Oracle.
00013 *
00014 * This notice may not be removed or altered.
00015 */
00016 #ifndef COH_ABSTRACT_HEAP_ANALYZER_HPP
00017 #define COH_ABSTRACT_HEAP_ANALYZER_HPP
00018 
00019 #include "coherence/lang/compatibility.hpp"
00020 
00021 
00022 #include "coherence/lang/abstract_spec.hpp"
00023 #include "coherence/lang/HeapAnalyzer.hpp"
00024 
00025 #include <ostream>
00026 
00027 COH_OPEN_NAMESPACE2(coherence,native)
00028 class NativeThreadLocal;
00029 COH_CLOSE_NAMESPACE2
00030 
00031 COH_OPEN_NAMESPACE2(coherence,lang)
00032 
00033 using coherence::native::NativeThreadLocal;
00034 
00035 
00036 /**
00037 * AbstractHeapAnalyzer provides a starting point for writting custom heap
00038 * analyzers. Most notibly it includes support for detecting analyzer
00039 * reentrance so that analyzers can avoid endlessly recursing if they create
00040 * objects as part of the registration process.
00041 *
00042 * @author mf  2008.04.27
00043 */
00044 class COH_EXPORT AbstractHeapAnalyzer
00045     : public abstract_spec<AbstractHeapAnalyzer,
00046         extends<Object>,
00047         implements<HeapAnalyzer> >
00048     {
00049     // ----- constructor ----------------------------------------------------
00050 
00051     protected:
00052         /**
00053         * @internal
00054         */
00055         AbstractHeapAnalyzer();
00056 
00057         /**
00058         * @internal
00059         */
00060         virtual ~AbstractHeapAnalyzer();
00061 
00062 
00063     // ----- AbstractHeapAnalyzer methods -----------------------------------
00064 
00065     protected:
00066         /**
00067         * Registers an object with the heap analyzer.
00068         *
00069         * @param o  the object to register
00070         */
00071         virtual void safeRegisterObject(const Object& o) = 0;
00072 
00073         /**
00074         * Unregisters an object with the heap analyzer.
00075         *
00076         * @param o  the object to unregister
00077         */
00078         virtual void safeUnregisterObject(const Object& o) = 0;
00079 
00080 
00081     // ----- HeapAnalyzer interface -----------------------------------------
00082 
00083     protected:
00084         /**
00085         * {@inheritDoc}
00086         *
00087         * If the calling thread is reentering this method return immediatley
00088         * otherwise delegates to safeRegisterObject.
00089         */
00090         virtual void registerObject(const Object& o);
00091 
00092         /**
00093         * {@inheritDoc}
00094         *
00095         * If the calling thread is reentering this method return immediatley
00096         * otherwise delegates to safeUnregisterObject.
00097         */
00098         virtual void unregisterObject(const Object& o);
00099 
00100 
00101     // ----- Object interface -----------------------------------------------
00102 
00103     public:
00104         /**
00105         * Capture a snapshot and output it to the supplied stream.
00106         *
00107         * @param out  the stream to output to
00108         */
00109         virtual void toStream(std::ostream& out) const;
00110 
00111 
00112     // ----- data members ---------------------------------------------------
00113 
00114     private:
00115         /**
00116         * Tracks if the calling thread is within the analyzer.
00117         *
00118         * The use of ThreadLocalReference here is not suitable, as it is a
00119         * managed object, and causes recursion into the HeapAnalyzer.
00120         */
00121         NativeThreadLocal* const m_pTLContext;
00122     };
00123 
00124 COH_CLOSE_NAMESPACE2
00125 
00126 #endif // COH_ABSTRACT_HEAP_ANALYZER_HPP
Copyright (c) 2000-2008 Oracle. All rights reserved.