122 f->do_oop(&_deleted_handle); |
122 f->do_oop(&_deleted_handle); |
123 _global_handles->oops_do(f); |
123 _global_handles->oops_do(f); |
124 } |
124 } |
125 |
125 |
126 |
126 |
127 void JNIHandles::weak_oops_do(BoolObjectClosure* is_alive, OopClosure* f) { |
127 size_t JNIHandles::weak_oops_do(BoolObjectClosure* is_alive, OopClosure* f) { |
128 _weak_global_handles->weak_oops_do(is_alive, f); |
128 return _weak_global_handles->weak_oops_do(is_alive, f); |
129 } |
129 } |
130 |
130 |
131 |
131 |
132 void JNIHandles::initialize() { |
132 void JNIHandles::initialize() { |
133 _global_handles = JNIHandleBlock::allocate_block(); |
133 _global_handles = JNIHandleBlock::allocate_block(); |
378 current_chain = current_chain->pop_frame_link(); |
378 current_chain = current_chain->pop_frame_link(); |
379 } |
379 } |
380 } |
380 } |
381 |
381 |
382 |
382 |
383 void JNIHandleBlock::weak_oops_do(BoolObjectClosure* is_alive, |
383 size_t JNIHandleBlock::weak_oops_do(BoolObjectClosure* is_alive, |
384 OopClosure* f) { |
384 OopClosure* f) { |
|
385 size_t count = 0; |
385 for (JNIHandleBlock* current = this; current != NULL; current = current->_next) { |
386 for (JNIHandleBlock* current = this; current != NULL; current = current->_next) { |
386 assert(current->pop_frame_link() == NULL, |
387 assert(current->pop_frame_link() == NULL, |
387 "blocks holding weak global JNI handles should not have pop frame link set"); |
388 "blocks holding weak global JNI handles should not have pop frame link set"); |
388 for (int index = 0; index < current->_top; index++) { |
389 for (int index = 0; index < current->_top; index++) { |
389 oop* root = &(current->_handles)[index]; |
390 oop* root = &(current->_handles)[index]; |
390 oop value = *root; |
391 oop value = *root; |
391 // traverse heap pointers only, not deleted handles or free list pointers |
392 // traverse heap pointers only, not deleted handles or free list pointers |
392 if (value != NULL && Universe::heap()->is_in_reserved(value)) { |
393 if (value != NULL && Universe::heap()->is_in_reserved(value)) { |
|
394 count++; |
393 if (is_alive->do_object_b(value)) { |
395 if (is_alive->do_object_b(value)) { |
394 // The weakly referenced object is alive, update pointer |
396 // The weakly referenced object is alive, update pointer |
395 f->do_oop(root); |
397 f->do_oop(root); |
396 } else { |
398 } else { |
397 // The weakly referenced object is not alive, clear the reference by storing NULL |
399 // The weakly referenced object is not alive, clear the reference by storing NULL |
410 |
412 |
411 /* |
413 /* |
412 * JVMTI data structures may also contain weak oops. The iteration of them |
414 * JVMTI data structures may also contain weak oops. The iteration of them |
413 * is placed here so that we don't need to add it to each of the collectors. |
415 * is placed here so that we don't need to add it to each of the collectors. |
414 */ |
416 */ |
415 JvmtiExport::weak_oops_do(is_alive, f); |
417 count += JvmtiExport::weak_oops_do(is_alive, f); |
|
418 |
|
419 return count; |
416 } |
420 } |
417 |
421 |
418 |
422 |
419 jobject JNIHandleBlock::allocate_handle(oop obj) { |
423 jobject JNIHandleBlock::allocate_handle(oop obj) { |
420 assert(Universe::heap()->is_in_reserved(obj), "sanity check"); |
424 assert(Universe::heap()->is_in_reserved(obj), "sanity check"); |