1 /*
   2  * Copyright (c) 2017, Red Hat, Inc. and/or its affiliates.
   3  *
   4  * This code is free software; you can redistribute it and/or modify it
   5  * under the terms of the GNU General Public License version 2 only, as
   6  * published by the Free Software Foundation.
   7  *
   8  * This code is distributed in the hope that it will be useful, but WITHOUT
   9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  11  * version 2 for more details (a copy is included in the LICENSE file that
  12  * accompanied this code).
  13  *
  14  * You should have received a copy of the GNU General Public License version
  15  * 2 along with this work; if not, write to the Free Software Foundation,
  16  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  17  *
  18  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  19  * or visit www.oracle.com if you need additional information or have any
  20  * questions.
  21  *
  22  */
  23 
  24 #include "utilities/copy.hpp"
  25 #include "gc/shared/collectedHeap.hpp"
  26 #include "epsilonCollectedHeap.hpp"
  27 #include "epsilonBarrierSet.hpp"
  28 
  29 jint EpsilonCollectedHeap::initialize() {
  30   size_t max_byte_size = _policy->max_heap_byte_size();
  31 
  32   ReservedSpace heap_rs = Universe::reserve_heap(max_byte_size,
  33                                                  _policy->heap_alignment());
  34 
  35   _start = (HeapWord *) heap_rs.base();
  36   _current = _start;
  37   _end = (HeapWord *) (heap_rs.base() + heap_rs.size());
  38 
  39   size_t size = pointer_delta(_end, _start);
  40 
  41   initialize_reserved_region(_start, _end);
  42   os::commit_memory((char*)_start, size*HeapWordSize, _policy->heap_alignment(), false);
  43 
  44   log_info(gc)("Heap space: [" PTR_FORMAT ", " PTR_FORMAT "] (" SIZE_FORMAT "M)",
  45                p2i(_start), p2i(_end), size*HeapWordSize / M);
  46 
  47   // eagerly zero out everything, or don't bother, let TLAB zeroing do its thing.
  48 //  log_info(gc)("Clearing " SIZE_FORMAT "M", size * HeapWordSize / M);
  49 //  Copy::zero_to_words(_start, size);
  50 
  51   EpsilonBarrierSet* bs = new EpsilonBarrierSet();
  52   set_barrier_set(bs);
  53 
  54   log_info(gc)("Ready to go. See you at your next OutOfMemoryException.");
  55 
  56   return JNI_OK;
  57 }
  58 
  59 HeapWord* EpsilonCollectedHeap::allocate_new_tlab(size_t size) {
  60   bool trap;
  61   return mem_allocate(size, &trap);
  62 }
  63 
  64 HeapWord* EpsilonCollectedHeap::mem_allocate(size_t size, bool *gc_overhead_limit_was_exceeded) {
  65   HeapWord* res = _current;
  66   if (_current + size > _end) {
  67     log_warning(gc)("Heap is exhausted, you sick bastard. Goodbye.");
  68     vm_abort(false);
  69   }
  70   _current += size;
  71   *gc_overhead_limit_was_exceeded = false;
  72   return res;
  73 }