Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
8296776: Stop using mtNone as marker for CHeap allocations in Growabl…
…eArray

Reviewed-by: sspitsyn, xliu, stuefe
  • Loading branch information
stefank committed Nov 16, 2022
1 parent 499406c commit 5f51dff
Showing 1 changed file with 43 additions and 18 deletions.
61 changes: 43 additions & 18 deletions src/hotspot/share/utilities/growableArray.hpp
Expand Up @@ -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:
// Resource allocation
GrowableArrayMetadata() :
_bits(bits())
debug_only(COMMA _nesting_check(true)) {
}

// Arena allocation
GrowableArrayMetadata(Arena* arena) :
_bits(bits(arena))
debug_only(COMMA _nesting_check(on_stack())) {
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
Expand Down Expand Up @@ -655,8 +666,8 @@ class GrowableArrayMetadata {
// 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
Expand All @@ -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) {
Expand Down Expand Up @@ -720,15 +727,33 @@ 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),
_metadata(memflags) {
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),
Expand Down

1 comment on commit 5f51dff

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.