src/hotspot/share/gc/epsilon/epsilonHeap.cpp
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 58021 5f5ca2e02f6e
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50523
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
     1
/*
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
     2
 * Copyright (c) 2017, 2018, Red Hat, Inc. All rights reserved.
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
     3
 *
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
     4
 * This code is free software; you can redistribute it and/or modify it
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
     5
 * under the terms of the GNU General Public License version 2 only, as
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
     6
 * published by the Free Software Foundation.
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
     7
 *
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
     8
 * This code is distributed in the hope that it will be useful, but WITHOUT
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
     9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    10
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    11
 * version 2 for more details (a copy is included in the LICENSE file that
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    12
 * accompanied this code).
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    13
 *
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License version
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    15
 * 2 along with this work; if not, write to the Free Software Foundation,
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    16
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    17
 *
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    18
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    19
 * or visit www.oracle.com if you need additional information or have any
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    20
 * questions.
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    21
 *
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    22
 */
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    23
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    24
#include "precompiled.hpp"
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    25
#include "gc/epsilon/epsilonHeap.hpp"
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    26
#include "gc/epsilon/epsilonMemoryPool.hpp"
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    27
#include "gc/epsilon/epsilonThreadLocalData.hpp"
54678
93f09ca4a7f8 8198505: Remove CollectorPolicy and its subclasses
stefank
parents: 54623
diff changeset
    28
#include "gc/shared/gcArguments.hpp"
57903
5e2576c303a2 8229278: Improve hs_err location printing to assume less about GC internals
eosterlund
parents: 54786
diff changeset
    29
#include "gc/shared/locationPrinter.inline.hpp"
50523
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    30
#include "memory/allocation.hpp"
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    31
#include "memory/allocation.inline.hpp"
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    32
#include "memory/resourceArea.hpp"
54786
ebf733a324d4 8223624: Cleanup includes of universe.hpp
stefank
parents: 54678
diff changeset
    33
#include "memory/universe.hpp"
54678
93f09ca4a7f8 8198505: Remove CollectorPolicy and its subclasses
stefank
parents: 54623
diff changeset
    34
#include "runtime/globals.hpp"
50523
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    35
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    36
jint EpsilonHeap::initialize() {
54678
93f09ca4a7f8 8198505: Remove CollectorPolicy and its subclasses
stefank
parents: 54623
diff changeset
    37
  size_t align = HeapAlignment;
93f09ca4a7f8 8198505: Remove CollectorPolicy and its subclasses
stefank
parents: 54623
diff changeset
    38
  size_t init_byte_size = align_up(InitialHeapSize, align);
93f09ca4a7f8 8198505: Remove CollectorPolicy and its subclasses
stefank
parents: 54623
diff changeset
    39
  size_t max_byte_size  = align_up(MaxHeapSize, align);
50523
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    40
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    41
  // Initialize backing storage
58015
dd84de796f2c 8224815: Remove non-GC uses of CollectedHeap::is_in_reserved()
eosterlund
parents: 57903
diff changeset
    42
  ReservedHeapSpace heap_rs = Universe::reserve_heap(max_byte_size, align);
50523
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    43
  _virtual_space.initialize(heap_rs, init_byte_size);
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    44
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    45
  MemRegion committed_region((HeapWord*)_virtual_space.low(),          (HeapWord*)_virtual_space.high());
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    46
  MemRegion  reserved_region((HeapWord*)_virtual_space.low_boundary(), (HeapWord*)_virtual_space.high_boundary());
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    47
58015
dd84de796f2c 8224815: Remove non-GC uses of CollectedHeap::is_in_reserved()
eosterlund
parents: 57903
diff changeset
    48
  initialize_reserved_region(heap_rs);
50523
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    49
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    50
  _space = new ContiguousSpace();
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    51
  _space->initialize(committed_region, /* clear_space = */ true, /* mangle_space = */ true);
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    52
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    53
  // Precompute hot fields
52150
f586d225bd0b 8212177: Epsilon alignment adjustments can overflow max TLAB size
shade
parents: 52091
diff changeset
    54
  _max_tlab_size = MIN2(CollectedHeap::max_tlab_size(), align_object_size(EpsilonMaxTLABSize / HeapWordSize));
50523
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    55
  _step_counter_update = MIN2<size_t>(max_byte_size / 16, EpsilonUpdateCountersStep);
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    56
  _step_heap_print = (EpsilonPrintHeapSteps == 0) ? SIZE_MAX : (max_byte_size / EpsilonPrintHeapSteps);
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    57
  _decay_time_ns = (int64_t) EpsilonTLABDecayTime * NANOSECS_PER_MILLISEC;
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    58
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    59
  // Enable monitoring
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    60
  _monitoring_support = new EpsilonMonitoringSupport(this);
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    61
  _last_counter_update = 0;
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    62
  _last_heap_print = 0;
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    63
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    64
  // Install barrier set
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    65
  BarrierSet::set_barrier_set(new EpsilonBarrierSet());
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    66
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    67
  // All done, print out the configuration
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    68
  if (init_byte_size != max_byte_size) {
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    69
    log_info(gc)("Resizeable heap; starting at " SIZE_FORMAT "M, max: " SIZE_FORMAT "M, step: " SIZE_FORMAT "M",
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    70
                 init_byte_size / M, max_byte_size / M, EpsilonMinHeapExpand / M);
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    71
  } else {
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    72
    log_info(gc)("Non-resizeable heap; start/max: " SIZE_FORMAT "M", init_byte_size / M);
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    73
  }
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    74
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    75
  if (UseTLAB) {
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    76
    log_info(gc)("Using TLAB allocation; max: " SIZE_FORMAT "K", _max_tlab_size * HeapWordSize / K);
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    77
    if (EpsilonElasticTLAB) {
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    78
      log_info(gc)("Elastic TLABs enabled; elasticity: %.2fx", EpsilonTLABElasticity);
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    79
    }
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    80
    if (EpsilonElasticTLABDecay) {
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    81
      log_info(gc)("Elastic TLABs decay enabled; decay time: " SIZE_FORMAT "ms", EpsilonTLABDecayTime);
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    82
    }
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    83
  } else {
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    84
    log_info(gc)("Not using TLAB allocation");
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    85
  }
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    86
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    87
  return JNI_OK;
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    88
}
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    89
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    90
void EpsilonHeap::post_initialize() {
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    91
  CollectedHeap::post_initialize();
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    92
}
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    93
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    94
void EpsilonHeap::initialize_serviceability() {
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    95
  _pool = new EpsilonMemoryPool(this);
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    96
  _memory_manager.add_pool(_pool);
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    97
}
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    98
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
    99
GrowableArray<GCMemoryManager*> EpsilonHeap::memory_managers() {
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   100
  GrowableArray<GCMemoryManager*> memory_managers(1);
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   101
  memory_managers.append(&_memory_manager);
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   102
  return memory_managers;
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   103
}
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   104
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   105
GrowableArray<MemoryPool*> EpsilonHeap::memory_pools() {
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   106
  GrowableArray<MemoryPool*> memory_pools(1);
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   107
  memory_pools.append(_pool);
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   108
  return memory_pools;
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   109
}
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   110
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   111
size_t EpsilonHeap::unsafe_max_tlab_alloc(Thread* thr) const {
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   112
  // Return max allocatable TLAB size, and let allocation path figure out
58021
5f5ca2e02f6e 8230646: Epsilon does not extend TLABs to max size
shade
parents: 58015
diff changeset
   113
  // the actual allocation size. Note: result should be in bytes.
5f5ca2e02f6e 8230646: Epsilon does not extend TLABs to max size
shade
parents: 58015
diff changeset
   114
  return _max_tlab_size * HeapWordSize;
50523
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   115
}
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   116
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   117
EpsilonHeap* EpsilonHeap::heap() {
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   118
  CollectedHeap* heap = Universe::heap();
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   119
  assert(heap != NULL, "Uninitialized access to EpsilonHeap::heap()");
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   120
  assert(heap->kind() == CollectedHeap::Epsilon, "Not an Epsilon heap");
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   121
  return (EpsilonHeap*)heap;
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   122
}
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   123
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   124
HeapWord* EpsilonHeap::allocate_work(size_t size) {
52091
b25bfa10f52f 8212005: Epsilon elastic TLAB sizing may cause misalignment
shade
parents: 50523
diff changeset
   125
  assert(is_object_aligned(size), "Allocation size should be aligned: " SIZE_FORMAT, size);
b25bfa10f52f 8212005: Epsilon elastic TLAB sizing may cause misalignment
shade
parents: 50523
diff changeset
   126
50523
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   127
  HeapWord* res = _space->par_allocate(size);
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   128
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   129
  while (res == NULL) {
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   130
    // Allocation failed, attempt expansion, and retry:
54623
1126f0607c70 8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents: 53385
diff changeset
   131
    MutexLocker ml(Heap_lock);
50523
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   132
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   133
    size_t space_left = max_capacity() - capacity();
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   134
    size_t want_space = MAX2(size, EpsilonMinHeapExpand);
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   135
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   136
    if (want_space < space_left) {
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   137
      // Enough space to expand in bulk:
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   138
      bool expand = _virtual_space.expand_by(want_space);
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   139
      assert(expand, "Should be able to expand");
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   140
    } else if (size < space_left) {
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   141
      // No space to expand in bulk, and this allocation is still possible,
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   142
      // take all the remaining space:
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   143
      bool expand = _virtual_space.expand_by(space_left);
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   144
      assert(expand, "Should be able to expand");
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   145
    } else {
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   146
      // No space left:
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   147
      return NULL;
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   148
    }
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   149
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   150
    _space->set_end((HeapWord *) _virtual_space.high());
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   151
    res = _space->par_allocate(size);
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   152
  }
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   153
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   154
  size_t used = _space->used();
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   155
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   156
  // Allocation successful, update counters
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   157
  {
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   158
    size_t last = _last_counter_update;
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   159
    if ((used - last >= _step_counter_update) && Atomic::cmpxchg(used, &_last_counter_update, last) == last) {
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   160
      _monitoring_support->update_counters();
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   161
    }
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   162
  }
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   163
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   164
  // ...and print the occupancy line, if needed
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   165
  {
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   166
    size_t last = _last_heap_print;
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   167
    if ((used - last >= _step_heap_print) && Atomic::cmpxchg(used, &_last_heap_print, last) == last) {
53385
e8ed617dc2bc 8217014: Epsilon should not ignore Metadata GC causes
shade
parents: 52150
diff changeset
   168
      print_heap_info(used);
e8ed617dc2bc 8217014: Epsilon should not ignore Metadata GC causes
shade
parents: 52150
diff changeset
   169
      print_metaspace_info();
50523
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   170
    }
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   171
  }
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   172
52091
b25bfa10f52f 8212005: Epsilon elastic TLAB sizing may cause misalignment
shade
parents: 50523
diff changeset
   173
  assert(is_object_aligned(res), "Object should be aligned: " PTR_FORMAT, p2i(res));
50523
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   174
  return res;
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   175
}
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   176
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   177
HeapWord* EpsilonHeap::allocate_new_tlab(size_t min_size,
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   178
                                         size_t requested_size,
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   179
                                         size_t* actual_size) {
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   180
  Thread* thread = Thread::current();
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   181
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   182
  // Defaults in case elastic paths are not taken
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   183
  bool fits = true;
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   184
  size_t size = requested_size;
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   185
  size_t ergo_tlab = requested_size;
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   186
  int64_t time = 0;
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   187
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   188
  if (EpsilonElasticTLAB) {
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   189
    ergo_tlab = EpsilonThreadLocalData::ergo_tlab_size(thread);
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   190
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   191
    if (EpsilonElasticTLABDecay) {
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   192
      int64_t last_time = EpsilonThreadLocalData::last_tlab_time(thread);
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   193
      time = (int64_t) os::javaTimeNanos();
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   194
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   195
      assert(last_time <= time, "time should be monotonic");
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   196
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   197
      // If the thread had not allocated recently, retract the ergonomic size.
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   198
      // This conserves memory when the thread had initial burst of allocations,
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   199
      // and then started allocating only sporadically.
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   200
      if (last_time != 0 && (time - last_time > _decay_time_ns)) {
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   201
        ergo_tlab = 0;
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   202
        EpsilonThreadLocalData::set_ergo_tlab_size(thread, 0);
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   203
      }
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   204
    }
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   205
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   206
    // If we can fit the allocation under current TLAB size, do so.
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   207
    // Otherwise, we want to elastically increase the TLAB size.
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   208
    fits = (requested_size <= ergo_tlab);
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   209
    if (!fits) {
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   210
      size = (size_t) (ergo_tlab * EpsilonTLABElasticity);
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   211
    }
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   212
  }
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   213
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   214
  // Always honor boundaries
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   215
  size = MAX2(min_size, MIN2(_max_tlab_size, size));
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   216
52091
b25bfa10f52f 8212005: Epsilon elastic TLAB sizing may cause misalignment
shade
parents: 50523
diff changeset
   217
  // Always honor alignment
b25bfa10f52f 8212005: Epsilon elastic TLAB sizing may cause misalignment
shade
parents: 50523
diff changeset
   218
  size = align_up(size, MinObjAlignment);
b25bfa10f52f 8212005: Epsilon elastic TLAB sizing may cause misalignment
shade
parents: 50523
diff changeset
   219
52150
f586d225bd0b 8212177: Epsilon alignment adjustments can overflow max TLAB size
shade
parents: 52091
diff changeset
   220
  // Check that adjustments did not break local and global invariants
f586d225bd0b 8212177: Epsilon alignment adjustments can overflow max TLAB size
shade
parents: 52091
diff changeset
   221
  assert(is_object_aligned(size),
f586d225bd0b 8212177: Epsilon alignment adjustments can overflow max TLAB size
shade
parents: 52091
diff changeset
   222
         "Size honors object alignment: " SIZE_FORMAT, size);
f586d225bd0b 8212177: Epsilon alignment adjustments can overflow max TLAB size
shade
parents: 52091
diff changeset
   223
  assert(min_size <= size,
f586d225bd0b 8212177: Epsilon alignment adjustments can overflow max TLAB size
shade
parents: 52091
diff changeset
   224
         "Size honors min size: "  SIZE_FORMAT " <= " SIZE_FORMAT, min_size, size);
f586d225bd0b 8212177: Epsilon alignment adjustments can overflow max TLAB size
shade
parents: 52091
diff changeset
   225
  assert(size <= _max_tlab_size,
f586d225bd0b 8212177: Epsilon alignment adjustments can overflow max TLAB size
shade
parents: 52091
diff changeset
   226
         "Size honors max size: "  SIZE_FORMAT " <= " SIZE_FORMAT, size, _max_tlab_size);
f586d225bd0b 8212177: Epsilon alignment adjustments can overflow max TLAB size
shade
parents: 52091
diff changeset
   227
  assert(size <= CollectedHeap::max_tlab_size(),
f586d225bd0b 8212177: Epsilon alignment adjustments can overflow max TLAB size
shade
parents: 52091
diff changeset
   228
         "Size honors global max size: "  SIZE_FORMAT " <= " SIZE_FORMAT, size, CollectedHeap::max_tlab_size());
f586d225bd0b 8212177: Epsilon alignment adjustments can overflow max TLAB size
shade
parents: 52091
diff changeset
   229
50523
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   230
  if (log_is_enabled(Trace, gc)) {
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   231
    ResourceMark rm;
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   232
    log_trace(gc)("TLAB size for \"%s\" (Requested: " SIZE_FORMAT "K, Min: " SIZE_FORMAT
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   233
                          "K, Max: " SIZE_FORMAT "K, Ergo: " SIZE_FORMAT "K) -> " SIZE_FORMAT "K",
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   234
                  thread->name(),
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   235
                  requested_size * HeapWordSize / K,
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   236
                  min_size * HeapWordSize / K,
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   237
                  _max_tlab_size * HeapWordSize / K,
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   238
                  ergo_tlab * HeapWordSize / K,
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   239
                  size * HeapWordSize / K);
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   240
  }
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   241
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   242
  // All prepared, let's do it!
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   243
  HeapWord* res = allocate_work(size);
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   244
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   245
  if (res != NULL) {
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   246
    // Allocation successful
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   247
    *actual_size = size;
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   248
    if (EpsilonElasticTLABDecay) {
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   249
      EpsilonThreadLocalData::set_last_tlab_time(thread, time);
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   250
    }
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   251
    if (EpsilonElasticTLAB && !fits) {
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   252
      // If we requested expansion, this is our new ergonomic TLAB size
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   253
      EpsilonThreadLocalData::set_ergo_tlab_size(thread, size);
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   254
    }
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   255
  } else {
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   256
    // Allocation failed, reset ergonomics to try and fit smaller TLABs
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   257
    if (EpsilonElasticTLAB) {
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   258
      EpsilonThreadLocalData::set_ergo_tlab_size(thread, 0);
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   259
    }
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   260
  }
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   261
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   262
  return res;
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   263
}
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   264
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   265
HeapWord* EpsilonHeap::mem_allocate(size_t size, bool *gc_overhead_limit_was_exceeded) {
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   266
  *gc_overhead_limit_was_exceeded = false;
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   267
  return allocate_work(size);
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   268
}
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   269
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   270
void EpsilonHeap::collect(GCCause::Cause cause) {
53385
e8ed617dc2bc 8217014: Epsilon should not ignore Metadata GC causes
shade
parents: 52150
diff changeset
   271
  switch (cause) {
e8ed617dc2bc 8217014: Epsilon should not ignore Metadata GC causes
shade
parents: 52150
diff changeset
   272
    case GCCause::_metadata_GC_threshold:
e8ed617dc2bc 8217014: Epsilon should not ignore Metadata GC causes
shade
parents: 52150
diff changeset
   273
    case GCCause::_metadata_GC_clear_soft_refs:
e8ed617dc2bc 8217014: Epsilon should not ignore Metadata GC causes
shade
parents: 52150
diff changeset
   274
      // Receiving these causes means the VM itself entered the safepoint for metadata collection.
e8ed617dc2bc 8217014: Epsilon should not ignore Metadata GC causes
shade
parents: 52150
diff changeset
   275
      // While Epsilon does not do GC, it has to perform sizing adjustments, otherwise we would
e8ed617dc2bc 8217014: Epsilon should not ignore Metadata GC causes
shade
parents: 52150
diff changeset
   276
      // re-enter the safepoint again very soon.
e8ed617dc2bc 8217014: Epsilon should not ignore Metadata GC causes
shade
parents: 52150
diff changeset
   277
e8ed617dc2bc 8217014: Epsilon should not ignore Metadata GC causes
shade
parents: 52150
diff changeset
   278
      assert(SafepointSynchronize::is_at_safepoint(), "Expected at safepoint");
e8ed617dc2bc 8217014: Epsilon should not ignore Metadata GC causes
shade
parents: 52150
diff changeset
   279
      log_info(gc)("GC request for \"%s\" is handled", GCCause::to_string(cause));
e8ed617dc2bc 8217014: Epsilon should not ignore Metadata GC causes
shade
parents: 52150
diff changeset
   280
      MetaspaceGC::compute_new_size();
e8ed617dc2bc 8217014: Epsilon should not ignore Metadata GC causes
shade
parents: 52150
diff changeset
   281
      print_metaspace_info();
e8ed617dc2bc 8217014: Epsilon should not ignore Metadata GC causes
shade
parents: 52150
diff changeset
   282
      break;
e8ed617dc2bc 8217014: Epsilon should not ignore Metadata GC causes
shade
parents: 52150
diff changeset
   283
    default:
e8ed617dc2bc 8217014: Epsilon should not ignore Metadata GC causes
shade
parents: 52150
diff changeset
   284
      log_info(gc)("GC request for \"%s\" is ignored", GCCause::to_string(cause));
e8ed617dc2bc 8217014: Epsilon should not ignore Metadata GC causes
shade
parents: 52150
diff changeset
   285
  }
50523
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   286
  _monitoring_support->update_counters();
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   287
}
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   288
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   289
void EpsilonHeap::do_full_collection(bool clear_all_soft_refs) {
53385
e8ed617dc2bc 8217014: Epsilon should not ignore Metadata GC causes
shade
parents: 52150
diff changeset
   290
  collect(gc_cause());
50523
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   291
}
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   292
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   293
void EpsilonHeap::safe_object_iterate(ObjectClosure *cl) {
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   294
  _space->safe_object_iterate(cl);
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   295
}
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   296
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   297
void EpsilonHeap::print_on(outputStream *st) const {
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   298
  st->print_cr("Epsilon Heap");
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   299
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   300
  // Cast away constness:
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   301
  ((VirtualSpace)_virtual_space).print_on(st);
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   302
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   303
  st->print_cr("Allocation space:");
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   304
  _space->print_on(st);
53385
e8ed617dc2bc 8217014: Epsilon should not ignore Metadata GC causes
shade
parents: 52150
diff changeset
   305
e8ed617dc2bc 8217014: Epsilon should not ignore Metadata GC causes
shade
parents: 52150
diff changeset
   306
  MetaspaceUtils::print_on(st);
50523
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   307
}
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   308
57903
5e2576c303a2 8229278: Improve hs_err location printing to assume less about GC internals
eosterlund
parents: 54786
diff changeset
   309
bool EpsilonHeap::print_location(outputStream* st, void* addr) const {
5e2576c303a2 8229278: Improve hs_err location printing to assume less about GC internals
eosterlund
parents: 54786
diff changeset
   310
  return BlockLocationPrinter<EpsilonHeap>::print_location(st, addr);
5e2576c303a2 8229278: Improve hs_err location printing to assume less about GC internals
eosterlund
parents: 54786
diff changeset
   311
}
5e2576c303a2 8229278: Improve hs_err location printing to assume less about GC internals
eosterlund
parents: 54786
diff changeset
   312
50523
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   313
void EpsilonHeap::print_tracing_info() const {
53385
e8ed617dc2bc 8217014: Epsilon should not ignore Metadata GC causes
shade
parents: 52150
diff changeset
   314
  print_heap_info(used());
e8ed617dc2bc 8217014: Epsilon should not ignore Metadata GC causes
shade
parents: 52150
diff changeset
   315
  print_metaspace_info();
50523
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
diff changeset
   316
}
53385
e8ed617dc2bc 8217014: Epsilon should not ignore Metadata GC causes
shade
parents: 52150
diff changeset
   317
e8ed617dc2bc 8217014: Epsilon should not ignore Metadata GC causes
shade
parents: 52150
diff changeset
   318
void EpsilonHeap::print_heap_info(size_t used) const {
e8ed617dc2bc 8217014: Epsilon should not ignore Metadata GC causes
shade
parents: 52150
diff changeset
   319
  size_t reserved  = max_capacity();
e8ed617dc2bc 8217014: Epsilon should not ignore Metadata GC causes
shade
parents: 52150
diff changeset
   320
  size_t committed = capacity();
e8ed617dc2bc 8217014: Epsilon should not ignore Metadata GC causes
shade
parents: 52150
diff changeset
   321
e8ed617dc2bc 8217014: Epsilon should not ignore Metadata GC causes
shade
parents: 52150
diff changeset
   322
  if (reserved != 0) {
e8ed617dc2bc 8217014: Epsilon should not ignore Metadata GC causes
shade
parents: 52150
diff changeset
   323
    log_info(gc)("Heap: " SIZE_FORMAT "%s reserved, " SIZE_FORMAT "%s (%.2f%%) committed, "
e8ed617dc2bc 8217014: Epsilon should not ignore Metadata GC causes
shade
parents: 52150
diff changeset
   324
                 SIZE_FORMAT "%s (%.2f%%) used",
e8ed617dc2bc 8217014: Epsilon should not ignore Metadata GC causes
shade
parents: 52150
diff changeset
   325
            byte_size_in_proper_unit(reserved),  proper_unit_for_byte_size(reserved),
e8ed617dc2bc 8217014: Epsilon should not ignore Metadata GC causes
shade
parents: 52150
diff changeset
   326
            byte_size_in_proper_unit(committed), proper_unit_for_byte_size(committed),
e8ed617dc2bc 8217014: Epsilon should not ignore Metadata GC causes
shade
parents: 52150
diff changeset
   327
            committed * 100.0 / reserved,
e8ed617dc2bc 8217014: Epsilon should not ignore Metadata GC causes
shade
parents: 52150
diff changeset
   328
            byte_size_in_proper_unit(used),      proper_unit_for_byte_size(used),
e8ed617dc2bc 8217014: Epsilon should not ignore Metadata GC causes
shade
parents: 52150
diff changeset
   329
            used * 100.0 / reserved);
e8ed617dc2bc 8217014: Epsilon should not ignore Metadata GC causes
shade
parents: 52150
diff changeset
   330
  } else {
e8ed617dc2bc 8217014: Epsilon should not ignore Metadata GC causes
shade
parents: 52150
diff changeset
   331
    log_info(gc)("Heap: no reliable data");
e8ed617dc2bc 8217014: Epsilon should not ignore Metadata GC causes
shade
parents: 52150
diff changeset
   332
  }
e8ed617dc2bc 8217014: Epsilon should not ignore Metadata GC causes
shade
parents: 52150
diff changeset
   333
}
e8ed617dc2bc 8217014: Epsilon should not ignore Metadata GC causes
shade
parents: 52150
diff changeset
   334
e8ed617dc2bc 8217014: Epsilon should not ignore Metadata GC causes
shade
parents: 52150
diff changeset
   335
void EpsilonHeap::print_metaspace_info() const {
e8ed617dc2bc 8217014: Epsilon should not ignore Metadata GC causes
shade
parents: 52150
diff changeset
   336
  size_t reserved  = MetaspaceUtils::reserved_bytes();
e8ed617dc2bc 8217014: Epsilon should not ignore Metadata GC causes
shade
parents: 52150
diff changeset
   337
  size_t committed = MetaspaceUtils::committed_bytes();
e8ed617dc2bc 8217014: Epsilon should not ignore Metadata GC causes
shade
parents: 52150
diff changeset
   338
  size_t used      = MetaspaceUtils::used_bytes();
e8ed617dc2bc 8217014: Epsilon should not ignore Metadata GC causes
shade
parents: 52150
diff changeset
   339
e8ed617dc2bc 8217014: Epsilon should not ignore Metadata GC causes
shade
parents: 52150
diff changeset
   340
  if (reserved != 0) {
e8ed617dc2bc 8217014: Epsilon should not ignore Metadata GC causes
shade
parents: 52150
diff changeset
   341
    log_info(gc, metaspace)("Metaspace: " SIZE_FORMAT "%s reserved, " SIZE_FORMAT "%s (%.2f%%) committed, "
e8ed617dc2bc 8217014: Epsilon should not ignore Metadata GC causes
shade
parents: 52150
diff changeset
   342
                            SIZE_FORMAT "%s (%.2f%%) used",
e8ed617dc2bc 8217014: Epsilon should not ignore Metadata GC causes
shade
parents: 52150
diff changeset
   343
            byte_size_in_proper_unit(reserved),  proper_unit_for_byte_size(reserved),
e8ed617dc2bc 8217014: Epsilon should not ignore Metadata GC causes
shade
parents: 52150
diff changeset
   344
            byte_size_in_proper_unit(committed), proper_unit_for_byte_size(committed),
e8ed617dc2bc 8217014: Epsilon should not ignore Metadata GC causes
shade
parents: 52150
diff changeset
   345
            committed * 100.0 / reserved,
e8ed617dc2bc 8217014: Epsilon should not ignore Metadata GC causes
shade
parents: 52150
diff changeset
   346
            byte_size_in_proper_unit(used),      proper_unit_for_byte_size(used),
e8ed617dc2bc 8217014: Epsilon should not ignore Metadata GC causes
shade
parents: 52150
diff changeset
   347
            used * 100.0 / reserved);
e8ed617dc2bc 8217014: Epsilon should not ignore Metadata GC causes
shade
parents: 52150
diff changeset
   348
  } else {
e8ed617dc2bc 8217014: Epsilon should not ignore Metadata GC causes
shade
parents: 52150
diff changeset
   349
    log_info(gc, metaspace)("Metaspace: no reliable data");
e8ed617dc2bc 8217014: Epsilon should not ignore Metadata GC causes
shade
parents: 52150
diff changeset
   350
  }
e8ed617dc2bc 8217014: Epsilon should not ignore Metadata GC causes
shade
parents: 52150
diff changeset
   351
}