src/share/vm/memory/heap.hpp

Tue, 24 Feb 2015 15:04:52 -0500

author
dlong
date
Tue, 24 Feb 2015 15:04:52 -0500
changeset 7598
ddce0b7cee93
parent 6198
55fb97c4c58d
child 6876
710a3c8b516e
permissions
-rw-r--r--

8072383: resolve conflicts between open and closed ports
Summary: refactor close to remove references to closed ports
Reviewed-by: kvn, simonis, sgehwolf, dholmes

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

mercurial