Skip to content

Commit 5f51dff

Browse files
committed
8296776: Stop using mtNone as marker for CHeap allocations in GrowableArray
Reviewed-by: sspitsyn, xliu, stuefe
1 parent 499406c commit 5f51dff

File tree

1 file changed

+43
-18
lines changed

1 file changed

+43
-18
lines changed

src/hotspot/share/utilities/growableArray.hpp

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -599,29 +599,40 @@ class GrowableArrayMetadata {
599599
// resource area nesting at creation
600600
debug_only(GrowableArrayNestingCheck _nesting_check;)
601601

602-
uintptr_t bits(MEMFLAGS memflags) const {
603-
if (memflags == mtNone) {
604-
// Stack allocation
605-
return 0;
606-
}
602+
// Resource allocation
603+
static uintptr_t bits() {
604+
return 0;
605+
}
607606

608-
// CHeap allocation
607+
// CHeap allocation
608+
static uintptr_t bits(MEMFLAGS memflags) {
609+
assert(memflags != mtNone, "Must provide a proper MEMFLAGS");
609610
return (uintptr_t(memflags) << 1) | 1;
610611
}
611612

612-
uintptr_t bits(Arena* arena) const {
613+
// Arena allocation
614+
static uintptr_t bits(Arena* arena) {
615+
assert((uintptr_t(arena) & 1) == 0, "Required for on_C_heap() to work");
613616
return uintptr_t(arena);
614617
}
615618

616619
public:
620+
// Resource allocation
621+
GrowableArrayMetadata() :
622+
_bits(bits())
623+
debug_only(COMMA _nesting_check(true)) {
624+
}
625+
626+
// Arena allocation
617627
GrowableArrayMetadata(Arena* arena) :
618628
_bits(bits(arena))
619-
debug_only(COMMA _nesting_check(on_stack())) {
629+
debug_only(COMMA _nesting_check(false)) {
620630
}
621631

632+
// CHeap allocation
622633
GrowableArrayMetadata(MEMFLAGS memflags) :
623634
_bits(bits(memflags))
624-
debug_only(COMMA _nesting_check(on_stack())) {
635+
debug_only(COMMA _nesting_check(false)) {
625636
}
626637

627638
#ifdef ASSERT
@@ -655,8 +666,8 @@ class GrowableArrayMetadata {
655666
// THE GrowableArray.
656667
//
657668
// Supports multiple allocation strategies:
658-
// - Resource stack allocation: if memflags == mtNone
659-
// - CHeap allocation: if memflags != mtNone
669+
// - Resource stack allocation: if no extra argument is provided
670+
// - CHeap allocation: if memflags is provided
660671
// - Arena allocation: if an arena is provided
661672
//
662673
// There are some drawbacks of using GrowableArray, that are removed in some
@@ -679,11 +690,7 @@ class GrowableArray : public GrowableArrayWithAllocator<E, GrowableArray<E> > {
679690
}
680691

681692
static E* allocate(int max, MEMFLAGS memflags) {
682-
if (memflags != mtNone) {
683-
return (E*)GrowableArrayCHeapAllocator::allocate(max, sizeof(E), memflags);
684-
}
685-
686-
return (E*)GrowableArrayResourceAllocator::allocate(max, sizeof(E));
693+
return (E*)GrowableArrayCHeapAllocator::allocate(max, sizeof(E), memflags);
687694
}
688695

689696
static E* allocate(int max, Arena* arena) {
@@ -720,15 +727,33 @@ class GrowableArray : public GrowableArrayWithAllocator<E, GrowableArray<E> > {
720727
}
721728

722729
public:
723-
GrowableArray(int initial_capacity = 2, MEMFLAGS memflags = mtNone) :
730+
GrowableArray() : GrowableArray(2 /* initial_capacity */) {}
731+
732+
explicit GrowableArray(int initial_capacity) :
733+
GrowableArrayWithAllocator<E, GrowableArray<E> >(
734+
allocate(initial_capacity),
735+
initial_capacity),
736+
_metadata() {
737+
init_checks();
738+
}
739+
740+
GrowableArray(int initial_capacity, MEMFLAGS memflags) :
724741
GrowableArrayWithAllocator<E, GrowableArray<E> >(
725742
allocate(initial_capacity, memflags),
726743
initial_capacity),
727744
_metadata(memflags) {
728745
init_checks();
729746
}
730747

731-
GrowableArray(int initial_capacity, int initial_len, const E& filler, MEMFLAGS memflags = mtNone) :
748+
GrowableArray(int initial_capacity, int initial_len, const E& filler) :
749+
GrowableArrayWithAllocator<E, GrowableArray<E> >(
750+
allocate(initial_capacity),
751+
initial_capacity, initial_len, filler),
752+
_metadata() {
753+
init_checks();
754+
}
755+
756+
GrowableArray(int initial_capacity, int initial_len, const E& filler, MEMFLAGS memflags) :
732757
GrowableArrayWithAllocator<E, GrowableArray<E> >(
733758
allocate(initial_capacity, memflags),
734759
initial_capacity, initial_len, filler),

0 commit comments

Comments
 (0)