hotspot/src/share/vm/memory/heap.hpp
author never
Thu, 21 Oct 2010 11:55:10 -0700
changeset 7108 4f87b92f3060
parent 5547 f4b087cbb361
child 7397 5b173b4ca846
permissions -rw-r--r--
6970683: improvements to hs_err output Reviewed-by: kvn, jrose, dholmes, coleenp
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
7108
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 5547
diff changeset
     2
 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
// Blocks
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
class HeapBlock VALUE_OBJ_CLASS_SPEC {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
  struct Header {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
    size_t  _length;                             // the length in segments
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
    bool    _used;                               // Used bit
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  union {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
    Header _header;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
    int64_t _padding[ (sizeof(Header) + sizeof(int64_t)-1) / sizeof(int64_t) ];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
                        // pad to 0 mod 8
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  // Initialization
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  void initialize(size_t length)                 { _header._length = length; set_used(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  // Accessors
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  void* allocated_space() const                  { return (void*)(this + 1); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  size_t length() const                          { return _header._length; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  // Used/free
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  void set_used()                                { _header._used = true; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  void set_free()                                { _header._used = false; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  bool free()                                    { return !_header._used; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
class FreeBlock: public HeapBlock {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  FreeBlock* _link;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  // Initialization
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  void initialize(size_t length)             { HeapBlock::initialize(length); _link= NULL; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  // Merging
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  void set_length(size_t l)                  { _header._length = l; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  // Accessors
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  FreeBlock* link() const                    { return _link; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  void set_link(FreeBlock* link)             { _link = link; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
class CodeHeap : public CHeapObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  VirtualSpace _memory;                          // the memory holding the blocks
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  VirtualSpace _segmap;                          // the memory holding the segment map
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  size_t       _number_of_committed_segments;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  size_t       _number_of_reserved_segments;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  size_t       _segment_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  int          _log2_segment_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  size_t       _next_segment;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  FreeBlock*   _freelist;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  size_t       _free_segments;                   // No. of segments in freelist
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  // Helper functions
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  size_t   number_of_segments(size_t size) const { return (size + _segment_size - 1) >> _log2_segment_size; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  size_t   size(size_t number_of_segments) const { return number_of_segments << _log2_segment_size; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  size_t   segment_for(void* p) const            { return ((char*)p - _memory.low()) >> _log2_segment_size; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  HeapBlock* block_at(size_t i) const            { return (HeapBlock*)(_memory.low() + (i << _log2_segment_size)); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  void  mark_segmap_as_free(size_t beg, size_t end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  void  mark_segmap_as_used(size_t beg, size_t end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  // Freelist management helpers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  FreeBlock* following_block(FreeBlock *b);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  void insert_after(FreeBlock* a, FreeBlock* b);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  void merge_right (FreeBlock* a);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  // Toplevel freelist management
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  void add_to_freelist(HeapBlock *b);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  FreeBlock* search_freelist(size_t length);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  // Iteration helpers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  void*      next_free(HeapBlock* b) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  HeapBlock* first_block() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  HeapBlock* next_block(HeapBlock* b) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  HeapBlock* block_start(void* p) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  // to perform additional actions on creation of executable code
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  void on_code_mapping(char* base, size_t size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  CodeHeap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  // Heap extents
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  bool  reserve(size_t reserved_size, size_t committed_size, size_t segment_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  void  release();                               // releases all allocated memory
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  bool  expand_by(size_t size);                  // expands commited memory by size
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  void  shrink_by(size_t size);                  // shrinks commited memory by size
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  void  clear();                                 // clears all heap contents
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  // Memory allocation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  void* allocate  (size_t size);                 // allocates a block of size or returns NULL
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  void  deallocate(void* p);                     // deallocates a block
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  // Attributes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  void*  begin() const                           { return _memory.low (); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  void*  end() const                             { return _memory.high(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  bool   contains(void* p) const                 { return begin() <= p && p < end(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  void*  find_start(void* p) const;              // returns the block containing p or NULL
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  size_t alignment_unit() const;                 // alignment of any block
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  size_t alignment_offset() const;               // offset of first byte of any block, within the enclosing alignment unit
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  static size_t header_size();                   // returns the header size for each heap block
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  // Returns reserved area high and low addresses
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  char *low_boundary() const                     { return _memory.low_boundary (); }
7108
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 5547
diff changeset
   143
  char *high() const                             { return _memory.high(); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  char *high_boundary() const                    { return _memory.high_boundary(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  // Iteration
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  // returns the first block or NULL
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  void* first() const       { return next_free(first_block()); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  // returns the next block given a block p or NULL
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  void* next(void* p) const { return next_free(next_block(block_start(p))); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  // Statistics
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  size_t capacity() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  size_t max_capacity() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  size_t allocated_capacity() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  size_t unallocated_capacity() const            { return max_capacity() - allocated_capacity(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  // Debugging
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  void verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  void print()  PRODUCT_RETURN;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
};