< prev index next >

src/share/vm/memory/metachunk.cpp

Print this page
rev 11935 : 8166804: Convert TestMetachunk_test to GTest
Reviewed-by: duke
   1 /*
   2  * Copyright (c) 2012, 2014, 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  *


  94 void Metachunk::mangle(juint word_value) {
  95   // Overwrite the payload of the chunk and not the links that
  96   // maintain list of chunks.
  97   HeapWord* start = (HeapWord*)initial_top();
  98   size_t size = word_size() - overhead();
  99   Copy::fill_to_words(start, size, word_value);
 100 }
 101 #endif // PRODUCT
 102 
 103 void Metachunk::verify() {
 104 #ifdef ASSERT
 105   // Cannot walk through the blocks unless the blocks have
 106   // headers with sizes.
 107   assert(bottom() <= _top &&
 108          _top <= (MetaWord*)end(),
 109          "Chunk has been smashed");
 110 #endif
 111   return;
 112 }
 113 
 114 /////////////// Unit tests ///////////////
 115 
 116 #ifndef PRODUCT
 117 
 118 class TestMetachunk {
 119  public:
 120   static void test() {
 121     size_t size = 2 * 1024 * 1024;
 122     void* memory = malloc(size);
 123     assert(memory != NULL, "Failed to malloc 2MB");
 124 
 125     Metachunk* metachunk = ::new (memory) Metachunk(size / BytesPerWord, NULL);
 126 
 127     assert(metachunk->bottom() == (MetaWord*)metachunk, "assert");
 128     assert(metachunk->end() == (uintptr_t*)metachunk + metachunk->size(), "assert");
 129 
 130     // Check sizes
 131     assert(metachunk->size() == metachunk->word_size(), "assert");
 132     assert(metachunk->word_size() == pointer_delta(metachunk->end(), metachunk->bottom(),
 133         sizeof(MetaWord*)), "assert");
 134 
 135     // Check usage
 136     assert(metachunk->used_word_size() == metachunk->overhead(), "assert");
 137     assert(metachunk->free_word_size() == metachunk->word_size() - metachunk->used_word_size(), "assert");
 138     assert(metachunk->top() == metachunk->initial_top(), "assert");
 139     assert(metachunk->is_empty(), "assert");
 140 
 141     // Allocate
 142     size_t alloc_size = 64; // Words
 143     assert(is_size_aligned(alloc_size, Metachunk::object_alignment()), "assert");
 144 
 145     MetaWord* mem = metachunk->allocate(alloc_size);
 146 
 147     // Check post alloc
 148     assert(mem == metachunk->initial_top(), "assert");
 149     assert(mem + alloc_size == metachunk->top(), "assert");
 150     assert(metachunk->used_word_size() == metachunk->overhead() + alloc_size, "assert");
 151     assert(metachunk->free_word_size() == metachunk->word_size() - metachunk->used_word_size(), "assert");
 152     assert(!metachunk->is_empty(), "assert");
 153 
 154     // Clear chunk
 155     metachunk->reset_empty();
 156 
 157     // Check post clear
 158     assert(metachunk->used_word_size() == metachunk->overhead(), "assert");
 159     assert(metachunk->free_word_size() == metachunk->word_size() - metachunk->used_word_size(), "assert");
 160     assert(metachunk->top() == metachunk->initial_top(), "assert");
 161     assert(metachunk->is_empty(), "assert");
 162 
 163     free(memory);
 164   }
 165 };
 166 
 167 void TestMetachunk_test() {
 168   TestMetachunk::test();
 169 }
 170 
 171 #endif
   1 /*
   2  * Copyright (c) 2012, 2016, 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  *


  94 void Metachunk::mangle(juint word_value) {
  95   // Overwrite the payload of the chunk and not the links that
  96   // maintain list of chunks.
  97   HeapWord* start = (HeapWord*)initial_top();
  98   size_t size = word_size() - overhead();
  99   Copy::fill_to_words(start, size, word_value);
 100 }
 101 #endif // PRODUCT
 102 
 103 void Metachunk::verify() {
 104 #ifdef ASSERT
 105   // Cannot walk through the blocks unless the blocks have
 106   // headers with sizes.
 107   assert(bottom() <= _top &&
 108          _top <= (MetaWord*)end(),
 109          "Chunk has been smashed");
 110 #endif
 111   return;
 112 }
 113 


























































< prev index next >