hotspot/src/share/vm/memory/classify.cpp
author ysr
Wed, 07 Sep 2011 13:55:42 -0700
changeset 10526 3e92f211533f
parent 8921 14bfe81f2a9d
permissions -rw-r--r--
4965777: GC changes to support use of discovered field for pending references Summary: If and when the reference handler thread is able to use the discovered field to link reference objects in its pending list, so will GC. In that case, GC will scan through this field once a reference object has been placed on the pending list, but not scan that field before that stage, as the field is used by the concurrent GC thread to link discovered objects. When ReferenceHandleR thread does not use the discovered field for the purpose of linking the elements in the pending list, as would be the case in older JDKs, the JVM will fall back to the old behaviour of using the next field for that purpose. Reviewed-by: jcoomes, mchung, stefank
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
8921
14bfe81f2a9d 7010070: Update all 2010 Oracle-changed OpenJDK files to have the proper copyright dates - second pass
trims
parents: 8076
diff changeset
     2
 * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
1
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
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4571
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4571
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4571
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#include "classfile/systemDictionary.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
#include "memory/classify.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
const char* ClassifyObjectClosure::object_type_name[number_object_types] = {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
  "unknown",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
  "instance",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
  "instanceRef",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
  "objArray",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  "symbol",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  "klass",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  "instanceKlass",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  "method",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  "constMethod",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  "methodData",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  "constantPool",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  "constantPoolCache",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  "typeArray",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  "compiledICHolder"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
object_type ClassifyObjectClosure::classify_object(oop obj, bool count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  object_type type = unknown_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  Klass* k = obj->blueprint();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
4571
80b553bddc26 6914300: ciEnv should export all well known classes
never
parents: 1
diff changeset
    53
  if (k->as_klassOop() == SystemDictionary::Object_klass()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
    tty->print_cr("Found the class!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  if (count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    k->set_alloc_count(k->alloc_count() + 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  if (obj->is_instance()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
    if (k->oop_is_instanceRef()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
      type = instanceRef_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
      type = instance_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  } else if (obj->is_typeArray()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
    type = typeArray_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  } else if (obj->is_objArray()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
    type = objArray_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  } else if (obj->is_klass()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
    Klass* k = ((klassOop)obj)->klass_part();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
    if (k->oop_is_instance()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
      type = instanceKlass_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
      type = klass_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  } else if (obj->is_method()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
    type = method_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  } else if (obj->is_constMethod()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
    type = constMethod_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  } else if (obj->is_methodData()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
    ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  } else if (obj->is_constantPool()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    type = constantPool_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  } else if (obj->is_constantPoolCache()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    type = constantPoolCache_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  } else if (obj->is_compiledICHolder()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    type = compiledICHolder_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  assert(type != unknown_type, "found object of unknown type.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  return type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
void ClassifyObjectClosure::reset() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  for (int i = 0; i < number_object_types; ++i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    object_count[i] = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
    object_size[i] = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  total_object_count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  total_object_size = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
void ClassifyObjectClosure::do_object(oop obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  int i = classify_object(obj, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  ++object_count[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  ++total_object_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  size_t size = obj->size() * HeapWordSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  object_size[i] += size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  total_object_size += size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
size_t ClassifyObjectClosure::print() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  int num_objects = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  size_t size_objects = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  for (int i = 0; i < number_object_types; ++i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
    if (object_count[i] != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
      tty->print_cr("%8d  %-22s  (%8d bytes, %5.2f bytes/object)",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
                    object_count[i], object_type_name[i], object_size[i],
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
                    (float)object_size[i]/(float)object_count[i]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
    num_objects += object_count[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
    size_objects += object_size[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  assert(num_objects == total_object_count, "Object count mismatch!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  assert(size_objects == total_object_size, "Object size mismatch!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  tty->print_cr(" Total:  %d objects, %d bytes", total_object_count,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
                total_object_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  return total_object_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
void ClassifyInstanceKlassClosure::do_object(oop obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  int type = classify_object(obj, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  if (type == instanceKlass_type || type == klass_type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
    Klass* k = ((klassOop)obj)->klass_part();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
    if (k->alloc_count() > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
      ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
      const char *name;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
      if (k->name() == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
        if (obj == Universe::klassKlassObj()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
          name = "_klassKlassObj";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
        } else if (obj == Universe::arrayKlassKlassObj()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
          name = "_arrayKlassKlassObj";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
        } else if (obj == Universe::objArrayKlassKlassObj()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
          name = "_objArrayKlassKlassObj";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
        } else if (obj == Universe::typeArrayKlassKlassObj()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
          name = "_typeArrayKlassKlassObj";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
        } else if (obj == Universe::instanceKlassKlassObj()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
          name = "_instanceKlassKlassObj";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
        } else if (obj == Universe::methodKlassObj()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
          name = "_methodKlassObj";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
        } else if (obj == Universe::constMethodKlassObj()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
          name = "_constMethodKlassObj";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
        } else if (obj == Universe::constantPoolKlassObj()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
          name = "_constantPoolKlassObj";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
        } else if (obj == Universe::constantPoolCacheKlassObj()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
          name = "_constantPoolCacheKlassObj";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
        } else if (obj == Universe::compiledICHolderKlassObj()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
          name = "_compiledICHolderKlassObj";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
        } else if (obj == Universe::systemObjArrayKlassObj()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
          name = "_systemObjArrayKlassObj";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
          name = "[unnamed]";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
        name = k->external_name();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
      tty->print_cr("% 8d  instances of %s", k->alloc_count(), name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
    total_instances += k->alloc_count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
void ClassifyInstanceKlassClosure::print() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  tty->print_cr(" Total instances:  %d.", total_instances);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
void ClassifyInstanceKlassClosure::reset() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  total_instances = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
}