Tue, 30 Apr 2013 11:56:52 -0700
8011661: Insufficient memory message says "malloc" when sometimes it should say "mmap"
Reviewed-by: coleenp, zgu, hseigel
jmasa@4196 | 1 | /* |
jmasa@4196 | 2 | * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
jmasa@4196 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
jmasa@4196 | 4 | * |
jmasa@4196 | 5 | * This code is free software; you can redistribute it and/or modify it |
jmasa@4196 | 6 | * under the terms of the GNU General Public License version 2 only, as |
jmasa@4196 | 7 | * published by the Free Software Foundation. |
jmasa@4196 | 8 | * |
jmasa@4196 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
jmasa@4196 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
jmasa@4196 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
jmasa@4196 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
jmasa@4196 | 13 | * accompanied this code). |
jmasa@4196 | 14 | * |
jmasa@4196 | 15 | * You should have received a copy of the GNU General Public License version |
jmasa@4196 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
jmasa@4196 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
jmasa@4196 | 18 | * |
jmasa@4196 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
jmasa@4196 | 20 | * or visit www.oracle.com if you need additional information or have any |
jmasa@4196 | 21 | * questions. |
jmasa@4196 | 22 | * |
jmasa@4196 | 23 | */ |
jmasa@4196 | 24 | #ifndef SHARE_VM_MEMORY_METACHUNK_HPP |
jmasa@4196 | 25 | #define SHARE_VM_MEMORY_METACHUNK_HPP |
jmasa@4196 | 26 | |
jmasa@4196 | 27 | // Metachunk - Quantum of allocation from a Virtualspace |
jmasa@4196 | 28 | // Metachunks are reused (when freed are put on a global freelist) and |
jmasa@4196 | 29 | // have no permanent association to a SpaceManager. |
jmasa@4196 | 30 | |
jmasa@4196 | 31 | // +--------------+ <- end |
jmasa@4196 | 32 | // | | --+ ---+ |
jmasa@4196 | 33 | // | | | free | |
jmasa@4196 | 34 | // | | | | |
jmasa@4196 | 35 | // | | | | capacity |
jmasa@4196 | 36 | // | | | | |
jmasa@4196 | 37 | // | | <- top --+ | |
jmasa@4196 | 38 | // | | ---+ | |
jmasa@4196 | 39 | // | | | used | |
jmasa@4196 | 40 | // | | | | |
jmasa@4196 | 41 | // | | | | |
jmasa@4196 | 42 | // +--------------+ <- bottom ---+ ---+ |
jmasa@4196 | 43 | |
jmasa@4196 | 44 | class Metachunk VALUE_OBJ_CLASS_SPEC { |
jmasa@4196 | 45 | // link to support lists of chunks |
jmasa@4196 | 46 | Metachunk* _next; |
jmasa@4196 | 47 | Metachunk* _prev; |
jmasa@4196 | 48 | |
jmasa@4196 | 49 | MetaWord* _bottom; |
jmasa@4196 | 50 | MetaWord* _end; |
jmasa@4196 | 51 | MetaWord* _top; |
jmasa@4196 | 52 | size_t _word_size; |
jmasa@4196 | 53 | // Used in a guarantee() so included in the Product builds |
jmasa@4196 | 54 | // even through it is only for debugging. |
jmasa@4196 | 55 | bool _is_free; |
jmasa@4196 | 56 | |
jmasa@4196 | 57 | // Metachunks are allocated out of a MetadataVirtualSpace and |
jmasa@4196 | 58 | // and use some of its space to describe itself (plus alignment |
jmasa@4196 | 59 | // considerations). Metadata is allocated in the rest of the chunk. |
jmasa@4196 | 60 | // This size is the overhead of maintaining the Metachunk within |
jmasa@4196 | 61 | // the space. |
jmasa@4196 | 62 | static size_t _overhead; |
jmasa@4196 | 63 | |
jmasa@4196 | 64 | void set_bottom(MetaWord* v) { _bottom = v; } |
jmasa@4196 | 65 | void set_end(MetaWord* v) { _end = v; } |
jmasa@4196 | 66 | void set_top(MetaWord* v) { _top = v; } |
jmasa@4196 | 67 | void set_word_size(size_t v) { _word_size = v; } |
jmasa@4196 | 68 | public: |
jmasa@4196 | 69 | #ifdef ASSERT |
jmasa@4382 | 70 | Metachunk() : _bottom(NULL), _end(NULL), _top(NULL), _is_free(false), |
jmasa@4382 | 71 | _next(NULL), _prev(NULL) {} |
jmasa@4196 | 72 | #else |
jmasa@4382 | 73 | Metachunk() : _bottom(NULL), _end(NULL), _top(NULL), |
jmasa@4382 | 74 | _next(NULL), _prev(NULL) {} |
jmasa@4196 | 75 | #endif |
jmasa@4196 | 76 | |
jmasa@4196 | 77 | // Used to add a Metachunk to a list of Metachunks |
jmasa@4196 | 78 | void set_next(Metachunk* v) { _next = v; assert(v != this, "Boom");} |
jmasa@4196 | 79 | void set_prev(Metachunk* v) { _prev = v; assert(v != this, "Boom");} |
jmasa@4196 | 80 | |
jmasa@4196 | 81 | MetaWord* allocate(size_t word_size); |
jmasa@4196 | 82 | static Metachunk* initialize(MetaWord* ptr, size_t word_size); |
jmasa@4196 | 83 | |
jmasa@4196 | 84 | // Accessors |
jmasa@4196 | 85 | Metachunk* next() const { return _next; } |
jmasa@4196 | 86 | Metachunk* prev() const { return _prev; } |
jmasa@4196 | 87 | MetaWord* bottom() const { return _bottom; } |
jmasa@4196 | 88 | MetaWord* end() const { return _end; } |
jmasa@4196 | 89 | MetaWord* top() const { return _top; } |
jmasa@4196 | 90 | size_t word_size() const { return _word_size; } |
jmasa@4196 | 91 | size_t size() const volatile { return _word_size; } |
jmasa@4196 | 92 | void set_size(size_t v) { _word_size = v; } |
jmasa@4196 | 93 | bool is_free() { return _is_free; } |
jmasa@4196 | 94 | void set_is_free(bool v) { _is_free = v; } |
jmasa@4196 | 95 | static size_t overhead() { return _overhead; } |
jmasa@4196 | 96 | void clear_next() { set_next(NULL); } |
jmasa@4196 | 97 | void link_prev(Metachunk* ptr) { set_prev(ptr); } |
jmasa@4196 | 98 | uintptr_t* end() { return ((uintptr_t*) this) + size(); } |
jmasa@4196 | 99 | bool cantCoalesce() const { return false; } |
jmasa@4196 | 100 | void link_next(Metachunk* ptr) { set_next(ptr); } |
jmasa@4196 | 101 | void link_after(Metachunk* ptr){ |
jmasa@4196 | 102 | link_next(ptr); |
jmasa@4196 | 103 | if (ptr != NULL) ptr->link_prev(this); |
jmasa@4196 | 104 | } |
jmasa@4196 | 105 | |
jmasa@4196 | 106 | // Reset top to bottom so chunk can be reused. |
jmasa@4382 | 107 | void reset_empty() { _top = (_bottom + _overhead); _next = NULL; _prev = NULL; } |
jmasa@4196 | 108 | bool is_empty() { return _top == (_bottom + _overhead); } |
jmasa@4196 | 109 | |
jmasa@4196 | 110 | // used (has been allocated) |
jmasa@4196 | 111 | // free (available for future allocations) |
jmasa@4196 | 112 | // capacity (total size of chunk) |
jmasa@4382 | 113 | size_t used_word_size() const; |
jmasa@4382 | 114 | size_t free_word_size() const; |
jmasa@4382 | 115 | size_t capacity_word_size()const; |
jmasa@4196 | 116 | |
jmasa@4196 | 117 | // Debug support |
jmasa@4196 | 118 | #ifdef ASSERT |
jmasa@4196 | 119 | void* prev_addr() const { return (void*)&_prev; } |
jmasa@4196 | 120 | void* next_addr() const { return (void*)&_next; } |
jmasa@4196 | 121 | void* size_addr() const { return (void*)&_word_size; } |
jmasa@4196 | 122 | #endif |
jmasa@4196 | 123 | bool verify_chunk_in_free_list(Metachunk* tc) const { return true; } |
jmasa@4196 | 124 | bool verify_par_locked() { return true; } |
jmasa@4196 | 125 | |
jmasa@4196 | 126 | void assert_is_mangled() const {/* Don't check "\*/} |
jmasa@4196 | 127 | |
coleenp@4304 | 128 | NOT_PRODUCT(void mangle();) |
jmasa@4196 | 129 | |
jmasa@4196 | 130 | void print_on(outputStream* st) const; |
jmasa@4196 | 131 | void verify(); |
jmasa@4196 | 132 | }; |
jmasa@4196 | 133 | #endif // SHARE_VM_MEMORY_METACHUNK_HPP |