hotspot/src/share/vm/memory/classify.cpp
author never
Wed, 06 Jan 2010 14:22:39 -0800
changeset 4571 80b553bddc26
parent 1 489c9b5090e2
child 5547 f4b087cbb361
permissions -rw-r--r--
6914300: ciEnv should export all well known classes Reviewed-by: kvn, twisti
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2003-2007 Sun Microsystems, Inc.  All Rights Reserved.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
# include "incls/_precompiled.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
# include "incls/_classify.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
const char* ClassifyObjectClosure::object_type_name[number_object_types] = {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
  "unknown",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
  "instance",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
  "instanceRef",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
  "objArray",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
  "symbol",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  "klass",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  "instanceKlass",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  "method",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  "constMethod",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  "methodData",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  "constantPool",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  "constantPoolCache",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  "typeArray",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  "compiledICHolder"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
object_type ClassifyObjectClosure::classify_object(oop obj, bool count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  object_type type = unknown_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  Klass* k = obj->blueprint();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
4571
80b553bddc26 6914300: ciEnv should export all well known classes
never
parents: 1
diff changeset
    52
  if (k->as_klassOop() == SystemDictionary::Object_klass()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
    tty->print_cr("Found the class!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  if (count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
    k->set_alloc_count(k->alloc_count() + 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  if (obj->is_instance()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
    if (k->oop_is_instanceRef()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
      type = instanceRef_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
      type = instance_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  } else if (obj->is_typeArray()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
    type = typeArray_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  } else if (obj->is_objArray()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
    type = objArray_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  } else if (obj->is_symbol()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
    type = symbol_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  } else if (obj->is_klass()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
    Klass* k = ((klassOop)obj)->klass_part();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    if (k->oop_is_instance()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
      type = instanceKlass_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
      type = klass_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  } else if (obj->is_method()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
    type = method_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  } else if (obj->is_constMethod()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    type = constMethod_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  } else if (obj->is_methodData()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  } else if (obj->is_constantPool()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    type = constantPool_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  } else if (obj->is_constantPoolCache()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    type = constantPoolCache_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  } else if (obj->is_compiledICHolder()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    type = compiledICHolder_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
    ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  assert(type != unknown_type, "found object of unknown type.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  return type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
void ClassifyObjectClosure::reset() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  for (int i = 0; i < number_object_types; ++i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
    object_count[i] = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    object_size[i] = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  total_object_count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  total_object_size = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
void ClassifyObjectClosure::do_object(oop obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  int i = classify_object(obj, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  ++object_count[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  ++total_object_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  size_t size = obj->size() * HeapWordSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  object_size[i] += size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  total_object_size += size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
size_t ClassifyObjectClosure::print() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  int num_objects = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  size_t size_objects = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  for (int i = 0; i < number_object_types; ++i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
    if (object_count[i] != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
      tty->print_cr("%8d  %-22s  (%8d bytes, %5.2f bytes/object)",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
                    object_count[i], object_type_name[i], object_size[i],
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
                    (float)object_size[i]/(float)object_count[i]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
    num_objects += object_count[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
    size_objects += object_size[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  assert(num_objects == total_object_count, "Object count mismatch!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  assert(size_objects == total_object_size, "Object size mismatch!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  tty->print_cr(" Total:  %d objects, %d bytes", total_object_count,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
                total_object_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  return total_object_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
void ClassifyInstanceKlassClosure::do_object(oop obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  int type = classify_object(obj, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  if (type == instanceKlass_type || type == klass_type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
    Klass* k = ((klassOop)obj)->klass_part();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
    if (k->alloc_count() > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
      ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
      const char *name;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
      if (k->name() == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
        if (obj == Universe::klassKlassObj()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
          name = "_klassKlassObj";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
        } else if (obj == Universe::arrayKlassKlassObj()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
          name = "_arrayKlassKlassObj";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
        } else if (obj == Universe::objArrayKlassKlassObj()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
          name = "_objArrayKlassKlassObj";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
        } else if (obj == Universe::typeArrayKlassKlassObj()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
          name = "_typeArrayKlassKlassObj";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
        } else if (obj == Universe::instanceKlassKlassObj()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
          name = "_instanceKlassKlassObj";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
        } else if (obj == Universe::symbolKlassObj()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
          name = "_symbolKlassObj";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
        } else if (obj == Universe::methodKlassObj()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
          name = "_methodKlassObj";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
        } else if (obj == Universe::constMethodKlassObj()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
          name = "_constMethodKlassObj";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
        } else if (obj == Universe::constantPoolKlassObj()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
          name = "_constantPoolKlassObj";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
        } else if (obj == Universe::constantPoolCacheKlassObj()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
          name = "_constantPoolCacheKlassObj";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
        } else if (obj == Universe::compiledICHolderKlassObj()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
          name = "_compiledICHolderKlassObj";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
        } else if (obj == Universe::systemObjArrayKlassObj()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
          name = "_systemObjArrayKlassObj";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
          name = "[unnamed]";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
        name = k->external_name();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
      tty->print_cr("% 8d  instances of %s", k->alloc_count(), name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
    total_instances += k->alloc_count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
void ClassifyInstanceKlassClosure::print() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  tty->print_cr(" Total instances:  %d.", total_instances);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
void ClassifyInstanceKlassClosure::reset() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  total_instances = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
}