Oracle® Fusion Middleware C++ API Reference for Oracle Coherence
12c (12.2.1.1.0)

E69640-01

coherence/lang/ClassBasedHeapAnalyzer.hpp

00001 /*
00002 * ClassBasedHeapAnalyzer.hpp
00003 *
00004 * Copyright (c) 2000, 2016, Oracle and/or its affiliates. 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_CLASS_BASED_HEAP_ANALYZER_HPP
00017 #define COH_CLASS_BASED_HEAP_ANALYZER_HPP
00018 
00019 #include "coherence/lang/compatibility.hpp"
00020 
00021 #include "coherence/lang/AbstractHeapAnalyzer.hpp"
00022 #include "coherence/lang/Comparable.hpp"
00023 #include "coherence/lang/FinalView.hpp"
00024 
00025 #include "coherence/native/NativeAtomic64.hpp"
00026 
00027 
00028 
00029 COH_OPEN_NAMESPACE2(coherence,util)
00030 class Map;
00031 COH_CLOSE_NAMESPACE2
00032 
00033 COH_OPEN_NAMESPACE2(coherence,lang)
00034 
00035 using coherence::util::Map;
00036 using coherence::native::NativeAtomic64;
00037 
00038 /**
00039 * ClassBasedHeapAnalyzer provides heap analysis at the class level, that is
00040 * it tracks the number of live instances of each class.
00041 *
00042 * The memory consumption of this heap analyzer is relative to the number of
00043 * classes used within the process. The CPU consumption is also very low, each
00044 * registration consists of roughly four compare-and-set operations. It is well
00045 * suited for development as well as many production environments.
00046 *
00047 * @see ObjectCountHeapAnalyzer for a lower overhead analyzer
00048 *
00049 * @author mf  2008.04.27
00050 */
00051 class COH_EXPORT ClassBasedHeapAnalyzer
00052     : public class_spec<ClassBasedHeapAnalyzer,
00053         extends<AbstractHeapAnalyzer> >
00054     {
00055     friend class factory<ClassBasedHeapAnalyzer>;
00056 
00057     // ----- constructor ----------------------------------------------------
00058 
00059     protected:
00060         /**
00061         * Create a new ClassBasedHeapAnalyzer.
00062         *
00063         * @param fShowAllocations  true if allocations should also be shown
00064         */
00065         ClassBasedHeapAnalyzer(bool fShowAllocations = false);
00066 
00067 
00068     // ----- nested class: ClassStats ---------------------------------------
00069 
00070     public:
00071         /**
00072         * Statistics relating to a class.
00073         */
00074         class COH_EXPORT ClassStats
00075             : public class_spec<ClassStats,
00076                 extends<Object>,
00077                 implements<Comparable> >
00078             {
00079             friend class factory<ClassStats>;
00080 
00081             protected:
00082                 /**
00083                 * Create a new ClassStats.
00084                 *
00085                 * @param cObjs   the instance count
00086                 * @param cBytes  the byte count
00087                 * @param cAlloc  the allocation count
00088                 * @return the new ClassStats
00089                 */
00090                 ClassStats(int64_t cObjs, int64_t cBytes, int64_t cAlloc);
00091 
00092             // ----- ClassStats interface ---------------------------------
00093 
00094             public:
00095                 /**
00096                 * Return the instance count for the class.
00097                 */
00098                 virtual int64_t getObjectCount() const;
00099 
00100                 /**
00101                 * Return the byte count for the class.
00102                 */
00103                 virtual int64_t getByteCount() const;
00104 
00105                 /**
00106                 * Return the allocation count for the class.
00107                 */
00108                 virtual int64_t getAllocationCount() const;
00109 
00110             // ----- Comparable interface ---------------------------------
00111 
00112             public:
00113                 /**
00114                 * {@inheritDoc}
00115                 */
00116                 int32_t compareTo(Object::View v) const;
00117 
00118             // ----- Object interface -------------------------------------
00119 
00120             public:
00121                 /**
00122                 * {@inheritDoc}
00123                 */
00124                 virtual TypedHandle<const String> toString() const;
00125 
00126             // ----- data members -----------------------------------------
00127 
00128             protected:
00129                 /**
00130                 * The number of instances of the class.
00131                 */
00132                 int64_t m_cInstanceCount;
00133 
00134                 /**
00135                 * The byte size of all the instances.
00136                 */
00137                 int64_t m_cByteCount;
00138 
00139                 /**
00140                 * The total number of allocations of the class.
00141                 */
00142                 int64_t m_cAllocationCount;
00143             };
00144 
00145     // ----- nested class: Snapshot -----------------------------------------
00146 
00147     public:
00148         /**
00149         * Snapshot containing the object count.
00150         */
00151         class COH_EXPORT Snapshot
00152             : public class_spec<Snapshot,
00153                 extends<Object>,
00154                 implements<HeapAnalyzer::Snapshot> >
00155             {
00156             friend class factory<Snapshot>;
00157 
00158             // ----- constructors ---------------------------------------
00159 
00160             protected:
00161                 /**
00162                 * Create a new Snapshot.
00163                 */
00164                 Snapshot(TypedHandle<const Map> vMap, bool fShowAllocations);
00165 
00166             // ----- Snapshot interface ---------------------------------
00167 
00168             public:
00169                 /**
00170                 * Return the Snapshots map of class names to ClassStats.
00171                 *
00172                 * The keys are class names, the values are ClassStats.
00173                 *
00174                 * @return the snapshots map.
00175                 */
00176                 virtual TypedHandle<const Map> getStatsMap() const;
00177 
00178                 /**
00179                 * {@inheritDoc}
00180                 */
00181                 virtual int64_t getObjectCount() const;
00182 
00183                 /**
00184                 * {@inheritDoc}
00185                 */
00186                 virtual HeapAnalyzer::Snapshot::View delta(
00187                         HeapAnalyzer::Snapshot::View vThat) const;
00188 
00189             // ----- Object interface: ----------------------------------
00190 
00191             public:
00192                 /**
00193                 * {@inheritDoc}
00194                 */
00195                 virtual TypedHandle<const String> toString() const;
00196 
00197             // ----- data members ---------------------------------------
00198 
00199             protected:
00200                 /**
00201                 * The map of class names to ClassStats.
00202                 */
00203                 FinalView<Object> f_vMapStats;
00204 
00205                 /**
00206                 * True if allocations are to be shown.
00207                 */
00208                 bool m_fShowAllocations;
00209             };
00210 
00211 
00212     // ----- AbstractHeapAnalyzer interface ---------------------------------
00213 
00214     protected:
00215         /**
00216         * {@inheritDoc}
00217         */
00218         virtual void safeRegisterObject(const Object& o);
00219 
00220         /**
00221         * {@inheritDoc}
00222         */
00223         virtual void safeUnregisterObject(const Object& o);
00224 
00225 
00226     // ----- HeapAnalyzer interface -----------------------------------------
00227 
00228     public:
00229         /**
00230         * {@inheritDoc}
00231         */
00232         virtual HeapAnalyzer::Snapshot::View capture() const;
00233 
00234         /**
00235         * {@inheritDoc}
00236         */
00237         virtual HeapAnalyzer::Snapshot::View delta(
00238                 HeapAnalyzer::Snapshot::View vSnap) const;
00239 
00240         /**
00241         * {@inheritDoc}
00242         */
00243         virtual int64_t getObjectCount() const;
00244 
00245         /**
00246         * {@inheritDoc}
00247         */
00248         virtual int64_t getImmortalCount() const;
00249 
00250     protected:
00251         /**
00252         * {@inheritDoc}
00253         */
00254         virtual void registerObject(const Object& o);
00255 
00256         /**
00257         * {@inheritDoc}
00258         */
00259         virtual void unregisterObject(const Object& o);
00260 
00261         /**
00262         * {@inheritDoc}
00263         */
00264         virtual void registerImmortal(const Object& o);
00265 
00266 
00267     // ----- data members ---------------------------------------------------
00268 
00269     protected:
00270         /**
00271         * True if allocations should be printed as part of analysis.
00272         */
00273         bool m_fShowAllocations;
00274 
00275         /**
00276          * The number of immortal objects.
00277          */
00278         NativeAtomic64 m_cImmortals;
00279 
00280 
00281     // ----- friends --------------------------------------------------------
00282 
00283     friend class Snapshot;
00284     };
00285 
00286 COH_CLOSE_NAMESPACE2
00287 
00288 #endif // COH_CLASS_BASED_HEAP_ANALYZER_HPP
Copyright © 2000, 2016, Oracle and/or its affiliates. All rights reserved.