1.1 --- a/src/share/vm/oops/instanceKlass.hpp Thu Apr 26 16:24:15 2012 -0400 1.2 +++ b/src/share/vm/oops/instanceKlass.hpp Wed May 02 13:21:36 2012 -0400 1.3 @@ -78,6 +78,7 @@ 1.4 // The embedded nonstatic oop-map blocks are short pairs (offset, length) 1.5 // indicating where oops are located in instances of this klass. 1.6 // [EMBEDDED implementor of the interface] only exist for interface 1.7 +// [EMBEDDED host klass ] only exist for an anonymous class (JSR 292 enabled) 1.8 1.9 1.10 // forward declaration for class -- see below for definition 1.11 @@ -176,10 +177,6 @@ 1.12 oop _class_loader; 1.13 // Protection domain. 1.14 oop _protection_domain; 1.15 - // Host class, which grants its access privileges to this class also. 1.16 - // This is only non-null for an anonymous class (JSR 292 enabled). 1.17 - // The host class is either named, or a previously loaded anonymous class. 1.18 - klassOop _host_klass; 1.19 // Class signers. 1.20 objArrayOop _signers; 1.21 // The InnerClasses attribute and EnclosingMethod attribute. The 1.22 @@ -234,9 +231,13 @@ 1.23 int _nonstatic_oop_map_size;// size in words of nonstatic oop map blocks 1.24 1.25 bool _is_marked_dependent; // used for marking during flushing and deoptimization 1.26 - bool _rewritten; // methods rewritten. 1.27 - bool _has_nonstatic_fields; // for sizing with UseCompressedOops 1.28 - bool _should_verify_class; // allow caching of preverification 1.29 + enum { 1.30 + _misc_rewritten = 1 << 0, // methods rewritten. 1.31 + _misc_has_nonstatic_fields = 1 << 1, // for sizing with UseCompressedOops 1.32 + _misc_should_verify_class = 1 << 2, // allow caching of preverification 1.33 + _misc_is_anonymous = 1 << 3 // has embedded _inner_classes field 1.34 + }; 1.35 + u2 _misc_flags; 1.36 u2 _minor_version; // minor version number of class file 1.37 u2 _major_version; // major version number of class file 1.38 Thread* _init_thread; // Pointer to current thread doing initialization (to handle recusive initialization) 1.39 @@ -276,13 +277,29 @@ 1.40 // NULL: no implementor. 1.41 // A klassOop that's not itself: one implementor. 1.42 // Itsef: more than one implementors. 1.43 + // embedded host klass follows here 1.44 + // The embedded host klass only exists in an anonymous class for 1.45 + // dynamic language support (JSR 292 enabled). The host class grants 1.46 + // its access privileges to this class also. The host class is either 1.47 + // named, or a previously loaded anonymous class. A non-anonymous class 1.48 + // or an anonymous class loaded through normal classloading does not 1.49 + // have this embedded field. 1.50 + // 1.51 1.52 friend class instanceKlassKlass; 1.53 friend class SystemDictionary; 1.54 1.55 public: 1.56 - bool has_nonstatic_fields() const { return _has_nonstatic_fields; } 1.57 - void set_has_nonstatic_fields(bool b) { _has_nonstatic_fields = b; } 1.58 + bool has_nonstatic_fields() const { 1.59 + return (_misc_flags & _misc_has_nonstatic_fields) != 0; 1.60 + } 1.61 + void set_has_nonstatic_fields(bool b) { 1.62 + if (b) { 1.63 + _misc_flags |= _misc_has_nonstatic_fields; 1.64 + } else { 1.65 + _misc_flags &= ~_misc_has_nonstatic_fields; 1.66 + } 1.67 + } 1.68 1.69 // field sizes 1.70 int nonstatic_field_size() const { return _nonstatic_field_size; } 1.71 @@ -396,11 +413,19 @@ 1.72 bool is_in_error_state() const { return _init_state == initialization_error; } 1.73 bool is_reentrant_initialization(Thread *thread) { return thread == _init_thread; } 1.74 ClassState init_state() { return (ClassState)_init_state; } 1.75 - bool is_rewritten() const { return _rewritten; } 1.76 + bool is_rewritten() const { return (_misc_flags & _misc_rewritten) != 0; } 1.77 1.78 // defineClass specified verification 1.79 - bool should_verify_class() const { return _should_verify_class; } 1.80 - void set_should_verify_class(bool value) { _should_verify_class = value; } 1.81 + bool should_verify_class() const { 1.82 + return (_misc_flags & _misc_should_verify_class) != 0; 1.83 + } 1.84 + void set_should_verify_class(bool value) { 1.85 + if (value) { 1.86 + _misc_flags |= _misc_should_verify_class; 1.87 + } else { 1.88 + _misc_flags &= ~_misc_should_verify_class; 1.89 + } 1.90 + } 1.91 1.92 // marking 1.93 bool is_marked_dependent() const { return _is_marked_dependent; } 1.94 @@ -469,9 +494,30 @@ 1.95 void set_protection_domain(oop pd) { oop_store((oop*) &_protection_domain, pd); } 1.96 1.97 // host class 1.98 - oop host_klass() const { return _host_klass; } 1.99 - void set_host_klass(oop host) { oop_store((oop*) &_host_klass, host); } 1.100 - bool is_anonymous() const { return _host_klass != NULL; } 1.101 + oop host_klass() const { 1.102 + oop* hk = adr_host_klass(); 1.103 + if (hk == NULL) { 1.104 + return NULL; 1.105 + } else { 1.106 + return *hk; 1.107 + } 1.108 + } 1.109 + void set_host_klass(oop host) { 1.110 + assert(is_anonymous(), "not anonymous"); 1.111 + oop* addr = adr_host_klass(); 1.112 + assert(addr != NULL, "no reversed space"); 1.113 + oop_store(addr, host); 1.114 + } 1.115 + bool is_anonymous() const { 1.116 + return (_misc_flags & _misc_is_anonymous) != 0; 1.117 + } 1.118 + void set_is_anonymous(bool value) { 1.119 + if (value) { 1.120 + _misc_flags |= _misc_is_anonymous; 1.121 + } else { 1.122 + _misc_flags &= ~_misc_is_anonymous; 1.123 + } 1.124 + } 1.125 1.126 // signers 1.127 objArrayOop signers() const { return _signers; } 1.128 @@ -651,7 +697,7 @@ 1.129 // Access to the implementor of an interface. 1.130 klassOop implementor() const 1.131 { 1.132 - klassOop* k = start_of_implementor(); 1.133 + klassOop* k = (klassOop*)adr_implementor(); 1.134 if (k == NULL) { 1.135 return NULL; 1.136 } else { 1.137 @@ -661,7 +707,7 @@ 1.138 1.139 void set_implementor(klassOop k) { 1.140 assert(is_interface(), "not interface"); 1.141 - oop* addr = (oop*)start_of_implementor(); 1.142 + oop* addr = adr_implementor(); 1.143 oop_store_without_check(addr, k); 1.144 } 1.145 1.146 @@ -717,9 +763,11 @@ 1.147 { 1.148 return object_size(align_object_offset(vtable_length()) + 1.149 align_object_offset(itable_length()) + 1.150 - (is_interface() ? 1.151 - (align_object_offset(nonstatic_oop_map_size()) + (int)sizeof(klassOop)/HeapWordSize) : 1.152 - nonstatic_oop_map_size())); 1.153 + ((is_interface() || is_anonymous()) ? 1.154 + align_object_offset(nonstatic_oop_map_size()) : 1.155 + nonstatic_oop_map_size()) + 1.156 + (is_interface() ? (int)sizeof(klassOop)/HeapWordSize : 0) + 1.157 + (is_anonymous() ? (int)sizeof(klassOop)/HeapWordSize : 0)); 1.158 } 1.159 static int vtable_start_offset() { return header_size(); } 1.160 static int vtable_length_offset() { return oopDesc::header_size() + offset_of(instanceKlass, _vtable_len) / HeapWordSize; } 1.161 @@ -737,15 +785,29 @@ 1.162 return (OopMapBlock*)(start_of_itable() + align_object_offset(itable_length())); 1.163 } 1.164 1.165 - klassOop* start_of_implementor() const { 1.166 + oop* adr_implementor() const { 1.167 if (is_interface()) { 1.168 - return (klassOop*)(start_of_nonstatic_oop_maps() + 1.169 - nonstatic_oop_map_count()); 1.170 + return (oop*)(start_of_nonstatic_oop_maps() + 1.171 + nonstatic_oop_map_count()); 1.172 } else { 1.173 return NULL; 1.174 } 1.175 }; 1.176 1.177 + oop* adr_host_klass() const { 1.178 + if (is_anonymous()) { 1.179 + oop* adr_impl = adr_implementor(); 1.180 + if (adr_impl != NULL) { 1.181 + return adr_impl + 1; 1.182 + } else { 1.183 + return (oop*)(start_of_nonstatic_oop_maps() + 1.184 + nonstatic_oop_map_count()); 1.185 + } 1.186 + } else { 1.187 + return NULL; 1.188 + } 1.189 + } 1.190 + 1.191 // Allocation profiling support 1.192 juint alloc_size() const { return _alloc_count * size_helper(); } 1.193 void set_alloc_size(juint n) {} 1.194 @@ -819,7 +881,7 @@ 1.195 #else 1.196 void set_init_state(ClassState state) { _init_state = (u1)state; } 1.197 #endif 1.198 - void set_rewritten() { _rewritten = true; } 1.199 + void set_rewritten() { _misc_flags |= _misc_rewritten; } 1.200 void set_init_thread(Thread *thread) { _init_thread = thread; } 1.201 1.202 u2 idnum_allocated_count() const { return _idnum_allocated_count; } 1.203 @@ -852,10 +914,8 @@ 1.204 oop* adr_constants() const { return (oop*)&this->_constants;} 1.205 oop* adr_class_loader() const { return (oop*)&this->_class_loader;} 1.206 oop* adr_protection_domain() const { return (oop*)&this->_protection_domain;} 1.207 - oop* adr_host_klass() const { return (oop*)&this->_host_klass;} 1.208 oop* adr_signers() const { return (oop*)&this->_signers;} 1.209 oop* adr_inner_classes() const { return (oop*)&this->_inner_classes;} 1.210 - oop* adr_implementor() const { return (oop*)start_of_implementor(); } 1.211 oop* adr_methods_jmethod_ids() const { return (oop*)&this->_methods_jmethod_ids;} 1.212 oop* adr_methods_cached_itable_indices() const { return (oop*)&this->_methods_cached_itable_indices;} 1.213 oop* adr_class_annotations() const { return (oop*)&this->_class_annotations;}