annotate src/share/vm/oops/klass.cpp @ 1142:4ce7240d622c

6914300: ciEnv should export all well known classes Reviewed-by: kvn, twisti
author never
date Wed, 06 Jan 2010 14:22:39 -0800
parents 987e948ebbc8
children 4e6abf09f540
rev   line source
duke@0 1 /*
xdono@196 2 * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved.
duke@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@0 4 *
duke@0 5 * This code is free software; you can redistribute it and/or modify it
duke@0 6 * under the terms of the GNU General Public License version 2 only, as
duke@0 7 * published by the Free Software Foundation.
duke@0 8 *
duke@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@0 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@0 13 * accompanied this code).
duke@0 14 *
duke@0 15 * You should have received a copy of the GNU General Public License version
duke@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@0 18 *
duke@0 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@0 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@0 21 * have any questions.
duke@0 22 *
duke@0 23 */
duke@0 24
duke@0 25 # include "incls/_precompiled.incl"
duke@0 26 # include "incls/_klass.cpp.incl"
duke@0 27
duke@0 28
duke@0 29 bool Klass::is_subclass_of(klassOop k) const {
duke@0 30 // Run up the super chain and check
duke@0 31 klassOop t = as_klassOop();
duke@0 32
duke@0 33 if (t == k) return true;
duke@0 34 t = Klass::cast(t)->super();
duke@0 35
duke@0 36 while (t != NULL) {
duke@0 37 if (t == k) return true;
duke@0 38 t = Klass::cast(t)->super();
duke@0 39 }
duke@0 40 return false;
duke@0 41 }
duke@0 42
duke@0 43 bool Klass::search_secondary_supers(klassOop k) const {
duke@0 44 // Put some extra logic here out-of-line, before the search proper.
duke@0 45 // This cuts down the size of the inline method.
duke@0 46
duke@0 47 // This is necessary, since I am never in my own secondary_super list.
duke@0 48 if (this->as_klassOop() == k)
duke@0 49 return true;
duke@0 50 // Scan the array-of-objects for a match
duke@0 51 int cnt = secondary_supers()->length();
duke@0 52 for (int i = 0; i < cnt; i++) {
duke@0 53 if (secondary_supers()->obj_at(i) == k) {
duke@0 54 ((Klass*)this)->set_secondary_super_cache(k);
duke@0 55 return true;
duke@0 56 }
duke@0 57 }
duke@0 58 return false;
duke@0 59 }
duke@0 60
duke@0 61 // Return self, except for abstract classes with exactly 1
duke@0 62 // implementor. Then return the 1 concrete implementation.
duke@0 63 Klass *Klass::up_cast_abstract() {
duke@0 64 Klass *r = this;
duke@0 65 while( r->is_abstract() ) { // Receiver is abstract?
duke@0 66 Klass *s = r->subklass(); // Check for exactly 1 subklass
duke@0 67 if( !s || s->next_sibling() ) // Oops; wrong count; give up
duke@0 68 return this; // Return 'this' as a no-progress flag
duke@0 69 r = s; // Loop till find concrete class
duke@0 70 }
duke@0 71 return r; // Return the 1 concrete class
duke@0 72 }
duke@0 73
twisti@605 74 // Find LCA in class hierarchy
duke@0 75 Klass *Klass::LCA( Klass *k2 ) {
duke@0 76 Klass *k1 = this;
duke@0 77 while( 1 ) {
duke@0 78 if( k1->is_subtype_of(k2->as_klassOop()) ) return k2;
duke@0 79 if( k2->is_subtype_of(k1->as_klassOop()) ) return k1;
duke@0 80 k1 = k1->super()->klass_part();
duke@0 81 k2 = k2->super()->klass_part();
duke@0 82 }
duke@0 83 }
duke@0 84
duke@0 85
duke@0 86 void Klass::check_valid_for_instantiation(bool throwError, TRAPS) {
duke@0 87 ResourceMark rm(THREAD);
duke@0 88 THROW_MSG(throwError ? vmSymbols::java_lang_InstantiationError()
duke@0 89 : vmSymbols::java_lang_InstantiationException(), external_name());
duke@0 90 }
duke@0 91
duke@0 92
duke@0 93 void Klass::copy_array(arrayOop s, int src_pos, arrayOop d, int dst_pos, int length, TRAPS) {
duke@0 94 THROW(vmSymbols::java_lang_ArrayStoreException());
duke@0 95 }
duke@0 96
duke@0 97
duke@0 98 void Klass::initialize(TRAPS) {
duke@0 99 ShouldNotReachHere();
duke@0 100 }
duke@0 101
duke@0 102 bool Klass::compute_is_subtype_of(klassOop k) {
duke@0 103 assert(k->is_klass(), "argument must be a class");
duke@0 104 return is_subclass_of(k);
duke@0 105 }
duke@0 106
duke@0 107
duke@0 108 methodOop Klass::uncached_lookup_method(symbolOop name, symbolOop signature) const {
duke@0 109 #ifdef ASSERT
duke@0 110 tty->print_cr("Error: uncached_lookup_method called on a klass oop."
duke@0 111 " Likely error: reflection method does not correctly"
duke@0 112 " wrap return value in a mirror object.");
duke@0 113 #endif
duke@0 114 ShouldNotReachHere();
duke@0 115 return NULL;
duke@0 116 }
duke@0 117
duke@0 118 klassOop Klass::base_create_klass_oop(KlassHandle& klass, int size,
duke@0 119 const Klass_vtbl& vtbl, TRAPS) {
duke@0 120 size = align_object_size(size);
duke@0 121 // allocate and initialize vtable
duke@0 122 Klass* kl = (Klass*) vtbl.allocate_permanent(klass, size, CHECK_NULL);
duke@0 123 klassOop k = kl->as_klassOop();
duke@0 124
duke@0 125 { // Preinitialize supertype information.
duke@0 126 // A later call to initialize_supers() may update these settings:
duke@0 127 kl->set_super(NULL);
duke@0 128 for (juint i = 0; i < Klass::primary_super_limit(); i++) {
duke@0 129 kl->_primary_supers[i] = NULL;
duke@0 130 }
duke@0 131 kl->set_secondary_supers(NULL);
duke@0 132 oop_store_without_check((oop*) &kl->_primary_supers[0], k);
duke@0 133 kl->set_super_check_offset(primary_supers_offset_in_bytes() + sizeof(oopDesc));
duke@0 134 }
duke@0 135
duke@0 136 kl->set_java_mirror(NULL);
duke@0 137 kl->set_modifier_flags(0);
duke@0 138 kl->set_layout_helper(Klass::_lh_neutral_value);
duke@0 139 kl->set_name(NULL);
duke@0 140 AccessFlags af;
duke@0 141 af.set_flags(0);
duke@0 142 kl->set_access_flags(af);
duke@0 143 kl->set_subklass(NULL);
duke@0 144 kl->set_next_sibling(NULL);
duke@0 145 kl->set_alloc_count(0);
duke@0 146 kl->set_alloc_size(0);
duke@0 147
duke@0 148 kl->set_prototype_header(markOopDesc::prototype());
duke@0 149 kl->set_biased_lock_revocation_count(0);
duke@0 150 kl->set_last_biased_lock_bulk_revocation_time(0);
duke@0 151
duke@0 152 return k;
duke@0 153 }
duke@0 154
duke@0 155 KlassHandle Klass::base_create_klass(KlassHandle& klass, int size,
duke@0 156 const Klass_vtbl& vtbl, TRAPS) {
duke@0 157 klassOop ek = base_create_klass_oop(klass, size, vtbl, THREAD);
duke@0 158 return KlassHandle(THREAD, ek);
duke@0 159 }
duke@0 160
duke@0 161 void Klass_vtbl::post_new_init_klass(KlassHandle& klass,
duke@0 162 klassOop new_klass,
duke@0 163 int size) const {
duke@0 164 assert(!new_klass->klass_part()->null_vtbl(), "Not a complete klass");
duke@0 165 CollectedHeap::post_allocation_install_obj_klass(klass, new_klass, size);
duke@0 166 }
duke@0 167
duke@0 168 void* Klass_vtbl::operator new(size_t ignored, KlassHandle& klass,
duke@0 169 int size, TRAPS) {
duke@0 170 // The vtable pointer is installed during the execution of
duke@0 171 // constructors in the call to permanent_obj_allocate(). Delay
duke@0 172 // the installation of the klass pointer into the new klass "k"
duke@0 173 // until after the vtable pointer has been installed (i.e., until
duke@0 174 // after the return of permanent_obj_allocate().
duke@0 175 klassOop k =
duke@0 176 (klassOop) CollectedHeap::permanent_obj_allocate_no_klass_install(klass,
duke@0 177 size, CHECK_NULL);
duke@0 178 return k->klass_part();
duke@0 179 }
duke@0 180
duke@0 181 jint Klass::array_layout_helper(BasicType etype) {
duke@0 182 assert(etype >= T_BOOLEAN && etype <= T_OBJECT, "valid etype");
duke@0 183 // Note that T_ARRAY is not allowed here.
duke@0 184 int hsize = arrayOopDesc::base_offset_in_bytes(etype);
kvn@29 185 int esize = type2aelembytes(etype);
duke@0 186 bool isobj = (etype == T_OBJECT);
duke@0 187 int tag = isobj ? _lh_array_tag_obj_value : _lh_array_tag_type_value;
duke@0 188 int lh = array_layout_helper(tag, hsize, etype, exact_log2(esize));
duke@0 189
duke@0 190 assert(lh < (int)_lh_neutral_value, "must look like an array layout");
duke@0 191 assert(layout_helper_is_javaArray(lh), "correct kind");
duke@0 192 assert(layout_helper_is_objArray(lh) == isobj, "correct kind");
duke@0 193 assert(layout_helper_is_typeArray(lh) == !isobj, "correct kind");
duke@0 194 assert(layout_helper_header_size(lh) == hsize, "correct decode");
duke@0 195 assert(layout_helper_element_type(lh) == etype, "correct decode");
duke@0 196 assert(1 << layout_helper_log2_element_size(lh) == esize, "correct decode");
duke@0 197
duke@0 198 return lh;
duke@0 199 }
duke@0 200
duke@0 201 bool Klass::can_be_primary_super_slow() const {
duke@0 202 if (super() == NULL)
duke@0 203 return true;
duke@0 204 else if (super()->klass_part()->super_depth() >= primary_super_limit()-1)
duke@0 205 return false;
duke@0 206 else
duke@0 207 return true;
duke@0 208 }
duke@0 209
duke@0 210 void Klass::initialize_supers(klassOop k, TRAPS) {
duke@0 211 if (FastSuperclassLimit == 0) {
duke@0 212 // None of the other machinery matters.
duke@0 213 set_super(k);
duke@0 214 return;
duke@0 215 }
duke@0 216 if (k == NULL) {
duke@0 217 set_super(NULL);
duke@0 218 oop_store_without_check((oop*) &_primary_supers[0], (oop) this->as_klassOop());
duke@0 219 assert(super_depth() == 0, "Object must already be initialized properly");
never@1142 220 } else if (k != super() || k == SystemDictionary::Object_klass()) {
never@1142 221 assert(super() == NULL || super() == SystemDictionary::Object_klass(),
duke@0 222 "initialize this only once to a non-trivial value");
duke@0 223 set_super(k);
duke@0 224 Klass* sup = k->klass_part();
duke@0 225 int sup_depth = sup->super_depth();
duke@0 226 juint my_depth = MIN2(sup_depth + 1, (int)primary_super_limit());
duke@0 227 if (!can_be_primary_super_slow())
duke@0 228 my_depth = primary_super_limit();
duke@0 229 for (juint i = 0; i < my_depth; i++) {
duke@0 230 oop_store_without_check((oop*) &_primary_supers[i], (oop) sup->_primary_supers[i]);
duke@0 231 }
duke@0 232 klassOop *super_check_cell;
duke@0 233 if (my_depth < primary_super_limit()) {
duke@0 234 oop_store_without_check((oop*) &_primary_supers[my_depth], (oop) this->as_klassOop());
duke@0 235 super_check_cell = &_primary_supers[my_depth];
duke@0 236 } else {
duke@0 237 // Overflow of the primary_supers array forces me to be secondary.
duke@0 238 super_check_cell = &_secondary_super_cache;
duke@0 239 }
duke@0 240 set_super_check_offset((address)super_check_cell - (address) this->as_klassOop());
duke@0 241
duke@0 242 #ifdef ASSERT
duke@0 243 {
duke@0 244 juint j = super_depth();
duke@0 245 assert(j == my_depth, "computed accessor gets right answer");
duke@0 246 klassOop t = as_klassOop();
duke@0 247 while (!Klass::cast(t)->can_be_primary_super()) {
duke@0 248 t = Klass::cast(t)->super();
duke@0 249 j = Klass::cast(t)->super_depth();
duke@0 250 }
duke@0 251 for (juint j1 = j+1; j1 < primary_super_limit(); j1++) {
duke@0 252 assert(primary_super_of_depth(j1) == NULL, "super list padding");
duke@0 253 }
duke@0 254 while (t != NULL) {
duke@0 255 assert(primary_super_of_depth(j) == t, "super list initialization");
duke@0 256 t = Klass::cast(t)->super();
duke@0 257 --j;
duke@0 258 }
duke@0 259 assert(j == (juint)-1, "correct depth count");
duke@0 260 }
duke@0 261 #endif
duke@0 262 }
duke@0 263
duke@0 264 if (secondary_supers() == NULL) {
duke@0 265 KlassHandle this_kh (THREAD, this);
duke@0 266
duke@0 267 // Now compute the list of secondary supertypes.
duke@0 268 // Secondaries can occasionally be on the super chain,
duke@0 269 // if the inline "_primary_supers" array overflows.
duke@0 270 int extras = 0;
duke@0 271 klassOop p;
duke@0 272 for (p = super(); !(p == NULL || p->klass_part()->can_be_primary_super()); p = p->klass_part()->super()) {
duke@0 273 ++extras;
duke@0 274 }
duke@0 275
duke@0 276 // Compute the "real" non-extra secondaries.
duke@0 277 objArrayOop secondary_oops = compute_secondary_supers(extras, CHECK);
duke@0 278 objArrayHandle secondaries (THREAD, secondary_oops);
duke@0 279
duke@0 280 // Store the extra secondaries in the first array positions:
duke@0 281 int fillp = extras;
duke@0 282 for (p = this_kh->super(); !(p == NULL || p->klass_part()->can_be_primary_super()); p = p->klass_part()->super()) {
duke@0 283 int i; // Scan for overflow primaries being duplicates of 2nd'arys
duke@0 284
duke@0 285 // This happens frequently for very deeply nested arrays: the
duke@0 286 // primary superclass chain overflows into the secondary. The
duke@0 287 // secondary list contains the element_klass's secondaries with
duke@0 288 // an extra array dimension added. If the element_klass's
duke@0 289 // secondary list already contains some primary overflows, they
duke@0 290 // (with the extra level of array-ness) will collide with the
duke@0 291 // normal primary superclass overflows.
duke@0 292 for( i = extras; i < secondaries->length(); i++ )
duke@0 293 if( secondaries->obj_at(i) == p )
duke@0 294 break;
duke@0 295 if( i < secondaries->length() )
duke@0 296 continue; // It's a dup, don't put it in
duke@0 297 secondaries->obj_at_put(--fillp, p);
duke@0 298 }
duke@0 299 // See if we had some dup's, so the array has holes in it.
duke@0 300 if( fillp > 0 ) {
duke@0 301 // Pack the array. Drop the old secondaries array on the floor
duke@0 302 // and let GC reclaim it.
duke@0 303 objArrayOop s2 = oopFactory::new_system_objArray(secondaries->length() - fillp, CHECK);
duke@0 304 for( int i = 0; i < s2->length(); i++ )
duke@0 305 s2->obj_at_put( i, secondaries->obj_at(i+fillp) );
duke@0 306 secondaries = objArrayHandle(THREAD, s2);
duke@0 307 }
duke@0 308
duke@0 309 #ifdef ASSERT
duke@0 310 if (secondaries() != Universe::the_array_interfaces_array()) {
duke@0 311 // We must not copy any NULL placeholders left over from bootstrap.
duke@0 312 for (int j = 0; j < secondaries->length(); j++) {
duke@0 313 assert(secondaries->obj_at(j) != NULL, "correct bootstrapping order");
duke@0 314 }
duke@0 315 }
duke@0 316 #endif
duke@0 317
duke@0 318 this_kh->set_secondary_supers(secondaries());
duke@0 319 }
duke@0 320 }
duke@0 321
duke@0 322 objArrayOop Klass::compute_secondary_supers(int num_extra_slots, TRAPS) {
duke@0 323 assert(num_extra_slots == 0, "override for complex klasses");
duke@0 324 return Universe::the_empty_system_obj_array();
duke@0 325 }
duke@0 326
duke@0 327
duke@0 328 Klass* Klass::subklass() const {
duke@0 329 return _subklass == NULL ? NULL : Klass::cast(_subklass);
duke@0 330 }
duke@0 331
duke@0 332 instanceKlass* Klass::superklass() const {
duke@0 333 assert(super() == NULL || super()->klass_part()->oop_is_instance(), "must be instance klass");
duke@0 334 return _super == NULL ? NULL : instanceKlass::cast(_super);
duke@0 335 }
duke@0 336
duke@0 337 Klass* Klass::next_sibling() const {
duke@0 338 return _next_sibling == NULL ? NULL : Klass::cast(_next_sibling);
duke@0 339 }
duke@0 340
duke@0 341 void Klass::set_subklass(klassOop s) {
duke@0 342 assert(s != as_klassOop(), "sanity check");
duke@0 343 oop_store_without_check((oop*)&_subklass, s);
duke@0 344 }
duke@0 345
duke@0 346 void Klass::set_next_sibling(klassOop s) {
duke@0 347 assert(s != as_klassOop(), "sanity check");
duke@0 348 oop_store_without_check((oop*)&_next_sibling, s);
duke@0 349 }
duke@0 350
duke@0 351 void Klass::append_to_sibling_list() {
duke@0 352 debug_only(if (!SharedSkipVerify) as_klassOop()->verify();)
duke@0 353 // add ourselves to superklass' subklass list
duke@0 354 instanceKlass* super = superklass();
duke@0 355 if (super == NULL) return; // special case: class Object
duke@0 356 assert(SharedSkipVerify ||
duke@0 357 (!super->is_interface() // interfaces cannot be supers
duke@0 358 && (super->superklass() == NULL || !is_interface())),
duke@0 359 "an interface can only be a subklass of Object");
duke@0 360 klassOop prev_first_subklass = super->subklass_oop();
duke@0 361 if (prev_first_subklass != NULL) {
duke@0 362 // set our sibling to be the superklass' previous first subklass
duke@0 363 set_next_sibling(prev_first_subklass);
duke@0 364 }
duke@0 365 // make ourselves the superklass' first subklass
duke@0 366 super->set_subklass(as_klassOop());
duke@0 367 debug_only(if (!SharedSkipVerify) as_klassOop()->verify();)
duke@0 368 }
duke@0 369
duke@0 370 void Klass::remove_from_sibling_list() {
duke@0 371 // remove receiver from sibling list
duke@0 372 instanceKlass* super = superklass();
never@1142 373 assert(super != NULL || as_klassOop() == SystemDictionary::Object_klass(), "should have super");
duke@0 374 if (super == NULL) return; // special case: class Object
duke@0 375 if (super->subklass() == this) {
duke@0 376 // first subklass
duke@0 377 super->set_subklass(_next_sibling);
duke@0 378 } else {
duke@0 379 Klass* sib = super->subklass();
duke@0 380 while (sib->next_sibling() != this) {
duke@0 381 sib = sib->next_sibling();
duke@0 382 };
duke@0 383 sib->set_next_sibling(_next_sibling);
duke@0 384 }
duke@0 385 }
duke@0 386
duke@0 387 void Klass::follow_weak_klass_links( BoolObjectClosure* is_alive, OopClosure* keep_alive) {
duke@0 388 // This klass is alive but the subklass and siblings are not followed/updated.
duke@0 389 // We update the subklass link and the subklass' sibling links here.
duke@0 390 // Our own sibling link will be updated by our superclass (which must be alive
duke@0 391 // since we are).
duke@0 392 assert(is_alive->do_object_b(as_klassOop()), "just checking, this should be live");
duke@0 393 if (ClassUnloading) {
duke@0 394 klassOop sub = subklass_oop();
duke@0 395 if (sub != NULL && !is_alive->do_object_b(sub)) {
duke@0 396 // first subklass not alive, find first one alive
duke@0 397 do {
duke@0 398 #ifndef PRODUCT
duke@0 399 if (TraceClassUnloading && WizardMode) {
duke@0 400 ResourceMark rm;
duke@0 401 tty->print_cr("[Unlinking class (subclass) %s]", sub->klass_part()->external_name());
duke@0 402 }
duke@0 403 #endif
duke@0 404 sub = sub->klass_part()->next_sibling_oop();
duke@0 405 } while (sub != NULL && !is_alive->do_object_b(sub));
duke@0 406 set_subklass(sub);
duke@0 407 }
duke@0 408 // now update the subklass' sibling list
duke@0 409 while (sub != NULL) {
duke@0 410 klassOop next = sub->klass_part()->next_sibling_oop();
duke@0 411 if (next != NULL && !is_alive->do_object_b(next)) {
duke@0 412 // first sibling not alive, find first one alive
duke@0 413 do {
duke@0 414 #ifndef PRODUCT
duke@0 415 if (TraceClassUnloading && WizardMode) {
duke@0 416 ResourceMark rm;
duke@0 417 tty->print_cr("[Unlinking class (sibling) %s]", next->klass_part()->external_name());
duke@0 418 }
duke@0 419 #endif
duke@0 420 next = next->klass_part()->next_sibling_oop();
duke@0 421 } while (next != NULL && !is_alive->do_object_b(next));
duke@0 422 sub->klass_part()->set_next_sibling(next);
duke@0 423 }
duke@0 424 sub = next;
duke@0 425 }
duke@0 426 } else {
duke@0 427 // Always follow subklass and sibling link. This will prevent any klasses from
duke@0 428 // being unloaded (all classes are transitively linked from java.lang.Object).
duke@0 429 keep_alive->do_oop(adr_subklass());
duke@0 430 keep_alive->do_oop(adr_next_sibling());
duke@0 431 }
duke@0 432 }
duke@0 433
duke@0 434
duke@0 435 void Klass::remove_unshareable_info() {
duke@0 436 if (oop_is_instance()) {
duke@0 437 instanceKlass* ik = (instanceKlass*)this;
duke@0 438 if (ik->is_linked()) {
duke@0 439 ik->unlink_class();
duke@0 440 }
duke@0 441 }
duke@0 442 set_subklass(NULL);
duke@0 443 set_next_sibling(NULL);
duke@0 444 }
duke@0 445
duke@0 446
duke@0 447 klassOop Klass::array_klass_or_null(int rank) {
duke@0 448 EXCEPTION_MARK;
duke@0 449 // No exception can be thrown by array_klass_impl when called with or_null == true.
duke@0 450 // (In anycase, the execption mark will fail if it do so)
duke@0 451 return array_klass_impl(true, rank, THREAD);
duke@0 452 }
duke@0 453
duke@0 454
duke@0 455 klassOop Klass::array_klass_or_null() {
duke@0 456 EXCEPTION_MARK;
duke@0 457 // No exception can be thrown by array_klass_impl when called with or_null == true.
duke@0 458 // (In anycase, the execption mark will fail if it do so)
duke@0 459 return array_klass_impl(true, THREAD);
duke@0 460 }
duke@0 461
duke@0 462
duke@0 463 klassOop Klass::array_klass_impl(bool or_null, int rank, TRAPS) {
duke@0 464 fatal("array_klass should be dispatched to instanceKlass, objArrayKlass or typeArrayKlass");
duke@0 465 return NULL;
duke@0 466 }
duke@0 467
duke@0 468
duke@0 469 klassOop Klass::array_klass_impl(bool or_null, TRAPS) {
duke@0 470 fatal("array_klass should be dispatched to instanceKlass, objArrayKlass or typeArrayKlass");
duke@0 471 return NULL;
duke@0 472 }
duke@0 473
duke@0 474
duke@0 475 void Klass::with_array_klasses_do(void f(klassOop k)) {
duke@0 476 f(as_klassOop());
duke@0 477 }
duke@0 478
duke@0 479
duke@0 480 const char* Klass::external_name() const {
jrose@431 481 if (oop_is_instance()) {
jrose@431 482 instanceKlass* ik = (instanceKlass*) this;
jrose@431 483 if (ik->is_anonymous()) {
jrose@431 484 assert(AnonymousClasses, "");
jrose@431 485 intptr_t hash = ik->java_mirror()->identity_hash();
jrose@431 486 char hash_buf[40];
jrose@431 487 sprintf(hash_buf, "/" UINTX_FORMAT, (uintx)hash);
jrose@431 488 size_t hash_len = strlen(hash_buf);
jrose@431 489
jrose@431 490 size_t result_len = name()->utf8_length();
jrose@431 491 char* result = NEW_RESOURCE_ARRAY(char, result_len + hash_len + 1);
jrose@431 492 name()->as_klass_external_name(result, (int) result_len + 1);
jrose@431 493 assert(strlen(result) == result_len, "");
jrose@431 494 strcpy(result + result_len, hash_buf);
jrose@431 495 assert(strlen(result) == result_len + hash_len, "");
jrose@431 496 return result;
jrose@431 497 }
jrose@431 498 }
jrose@1039 499 if (name() == NULL) return "<unknown>";
duke@0 500 return name()->as_klass_external_name();
duke@0 501 }
duke@0 502
duke@0 503
jrose@1039 504 const char* Klass::signature_name() const {
jrose@1039 505 if (name() == NULL) return "<unknown>";
duke@0 506 return name()->as_C_string();
duke@0 507 }
duke@0 508
duke@0 509 // Unless overridden, modifier_flags is 0.
duke@0 510 jint Klass::compute_modifier_flags(TRAPS) const {
duke@0 511 return 0;
duke@0 512 }
duke@0 513
duke@0 514 int Klass::atomic_incr_biased_lock_revocation_count() {
duke@0 515 return (int) Atomic::add(1, &_biased_lock_revocation_count);
duke@0 516 }
duke@0 517
duke@0 518 // Unless overridden, jvmti_class_status has no flags set.
duke@0 519 jint Klass::jvmti_class_status() const {
duke@0 520 return 0;
duke@0 521 }
duke@0 522
duke@0 523 #ifndef PRODUCT
duke@0 524
duke@0 525 // Printing
duke@0 526
duke@0 527 void Klass::oop_print_on(oop obj, outputStream* st) {
duke@0 528 ResourceMark rm;
duke@0 529 // print title
duke@0 530 st->print_cr("%s ", internal_name());
duke@0 531 obj->print_address_on(st);
duke@0 532
duke@0 533 if (WizardMode) {
duke@0 534 // print header
duke@0 535 obj->mark()->print_on(st);
duke@0 536 }
duke@0 537
duke@0 538 // print class
duke@0 539 st->print(" - klass: ");
duke@0 540 obj->klass()->print_value_on(st);
duke@0 541 st->cr();
duke@0 542 }
duke@0 543
duke@0 544
duke@0 545 void Klass::oop_print_value_on(oop obj, outputStream* st) {
duke@0 546 // print title
duke@0 547 ResourceMark rm; // Cannot print in debug mode without this
duke@0 548 st->print("%s", internal_name());
duke@0 549 obj->print_address_on(st);
duke@0 550 }
duke@0 551
duke@0 552 #endif
duke@0 553
duke@0 554 // Verification
duke@0 555
duke@0 556 void Klass::oop_verify_on(oop obj, outputStream* st) {
duke@0 557 guarantee(obj->is_oop(), "should be oop");
duke@0 558 guarantee(obj->klass()->is_perm(), "should be in permspace");
duke@0 559 guarantee(obj->klass()->is_klass(), "klass field is not a klass");
duke@0 560 }
duke@0 561
duke@0 562
duke@0 563 void Klass::oop_verify_old_oop(oop obj, oop* p, bool allow_dirty) {
duke@0 564 /* $$$ I think this functionality should be handled by verification of
duke@0 565 RememberedSet::verify_old_oop(obj, p, allow_dirty, false);
duke@0 566 the card table. */
duke@0 567 }
coleenp@113 568 void Klass::oop_verify_old_oop(oop obj, narrowOop* p, bool allow_dirty) { }
duke@0 569
duke@0 570 #ifndef PRODUCT
duke@0 571
duke@0 572 void Klass::verify_vtable_index(int i) {
duke@0 573 assert(oop_is_instance() || oop_is_array(), "only instanceKlass and arrayKlass have vtables");
duke@0 574 if (oop_is_instance()) {
duke@0 575 assert(i>=0 && i<((instanceKlass*)this)->vtable_length()/vtableEntry::size(), "index out of bounds");
duke@0 576 } else {
duke@0 577 assert(i>=0 && i<((arrayKlass*)this)->vtable_length()/vtableEntry::size(), "index out of bounds");
duke@0 578 }
duke@0 579 }
duke@0 580
duke@0 581 #endif