< prev index next >

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

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, 2012, 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  *


  95 class JNIHandleBlock : public CHeapObj<mtInternal> {
  96   friend class VMStructs;
  97   friend class CppInterpreter;
  98 
  99  private:
 100   enum SomeConstants {
 101     block_size_in_oops  = 32                    // Number of handles per handle block
 102   };
 103 
 104   oop             _handles[block_size_in_oops]; // The handles
 105   int             _top;                         // Index of next unused handle
 106   JNIHandleBlock* _next;                        // Link to next block
 107 
 108   // The following instance variables are only used by the first block in a chain.
 109   // Having two types of blocks complicates the code and the space overhead in negligble.
 110   JNIHandleBlock* _last;                        // Last block in use
 111   JNIHandleBlock* _pop_frame_link;              // Block to restore on PopLocalFrame call
 112   oop*            _free_list;                   // Handle free list
 113   int             _allocate_before_rebuild;     // Number of blocks to allocate before rebuilding free list
 114 



 115   #ifndef PRODUCT
 116   JNIHandleBlock* _block_list_link;             // Link for list below
 117   static JNIHandleBlock* _block_list;           // List of all allocated blocks (for debugging only)
 118   #endif
 119 
 120   static JNIHandleBlock* _block_free_list;      // Free list of currently unused blocks
 121   static int      _blocks_allocated;            // For debugging/printing
 122 
 123   // Fill block with bad_handle values
 124   void zap();
 125 
 126  protected:
 127   // No more handles in the both the current and following blocks
 128   void clear() { _top = 0; }
 129 
 130  private:
 131   // Free list computation
 132   void rebuild_free_list();
 133 
 134  public:
 135   // Handle allocation
 136   jobject allocate_handle(oop obj);
 137 
 138   // Block allocation and block free list management
 139   static JNIHandleBlock* allocate_block(Thread* thread = NULL);
 140   static void release_block(JNIHandleBlock* block, Thread* thread = NULL);
 141 
 142   // JNI PushLocalFrame/PopLocalFrame support
 143   JNIHandleBlock* pop_frame_link() const          { return _pop_frame_link; }
 144   void set_pop_frame_link(JNIHandleBlock* block)  { _pop_frame_link = block; }
 145 
 146   // Stub generator support
 147   static int top_offset_in_bytes()                { return offset_of(JNIHandleBlock, _top); }
 148 
 149   // Garbage collection support
 150   // Traversal of regular handles
 151   void oops_do(OopClosure* f);
 152   // Traversal of weak handles. Unreachable oops are cleared.
 153   void weak_oops_do(BoolObjectClosure* is_alive, OopClosure* f);
 154 





 155   // Debugging
 156   bool chain_contains(jobject handle) const;    // Does this block or following blocks contain handle
 157   bool contains(jobject handle) const;          // Does this block contain handle
 158   int length() const;                           // Length of chain starting with this block
 159   long memory_usage() const;
 160   #ifndef PRODUCT
 161   static bool any_contains(jobject handle);     // Does any block currently in use contain handle
 162   static void print_statistics();
 163   #endif
 164 };
 165 
 166 
 167 inline oop JNIHandles::resolve(jobject handle) {
 168   oop result = (handle == NULL ? (oop)NULL : *(oop*)handle);
 169   assert(result != NULL || (handle == NULL || !CheckJNICalls || is_weak_global_handle(handle)), "Invalid value read from jni handle");
 170   assert(result != badJNIHandle, "Pointing to zapped jni handle area");
 171   return result;
 172 };
 173 
 174 


   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  *


  95 class JNIHandleBlock : public CHeapObj<mtInternal> {
  96   friend class VMStructs;
  97   friend class CppInterpreter;
  98 
  99  private:
 100   enum SomeConstants {
 101     block_size_in_oops  = 32                    // Number of handles per handle block
 102   };
 103 
 104   oop             _handles[block_size_in_oops]; // The handles
 105   int             _top;                         // Index of next unused handle
 106   JNIHandleBlock* _next;                        // Link to next block
 107 
 108   // The following instance variables are only used by the first block in a chain.
 109   // Having two types of blocks complicates the code and the space overhead in negligble.
 110   JNIHandleBlock* _last;                        // Last block in use
 111   JNIHandleBlock* _pop_frame_link;              // Block to restore on PopLocalFrame call
 112   oop*            _free_list;                   // Handle free list
 113   int             _allocate_before_rebuild;     // Number of blocks to allocate before rebuilding free list
 114 
 115   // Check JNI, "planned capacity" for current frame (or push/ensure)
 116   size_t          _planned_capacity;
 117 
 118   #ifndef PRODUCT
 119   JNIHandleBlock* _block_list_link;             // Link for list below
 120   static JNIHandleBlock* _block_list;           // List of all allocated blocks (for debugging only)
 121   #endif
 122 
 123   static JNIHandleBlock* _block_free_list;      // Free list of currently unused blocks
 124   static int      _blocks_allocated;            // For debugging/printing
 125 
 126   // Fill block with bad_handle values
 127   void zap();
 128 
 129  protected:
 130   // No more handles in the both the current and following blocks
 131   void clear() { _top = 0; }
 132 
 133  private:
 134   // Free list computation
 135   void rebuild_free_list();
 136 
 137  public:
 138   // Handle allocation
 139   jobject allocate_handle(oop obj);
 140 
 141   // Block allocation and block free list management
 142   static JNIHandleBlock* allocate_block(Thread* thread = NULL);
 143   static void release_block(JNIHandleBlock* block, Thread* thread = NULL);
 144 
 145   // JNI PushLocalFrame/PopLocalFrame support
 146   JNIHandleBlock* pop_frame_link() const          { return _pop_frame_link; }
 147   void set_pop_frame_link(JNIHandleBlock* block)  { _pop_frame_link = block; }
 148 
 149   // Stub generator support
 150   static int top_offset_in_bytes()                { return offset_of(JNIHandleBlock, _top); }
 151 
 152   // Garbage collection support
 153   // Traversal of regular handles
 154   void oops_do(OopClosure* f);
 155   // Traversal of weak handles. Unreachable oops are cleared.
 156   void weak_oops_do(BoolObjectClosure* is_alive, OopClosure* f);
 157 
 158   // Checked JNI support
 159   void set_planned_capacity(size_t planned_capacity) { _planned_capacity = planned_capacity; }
 160   const size_t get_planned_capacity() { return _planned_capacity; }
 161   const size_t get_number_of_live_handles();
 162 
 163   // Debugging
 164   bool chain_contains(jobject handle) const;    // Does this block or following blocks contain handle
 165   bool contains(jobject handle) const;          // Does this block contain handle
 166   int length() const;                           // Length of chain starting with this block
 167   long memory_usage() const;
 168   #ifndef PRODUCT
 169   static bool any_contains(jobject handle);     // Does any block currently in use contain handle
 170   static void print_statistics();
 171   #endif
 172 };
 173 
 174 
 175 inline oop JNIHandles::resolve(jobject handle) {
 176   oop result = (handle == NULL ? (oop)NULL : *(oop*)handle);
 177   assert(result != NULL || (handle == NULL || !CheckJNICalls || is_weak_global_handle(handle)), "Invalid value read from jni handle");
 178   assert(result != badJNIHandle, "Pointing to zapped jni handle area");
 179   return result;
 180 };
 181 
 182 


< prev index next >