src/share/vm/memory/classify.cpp

Thu, 24 Mar 2011 15:47:01 -0700

author
ysr
date
Thu, 24 Mar 2011 15:47:01 -0700
changeset 2710
5134fa1cfe63
parent 2497
3582bf76420e
child 2708
1d1603768966
permissions
-rw-r--r--

7029036: Card-table verification hangs with all framework collectors, except G1, even before the first GC
Summary: When verifying clean card ranges, use memory-range-bounded iteration over oops of objects overlapping that range, thus avoiding the otherwise quadratic worst-case cost of scanning large object arrays.
Reviewed-by: jmasa, jwilhelm, tonyp

     1 /*
     2  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  *
    23  */
    25 #include "precompiled.hpp"
    26 #include "classfile/systemDictionary.hpp"
    27 #include "memory/classify.hpp"
    30 const char* ClassifyObjectClosure::object_type_name[number_object_types] = {
    31   "unknown",
    32   "instance",
    33   "instanceRef",
    34   "objArray",
    35   "symbol",
    36   "klass",
    37   "instanceKlass",
    38   "method",
    39   "constMethod",
    40   "methodData",
    41   "constantPool",
    42   "constantPoolCache",
    43   "typeArray",
    44   "compiledICHolder"
    45 };
    48 object_type ClassifyObjectClosure::classify_object(oop obj, bool count) {
    49   object_type type = unknown_type;
    51   Klass* k = obj->blueprint();
    53   if (k->as_klassOop() == SystemDictionary::Object_klass()) {
    54     tty->print_cr("Found the class!");
    55   }
    57   if (count) {
    58     k->set_alloc_count(k->alloc_count() + 1);
    59   }
    61   if (obj->is_instance()) {
    62     if (k->oop_is_instanceRef()) {
    63       type = instanceRef_type;
    64     } else {
    65       type = instance_type;
    66     }
    67   } else if (obj->is_typeArray()) {
    68     type = typeArray_type;
    69   } else if (obj->is_objArray()) {
    70     type = objArray_type;
    71   } else if (obj->is_klass()) {
    72     Klass* k = ((klassOop)obj)->klass_part();
    73     if (k->oop_is_instance()) {
    74       type = instanceKlass_type;
    75     } else {
    76       type = klass_type;
    77     }
    78   } else if (obj->is_method()) {
    79     type = method_type;
    80   } else if (obj->is_constMethod()) {
    81     type = constMethod_type;
    82   } else if (obj->is_methodData()) {
    83     ShouldNotReachHere();
    84   } else if (obj->is_constantPool()) {
    85     type = constantPool_type;
    86   } else if (obj->is_constantPoolCache()) {
    87     type = constantPoolCache_type;
    88   } else if (obj->is_compiledICHolder()) {
    89     type = compiledICHolder_type;
    90   } else {
    91     ShouldNotReachHere();
    92   }
    94   assert(type != unknown_type, "found object of unknown type.");
    95   return type;
    96 }
    99 void ClassifyObjectClosure::reset() {
   100   for (int i = 0; i < number_object_types; ++i) {
   101     object_count[i] = 0;
   102     object_size[i] = 0;
   103   }
   104   total_object_count = 0;
   105   total_object_size = 0;
   106 }
   109 void ClassifyObjectClosure::do_object(oop obj) {
   110   int i = classify_object(obj, true);
   111   ++object_count[i];
   112   ++total_object_count;
   113   size_t size = obj->size() * HeapWordSize;
   114   object_size[i] += size;
   115   total_object_size += size;
   116 }
   119 size_t ClassifyObjectClosure::print() {
   120   int num_objects = 0;
   121   size_t size_objects = 0;
   122   for (int i = 0; i < number_object_types; ++i) {
   123     if (object_count[i] != 0) {
   124       tty->print_cr("%8d  %-22s  (%8d bytes, %5.2f bytes/object)",
   125                     object_count[i], object_type_name[i], object_size[i],
   126                     (float)object_size[i]/(float)object_count[i]);
   127     }
   128     num_objects += object_count[i];
   129     size_objects += object_size[i];
   130   }
   131   assert(num_objects == total_object_count, "Object count mismatch!");
   132   assert(size_objects == total_object_size, "Object size mismatch!");
   134   tty->print_cr(" Total:  %d objects, %d bytes", total_object_count,
   135                 total_object_size);
   136   return total_object_size;
   137 }
   140 void ClassifyInstanceKlassClosure::do_object(oop obj) {
   141   int type = classify_object(obj, false);
   142   if (type == instanceKlass_type || type == klass_type) {
   143     Klass* k = ((klassOop)obj)->klass_part();
   144     if (k->alloc_count() > 0) {
   145       ResourceMark rm;
   146       const char *name;
   147       if (k->name() == NULL) {
   149         if (obj == Universe::klassKlassObj()) {
   150           name = "_klassKlassObj";
   151         } else if (obj == Universe::arrayKlassKlassObj()) {
   152           name = "_arrayKlassKlassObj";
   153         } else if (obj == Universe::objArrayKlassKlassObj()) {
   154           name = "_objArrayKlassKlassObj";
   155         } else if (obj == Universe::typeArrayKlassKlassObj()) {
   156           name = "_typeArrayKlassKlassObj";
   157         } else if (obj == Universe::instanceKlassKlassObj()) {
   158           name = "_instanceKlassKlassObj";
   159         } else if (obj == Universe::methodKlassObj()) {
   160           name = "_methodKlassObj";
   161         } else if (obj == Universe::constMethodKlassObj()) {
   162           name = "_constMethodKlassObj";
   163         } else if (obj == Universe::constantPoolKlassObj()) {
   164           name = "_constantPoolKlassObj";
   165         } else if (obj == Universe::constantPoolCacheKlassObj()) {
   166           name = "_constantPoolCacheKlassObj";
   167         } else if (obj == Universe::compiledICHolderKlassObj()) {
   168           name = "_compiledICHolderKlassObj";
   169         } else if (obj == Universe::systemObjArrayKlassObj()) {
   170           name = "_systemObjArrayKlassObj";
   171         } else {
   172           name = "[unnamed]";
   173         }
   174       } else {
   175         name = k->external_name();
   176       }
   177       tty->print_cr("% 8d  instances of %s", k->alloc_count(), name);
   178     }
   179     total_instances += k->alloc_count();
   180   }
   181 }
   184 void ClassifyInstanceKlassClosure::print() {
   185   tty->print_cr(" Total instances:  %d.", total_instances);
   186 }
   189 void ClassifyInstanceKlassClosure::reset() {
   190   total_instances = 0;
   191 }

mercurial