src/share/vm/memory/heap.hpp

Print this page


   1 /*
   2  * Copyright (c) 1997, 2006, 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  *
  23  */
  24 






  25 // Blocks
  26 
  27 class HeapBlock VALUE_OBJ_CLASS_SPEC {
  28   friend class VMStructs;
  29 
  30  public:
  31   struct Header {
  32     size_t  _length;                             // the length in segments
  33     bool    _used;                               // Used bit
  34   };
  35 
  36  protected:
  37   union {
  38     Header _header;
  39     int64_t _padding[ (sizeof(Header) + sizeof(int64_t)-1) / sizeof(int64_t) ];
  40                         // pad to 0 mod 8
  41   };
  42 
  43  public:
  44   // Initialization


 142   char *low_boundary() const                     { return _memory.low_boundary (); }
 143   char *high_boundary() const                    { return _memory.high_boundary(); }
 144 
 145   // Iteration
 146 
 147   // returns the first block or NULL
 148   void* first() const       { return next_free(first_block()); }
 149   // returns the next block given a block p or NULL
 150   void* next(void* p) const { return next_free(next_block(block_start(p))); }
 151 
 152   // Statistics
 153   size_t capacity() const;
 154   size_t max_capacity() const;
 155   size_t allocated_capacity() const;
 156   size_t unallocated_capacity() const            { return max_capacity() - allocated_capacity(); }
 157 
 158   // Debugging
 159   void verify();
 160   void print()  PRODUCT_RETURN;
 161 };


   1 /*
   2  * Copyright (c) 1997, 2010, 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  *
  23  */
  24 
  25 #ifndef SHARE_VM_MEMORY_HEAP_HPP
  26 #define SHARE_VM_MEMORY_HEAP_HPP
  27 
  28 #include "memory/allocation.hpp"
  29 #include "runtime/virtualspace.hpp"
  30 
  31 // Blocks
  32 
  33 class HeapBlock VALUE_OBJ_CLASS_SPEC {
  34   friend class VMStructs;
  35 
  36  public:
  37   struct Header {
  38     size_t  _length;                             // the length in segments
  39     bool    _used;                               // Used bit
  40   };
  41 
  42  protected:
  43   union {
  44     Header _header;
  45     int64_t _padding[ (sizeof(Header) + sizeof(int64_t)-1) / sizeof(int64_t) ];
  46                         // pad to 0 mod 8
  47   };
  48 
  49  public:
  50   // Initialization


 148   char *low_boundary() const                     { return _memory.low_boundary (); }
 149   char *high_boundary() const                    { return _memory.high_boundary(); }
 150 
 151   // Iteration
 152 
 153   // returns the first block or NULL
 154   void* first() const       { return next_free(first_block()); }
 155   // returns the next block given a block p or NULL
 156   void* next(void* p) const { return next_free(next_block(block_start(p))); }
 157 
 158   // Statistics
 159   size_t capacity() const;
 160   size_t max_capacity() const;
 161   size_t allocated_capacity() const;
 162   size_t unallocated_capacity() const            { return max_capacity() - allocated_capacity(); }
 163 
 164   // Debugging
 165   void verify();
 166   void print()  PRODUCT_RETURN;
 167 };
 168 
 169 #endif // SHARE_VM_MEMORY_HEAP_HPP