src/hotspot/share/memory/arena.hpp
author gziemski
Wed, 08 May 2019 11:11:50 -0500
changeset 54764 865ec913f916
parent 53244 9807daeb47c4
child 55745 fa337ff85b9a
permissions -rw-r--r--
8185525: Add JFR event for DictionarySizes Summary: Added TableStatistics event Reviewed-by: egahlin, coleenp
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
46818
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
     1
/*
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 51405
diff changeset
     2
 * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
46818
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
     4
 *
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
     7
 * published by the Free Software Foundation.
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
     8
 *
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    13
 * accompanied this code).
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    14
 *
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    18
 *
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    21
 * questions.
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    22
 *
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    23
 */
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    24
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 51405
diff changeset
    25
#ifndef SHARE_MEMORY_ARENA_HPP
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 51405
diff changeset
    26
#define SHARE_MEMORY_ARENA_HPP
46818
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    27
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    28
#include "memory/allocation.hpp"
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    29
#include "runtime/globals.hpp"
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    30
#include "utilities/globalDefinitions.hpp"
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    31
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    32
#include <new>
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    33
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    34
// The byte alignment to be used by Arena::Amalloc.  See bugid 4169348.
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    35
// Note: this value must be a power of 2
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    36
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    37
#define ARENA_AMALLOC_ALIGNMENT (2*BytesPerWord)
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    38
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    39
#define ARENA_ALIGN_M1 (((size_t)(ARENA_AMALLOC_ALIGNMENT)) - 1)
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    40
#define ARENA_ALIGN_MASK (~((size_t)ARENA_ALIGN_M1))
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    41
#define ARENA_ALIGN(x) ((((size_t)(x)) + ARENA_ALIGN_M1) & ARENA_ALIGN_MASK)
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    42
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    43
//------------------------------Chunk------------------------------------------
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    44
// Linked list of raw memory chunks
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    45
class Chunk: CHeapObj<mtChunk> {
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    46
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    47
 private:
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    48
  Chunk*       _next;     // Next Chunk in list
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    49
  const size_t _len;      // Size of this Chunk
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    50
 public:
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    51
  void* operator new(size_t size, AllocFailType alloc_failmode, size_t length) throw();
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    52
  void  operator delete(void* p);
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    53
  Chunk(size_t length);
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    54
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    55
  enum {
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    56
    // default sizes; make them slightly smaller than 2**k to guard against
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    57
    // buddy-system style malloc implementations
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    58
#ifdef _LP64
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    59
    slack      = 40,            // [RGV] Not sure if this is right, but make it
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    60
                                //       a multiple of 8.
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    61
#else
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    62
    slack      = 20,            // suspected sizeof(Chunk) + internal malloc headers
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    63
#endif
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    64
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    65
    tiny_size  =  256  - slack, // Size of first chunk (tiny)
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    66
    init_size  =  1*K  - slack, // Size of first chunk (normal aka small)
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    67
    medium_size= 10*K  - slack, // Size of medium-sized chunk
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    68
    size       = 32*K  - slack, // Default size of an Arena chunk (following the first)
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    69
    non_pool_size = init_size + 32 // An initial size which is not one of above
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    70
  };
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    71
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    72
  void chop();                  // Chop this chunk
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    73
  void next_chop();             // Chop next chunk
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    74
  static size_t aligned_overhead_size(void) { return ARENA_ALIGN(sizeof(Chunk)); }
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    75
  static size_t aligned_overhead_size(size_t byte_size) { return ARENA_ALIGN(byte_size); }
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    76
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    77
  size_t length() const         { return _len;  }
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    78
  Chunk* next() const           { return _next;  }
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    79
  void set_next(Chunk* n)       { _next = n;  }
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    80
  // Boundaries of data area (possibly unused)
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    81
  char* bottom() const          { return ((char*) this) + aligned_overhead_size();  }
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    82
  char* top()    const          { return bottom() + _len; }
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    83
  bool contains(char* p) const  { return bottom() <= p && p <= top(); }
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    84
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    85
  // Start the chunk_pool cleaner task
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    86
  static void start_chunk_pool_cleaner_task();
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    87
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    88
  static void clean_chunk_pool();
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    89
};
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    90
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    91
//------------------------------Arena------------------------------------------
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    92
// Fast allocation of memory
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    93
class Arena : public CHeapObj<mtNone> {
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    94
protected:
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    95
  friend class ResourceMark;
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    96
  friend class HandleMark;
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    97
  friend class NoHandleMark;
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    98
  friend class VMStructs;
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
    99
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   100
  MEMFLAGS    _flags;           // Memory tracking flags
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   101
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   102
  Chunk *_first;                // First chunk
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   103
  Chunk *_chunk;                // current chunk
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   104
  char *_hwm, *_max;            // High water mark and max in current chunk
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   105
  // Get a new Chunk of at least size x
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   106
  void* grow(size_t x, AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM);
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   107
  size_t _size_in_bytes;        // Size of arena (used for native memory tracking)
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   108
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   109
  NOT_PRODUCT(static julong _bytes_allocated;) // total #bytes allocated since start
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   110
  friend class AllocStats;
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   111
  debug_only(void* malloc(size_t size);)
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   112
  debug_only(void* internal_malloc_4(size_t x);)
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   113
  NOT_PRODUCT(void inc_bytes_allocated(size_t x);)
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   114
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   115
  void signal_out_of_memory(size_t request, const char* whence) const;
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   116
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   117
  bool check_for_overflow(size_t request, const char* whence,
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   118
      AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM) const {
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   119
    if (UINTPTR_MAX - request < (uintptr_t)_hwm) {
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   120
      if (alloc_failmode == AllocFailStrategy::RETURN_NULL) {
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   121
        return false;
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   122
      }
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   123
      signal_out_of_memory(request, whence);
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   124
    }
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   125
    return true;
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   126
 }
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   127
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   128
 public:
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   129
  Arena(MEMFLAGS memflag);
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   130
  Arena(MEMFLAGS memflag, size_t init_size);
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   131
  ~Arena();
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   132
  void  destruct_contents();
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   133
  char* hwm() const             { return _hwm; }
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   134
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   135
  // new operators
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   136
  void* operator new (size_t size) throw();
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   137
  void* operator new (size_t size, const std::nothrow_t& nothrow_constant) throw();
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   138
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   139
  // dynamic memory type tagging
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   140
  void* operator new(size_t size, MEMFLAGS flags) throw();
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   141
  void* operator new(size_t size, const std::nothrow_t& nothrow_constant, MEMFLAGS flags) throw();
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   142
  void  operator delete(void* p);
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   143
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   144
  // Fast allocate in the arena.  Common case is: pointer test + increment.
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   145
  void* Amalloc(size_t x, AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM) {
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   146
    assert(is_power_of_2(ARENA_AMALLOC_ALIGNMENT) , "should be a power of 2");
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   147
    x = ARENA_ALIGN(x);
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   148
    debug_only(if (UseMallocOnly) return malloc(x);)
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   149
    if (!check_for_overflow(x, "Arena::Amalloc", alloc_failmode))
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   150
      return NULL;
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   151
    NOT_PRODUCT(inc_bytes_allocated(x);)
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   152
    if (_hwm + x > _max) {
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   153
      return grow(x, alloc_failmode);
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   154
    } else {
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   155
      char *old = _hwm;
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   156
      _hwm += x;
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   157
      return old;
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   158
    }
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   159
  }
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   160
  // Further assume size is padded out to words
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   161
  void *Amalloc_4(size_t x, AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM) {
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   162
    assert( (x&(sizeof(char*)-1)) == 0, "misaligned size" );
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   163
    debug_only(if (UseMallocOnly) return malloc(x);)
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   164
    if (!check_for_overflow(x, "Arena::Amalloc_4", alloc_failmode))
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   165
      return NULL;
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   166
    NOT_PRODUCT(inc_bytes_allocated(x);)
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   167
    if (_hwm + x > _max) {
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   168
      return grow(x, alloc_failmode);
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   169
    } else {
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   170
      char *old = _hwm;
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   171
      _hwm += x;
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   172
      return old;
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   173
    }
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   174
  }
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   175
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   176
  // Allocate with 'double' alignment. It is 8 bytes on sparc.
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   177
  // In other cases Amalloc_D() should be the same as Amalloc_4().
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   178
  void* Amalloc_D(size_t x, AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM) {
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   179
    assert( (x&(sizeof(char*)-1)) == 0, "misaligned size" );
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   180
    debug_only(if (UseMallocOnly) return malloc(x);)
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   181
#if defined(SPARC) && !defined(_LP64)
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   182
#define DALIGN_M1 7
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   183
    size_t delta = (((size_t)_hwm + DALIGN_M1) & ~DALIGN_M1) - (size_t)_hwm;
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   184
    x += delta;
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   185
#endif
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   186
    if (!check_for_overflow(x, "Arena::Amalloc_D", alloc_failmode))
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   187
      return NULL;
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   188
    NOT_PRODUCT(inc_bytes_allocated(x);)
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   189
    if (_hwm + x > _max) {
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   190
      return grow(x, alloc_failmode); // grow() returns a result aligned >= 8 bytes.
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   191
    } else {
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   192
      char *old = _hwm;
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   193
      _hwm += x;
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   194
#if defined(SPARC) && !defined(_LP64)
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   195
      old += delta; // align to 8-bytes
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   196
#endif
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   197
      return old;
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   198
    }
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   199
  }
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   200
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   201
  // Fast delete in area.  Common case is: NOP (except for storage reclaimed)
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 47216
diff changeset
   202
  bool Afree(void *ptr, size_t size) {
46818
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   203
#ifdef ASSERT
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   204
    if (ZapResourceArea) memset(ptr, badResourceValue, size); // zap freed memory
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 47216
diff changeset
   205
    if (UseMallocOnly) return true;
46818
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   206
#endif
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 47216
diff changeset
   207
    if (((char*)ptr) + size == _hwm) {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 47216
diff changeset
   208
      _hwm = (char*)ptr;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 47216
diff changeset
   209
      return true;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 47216
diff changeset
   210
    } else {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 47216
diff changeset
   211
      // Unable to fast free, so we just drop it.
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 47216
diff changeset
   212
      return false;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 47216
diff changeset
   213
    }
46818
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   214
  }
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   215
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   216
  void *Arealloc( void *old_ptr, size_t old_size, size_t new_size,
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   217
      AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM);
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   218
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   219
  // Move contents of this arena into an empty arena
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   220
  Arena *move_contents(Arena *empty_arena);
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   221
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   222
  // Determine if pointer belongs to this Arena or not.
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   223
  bool contains( const void *ptr ) const;
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   224
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   225
  // Total of all chunks in use (not thread-safe)
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   226
  size_t used() const;
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   227
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   228
  // Total # of bytes used
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   229
  size_t size_in_bytes() const         {  return _size_in_bytes; };
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   230
  void set_size_in_bytes(size_t size);
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   231
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   232
  static void free_malloced_objects(Chunk* chunk, char* hwm, char* max, char* hwm2)  PRODUCT_RETURN;
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   233
  static void free_all(char** start, char** end)                                     PRODUCT_RETURN;
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   234
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   235
private:
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   236
  // Reset this Arena to empty, access will trigger grow if necessary
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   237
  void   reset(void) {
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   238
    _first = _chunk = NULL;
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   239
    _hwm = _max = NULL;
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   240
    set_size_in_bytes(0);
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   241
  }
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   242
};
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   243
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   244
// One of the following macros must be used when allocating
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   245
// an array or object from an arena
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   246
#define NEW_ARENA_ARRAY(arena, type, size) \
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   247
  (type*) (arena)->Amalloc((size) * sizeof(type))
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   248
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   249
#define REALLOC_ARENA_ARRAY(arena, type, old, old_size, new_size)    \
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   250
  (type*) (arena)->Arealloc((char*)(old), (old_size) * sizeof(type), \
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   251
                            (new_size) * sizeof(type) )
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   252
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   253
#define FREE_ARENA_ARRAY(arena, type, old, size) \
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   254
  (arena)->Afree((char*)(old), (size) * sizeof(type))
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   255
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   256
#define NEW_ARENA_OBJ(arena, type) \
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   257
  NEW_ARENA_ARRAY(arena, type, 1)
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents:
diff changeset
   258
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 51405
diff changeset
   259
#endif // SHARE_MEMORY_ARENA_HPP