annotate src/share/vm/oops/klass.cpp @ 2062:3582bf76420e

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