src/share/vm/runtime/jniHandles.cpp

Print this page
rev 6562 : 8043224: -Xcheck:jni improvements to exception checking and excessive local refs
Summary: Warning when not checking exceptions from function that require so, also when local refs expand beyond capacity.
Reviewed-by: zgu, coleenp, hseigel


 281       _blocks_allocated++;
 282       if (TraceJNIHandleAllocation) {
 283         tty->print_cr("JNIHandleBlock " INTPTR_FORMAT " allocated (%d total blocks)",
 284                       block, _blocks_allocated);
 285       }
 286       if (ZapJNIHandleArea) block->zap();
 287       #ifndef PRODUCT
 288       // Link new block to list of all allocated blocks
 289       block->_block_list_link = _block_list;
 290       _block_list = block;
 291       #endif
 292     } else {
 293       // Get block from free list
 294       block = _block_free_list;
 295       _block_free_list = _block_free_list->_next;
 296     }
 297   }
 298   block->_top  = 0;
 299   block->_next = NULL;
 300   block->_pop_frame_link = NULL;

 301   // _last, _free_list & _allocate_before_rebuild initialized in allocate_handle
 302   debug_only(block->_last = NULL);
 303   debug_only(block->_free_list = NULL);
 304   debug_only(block->_allocate_before_rebuild = -1);
 305   return block;
 306 }
 307 
 308 
 309 void JNIHandleBlock::release_block(JNIHandleBlock* block, Thread* thread) {
 310   assert(thread == NULL || thread == Thread::current(), "sanity check");
 311   JNIHandleBlock* pop_frame_link = block->pop_frame_link();
 312   // Put returned block at the beginning of the thread-local free list.
 313   // Note that if thread == NULL, we use it as an implicit argument that
 314   // we _don't_ want the block to be kept on the free_handle_block.
 315   // See for instance JavaThread::exit().
 316   if (thread != NULL ) {
 317     if (ZapJNIHandleArea) block->zap();
 318     JNIHandleBlock* freelist = thread->free_handle_block();
 319     block->_pop_frame_link = NULL;
 320     thread->set_free_handle_block(block);


 512   return ((jobject)&_handles[0] <= handle && handle<(jobject)&_handles[_top]);
 513 }
 514 
 515 
 516 bool JNIHandleBlock::chain_contains(jobject handle) const {
 517   for (JNIHandleBlock* current = (JNIHandleBlock*) this; current != NULL; current = current->_next) {
 518     if (current->contains(handle)) {
 519       return true;
 520     }
 521   }
 522   return false;
 523 }
 524 
 525 
 526 int JNIHandleBlock::length() const {
 527   int result = 1;
 528   for (JNIHandleBlock* current = _next; current != NULL; current = current->_next) {
 529     result++;
 530   }
 531   return result;






 532 }
 533 
 534 // This method is not thread-safe, i.e., must be called while holding a lock on the
 535 // structure.
 536 long JNIHandleBlock::memory_usage() const {
 537   return length() * sizeof(JNIHandleBlock);
 538 }
 539 
 540 
 541 #ifndef PRODUCT
 542 
 543 bool JNIHandleBlock::any_contains(jobject handle) {
 544   for (JNIHandleBlock* current = _block_list; current != NULL; current = current->_block_list_link) {
 545     if (current->contains(handle)) {
 546       return true;
 547     }
 548   }
 549   return false;
 550 }
 551 




 281       _blocks_allocated++;
 282       if (TraceJNIHandleAllocation) {
 283         tty->print_cr("JNIHandleBlock " INTPTR_FORMAT " allocated (%d total blocks)",
 284                       block, _blocks_allocated);
 285       }
 286       if (ZapJNIHandleArea) block->zap();
 287       #ifndef PRODUCT
 288       // Link new block to list of all allocated blocks
 289       block->_block_list_link = _block_list;
 290       _block_list = block;
 291       #endif
 292     } else {
 293       // Get block from free list
 294       block = _block_free_list;
 295       _block_free_list = _block_free_list->_next;
 296     }
 297   }
 298   block->_top  = 0;
 299   block->_next = NULL;
 300   block->_pop_frame_link = NULL;
 301   block->_planned_capacity = block_size_in_oops;
 302   // _last, _free_list & _allocate_before_rebuild initialized in allocate_handle
 303   debug_only(block->_last = NULL);
 304   debug_only(block->_free_list = NULL);
 305   debug_only(block->_allocate_before_rebuild = -1);
 306   return block;
 307 }
 308 
 309 
 310 void JNIHandleBlock::release_block(JNIHandleBlock* block, Thread* thread) {
 311   assert(thread == NULL || thread == Thread::current(), "sanity check");
 312   JNIHandleBlock* pop_frame_link = block->pop_frame_link();
 313   // Put returned block at the beginning of the thread-local free list.
 314   // Note that if thread == NULL, we use it as an implicit argument that
 315   // we _don't_ want the block to be kept on the free_handle_block.
 316   // See for instance JavaThread::exit().
 317   if (thread != NULL ) {
 318     if (ZapJNIHandleArea) block->zap();
 319     JNIHandleBlock* freelist = thread->free_handle_block();
 320     block->_pop_frame_link = NULL;
 321     thread->set_free_handle_block(block);


 513   return ((jobject)&_handles[0] <= handle && handle<(jobject)&_handles[_top]);
 514 }
 515 
 516 
 517 bool JNIHandleBlock::chain_contains(jobject handle) const {
 518   for (JNIHandleBlock* current = (JNIHandleBlock*) this; current != NULL; current = current->_next) {
 519     if (current->contains(handle)) {
 520       return true;
 521     }
 522   }
 523   return false;
 524 }
 525 
 526 
 527 int JNIHandleBlock::length() const {
 528   int result = 1;
 529   for (JNIHandleBlock* current = _next; current != NULL; current = current->_next) {
 530     result++;
 531   }
 532   return result;
 533 }
 534 
 535 const size_t JNIHandleBlock::get_number_of_live_handles() {
 536   CountHandleClosure counter;
 537   oops_do(&counter);
 538   return counter.count();
 539 }
 540 
 541 // This method is not thread-safe, i.e., must be called while holding a lock on the
 542 // structure.
 543 long JNIHandleBlock::memory_usage() const {
 544   return length() * sizeof(JNIHandleBlock);
 545 }
 546 
 547 
 548 #ifndef PRODUCT
 549 
 550 bool JNIHandleBlock::any_contains(jobject handle) {
 551   for (JNIHandleBlock* current = _block_list; current != NULL; current = current->_block_list_link) {
 552     if (current->contains(handle)) {
 553       return true;
 554     }
 555   }
 556   return false;
 557 }
 558