< prev index next >

hotspot/src/share/vm/runtime/jniHandles.cpp

Print this page
rev 7151 : 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: dsimms
   1 /*
   2  * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   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
   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  *


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

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


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






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


   1 /*
   2  * Copyright (c) 1998, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   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
   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  *


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


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


< prev index next >