1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/runtime/aprofiler.hpp Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,60 @@ 1.4 +/* 1.5 + * Copyright 1997-2003 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +// A simple allocation profiler for Java. The profiler collects and prints 1.29 +// the number and total size of instances allocated per class, including 1.30 +// array classes. 1.31 +// 1.32 +// The profiler is currently global for all threads. It can be changed to a 1.33 +// per threads profiler by keeping a more elaborate data structure and calling 1.34 +// iterate_since_last_scavenge at thread switches. 1.35 + 1.36 + 1.37 +class AllocationProfiler: AllStatic { 1.38 + friend class GenCollectedHeap; 1.39 + friend class MarkSweep; 1.40 + private: 1.41 + static bool _active; // tells whether profiler is active 1.42 + static GrowableArray<klassOop>* _print_array; // temporary array for printing 1.43 + 1.44 + // Utility printing functions 1.45 + static void add_class_to_array(klassOop k); 1.46 + static void add_classes_to_array(klassOop k); 1.47 + static int compare_classes(klassOop* k1, klassOop* k2); 1.48 + static int average(size_t alloc_size, int alloc_count); 1.49 + static void sort_and_print_array(size_t cutoff); 1.50 + 1.51 + // Call for collecting allocation information. Called at scavenge, mark-sweep and disengage. 1.52 + static void iterate_since_last_gc(); 1.53 + 1.54 + public: 1.55 + // Start profiler 1.56 + static void engage(); 1.57 + // Stop profiler 1.58 + static void disengage(); 1.59 + // Tells whether profiler is active 1.60 + static bool is_active() { return _active; } 1.61 + // Print profile 1.62 + static void print(size_t cutoff); // Cutoff in total allocation size (in words) 1.63 +};