1 #ifdef USE_PRAGMA_IDENT_SRC
2 #pragma ident "@(#)klass.cpp 1.119 07/05/05 17:06:00 JVM"
3 #endif
4 /*
5 * Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved.
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7 *
8 * This code is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 2 only, as
10 * published by the Free Software Foundation.
11 *
12 * This code is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * version 2 for more details (a copy is included in the LICENSE file that
16 * accompanied this code).
17 *
18 * You should have received a copy of the GNU General Public License version
19 * 2 along with this work; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21 *
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
24 * have any questions.
25 *
168 CollectedHeap::post_allocation_install_obj_klass(klass, new_klass, size);
169 }
170
171 void* Klass_vtbl::operator new(size_t ignored, KlassHandle& klass,
172 int size, TRAPS) {
173 // The vtable pointer is installed during the execution of
174 // constructors in the call to permanent_obj_allocate(). Delay
175 // the installation of the klass pointer into the new klass "k"
176 // until after the vtable pointer has been installed (i.e., until
177 // after the return of permanent_obj_allocate().
178 klassOop k =
179 (klassOop) CollectedHeap::permanent_obj_allocate_no_klass_install(klass,
180 size, CHECK_NULL);
181 return k->klass_part();
182 }
183
184 jint Klass::array_layout_helper(BasicType etype) {
185 assert(etype >= T_BOOLEAN && etype <= T_OBJECT, "valid etype");
186 // Note that T_ARRAY is not allowed here.
187 int hsize = arrayOopDesc::base_offset_in_bytes(etype);
188 int esize = type2aelembytes[etype];
189 bool isobj = (etype == T_OBJECT);
190 int tag = isobj ? _lh_array_tag_obj_value : _lh_array_tag_type_value;
191 int lh = array_layout_helper(tag, hsize, etype, exact_log2(esize));
192
193 assert(lh < (int)_lh_neutral_value, "must look like an array layout");
194 assert(layout_helper_is_javaArray(lh), "correct kind");
195 assert(layout_helper_is_objArray(lh) == isobj, "correct kind");
196 assert(layout_helper_is_typeArray(lh) == !isobj, "correct kind");
197 assert(layout_helper_header_size(lh) == hsize, "correct decode");
198 assert(layout_helper_element_type(lh) == etype, "correct decode");
199 assert(1 << layout_helper_log2_element_size(lh) == esize, "correct decode");
200
201 return lh;
202 }
203
204 bool Klass::can_be_primary_super_slow() const {
205 if (super() == NULL)
206 return true;
207 else if (super()->klass_part()->super_depth() >= primary_super_limit()-1)
208 return false;
464
465
466 klassOop Klass::array_klass_impl(bool or_null, int rank, TRAPS) {
467 fatal("array_klass should be dispatched to instanceKlass, objArrayKlass or typeArrayKlass");
468 return NULL;
469 }
470
471
472 klassOop Klass::array_klass_impl(bool or_null, TRAPS) {
473 fatal("array_klass should be dispatched to instanceKlass, objArrayKlass or typeArrayKlass");
474 return NULL;
475 }
476
477
478 void Klass::with_array_klasses_do(void f(klassOop k)) {
479 f(as_klassOop());
480 }
481
482
483 const char* Klass::external_name() const {
484 return name()->as_klass_external_name();
485 }
486
487
488 char* Klass::signature_name() const {
489 return name()->as_C_string();
490 }
491
492 // Unless overridden, modifier_flags is 0.
493 jint Klass::compute_modifier_flags(TRAPS) const {
494 return 0;
495 }
496
497 int Klass::atomic_incr_biased_lock_revocation_count() {
498 return (int) Atomic::add(1, &_biased_lock_revocation_count);
499 }
500
501 // Unless overridden, jvmti_class_status has no flags set.
502 jint Klass::jvmti_class_status() const {
503 return 0;
528 void Klass::oop_print_value_on(oop obj, outputStream* st) {
529 // print title
530 ResourceMark rm; // Cannot print in debug mode without this
531 st->print("%s", internal_name());
532 obj->print_address_on(st);
533 }
534
535 #endif
536
537 // Verification
538
539 void Klass::oop_verify_on(oop obj, outputStream* st) {
540 guarantee(obj->is_oop(), "should be oop");
541 guarantee(obj->klass()->is_perm(), "should be in permspace");
542 guarantee(obj->klass()->is_klass(), "klass field is not a klass");
543 }
544
545
546 void Klass::oop_verify_old_oop(oop obj, oop* p, bool allow_dirty) {
547 /* $$$ I think this functionality should be handled by verification of
548
549 RememberedSet::verify_old_oop(obj, p, allow_dirty, false);
550
551 the card table. */
552 }
553
554 #ifndef PRODUCT
555
556 void Klass::verify_vtable_index(int i) {
557 assert(oop_is_instance() || oop_is_array(), "only instanceKlass and arrayKlass have vtables");
558 if (oop_is_instance()) {
559 assert(i>=0 && i<((instanceKlass*)this)->vtable_length()/vtableEntry::size(), "index out of bounds");
560 } else {
561 assert(i>=0 && i<((arrayKlass*)this)->vtable_length()/vtableEntry::size(), "index out of bounds");
562 }
563 }
564
565 #endif
|
1 #ifdef USE_PRAGMA_IDENT_SRC
2 #pragma ident "@(#)klass.cpp 1.119 07/05/05 17:06:00 JVM"
3 #endif
4 /*
5 * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved.
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7 *
8 * This code is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 2 only, as
10 * published by the Free Software Foundation.
11 *
12 * This code is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * version 2 for more details (a copy is included in the LICENSE file that
16 * accompanied this code).
17 *
18 * You should have received a copy of the GNU General Public License version
19 * 2 along with this work; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21 *
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
24 * have any questions.
25 *
168 CollectedHeap::post_allocation_install_obj_klass(klass, new_klass, size);
169 }
170
171 void* Klass_vtbl::operator new(size_t ignored, KlassHandle& klass,
172 int size, TRAPS) {
173 // The vtable pointer is installed during the execution of
174 // constructors in the call to permanent_obj_allocate(). Delay
175 // the installation of the klass pointer into the new klass "k"
176 // until after the vtable pointer has been installed (i.e., until
177 // after the return of permanent_obj_allocate().
178 klassOop k =
179 (klassOop) CollectedHeap::permanent_obj_allocate_no_klass_install(klass,
180 size, CHECK_NULL);
181 return k->klass_part();
182 }
183
184 jint Klass::array_layout_helper(BasicType etype) {
185 assert(etype >= T_BOOLEAN && etype <= T_OBJECT, "valid etype");
186 // Note that T_ARRAY is not allowed here.
187 int hsize = arrayOopDesc::base_offset_in_bytes(etype);
188 int esize = type2aelembytes(etype);
189 bool isobj = (etype == T_OBJECT);
190 int tag = isobj ? _lh_array_tag_obj_value : _lh_array_tag_type_value;
191 int lh = array_layout_helper(tag, hsize, etype, exact_log2(esize));
192
193 assert(lh < (int)_lh_neutral_value, "must look like an array layout");
194 assert(layout_helper_is_javaArray(lh), "correct kind");
195 assert(layout_helper_is_objArray(lh) == isobj, "correct kind");
196 assert(layout_helper_is_typeArray(lh) == !isobj, "correct kind");
197 assert(layout_helper_header_size(lh) == hsize, "correct decode");
198 assert(layout_helper_element_type(lh) == etype, "correct decode");
199 assert(1 << layout_helper_log2_element_size(lh) == esize, "correct decode");
200
201 return lh;
202 }
203
204 bool Klass::can_be_primary_super_slow() const {
205 if (super() == NULL)
206 return true;
207 else if (super()->klass_part()->super_depth() >= primary_super_limit()-1)
208 return false;
464
465
466 klassOop Klass::array_klass_impl(bool or_null, int rank, TRAPS) {
467 fatal("array_klass should be dispatched to instanceKlass, objArrayKlass or typeArrayKlass");
468 return NULL;
469 }
470
471
472 klassOop Klass::array_klass_impl(bool or_null, TRAPS) {
473 fatal("array_klass should be dispatched to instanceKlass, objArrayKlass or typeArrayKlass");
474 return NULL;
475 }
476
477
478 void Klass::with_array_klasses_do(void f(klassOop k)) {
479 f(as_klassOop());
480 }
481
482
483 const char* Klass::external_name() const {
484 if (oop_is_instance()) {
485 instanceKlass* ik = (instanceKlass*) this;
486 if (ik->is_anonymous()) {
487 assert(AnonymousClasses, "");
488 intptr_t hash = ik->java_mirror()->identity_hash();
489 char hash_buf[40];
490 sprintf(hash_buf, "/" UINTX_FORMAT, (uintx)hash);
491 size_t hash_len = strlen(hash_buf);
492
493 size_t result_len = name()->utf8_length();
494 char* result = NEW_RESOURCE_ARRAY(char, result_len + hash_len + 1);
495 name()->as_klass_external_name(result, (int) result_len + 1);
496 assert(strlen(result) == result_len, "");
497 strcpy(result + result_len, hash_buf);
498 assert(strlen(result) == result_len + hash_len, "");
499 return result;
500 }
501 }
502 return name()->as_klass_external_name();
503 }
504
505
506 char* Klass::signature_name() const {
507 return name()->as_C_string();
508 }
509
510 // Unless overridden, modifier_flags is 0.
511 jint Klass::compute_modifier_flags(TRAPS) const {
512 return 0;
513 }
514
515 int Klass::atomic_incr_biased_lock_revocation_count() {
516 return (int) Atomic::add(1, &_biased_lock_revocation_count);
517 }
518
519 // Unless overridden, jvmti_class_status has no flags set.
520 jint Klass::jvmti_class_status() const {
521 return 0;
546 void Klass::oop_print_value_on(oop obj, outputStream* st) {
547 // print title
548 ResourceMark rm; // Cannot print in debug mode without this
549 st->print("%s", internal_name());
550 obj->print_address_on(st);
551 }
552
553 #endif
554
555 // Verification
556
557 void Klass::oop_verify_on(oop obj, outputStream* st) {
558 guarantee(obj->is_oop(), "should be oop");
559 guarantee(obj->klass()->is_perm(), "should be in permspace");
560 guarantee(obj->klass()->is_klass(), "klass field is not a klass");
561 }
562
563
564 void Klass::oop_verify_old_oop(oop obj, oop* p, bool allow_dirty) {
565 /* $$$ I think this functionality should be handled by verification of
566 RememberedSet::verify_old_oop(obj, p, allow_dirty, false);
567 the card table. */
568 }
569 void Klass::oop_verify_old_oop(oop obj, narrowOop* p, bool allow_dirty) { }
570
571 #ifndef PRODUCT
572
573 void Klass::verify_vtable_index(int i) {
574 assert(oop_is_instance() || oop_is_array(), "only instanceKlass and arrayKlass have vtables");
575 if (oop_is_instance()) {
576 assert(i>=0 && i<((instanceKlass*)this)->vtable_length()/vtableEntry::size(), "index out of bounds");
577 } else {
578 assert(i>=0 && i<((arrayKlass*)this)->vtable_length()/vtableEntry::size(), "index out of bounds");
579 }
580 }
581
582 #endif
|