Thu, 13 Jun 2013 22:02:40 -0700
8014431: cleanup warnings indicated by the -Wunused-value compiler option on linux
Reviewed-by: dholmes, coleenp
Contributed-by: jeremymanson@google.com, calvin.cheung@oracle.com
jmasa@4327 | 1 | /* |
jmasa@4327 | 2 | * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
jmasa@4327 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
jmasa@4327 | 4 | * |
jmasa@4327 | 5 | * This code is free software; you can redistribute it and/or modify it |
jmasa@4327 | 6 | * under the terms of the GNU General Public License version 2 only, as |
jmasa@4327 | 7 | * published by the Free Software Foundation. |
jmasa@4327 | 8 | * |
jmasa@4327 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
jmasa@4327 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
jmasa@4327 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
jmasa@4327 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
jmasa@4327 | 13 | * accompanied this code). |
jmasa@4327 | 14 | * |
jmasa@4327 | 15 | * You should have received a copy of the GNU General Public License version |
jmasa@4327 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
jmasa@4327 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
jmasa@4327 | 18 | * |
jmasa@4327 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
jmasa@4327 | 20 | * or visit www.oracle.com if you need additional information or have any |
jmasa@4327 | 21 | * questions. |
jmasa@4327 | 22 | * |
jmasa@4327 | 23 | */ |
jmasa@4327 | 24 | |
jmasa@4327 | 25 | #include "precompiled.hpp" |
jmasa@4327 | 26 | #include "memory/allocation.hpp" |
jmasa@4327 | 27 | #include "memory/metachunk.hpp" |
jmasa@4327 | 28 | #include "utilities/copy.hpp" |
jmasa@4327 | 29 | #include "utilities/debug.hpp" |
jmasa@4327 | 30 | |
jmasa@5007 | 31 | class VirtualSpaceNode; |
jmasa@4327 | 32 | // |
jmasa@4327 | 33 | // Future modification |
jmasa@4327 | 34 | // |
jmasa@4327 | 35 | // The Metachunk can conceivable be replaced by the Chunk in |
jmasa@4327 | 36 | // allocation.hpp. Note that the latter Chunk is the space for |
jmasa@4327 | 37 | // allocation (allocations from the chunk are out of the space in |
jmasa@4327 | 38 | // the Chunk after the header for the Chunk) where as Metachunks |
jmasa@4327 | 39 | // point to space in a VirtualSpace. To replace Metachunks with |
jmasa@4327 | 40 | // Chunks, change Chunks so that they can be allocated out of a VirtualSpace. |
jmasa@4327 | 41 | |
jmasa@4327 | 42 | const size_t metadata_chunk_initialize = 0xf7f7f7f7; |
jmasa@4327 | 43 | |
jmasa@4327 | 44 | size_t Metachunk::_overhead = |
jmasa@4327 | 45 | Chunk::aligned_overhead_size(sizeof(Metachunk)) / BytesPerWord; |
jmasa@4327 | 46 | |
jmasa@4327 | 47 | // Metachunk methods |
jmasa@4327 | 48 | |
jmasa@5007 | 49 | Metachunk::Metachunk(size_t word_size, |
jmasa@5007 | 50 | VirtualSpaceNode* container) : |
jmasa@5007 | 51 | _word_size(word_size), |
jmasa@5007 | 52 | _bottom(NULL), |
jmasa@5007 | 53 | _end(NULL), |
jmasa@5007 | 54 | _top(NULL), |
jmasa@5007 | 55 | _next(NULL), |
jmasa@5007 | 56 | _prev(NULL), |
jmasa@5007 | 57 | _container(container) |
jmasa@5007 | 58 | { |
jmasa@5007 | 59 | _bottom = (MetaWord*)this; |
jmasa@5007 | 60 | _top = (MetaWord*)this + _overhead; |
jmasa@5007 | 61 | _end = (MetaWord*)this + word_size; |
jmasa@4327 | 62 | #ifdef ASSERT |
jmasa@5007 | 63 | set_is_free(false); |
jmasa@5007 | 64 | size_t data_word_size = pointer_delta(end(), |
jmasa@5007 | 65 | top(), |
jmasa@5007 | 66 | sizeof(MetaWord)); |
jmasa@5007 | 67 | Copy::fill_to_words((HeapWord*) top(), |
jmasa@5007 | 68 | data_word_size, |
jmasa@5007 | 69 | metadata_chunk_initialize); |
jmasa@4327 | 70 | #endif |
jmasa@4327 | 71 | } |
jmasa@4327 | 72 | |
jmasa@4327 | 73 | MetaWord* Metachunk::allocate(size_t word_size) { |
jmasa@4327 | 74 | MetaWord* result = NULL; |
jmasa@4327 | 75 | // If available, bump the pointer to allocate. |
jmasa@4327 | 76 | if (free_word_size() >= word_size) { |
jmasa@4327 | 77 | result = _top; |
jmasa@4327 | 78 | _top = _top + word_size; |
jmasa@4327 | 79 | } |
jmasa@4327 | 80 | return result; |
jmasa@4327 | 81 | } |
jmasa@4327 | 82 | |
jmasa@4327 | 83 | // _bottom points to the start of the chunk including the overhead. |
jmasa@4382 | 84 | size_t Metachunk::used_word_size() const { |
jmasa@4327 | 85 | return pointer_delta(_top, _bottom, sizeof(MetaWord)); |
jmasa@4327 | 86 | } |
jmasa@4327 | 87 | |
jmasa@4382 | 88 | size_t Metachunk::free_word_size() const { |
jmasa@4327 | 89 | return pointer_delta(_end, _top, sizeof(MetaWord)); |
jmasa@4327 | 90 | } |
jmasa@4327 | 91 | |
jmasa@4382 | 92 | size_t Metachunk::capacity_word_size() const { |
jmasa@4327 | 93 | return pointer_delta(_end, _bottom, sizeof(MetaWord)); |
jmasa@4327 | 94 | } |
jmasa@4327 | 95 | |
jmasa@4327 | 96 | void Metachunk::print_on(outputStream* st) const { |
jmasa@4327 | 97 | st->print_cr("Metachunk:" |
jmasa@4327 | 98 | " bottom " PTR_FORMAT " top " PTR_FORMAT |
jmasa@4327 | 99 | " end " PTR_FORMAT " size " SIZE_FORMAT, |
jmasa@4327 | 100 | bottom(), top(), end(), word_size()); |
jmasa@4382 | 101 | if (Verbose) { |
jmasa@4382 | 102 | st->print_cr(" used " SIZE_FORMAT " free " SIZE_FORMAT, |
jmasa@4382 | 103 | used_word_size(), free_word_size()); |
jmasa@4382 | 104 | } |
jmasa@4327 | 105 | } |
jmasa@4327 | 106 | |
jmasa@4327 | 107 | #ifndef PRODUCT |
jmasa@4327 | 108 | void Metachunk::mangle() { |
jmasa@4327 | 109 | // Mangle the payload of the chunk and not the links that |
jmasa@4327 | 110 | // maintain list of chunks. |
jmasa@4327 | 111 | HeapWord* start = (HeapWord*)(bottom() + overhead()); |
jmasa@4327 | 112 | size_t word_size = capacity_word_size() - overhead(); |
jmasa@4327 | 113 | Copy::fill_to_words(start, word_size, metadata_chunk_initialize); |
jmasa@4327 | 114 | } |
jmasa@4327 | 115 | #endif // PRODUCT |
jmasa@4327 | 116 | |
jmasa@4327 | 117 | void Metachunk::verify() { |
jmasa@4327 | 118 | #ifdef ASSERT |
jmasa@4327 | 119 | // Cannot walk through the blocks unless the blocks have |
jmasa@4327 | 120 | // headers with sizes. |
jmasa@4327 | 121 | assert(_bottom <= _top && |
jmasa@4327 | 122 | _top <= _end, |
jmasa@4327 | 123 | "Chunk has been smashed"); |
jmasa@4327 | 124 | #endif |
jmasa@4327 | 125 | return; |
jmasa@4327 | 126 | } |