src/share/vm/memory/classify.cpp

changeset 435
a61af66fc99e
child 1577
4ce7240d622c
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/memory/classify.cpp	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,194 @@
     1.4 +/*
     1.5 + * Copyright 2003-2007 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 +# include "incls/_precompiled.incl"
    1.29 +# include "incls/_classify.cpp.incl"
    1.30 +
    1.31 +
    1.32 +const char* ClassifyObjectClosure::object_type_name[number_object_types] = {
    1.33 +  "unknown",
    1.34 +  "instance",
    1.35 +  "instanceRef",
    1.36 +  "objArray",
    1.37 +  "symbol",
    1.38 +  "klass",
    1.39 +  "instanceKlass",
    1.40 +  "method",
    1.41 +  "constMethod",
    1.42 +  "methodData",
    1.43 +  "constantPool",
    1.44 +  "constantPoolCache",
    1.45 +  "typeArray",
    1.46 +  "compiledICHolder"
    1.47 +};
    1.48 +
    1.49 +
    1.50 +object_type ClassifyObjectClosure::classify_object(oop obj, bool count) {
    1.51 +  object_type type = unknown_type;
    1.52 +
    1.53 +  Klass* k = obj->blueprint();
    1.54 +
    1.55 +  if (k->as_klassOop() == SystemDictionary::object_klass()) {
    1.56 +    tty->print_cr("Found the class!");
    1.57 +  }
    1.58 +
    1.59 +  if (count) {
    1.60 +    k->set_alloc_count(k->alloc_count() + 1);
    1.61 +  }
    1.62 +
    1.63 +  if (obj->is_instance()) {
    1.64 +    if (k->oop_is_instanceRef()) {
    1.65 +      type = instanceRef_type;
    1.66 +    } else {
    1.67 +      type = instance_type;
    1.68 +    }
    1.69 +  } else if (obj->is_typeArray()) {
    1.70 +    type = typeArray_type;
    1.71 +  } else if (obj->is_objArray()) {
    1.72 +    type = objArray_type;
    1.73 +  } else if (obj->is_symbol()) {
    1.74 +    type = symbol_type;
    1.75 +  } else if (obj->is_klass()) {
    1.76 +    Klass* k = ((klassOop)obj)->klass_part();
    1.77 +    if (k->oop_is_instance()) {
    1.78 +      type = instanceKlass_type;
    1.79 +    } else {
    1.80 +      type = klass_type;
    1.81 +    }
    1.82 +  } else if (obj->is_method()) {
    1.83 +    type = method_type;
    1.84 +  } else if (obj->is_constMethod()) {
    1.85 +    type = constMethod_type;
    1.86 +  } else if (obj->is_methodData()) {
    1.87 +    ShouldNotReachHere();
    1.88 +  } else if (obj->is_constantPool()) {
    1.89 +    type = constantPool_type;
    1.90 +  } else if (obj->is_constantPoolCache()) {
    1.91 +    type = constantPoolCache_type;
    1.92 +  } else if (obj->is_compiledICHolder()) {
    1.93 +    type = compiledICHolder_type;
    1.94 +  } else {
    1.95 +    ShouldNotReachHere();
    1.96 +  }
    1.97 +
    1.98 +  assert(type != unknown_type, "found object of unknown type.");
    1.99 +  return type;
   1.100 +}
   1.101 +
   1.102 +
   1.103 +void ClassifyObjectClosure::reset() {
   1.104 +  for (int i = 0; i < number_object_types; ++i) {
   1.105 +    object_count[i] = 0;
   1.106 +    object_size[i] = 0;
   1.107 +  }
   1.108 +  total_object_count = 0;
   1.109 +  total_object_size = 0;
   1.110 +}
   1.111 +
   1.112 +
   1.113 +void ClassifyObjectClosure::do_object(oop obj) {
   1.114 +  int i = classify_object(obj, true);
   1.115 +  ++object_count[i];
   1.116 +  ++total_object_count;
   1.117 +  size_t size = obj->size() * HeapWordSize;
   1.118 +  object_size[i] += size;
   1.119 +  total_object_size += size;
   1.120 +}
   1.121 +
   1.122 +
   1.123 +size_t ClassifyObjectClosure::print() {
   1.124 +  int num_objects = 0;
   1.125 +  size_t size_objects = 0;
   1.126 +  for (int i = 0; i < number_object_types; ++i) {
   1.127 +    if (object_count[i] != 0) {
   1.128 +      tty->print_cr("%8d  %-22s  (%8d bytes, %5.2f bytes/object)",
   1.129 +                    object_count[i], object_type_name[i], object_size[i],
   1.130 +                    (float)object_size[i]/(float)object_count[i]);
   1.131 +    }
   1.132 +    num_objects += object_count[i];
   1.133 +    size_objects += object_size[i];
   1.134 +  }
   1.135 +  assert(num_objects == total_object_count, "Object count mismatch!");
   1.136 +  assert(size_objects == total_object_size, "Object size mismatch!");
   1.137 +
   1.138 +  tty->print_cr(" Total:  %d objects, %d bytes", total_object_count,
   1.139 +                total_object_size);
   1.140 +  return total_object_size;
   1.141 +}
   1.142 +
   1.143 +
   1.144 +void ClassifyInstanceKlassClosure::do_object(oop obj) {
   1.145 +  int type = classify_object(obj, false);
   1.146 +  if (type == instanceKlass_type || type == klass_type) {
   1.147 +    Klass* k = ((klassOop)obj)->klass_part();
   1.148 +    if (k->alloc_count() > 0) {
   1.149 +      ResourceMark rm;
   1.150 +      const char *name;
   1.151 +      if (k->name() == NULL) {
   1.152 +
   1.153 +        if (obj == Universe::klassKlassObj()) {
   1.154 +          name = "_klassKlassObj";
   1.155 +        } else if (obj == Universe::arrayKlassKlassObj()) {
   1.156 +          name = "_arrayKlassKlassObj";
   1.157 +        } else if (obj == Universe::objArrayKlassKlassObj()) {
   1.158 +          name = "_objArrayKlassKlassObj";
   1.159 +        } else if (obj == Universe::typeArrayKlassKlassObj()) {
   1.160 +          name = "_typeArrayKlassKlassObj";
   1.161 +        } else if (obj == Universe::instanceKlassKlassObj()) {
   1.162 +          name = "_instanceKlassKlassObj";
   1.163 +        } else if (obj == Universe::symbolKlassObj()) {
   1.164 +          name = "_symbolKlassObj";
   1.165 +        } else if (obj == Universe::methodKlassObj()) {
   1.166 +          name = "_methodKlassObj";
   1.167 +        } else if (obj == Universe::constMethodKlassObj()) {
   1.168 +          name = "_constMethodKlassObj";
   1.169 +        } else if (obj == Universe::constantPoolKlassObj()) {
   1.170 +          name = "_constantPoolKlassObj";
   1.171 +        } else if (obj == Universe::constantPoolCacheKlassObj()) {
   1.172 +          name = "_constantPoolCacheKlassObj";
   1.173 +        } else if (obj == Universe::compiledICHolderKlassObj()) {
   1.174 +          name = "_compiledICHolderKlassObj";
   1.175 +        } else if (obj == Universe::systemObjArrayKlassObj()) {
   1.176 +          name = "_systemObjArrayKlassObj";
   1.177 +        } else {
   1.178 +          name = "[unnamed]";
   1.179 +        }
   1.180 +      } else {
   1.181 +        name = k->external_name();
   1.182 +      }
   1.183 +      tty->print_cr("% 8d  instances of %s", k->alloc_count(), name);
   1.184 +    }
   1.185 +    total_instances += k->alloc_count();
   1.186 +  }
   1.187 +}
   1.188 +
   1.189 +
   1.190 +void ClassifyInstanceKlassClosure::print() {
   1.191 +  tty->print_cr(" Total instances:  %d.", total_instances);
   1.192 +}
   1.193 +
   1.194 +
   1.195 +void ClassifyInstanceKlassClosure::reset() {
   1.196 +  total_instances = 0;
   1.197 +}

mercurial