Print this page
rev 6875 : 8056240: Investigate increased GC remark time after class unloading changes in CRM Fuse
Reviewed-by: mgerdin, coleenp, bdelsart
Split |
Split |
Close |
Expand all |
Collapse all |
--- old/src/share/vm/classfile/classLoaderData.hpp
+++ new/src/share/vm/classfile/classLoaderData.hpp
1 1 /*
2 2 * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
3 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 4 *
5 5 * This code is free software; you can redistribute it and/or modify it
6 6 * under the terms of the GNU General Public License version 2 only, as
7 7 * published by the Free Software Foundation.
8 8 *
9 9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 12 * version 2 for more details (a copy is included in the LICENSE file that
13 13 * accompanied this code).
14 14 *
15 15 * You should have received a copy of the GNU General Public License version
16 16 * 2 along with this work; if not, write to the Free Software Foundation,
17 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 18 *
19 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 20 * or visit www.oracle.com if you need additional information or have any
21 21 * questions.
22 22 *
23 23 */
24 24
25 25 #ifndef SHARE_VM_CLASSFILE_CLASSLOADERDATA_HPP
26 26 #define SHARE_VM_CLASSFILE_CLASSLOADERDATA_HPP
27 27
28 28 #include "memory/allocation.hpp"
29 29 #include "memory/memRegion.hpp"
30 30 #include "memory/metaspace.hpp"
31 31 #include "memory/metaspaceCounters.hpp"
32 32 #include "runtime/mutex.hpp"
33 33 #include "utilities/growableArray.hpp"
34 34 #if INCLUDE_TRACE
35 35 # include "utilities/ticks.hpp"
36 36 #endif
37 37
38 38 //
39 39 // A class loader represents a linkset. Conceptually, a linkset identifies
40 40 // the complete transitive closure of resolved links that a dynamic linker can
41 41 // produce.
42 42 //
43 43 // A ClassLoaderData also encapsulates the allocation space, called a metaspace,
44 44 // used by the dynamic linker to allocate the runtime representation of all
45 45 // the types it defines.
46 46 //
47 47 // ClassLoaderData are stored in the runtime representation of classes and the
48 48 // system dictionary, are roots of garbage collection, and provides iterators
49 49 // for root tracing and other GC operations.
50 50
51 51 class ClassLoaderData;
52 52 class JNIMethodBlock;
53 53 class JNIHandleBlock;
54 54 class Metadebug;
55 55
56 56 // GC root for walking class loader data created
57 57
58 58 class ClassLoaderDataGraph : public AllStatic {
59 59 friend class ClassLoaderData;
60 60 friend class ClassLoaderDataGraphMetaspaceIterator;
61 61 friend class ClassLoaderDataGraphKlassIteratorAtomic;
62 62 friend class VMStructs;
63 63 private:
↓ open down ↓ |
63 lines elided |
↑ open up ↑ |
64 64 // All CLDs (except the null CLD) can be reached by walking _head->_next->...
65 65 static ClassLoaderData* _head;
66 66 static ClassLoaderData* _unloading;
67 67 // CMS support.
68 68 static ClassLoaderData* _saved_head;
69 69 static ClassLoaderData* _saved_unloading;
70 70 static bool _should_purge;
71 71
72 72 static ClassLoaderData* add(Handle class_loader, bool anonymous, TRAPS);
73 73 static void post_class_unload_events(void);
74 + static void clean_metaspaces();
74 75 public:
75 76 static ClassLoaderData* find_or_create(Handle class_loader, TRAPS);
76 77 static void purge();
77 78 static void clear_claimed_marks();
78 79 // oops do
79 80 static void oops_do(OopClosure* f, KlassClosure* klass_closure, bool must_claim);
80 81 static void keep_alive_oops_do(OopClosure* blk, KlassClosure* klass_closure, bool must_claim);
81 82 static void always_strong_oops_do(OopClosure* blk, KlassClosure* klass_closure, bool must_claim);
82 83 // cld do
83 84 static void cld_do(CLDClosure* cl);
84 85 static void roots_cld_do(CLDClosure* strong, CLDClosure* weak);
85 86 static void keep_alive_cld_do(CLDClosure* cl);
86 87 static void always_strong_cld_do(CLDClosure* cl);
87 88 // klass do
88 89 static void classes_do(KlassClosure* klass_closure);
89 90 static void classes_do(void f(Klass* const));
90 91 static void loaded_classes_do(KlassClosure* klass_closure);
91 92 static void classes_unloading_do(void f(Klass* const));
92 - static bool do_unloading(BoolObjectClosure* is_alive);
93 + static bool do_unloading(BoolObjectClosure* is_alive, bool clean_alive);
93 94
94 95 // CMS support.
95 96 static void remember_new_clds(bool remember) { _saved_head = (remember ? _head : NULL); }
96 97 static GrowableArray<ClassLoaderData*>* new_clds();
97 98
98 99 static void set_should_purge(bool b) { _should_purge = b; }
99 100 static void purge_if_needed() {
100 101 // Only purge the CLDG for CMS if concurrent sweep is complete.
101 102 if (_should_purge) {
102 103 purge();
103 104 // reset for next time.
104 105 set_should_purge(false);
105 106 }
106 107 }
107 108
109 + static void free_deallocate_lists();
110 +
108 111 static void dump_on(outputStream * const out) PRODUCT_RETURN;
109 112 static void dump() { dump_on(tty); }
110 113 static void verify();
111 114
112 115 static bool unload_list_contains(const void* x);
113 116 #ifndef PRODUCT
114 117 static bool contains_loader_data(ClassLoaderData* loader_data);
115 118 #endif
116 119
117 120 #if INCLUDE_TRACE
118 121 private:
119 122 static Ticks _class_unload_time;
120 123 static void class_unload_event(Klass* const k);
121 124 #endif
122 125 };
123 126
124 127 // ClassLoaderData class
125 128
126 129 class ClassLoaderData : public CHeapObj<mtClass> {
127 130 friend class VMStructs;
128 131 private:
129 132 class Dependencies VALUE_OBJ_CLASS_SPEC {
130 133 objArrayOop _list_head;
131 134 void locked_add(objArrayHandle last,
132 135 objArrayHandle new_dependency,
133 136 Thread* THREAD);
134 137 public:
135 138 Dependencies() : _list_head(NULL) {}
136 139 Dependencies(TRAPS) : _list_head(NULL) {
137 140 init(CHECK);
138 141 }
139 142 void add(Handle dependency, TRAPS);
140 143 void init(TRAPS);
141 144 void oops_do(OopClosure* f);
142 145 };
143 146
144 147 friend class ClassLoaderDataGraph;
145 148 friend class ClassLoaderDataGraphKlassIteratorAtomic;
146 149 friend class ClassLoaderDataGraphMetaspaceIterator;
147 150 friend class MetaDataFactory;
148 151 friend class Method;
149 152
150 153 static ClassLoaderData * _the_null_class_loader_data;
151 154
152 155 oop _class_loader; // oop used to uniquely identify a class loader
153 156 // class loader or a canonical class path
154 157 Dependencies _dependencies; // holds dependencies from this class loader
155 158 // data to others.
156 159
157 160 Metaspace * _metaspace; // Meta-space where meta-data defined by the
158 161 // classes in the class loader are allocated.
159 162 Mutex* _metaspace_lock; // Locks the metaspace for allocations and setup.
160 163 bool _unloading; // true if this class loader goes away
161 164 bool _keep_alive; // if this CLD is kept alive without a keep_alive_object().
162 165 bool _is_anonymous; // if this CLD is for an anonymous class
163 166 volatile int _claimed; // true if claimed, for example during GC traces.
164 167 // To avoid applying oop closure more than once.
165 168 // Has to be an int because we cas it.
166 169 Klass* _klasses; // The classes defined by the class loader.
167 170
168 171 JNIHandleBlock* _handles; // Handles to constant pool arrays
169 172
170 173 // These method IDs are created for the class loader and set to NULL when the
171 174 // class loader is unloaded. They are rarely freed, only for redefine classes
172 175 // and if they lose a data race in InstanceKlass.
173 176 JNIMethodBlock* _jmethod_ids;
174 177
175 178 // Metadata to be deallocated when it's safe at class unloading, when
176 179 // this class loader isn't unloaded itself.
177 180 GrowableArray<Metadata*>* _deallocate_list;
178 181
179 182 // Support for walking class loader data objects
180 183 ClassLoaderData* _next; /// Next loader_datas created
181 184
182 185 // ReadOnly and ReadWrite metaspaces (static because only on the null
183 186 // class loader for now).
184 187 static Metaspace* _ro_metaspace;
185 188 static Metaspace* _rw_metaspace;
186 189
187 190 void set_next(ClassLoaderData* next) { _next = next; }
188 191 ClassLoaderData* next() const { return _next; }
189 192
190 193 ClassLoaderData(Handle h_class_loader, bool is_anonymous, Dependencies dependencies);
191 194 ~ClassLoaderData();
192 195
193 196 void set_metaspace(Metaspace* m) { _metaspace = m; }
194 197
195 198 JNIHandleBlock* handles() const;
196 199 void set_handles(JNIHandleBlock* handles);
197 200
198 201 Mutex* metaspace_lock() const { return _metaspace_lock; }
199 202
200 203 // GC interface.
201 204 void clear_claimed() { _claimed = 0; }
202 205 bool claimed() const { return _claimed == 1; }
203 206 bool claim();
204 207
205 208 void unload();
206 209 bool keep_alive() const { return _keep_alive; }
207 210 void classes_do(void f(Klass*));
208 211 void loaded_classes_do(KlassClosure* klass_closure);
209 212 void classes_do(void f(InstanceKlass*));
210 213
211 214 // Deallocate free list during class unloading.
212 215 void free_deallocate_list();
213 216
214 217 // Allocate out of this class loader data
215 218 MetaWord* allocate(size_t size);
216 219
217 220 public:
218 221
219 222 bool is_alive(BoolObjectClosure* is_alive_closure) const;
220 223
221 224 // Accessors
222 225 Metaspace* metaspace_or_null() const { return _metaspace; }
223 226
224 227 static ClassLoaderData* the_null_class_loader_data() {
225 228 return _the_null_class_loader_data;
226 229 }
227 230
228 231 bool is_anonymous() const { return _is_anonymous; }
229 232
230 233 static void init_null_class_loader_data() {
231 234 assert(_the_null_class_loader_data == NULL, "cannot initialize twice");
232 235 assert(ClassLoaderDataGraph::_head == NULL, "cannot initialize twice");
233 236
234 237 // We explicitly initialize the Dependencies object at a later phase in the initialization
235 238 _the_null_class_loader_data = new ClassLoaderData((oop)NULL, false, Dependencies());
236 239 ClassLoaderDataGraph::_head = _the_null_class_loader_data;
237 240 assert(_the_null_class_loader_data->is_the_null_class_loader_data(), "Must be");
238 241 if (DumpSharedSpaces) {
239 242 _the_null_class_loader_data->initialize_shared_metaspaces();
240 243 }
241 244 }
242 245
243 246 bool is_the_null_class_loader_data() const {
244 247 return this == _the_null_class_loader_data;
245 248 }
246 249 bool is_ext_class_loader_data() const;
247 250
248 251 // The Metaspace is created lazily so may be NULL. This
249 252 // method will allocate a Metaspace if needed.
250 253 Metaspace* metaspace_non_null();
251 254
252 255 oop class_loader() const { return _class_loader; }
253 256
254 257 // The object the GC is using to keep this ClassLoaderData alive.
255 258 oop keep_alive_object() const;
256 259
257 260 // Returns true if this class loader data is for a loader going away.
258 261 bool is_unloading() const {
259 262 assert(!(is_the_null_class_loader_data() && _unloading), "The null class loader can never be unloaded");
260 263 return _unloading;
261 264 }
262 265
263 266 // Used to make sure that this CLD is not unloaded.
264 267 void set_keep_alive(bool value) { _keep_alive = value; }
265 268
266 269 unsigned int identity_hash() {
267 270 return _class_loader == NULL ? 0 : _class_loader->identity_hash();
268 271 }
269 272
270 273 // Used when tracing from klasses.
271 274 void oops_do(OopClosure* f, KlassClosure* klass_closure, bool must_claim);
272 275
273 276 void classes_do(KlassClosure* klass_closure);
274 277
275 278 JNIMethodBlock* jmethod_ids() const { return _jmethod_ids; }
276 279 void set_jmethod_ids(JNIMethodBlock* new_block) { _jmethod_ids = new_block; }
277 280
278 281 void print_value() { print_value_on(tty); }
279 282 void print_value_on(outputStream* out) const;
280 283 void dump(outputStream * const out) PRODUCT_RETURN;
281 284 void verify();
282 285 const char* loader_name();
283 286
284 287 jobject add_handle(Handle h);
285 288 void add_class(Klass* k);
286 289 void remove_class(Klass* k);
287 290 bool contains_klass(Klass* k);
288 291 void record_dependency(Klass* to, TRAPS);
289 292 void init_dependencies(TRAPS);
290 293
291 294 void add_to_deallocate_list(Metadata* m);
292 295
293 296 static ClassLoaderData* class_loader_data(oop loader);
294 297 static ClassLoaderData* class_loader_data_or_null(oop loader);
295 298 static ClassLoaderData* anonymous_class_loader_data(oop loader, TRAPS);
296 299 static void print_loader(ClassLoaderData *loader_data, outputStream *out);
297 300
298 301 // CDS support
299 302 Metaspace* ro_metaspace();
300 303 Metaspace* rw_metaspace();
301 304 void initialize_shared_metaspaces();
302 305 };
303 306
304 307 // An iterator that distributes Klasses to parallel worker threads.
305 308 class ClassLoaderDataGraphKlassIteratorAtomic : public StackObj {
306 309 volatile Klass* _next_klass;
307 310 public:
308 311 ClassLoaderDataGraphKlassIteratorAtomic();
309 312 Klass* next_klass();
310 313 private:
311 314 static Klass* next_klass_in_cldg(Klass* klass);
312 315 };
313 316
314 317 class ClassLoaderDataGraphMetaspaceIterator : public StackObj {
315 318 ClassLoaderData* _data;
316 319 public:
317 320 ClassLoaderDataGraphMetaspaceIterator();
318 321 ~ClassLoaderDataGraphMetaspaceIterator();
319 322 bool repeat() { return _data != NULL; }
320 323 Metaspace* get_next() {
321 324 assert(_data != NULL, "Should not be NULL in call to the iterator");
322 325 Metaspace* result = _data->metaspace_or_null();
323 326 _data = _data->next();
324 327 // This result might be NULL for class loaders without metaspace
325 328 // yet. It would be nice to return only non-null results but
326 329 // there is no guarantee that there will be a non-null result
327 330 // down the list so the caller is going to have to check.
328 331 return result;
329 332 }
330 333 };
331 334 #endif // SHARE_VM_CLASSFILE_CLASSLOADERDATA_HPP
↓ open down ↓ |
214 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX