classify.hpp revision 1472
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen/*
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen * Copyright (c) 2003, 2007, Oracle and/or its affiliates. All rights reserved.
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen *
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen * This code is free software; you can redistribute it and/or modify it
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen * under the terms of the GNU General Public License version 2 only, as
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen * published by the Free Software Foundation.
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen *
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen * This code is distributed in the hope that it will be useful, but WITHOUT
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen * version 2 for more details (a copy is included in the LICENSE file that
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen * accompanied this code).
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen *
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen * You should have received a copy of the GNU General Public License version
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen * 2 along with this work; if not, write to the Free Software Foundation,
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen *
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen * or visit www.oracle.com if you need additional information or have any
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen * questions.
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen *
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen */
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chentypedef enum oop_type {
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen unknown_type,
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen instance_type,
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen instanceRef_type,
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen objArray_type,
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen symbol_type,
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen klass_type,
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen instanceKlass_type,
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen method_type,
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen constMethod_type,
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen methodData_type,
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen constantPool_type,
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen constantPoolCache_type,
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen typeArray_type,
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen compiledICHolder_type,
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen number_object_types
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen} object_type;
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen// Classify objects by type and keep counts.
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen// Print the count and space taken for each type.
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chenclass ClassifyObjectClosure : public ObjectClosure {
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chenprivate:
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen static const char* object_type_name[number_object_types];
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen int total_object_count;
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen size_t total_object_size;
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen int object_count[number_object_types];
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen size_t object_size[number_object_types];
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chenpublic:
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen ClassifyObjectClosure() { reset(); }
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen void reset();
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen void do_object(oop obj);
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen static object_type classify_object(oop obj, bool count);
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen size_t print();
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen};
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen// Count objects using the alloc_count field in the object's klass
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen// object.
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chenclass ClassifyInstanceKlassClosure : public ClassifyObjectClosure {
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chenprivate:
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen int total_instances;
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chenpublic:
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen ClassifyInstanceKlassClosure() { reset(); }
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen void reset();
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen void print();
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen void do_object(oop obj);
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen};
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen// Clear the alloc_count fields in all classes so that the count can be
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen// restarted.
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chenclass ClearAllocCountClosure : public ObjectClosure {
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chenpublic:
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen void do_object(oop obj) {
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen if (obj->is_klass()) {
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen Klass* k = Klass::cast((klassOop)obj);
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen k->set_alloc_count(0);
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen }
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen }
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen};
0035018c6da861f1b758fb9bf6b50245c52b48e2Raymond Chen