src/share/vm/oops/instanceKlassKlass.cpp

changeset 435
a61af66fc99e
child 548
ba764ed4b6f2
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/oops/instanceKlassKlass.cpp	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,809 @@
     1.4 +/*
     1.5 + * Copyright 1997-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/_instanceKlassKlass.cpp.incl"
    1.30 +
    1.31 +klassOop instanceKlassKlass::create_klass(TRAPS) {
    1.32 +  instanceKlassKlass o;
    1.33 +  KlassHandle h_this_klass(THREAD, Universe::klassKlassObj());
    1.34 +  KlassHandle k = base_create_klass(h_this_klass, header_size(), o.vtbl_value(), CHECK_NULL);
    1.35 +  // Make sure size calculation is right
    1.36 +  assert(k()->size() == align_object_size(header_size()), "wrong size for object");
    1.37 +  java_lang_Class::create_mirror(k, CHECK_NULL); // Allocate mirror
    1.38 +  return k();
    1.39 +}
    1.40 +
    1.41 +int instanceKlassKlass::oop_size(oop obj) const {
    1.42 +  assert(obj->is_klass(), "must be klass");
    1.43 +  return instanceKlass::cast(klassOop(obj))->object_size();
    1.44 +}
    1.45 +
    1.46 +bool instanceKlassKlass::oop_is_parsable(oop obj) const {
    1.47 +  assert(obj->is_klass(), "must be klass");
    1.48 +  instanceKlass* ik = instanceKlass::cast(klassOop(obj));
    1.49 +  return (!ik->null_vtbl()) && ik->object_is_parsable();
    1.50 +}
    1.51 +
    1.52 +void instanceKlassKlass::iterate_c_heap_oops(instanceKlass* ik,
    1.53 +                                             OopClosure* closure) {
    1.54 +  if (ik->oop_map_cache() != NULL) {
    1.55 +    ik->oop_map_cache()->oop_iterate(closure);
    1.56 +  }
    1.57 +
    1.58 +  if (ik->jni_ids() != NULL) {
    1.59 +    ik->jni_ids()->oops_do(closure);
    1.60 +  }
    1.61 +}
    1.62 +
    1.63 +void instanceKlassKlass::oop_follow_contents(oop obj) {
    1.64 +  assert(obj->is_klass(),"must be a klass");
    1.65 +  assert(klassOop(obj)->klass_part()->oop_is_instance_slow(), "must be instance klass");
    1.66 +
    1.67 +  instanceKlass* ik = instanceKlass::cast(klassOop(obj));
    1.68 +  ik->follow_static_fields();
    1.69 +  {
    1.70 +    HandleMark hm;
    1.71 +    ik->vtable()->oop_follow_contents();
    1.72 +    ik->itable()->oop_follow_contents();
    1.73 +  }
    1.74 +
    1.75 +  MarkSweep::mark_and_push(ik->adr_array_klasses());
    1.76 +  MarkSweep::mark_and_push(ik->adr_methods());
    1.77 +  MarkSweep::mark_and_push(ik->adr_method_ordering());
    1.78 +  MarkSweep::mark_and_push(ik->adr_local_interfaces());
    1.79 +  MarkSweep::mark_and_push(ik->adr_transitive_interfaces());
    1.80 +  MarkSweep::mark_and_push(ik->adr_fields());
    1.81 +  MarkSweep::mark_and_push(ik->adr_constants());
    1.82 +  MarkSweep::mark_and_push(ik->adr_class_loader());
    1.83 +  MarkSweep::mark_and_push(ik->adr_source_file_name());
    1.84 +  MarkSweep::mark_and_push(ik->adr_source_debug_extension());
    1.85 +  MarkSweep::mark_and_push(ik->adr_inner_classes());
    1.86 +  MarkSweep::mark_and_push(ik->adr_protection_domain());
    1.87 +  MarkSweep::mark_and_push(ik->adr_signers());
    1.88 +  MarkSweep::mark_and_push(ik->adr_generic_signature());
    1.89 +  MarkSweep::mark_and_push(ik->adr_class_annotations());
    1.90 +  MarkSweep::mark_and_push(ik->adr_fields_annotations());
    1.91 +  MarkSweep::mark_and_push(ik->adr_methods_annotations());
    1.92 +  MarkSweep::mark_and_push(ik->adr_methods_parameter_annotations());
    1.93 +  MarkSweep::mark_and_push(ik->adr_methods_default_annotations());
    1.94 +
    1.95 +  // We do not follow adr_implementors() here. It is followed later
    1.96 +  // in instanceKlass::follow_weak_klass_links()
    1.97 +
    1.98 +  klassKlass::oop_follow_contents(obj);
    1.99 +
   1.100 +  iterate_c_heap_oops(ik, &MarkSweep::mark_and_push_closure);
   1.101 +}
   1.102 +
   1.103 +#ifndef SERIALGC
   1.104 +void instanceKlassKlass::oop_follow_contents(ParCompactionManager* cm,
   1.105 +                                             oop obj) {
   1.106 +  assert(obj->is_klass(),"must be a klass");
   1.107 +  assert(klassOop(obj)->klass_part()->oop_is_instance_slow(), "must be instance klass");
   1.108 +
   1.109 +  instanceKlass* ik = instanceKlass::cast(klassOop(obj));
   1.110 +  ik->follow_static_fields(cm);
   1.111 +  ik->vtable()->oop_follow_contents(cm);
   1.112 +  ik->itable()->oop_follow_contents(cm);
   1.113 +
   1.114 +  PSParallelCompact::mark_and_push(cm, ik->adr_array_klasses());
   1.115 +  PSParallelCompact::mark_and_push(cm, ik->adr_methods());
   1.116 +  PSParallelCompact::mark_and_push(cm, ik->adr_method_ordering());
   1.117 +  PSParallelCompact::mark_and_push(cm, ik->adr_local_interfaces());
   1.118 +  PSParallelCompact::mark_and_push(cm, ik->adr_transitive_interfaces());
   1.119 +  PSParallelCompact::mark_and_push(cm, ik->adr_fields());
   1.120 +  PSParallelCompact::mark_and_push(cm, ik->adr_constants());
   1.121 +  PSParallelCompact::mark_and_push(cm, ik->adr_class_loader());
   1.122 +  PSParallelCompact::mark_and_push(cm, ik->adr_source_file_name());
   1.123 +  PSParallelCompact::mark_and_push(cm, ik->adr_source_debug_extension());
   1.124 +  PSParallelCompact::mark_and_push(cm, ik->adr_inner_classes());
   1.125 +  PSParallelCompact::mark_and_push(cm, ik->adr_protection_domain());
   1.126 +  PSParallelCompact::mark_and_push(cm, ik->adr_signers());
   1.127 +  PSParallelCompact::mark_and_push(cm, ik->adr_generic_signature());
   1.128 +  PSParallelCompact::mark_and_push(cm, ik->adr_class_annotations());
   1.129 +  PSParallelCompact::mark_and_push(cm, ik->adr_fields_annotations());
   1.130 +  PSParallelCompact::mark_and_push(cm, ik->adr_methods_annotations());
   1.131 +  PSParallelCompact::mark_and_push(cm, ik->adr_methods_parameter_annotations());
   1.132 +  PSParallelCompact::mark_and_push(cm, ik->adr_methods_default_annotations());
   1.133 +
   1.134 +  // We do not follow adr_implementor() here. It is followed later
   1.135 +  // in instanceKlass::follow_weak_klass_links()
   1.136 +
   1.137 +  klassKlass::oop_follow_contents(cm, obj);
   1.138 +
   1.139 +  PSParallelCompact::MarkAndPushClosure mark_and_push_closure(cm);
   1.140 +  iterate_c_heap_oops(ik, &mark_and_push_closure);
   1.141 +}
   1.142 +#endif // SERIALGC
   1.143 +
   1.144 +int instanceKlassKlass::oop_oop_iterate(oop obj, OopClosure* blk) {
   1.145 +  assert(obj->is_klass(),"must be a klass");
   1.146 +  assert(klassOop(obj)->klass_part()->oop_is_instance_slow(), "must be instance klass");
   1.147 +  instanceKlass* ik = instanceKlass::cast(klassOop(obj));
   1.148 +  // Get size before changing pointers.
   1.149 +  // Don't call size() or oop_size() since that is a virtual call.
   1.150 +  int size = ik->object_size();
   1.151 +
   1.152 +  ik->iterate_static_fields(blk);
   1.153 +  ik->vtable()->oop_oop_iterate(blk);
   1.154 +  ik->itable()->oop_oop_iterate(blk);
   1.155 +
   1.156 +  blk->do_oop(ik->adr_array_klasses());
   1.157 +  blk->do_oop(ik->adr_methods());
   1.158 +  blk->do_oop(ik->adr_method_ordering());
   1.159 +  blk->do_oop(ik->adr_local_interfaces());
   1.160 +  blk->do_oop(ik->adr_transitive_interfaces());
   1.161 +  blk->do_oop(ik->adr_fields());
   1.162 +  blk->do_oop(ik->adr_constants());
   1.163 +  blk->do_oop(ik->adr_class_loader());
   1.164 +  blk->do_oop(ik->adr_protection_domain());
   1.165 +  blk->do_oop(ik->adr_signers());
   1.166 +  blk->do_oop(ik->adr_source_file_name());
   1.167 +  blk->do_oop(ik->adr_source_debug_extension());
   1.168 +  blk->do_oop(ik->adr_inner_classes());
   1.169 +  for (int i = 0; i < instanceKlass::implementors_limit; i++) {
   1.170 +    blk->do_oop(&ik->adr_implementors()[i]);
   1.171 +  }
   1.172 +  blk->do_oop(ik->adr_generic_signature());
   1.173 +  blk->do_oop(ik->adr_class_annotations());
   1.174 +  blk->do_oop(ik->adr_fields_annotations());
   1.175 +  blk->do_oop(ik->adr_methods_annotations());
   1.176 +  blk->do_oop(ik->adr_methods_parameter_annotations());
   1.177 +  blk->do_oop(ik->adr_methods_default_annotations());
   1.178 +
   1.179 +  klassKlass::oop_oop_iterate(obj, blk);
   1.180 +
   1.181 +  if(ik->oop_map_cache() != NULL) ik->oop_map_cache()->oop_iterate(blk);
   1.182 +  return size;
   1.183 +}
   1.184 +
   1.185 +int instanceKlassKlass::oop_oop_iterate_m(oop obj, OopClosure* blk,
   1.186 +                                           MemRegion mr) {
   1.187 +  assert(obj->is_klass(),"must be a klass");
   1.188 +  assert(klassOop(obj)->klass_part()->oop_is_instance_slow(), "must be instance klass");
   1.189 +  instanceKlass* ik = instanceKlass::cast(klassOop(obj));
   1.190 +  // Get size before changing pointers.
   1.191 +  // Don't call size() or oop_size() since that is a virtual call.
   1.192 +  int size = ik->object_size();
   1.193 +
   1.194 +  ik->iterate_static_fields(blk, mr);
   1.195 +  ik->vtable()->oop_oop_iterate_m(blk, mr);
   1.196 +  ik->itable()->oop_oop_iterate_m(blk, mr);
   1.197 +
   1.198 +  oop* adr;
   1.199 +  adr = ik->adr_array_klasses();
   1.200 +  if (mr.contains(adr)) blk->do_oop(adr);
   1.201 +  adr = ik->adr_methods();
   1.202 +  if (mr.contains(adr)) blk->do_oop(adr);
   1.203 +  adr = ik->adr_method_ordering();
   1.204 +  if (mr.contains(adr)) blk->do_oop(adr);
   1.205 +  adr = ik->adr_local_interfaces();
   1.206 +  if (mr.contains(adr)) blk->do_oop(adr);
   1.207 +  adr = ik->adr_transitive_interfaces();
   1.208 +  if (mr.contains(adr)) blk->do_oop(adr);
   1.209 +  adr = ik->adr_fields();
   1.210 +  if (mr.contains(adr)) blk->do_oop(adr);
   1.211 +  adr = ik->adr_constants();
   1.212 +  if (mr.contains(adr)) blk->do_oop(adr);
   1.213 +  adr = ik->adr_class_loader();
   1.214 +  if (mr.contains(adr)) blk->do_oop(adr);
   1.215 +  adr = ik->adr_protection_domain();
   1.216 +  if (mr.contains(adr)) blk->do_oop(adr);
   1.217 +  adr = ik->adr_signers();
   1.218 +  if (mr.contains(adr)) blk->do_oop(adr);
   1.219 +  adr = ik->adr_source_file_name();
   1.220 +  if (mr.contains(adr)) blk->do_oop(adr);
   1.221 +  adr = ik->adr_source_debug_extension();
   1.222 +  if (mr.contains(adr)) blk->do_oop(adr);
   1.223 +  adr = ik->adr_inner_classes();
   1.224 +  if (mr.contains(adr)) blk->do_oop(adr);
   1.225 +  adr = ik->adr_implementors();
   1.226 +  for (int i = 0; i < instanceKlass::implementors_limit; i++) {
   1.227 +    if (mr.contains(&adr[i])) blk->do_oop(&adr[i]);
   1.228 +  }
   1.229 +  adr = ik->adr_generic_signature();
   1.230 +  if (mr.contains(adr)) blk->do_oop(adr);
   1.231 +  adr = ik->adr_class_annotations();
   1.232 +  if (mr.contains(adr)) blk->do_oop(adr);
   1.233 +  adr = ik->adr_fields_annotations();
   1.234 +  if (mr.contains(adr)) blk->do_oop(adr);
   1.235 +  adr = ik->adr_methods_annotations();
   1.236 +  if (mr.contains(adr)) blk->do_oop(adr);
   1.237 +  adr = ik->adr_methods_parameter_annotations();
   1.238 +  if (mr.contains(adr)) blk->do_oop(adr);
   1.239 +  adr = ik->adr_methods_default_annotations();
   1.240 +  if (mr.contains(adr)) blk->do_oop(adr);
   1.241 +
   1.242 +  klassKlass::oop_oop_iterate_m(obj, blk, mr);
   1.243 +
   1.244 +  if(ik->oop_map_cache() != NULL) ik->oop_map_cache()->oop_iterate(blk, mr);
   1.245 +  return size;
   1.246 +}
   1.247 +
   1.248 +int instanceKlassKlass::oop_adjust_pointers(oop obj) {
   1.249 +  assert(obj->is_klass(),"must be a klass");
   1.250 +  assert(klassOop(obj)->klass_part()->oop_is_instance_slow(), "must be instance klass");
   1.251 +
   1.252 +  instanceKlass* ik = instanceKlass::cast(klassOop(obj));
   1.253 +  ik->adjust_static_fields();
   1.254 +  ik->vtable()->oop_adjust_pointers();
   1.255 +  ik->itable()->oop_adjust_pointers();
   1.256 +
   1.257 +  MarkSweep::adjust_pointer(ik->adr_array_klasses());
   1.258 +  MarkSweep::adjust_pointer(ik->adr_methods());
   1.259 +  MarkSweep::adjust_pointer(ik->adr_method_ordering());
   1.260 +  MarkSweep::adjust_pointer(ik->adr_local_interfaces());
   1.261 +  MarkSweep::adjust_pointer(ik->adr_transitive_interfaces());
   1.262 +  MarkSweep::adjust_pointer(ik->adr_fields());
   1.263 +  MarkSweep::adjust_pointer(ik->adr_constants());
   1.264 +  MarkSweep::adjust_pointer(ik->adr_class_loader());
   1.265 +  MarkSweep::adjust_pointer(ik->adr_protection_domain());
   1.266 +  MarkSweep::adjust_pointer(ik->adr_signers());
   1.267 +  MarkSweep::adjust_pointer(ik->adr_source_file_name());
   1.268 +  MarkSweep::adjust_pointer(ik->adr_source_debug_extension());
   1.269 +  MarkSweep::adjust_pointer(ik->adr_inner_classes());
   1.270 +  for (int i = 0; i < instanceKlass::implementors_limit; i++) {
   1.271 +    MarkSweep::adjust_pointer(&ik->adr_implementors()[i]);
   1.272 +  }
   1.273 +  MarkSweep::adjust_pointer(ik->adr_generic_signature());
   1.274 +  MarkSweep::adjust_pointer(ik->adr_class_annotations());
   1.275 +  MarkSweep::adjust_pointer(ik->adr_fields_annotations());
   1.276 +  MarkSweep::adjust_pointer(ik->adr_methods_annotations());
   1.277 +  MarkSweep::adjust_pointer(ik->adr_methods_parameter_annotations());
   1.278 +  MarkSweep::adjust_pointer(ik->adr_methods_default_annotations());
   1.279 +
   1.280 +  iterate_c_heap_oops(ik, &MarkSweep::adjust_root_pointer_closure);
   1.281 +
   1.282 +  return klassKlass::oop_adjust_pointers(obj);
   1.283 +}
   1.284 +
   1.285 +#ifndef SERIALGC
   1.286 +void instanceKlassKlass::oop_copy_contents(PSPromotionManager* pm, oop obj) {
   1.287 +  assert(!pm->depth_first(), "invariant");
   1.288 +  instanceKlass* ik = instanceKlass::cast(klassOop(obj));
   1.289 +  ik->copy_static_fields(pm);
   1.290 +
   1.291 +  oop* loader_addr = ik->adr_class_loader();
   1.292 +  if (PSScavenge::should_scavenge(*loader_addr)) {
   1.293 +    pm->claim_or_forward_breadth(loader_addr);
   1.294 +  }
   1.295 +
   1.296 +  oop* pd_addr = ik->adr_protection_domain();
   1.297 +  if (PSScavenge::should_scavenge(*pd_addr)) {
   1.298 +    pm->claim_or_forward_breadth(pd_addr);
   1.299 +  }
   1.300 +
   1.301 +  oop* sg_addr = ik->adr_signers();
   1.302 +  if (PSScavenge::should_scavenge(*sg_addr)) {
   1.303 +    pm->claim_or_forward_breadth(sg_addr);
   1.304 +  }
   1.305 +
   1.306 +  klassKlass::oop_copy_contents(pm, obj);
   1.307 +}
   1.308 +
   1.309 +void instanceKlassKlass::oop_push_contents(PSPromotionManager* pm, oop obj) {
   1.310 +  assert(pm->depth_first(), "invariant");
   1.311 +  instanceKlass* ik = instanceKlass::cast(klassOop(obj));
   1.312 +  ik->push_static_fields(pm);
   1.313 +
   1.314 +  oop* loader_addr = ik->adr_class_loader();
   1.315 +  if (PSScavenge::should_scavenge(*loader_addr)) {
   1.316 +    pm->claim_or_forward_depth(loader_addr);
   1.317 +  }
   1.318 +
   1.319 +  oop* pd_addr = ik->adr_protection_domain();
   1.320 +  if (PSScavenge::should_scavenge(*pd_addr)) {
   1.321 +    pm->claim_or_forward_depth(pd_addr);
   1.322 +  }
   1.323 +
   1.324 +  oop* sg_addr = ik->adr_signers();
   1.325 +  if (PSScavenge::should_scavenge(*sg_addr)) {
   1.326 +    pm->claim_or_forward_depth(sg_addr);
   1.327 +  }
   1.328 +
   1.329 +  klassKlass::oop_copy_contents(pm, obj);
   1.330 +}
   1.331 +
   1.332 +int instanceKlassKlass::oop_update_pointers(ParCompactionManager* cm, oop obj) {
   1.333 +  assert(obj->is_klass(),"must be a klass");
   1.334 +  assert(klassOop(obj)->klass_part()->oop_is_instance_slow(),
   1.335 +         "must be instance klass");
   1.336 +
   1.337 +  instanceKlass* ik = instanceKlass::cast(klassOop(obj));
   1.338 +  ik->update_static_fields();
   1.339 +  ik->vtable()->oop_update_pointers(cm);
   1.340 +  ik->itable()->oop_update_pointers(cm);
   1.341 +
   1.342 +  oop* const beg_oop = ik->oop_block_beg();
   1.343 +  oop* const end_oop = ik->oop_block_end();
   1.344 +  for (oop* cur_oop = beg_oop; cur_oop < end_oop; ++cur_oop) {
   1.345 +    PSParallelCompact::adjust_pointer(cur_oop);
   1.346 +  }
   1.347 +
   1.348 +  OopClosure* closure = PSParallelCompact::adjust_root_pointer_closure();
   1.349 +  iterate_c_heap_oops(ik, closure);
   1.350 +
   1.351 +  klassKlass::oop_update_pointers(cm, obj);
   1.352 +  return ik->object_size();
   1.353 +}
   1.354 +
   1.355 +int instanceKlassKlass::oop_update_pointers(ParCompactionManager* cm, oop obj,
   1.356 +                                            HeapWord* beg_addr,
   1.357 +                                            HeapWord* end_addr) {
   1.358 +  assert(obj->is_klass(),"must be a klass");
   1.359 +  assert(klassOop(obj)->klass_part()->oop_is_instance_slow(),
   1.360 +         "must be instance klass");
   1.361 +
   1.362 +  instanceKlass* ik = instanceKlass::cast(klassOop(obj));
   1.363 +  ik->update_static_fields(beg_addr, end_addr);
   1.364 +  ik->vtable()->oop_update_pointers(cm, beg_addr, end_addr);
   1.365 +  ik->itable()->oop_update_pointers(cm, beg_addr, end_addr);
   1.366 +
   1.367 +  oop* const beg_oop = MAX2((oop*)beg_addr, ik->oop_block_beg());
   1.368 +  oop* const end_oop = MIN2((oop*)end_addr, ik->oop_block_end());
   1.369 +  for (oop* cur_oop = beg_oop; cur_oop < end_oop; ++cur_oop) {
   1.370 +    PSParallelCompact::adjust_pointer(cur_oop);
   1.371 +  }
   1.372 +
   1.373 +  // The oop_map_cache, jni_ids and jni_id_map are allocated from the C heap,
   1.374 +  // and so don't lie within any 'Chunk' boundaries.  Update them when the
   1.375 +  // lowest addressed oop in the instanceKlass 'oop_block' is updated.
   1.376 +  if (beg_oop == ik->oop_block_beg()) {
   1.377 +    OopClosure* closure = PSParallelCompact::adjust_root_pointer_closure();
   1.378 +    iterate_c_heap_oops(ik, closure);
   1.379 +  }
   1.380 +
   1.381 +  klassKlass::oop_update_pointers(cm, obj, beg_addr, end_addr);
   1.382 +  return ik->object_size();
   1.383 +}
   1.384 +#endif // SERIALGC
   1.385 +
   1.386 +klassOop instanceKlassKlass::allocate_instance_klass(int vtable_len, int itable_len, int static_field_size,
   1.387 +                                                     int nonstatic_oop_map_size, ReferenceType rt, TRAPS) {
   1.388 +
   1.389 +  int size = instanceKlass::object_size(align_object_offset(vtable_len) + align_object_offset(itable_len) + static_field_size + nonstatic_oop_map_size);
   1.390 +
   1.391 +  // Allocation
   1.392 +  KlassHandle h_this_klass(THREAD, as_klassOop());
   1.393 +  KlassHandle k;
   1.394 +  if (rt == REF_NONE) {
   1.395 +    // regular klass
   1.396 +    instanceKlass o;
   1.397 +    k = base_create_klass(h_this_klass, size, o.vtbl_value(), CHECK_NULL);
   1.398 +  } else {
   1.399 +    // reference klass
   1.400 +    instanceRefKlass o;
   1.401 +    k = base_create_klass(h_this_klass, size, o.vtbl_value(), CHECK_NULL);
   1.402 +  }
   1.403 +  {
   1.404 +    No_Safepoint_Verifier no_safepoint; // until k becomes parsable
   1.405 +    instanceKlass* ik = (instanceKlass*) k()->klass_part();
   1.406 +    assert(!k()->is_parsable(), "not expecting parsability yet.");
   1.407 +
   1.408 +    // The sizes of these these three variables are used for determining the
   1.409 +    // size of the instanceKlassOop. It is critical that these are set to the right
   1.410 +    // sizes before the first GC, i.e., when we allocate the mirror.
   1.411 +    ik->set_vtable_length(vtable_len);
   1.412 +    ik->set_itable_length(itable_len);
   1.413 +    ik->set_static_field_size(static_field_size);
   1.414 +    ik->set_nonstatic_oop_map_size(nonstatic_oop_map_size);
   1.415 +    assert(k()->size() == size, "wrong size for object");
   1.416 +
   1.417 +    ik->set_array_klasses(NULL);
   1.418 +    ik->set_methods(NULL);
   1.419 +    ik->set_method_ordering(NULL);
   1.420 +    ik->set_local_interfaces(NULL);
   1.421 +    ik->set_transitive_interfaces(NULL);
   1.422 +    ik->init_implementor();
   1.423 +    ik->set_fields(NULL);
   1.424 +    ik->set_constants(NULL);
   1.425 +    ik->set_class_loader(NULL);
   1.426 +    ik->set_protection_domain(NULL);
   1.427 +    ik->set_signers(NULL);
   1.428 +    ik->set_source_file_name(NULL);
   1.429 +    ik->set_source_debug_extension(NULL);
   1.430 +    ik->set_inner_classes(NULL);
   1.431 +    ik->set_static_oop_field_size(0);
   1.432 +    ik->set_nonstatic_field_size(0);
   1.433 +    ik->set_is_marked_dependent(false);
   1.434 +    ik->set_init_state(instanceKlass::allocated);
   1.435 +    ik->set_init_thread(NULL);
   1.436 +    ik->set_reference_type(rt);
   1.437 +    ik->set_oop_map_cache(NULL);
   1.438 +    ik->set_jni_ids(NULL);
   1.439 +    ik->set_osr_nmethods_head(NULL);
   1.440 +    ik->set_breakpoints(NULL);
   1.441 +    ik->init_previous_versions();
   1.442 +    ik->set_generic_signature(NULL);
   1.443 +    ik->release_set_methods_jmethod_ids(NULL);
   1.444 +    ik->release_set_methods_cached_itable_indices(NULL);
   1.445 +    ik->set_class_annotations(NULL);
   1.446 +    ik->set_fields_annotations(NULL);
   1.447 +    ik->set_methods_annotations(NULL);
   1.448 +    ik->set_methods_parameter_annotations(NULL);
   1.449 +    ik->set_methods_default_annotations(NULL);
   1.450 +    ik->set_enclosing_method_indices(0, 0);
   1.451 +    ik->set_jvmti_cached_class_field_map(NULL);
   1.452 +    ik->set_initial_method_idnum(0);
   1.453 +    assert(k()->is_parsable(), "should be parsable here.");
   1.454 +
   1.455 +    // initialize the non-header words to zero
   1.456 +    intptr_t* p = (intptr_t*)k();
   1.457 +    for (int index = instanceKlass::header_size(); index < size; index++) {
   1.458 +      p[index] = NULL_WORD;
   1.459 +    }
   1.460 +
   1.461 +    // To get verify to work - must be set to partial loaded before first GC point.
   1.462 +    k()->set_partially_loaded();
   1.463 +  }
   1.464 +
   1.465 +  // GC can happen here
   1.466 +  java_lang_Class::create_mirror(k, CHECK_NULL); // Allocate mirror
   1.467 +  return k();
   1.468 +}
   1.469 +
   1.470 +
   1.471 +
   1.472 +#ifndef PRODUCT
   1.473 +
   1.474 +// Printing
   1.475 +
   1.476 +static const char* state_names[] = {
   1.477 +  "unparseable_by_gc", "allocated", "loaded", "linked", "being_initialized", "fully_initialized", "initialization_error"
   1.478 +};
   1.479 +
   1.480 +
   1.481 +void instanceKlassKlass::oop_print_on(oop obj, outputStream* st) {
   1.482 +  assert(obj->is_klass(), "must be klass");
   1.483 +  instanceKlass* ik = instanceKlass::cast(klassOop(obj));
   1.484 +  klassKlass::oop_print_on(obj, st);
   1.485 +
   1.486 +  st->print(" - instance size:     %d", ik->size_helper());                        st->cr();
   1.487 +  st->print(" - klass size:        %d", ik->object_size());                        st->cr();
   1.488 +  st->print(" - access:            "); ik->access_flags().print_on(st);            st->cr();
   1.489 +  st->print(" - state:             "); st->print_cr(state_names[ik->_init_state]);
   1.490 +  st->print(" - name:              "); ik->name()->print_value_on(st);             st->cr();
   1.491 +  st->print(" - super:             "); ik->super()->print_value_on(st);            st->cr();
   1.492 +  st->print(" - sub:               ");
   1.493 +  Klass* sub = ik->subklass();
   1.494 +  int n;
   1.495 +  for (n = 0; sub != NULL; n++, sub = sub->next_sibling()) {
   1.496 +    if (n < MaxSubklassPrintSize) {
   1.497 +      sub->as_klassOop()->print_value_on(st);
   1.498 +      st->print("   ");
   1.499 +    }
   1.500 +  }
   1.501 +  if (n >= MaxSubklassPrintSize) st->print("(%d more klasses...)", n - MaxSubklassPrintSize);
   1.502 +  st->cr();
   1.503 +
   1.504 +  if (ik->is_interface()) {
   1.505 +    st->print_cr(" - nof implementors:  %d", ik->nof_implementors());
   1.506 +    int print_impl = 0;
   1.507 +    for (int i = 0; i < instanceKlass::implementors_limit; i++) {
   1.508 +      if (ik->implementor(i) != NULL) {
   1.509 +        if (++print_impl == 1)
   1.510 +          st->print_cr(" - implementor:    ");
   1.511 +        st->print("   ");
   1.512 +        ik->implementor(i)->print_value_on(st);
   1.513 +      }
   1.514 +    }
   1.515 +    if (print_impl > 0)  st->cr();
   1.516 +  }
   1.517 +
   1.518 +  st->print(" - arrays:            "); ik->array_klasses()->print_value_on(st);     st->cr();
   1.519 +  st->print(" - methods:           "); ik->methods()->print_value_on(st);           st->cr();
   1.520 +  if (Verbose) {
   1.521 +    objArrayOop methods = ik->methods();
   1.522 +    for(int i = 0; i < methods->length(); i++) {
   1.523 +      tty->print("%d : ", i); methods->obj_at(i)->print_value(); tty->cr();
   1.524 +    }
   1.525 +  }
   1.526 +  st->print(" - method ordering:   "); ik->method_ordering()->print_value_on(st);       st->cr();
   1.527 +  st->print(" - local interfaces:  "); ik->local_interfaces()->print_value_on(st);      st->cr();
   1.528 +  st->print(" - trans. interfaces: "); ik->transitive_interfaces()->print_value_on(st); st->cr();
   1.529 +  st->print(" - constants:         "); ik->constants()->print_value_on(st);         st->cr();
   1.530 +  st->print(" - class loader:      "); ik->class_loader()->print_value_on(st);      st->cr();
   1.531 +  st->print(" - protection domain: "); ik->protection_domain()->print_value_on(st); st->cr();
   1.532 +  st->print(" - signers:           "); ik->signers()->print_value_on(st);           st->cr();
   1.533 +  if (ik->source_file_name() != NULL) {
   1.534 +    st->print(" - source file:       ");
   1.535 +    ik->source_file_name()->print_value_on(st);
   1.536 +    st->cr();
   1.537 +  }
   1.538 +  if (ik->source_debug_extension() != NULL) {
   1.539 +    st->print(" - source debug extension:       ");
   1.540 +    ik->source_debug_extension()->print_value_on(st);
   1.541 +    st->cr();
   1.542 +  }
   1.543 +
   1.544 +  st->print_cr(" - previous version:       ");
   1.545 +  {
   1.546 +    ResourceMark rm;
   1.547 +    // PreviousVersionInfo objects returned via PreviousVersionWalker
   1.548 +    // contain a GrowableArray of handles. We have to clean up the
   1.549 +    // GrowableArray _after_ the PreviousVersionWalker destructor
   1.550 +    // has destroyed the handles.
   1.551 +    {
   1.552 +      PreviousVersionWalker pvw(ik);
   1.553 +      for (PreviousVersionInfo * pv_info = pvw.next_previous_version();
   1.554 +           pv_info != NULL; pv_info = pvw.next_previous_version()) {
   1.555 +        pv_info->prev_constant_pool_handle()()->print_value_on(st);
   1.556 +      }
   1.557 +      st->cr();
   1.558 +    } // pvw is cleaned up
   1.559 +  } // rm is cleaned up
   1.560 +
   1.561 +  if (ik->generic_signature() != NULL) {
   1.562 +    st->print(" - generic signature:            ");
   1.563 +    ik->generic_signature()->print_value_on(st);
   1.564 +  }
   1.565 +  st->print(" - inner classes:     "); ik->inner_classes()->print_value_on(st);     st->cr();
   1.566 +  st->print(" - java mirror:       "); ik->java_mirror()->print_value_on(st);       st->cr();
   1.567 +  st->print(" - vtable length      %d  (start addr: " INTPTR_FORMAT ")", ik->vtable_length(), ik->start_of_vtable());  st->cr();
   1.568 +  st->print(" - itable length      %d (start addr: " INTPTR_FORMAT ")", ik->itable_length(), ik->start_of_itable()); st->cr();
   1.569 +  st->print_cr(" - static fields:");
   1.570 +  FieldPrinter print_static_field(st);
   1.571 +  ik->do_local_static_fields(&print_static_field);
   1.572 +  st->print_cr(" - non-static fields:");
   1.573 +  FieldPrinter print_nonstatic_field(st, obj);
   1.574 +  ik->do_nonstatic_fields(&print_nonstatic_field);
   1.575 +
   1.576 +  st->print(" - static oop maps:     ");
   1.577 +  if (ik->static_oop_field_size() > 0) {
   1.578 +    int first_offset = ik->offset_of_static_fields();
   1.579 +    st->print("%d-%d", first_offset, first_offset + ik->static_oop_field_size() - 1);
   1.580 +  }
   1.581 +  st->cr();
   1.582 +
   1.583 +  st->print(" - non-static oop maps: ");
   1.584 +  OopMapBlock* map     = ik->start_of_nonstatic_oop_maps();
   1.585 +  OopMapBlock* end_map = map + ik->nonstatic_oop_map_size();
   1.586 +  while (map < end_map) {
   1.587 +    st->print("%d-%d ", map->offset(), map->offset() + oopSize*(map->length() - 1));
   1.588 +    map++;
   1.589 +  }
   1.590 +  st->cr();
   1.591 +}
   1.592 +
   1.593 +
   1.594 +void instanceKlassKlass::oop_print_value_on(oop obj, outputStream* st) {
   1.595 +  assert(obj->is_klass(), "must be klass");
   1.596 +  instanceKlass* ik = instanceKlass::cast(klassOop(obj));
   1.597 +  ik->name()->print_value_on(st);
   1.598 +}
   1.599 +
   1.600 +#endif // PRODUCT
   1.601 +
   1.602 +const char* instanceKlassKlass::internal_name() const {
   1.603 +  return "{instance class}";
   1.604 +}
   1.605 +
   1.606 +// Verification
   1.607 +
   1.608 +
   1.609 +class VerifyFieldClosure: public OopClosure {
   1.610 + public:
   1.611 +  void do_oop(oop* p) {
   1.612 +    guarantee(Universe::heap()->is_in(p), "should be in heap");
   1.613 +    guarantee((*p)->is_oop_or_null(), "should be in heap");
   1.614 +  }
   1.615 +};
   1.616 +
   1.617 +
   1.618 +void instanceKlassKlass::oop_verify_on(oop obj, outputStream* st) {
   1.619 +  klassKlass::oop_verify_on(obj, st);
   1.620 +  if (!obj->partially_loaded()) {
   1.621 +    Thread *thread = Thread::current();
   1.622 +    instanceKlass* ik = instanceKlass::cast(klassOop(obj));
   1.623 +
   1.624 +#ifndef PRODUCT
   1.625 +    // Avoid redundant verifies
   1.626 +    if (ik->_verify_count == Universe::verify_count()) return;
   1.627 +    ik->_verify_count = Universe::verify_count();
   1.628 +#endif
   1.629 +    // Verify that klass is present in SystemDictionary
   1.630 +    if (ik->is_loaded()) {
   1.631 +      symbolHandle h_name (thread, ik->name());
   1.632 +      Handle h_loader (thread, ik->class_loader());
   1.633 +      Handle h_obj(thread, obj);
   1.634 +      SystemDictionary::verify_obj_klass_present(h_obj, h_name, h_loader);
   1.635 +    }
   1.636 +
   1.637 +    // Verify static fields
   1.638 +    VerifyFieldClosure blk;
   1.639 +    ik->iterate_static_fields(&blk);
   1.640 +
   1.641 +    // Verify vtables
   1.642 +    if (ik->is_linked()) {
   1.643 +      ResourceMark rm(thread);
   1.644 +      // $$$ This used to be done only for m/s collections.  Doing it
   1.645 +      // always seemed a valid generalization.  (DLD -- 6/00)
   1.646 +      ik->vtable()->verify(st);
   1.647 +    }
   1.648 +
   1.649 +    // Verify oop map cache
   1.650 +    if (ik->oop_map_cache() != NULL) {
   1.651 +      ik->oop_map_cache()->verify();
   1.652 +    }
   1.653 +
   1.654 +    // Verify first subklass
   1.655 +    if (ik->subklass_oop() != NULL) {
   1.656 +      guarantee(ik->subklass_oop()->is_perm(),  "should be in permspace");
   1.657 +      guarantee(ik->subklass_oop()->is_klass(), "should be klass");
   1.658 +    }
   1.659 +
   1.660 +    // Verify siblings
   1.661 +    klassOop super = ik->super();
   1.662 +    Klass* sib = ik->next_sibling();
   1.663 +    int sib_count = 0;
   1.664 +    while (sib != NULL) {
   1.665 +      if (sib == ik) {
   1.666 +        fatal1("subclass cycle of length %d", sib_count);
   1.667 +      }
   1.668 +      if (sib_count >= 100000) {
   1.669 +        fatal1("suspiciously long subclass list %d", sib_count);
   1.670 +      }
   1.671 +      guarantee(sib->as_klassOop()->is_klass(), "should be klass");
   1.672 +      guarantee(sib->as_klassOop()->is_perm(),  "should be in permspace");
   1.673 +      guarantee(sib->super() == super, "siblings should have same superklass");
   1.674 +      sib = sib->next_sibling();
   1.675 +    }
   1.676 +
   1.677 +    // Verify implementor fields
   1.678 +    bool saw_null_impl = false;
   1.679 +    for (int i = 0; i < instanceKlass::implementors_limit; i++) {
   1.680 +      klassOop im = ik->implementor(i);
   1.681 +      if (im == NULL) { saw_null_impl = true; continue; }
   1.682 +      guarantee(!saw_null_impl, "non-nulls must preceded all nulls");
   1.683 +      guarantee(ik->is_interface(), "only interfaces should have implementor set");
   1.684 +      guarantee(i < ik->nof_implementors(), "should only have one implementor");
   1.685 +      guarantee(im->is_perm(),  "should be in permspace");
   1.686 +      guarantee(im->is_klass(), "should be klass");
   1.687 +      guarantee(!Klass::cast(klassOop(im))->is_interface(), "implementors cannot be interfaces");
   1.688 +    }
   1.689 +
   1.690 +    // Verify local interfaces
   1.691 +    objArrayOop local_interfaces = ik->local_interfaces();
   1.692 +    guarantee(local_interfaces->is_perm(),          "should be in permspace");
   1.693 +    guarantee(local_interfaces->is_objArray(),      "should be obj array");
   1.694 +    int j;
   1.695 +    for (j = 0; j < local_interfaces->length(); j++) {
   1.696 +      oop e = local_interfaces->obj_at(j);
   1.697 +      guarantee(e->is_klass() && Klass::cast(klassOop(e))->is_interface(), "invalid local interface");
   1.698 +    }
   1.699 +
   1.700 +    // Verify transitive interfaces
   1.701 +    objArrayOop transitive_interfaces = ik->transitive_interfaces();
   1.702 +    guarantee(transitive_interfaces->is_perm(),          "should be in permspace");
   1.703 +    guarantee(transitive_interfaces->is_objArray(),      "should be obj array");
   1.704 +    for (j = 0; j < transitive_interfaces->length(); j++) {
   1.705 +      oop e = transitive_interfaces->obj_at(j);
   1.706 +      guarantee(e->is_klass() && Klass::cast(klassOop(e))->is_interface(), "invalid transitive interface");
   1.707 +    }
   1.708 +
   1.709 +    // Verify methods
   1.710 +    objArrayOop methods = ik->methods();
   1.711 +    guarantee(methods->is_perm(),              "should be in permspace");
   1.712 +    guarantee(methods->is_objArray(),          "should be obj array");
   1.713 +    for (j = 0; j < methods->length(); j++) {
   1.714 +      guarantee(methods->obj_at(j)->is_method(), "non-method in methods array");
   1.715 +    }
   1.716 +    for (j = 0; j < methods->length() - 1; j++) {
   1.717 +      methodOop m1 = methodOop(methods->obj_at(j));
   1.718 +      methodOop m2 = methodOop(methods->obj_at(j + 1));
   1.719 +      guarantee(m1->name()->fast_compare(m2->name()) <= 0, "methods not sorted correctly");
   1.720 +    }
   1.721 +
   1.722 +    // Verify method ordering
   1.723 +    typeArrayOop method_ordering = ik->method_ordering();
   1.724 +    guarantee(method_ordering->is_perm(),              "should be in permspace");
   1.725 +    guarantee(method_ordering->is_typeArray(),         "should be type array");
   1.726 +    int length = method_ordering->length();
   1.727 +    if (JvmtiExport::can_maintain_original_method_order()) {
   1.728 +      guarantee(length == methods->length(),           "invalid method ordering length");
   1.729 +      jlong sum = 0;
   1.730 +      for (j = 0; j < length; j++) {
   1.731 +        int original_index = method_ordering->int_at(j);
   1.732 +        guarantee(original_index >= 0 && original_index < length, "invalid method ordering index");
   1.733 +        sum += original_index;
   1.734 +      }
   1.735 +      // Verify sum of indices 0,1,...,length-1
   1.736 +      guarantee(sum == ((jlong)length*(length-1))/2,   "invalid method ordering sum");
   1.737 +    } else {
   1.738 +      guarantee(length == 0,                           "invalid method ordering length");
   1.739 +    }
   1.740 +
   1.741 +    // Verify JNI static field identifiers
   1.742 +    if (ik->jni_ids() != NULL) {
   1.743 +      ik->jni_ids()->verify(ik->as_klassOop());
   1.744 +    }
   1.745 +
   1.746 +    // Verify other fields
   1.747 +    if (ik->array_klasses() != NULL) {
   1.748 +      guarantee(ik->array_klasses()->is_perm(),      "should be in permspace");
   1.749 +      guarantee(ik->array_klasses()->is_klass(),     "should be klass");
   1.750 +    }
   1.751 +    guarantee(ik->fields()->is_perm(),               "should be in permspace");
   1.752 +    guarantee(ik->fields()->is_typeArray(),          "should be type array");
   1.753 +    guarantee(ik->constants()->is_perm(),            "should be in permspace");
   1.754 +    guarantee(ik->constants()->is_constantPool(),    "should be constant pool");
   1.755 +    guarantee(ik->inner_classes()->is_perm(),        "should be in permspace");
   1.756 +    guarantee(ik->inner_classes()->is_typeArray(),   "should be type array");
   1.757 +    if (ik->source_file_name() != NULL) {
   1.758 +      guarantee(ik->source_file_name()->is_perm(),   "should be in permspace");
   1.759 +      guarantee(ik->source_file_name()->is_symbol(), "should be symbol");
   1.760 +    }
   1.761 +    if (ik->source_debug_extension() != NULL) {
   1.762 +      guarantee(ik->source_debug_extension()->is_perm(),   "should be in permspace");
   1.763 +      guarantee(ik->source_debug_extension()->is_symbol(), "should be symbol");
   1.764 +    }
   1.765 +    if (ik->protection_domain() != NULL) {
   1.766 +      guarantee(ik->protection_domain()->is_oop(),  "should be oop");
   1.767 +    }
   1.768 +    if (ik->signers() != NULL) {
   1.769 +      guarantee(ik->signers()->is_objArray(),       "should be obj array");
   1.770 +    }
   1.771 +    if (ik->generic_signature() != NULL) {
   1.772 +      guarantee(ik->generic_signature()->is_perm(),   "should be in permspace");
   1.773 +      guarantee(ik->generic_signature()->is_symbol(), "should be symbol");
   1.774 +    }
   1.775 +    if (ik->class_annotations() != NULL) {
   1.776 +      guarantee(ik->class_annotations()->is_typeArray(), "should be type array");
   1.777 +    }
   1.778 +    if (ik->fields_annotations() != NULL) {
   1.779 +      guarantee(ik->fields_annotations()->is_objArray(), "should be obj array");
   1.780 +    }
   1.781 +    if (ik->methods_annotations() != NULL) {
   1.782 +      guarantee(ik->methods_annotations()->is_objArray(), "should be obj array");
   1.783 +    }
   1.784 +    if (ik->methods_parameter_annotations() != NULL) {
   1.785 +      guarantee(ik->methods_parameter_annotations()->is_objArray(), "should be obj array");
   1.786 +    }
   1.787 +    if (ik->methods_default_annotations() != NULL) {
   1.788 +      guarantee(ik->methods_default_annotations()->is_objArray(), "should be obj array");
   1.789 +    }
   1.790 +  }
   1.791 +}
   1.792 +
   1.793 +
   1.794 +bool instanceKlassKlass::oop_partially_loaded(oop obj) const {
   1.795 +  assert(obj->is_klass(), "object must be klass");
   1.796 +  instanceKlass* ik = instanceKlass::cast(klassOop(obj));
   1.797 +  assert(ik->oop_is_instance(), "object must be instanceKlass");
   1.798 +  return ik->transitive_interfaces() == (objArrayOop) obj;   // Check whether transitive_interfaces points to self
   1.799 +}
   1.800 +
   1.801 +
   1.802 +// The transitive_interfaces is the last field set when loading an object.
   1.803 +void instanceKlassKlass::oop_set_partially_loaded(oop obj) {
   1.804 +  assert(obj->is_klass(), "object must be klass");
   1.805 +  instanceKlass* ik = instanceKlass::cast(klassOop(obj));
   1.806 +  // Set the layout helper to a place-holder value, until fuller initialization.
   1.807 +  // (This allows asserts in oop_is_instance to succeed.)
   1.808 +  ik->set_layout_helper(Klass::instance_layout_helper(0, true));
   1.809 +  assert(ik->oop_is_instance(), "object must be instanceKlass");
   1.810 +  assert(ik->transitive_interfaces() == NULL, "just checking");
   1.811 +  ik->set_transitive_interfaces((objArrayOop) obj);   // Temporarily set transitive_interfaces to point to self
   1.812 +}

mercurial