jdk

Форк
0
/
bufferNode.cpp 
70 строк · 2.4 Кб
1
/*
2
 * Copyright (c) 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/bufferNode.hpp"
27
#include "utilities/debug.hpp"
28
#include "memory/allocation.inline.hpp"
29

30
#include <new>
31

32
BufferNode::AllocatorConfig::AllocatorConfig(size_t size)
33
  : _buffer_capacity(size)
34
{
35
  assert(size >= 1, "Invalid buffer capacity %zu", size);
36
  assert(size <= max_size(), "Invalid buffer capacity %zu", size);
37
}
38

39
void* BufferNode::AllocatorConfig::allocate() {
40
  size_t byte_size = buffer_capacity() * sizeof(void*);
41
  return NEW_C_HEAP_ARRAY(char, buffer_offset() + byte_size, mtGC);
42
}
43

44
void BufferNode::AllocatorConfig::deallocate(void* node) {
45
  assert(node != nullptr, "precondition");
46
  FREE_C_HEAP_ARRAY(char, node);
47
}
48

49
BufferNode::Allocator::Allocator(const char* name, size_t buffer_capacity) :
50
  _config(buffer_capacity),
51
  _free_list(name, &_config)
52
{}
53

54
size_t BufferNode::Allocator::free_count() const {
55
  return _free_list.free_count();
56
}
57

58
BufferNode* BufferNode::Allocator::allocate() {
59
  auto internal_capacity = static_cast<InternalSizeType>(buffer_capacity());
60
  return ::new (_free_list.allocate()) BufferNode(internal_capacity);
61
}
62

63
void BufferNode::Allocator::release(BufferNode* node) {
64
  assert(node != nullptr, "precondition");
65
  assert(node->next() == nullptr, "precondition");
66
  assert(node->capacity() == buffer_capacity(),
67
         "Wrong size %zu, expected %zu", node->capacity(), buffer_capacity());
68
  node->~BufferNode();
69
  _free_list.release(node);
70
}
71

72

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

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

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

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