62 class PackageEntryTable;
63 class DictionaryEntry;
64 class Dictionary;
65
66 // GC root for walking class loader data created
67
68 class ClassLoaderDataGraph : public AllStatic {
69 friend class ClassLoaderData;
70 friend class ClassLoaderDataGraphMetaspaceIterator;
71 friend class ClassLoaderDataGraphKlassIteratorAtomic;
72 friend class ClassLoaderDataGraphKlassIteratorStatic;
73 friend class VMStructs;
74 private:
75 // All CLDs (except the null CLD) can be reached by walking _head->_next->...
76 static ClassLoaderData* _head;
77 static ClassLoaderData* _unloading;
78 // CMS support.
79 static ClassLoaderData* _saved_head;
80 static ClassLoaderData* _saved_unloading;
81 static bool _should_purge;
82 // OOM has been seen in metaspace allocation. Used to prevent some
83 // allocations until class unloading
84 static bool _metaspace_oom;
85
86 static volatile size_t _num_instance_classes;
87 static volatile size_t _num_array_classes;
88
89 static ClassLoaderData* add_to_graph(Handle class_loader, bool anonymous);
90 static ClassLoaderData* add(Handle class_loader, bool anonymous);
91 public:
92 static ClassLoaderData* find_or_create(Handle class_loader);
93 static void purge();
94 static void clear_claimed_marks();
95 // oops do
96 static void oops_do(OopClosure* f, bool must_claim);
97 static void keep_alive_oops_do(OopClosure* blk, bool must_claim);
98 static void always_strong_oops_do(OopClosure* blk, bool must_claim);
99 // cld do
100 static void cld_do(CLDClosure* cl);
101 static void cld_unloading_do(CLDClosure* cl);
102 static void roots_cld_do(CLDClosure* strong, CLDClosure* weak);
103 static void keep_alive_cld_do(CLDClosure* cl);
104 static void always_strong_cld_do(CLDClosure* cl);
105 // klass do
106 // Walking classes through the ClassLoaderDataGraph include array classes. It also includes
107 // classes that are allocated but not loaded, classes that have errors, and scratch classes
108 // for redefinition. These classes are removed during the next class unloading.
109 // Walking the ClassLoaderDataGraph also includes anonymous classes.
110 static void classes_do(KlassClosure* klass_closure);
111 static void classes_do(void f(Klass* const));
112 static void methods_do(void f(Method*));
113 static void modules_do(void f(ModuleEntry*));
114 static void modules_unloading_do(void f(ModuleEntry*));
115 static void packages_do(void f(PackageEntry*));
116 static void packages_unloading_do(void f(PackageEntry*));
117 static void loaded_classes_do(KlassClosure* klass_closure);
118 static void classes_unloading_do(void f(Klass* const));
119 static bool do_unloading(bool clean_previous_versions);
120
121 // dictionary do
122 // Iterate over all klasses in dictionary, but
123 // just the classes from defining class loaders.
124 static void dictionary_classes_do(void f(InstanceKlass*));
125 // Added for initialize_itable_for_klass to handle exceptions.
126 static void dictionary_classes_do(void f(InstanceKlass*, TRAPS), TRAPS);
127
128 // Iterate all classes and their class loaders, including initiating class loaders.
129 static void dictionary_all_entries_do(void f(InstanceKlass*, ClassLoaderData*));
130
131 // VM_CounterDecay iteration support
132 static InstanceKlass* try_get_next_class();
133
134 static void verify_dictionary();
135 static void print_dictionary(outputStream* st);
136 static void print_dictionary_statistics(outputStream* st);
137
138 // CMS support.
139 static void remember_new_clds(bool remember) { _saved_head = (remember ? _head : NULL); }
281 bool has_modified_oops() { return _modified_oops; }
282
283 void accumulate_modified_oops() { if (has_modified_oops()) _accumulated_modified_oops = true; }
284 void clear_accumulated_modified_oops() { _accumulated_modified_oops = false; }
285 bool has_accumulated_modified_oops() { return _accumulated_modified_oops; }
286 private:
287
288 void unload();
289 bool keep_alive() const { return _keep_alive > 0; }
290
291 oop holder_phantom() const;
292 void classes_do(void f(Klass*));
293 void loaded_classes_do(KlassClosure* klass_closure);
294 void classes_do(void f(InstanceKlass*));
295 void methods_do(void f(Method*));
296 void modules_do(void f(ModuleEntry*));
297 void packages_do(void f(PackageEntry*));
298
299 // Deallocate free list during class unloading.
300 void free_deallocate_list(); // for the classes that are not unloaded
301 void unload_deallocate_list(); // for the classes that are unloaded
302
303 // Allocate out of this class loader data
304 MetaWord* allocate(size_t size);
305
306 Dictionary* create_dictionary();
307
308 void initialize_name(Handle class_loader);
309 public:
310 // GC interface.
311 void clear_claimed() { _claimed = 0; }
312 bool claimed() const { return _claimed == 1; }
313 bool claim();
314
315 bool is_alive() const;
316
317 // Accessors
318 ClassLoaderMetaspace* metaspace_or_null() const { return _metaspace; }
319
320 static ClassLoaderData* the_null_class_loader_data() {
321 return _the_null_class_loader_data;
|
62 class PackageEntryTable;
63 class DictionaryEntry;
64 class Dictionary;
65
66 // GC root for walking class loader data created
67
68 class ClassLoaderDataGraph : public AllStatic {
69 friend class ClassLoaderData;
70 friend class ClassLoaderDataGraphMetaspaceIterator;
71 friend class ClassLoaderDataGraphKlassIteratorAtomic;
72 friend class ClassLoaderDataGraphKlassIteratorStatic;
73 friend class VMStructs;
74 private:
75 // All CLDs (except the null CLD) can be reached by walking _head->_next->...
76 static ClassLoaderData* _head;
77 static ClassLoaderData* _unloading;
78 // CMS support.
79 static ClassLoaderData* _saved_head;
80 static ClassLoaderData* _saved_unloading;
81 static bool _should_purge;
82
83 // Set if there's anything to purge in the deallocate lists or previous versions
84 // during a safepoint after class unloading in a full GC.
85 static bool _should_clean_deallocate_lists;
86 static bool _safepoint_cleanup_needed;
87
88 // OOM has been seen in metaspace allocation. Used to prevent some
89 // allocations until class unloading
90 static bool _metaspace_oom;
91
92 static volatile size_t _num_instance_classes;
93 static volatile size_t _num_array_classes;
94
95 static ClassLoaderData* add_to_graph(Handle class_loader, bool anonymous);
96 static ClassLoaderData* add(Handle class_loader, bool anonymous);
97
98 public:
99 static ClassLoaderData* find_or_create(Handle class_loader);
100 static void purge();
101 static void clear_claimed_marks();
102 // oops do
103 static void oops_do(OopClosure* f, bool must_claim);
104 static void keep_alive_oops_do(OopClosure* blk, bool must_claim);
105 static void always_strong_oops_do(OopClosure* blk, bool must_claim);
106 // cld do
107 static void cld_do(CLDClosure* cl);
108 static void cld_unloading_do(CLDClosure* cl);
109 static void roots_cld_do(CLDClosure* strong, CLDClosure* weak);
110 static void keep_alive_cld_do(CLDClosure* cl);
111 static void always_strong_cld_do(CLDClosure* cl);
112 // klass do
113 // Walking classes through the ClassLoaderDataGraph include array classes. It also includes
114 // classes that are allocated but not loaded, classes that have errors, and scratch classes
115 // for redefinition. These classes are removed during the next class unloading.
116 // Walking the ClassLoaderDataGraph also includes anonymous classes.
117 static void classes_do(KlassClosure* klass_closure);
118 static void classes_do(void f(Klass* const));
119 static void methods_do(void f(Method*));
120 static void modules_do(void f(ModuleEntry*));
121 static void modules_unloading_do(void f(ModuleEntry*));
122 static void packages_do(void f(PackageEntry*));
123 static void packages_unloading_do(void f(PackageEntry*));
124 static void loaded_classes_do(KlassClosure* klass_closure);
125 static void classes_unloading_do(void f(Klass* const));
126 static bool do_unloading(bool do_cleaning);
127
128 // Expose state to avoid logging overhead in safepoint cleanup tasks.
129 static inline bool should_clean_metaspaces();
130 static void set_should_clean_deallocate_lists() { _should_clean_deallocate_lists = true; }
131 static void clean_deallocate_lists(bool purge_previous_versions);
132 static void walk_metadata_and_clean_metaspaces();
133
134 // dictionary do
135 // Iterate over all klasses in dictionary, but
136 // just the classes from defining class loaders.
137 static void dictionary_classes_do(void f(InstanceKlass*));
138 // Added for initialize_itable_for_klass to handle exceptions.
139 static void dictionary_classes_do(void f(InstanceKlass*, TRAPS), TRAPS);
140
141 // Iterate all classes and their class loaders, including initiating class loaders.
142 static void dictionary_all_entries_do(void f(InstanceKlass*, ClassLoaderData*));
143
144 // VM_CounterDecay iteration support
145 static InstanceKlass* try_get_next_class();
146
147 static void verify_dictionary();
148 static void print_dictionary(outputStream* st);
149 static void print_dictionary_statistics(outputStream* st);
150
151 // CMS support.
152 static void remember_new_clds(bool remember) { _saved_head = (remember ? _head : NULL); }
294 bool has_modified_oops() { return _modified_oops; }
295
296 void accumulate_modified_oops() { if (has_modified_oops()) _accumulated_modified_oops = true; }
297 void clear_accumulated_modified_oops() { _accumulated_modified_oops = false; }
298 bool has_accumulated_modified_oops() { return _accumulated_modified_oops; }
299 private:
300
301 void unload();
302 bool keep_alive() const { return _keep_alive > 0; }
303
304 oop holder_phantom() const;
305 void classes_do(void f(Klass*));
306 void loaded_classes_do(KlassClosure* klass_closure);
307 void classes_do(void f(InstanceKlass*));
308 void methods_do(void f(Method*));
309 void modules_do(void f(ModuleEntry*));
310 void packages_do(void f(PackageEntry*));
311
312 // Deallocate free list during class unloading.
313 void free_deallocate_list(); // for the classes that are not unloaded
314 void free_deallocate_list_C_heap_structures(); // for the classes that are unloaded
315
316 // Allocate out of this class loader data
317 MetaWord* allocate(size_t size);
318
319 Dictionary* create_dictionary();
320
321 void initialize_name(Handle class_loader);
322 public:
323 // GC interface.
324 void clear_claimed() { _claimed = 0; }
325 bool claimed() const { return _claimed == 1; }
326 bool claim();
327
328 bool is_alive() const;
329
330 // Accessors
331 ClassLoaderMetaspace* metaspace_or_null() const { return _metaspace; }
332
333 static ClassLoaderData* the_null_class_loader_data() {
334 return _the_null_class_loader_data;
|