44 // |
44 // |
45 // A ClassLoaderData also encapsulates the allocation space, called a metaspace, |
45 // A ClassLoaderData also encapsulates the allocation space, called a metaspace, |
46 // used by the dynamic linker to allocate the runtime representation of all |
46 // used by the dynamic linker to allocate the runtime representation of all |
47 // the types it defines. |
47 // the types it defines. |
48 // |
48 // |
49 // ClassLoaderData are stored in the runtime representation of classes and the |
49 // ClassLoaderData are stored in the runtime representation of classes, |
50 // system dictionary, are roots of garbage collection, and provides iterators |
50 // and provides iterators for root tracing and other GC operations. |
51 // for root tracing and other GC operations. |
|
52 |
51 |
53 class ClassLoaderData; |
52 class ClassLoaderData; |
54 class JNIMethodBlock; |
53 class JNIMethodBlock; |
55 class Metadebug; |
54 class Metadebug; |
56 class ModuleEntry; |
55 class ModuleEntry; |
57 class PackageEntry; |
56 class PackageEntry; |
58 class ModuleEntryTable; |
57 class ModuleEntryTable; |
59 class PackageEntryTable; |
58 class PackageEntryTable; |
|
59 class DictionaryEntry; |
|
60 class Dictionary; |
60 |
61 |
61 // GC root for walking class loader data created |
62 // GC root for walking class loader data created |
62 |
63 |
63 class ClassLoaderDataGraph : public AllStatic { |
64 class ClassLoaderDataGraph : public AllStatic { |
64 friend class ClassLoaderData; |
65 friend class ClassLoaderData; |
65 friend class ClassLoaderDataGraphMetaspaceIterator; |
66 friend class ClassLoaderDataGraphMetaspaceIterator; |
66 friend class ClassLoaderDataGraphKlassIteratorAtomic; |
67 friend class ClassLoaderDataGraphKlassIteratorAtomic; |
|
68 friend class ClassLoaderDataGraphKlassIteratorStatic; |
67 friend class VMStructs; |
69 friend class VMStructs; |
68 private: |
70 private: |
69 // All CLDs (except the null CLD) can be reached by walking _head->_next->... |
71 // All CLDs (except the null CLD) can be reached by walking _head->_next->... |
70 static ClassLoaderData* _head; |
72 static ClassLoaderData* _head; |
71 static ClassLoaderData* _unloading; |
73 static ClassLoaderData* _unloading; |
107 static void packages_unloading_do(void f(PackageEntry*)); |
109 static void packages_unloading_do(void f(PackageEntry*)); |
108 static void loaded_classes_do(KlassClosure* klass_closure); |
110 static void loaded_classes_do(KlassClosure* klass_closure); |
109 static void classes_unloading_do(void f(Klass* const)); |
111 static void classes_unloading_do(void f(Klass* const)); |
110 static bool do_unloading(BoolObjectClosure* is_alive, bool clean_previous_versions); |
112 static bool do_unloading(BoolObjectClosure* is_alive, bool clean_previous_versions); |
111 |
113 |
|
114 // dictionary do |
|
115 // Iterate over all klasses in dictionary, but |
|
116 // just the classes from defining class loaders. |
|
117 static void dictionary_classes_do(void f(InstanceKlass*)); |
|
118 // Added for initialize_itable_for_klass to handle exceptions. |
|
119 static void dictionary_classes_do(void f(InstanceKlass*, TRAPS), TRAPS); |
|
120 |
|
121 // Iterate all classes and their class loaders, including initiating class loaders. |
|
122 static void dictionary_all_entries_do(void f(InstanceKlass*, ClassLoaderData*)); |
|
123 |
|
124 // VM_CounterDecay iteration support |
|
125 static InstanceKlass* try_get_next_class(); |
|
126 |
|
127 static void verify_dictionary(); |
|
128 static void print_dictionary(bool details); |
|
129 |
112 // CMS support. |
130 // CMS support. |
113 static void remember_new_clds(bool remember) { _saved_head = (remember ? _head : NULL); } |
131 static void remember_new_clds(bool remember) { _saved_head = (remember ? _head : NULL); } |
114 static GrowableArray<ClassLoaderData*>* new_clds(); |
132 static GrowableArray<ClassLoaderData*>* new_clds(); |
115 |
133 |
116 static void set_should_purge(bool b) { _should_purge = b; } |
134 static void set_should_purge(bool b) { _should_purge = b; } |
191 void oops_do(OopClosure* f); |
209 void oops_do(OopClosure* f); |
192 }; |
210 }; |
193 |
211 |
194 friend class ClassLoaderDataGraph; |
212 friend class ClassLoaderDataGraph; |
195 friend class ClassLoaderDataGraphKlassIteratorAtomic; |
213 friend class ClassLoaderDataGraphKlassIteratorAtomic; |
|
214 friend class ClassLoaderDataGraphKlassIteratorStatic; |
196 friend class ClassLoaderDataGraphMetaspaceIterator; |
215 friend class ClassLoaderDataGraphMetaspaceIterator; |
197 friend class MetaDataFactory; |
216 friend class MetaDataFactory; |
198 friend class Method; |
217 friend class Method; |
199 |
218 |
200 static ClassLoaderData * _the_null_class_loader_data; |
219 static ClassLoaderData * _the_null_class_loader_data; |
219 ChunkedHandleList _handles; // Handles to constant pool arrays, Modules, etc, which |
238 ChunkedHandleList _handles; // Handles to constant pool arrays, Modules, etc, which |
220 // have the same life cycle of the corresponding ClassLoader. |
239 // have the same life cycle of the corresponding ClassLoader. |
221 |
240 |
222 Klass* volatile _klasses; // The classes defined by the class loader. |
241 Klass* volatile _klasses; // The classes defined by the class loader. |
223 PackageEntryTable* volatile _packages; // The packages defined by the class loader. |
242 PackageEntryTable* volatile _packages; // The packages defined by the class loader. |
|
243 ModuleEntryTable* volatile _modules; // The modules defined by the class loader. |
224 ModuleEntry* _unnamed_module; // This class loader's unnamed module. |
244 ModuleEntry* _unnamed_module; // This class loader's unnamed module. |
225 ModuleEntryTable* volatile _modules; // The modules defined by the class loader. |
245 Dictionary* _dictionary; // The loaded InstanceKlasses, including initiated by this class loader |
226 |
246 |
227 // These method IDs are created for the class loader and set to NULL when the |
247 // These method IDs are created for the class loader and set to NULL when the |
228 // class loader is unloaded. They are rarely freed, only for redefine classes |
248 // class loader is unloaded. They are rarely freed, only for redefine classes |
229 // and if they lose a data race in InstanceKlass. |
249 // and if they lose a data race in InstanceKlass. |
230 JNIMethodBlock* _jmethod_ids; |
250 JNIMethodBlock* _jmethod_ids; |
322 // Used to refcount an anonymous class's CLD in order to |
343 // Used to refcount an anonymous class's CLD in order to |
323 // indicate their aliveness without a keep_alive_object(). |
344 // indicate their aliveness without a keep_alive_object(). |
324 void inc_keep_alive(); |
345 void inc_keep_alive(); |
325 void dec_keep_alive(); |
346 void dec_keep_alive(); |
326 |
347 |
327 inline unsigned int identity_hash() const; |
348 inline unsigned int identity_hash() const { return (unsigned int)(((intptr_t)this) >> 3); } |
328 |
349 |
329 // Used when tracing from klasses. |
350 // Used when tracing from klasses. |
330 void oops_do(OopClosure* f, KlassClosure* klass_closure, bool must_claim); |
351 void oops_do(OopClosure* f, KlassClosure* klass_closure, bool must_claim); |
331 |
352 |
332 void classes_do(KlassClosure* klass_closure); |
353 void classes_do(KlassClosure* klass_closure); |
|
354 Klass* klasses() { return _klasses; } |
333 |
355 |
334 JNIMethodBlock* jmethod_ids() const { return _jmethod_ids; } |
356 JNIMethodBlock* jmethod_ids() const { return _jmethod_ids; } |
335 void set_jmethod_ids(JNIMethodBlock* new_block) { _jmethod_ids = new_block; } |
357 void set_jmethod_ids(JNIMethodBlock* new_block) { _jmethod_ids = new_block; } |
336 |
358 |
337 void print_value() { print_value_on(tty); } |
359 void print() { print_on(tty); } |
|
360 void print_on(outputStream* out) const; |
|
361 void print_value() { print_value_on(tty); } |
338 void print_value_on(outputStream* out) const; |
362 void print_value_on(outputStream* out) const; |
339 void dump(outputStream * const out) PRODUCT_RETURN; |
363 void dump(outputStream * const out) PRODUCT_RETURN; |
340 void verify(); |
364 void verify(); |
341 const char* loader_name(); |
365 const char* loader_name(); |
342 |
366 |
349 void init_dependencies(TRAPS); |
373 void init_dependencies(TRAPS); |
350 PackageEntryTable* packages() { return _packages; } |
374 PackageEntryTable* packages() { return _packages; } |
351 ModuleEntry* unnamed_module() { return _unnamed_module; } |
375 ModuleEntry* unnamed_module() { return _unnamed_module; } |
352 ModuleEntryTable* modules(); |
376 ModuleEntryTable* modules(); |
353 bool modules_defined() { return (_modules != NULL); } |
377 bool modules_defined() { return (_modules != NULL); } |
|
378 |
|
379 // Loaded class dictionary |
|
380 Dictionary* dictionary() const { return _dictionary; } |
354 |
381 |
355 void add_to_deallocate_list(Metadata* m); |
382 void add_to_deallocate_list(Metadata* m); |
356 |
383 |
357 static ClassLoaderData* class_loader_data(oop loader); |
384 static ClassLoaderData* class_loader_data(oop loader); |
358 static ClassLoaderData* class_loader_data_or_null(oop loader); |
385 static ClassLoaderData* class_loader_data_or_null(oop loader); |