< prev index next >

hotspot/src/share/vm/memory/guardedMemory.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) 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  *


 218   /**
 219    * Set the general purpose tag.
 220    *
 221    * @param tag general purpose tag.
 222    */
 223   void set_tag(const void* tag) { get_head_guard()->set_tag(tag); }
 224 
 225   /**
 226    * Return the general purpose tag.
 227    *
 228    * @return the general purpose tag, defaults to NULL.
 229    */
 230   void* get_tag() const { return get_head_guard()->get_tag(); }
 231 
 232   /**
 233    * Return the size of the user data.
 234    *
 235    * @return the size of the user data.
 236    */
 237   size_t get_user_size() const {
 238     assert(_base_addr, "Not wrapping any memory");
 239     return get_head_guard()->get_user_size();
 240   }
 241 
 242   /**
 243    * Return the user data pointer.
 244    *
 245    * @return the user data pointer.
 246    */
 247   u_char* get_user_ptr() const {
 248     assert(_base_addr, "Not wrapping any memory");
 249     return _base_addr + sizeof(GuardHeader);
 250   }
 251 
 252   /**
 253    * Release the wrapped pointer for resource freeing.
 254    *
 255    * Pads the user data with "freeBlockPad", and dis-associates the helper.
 256    *
 257    * @return the original base pointer used to wrap the data.
 258    */
 259   void* release_for_freeing() {
 260     set_user_bytes(freeBlockPad);
 261     return release();
 262   }
 263 
 264   /**
 265    * Dis-associate the help from the original base address.
 266    *
 267    * @return the original base pointer used to wrap the data.
 268    */
 269   void* release() {
 270     void* p = (void*) _base_addr;
 271     _base_addr = NULL;
 272     return p;
 273   }
 274 
 275   virtual void print_on(outputStream* st) const;
 276 
 277  protected:
 278   GuardHeader*  get_head_guard() const { return (GuardHeader*) _base_addr; }
 279   Guard*        get_tail_guard() const { return (Guard*) (get_user_ptr() + get_user_size()); };
 280   void set_user_bytes(u_char ch) {
 281     memset(get_user_ptr(), ch, get_user_size());
 282   }
 283 
 284 public:
 285   /**
 286    * Return the total size required for wrapping the given user size.
 287    *
 288    * @return the total size required for wrapping the given user size.
 289    */
 290   static size_t get_total_size(size_t user_size) {
 291     size_t total_size = sizeof(GuardHeader) + user_size + sizeof(Guard);
 292     assert(total_size > user_size, "Unexpected wrap-around");
 293     return total_size;
 294   }
 295 
 296   // Helper functions...
 297 
 298   /**
 299    * Wrap a copy of size "len" of "ptr".
 300    *
 301    * @param ptr the memory to be copied
 302    * @param len the length of the copy
 303    * @param tag optional general purpose tag (see GuardedMemory::get_tag())
 304    *


   1 /*
   2  * Copyright (c) 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  *


 218   /**
 219    * Set the general purpose tag.
 220    *
 221    * @param tag general purpose tag.
 222    */
 223   void set_tag(const void* tag) { get_head_guard()->set_tag(tag); }
 224 
 225   /**
 226    * Return the general purpose tag.
 227    *
 228    * @return the general purpose tag, defaults to NULL.
 229    */
 230   void* get_tag() const { return get_head_guard()->get_tag(); }
 231 
 232   /**
 233    * Return the size of the user data.
 234    *
 235    * @return the size of the user data.
 236    */
 237   size_t get_user_size() const {
 238     assert(_base_addr != NULL, "Not wrapping any memory");
 239     return get_head_guard()->get_user_size();
 240   }
 241 
 242   /**
 243    * Return the user data pointer.
 244    *
 245    * @return the user data pointer.
 246    */
 247   u_char* get_user_ptr() const {
 248     assert(_base_addr != NULL, "Not wrapping any memory");
 249     return _base_addr + sizeof(GuardHeader);
 250   }
 251 
 252   /**
 253    * Release the wrapped pointer for resource freeing.
 254    *
 255    * Pads the user data with "freeBlockPad", and dis-associates the helper.
 256    *
 257    * @return the original base pointer used to wrap the data.
 258    */
 259   void* release_for_freeing() {
 260     set_user_bytes(freeBlockPad);
 261     return release();
 262   }
 263 
 264   /**
 265    * Dis-associate the help from the original base address.
 266    *
 267    * @return the original base pointer used to wrap the data.
 268    */
 269   void* release() {
 270     void* p = (void*) _base_addr;
 271     _base_addr = NULL;
 272     return p;
 273   }
 274 
 275   virtual void print_on(outputStream* st) const;
 276 
 277  protected:
 278   GuardHeader*  get_head_guard() const { return (GuardHeader*) _base_addr; }
 279   Guard*        get_tail_guard() const { return (Guard*) (get_user_ptr() + get_user_size()); };
 280   void set_user_bytes(u_char ch) {
 281     memset(get_user_ptr(), ch, get_user_size());
 282   }
 283 
 284  public:
 285   /**
 286    * Return the total size required for wrapping the given user size.
 287    *
 288    * @return the total size required for wrapping the given user size.
 289    */
 290   static size_t get_total_size(size_t user_size) {
 291     size_t total_size = sizeof(GuardHeader) + user_size + sizeof(Guard);
 292     assert(total_size > user_size, "Unexpected wrap-around");
 293     return total_size;
 294   }
 295 
 296   // Helper functions...
 297 
 298   /**
 299    * Wrap a copy of size "len" of "ptr".
 300    *
 301    * @param ptr the memory to be copied
 302    * @param len the length of the copy
 303    * @param tag optional general purpose tag (see GuardedMemory::get_tag())
 304    *


< prev index next >