< prev index next >

src/hotspot/share/adlc/arena.cpp

Print this page




   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 #include "adlc.hpp"
  26 








  27 void* Chunk::operator new(size_t requested_size, size_t length) throw() {
  28   return CHeapObj::operator new(requested_size + length);
  29 }
  30 
  31 void  Chunk::operator delete(void* p, size_t length) {
  32   CHeapObj::operator delete(p);
  33 }
  34 
  35 Chunk::Chunk(size_t length) {
  36   _next = NULL;         // Chain on the linked list
  37   _len  = length;       // Save actual size
  38 }
  39 
  40 //------------------------------chop-------------------------------------------
  41 void Chunk::chop() {
  42   Chunk *k = this;
  43   while( k ) {
  44     Chunk *tmp = k->_next;
  45     // clear out this chunk (to detect allocation bugs)
  46     memset(k, 0xBE, k->_len);


 147   _first = _chunk = NULL;       // Normal, new-arena initialization
 148   _hwm = _max = NULL;
 149   return a;                     // Return Arena with guts
 150 }
 151 
 152 //------------------------------contains---------------------------------------
 153 // Determine if pointer belongs to this Arena or not.
 154 bool Arena::contains( const void *ptr ) const {
 155   if( (void*)_chunk->bottom() <= ptr && ptr < (void*)_hwm )
 156     return true;                // Check for in this chunk
 157   for( Chunk *c = _first; c; c = c->_next )
 158     if( (void*)c->bottom() <= ptr && ptr < (void*)c->top())
 159       return true;              // Check for every chunk in Arena
 160   return false;                 // Not in any Chunk, so not in Arena
 161 }
 162 
 163 //-----------------------------------------------------------------------------
 164 // CHeapObj
 165 
 166 void* CHeapObj::operator new(size_t size) throw() {
 167   return (void *) malloc(size);
 168 }
 169 
 170 void CHeapObj::operator delete(void* p){
 171  free(p);
 172 }


   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 #include "adlc.hpp"
  26 
  27 void* AllocateHeap(size_t size, AllocFailType alloc_fail_mode) {
  28   unsigned char* ptr = (unsigned char*) malloc(size);
  29   if (ptr == NULL && size != 0 && alloc_fail_mode == AllocFailStrategy::EXIT_OOM) {
  30     exit(1);
  31   }
  32   return ptr;
  33 }
  34 
  35 void* Chunk::operator new(size_t requested_size, size_t length) throw() {
  36   return CHeapObj::operator new(requested_size + length);
  37 }
  38 
  39 void  Chunk::operator delete(void* p, size_t length) {
  40   CHeapObj::operator delete(p);
  41 }
  42 
  43 Chunk::Chunk(size_t length) {
  44   _next = NULL;         // Chain on the linked list
  45   _len  = length;       // Save actual size
  46 }
  47 
  48 //------------------------------chop-------------------------------------------
  49 void Chunk::chop() {
  50   Chunk *k = this;
  51   while( k ) {
  52     Chunk *tmp = k->_next;
  53     // clear out this chunk (to detect allocation bugs)
  54     memset(k, 0xBE, k->_len);


 155   _first = _chunk = NULL;       // Normal, new-arena initialization
 156   _hwm = _max = NULL;
 157   return a;                     // Return Arena with guts
 158 }
 159 
 160 //------------------------------contains---------------------------------------
 161 // Determine if pointer belongs to this Arena or not.
 162 bool Arena::contains( const void *ptr ) const {
 163   if( (void*)_chunk->bottom() <= ptr && ptr < (void*)_hwm )
 164     return true;                // Check for in this chunk
 165   for( Chunk *c = _first; c; c = c->_next )
 166     if( (void*)c->bottom() <= ptr && ptr < (void*)c->top())
 167       return true;              // Check for every chunk in Arena
 168   return false;                 // Not in any Chunk, so not in Arena
 169 }
 170 
 171 //-----------------------------------------------------------------------------
 172 // CHeapObj
 173 
 174 void* CHeapObj::operator new(size_t size) throw() {
 175   return (void *) AllocateHeap(size);
 176 }
 177 
 178 void CHeapObj::operator delete(void* p){
 179  free(p);
 180 }
< prev index next >