-
Notifications
You must be signed in to change notification settings - Fork 6.1k
8355013: GrowableArray default constructor should not allocate #24748
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -537,7 +537,7 @@ void GrowableArrayWithAllocator<E, Derived>::expand_to(int new_capacity) { | |||||||||||||||||||||||||||
template <typename E, typename Derived> | ||||||||||||||||||||||||||||
void GrowableArrayWithAllocator<E, Derived>::grow(int j) { | ||||||||||||||||||||||||||||
// grow the array by increasing _capacity to the first power of two larger than the size we need | ||||||||||||||||||||||||||||
expand_to(next_power_of_2(j)); | ||||||||||||||||||||||||||||
expand_to(next_power_of_2(MAX2(j, 4))); | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
template <typename E, typename Derived> | ||||||||||||||||||||||||||||
|
@@ -754,7 +754,9 @@ class GrowableArray : public GrowableArrayWithAllocator<E, GrowableArray<E>> { | |||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
public: | ||||||||||||||||||||||||||||
GrowableArray() : GrowableArray(2 /* initial_capacity */) {} | ||||||||||||||||||||||||||||
GrowableArray() : GrowableArrayWithAllocator<E, GrowableArray>(nullptr, 0), _metadata() { | ||||||||||||||||||||||||||||
init_checks(); | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
explicit GrowableArray(int initial_capacity) : | ||||||||||||||||||||||||||||
GrowableArrayWithAllocator<E, GrowableArray>( | ||||||||||||||||||||||||||||
|
@@ -764,6 +766,12 @@ class GrowableArray : public GrowableArrayWithAllocator<E, GrowableArray<E>> { | |||||||||||||||||||||||||||
init_checks(); | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
explicit GrowableArray(MemTag mem_tag) : | ||||||||||||||||||||||||||||
GrowableArrayWithAllocator<E, GrowableArray>(nullptr, 0), | ||||||||||||||||||||||||||||
_metadata(mem_tag) { | ||||||||||||||||||||||||||||
init_checks(); | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
Comment on lines
+769
to
+774
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||
GrowableArray(int initial_capacity, MemTag mem_tag) : | ||||||||||||||||||||||||||||
GrowableArrayWithAllocator<E, GrowableArray>( | ||||||||||||||||||||||||||||
allocate(initial_capacity, mem_tag), | ||||||||||||||||||||||||||||
|
@@ -825,7 +833,9 @@ class GrowableArrayCHeap : public GrowableArrayWithAllocator<E, GrowableArrayCHe | |||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
public: | ||||||||||||||||||||||||||||
GrowableArrayCHeap(int initial_capacity = 0) : | ||||||||||||||||||||||||||||
GrowableArrayCHeap() : GrowableArrayWithAllocator<E, GrowableArrayCHeap<E, MT>>(nullptr, 0) {} | ||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change isn't necessary since the allocator doesn't allocate if you pass in |
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
explicit GrowableArrayCHeap(int initial_capacity) : | ||||||||||||||||||||||||||||
GrowableArrayWithAllocator<E, GrowableArrayCHeap<E, MT> >( | ||||||||||||||||||||||||||||
allocate(initial_capacity, MT), | ||||||||||||||||||||||||||||
initial_capacity) {} | ||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -350,6 +350,12 @@ class GrowableArrayTest : public ::testing::Test { | |
// Combination not supported | ||
|
||
// Stack/Resource allocated | ||
{ | ||
ResourceMark rm; | ||
GrowableArray<int> a; | ||
modify_and_test(&a, modify, test); | ||
merykitty marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
{ | ||
ResourceMark rm; | ||
GrowableArray<int> a(max); | ||
|
@@ -435,6 +441,10 @@ class GrowableArrayTest : public ::testing::Test { | |
} | ||
}; | ||
|
||
// static empty vector | ||
const GrowableArray<int> empty_array(mtTest); | ||
const GrowableArrayCHeap<int, mtTest> empty_cheap_array; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where are these used? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for your reviews, these are additional to ensure that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. HotSpot denigrates non-local objects with non-trivial ctors. We shouldn't have such instances. |
||
|
||
TEST_VM_F(GrowableArrayTest, append) { | ||
with_all_types_all_0(Append); | ||
} | ||
|
@@ -561,7 +571,7 @@ TEST_VM_ASSERT_MSG(GrowableArrayAssertingTest, assignment_with_embedded_cheap, | |
TEST(GrowableArrayCHeap, sanity) { | ||
// Stack/CHeap | ||
{ | ||
GrowableArrayCHeap<int, mtTest> a(0); | ||
GrowableArrayCHeap<int, mtTest> a; | ||
#ifdef ASSERT | ||
ASSERT_TRUE(a.allocated_on_stack_or_embedded()); | ||
#endif | ||
|
@@ -574,7 +584,7 @@ TEST(GrowableArrayCHeap, sanity) { | |
|
||
// CHeap/CHeap | ||
{ | ||
GrowableArrayCHeap<int, mtTest>* a = new GrowableArrayCHeap<int, mtTest>(0); | ||
GrowableArrayCHeap<int, mtTest>* a = new GrowableArrayCHeap<int, mtTest>(); | ||
#ifdef ASSERT | ||
ASSERT_TRUE(a->allocated_on_C_heap()); | ||
#endif | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.