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

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

mercurial