comparison src/share/vm/oops/instanceKlass.hpp @ 6038:8bafad97cd26

7158552: The instanceKlsss::_host_klass is only needed for anonymous class for JSR 292 support. Summary: Change the _host_klass to be conditionally created embedded instanceKlass field. Reviewed-by: jrose, coleenp, dholmes
author jiangli
date Wed, 02 May 2012 13:21:36 -0400
parents 0105f367a14c
children 2766551175a0
comparison
equal deleted inserted replaced
6024:973046802b6f 6038:8bafad97cd26
76 // [EMBEDDED Java vtable ] size in words = vtable_len 76 // [EMBEDDED Java vtable ] size in words = vtable_len
77 // [EMBEDDED nonstatic oop-map blocks] size in words = nonstatic_oop_map_size 77 // [EMBEDDED nonstatic oop-map blocks] size in words = nonstatic_oop_map_size
78 // The embedded nonstatic oop-map blocks are short pairs (offset, length) 78 // The embedded nonstatic oop-map blocks are short pairs (offset, length)
79 // indicating where oops are located in instances of this klass. 79 // indicating where oops are located in instances of this klass.
80 // [EMBEDDED implementor of the interface] only exist for interface 80 // [EMBEDDED implementor of the interface] only exist for interface
81 // [EMBEDDED host klass ] only exist for an anonymous class (JSR 292 enabled)
81 82
82 83
83 // forward declaration for class -- see below for definition 84 // forward declaration for class -- see below for definition
84 class SuperTypeClosure; 85 class SuperTypeClosure;
85 class JNIid; 86 class JNIid;
174 constantPoolOop _constants; 175 constantPoolOop _constants;
175 // Class loader used to load this class, NULL if VM loader used. 176 // Class loader used to load this class, NULL if VM loader used.
176 oop _class_loader; 177 oop _class_loader;
177 // Protection domain. 178 // Protection domain.
178 oop _protection_domain; 179 oop _protection_domain;
179 // Host class, which grants its access privileges to this class also.
180 // This is only non-null for an anonymous class (JSR 292 enabled).
181 // The host class is either named, or a previously loaded anonymous class.
182 klassOop _host_klass;
183 // Class signers. 180 // Class signers.
184 objArrayOop _signers; 181 objArrayOop _signers;
185 // The InnerClasses attribute and EnclosingMethod attribute. The 182 // The InnerClasses attribute and EnclosingMethod attribute. The
186 // _inner_classes is an array of shorts. If the class has InnerClasses 183 // _inner_classes is an array of shorts. If the class has InnerClasses
187 // attribute, then the _inner_classes array begins with 4-tuples of shorts 184 // attribute, then the _inner_classes array begins with 4-tuples of shorts
232 u2 _static_oop_field_count;// number of static oop fields in this klass 229 u2 _static_oop_field_count;// number of static oop fields in this klass
233 u2 _java_fields_count; // The number of declared Java fields 230 u2 _java_fields_count; // The number of declared Java fields
234 int _nonstatic_oop_map_size;// size in words of nonstatic oop map blocks 231 int _nonstatic_oop_map_size;// size in words of nonstatic oop map blocks
235 232
236 bool _is_marked_dependent; // used for marking during flushing and deoptimization 233 bool _is_marked_dependent; // used for marking during flushing and deoptimization
237 bool _rewritten; // methods rewritten. 234 enum {
238 bool _has_nonstatic_fields; // for sizing with UseCompressedOops 235 _misc_rewritten = 1 << 0, // methods rewritten.
239 bool _should_verify_class; // allow caching of preverification 236 _misc_has_nonstatic_fields = 1 << 1, // for sizing with UseCompressedOops
237 _misc_should_verify_class = 1 << 2, // allow caching of preverification
238 _misc_is_anonymous = 1 << 3 // has embedded _inner_classes field
239 };
240 u2 _misc_flags;
240 u2 _minor_version; // minor version number of class file 241 u2 _minor_version; // minor version number of class file
241 u2 _major_version; // major version number of class file 242 u2 _major_version; // major version number of class file
242 Thread* _init_thread; // Pointer to current thread doing initialization (to handle recusive initialization) 243 Thread* _init_thread; // Pointer to current thread doing initialization (to handle recusive initialization)
243 int _vtable_len; // length of Java vtable (in words) 244 int _vtable_len; // length of Java vtable (in words)
244 int _itable_len; // length of Java itable (in words) 245 int _itable_len; // length of Java itable (in words)
274 // iterface. The possible values of the implementor fall into following 275 // iterface. The possible values of the implementor fall into following
275 // three cases: 276 // three cases:
276 // NULL: no implementor. 277 // NULL: no implementor.
277 // A klassOop that's not itself: one implementor. 278 // A klassOop that's not itself: one implementor.
278 // Itsef: more than one implementors. 279 // Itsef: more than one implementors.
280 // embedded host klass follows here
281 // The embedded host klass only exists in an anonymous class for
282 // dynamic language support (JSR 292 enabled). The host class grants
283 // its access privileges to this class also. The host class is either
284 // named, or a previously loaded anonymous class. A non-anonymous class
285 // or an anonymous class loaded through normal classloading does not
286 // have this embedded field.
287 //
279 288
280 friend class instanceKlassKlass; 289 friend class instanceKlassKlass;
281 friend class SystemDictionary; 290 friend class SystemDictionary;
282 291
283 public: 292 public:
284 bool has_nonstatic_fields() const { return _has_nonstatic_fields; } 293 bool has_nonstatic_fields() const {
285 void set_has_nonstatic_fields(bool b) { _has_nonstatic_fields = b; } 294 return (_misc_flags & _misc_has_nonstatic_fields) != 0;
295 }
296 void set_has_nonstatic_fields(bool b) {
297 if (b) {
298 _misc_flags |= _misc_has_nonstatic_fields;
299 } else {
300 _misc_flags &= ~_misc_has_nonstatic_fields;
301 }
302 }
286 303
287 // field sizes 304 // field sizes
288 int nonstatic_field_size() const { return _nonstatic_field_size; } 305 int nonstatic_field_size() const { return _nonstatic_field_size; }
289 void set_nonstatic_field_size(int size) { _nonstatic_field_size = size; } 306 void set_nonstatic_field_size(int size) { _nonstatic_field_size = size; }
290 307
394 bool is_not_initialized() const { return _init_state < being_initialized; } 411 bool is_not_initialized() const { return _init_state < being_initialized; }
395 bool is_being_initialized() const { return _init_state == being_initialized; } 412 bool is_being_initialized() const { return _init_state == being_initialized; }
396 bool is_in_error_state() const { return _init_state == initialization_error; } 413 bool is_in_error_state() const { return _init_state == initialization_error; }
397 bool is_reentrant_initialization(Thread *thread) { return thread == _init_thread; } 414 bool is_reentrant_initialization(Thread *thread) { return thread == _init_thread; }
398 ClassState init_state() { return (ClassState)_init_state; } 415 ClassState init_state() { return (ClassState)_init_state; }
399 bool is_rewritten() const { return _rewritten; } 416 bool is_rewritten() const { return (_misc_flags & _misc_rewritten) != 0; }
400 417
401 // defineClass specified verification 418 // defineClass specified verification
402 bool should_verify_class() const { return _should_verify_class; } 419 bool should_verify_class() const {
403 void set_should_verify_class(bool value) { _should_verify_class = value; } 420 return (_misc_flags & _misc_should_verify_class) != 0;
421 }
422 void set_should_verify_class(bool value) {
423 if (value) {
424 _misc_flags |= _misc_should_verify_class;
425 } else {
426 _misc_flags &= ~_misc_should_verify_class;
427 }
428 }
404 429
405 // marking 430 // marking
406 bool is_marked_dependent() const { return _is_marked_dependent; } 431 bool is_marked_dependent() const { return _is_marked_dependent; }
407 void set_is_marked_dependent(bool value) { _is_marked_dependent = value; } 432 void set_is_marked_dependent(bool value) { _is_marked_dependent = value; }
408 433
467 // protection domain 492 // protection domain
468 oop protection_domain() { return _protection_domain; } 493 oop protection_domain() { return _protection_domain; }
469 void set_protection_domain(oop pd) { oop_store((oop*) &_protection_domain, pd); } 494 void set_protection_domain(oop pd) { oop_store((oop*) &_protection_domain, pd); }
470 495
471 // host class 496 // host class
472 oop host_klass() const { return _host_klass; } 497 oop host_klass() const {
473 void set_host_klass(oop host) { oop_store((oop*) &_host_klass, host); } 498 oop* hk = adr_host_klass();
474 bool is_anonymous() const { return _host_klass != NULL; } 499 if (hk == NULL) {
500 return NULL;
501 } else {
502 return *hk;
503 }
504 }
505 void set_host_klass(oop host) {
506 assert(is_anonymous(), "not anonymous");
507 oop* addr = adr_host_klass();
508 assert(addr != NULL, "no reversed space");
509 oop_store(addr, host);
510 }
511 bool is_anonymous() const {
512 return (_misc_flags & _misc_is_anonymous) != 0;
513 }
514 void set_is_anonymous(bool value) {
515 if (value) {
516 _misc_flags |= _misc_is_anonymous;
517 } else {
518 _misc_flags &= ~_misc_is_anonymous;
519 }
520 }
475 521
476 // signers 522 // signers
477 objArrayOop signers() const { return _signers; } 523 objArrayOop signers() const { return _signers; }
478 void set_signers(objArrayOop s) { oop_store((oop*) &_signers, oop(s)); } 524 void set_signers(objArrayOop s) { oop_store((oop*) &_signers, oop(s)); }
479 525
649 bool implements_interface(klassOop k) const; 695 bool implements_interface(klassOop k) const;
650 696
651 // Access to the implementor of an interface. 697 // Access to the implementor of an interface.
652 klassOop implementor() const 698 klassOop implementor() const
653 { 699 {
654 klassOop* k = start_of_implementor(); 700 klassOop* k = (klassOop*)adr_implementor();
655 if (k == NULL) { 701 if (k == NULL) {
656 return NULL; 702 return NULL;
657 } else { 703 } else {
658 return *k; 704 return *k;
659 } 705 }
660 } 706 }
661 707
662 void set_implementor(klassOop k) { 708 void set_implementor(klassOop k) {
663 assert(is_interface(), "not interface"); 709 assert(is_interface(), "not interface");
664 oop* addr = (oop*)start_of_implementor(); 710 oop* addr = adr_implementor();
665 oop_store_without_check(addr, k); 711 oop_store_without_check(addr, k);
666 } 712 }
667 713
668 int nof_implementors() const { 714 int nof_implementors() const {
669 klassOop k = implementor(); 715 klassOop k = implementor();
715 761
716 int object_size() const 762 int object_size() const
717 { 763 {
718 return object_size(align_object_offset(vtable_length()) + 764 return object_size(align_object_offset(vtable_length()) +
719 align_object_offset(itable_length()) + 765 align_object_offset(itable_length()) +
720 (is_interface() ? 766 ((is_interface() || is_anonymous()) ?
721 (align_object_offset(nonstatic_oop_map_size()) + (int)sizeof(klassOop)/HeapWordSize) : 767 align_object_offset(nonstatic_oop_map_size()) :
722 nonstatic_oop_map_size())); 768 nonstatic_oop_map_size()) +
769 (is_interface() ? (int)sizeof(klassOop)/HeapWordSize : 0) +
770 (is_anonymous() ? (int)sizeof(klassOop)/HeapWordSize : 0));
723 } 771 }
724 static int vtable_start_offset() { return header_size(); } 772 static int vtable_start_offset() { return header_size(); }
725 static int vtable_length_offset() { return oopDesc::header_size() + offset_of(instanceKlass, _vtable_len) / HeapWordSize; } 773 static int vtable_length_offset() { return oopDesc::header_size() + offset_of(instanceKlass, _vtable_len) / HeapWordSize; }
726 static int object_size(int extra) { return align_object_size(header_size() + extra); } 774 static int object_size(int extra) { return align_object_size(header_size() + extra); }
727 775
735 783
736 OopMapBlock* start_of_nonstatic_oop_maps() const { 784 OopMapBlock* start_of_nonstatic_oop_maps() const {
737 return (OopMapBlock*)(start_of_itable() + align_object_offset(itable_length())); 785 return (OopMapBlock*)(start_of_itable() + align_object_offset(itable_length()));
738 } 786 }
739 787
740 klassOop* start_of_implementor() const { 788 oop* adr_implementor() const {
741 if (is_interface()) { 789 if (is_interface()) {
742 return (klassOop*)(start_of_nonstatic_oop_maps() + 790 return (oop*)(start_of_nonstatic_oop_maps() +
743 nonstatic_oop_map_count()); 791 nonstatic_oop_map_count());
744 } else { 792 } else {
745 return NULL; 793 return NULL;
746 } 794 }
747 }; 795 };
796
797 oop* adr_host_klass() const {
798 if (is_anonymous()) {
799 oop* adr_impl = adr_implementor();
800 if (adr_impl != NULL) {
801 return adr_impl + 1;
802 } else {
803 return (oop*)(start_of_nonstatic_oop_maps() +
804 nonstatic_oop_map_count());
805 }
806 } else {
807 return NULL;
808 }
809 }
748 810
749 // Allocation profiling support 811 // Allocation profiling support
750 juint alloc_size() const { return _alloc_count * size_helper(); } 812 juint alloc_size() const { return _alloc_count * size_helper(); }
751 void set_alloc_size(juint n) {} 813 void set_alloc_size(juint n) {}
752 814
817 #ifdef ASSERT 879 #ifdef ASSERT
818 void set_init_state(ClassState state); 880 void set_init_state(ClassState state);
819 #else 881 #else
820 void set_init_state(ClassState state) { _init_state = (u1)state; } 882 void set_init_state(ClassState state) { _init_state = (u1)state; }
821 #endif 883 #endif
822 void set_rewritten() { _rewritten = true; } 884 void set_rewritten() { _misc_flags |= _misc_rewritten; }
823 void set_init_thread(Thread *thread) { _init_thread = thread; } 885 void set_init_thread(Thread *thread) { _init_thread = thread; }
824 886
825 u2 idnum_allocated_count() const { return _idnum_allocated_count; } 887 u2 idnum_allocated_count() const { return _idnum_allocated_count; }
826 // The RedefineClasses() API can cause new method idnums to be needed 888 // The RedefineClasses() API can cause new method idnums to be needed
827 // which will cause the caches to grow. Safety requires different 889 // which will cause the caches to grow. Safety requires different
850 oop* adr_transitive_interfaces() const { return (oop*)&this->_transitive_interfaces;} 912 oop* adr_transitive_interfaces() const { return (oop*)&this->_transitive_interfaces;}
851 oop* adr_fields() const { return (oop*)&this->_fields;} 913 oop* adr_fields() const { return (oop*)&this->_fields;}
852 oop* adr_constants() const { return (oop*)&this->_constants;} 914 oop* adr_constants() const { return (oop*)&this->_constants;}
853 oop* adr_class_loader() const { return (oop*)&this->_class_loader;} 915 oop* adr_class_loader() const { return (oop*)&this->_class_loader;}
854 oop* adr_protection_domain() const { return (oop*)&this->_protection_domain;} 916 oop* adr_protection_domain() const { return (oop*)&this->_protection_domain;}
855 oop* adr_host_klass() const { return (oop*)&this->_host_klass;}
856 oop* adr_signers() const { return (oop*)&this->_signers;} 917 oop* adr_signers() const { return (oop*)&this->_signers;}
857 oop* adr_inner_classes() const { return (oop*)&this->_inner_classes;} 918 oop* adr_inner_classes() const { return (oop*)&this->_inner_classes;}
858 oop* adr_implementor() const { return (oop*)start_of_implementor(); }
859 oop* adr_methods_jmethod_ids() const { return (oop*)&this->_methods_jmethod_ids;} 919 oop* adr_methods_jmethod_ids() const { return (oop*)&this->_methods_jmethod_ids;}
860 oop* adr_methods_cached_itable_indices() const { return (oop*)&this->_methods_cached_itable_indices;} 920 oop* adr_methods_cached_itable_indices() const { return (oop*)&this->_methods_cached_itable_indices;}
861 oop* adr_class_annotations() const { return (oop*)&this->_class_annotations;} 921 oop* adr_class_annotations() const { return (oop*)&this->_class_annotations;}
862 oop* adr_fields_annotations() const { return (oop*)&this->_fields_annotations;} 922 oop* adr_fields_annotations() const { return (oop*)&this->_fields_annotations;}
863 oop* adr_methods_annotations() const { return (oop*)&this->_methods_annotations;} 923 oop* adr_methods_annotations() const { return (oop*)&this->_methods_annotations;}