mirror of
https://github.com/openjdk/jdk.git
synced 2026-01-28 12:09:14 +00:00
8296776: Stop using mtNone as marker for CHeap allocations in GrowableArray
Reviewed-by: sspitsyn, xliu, stuefe
This commit is contained in:
parent
499406c764
commit
5f51dff697
@ -599,29 +599,40 @@ class GrowableArrayMetadata {
|
||||
// resource area nesting at creation
|
||||
debug_only(GrowableArrayNestingCheck _nesting_check;)
|
||||
|
||||
uintptr_t bits(MEMFLAGS memflags) const {
|
||||
if (memflags == mtNone) {
|
||||
// Stack allocation
|
||||
return 0;
|
||||
}
|
||||
// Resource allocation
|
||||
static uintptr_t bits() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// CHeap allocation
|
||||
// CHeap allocation
|
||||
static uintptr_t bits(MEMFLAGS memflags) {
|
||||
assert(memflags != mtNone, "Must provide a proper MEMFLAGS");
|
||||
return (uintptr_t(memflags) << 1) | 1;
|
||||
}
|
||||
|
||||
uintptr_t bits(Arena* arena) const {
|
||||
// Arena allocation
|
||||
static uintptr_t bits(Arena* arena) {
|
||||
assert((uintptr_t(arena) & 1) == 0, "Required for on_C_heap() to work");
|
||||
return uintptr_t(arena);
|
||||
}
|
||||
|
||||
public:
|
||||
GrowableArrayMetadata(Arena* arena) :
|
||||
_bits(bits(arena))
|
||||
debug_only(COMMA _nesting_check(on_stack())) {
|
||||
// Resource allocation
|
||||
GrowableArrayMetadata() :
|
||||
_bits(bits())
|
||||
debug_only(COMMA _nesting_check(true)) {
|
||||
}
|
||||
|
||||
// Arena allocation
|
||||
GrowableArrayMetadata(Arena* arena) :
|
||||
_bits(bits(arena))
|
||||
debug_only(COMMA _nesting_check(false)) {
|
||||
}
|
||||
|
||||
// CHeap allocation
|
||||
GrowableArrayMetadata(MEMFLAGS memflags) :
|
||||
_bits(bits(memflags))
|
||||
debug_only(COMMA _nesting_check(on_stack())) {
|
||||
debug_only(COMMA _nesting_check(false)) {
|
||||
}
|
||||
|
||||
#ifdef ASSERT
|
||||
@ -655,8 +666,8 @@ public:
|
||||
// THE GrowableArray.
|
||||
//
|
||||
// Supports multiple allocation strategies:
|
||||
// - Resource stack allocation: if memflags == mtNone
|
||||
// - CHeap allocation: if memflags != mtNone
|
||||
// - Resource stack allocation: if no extra argument is provided
|
||||
// - CHeap allocation: if memflags is provided
|
||||
// - Arena allocation: if an arena is provided
|
||||
//
|
||||
// There are some drawbacks of using GrowableArray, that are removed in some
|
||||
@ -679,11 +690,7 @@ class GrowableArray : public GrowableArrayWithAllocator<E, GrowableArray<E> > {
|
||||
}
|
||||
|
||||
static E* allocate(int max, MEMFLAGS memflags) {
|
||||
if (memflags != mtNone) {
|
||||
return (E*)GrowableArrayCHeapAllocator::allocate(max, sizeof(E), memflags);
|
||||
}
|
||||
|
||||
return (E*)GrowableArrayResourceAllocator::allocate(max, sizeof(E));
|
||||
return (E*)GrowableArrayCHeapAllocator::allocate(max, sizeof(E), memflags);
|
||||
}
|
||||
|
||||
static E* allocate(int max, Arena* arena) {
|
||||
@ -720,7 +727,17 @@ class GrowableArray : public GrowableArrayWithAllocator<E, GrowableArray<E> > {
|
||||
}
|
||||
|
||||
public:
|
||||
GrowableArray(int initial_capacity = 2, MEMFLAGS memflags = mtNone) :
|
||||
GrowableArray() : GrowableArray(2 /* initial_capacity */) {}
|
||||
|
||||
explicit GrowableArray(int initial_capacity) :
|
||||
GrowableArrayWithAllocator<E, GrowableArray<E> >(
|
||||
allocate(initial_capacity),
|
||||
initial_capacity),
|
||||
_metadata() {
|
||||
init_checks();
|
||||
}
|
||||
|
||||
GrowableArray(int initial_capacity, MEMFLAGS memflags) :
|
||||
GrowableArrayWithAllocator<E, GrowableArray<E> >(
|
||||
allocate(initial_capacity, memflags),
|
||||
initial_capacity),
|
||||
@ -728,7 +745,15 @@ public:
|
||||
init_checks();
|
||||
}
|
||||
|
||||
GrowableArray(int initial_capacity, int initial_len, const E& filler, MEMFLAGS memflags = mtNone) :
|
||||
GrowableArray(int initial_capacity, int initial_len, const E& filler) :
|
||||
GrowableArrayWithAllocator<E, GrowableArray<E> >(
|
||||
allocate(initial_capacity),
|
||||
initial_capacity, initial_len, filler),
|
||||
_metadata() {
|
||||
init_checks();
|
||||
}
|
||||
|
||||
GrowableArray(int initial_capacity, int initial_len, const E& filler, MEMFLAGS memflags) :
|
||||
GrowableArrayWithAllocator<E, GrowableArray<E> >(
|
||||
allocate(initial_capacity, memflags),
|
||||
initial_capacity, initial_len, filler),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user