src/share/vm/classfile/classLoaderData.cpp

changeset 8762
654eaca01d61
parent 8445
001e0c530e2c
child 8856
ac27a9c85bea
child 9327
f96fcd9e1e1b
equal deleted inserted replaced
8761:4c3cae5323bb 8762:654eaca01d61
1 /* 1 /*
2 * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
76 // An anonymous class loader data doesn't have anything to keep 76 // An anonymous class loader data doesn't have anything to keep
77 // it from being unloaded during parsing of the anonymous class. 77 // it from being unloaded during parsing of the anonymous class.
78 // The null-class-loader should always be kept alive. 78 // The null-class-loader should always be kept alive.
79 _keep_alive(is_anonymous || h_class_loader.is_null()), 79 _keep_alive(is_anonymous || h_class_loader.is_null()),
80 _metaspace(NULL), _unloading(false), _klasses(NULL), 80 _metaspace(NULL), _unloading(false), _klasses(NULL),
81 _claimed(0), _jmethod_ids(NULL), _handles(NULL), _deallocate_list(NULL), 81 _claimed(0), _jmethod_ids(NULL), _handles(), _deallocate_list(NULL),
82 _next(NULL), _dependencies(dependencies), 82 _next(NULL), _dependencies(dependencies),
83 _metaspace_lock(new Mutex(Monitor::leaf+1, "Metaspace allocation lock", true)) { 83 _metaspace_lock(new Mutex(Monitor::leaf+1, "Metaspace allocation lock", true)) {
84 // empty 84 // empty
85 } 85 }
86 86
94 // Create empty dependencies array to add to. CMS requires this to be 94 // Create empty dependencies array to add to. CMS requires this to be
95 // an oop so that it can track additions via card marks. We think. 95 // an oop so that it can track additions via card marks. We think.
96 _list_head = oopFactory::new_objectArray(2, CHECK); 96 _list_head = oopFactory::new_objectArray(2, CHECK);
97 } 97 }
98 98
99 ClassLoaderData::ChunkedHandleList::~ChunkedHandleList() {
100 Chunk* c = _head;
101 while (c != NULL) {
102 Chunk* next = c->_next;
103 delete c;
104 c = next;
105 }
106 }
107
108 oop* ClassLoaderData::ChunkedHandleList::add(oop o) {
109 if (_head == NULL || _head->_size == Chunk::CAPACITY) {
110 Chunk* next = new Chunk(_head);
111 OrderAccess::release_store_ptr(&_head, next);
112 }
113 oop* handle = &_head->_data[_head->_size];
114 *handle = o;
115 OrderAccess::release_store(&_head->_size, _head->_size + 1);
116 return handle;
117 }
118
119 inline void ClassLoaderData::ChunkedHandleList::oops_do_chunk(OopClosure* f, Chunk* c, const juint size) {
120 for (juint i = 0; i < size; i++) {
121 if (c->_data[i] != NULL) {
122 f->do_oop(&c->_data[i]);
123 }
124 }
125 }
126
127 void ClassLoaderData::ChunkedHandleList::oops_do(OopClosure* f) {
128 Chunk* head = (Chunk*) OrderAccess::load_ptr_acquire(&_head);
129 if (head != NULL) {
130 // Must be careful when reading size of head
131 oops_do_chunk(f, head, OrderAccess::load_acquire(&head->_size));
132 for (Chunk* c = head->_next; c != NULL; c = c->_next) {
133 oops_do_chunk(f, c, c->_size);
134 }
135 }
136 }
137
99 bool ClassLoaderData::claim() { 138 bool ClassLoaderData::claim() {
100 if (_claimed == 1) { 139 if (_claimed == 1) {
101 return false; 140 return false;
102 } 141 }
103 142
109 return; 148 return;
110 } 149 }
111 150
112 f->do_oop(&_class_loader); 151 f->do_oop(&_class_loader);
113 _dependencies.oops_do(f); 152 _dependencies.oops_do(f);
114 _handles->oops_do(f); 153 _handles.oops_do(f);
115 if (klass_closure != NULL) { 154 if (klass_closure != NULL) {
116 classes_do(klass_closure); 155 classes_do(klass_closure);
117 } 156 }
118 } 157 }
119 158
340 Metaspace *m = _metaspace; 379 Metaspace *m = _metaspace;
341 if (m != NULL) { 380 if (m != NULL) {
342 _metaspace = NULL; 381 _metaspace = NULL;
343 // release the metaspace 382 // release the metaspace
344 delete m; 383 delete m;
345 // release the handles
346 if (_handles != NULL) {
347 JNIHandleBlock::release_block(_handles);
348 _handles = NULL;
349 }
350 } 384 }
351 385
352 // Clear all the JNI handles for methods 386 // Clear all the JNI handles for methods
353 // These aren't deallocated and are going to look like a leak, but that's 387 // These aren't deallocated and are going to look like a leak, but that's
354 // needed because we can't really get rid of jmethodIDs because we don't 388 // needed because we can't really get rid of jmethodIDs because we don't
404 } 438 }
405 } 439 }
406 return _metaspace; 440 return _metaspace;
407 } 441 }
408 442
409 JNIHandleBlock* ClassLoaderData::handles() const { return _handles; }
410 void ClassLoaderData::set_handles(JNIHandleBlock* handles) { _handles = handles; }
411
412 jobject ClassLoaderData::add_handle(Handle h) { 443 jobject ClassLoaderData::add_handle(Handle h) {
413 MutexLockerEx ml(metaspace_lock(), Mutex::_no_safepoint_check_flag); 444 MutexLockerEx ml(metaspace_lock(), Mutex::_no_safepoint_check_flag);
414 if (handles() == NULL) { 445 return (jobject) _handles.add(h());
415 set_handles(JNIHandleBlock::allocate_block());
416 }
417 return handles()->allocate_handle(h());
418 } 446 }
419 447
420 // Add this metadata pointer to be freed when it's safe. This is only during 448 // Add this metadata pointer to be freed when it's safe. This is only during
421 // class unloading because Handles might point to this metadata field. 449 // class unloading because Handles might point to this metadata field.
422 void ClassLoaderData::add_to_deallocate_list(Metadata* m) { 450 void ClassLoaderData::add_to_deallocate_list(Metadata* m) {
477 out->print("ClassLoaderData CLD: "PTR_FORMAT", loader: "PTR_FORMAT", loader_klass: "PTR_FORMAT" %s {", 505 out->print("ClassLoaderData CLD: "PTR_FORMAT", loader: "PTR_FORMAT", loader_klass: "PTR_FORMAT" %s {",
478 p2i(this), p2i((void *)class_loader()), 506 p2i(this), p2i((void *)class_loader()),
479 p2i(class_loader() != NULL ? class_loader()->klass() : NULL), loader_name()); 507 p2i(class_loader() != NULL ? class_loader()->klass() : NULL), loader_name());
480 if (claimed()) out->print(" claimed "); 508 if (claimed()) out->print(" claimed ");
481 if (is_unloading()) out->print(" unloading "); 509 if (is_unloading()) out->print(" unloading ");
482 out->print(" handles " INTPTR_FORMAT, p2i(handles()));
483 out->cr(); 510 out->cr();
484 if (metaspace_or_null() != NULL) { 511 if (metaspace_or_null() != NULL) {
485 out->print_cr("metaspace: " INTPTR_FORMAT, p2i(metaspace_or_null())); 512 out->print_cr("metaspace: " INTPTR_FORMAT, p2i(metaspace_or_null()));
486 metaspace_or_null()->dump(out); 513 metaspace_or_null()->dump(out);
487 } else { 514 } else {

mercurial