mirror of
https://github.com/openjdk/jdk.git
synced 2026-03-25 15:20:11 +00:00
8344609: Check ResourceMark nesting when allocating a GrowableArray on an alternative ResourceArea
Reviewed-by: dholmes, mdoerr
This commit is contained in:
parent
4b92816743
commit
4c33caa185
@ -61,6 +61,10 @@ GrowableArrayNestingCheck::GrowableArrayNestingCheck(bool on_resource_area) :
|
||||
_nesting(on_resource_area ? Thread::current()->resource_area()->nesting() : 0) {
|
||||
}
|
||||
|
||||
GrowableArrayNestingCheck::GrowableArrayNestingCheck(Arena* arena) :
|
||||
_nesting((arena->get_tag() == Arena::Tag::tag_ra) ? static_cast<ResourceArea*>(arena)->nesting() : 0) {
|
||||
}
|
||||
|
||||
void GrowableArrayNestingCheck::on_resource_area_alloc() const {
|
||||
// Check for insidious allocation bug: if a GrowableArray overflows, the
|
||||
// grown array must be allocated under the same ResourceMark as the original.
|
||||
@ -70,6 +74,11 @@ void GrowableArrayNestingCheck::on_resource_area_alloc() const {
|
||||
}
|
||||
}
|
||||
|
||||
void GrowableArrayNestingCheck::on_arena_alloc(Arena* arena) const {
|
||||
if ((arena->get_tag() == Arena::Tag::tag_ra) && (_nesting != static_cast<ResourceArea*>(arena)->nesting())) {
|
||||
fatal("allocation bug: GrowableArray is growing within nested ResourceMark");
|
||||
}
|
||||
}
|
||||
void GrowableArrayMetadata::init_checks(const GrowableArrayBase* array) const {
|
||||
// Stack allocated arrays support all three element allocation locations
|
||||
if (array->allocated_on_stack_or_embedded()) {
|
||||
@ -89,4 +98,8 @@ void GrowableArrayMetadata::on_resource_area_alloc_check() const {
|
||||
_nesting_check.on_resource_area_alloc();
|
||||
}
|
||||
|
||||
void GrowableArrayMetadata::on_arena_alloc_check() const {
|
||||
_nesting_check.on_arena_alloc(arena());
|
||||
}
|
||||
|
||||
#endif // ASSERT
|
||||
|
||||
@ -608,8 +608,10 @@ class GrowableArrayNestingCheck {
|
||||
|
||||
public:
|
||||
GrowableArrayNestingCheck(bool on_resource_area);
|
||||
GrowableArrayNestingCheck(Arena* arena);
|
||||
|
||||
void on_resource_area_alloc() const;
|
||||
void on_arena_alloc(Arena* arena) const;
|
||||
};
|
||||
|
||||
#endif // ASSERT
|
||||
@ -649,7 +651,7 @@ public:
|
||||
// Arena allocation
|
||||
GrowableArrayMetadata(Arena* arena) :
|
||||
_bits(bits(arena))
|
||||
debug_only(COMMA _nesting_check(false)) {
|
||||
debug_only(COMMA _nesting_check(arena)) {
|
||||
}
|
||||
|
||||
// CHeap allocation
|
||||
@ -676,6 +678,7 @@ public:
|
||||
|
||||
void init_checks(const GrowableArrayBase* array) const;
|
||||
void on_resource_area_alloc_check() const;
|
||||
void on_arena_alloc_check() const;
|
||||
#endif // ASSERT
|
||||
|
||||
bool on_C_heap() const { return (_bits & 1) == 1; }
|
||||
@ -740,6 +743,7 @@ class GrowableArray : public GrowableArrayWithAllocator<E, GrowableArray<E>> {
|
||||
}
|
||||
|
||||
assert(on_arena(), "Sanity");
|
||||
debug_only(_metadata.on_arena_alloc_check());
|
||||
return allocate(this->_capacity, _metadata.arena());
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user