src/share/vm/memory/guardedMemory.hpp

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


 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    *




 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    *