< prev index next >

src/hotspot/share/cds/dumpTimeClassInfo.cpp

Print this page

  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #include "precompiled.hpp"
 26 #include "cds/archiveBuilder.hpp"

 27 #include "cds/dumpTimeClassInfo.inline.hpp"
 28 #include "cds/runTimeClassInfo.hpp"
 29 #include "classfile/classLoader.hpp"
 30 #include "classfile/classLoaderData.inline.hpp"
 31 #include "classfile/systemDictionaryShared.hpp"
 32 #include "memory/resourceArea.hpp"
 33 
 34 DumpTimeClassInfo::~DumpTimeClassInfo() {
 35   if (_verifier_constraints != nullptr) {
 36     assert(_verifier_constraint_flags != nullptr, "must be");
 37     delete _verifier_constraints;
 38     delete _verifier_constraint_flags;
 39   }
 40   if (_loader_constraints != nullptr) {
 41     delete _loader_constraints;
 42   }
 43 }
 44 
























 45 size_t DumpTimeClassInfo::runtime_info_bytesize() const {
 46   return RunTimeClassInfo::byte_size(_klass, num_verifier_constraints(),
 47                                      num_loader_constraints(),
 48                                      num_enum_klass_static_fields());
 49 }
 50 
 51 void DumpTimeClassInfo::add_verification_constraint(InstanceKlass* k, Symbol* name,
 52          Symbol* from_name, bool from_field_is_protected, bool from_is_array, bool from_is_object) {
 53   if (_verifier_constraints == nullptr) {
 54     _verifier_constraints = new (mtClass) GrowableArray<DTVerifierConstraint>(4, mtClass);
 55   }
 56   if (_verifier_constraint_flags == nullptr) {
 57     _verifier_constraint_flags = new (mtClass) GrowableArray<char>(4, mtClass);
 58   }
 59   GrowableArray<DTVerifierConstraint>* vc_array = _verifier_constraints;
 60   for (int i = 0; i < vc_array->length(); i++) {
 61     if (vc_array->at(i).equals(name, from_name)) {
 62       return;
 63     }
 64   }

126   }
127 }
128 
129 void DumpTimeClassInfo::add_enum_klass_static_field(int archived_heap_root_index) {
130   if (_enum_klass_static_fields == nullptr) {
131     _enum_klass_static_fields = new (mtClass) GrowableArray<int>(20, mtClass);
132   }
133   _enum_klass_static_fields->append(archived_heap_root_index);
134 }
135 
136 int DumpTimeClassInfo::enum_klass_static_field(int which_field) {
137   assert(_enum_klass_static_fields != nullptr, "must be");
138   return _enum_klass_static_fields->at(which_field);
139 }
140 
141 bool DumpTimeClassInfo::is_builtin() {
142   return SystemDictionaryShared::is_builtin(_klass);
143 }
144 
145 DumpTimeClassInfo* DumpTimeSharedClassTable::allocate_info(InstanceKlass* k) {
146   assert(!k->is_shared(), "Do not call with shared classes");


147   bool created;
148   DumpTimeClassInfo* p = put_if_absent(k, &created);
149   assert(created, "must not exist in table");
150   p->_klass = k;
151   return p;
152 }
153 
154 DumpTimeClassInfo* DumpTimeSharedClassTable::get_info(InstanceKlass* k) {
155   assert(!k->is_shared(), "Do not call with shared classes");


156   DumpTimeClassInfo* p = get(k);
157   assert(p != nullptr, "we must not see any non-shared InstanceKlass* that's "
158          "not stored with SystemDictionaryShared::init_dumptime_info");
159   assert(p->_klass == k, "Sanity");
160   return p;
161 }
162 
163 class CountClassByCategory : StackObj {
164   DumpTimeSharedClassTable* _table;
165 public:
166   CountClassByCategory(DumpTimeSharedClassTable* table) : _table(table) {}
167   void do_entry(InstanceKlass* k, DumpTimeClassInfo& info) {
168     if (!info.is_excluded()) {
169       if (info.is_builtin()) {
170         _table->inc_builtin_count();
171       } else {
172         _table->inc_unregistered_count();
173       }
174     }
175   }

  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #include "precompiled.hpp"
 26 #include "cds/archiveBuilder.hpp"
 27 #include "cds/cdsConfig.hpp"
 28 #include "cds/dumpTimeClassInfo.inline.hpp"
 29 #include "cds/runTimeClassInfo.hpp"
 30 #include "classfile/classLoader.hpp"
 31 #include "classfile/classLoaderData.inline.hpp"
 32 #include "classfile/systemDictionaryShared.hpp"
 33 #include "memory/resourceArea.hpp"
 34 
 35 DumpTimeClassInfo::~DumpTimeClassInfo() {
 36   if (_verifier_constraints != nullptr) {
 37     assert(_verifier_constraint_flags != nullptr, "must be");
 38     delete _verifier_constraints;
 39     delete _verifier_constraint_flags;
 40   }
 41   if (_loader_constraints != nullptr) {
 42     delete _loader_constraints;
 43   }
 44 }
 45 
 46 bool DumpTimeClassInfo::is_excluded() {
 47   if (_excluded) {
 48     return true;
 49   }
 50   if (_failed_verification) {
 51     if (CDSConfig::preserve_all_dumptime_verification_states(_klass)) {
 52       assert(CDSConfig::is_dumping_aot_linked_classes(), "sanity");
 53       // If the verification states are preserved, _klass will be archived in unlinked state. This is
 54       // necessary to support the following scenario, where the verification of X requires that
 55       // A be a subclass of B:
 56       //     class X {
 57       //        B getB() { return new A(); }
 58       //     }
 59       // If X and B can be verified, but A fails verification, we still archive A (in a preloaded
 60       // SystemDictionary) so that at runtime we cannot subvert the verification of X by replacing
 61       // A with a version that is not a subtype of B.
 62     } else {
 63       // Don't archive this class. At runtime, load it from classfile and rerun verification.
 64       return true;
 65     }
 66   }
 67   return false;
 68 }
 69 
 70 size_t DumpTimeClassInfo::runtime_info_bytesize() const {
 71   return RunTimeClassInfo::byte_size(_klass, num_verifier_constraints(),
 72                                      num_loader_constraints(),
 73                                      num_enum_klass_static_fields());
 74 }
 75 
 76 void DumpTimeClassInfo::add_verification_constraint(InstanceKlass* k, Symbol* name,
 77          Symbol* from_name, bool from_field_is_protected, bool from_is_array, bool from_is_object) {
 78   if (_verifier_constraints == nullptr) {
 79     _verifier_constraints = new (mtClass) GrowableArray<DTVerifierConstraint>(4, mtClass);
 80   }
 81   if (_verifier_constraint_flags == nullptr) {
 82     _verifier_constraint_flags = new (mtClass) GrowableArray<char>(4, mtClass);
 83   }
 84   GrowableArray<DTVerifierConstraint>* vc_array = _verifier_constraints;
 85   for (int i = 0; i < vc_array->length(); i++) {
 86     if (vc_array->at(i).equals(name, from_name)) {
 87       return;
 88     }
 89   }

151   }
152 }
153 
154 void DumpTimeClassInfo::add_enum_klass_static_field(int archived_heap_root_index) {
155   if (_enum_klass_static_fields == nullptr) {
156     _enum_klass_static_fields = new (mtClass) GrowableArray<int>(20, mtClass);
157   }
158   _enum_klass_static_fields->append(archived_heap_root_index);
159 }
160 
161 int DumpTimeClassInfo::enum_klass_static_field(int which_field) {
162   assert(_enum_klass_static_fields != nullptr, "must be");
163   return _enum_klass_static_fields->at(which_field);
164 }
165 
166 bool DumpTimeClassInfo::is_builtin() {
167   return SystemDictionaryShared::is_builtin(_klass);
168 }
169 
170 DumpTimeClassInfo* DumpTimeSharedClassTable::allocate_info(InstanceKlass* k) {
171   if (!CDSConfig::is_dumping_final_static_archive()) {
172     assert(!k->is_shared(), "Do not call with shared classes");
173   }
174   bool created;
175   DumpTimeClassInfo* p = put_if_absent(k, &created);
176   assert(created, "must not exist in table");
177   p->_klass = k;
178   return p;
179 }
180 
181 DumpTimeClassInfo* DumpTimeSharedClassTable::get_info(InstanceKlass* k) {
182   if (!CDSConfig::is_dumping_final_static_archive()) {
183     assert(!k->is_shared(), "Do not call with shared classes");
184   }
185   DumpTimeClassInfo* p = get(k);
186   assert(p != nullptr, "we must not see any non-shared InstanceKlass* that's "
187          "not stored with SystemDictionaryShared::init_dumptime_info");
188   assert(p->_klass == k, "Sanity");
189   return p;
190 }
191 
192 class CountClassByCategory : StackObj {
193   DumpTimeSharedClassTable* _table;
194 public:
195   CountClassByCategory(DumpTimeSharedClassTable* table) : _table(table) {}
196   void do_entry(InstanceKlass* k, DumpTimeClassInfo& info) {
197     if (!info.is_excluded()) {
198       if (info.is_builtin()) {
199         _table->inc_builtin_count();
200       } else {
201         _table->inc_unregistered_count();
202       }
203     }
204   }
< prev index next >