Skip to content

Commit 1e76ba0

Browse files
author
Kim Barrett
committedNov 15, 2023
8319439: Move BufferNode from PtrQueue files to new files
Reviewed-by: tschatzl, iwalulya
1 parent d5abe49 commit 1e76ba0

17 files changed

+231
-160
lines changed
 

‎src/hotspot/share/gc/g1/g1BarrierSet.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -29,6 +29,7 @@
2929
#include "gc/g1/g1SATBMarkQueueSet.hpp"
3030
#include "gc/shared/cardTable.hpp"
3131
#include "gc/shared/cardTableBarrierSet.hpp"
32+
#include "gc/shared/bufferNode.hpp"
3233

3334
class G1CardTable;
3435

‎src/hotspot/share/gc/g1/g1CardTableEntryClosure.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
#ifndef SHARE_GC_G1_G1CARDTABLEENTRYCLOSURE_HPP
2626
#define SHARE_GC_G1_G1CARDTABLEENTRYCLOSURE_HPP
2727

28+
#include "gc/shared/bufferNode.hpp"
2829
#include "gc/shared/cardTable.hpp"
29-
#include "gc/shared/ptrQueue.hpp"
3030
#include "memory/allocation.hpp"
3131

3232
// A closure class for processing card table entries. Note that we don't

‎src/hotspot/share/gc/g1/g1DirtyCardQueue.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "gc/g1/g1RemSet.hpp"
3535
#include "gc/g1/g1ThreadLocalData.hpp"
3636
#include "gc/g1/heapRegionRemSet.inline.hpp"
37+
#include "gc/shared/bufferNode.hpp"
3738
#include "gc/shared/bufferNodeList.hpp"
3839
#include "gc/shared/suspendibleThreadSet.hpp"
3940
#include "memory/iterator.hpp"

‎src/hotspot/share/gc/g1/g1DirtyCardQueue.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "gc/g1/g1FreeIdSet.hpp"
2929
#include "gc/g1/g1CardTable.hpp"
3030
#include "gc/g1/g1ConcurrentRefineStats.hpp"
31+
#include "gc/shared/bufferNode.hpp"
3132
#include "gc/shared/bufferNodeList.hpp"
3233
#include "gc/shared/ptrQueue.hpp"
3334
#include "memory/allocation.hpp"

‎src/hotspot/share/gc/g1/g1RedirtyCardsQueue.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
#include "precompiled.hpp"
2626
#include "gc/g1/g1RedirtyCardsQueue.hpp"
27+
#include "gc/shared/bufferNode.hpp"
2728
#include "runtime/atomic.hpp"
2829
#include "utilities/debug.hpp"
2930
#include "utilities/macros.hpp"

‎src/hotspot/share/gc/g1/g1RedirtyCardsQueue.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,6 +25,7 @@
2525
#ifndef SHARE_GC_G1_G1REDIRTYCARDSQUEUE_HPP
2626
#define SHARE_GC_G1_G1REDIRTYCARDSQUEUE_HPP
2727

28+
#include "gc/shared/bufferNode.hpp"
2829
#include "gc/shared/bufferNodeList.hpp"
2930
#include "gc/shared/ptrQueue.hpp"
3031
#include "memory/padded.hpp"

‎src/hotspot/share/gc/g1/g1RemSet.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@
4343
#include "gc/g1/heapRegion.inline.hpp"
4444
#include "gc/g1/heapRegionManager.inline.hpp"
4545
#include "gc/g1/heapRegionRemSet.inline.hpp"
46+
#include "gc/shared/bufferNode.hpp"
4647
#include "gc/shared/bufferNodeList.hpp"
4748
#include "gc/shared/gcTraceTime.inline.hpp"
48-
#include "gc/shared/ptrQueue.hpp"
4949
#include "jfr/jfrEvents.hpp"
5050
#include "memory/iterator.hpp"
5151
#include "memory/resourceArea.hpp"

‎src/hotspot/share/gc/g1/g1SATBMarkQueueSet.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,6 +25,7 @@
2525
#ifndef SHARE_GC_G1_G1SATBMARKQUEUESET_HPP
2626
#define SHARE_GC_G1_G1SATBMARKQUEUESET_HPP
2727

28+
#include "gc/shared/bufferNode.hpp"
2829
#include "gc/shared/satbMarkQueue.hpp"
2930

3031
class Monitor;

‎src/hotspot/share/gc/g1/g1YoungGCPostEvacuateTasks.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "gc/g1/g1YoungGCPostEvacuateTasks.hpp"
4141
#include "gc/g1/heapRegion.inline.hpp"
4242
#include "gc/g1/heapRegionRemSet.inline.hpp"
43+
#include "gc/shared/bufferNode.hpp"
4344
#include "gc/shared/preservedMarks.inline.hpp"
4445
#include "jfr/jfrEvents.hpp"
4546
#include "oops/access.inline.hpp"

‎src/hotspot/share/gc/g1/jvmFlagConstraintsG1.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,6 +25,7 @@
2525
#include "precompiled.hpp"
2626
#include "gc/g1/heapRegionBounds.inline.hpp"
2727
#include "gc/g1/jvmFlagConstraintsG1.hpp"
28+
#include "gc/shared/bufferNode.hpp"
2829
#include "gc/shared/ptrQueue.hpp"
2930
#include "runtime/globals_extension.hpp"
3031
#include "utilities/globalDefinitions.hpp"
+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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+
+139
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
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+
#ifndef SHARE_GC_SHARED_BUFFERNODE_HPP
26+
#define SHARE_GC_SHARED_BUFFERNODE_HPP
27+
28+
#include "gc/shared/freeListAllocator.hpp"
29+
#include "utilities/debug.hpp"
30+
#include "utilities/globalDefinitions.hpp"
31+
#include "utilities/lockFreeStack.hpp"
32+
#include "utilities/macros.hpp"
33+
34+
#include <limits>
35+
36+
class BufferNode {
37+
using InternalSizeType = LP64_ONLY(uint32_t) NOT_LP64(uint16_t);
38+
static_assert(sizeof(InternalSizeType) <= sizeof(size_t), "assumption");
39+
40+
InternalSizeType _index;
41+
InternalSizeType _capacity;
42+
BufferNode* volatile _next;
43+
void* _buffer[1]; // Pseudo flexible array member.
44+
45+
BufferNode(InternalSizeType capacity)
46+
: _index(capacity), _capacity(capacity), _next(nullptr)
47+
{}
48+
49+
~BufferNode() = default;
50+
51+
NONCOPYABLE(BufferNode);
52+
53+
static size_t buffer_offset() {
54+
return offset_of(BufferNode, _buffer);
55+
}
56+
57+
public:
58+
static constexpr size_t max_size() {
59+
return std::numeric_limits<InternalSizeType>::max();
60+
}
61+
62+
static BufferNode* volatile* next_ptr(BufferNode& bn) { return &bn._next; }
63+
typedef LockFreeStack<BufferNode, &next_ptr> Stack;
64+
65+
BufferNode* next() const { return _next; }
66+
void set_next(BufferNode* n) { _next = n; }
67+
size_t index() const { return _index; }
68+
69+
void set_index(size_t i) {
70+
assert(i <= capacity(), "precondition");
71+
_index = static_cast<InternalSizeType>(i);
72+
}
73+
74+
size_t capacity() const { return _capacity; }
75+
76+
bool is_empty() const { return index() == capacity(); }
77+
size_t size() const { return capacity() - index(); }
78+
79+
// Return the BufferNode containing the buffer, WITHOUT setting its index.
80+
static BufferNode* make_node_from_buffer(void** buffer) {
81+
char* base = reinterpret_cast<char*>(buffer) - buffer_offset();
82+
return reinterpret_cast<BufferNode*>(base);
83+
}
84+
85+
// Return the BufferNode containing the buffer, after setting its index.
86+
static BufferNode* make_node_from_buffer(void** buffer, size_t index) {
87+
BufferNode* node = make_node_from_buffer(buffer);
88+
node->set_index(index);
89+
return node;
90+
}
91+
92+
// Return the buffer for node.
93+
static void** make_buffer_from_node(BufferNode *node) {
94+
// &_buffer[0] might lead to index out of bounds warnings.
95+
return reinterpret_cast<void**>(
96+
reinterpret_cast<char*>(node) + buffer_offset());
97+
}
98+
99+
class AllocatorConfig;
100+
class Allocator; // Free-list based allocator.
101+
class TestSupport; // Unit test support.
102+
};
103+
104+
// We use BufferNode::AllocatorConfig to set the allocation options for the
105+
// FreeListAllocator.
106+
class BufferNode::AllocatorConfig : public FreeListConfig {
107+
const size_t _buffer_capacity;
108+
109+
public:
110+
explicit AllocatorConfig(size_t size);
111+
112+
~AllocatorConfig() = default;
113+
114+
void* allocate() override;
115+
116+
void deallocate(void* node) override;
117+
118+
size_t buffer_capacity() const { return _buffer_capacity; }
119+
};
120+
121+
class BufferNode::Allocator {
122+
friend class TestSupport;
123+
124+
AllocatorConfig _config;
125+
FreeListAllocator _free_list;
126+
127+
NONCOPYABLE(Allocator);
128+
129+
public:
130+
Allocator(const char* name, size_t buffer_capacity);
131+
~Allocator() = default;
132+
133+
size_t buffer_capacity() const { return _config.buffer_capacity(); }
134+
size_t free_count() const;
135+
BufferNode* allocate();
136+
void release(BufferNode* node);
137+
};
138+
139+
#endif // SHARE_GC_SHARED_BUFFERNODE_HPP

‎src/hotspot/share/gc/shared/ptrQueue.cpp

+1-43
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@
2323
*/
2424

2525
#include "precompiled.hpp"
26+
#include "gc/shared/bufferNode.hpp"
2627
#include "gc/shared/ptrQueue.hpp"
27-
#include "memory/allocation.inline.hpp"
28-
29-
#include <new>
3028

3129
PtrQueue::PtrQueue(PtrQueueSet* qset) :
3230
_index(0),
@@ -45,46 +43,6 @@ size_t PtrQueue::current_capacity() const {
4543
}
4644
}
4745

48-
BufferNode::AllocatorConfig::AllocatorConfig(size_t size)
49-
: _buffer_capacity(size)
50-
{
51-
assert(size >= 1, "Invalid buffer capacity %zu", size);
52-
assert(size <= max_size(), "Invalid buffer capacity %zu", size);
53-
}
54-
55-
void* BufferNode::AllocatorConfig::allocate() {
56-
size_t byte_size = buffer_capacity() * sizeof(void*);
57-
return NEW_C_HEAP_ARRAY(char, buffer_offset() + byte_size, mtGC);
58-
}
59-
60-
void BufferNode::AllocatorConfig::deallocate(void* node) {
61-
assert(node != nullptr, "precondition");
62-
FREE_C_HEAP_ARRAY(char, node);
63-
}
64-
65-
BufferNode::Allocator::Allocator(const char* name, size_t buffer_capacity) :
66-
_config(buffer_capacity),
67-
_free_list(name, &_config)
68-
{}
69-
70-
size_t BufferNode::Allocator::free_count() const {
71-
return _free_list.free_count();
72-
}
73-
74-
BufferNode* BufferNode::Allocator::allocate() {
75-
auto internal_capacity = static_cast<InternalSizeType>(buffer_capacity());
76-
return ::new (_free_list.allocate()) BufferNode(internal_capacity);
77-
}
78-
79-
void BufferNode::Allocator::release(BufferNode* node) {
80-
assert(node != nullptr, "precondition");
81-
assert(node->next() == nullptr, "precondition");
82-
assert(node->capacity() == buffer_capacity(),
83-
"Wrong size %zu, expected %zu", node->capacity(), buffer_capacity());
84-
node->~BufferNode();
85-
_free_list.release(node);
86-
}
87-
8846
PtrQueueSet::PtrQueueSet(BufferNode::Allocator* allocator) :
8947
_allocator(allocator)
9048
{}

0 commit comments

Comments
 (0)
Please sign in to comment.