src/hotspot/share/gc/epsilon/epsilonHeap.cpp
author shade
Mon, 21 May 2018 15:01:17 +0200
branchepsilon-gc-branch
changeset 56596 e4e901df90f8
parent 56582 c75a617df2f8
child 56641 ecdf81479e0f
permissions -rw-r--r--
Last stylistic touchups
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
55767
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
     1
/*
56350
56014b46de69 Update copyrights
shade
parents: 56276
diff changeset
     2
 * Copyright (c) 2017, 2018, Red Hat, Inc. All rights reserved.
55767
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
     3
 *
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
     4
 * This code is free software; you can redistribute it and/or modify it
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
     5
 * under the terms of the GNU General Public License version 2 only, as
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
     6
 * published by the Free Software Foundation.
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
     7
 *
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
     8
 * This code is distributed in the hope that it will be useful, but WITHOUT
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
     9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    10
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    11
 * version 2 for more details (a copy is included in the LICENSE file that
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    12
 * accompanied this code).
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    13
 *
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License version
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    15
 * 2 along with this work; if not, write to the Free Software Foundation,
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    16
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    17
 *
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    18
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    19
 * or visit www.oracle.com if you need additional information or have any
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    20
 * questions.
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    21
 *
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    22
 */
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    23
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    24
#include "precompiled.hpp"
55939
c5c3e1a5c3f0 Rename EpsilonCollectedHeap to EpsilonHeap.
shade
parents: 55767
diff changeset
    25
#include "gc/epsilon/epsilonHeap.hpp"
55974
shade
parents: 55939
diff changeset
    26
#include "gc/epsilon/epsilonMemoryPool.hpp"
56510
54c1aa06c1d8 Epsilon should use Elastic TLABs facility to control sizes
shade
parents: 56508
diff changeset
    27
#include "gc/epsilon/epsilonThreadLocalData.hpp"
56354
4b9449c330fb Fix non-PCH build
shade
parents: 56353
diff changeset
    28
#include "memory/allocation.hpp"
4b9449c330fb Fix non-PCH build
shade
parents: 56353
diff changeset
    29
#include "memory/allocation.inline.hpp"
4b9449c330fb Fix non-PCH build
shade
parents: 56353
diff changeset
    30
#include "memory/resourceArea.hpp"
55767
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    31
55939
c5c3e1a5c3f0 Rename EpsilonCollectedHeap to EpsilonHeap.
shade
parents: 55767
diff changeset
    32
jint EpsilonHeap::initialize() {
55767
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    33
  size_t init_byte_size = _policy->initial_heap_byte_size();
56581
d6ace215b52c Formatting and renames
shade
parents: 56580
diff changeset
    34
  size_t max_byte_size  = _policy->max_heap_byte_size();
55767
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    35
56581
d6ace215b52c Formatting and renames
shade
parents: 56580
diff changeset
    36
  // Initialize backing storage
d6ace215b52c Formatting and renames
shade
parents: 56580
diff changeset
    37
  ReservedSpace heap_rs = Universe::reserve_heap(max_byte_size, _policy->heap_alignment());
55767
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    38
  _virtual_space.initialize(heap_rs, init_byte_size);
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    39
56581
d6ace215b52c Formatting and renames
shade
parents: 56580
diff changeset
    40
  MemRegion committed_region((HeapWord*)_virtual_space.low(),          (HeapWord*)_virtual_space.high());
d6ace215b52c Formatting and renames
shade
parents: 56580
diff changeset
    41
  MemRegion  reserved_region((HeapWord*)_virtual_space.low_boundary(), (HeapWord*)_virtual_space.high_boundary());
55767
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    42
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    43
  initialize_reserved_region(reserved_region.start(), reserved_region.end());
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    44
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    45
  _space = new ContiguousSpace();
56582
c75a617df2f8 Fix build failure
shade
parents: 56581
diff changeset
    46
  _space->initialize(committed_region, /* clear_space = */ true, /* mangle_space = */ true);
55767
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    47
56581
d6ace215b52c Formatting and renames
shade
parents: 56580
diff changeset
    48
  // Precompute hot fields
d6ace215b52c Formatting and renames
shade
parents: 56580
diff changeset
    49
  _max_tlab_size = MIN2(CollectedHeap::max_tlab_size(), EpsilonMaxTLABSize / HeapWordSize);
d6ace215b52c Formatting and renames
shade
parents: 56580
diff changeset
    50
  _step_counter_update = MIN2<size_t>(max_byte_size / 16, EpsilonUpdateCountersStep);
d6ace215b52c Formatting and renames
shade
parents: 56580
diff changeset
    51
  _step_heap_print = (EpsilonPrintHeapStep == 0) ? SIZE_MAX : (max_byte_size / EpsilonPrintHeapStep);
56596
e4e901df90f8 Last stylistic touchups
shade
parents: 56582
diff changeset
    52
  _decay_time_ns = (int64_t) EpsilonTLABDecayTime * NANOSECS_PER_MILLISEC;
55767
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    53
56581
d6ace215b52c Formatting and renames
shade
parents: 56580
diff changeset
    54
  // Enable monitoring
55767
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    55
  _monitoring_support = new EpsilonMonitoringSupport(this);
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    56
  _last_counter_update = 0;
55979
669f8c047c9c Print heap counters occasionally
shade
parents: 55976
diff changeset
    57
  _last_heap_print = 0;
669f8c047c9c Print heap counters occasionally
shade
parents: 55976
diff changeset
    58
56581
d6ace215b52c Formatting and renames
shade
parents: 56580
diff changeset
    59
  // Install barrier set
d6ace215b52c Formatting and renames
shade
parents: 56580
diff changeset
    60
  BarrierSet::set_barrier_set(new EpsilonBarrierSet());
55767
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    61
56581
d6ace215b52c Formatting and renames
shade
parents: 56580
diff changeset
    62
  // All done, print out the configuration
55767
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    63
  if (init_byte_size != max_byte_size) {
56580
b6c934c3fda2 Fix 32-bit builds
shade
parents: 56577
diff changeset
    64
    log_info(gc)("Resizeable heap; starting at " SIZE_FORMAT "M, max: " SIZE_FORMAT "M, step: " SIZE_FORMAT "M",
55767
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    65
                 init_byte_size / M, max_byte_size / M, EpsilonMinHeapExpand / M);
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    66
  } else {
56580
b6c934c3fda2 Fix 32-bit builds
shade
parents: 56577
diff changeset
    67
    log_info(gc)("Non-resizeable heap; start/max: " SIZE_FORMAT "M", init_byte_size / M);
55767
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    68
  }
56581
d6ace215b52c Formatting and renames
shade
parents: 56580
diff changeset
    69
55767
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    70
  if (UseTLAB) {
56577
338a117fb65c Elastic TLAB machinery should handle decays
shade
parents: 56510
diff changeset
    71
    log_info(gc)("Using TLAB allocation; max: " SIZE_FORMAT "K", _max_tlab_size * HeapWordSize / K);
338a117fb65c Elastic TLAB machinery should handle decays
shade
parents: 56510
diff changeset
    72
    if (EpsilonElasticTLAB) {
56580
b6c934c3fda2 Fix 32-bit builds
shade
parents: 56577
diff changeset
    73
      log_info(gc)("Elastic TLABs enabled; elasticity: %.2fx", EpsilonTLABElasticity);
56577
338a117fb65c Elastic TLAB machinery should handle decays
shade
parents: 56510
diff changeset
    74
    }
338a117fb65c Elastic TLAB machinery should handle decays
shade
parents: 56510
diff changeset
    75
    if (EpsilonElasticTLABDecay) {
56580
b6c934c3fda2 Fix 32-bit builds
shade
parents: 56577
diff changeset
    76
      log_info(gc)("Elastic TLABs decay enabled; decay time: " SIZE_FORMAT "ms", EpsilonTLABDecayTime);
56577
338a117fb65c Elastic TLAB machinery should handle decays
shade
parents: 56510
diff changeset
    77
    }
55767
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    78
  } else {
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    79
    log_info(gc)("Not using TLAB allocation");
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    80
  }
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    81
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    82
  return JNI_OK;
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    83
}
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    84
55974
shade
parents: 55939
diff changeset
    85
void EpsilonHeap::post_initialize() {
shade
parents: 55939
diff changeset
    86
  CollectedHeap::post_initialize();
shade
parents: 55939
diff changeset
    87
}
shade
parents: 55939
diff changeset
    88
shade
parents: 55939
diff changeset
    89
void EpsilonHeap::initialize_serviceability() {
55975
26d15be1c920 Fixup serviceability for Epsilon.
shade
parents: 55974
diff changeset
    90
  _pool = new EpsilonMemoryPool(this);
26d15be1c920 Fixup serviceability for Epsilon.
shade
parents: 55974
diff changeset
    91
  _memory_manager.add_pool(_pool);
55974
shade
parents: 55939
diff changeset
    92
}
shade
parents: 55939
diff changeset
    93
shade
parents: 55939
diff changeset
    94
GrowableArray<GCMemoryManager*> EpsilonHeap::memory_managers() {
55975
26d15be1c920 Fixup serviceability for Epsilon.
shade
parents: 55974
diff changeset
    95
  GrowableArray<GCMemoryManager*> memory_managers(1);
26d15be1c920 Fixup serviceability for Epsilon.
shade
parents: 55974
diff changeset
    96
  memory_managers.append(&_memory_manager);
55974
shade
parents: 55939
diff changeset
    97
  return memory_managers;
shade
parents: 55939
diff changeset
    98
}
shade
parents: 55939
diff changeset
    99
shade
parents: 55939
diff changeset
   100
GrowableArray<MemoryPool*> EpsilonHeap::memory_pools() {
56492
e1871d34a188 Small bugfixes and improvements
shade
parents: 56449
diff changeset
   101
  GrowableArray<MemoryPool*> memory_pools(1);
55975
26d15be1c920 Fixup serviceability for Epsilon.
shade
parents: 55974
diff changeset
   102
  memory_pools.append(_pool);
55974
shade
parents: 55939
diff changeset
   103
  return memory_pools;
shade
parents: 55939
diff changeset
   104
}
shade
parents: 55939
diff changeset
   105
56352
ebb84e128ed3 Whitespace, formatting, dead code elimination
shade
parents: 56350
diff changeset
   106
size_t EpsilonHeap::unsafe_max_tlab_alloc(Thread* thr) const {
56510
54c1aa06c1d8 Epsilon should use Elastic TLABs facility to control sizes
shade
parents: 56508
diff changeset
   107
  // Return max allocatable TLAB size, and let allocation path figure out
54c1aa06c1d8 Epsilon should use Elastic TLABs facility to control sizes
shade
parents: 56508
diff changeset
   108
  // the actual TLAB allocation size.
54c1aa06c1d8 Epsilon should use Elastic TLABs facility to control sizes
shade
parents: 56508
diff changeset
   109
  return _max_tlab_size;
55767
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
   110
}
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
   111
55939
c5c3e1a5c3f0 Rename EpsilonCollectedHeap to EpsilonHeap.
shade
parents: 55767
diff changeset
   112
EpsilonHeap* EpsilonHeap::heap() {
55767
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
   113
  CollectedHeap* heap = Universe::heap();
55939
c5c3e1a5c3f0 Rename EpsilonCollectedHeap to EpsilonHeap.
shade
parents: 55767
diff changeset
   114
  assert(heap != NULL, "Uninitialized access to EpsilonHeap::heap()");
56492
e1871d34a188 Small bugfixes and improvements
shade
parents: 56449
diff changeset
   115
  assert(heap->kind() == CollectedHeap::Epsilon, "Not an Epsilon heap");
55939
c5c3e1a5c3f0 Rename EpsilonCollectedHeap to EpsilonHeap.
shade
parents: 55767
diff changeset
   116
  return (EpsilonHeap*)heap;
55767
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
   117
}
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
   118
55939
c5c3e1a5c3f0 Rename EpsilonCollectedHeap to EpsilonHeap.
shade
parents: 55767
diff changeset
   119
HeapWord* EpsilonHeap::allocate_work(size_t size) {
55767
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
   120
  HeapWord* res = _space->par_allocate(size);
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
   121
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
   122
  while (res == NULL) {
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
   123
    // Allocation failed, attempt expansion, and retry:
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
   124
    MutexLockerEx ml(Heap_lock);
55980
67d289ae67f5 Make sure Epsilon is able to use the last bit of expanded heap
shade
parents: 55979
diff changeset
   125
67d289ae67f5 Make sure Epsilon is able to use the last bit of expanded heap
shade
parents: 55979
diff changeset
   126
    size_t space_left = max_capacity() - capacity();
67d289ae67f5 Make sure Epsilon is able to use the last bit of expanded heap
shade
parents: 55979
diff changeset
   127
    size_t want_space = MAX2(size, EpsilonMinHeapExpand);
67d289ae67f5 Make sure Epsilon is able to use the last bit of expanded heap
shade
parents: 55979
diff changeset
   128
67d289ae67f5 Make sure Epsilon is able to use the last bit of expanded heap
shade
parents: 55979
diff changeset
   129
    if (want_space < space_left) {
67d289ae67f5 Make sure Epsilon is able to use the last bit of expanded heap
shade
parents: 55979
diff changeset
   130
      // Enough space to expand in bulk:
67d289ae67f5 Make sure Epsilon is able to use the last bit of expanded heap
shade
parents: 55979
diff changeset
   131
      bool expand = _virtual_space.expand_by(want_space);
67d289ae67f5 Make sure Epsilon is able to use the last bit of expanded heap
shade
parents: 55979
diff changeset
   132
      assert(expand, "Should be able to expand");
67d289ae67f5 Make sure Epsilon is able to use the last bit of expanded heap
shade
parents: 55979
diff changeset
   133
    } else if (size < space_left) {
67d289ae67f5 Make sure Epsilon is able to use the last bit of expanded heap
shade
parents: 55979
diff changeset
   134
      // No space to expand in bulk, and this allocation is still possible,
56581
d6ace215b52c Formatting and renames
shade
parents: 56580
diff changeset
   135
      // take all the remaining space:
55980
67d289ae67f5 Make sure Epsilon is able to use the last bit of expanded heap
shade
parents: 55979
diff changeset
   136
      bool expand = _virtual_space.expand_by(space_left);
67d289ae67f5 Make sure Epsilon is able to use the last bit of expanded heap
shade
parents: 55979
diff changeset
   137
      assert(expand, "Should be able to expand");
67d289ae67f5 Make sure Epsilon is able to use the last bit of expanded heap
shade
parents: 55979
diff changeset
   138
    } else {
67d289ae67f5 Make sure Epsilon is able to use the last bit of expanded heap
shade
parents: 55979
diff changeset
   139
      // No space left:
55767
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
   140
      return NULL;
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
   141
    }
55980
67d289ae67f5 Make sure Epsilon is able to use the last bit of expanded heap
shade
parents: 55979
diff changeset
   142
55767
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
   143
    _space->set_end((HeapWord *) _virtual_space.high());
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
   144
    res = _space->par_allocate(size);
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
   145
  }
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
   146
56581
d6ace215b52c Formatting and renames
shade
parents: 56580
diff changeset
   147
  // Allocation successful, update counters
55767
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
   148
  size_t used = _space->used();
55979
669f8c047c9c Print heap counters occasionally
shade
parents: 55976
diff changeset
   149
  if (used - _last_counter_update >= _step_counter_update) {
55767
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
   150
    _last_counter_update = used;
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
   151
    _monitoring_support->update_counters();
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
   152
  }
55979
669f8c047c9c Print heap counters occasionally
shade
parents: 55976
diff changeset
   153
56581
d6ace215b52c Formatting and renames
shade
parents: 56580
diff changeset
   154
  // ...and print the occupancy line, if needed
55979
669f8c047c9c Print heap counters occasionally
shade
parents: 55976
diff changeset
   155
  if (used - _last_heap_print >= _step_heap_print) {
669f8c047c9c Print heap counters occasionally
shade
parents: 55976
diff changeset
   156
    log_info(gc)("Heap: " SIZE_FORMAT "M reserved, " SIZE_FORMAT "M committed, " SIZE_FORMAT "M used",
669f8c047c9c Print heap counters occasionally
shade
parents: 55976
diff changeset
   157
                 max_capacity() / M, capacity() / M, used / M);
669f8c047c9c Print heap counters occasionally
shade
parents: 55976
diff changeset
   158
    _last_heap_print = used;
669f8c047c9c Print heap counters occasionally
shade
parents: 55976
diff changeset
   159
  }
669f8c047c9c Print heap counters occasionally
shade
parents: 55976
diff changeset
   160
55767
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
   161
  return res;
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
   162
}
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
   163
56508
shade
parents: 56492
diff changeset
   164
HeapWord* EpsilonHeap::allocate_new_tlab(size_t min_size,
56510
54c1aa06c1d8 Epsilon should use Elastic TLABs facility to control sizes
shade
parents: 56508
diff changeset
   165
                                         size_t requested_size,
54c1aa06c1d8 Epsilon should use Elastic TLABs facility to control sizes
shade
parents: 56508
diff changeset
   166
                                         size_t* actual_size) {
56577
338a117fb65c Elastic TLAB machinery should handle decays
shade
parents: 56510
diff changeset
   167
  Thread* thread = Thread::current();
338a117fb65c Elastic TLAB machinery should handle decays
shade
parents: 56510
diff changeset
   168
338a117fb65c Elastic TLAB machinery should handle decays
shade
parents: 56510
diff changeset
   169
  // Defaults in case elastic paths are not taken
338a117fb65c Elastic TLAB machinery should handle decays
shade
parents: 56510
diff changeset
   170
  bool fits = true;
338a117fb65c Elastic TLAB machinery should handle decays
shade
parents: 56510
diff changeset
   171
  size_t size = requested_size;
338a117fb65c Elastic TLAB machinery should handle decays
shade
parents: 56510
diff changeset
   172
  size_t ergo_tlab = requested_size;
338a117fb65c Elastic TLAB machinery should handle decays
shade
parents: 56510
diff changeset
   173
  int64_t time = 0;
56510
54c1aa06c1d8 Epsilon should use Elastic TLABs facility to control sizes
shade
parents: 56508
diff changeset
   174
56577
338a117fb65c Elastic TLAB machinery should handle decays
shade
parents: 56510
diff changeset
   175
  if (EpsilonElasticTLAB) {
338a117fb65c Elastic TLAB machinery should handle decays
shade
parents: 56510
diff changeset
   176
    ergo_tlab = EpsilonThreadLocalData::ergo_tlab_size(thread);
338a117fb65c Elastic TLAB machinery should handle decays
shade
parents: 56510
diff changeset
   177
338a117fb65c Elastic TLAB machinery should handle decays
shade
parents: 56510
diff changeset
   178
    if (EpsilonElasticTLABDecay) {
56581
d6ace215b52c Formatting and renames
shade
parents: 56580
diff changeset
   179
      int64_t last_time = EpsilonThreadLocalData::last_tlab_time(thread);
56577
338a117fb65c Elastic TLAB machinery should handle decays
shade
parents: 56510
diff changeset
   180
      time = (int64_t) os::javaTimeNanos();
338a117fb65c Elastic TLAB machinery should handle decays
shade
parents: 56510
diff changeset
   181
56581
d6ace215b52c Formatting and renames
shade
parents: 56580
diff changeset
   182
      assert(last_time <= time, "time should be monotonic");
56510
54c1aa06c1d8 Epsilon should use Elastic TLABs facility to control sizes
shade
parents: 56508
diff changeset
   183
56577
338a117fb65c Elastic TLAB machinery should handle decays
shade
parents: 56510
diff changeset
   184
      // If the thread had not allocated recently, retract the ergonomic size.
338a117fb65c Elastic TLAB machinery should handle decays
shade
parents: 56510
diff changeset
   185
      // This conserves memory when the thread had initial burst of allocations,
338a117fb65c Elastic TLAB machinery should handle decays
shade
parents: 56510
diff changeset
   186
      // and then started allocating only sporadically.
56581
d6ace215b52c Formatting and renames
shade
parents: 56580
diff changeset
   187
      if (last_time != 0 && (time - last_time > _decay_time_ns)) {
56577
338a117fb65c Elastic TLAB machinery should handle decays
shade
parents: 56510
diff changeset
   188
        ergo_tlab = 0;
338a117fb65c Elastic TLAB machinery should handle decays
shade
parents: 56510
diff changeset
   189
        EpsilonThreadLocalData::set_ergo_tlab_size(thread, 0);
338a117fb65c Elastic TLAB machinery should handle decays
shade
parents: 56510
diff changeset
   190
      }
338a117fb65c Elastic TLAB machinery should handle decays
shade
parents: 56510
diff changeset
   191
    }
338a117fb65c Elastic TLAB machinery should handle decays
shade
parents: 56510
diff changeset
   192
338a117fb65c Elastic TLAB machinery should handle decays
shade
parents: 56510
diff changeset
   193
    // If we can fit the allocation under current TLAB size, do so.
338a117fb65c Elastic TLAB machinery should handle decays
shade
parents: 56510
diff changeset
   194
    // Otherwise, we want to elastically increase the TLAB size.
338a117fb65c Elastic TLAB machinery should handle decays
shade
parents: 56510
diff changeset
   195
    fits = (requested_size <= ergo_tlab);
338a117fb65c Elastic TLAB machinery should handle decays
shade
parents: 56510
diff changeset
   196
    if (!fits) {
338a117fb65c Elastic TLAB machinery should handle decays
shade
parents: 56510
diff changeset
   197
      size = (size_t) (ergo_tlab * EpsilonTLABElasticity);
338a117fb65c Elastic TLAB machinery should handle decays
shade
parents: 56510
diff changeset
   198
    }
338a117fb65c Elastic TLAB machinery should handle decays
shade
parents: 56510
diff changeset
   199
  }
56510
54c1aa06c1d8 Epsilon should use Elastic TLABs facility to control sizes
shade
parents: 56508
diff changeset
   200
56581
d6ace215b52c Formatting and renames
shade
parents: 56580
diff changeset
   201
  // Always honor boundaries
56510
54c1aa06c1d8 Epsilon should use Elastic TLABs facility to control sizes
shade
parents: 56508
diff changeset
   202
  size = MAX2(min_size, MIN2(_max_tlab_size, size));
54c1aa06c1d8 Epsilon should use Elastic TLABs facility to control sizes
shade
parents: 56508
diff changeset
   203
54c1aa06c1d8 Epsilon should use Elastic TLABs facility to control sizes
shade
parents: 56508
diff changeset
   204
  if (log_is_enabled(Trace, gc)) {
54c1aa06c1d8 Epsilon should use Elastic TLABs facility to control sizes
shade
parents: 56508
diff changeset
   205
    ResourceMark rm;
56577
338a117fb65c Elastic TLAB machinery should handle decays
shade
parents: 56510
diff changeset
   206
    log_trace(gc)("TLAB size for \"%s\" (Requested: " SIZE_FORMAT "K, Min: " SIZE_FORMAT
338a117fb65c Elastic TLAB machinery should handle decays
shade
parents: 56510
diff changeset
   207
                          "K, Max: " SIZE_FORMAT "K, Ergo: " SIZE_FORMAT "K) -> " SIZE_FORMAT "K",
338a117fb65c Elastic TLAB machinery should handle decays
shade
parents: 56510
diff changeset
   208
                  thread->name(),
338a117fb65c Elastic TLAB machinery should handle decays
shade
parents: 56510
diff changeset
   209
                  requested_size * HeapWordSize / K,
338a117fb65c Elastic TLAB machinery should handle decays
shade
parents: 56510
diff changeset
   210
                  min_size * HeapWordSize / K,
338a117fb65c Elastic TLAB machinery should handle decays
shade
parents: 56510
diff changeset
   211
                  _max_tlab_size * HeapWordSize / K,
338a117fb65c Elastic TLAB machinery should handle decays
shade
parents: 56510
diff changeset
   212
                  ergo_tlab * HeapWordSize / K,
338a117fb65c Elastic TLAB machinery should handle decays
shade
parents: 56510
diff changeset
   213
                  size * HeapWordSize / K);
56510
54c1aa06c1d8 Epsilon should use Elastic TLABs facility to control sizes
shade
parents: 56508
diff changeset
   214
  }
54c1aa06c1d8 Epsilon should use Elastic TLABs facility to control sizes
shade
parents: 56508
diff changeset
   215
56581
d6ace215b52c Formatting and renames
shade
parents: 56580
diff changeset
   216
  // All prepared, let's do it!
56510
54c1aa06c1d8 Epsilon should use Elastic TLABs facility to control sizes
shade
parents: 56508
diff changeset
   217
  HeapWord* res = allocate_work(size);
56581
d6ace215b52c Formatting and renames
shade
parents: 56580
diff changeset
   218
56510
54c1aa06c1d8 Epsilon should use Elastic TLABs facility to control sizes
shade
parents: 56508
diff changeset
   219
  if (res != NULL) {
56577
338a117fb65c Elastic TLAB machinery should handle decays
shade
parents: 56510
diff changeset
   220
    // Allocation successful
56510
54c1aa06c1d8 Epsilon should use Elastic TLABs facility to control sizes
shade
parents: 56508
diff changeset
   221
    *actual_size = size;
56577
338a117fb65c Elastic TLAB machinery should handle decays
shade
parents: 56510
diff changeset
   222
    if (EpsilonElasticTLABDecay) {
56581
d6ace215b52c Formatting and renames
shade
parents: 56580
diff changeset
   223
      EpsilonThreadLocalData::set_last_tlab_time(thread, time);
56577
338a117fb65c Elastic TLAB machinery should handle decays
shade
parents: 56510
diff changeset
   224
    }
338a117fb65c Elastic TLAB machinery should handle decays
shade
parents: 56510
diff changeset
   225
    if (EpsilonElasticTLAB && !fits) {
338a117fb65c Elastic TLAB machinery should handle decays
shade
parents: 56510
diff changeset
   226
      // If we requested expansion, this is our new ergonomic TLAB size
338a117fb65c Elastic TLAB machinery should handle decays
shade
parents: 56510
diff changeset
   227
      EpsilonThreadLocalData::set_ergo_tlab_size(thread, size);
56510
54c1aa06c1d8 Epsilon should use Elastic TLABs facility to control sizes
shade
parents: 56508
diff changeset
   228
    }
54c1aa06c1d8 Epsilon should use Elastic TLABs facility to control sizes
shade
parents: 56508
diff changeset
   229
  } else {
56577
338a117fb65c Elastic TLAB machinery should handle decays
shade
parents: 56510
diff changeset
   230
    // Allocation failed, reset ergonomics to try and fit smaller TLABs
338a117fb65c Elastic TLAB machinery should handle decays
shade
parents: 56510
diff changeset
   231
    if (EpsilonElasticTLAB) {
338a117fb65c Elastic TLAB machinery should handle decays
shade
parents: 56510
diff changeset
   232
      EpsilonThreadLocalData::set_ergo_tlab_size(thread, 0);
338a117fb65c Elastic TLAB machinery should handle decays
shade
parents: 56510
diff changeset
   233
    }
56510
54c1aa06c1d8 Epsilon should use Elastic TLABs facility to control sizes
shade
parents: 56508
diff changeset
   234
  }
54c1aa06c1d8 Epsilon should use Elastic TLABs facility to control sizes
shade
parents: 56508
diff changeset
   235
54c1aa06c1d8 Epsilon should use Elastic TLABs facility to control sizes
shade
parents: 56508
diff changeset
   236
  return res;
55767
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
   237
}
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
   238
55939
c5c3e1a5c3f0 Rename EpsilonCollectedHeap to EpsilonHeap.
shade
parents: 55767
diff changeset
   239
HeapWord* EpsilonHeap::mem_allocate(size_t size, bool *gc_overhead_limit_was_exceeded) {
55767
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
   240
  *gc_overhead_limit_was_exceeded = false;
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
   241
  return allocate_work(size);
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
   242
}
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
   243
55939
c5c3e1a5c3f0 Rename EpsilonCollectedHeap to EpsilonHeap.
shade
parents: 55767
diff changeset
   244
void EpsilonHeap::collect(GCCause::Cause cause) {
56353
eb96d40953f1 Rehash messages printed by Epsilon
shade
parents: 56352
diff changeset
   245
  log_info(gc)("GC request for \"%s\" is ignored", GCCause::to_string(cause));
55767
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
   246
  _monitoring_support->update_counters();
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
   247
}
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
   248
55939
c5c3e1a5c3f0 Rename EpsilonCollectedHeap to EpsilonHeap.
shade
parents: 55767
diff changeset
   249
void EpsilonHeap::do_full_collection(bool clear_all_soft_refs) {
56353
eb96d40953f1 Rehash messages printed by Epsilon
shade
parents: 56352
diff changeset
   250
  log_info(gc)("Full GC request for \"%s\" is ignored", GCCause::to_string(gc_cause()));
55767
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
   251
  _monitoring_support->update_counters();
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
   252
}
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
   253
55939
c5c3e1a5c3f0 Rename EpsilonCollectedHeap to EpsilonHeap.
shade
parents: 55767
diff changeset
   254
void EpsilonHeap::safe_object_iterate(ObjectClosure *cl) {
55767
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
   255
  _space->safe_object_iterate(cl);
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
   256
}
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
   257
55939
c5c3e1a5c3f0 Rename EpsilonCollectedHeap to EpsilonHeap.
shade
parents: 55767
diff changeset
   258
void EpsilonHeap::print_on(outputStream *st) const {
55767
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
   259
  st->print_cr("Epsilon Heap");
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
   260
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
   261
  // Cast away constness:
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
   262
  ((VirtualSpace)_virtual_space).print_on(st);
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
   263
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
   264
  st->print_cr("Allocation space:");
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
   265
  _space->print_on(st);
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
   266
}
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
   267
55939
c5c3e1a5c3f0 Rename EpsilonCollectedHeap to EpsilonHeap.
shade
parents: 55767
diff changeset
   268
void EpsilonHeap::print_tracing_info() const {
55767
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
   269
  Log(gc) log;
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
   270
  size_t allocated_kb = used() / K;
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
   271
  log.info("Total allocated: " SIZE_FORMAT " KB",
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
   272
           allocated_kb);
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
   273
  log.info("Average allocation rate: " SIZE_FORMAT " KB/sec",
55976
be6a0c9587da Fix implicit conversion out of size_t.
shade
parents: 55975
diff changeset
   274
           (size_t)(allocated_kb * NANOSECS_PER_SEC / os::elapsed_counter()));
55767
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
   275
}