annotate src/share/vm/oops/klass.cpp @ 1879:f95d63e2154a

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