0N/A/*
2273N/A * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#include "precompiled.hpp"
1879N/A#include "classfile/systemDictionary.hpp"
1879N/A#include "memory/classify.hpp"
0N/A
0N/A
0N/Aconst char* ClassifyObjectClosure::object_type_name[number_object_types] = {
0N/A "unknown",
0N/A "instance",
0N/A "instanceRef",
0N/A "objArray",
0N/A "symbol",
0N/A "klass",
0N/A "instanceKlass",
0N/A "method",
0N/A "constMethod",
0N/A "methodData",
0N/A "constantPool",
0N/A "constantPoolCache",
0N/A "typeArray",
0N/A "compiledICHolder"
0N/A};
0N/A
0N/A
0N/Aobject_type ClassifyObjectClosure::classify_object(oop obj, bool count) {
0N/A object_type type = unknown_type;
0N/A
0N/A Klass* k = obj->blueprint();
0N/A
1142N/A if (k->as_klassOop() == SystemDictionary::Object_klass()) {
0N/A tty->print_cr("Found the class!");
0N/A }
0N/A
0N/A if (count) {
0N/A k->set_alloc_count(k->alloc_count() + 1);
0N/A }
0N/A
0N/A if (obj->is_instance()) {
0N/A if (k->oop_is_instanceRef()) {
0N/A type = instanceRef_type;
0N/A } else {
0N/A type = instance_type;
0N/A }
0N/A } else if (obj->is_typeArray()) {
0N/A type = typeArray_type;
0N/A } else if (obj->is_objArray()) {
0N/A type = objArray_type;
0N/A } else if (obj->is_klass()) {
0N/A Klass* k = ((klassOop)obj)->klass_part();
0N/A if (k->oop_is_instance()) {
0N/A type = instanceKlass_type;
0N/A } else {
0N/A type = klass_type;
0N/A }
0N/A } else if (obj->is_method()) {
0N/A type = method_type;
0N/A } else if (obj->is_constMethod()) {
0N/A type = constMethod_type;
0N/A } else if (obj->is_methodData()) {
0N/A ShouldNotReachHere();
0N/A } else if (obj->is_constantPool()) {
0N/A type = constantPool_type;
0N/A } else if (obj->is_constantPoolCache()) {
0N/A type = constantPoolCache_type;
0N/A } else if (obj->is_compiledICHolder()) {
0N/A type = compiledICHolder_type;
0N/A } else {
0N/A ShouldNotReachHere();
0N/A }
0N/A
0N/A assert(type != unknown_type, "found object of unknown type.");
0N/A return type;
0N/A}
0N/A
0N/A
0N/Avoid ClassifyObjectClosure::reset() {
0N/A for (int i = 0; i < number_object_types; ++i) {
0N/A object_count[i] = 0;
0N/A object_size[i] = 0;
0N/A }
0N/A total_object_count = 0;
0N/A total_object_size = 0;
0N/A}
0N/A
0N/A
0N/Avoid ClassifyObjectClosure::do_object(oop obj) {
0N/A int i = classify_object(obj, true);
0N/A ++object_count[i];
0N/A ++total_object_count;
0N/A size_t size = obj->size() * HeapWordSize;
0N/A object_size[i] += size;
0N/A total_object_size += size;
0N/A}
0N/A
0N/A
0N/Asize_t ClassifyObjectClosure::print() {
0N/A int num_objects = 0;
0N/A size_t size_objects = 0;
0N/A for (int i = 0; i < number_object_types; ++i) {
0N/A if (object_count[i] != 0) {
0N/A tty->print_cr("%8d %-22s (%8d bytes, %5.2f bytes/object)",
0N/A object_count[i], object_type_name[i], object_size[i],
0N/A (float)object_size[i]/(float)object_count[i]);
0N/A }
0N/A num_objects += object_count[i];
0N/A size_objects += object_size[i];
0N/A }
0N/A assert(num_objects == total_object_count, "Object count mismatch!");
0N/A assert(size_objects == total_object_size, "Object size mismatch!");
0N/A
0N/A tty->print_cr(" Total: %d objects, %d bytes", total_object_count,
0N/A total_object_size);
0N/A return total_object_size;
0N/A}
0N/A
0N/A
0N/Avoid ClassifyInstanceKlassClosure::do_object(oop obj) {
0N/A int type = classify_object(obj, false);
0N/A if (type == instanceKlass_type || type == klass_type) {
0N/A Klass* k = ((klassOop)obj)->klass_part();
0N/A if (k->alloc_count() > 0) {
0N/A ResourceMark rm;
0N/A const char *name;
0N/A if (k->name() == NULL) {
0N/A
0N/A if (obj == Universe::klassKlassObj()) {
0N/A name = "_klassKlassObj";
0N/A } else if (obj == Universe::arrayKlassKlassObj()) {
0N/A name = "_arrayKlassKlassObj";
0N/A } else if (obj == Universe::objArrayKlassKlassObj()) {
0N/A name = "_objArrayKlassKlassObj";
0N/A } else if (obj == Universe::typeArrayKlassKlassObj()) {
0N/A name = "_typeArrayKlassKlassObj";
0N/A } else if (obj == Universe::instanceKlassKlassObj()) {
0N/A name = "_instanceKlassKlassObj";
0N/A } else if (obj == Universe::methodKlassObj()) {
0N/A name = "_methodKlassObj";
0N/A } else if (obj == Universe::constMethodKlassObj()) {
0N/A name = "_constMethodKlassObj";
0N/A } else if (obj == Universe::constantPoolKlassObj()) {
0N/A name = "_constantPoolKlassObj";
0N/A } else if (obj == Universe::constantPoolCacheKlassObj()) {
0N/A name = "_constantPoolCacheKlassObj";
0N/A } else if (obj == Universe::compiledICHolderKlassObj()) {
0N/A name = "_compiledICHolderKlassObj";
0N/A } else if (obj == Universe::systemObjArrayKlassObj()) {
0N/A name = "_systemObjArrayKlassObj";
0N/A } else {
0N/A name = "[unnamed]";
0N/A }
0N/A } else {
0N/A name = k->external_name();
0N/A }
0N/A tty->print_cr("% 8d instances of %s", k->alloc_count(), name);
0N/A }
0N/A total_instances += k->alloc_count();
0N/A }
0N/A}
0N/A
0N/A
0N/Avoid ClassifyInstanceKlassClosure::print() {
0N/A tty->print_cr(" Total instances: %d.", total_instances);
0N/A}
0N/A
0N/A
0N/Avoid ClassifyInstanceKlassClosure::reset() {
0N/A total_instances = 0;
0N/A}