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 "classfile/systemDictionary.hpp"
27 #include "oops/oop.inline.hpp"
28 #include "prims/jvmtiExport.hpp"
29 #include "runtime/jniHandles.hpp"
30 #include "runtime/mutexLocker.hpp"
31 #include "runtime/thread.inline.hpp"
32
33 JNIHandleBlock* JNIHandles::_global_handles = NULL;
34 JNIHandleBlock* JNIHandles::_weak_global_handles = NULL;
35 oop JNIHandles::_deleted_handle = NULL;
36
37
38 jobject JNIHandles::make_local(oop obj) {
39 if (obj == NULL) {
40 return NULL; // ignore null handles
41 } else {
42 Thread* thread = Thread::current();
43 assert(Universe::heap()->is_in_reserved(obj), "sanity check");
44 return thread->active_handles()->allocate_handle(obj);
45 }
46 }
376 current_chain = current_chain->pop_frame_link();
377 }
378 }
379
380
381 void JNIHandleBlock::weak_oops_do(BoolObjectClosure* is_alive,
382 OopClosure* f) {
383 for (JNIHandleBlock* current = this; current != NULL; current = current->_next) {
384 assert(current->pop_frame_link() == NULL,
385 "blocks holding weak global JNI handles should not have pop frame link set");
386 for (int index = 0; index < current->_top; index++) {
387 oop* root = &(current->_handles)[index];
388 oop value = *root;
389 // traverse heap pointers only, not deleted handles or free list pointers
390 if (value != NULL && Universe::heap()->is_in_reserved(value)) {
391 if (is_alive->do_object_b(value)) {
392 // The weakly referenced object is alive, update pointer
393 f->do_oop(root);
394 } else {
395 // The weakly referenced object is not alive, clear the reference by storing NULL
396 if (TraceReferenceGC) {
397 tty->print_cr("Clearing JNI weak reference (" INTPTR_FORMAT ")", p2i(root));
398 }
399 *root = NULL;
400 }
401 }
402 }
403 // the next handle block is valid only if current block is full
404 if (current->_top < block_size_in_oops) {
405 break;
406 }
407 }
408
409 /*
410 * JVMTI data structures may also contain weak oops. The iteration of them
411 * is placed here so that we don't need to add it to each of the collectors.
412 */
413 JvmtiExport::weak_oops_do(is_alive, f);
414 }
415
416
417 jobject JNIHandleBlock::allocate_handle(oop obj) {
418 assert(Universe::heap()->is_in_reserved(obj), "sanity check");
|
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 "classfile/systemDictionary.hpp"
27 #include "logging/log.hpp"
28 #include "oops/oop.inline.hpp"
29 #include "prims/jvmtiExport.hpp"
30 #include "runtime/jniHandles.hpp"
31 #include "runtime/mutexLocker.hpp"
32 #include "runtime/thread.inline.hpp"
33
34 JNIHandleBlock* JNIHandles::_global_handles = NULL;
35 JNIHandleBlock* JNIHandles::_weak_global_handles = NULL;
36 oop JNIHandles::_deleted_handle = NULL;
37
38
39 jobject JNIHandles::make_local(oop obj) {
40 if (obj == NULL) {
41 return NULL; // ignore null handles
42 } else {
43 Thread* thread = Thread::current();
44 assert(Universe::heap()->is_in_reserved(obj), "sanity check");
45 return thread->active_handles()->allocate_handle(obj);
46 }
47 }
377 current_chain = current_chain->pop_frame_link();
378 }
379 }
380
381
382 void JNIHandleBlock::weak_oops_do(BoolObjectClosure* is_alive,
383 OopClosure* f) {
384 for (JNIHandleBlock* current = this; current != NULL; current = current->_next) {
385 assert(current->pop_frame_link() == NULL,
386 "blocks holding weak global JNI handles should not have pop frame link set");
387 for (int index = 0; index < current->_top; index++) {
388 oop* root = &(current->_handles)[index];
389 oop value = *root;
390 // traverse heap pointers only, not deleted handles or free list pointers
391 if (value != NULL && Universe::heap()->is_in_reserved(value)) {
392 if (is_alive->do_object_b(value)) {
393 // The weakly referenced object is alive, update pointer
394 f->do_oop(root);
395 } else {
396 // The weakly referenced object is not alive, clear the reference by storing NULL
397 log_develop(gc, ref)("Clearing JNI weak reference (" INTPTR_FORMAT ")", p2i(root));
398 *root = NULL;
399 }
400 }
401 }
402 // the next handle block is valid only if current block is full
403 if (current->_top < block_size_in_oops) {
404 break;
405 }
406 }
407
408 /*
409 * JVMTI data structures may also contain weak oops. The iteration of them
410 * is placed here so that we don't need to add it to each of the collectors.
411 */
412 JvmtiExport::weak_oops_do(is_alive, f);
413 }
414
415
416 jobject JNIHandleBlock::allocate_handle(oop obj) {
417 assert(Universe::heap()->is_in_reserved(obj), "sanity check");
|