jdk

Форк
0
123 строки · 4.3 Кб
1
/*
2
 * Copyright (c) 2001, 2023, Oracle and/or its affiliates. All rights reserved.
3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
 *
5
 * This code is free software; you can redistribute it and/or modify it
6
 * under the terms of the GNU General Public License version 2 only, as
7
 * published by the Free Software Foundation.
8
 *
9
 * This code is distributed in the hope that it will be useful, but WITHOUT
10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12
 * version 2 for more details (a copy is included in the LICENSE file that
13
 * accompanied this code).
14
 *
15
 * You should have received a copy of the GNU General Public License version
16
 * 2 along with this work; if not, write to the Free Software Foundation,
17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
 *
19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
 * or visit www.oracle.com if you need additional information or have any
21
 * questions.
22
 *
23
 */
24

25
#include "precompiled.hpp"
26
#include "gc/shared/collectedHeap.hpp"
27
#include "gc/shared/gc_globals.hpp"
28
#include "gc/shared/plab.inline.hpp"
29
#include "gc/shared/threadLocalAllocBuffer.hpp"
30
#include "gc/shared/tlab_globals.hpp"
31
#include "logging/log.hpp"
32
#include "memory/universe.hpp"
33
#include "oops/oop.inline.hpp"
34
#include "runtime/globals_extension.hpp"
35

36
size_t PLAB::min_size() {
37
  // Make sure that we return something that is larger than AlignmentReserve
38
  return align_object_size(MAX2(MinTLABSize / HeapWordSize, (size_t)oopDesc::header_size())) + CollectedHeap::lab_alignment_reserve();
39
}
40

41
size_t PLAB::max_size() {
42
  return ThreadLocalAllocBuffer::max_size();
43
}
44

45
void PLAB::startup_initialization() {
46
  if (!FLAG_IS_DEFAULT(MinTLABSize)) {
47
    if (FLAG_IS_DEFAULT(YoungPLABSize)) {
48
      FLAG_SET_ERGO(YoungPLABSize, MAX2(ThreadLocalAllocBuffer::min_size(), YoungPLABSize));
49
    }
50
    if (FLAG_IS_DEFAULT(OldPLABSize)) {
51
      FLAG_SET_ERGO(OldPLABSize, MAX2(ThreadLocalAllocBuffer::min_size(), OldPLABSize));
52
    }
53
  }
54
  uint obj_alignment = checked_cast<uint>(ObjectAlignmentInBytes / HeapWordSize);
55
  if (!is_aligned(YoungPLABSize, obj_alignment)) {
56
    FLAG_SET_ERGO(YoungPLABSize, align_up(YoungPLABSize, obj_alignment));
57
  }
58
  if (!is_aligned(OldPLABSize, obj_alignment)) {
59
    FLAG_SET_ERGO(OldPLABSize, align_up(OldPLABSize, obj_alignment));
60
  }
61
}
62

63
PLAB::PLAB(size_t desired_plab_sz_) :
64
  _word_sz(desired_plab_sz_), _bottom(nullptr), _top(nullptr),
65
  _end(nullptr), _hard_end(nullptr), _allocated(0), _wasted(0), _undo_wasted(0)
66
{
67
  assert(min_size() > CollectedHeap::lab_alignment_reserve(),
68
         "Minimum PLAB size " SIZE_FORMAT " must be larger than alignment reserve " SIZE_FORMAT " "
69
         "to be able to contain objects", min_size(), CollectedHeap::lab_alignment_reserve());
70
}
71

72
void PLAB::flush_and_retire_stats(PLABStats* stats) {
73
  // Retire the last allocation buffer.
74
  size_t unused = retire_internal();
75

76
  // Now flush the statistics.
77
  stats->add_allocated(_allocated);
78
  stats->add_wasted(_wasted);
79
  stats->add_undo_wasted(_undo_wasted);
80
  stats->add_unused(unused);
81

82
  // Since we have flushed the stats we need to clear  the _allocated and _wasted
83
  // fields in case somebody retains an instance of this over GCs. Not doing so
84
  // will artificially inflate the values in the statistics.
85
  _allocated   = 0;
86
  _wasted      = 0;
87
  _undo_wasted = 0;
88
}
89

90
void PLAB::retire() {
91
  _wasted += retire_internal();
92
}
93

94
size_t PLAB::retire_internal() {
95
  size_t result = 0;
96
  if (_top < _hard_end) {
97
    Universe::heap()->fill_with_dummy_object(_top, _hard_end, true);
98
    result += invalidate();
99
  }
100
  return result;
101
}
102

103
void PLAB::add_undo_waste(HeapWord* obj, size_t word_sz) {
104
  Universe::heap()->fill_with_dummy_object(obj, obj + word_sz, true);
105
  _undo_wasted += word_sz;
106
}
107

108
void PLAB::undo_last_allocation(HeapWord* obj, size_t word_sz) {
109
  assert(pointer_delta(_top, _bottom) >= word_sz, "Bad undo");
110
  assert(pointer_delta(_top, obj) == word_sz, "Bad undo");
111
  _top = obj;
112
}
113

114
void PLAB::undo_allocation(HeapWord* obj, size_t word_sz) {
115
  // Is the alloc in the current alloc buffer?
116
  if (contains(obj)) {
117
    assert(contains(obj + word_sz - 1),
118
      "should contain whole object");
119
    undo_last_allocation(obj, word_sz);
120
  } else {
121
    add_undo_waste(obj, word_sz);
122
  }
123
}
124

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.