Commit 57f48168 authored by Omer Katz's avatar Omer Katz Committed by Commit Bot

heap: Don't use new for GCed objects in HeapTest

These objects were never marked as fully constructed.

Bug: 986235
Change-Id: Ia71abf4f8c118df29ccbd1e008d3ac484bdd6668
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2212162Reviewed-by: default avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Omer Katz <omerkatz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#772166}
parent ec654ffa
...@@ -637,31 +637,24 @@ int SimpleFinalizedObject::destructor_calls_ = 0; ...@@ -637,31 +637,24 @@ int SimpleFinalizedObject::destructor_calls_ = 0;
class IntNode : public GarbageCollected<IntNode> { class IntNode : public GarbageCollected<IntNode> {
public: public:
// IntNode is used to test typed heap allocation. Instead of template <typename T>
// redefining blink::Node to our test version, we keep it separate static void* AllocateObject(size_t size) {
// so as to avoid possible warnings about linker duplicates.
// Override operator new to allocate IntNode subtype objects onto
// the dedicated heap for blink::Node.
//
// TODO(haraken): untangling the heap unit tests from Blink would
// simplify and avoid running into this problem - http://crbug.com/425381
GC_PLUGIN_IGNORE("crbug.com/443854")
void* operator new(size_t size) {
ThreadState* state = ThreadState::Current(); ThreadState* state = ThreadState::Current();
const char* type_name = WTF_HEAP_PROFILER_TYPE_NAME(IntNode); const char* type_name = WTF_HEAP_PROFILER_TYPE_NAME(IntNode);
return state->Heap().AllocateOnArenaIndex( return state->Heap().AllocateOnArenaIndex(
state, size, BlinkGC::kNodeArenaIndex, GCInfoTrait<IntNode>::Index(), state, size, BlinkGC::kNodeArenaIndex,
type_name); GCInfoTrait<GCInfoFoldedType<IntNode>>::Index(), type_name);
} }
static IntNode* Create(int i) { return new IntNode(i); } explicit IntNode(int i) : value_(i) {}
static IntNode* Create(int i) { return MakeGarbageCollected<IntNode>(i); }
void Trace(Visitor* visitor) const {} void Trace(Visitor* visitor) const {}
int Value() { return value_; } int Value() { return value_; }
private: private:
IntNode(int i) : value_(i) {}
int value_; int value_;
}; };
...@@ -1262,18 +1255,13 @@ int OneKiloByteObject::destructor_calls_ = 0; ...@@ -1262,18 +1255,13 @@ int OneKiloByteObject::destructor_calls_ = 0;
class DynamicallySizedObject : public GarbageCollected<DynamicallySizedObject> { class DynamicallySizedObject : public GarbageCollected<DynamicallySizedObject> {
public: public:
static DynamicallySizedObject* Create(size_t size) { static DynamicallySizedObject* Create(size_t size) {
void* slot = ThreadHeap::Allocate<DynamicallySizedObject>(size); return MakeGarbageCollected<DynamicallySizedObject>(
return new (slot) DynamicallySizedObject(); AdditionalBytes(size - sizeof(DynamicallySizedObject)));
} }
void* operator new(std::size_t, void* location) { return location; }
uint8_t Get(int i) { return *(reinterpret_cast<uint8_t*>(this) + i); } uint8_t Get(int i) { return *(reinterpret_cast<uint8_t*>(this) + i); }
void Trace(Visitor* visitor) const {} void Trace(Visitor* visitor) const {}
private:
DynamicallySizedObject() = default;
}; };
class FinalizationAllocator final class FinalizationAllocator final
...@@ -4134,18 +4122,6 @@ TEST_F(HeapTest, VectorDestructorsWithVtable) { ...@@ -4134,18 +4122,6 @@ TEST_F(HeapTest, VectorDestructorsWithVtable) {
} }
#endif #endif
template <typename Set>
void RawPtrInHashHelper() {
Set set;
set.Add(new int(42));
set.Add(new int(42));
EXPECT_EQ(2u, set.size());
for (typename Set::iterator it = set.begin(); it != set.end(); ++it) {
EXPECT_EQ(42, **it);
delete *it;
}
}
TEST_F(HeapTest, AllocationDuringFinalization) { TEST_F(HeapTest, AllocationDuringFinalization) {
ClearOutOldGarbage(); ClearOutOldGarbage();
IntWrapper::destructor_calls_ = 0; IntWrapper::destructor_calls_ = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment