src/share/vm/memory/metachunk.cpp

Fri, 19 Apr 2013 11:08:52 -0700

author
minqi
date
Fri, 19 Apr 2013 11:08:52 -0700
changeset 4962
6f817ce50129
parent 4382
e51c9860cf66
child 5007
c23dbf0e8ab7
permissions
-rw-r--r--

8010992: Remove calls to global ::operator new[] and new
Summary: disable use of global operator new and new[] which could cause unexpected exception and escape from NMT tracking.
Reviewed-by: coleenp, dholmes, zgu
Contributed-by: yumin.qi@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@4327 31 //
jmasa@4327 32 // Future modification
jmasa@4327 33 //
jmasa@4327 34 // The Metachunk can conceivable be replaced by the Chunk in
jmasa@4327 35 // allocation.hpp. Note that the latter Chunk is the space for
jmasa@4327 36 // allocation (allocations from the chunk are out of the space in
jmasa@4327 37 // the Chunk after the header for the Chunk) where as Metachunks
jmasa@4327 38 // point to space in a VirtualSpace. To replace Metachunks with
jmasa@4327 39 // Chunks, change Chunks so that they can be allocated out of a VirtualSpace.
jmasa@4327 40
jmasa@4327 41 const size_t metadata_chunk_initialize = 0xf7f7f7f7;
jmasa@4327 42
jmasa@4327 43 size_t Metachunk::_overhead =
jmasa@4327 44 Chunk::aligned_overhead_size(sizeof(Metachunk)) / BytesPerWord;
jmasa@4327 45
jmasa@4327 46 // Metachunk methods
jmasa@4327 47
jmasa@4327 48 Metachunk* Metachunk::initialize(MetaWord* ptr, size_t word_size) {
jmasa@4327 49 // Set bottom, top, and end. Allow space for the Metachunk itself
jmasa@4327 50 Metachunk* chunk = (Metachunk*) ptr;
jmasa@4327 51
jmasa@4327 52 MetaWord* chunk_bottom = ptr + _overhead;
jmasa@4327 53 chunk->set_bottom(ptr);
jmasa@4327 54 chunk->set_top(chunk_bottom);
jmasa@4327 55 MetaWord* chunk_end = ptr + word_size;
jmasa@4327 56 assert(chunk_end > chunk_bottom, "Chunk must be too small");
jmasa@4327 57 chunk->set_end(chunk_end);
jmasa@4327 58 chunk->set_next(NULL);
jmasa@4382 59 chunk->set_prev(NULL);
jmasa@4327 60 chunk->set_word_size(word_size);
jmasa@4327 61 #ifdef ASSERT
jmasa@4327 62 size_t data_word_size = pointer_delta(chunk_end, chunk_bottom, sizeof(MetaWord));
jmasa@4327 63 Copy::fill_to_words((HeapWord*) chunk_bottom, data_word_size, metadata_chunk_initialize);
jmasa@4327 64 #endif
jmasa@4327 65 return chunk;
jmasa@4327 66 }
jmasa@4327 67
jmasa@4327 68
jmasa@4327 69 MetaWord* Metachunk::allocate(size_t word_size) {
jmasa@4327 70 MetaWord* result = NULL;
jmasa@4327 71 // If available, bump the pointer to allocate.
jmasa@4327 72 if (free_word_size() >= word_size) {
jmasa@4327 73 result = _top;
jmasa@4327 74 _top = _top + word_size;
jmasa@4327 75 }
jmasa@4327 76 return result;
jmasa@4327 77 }
jmasa@4327 78
jmasa@4327 79 // _bottom points to the start of the chunk including the overhead.
jmasa@4382 80 size_t Metachunk::used_word_size() const {
jmasa@4327 81 return pointer_delta(_top, _bottom, sizeof(MetaWord));
jmasa@4327 82 }
jmasa@4327 83
jmasa@4382 84 size_t Metachunk::free_word_size() const {
jmasa@4327 85 return pointer_delta(_end, _top, sizeof(MetaWord));
jmasa@4327 86 }
jmasa@4327 87
jmasa@4382 88 size_t Metachunk::capacity_word_size() const {
jmasa@4327 89 return pointer_delta(_end, _bottom, sizeof(MetaWord));
jmasa@4327 90 }
jmasa@4327 91
jmasa@4327 92 void Metachunk::print_on(outputStream* st) const {
jmasa@4327 93 st->print_cr("Metachunk:"
jmasa@4327 94 " bottom " PTR_FORMAT " top " PTR_FORMAT
jmasa@4327 95 " end " PTR_FORMAT " size " SIZE_FORMAT,
jmasa@4327 96 bottom(), top(), end(), word_size());
jmasa@4382 97 if (Verbose) {
jmasa@4382 98 st->print_cr(" used " SIZE_FORMAT " free " SIZE_FORMAT,
jmasa@4382 99 used_word_size(), free_word_size());
jmasa@4382 100 }
jmasa@4327 101 }
jmasa@4327 102
jmasa@4327 103 #ifndef PRODUCT
jmasa@4327 104 void Metachunk::mangle() {
jmasa@4327 105 // Mangle the payload of the chunk and not the links that
jmasa@4327 106 // maintain list of chunks.
jmasa@4327 107 HeapWord* start = (HeapWord*)(bottom() + overhead());
jmasa@4327 108 size_t word_size = capacity_word_size() - overhead();
jmasa@4327 109 Copy::fill_to_words(start, word_size, metadata_chunk_initialize);
jmasa@4327 110 }
jmasa@4327 111 #endif // PRODUCT
jmasa@4327 112
jmasa@4327 113 void Metachunk::verify() {
jmasa@4327 114 #ifdef ASSERT
jmasa@4327 115 // Cannot walk through the blocks unless the blocks have
jmasa@4327 116 // headers with sizes.
jmasa@4327 117 assert(_bottom <= _top &&
jmasa@4327 118 _top <= _end,
jmasa@4327 119 "Chunk has been smashed");
jmasa@4327 120 #endif
jmasa@4327 121 return;
jmasa@4327 122 }

mercurial