Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Side by Side Diff: Source/platform/heap/HeapTest.cpp

Issue 1098953006: Oilpan: Support polymorphic objects in HeapVectorBackings (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 3925 matching lines...) Expand 10 before | Expand all | Expand 10 after
3936 } 3936 }
3937 DEFINE_INLINE_TRACE() 3937 DEFINE_INLINE_TRACE()
3938 { 3938 {
3939 } 3939 }
3940 3940
3941 static int s_destructorCalls; 3941 static int s_destructorCalls;
3942 }; 3942 };
3943 3943
3944 int InlinedVectorObject::s_destructorCalls = 0; 3944 int InlinedVectorObject::s_destructorCalls = 0;
3945 3945
3946 class InlinedVectorObjectWithVtable {
3947 ALLOW_ONLY_INLINE_ALLOCATION();
3948 public:
3949 InlinedVectorObjectWithVtable()
3950 {
3951 }
3952 ~InlinedVectorObjectWithVtable()
3953 {
3954 s_destructorCalls++;
3955 }
3956 virtual void virtualMethod() { }
3957 DEFINE_INLINE_TRACE()
3958 {
3959 }
3960
3961 static int s_destructorCalls;
3962 };
3963
3964 int InlinedVectorObjectWithVtable::s_destructorCalls = 0;
3965
3946 } // namespace blink 3966 } // namespace blink
3947 3967
3948 WTF_ALLOW_MOVE_AND_INIT_WITH_MEM_FUNCTIONS(blink::InlinedVectorObject); 3968 WTF_ALLOW_MOVE_AND_INIT_WITH_MEM_FUNCTIONS(blink::InlinedVectorObject);
3949 3969
3950 namespace blink { 3970 namespace blink {
3951 3971
3952 class InlinedVectorObjectWrapper final : public GarbageCollectedFinalized<Inline dVectorObjectWrapper> { 3972 class InlinedVectorObjectWrapper final : public GarbageCollectedFinalized<Inline dVectorObjectWrapper> {
3953 public: 3973 public:
3954 InlinedVectorObjectWrapper() 3974 InlinedVectorObjectWrapper()
3955 { 3975 {
(...skipping 12 matching lines...) Expand all
3968 visitor->trace(m_vector2); 3988 visitor->trace(m_vector2);
3969 visitor->trace(m_vector3); 3989 visitor->trace(m_vector3);
3970 } 3990 }
3971 3991
3972 private: 3992 private:
3973 HeapVector<InlinedVectorObject> m_vector1; 3993 HeapVector<InlinedVectorObject> m_vector1;
3974 HeapVector<InlinedVectorObject, 1> m_vector2; 3994 HeapVector<InlinedVectorObject, 1> m_vector2;
3975 HeapVector<InlinedVectorObject, 2> m_vector3; 3995 HeapVector<InlinedVectorObject, 2> m_vector3;
3976 }; 3996 };
3977 3997
3998 class InlinedVectorObjectWithVtableWrapper final : public GarbageCollectedFinali zed<InlinedVectorObjectWithVtableWrapper> {
3999 public:
4000 InlinedVectorObjectWithVtableWrapper()
4001 {
4002 InlinedVectorObjectWithVtable i1, i2;
4003 m_vector1.append(i1);
4004 m_vector1.append(i2);
4005 m_vector2.append(i1);
4006 m_vector2.append(i2); // This allocates an out-of-line buffer.
4007 m_vector3.append(i1);
4008 m_vector3.append(i2);
4009 }
4010
4011 DEFINE_INLINE_TRACE()
4012 {
4013 visitor->trace(m_vector1);
4014 visitor->trace(m_vector2);
4015 visitor->trace(m_vector3);
4016 }
4017
4018 private:
4019 HeapVector<InlinedVectorObjectWithVtable> m_vector1;
4020 HeapVector<InlinedVectorObjectWithVtable, 1> m_vector2;
4021 HeapVector<InlinedVectorObjectWithVtable, 2> m_vector3;
4022 };
4023
3978 TEST(HeapTest, VectorDestructors) 4024 TEST(HeapTest, VectorDestructors)
3979 { 4025 {
3980 clearOutOldGarbage(); 4026 clearOutOldGarbage();
3981 InlinedVectorObject::s_destructorCalls = 0; 4027 InlinedVectorObject::s_destructorCalls = 0;
3982 { 4028 {
3983 HeapVector<InlinedVectorObject> vector; 4029 HeapVector<InlinedVectorObject> vector;
3984 InlinedVectorObject i1, i2; 4030 InlinedVectorObject i1, i2;
3985 vector.append(i1); 4031 vector.append(i1);
3986 vector.append(i2); 4032 vector.append(i2);
3987 } 4033 }
(...skipping 27 matching lines...) Expand all
4015 InlinedVectorObject::s_destructorCalls = 0; 4061 InlinedVectorObject::s_destructorCalls = 0;
4016 { 4062 {
4017 new InlinedVectorObjectWrapper(); 4063 new InlinedVectorObjectWrapper();
4018 Heap::collectGarbage(ThreadState::HeapPointersOnStack, ThreadState::GCWi thSweep, Heap::ForcedGC); 4064 Heap::collectGarbage(ThreadState::HeapPointersOnStack, ThreadState::GCWi thSweep, Heap::ForcedGC);
4019 EXPECT_EQ(2, InlinedVectorObject::s_destructorCalls); 4065 EXPECT_EQ(2, InlinedVectorObject::s_destructorCalls);
4020 } 4066 }
4021 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWith Sweep, Heap::ForcedGC); 4067 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWith Sweep, Heap::ForcedGC);
4022 EXPECT_LE(8, InlinedVectorObject::s_destructorCalls); 4068 EXPECT_LE(8, InlinedVectorObject::s_destructorCalls);
4023 } 4069 }
4024 4070
4071 TEST(HeapTest, VectorDestructorsWithVtable)
4072 {
4073 clearOutOldGarbage();
4074 InlinedVectorObjectWithVtable::s_destructorCalls = 0;
4075 {
4076 HeapVector<InlinedVectorObjectWithVtable> vector;
4077 InlinedVectorObjectWithVtable i1, i2;
4078 vector.append(i1);
4079 vector.append(i2);
4080 }
4081 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWith Sweep, Heap::ForcedGC);
4082 EXPECT_EQ(4, InlinedVectorObjectWithVtable::s_destructorCalls);
4083
4084 InlinedVectorObjectWithVtable::s_destructorCalls = 0;
4085 {
4086 HeapVector<InlinedVectorObjectWithVtable, 1> vector;
4087 InlinedVectorObjectWithVtable i1, i2;
4088 vector.append(i1);
4089 vector.append(i2); // This allocates an out-of-line buffer.
4090 }
4091 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWith Sweep, Heap::ForcedGC);
4092 EXPECT_EQ(5, InlinedVectorObjectWithVtable::s_destructorCalls);
4093
4094 InlinedVectorObjectWithVtable::s_destructorCalls = 0;
4095 {
4096 HeapVector<InlinedVectorObjectWithVtable, 2> vector;
4097 InlinedVectorObjectWithVtable i1, i2;
4098 vector.append(i1);
4099 vector.append(i2);
4100 }
4101 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWith Sweep, Heap::ForcedGC);
4102 EXPECT_EQ(4, InlinedVectorObjectWithVtable::s_destructorCalls);
4103
4104 InlinedVectorObjectWithVtable::s_destructorCalls = 0;
4105 {
4106 new InlinedVectorObjectWithVtableWrapper();
4107 Heap::collectGarbage(ThreadState::HeapPointersOnStack, ThreadState::GCWi thSweep, Heap::ForcedGC);
4108 EXPECT_EQ(3, InlinedVectorObjectWithVtable::s_destructorCalls);
4109 }
4110 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWith Sweep, Heap::ForcedGC);
4111 EXPECT_EQ(9, InlinedVectorObjectWithVtable::s_destructorCalls);
4112 }
4113
4025 template<typename Set> 4114 template<typename Set>
4026 void rawPtrInHashHelper() 4115 void rawPtrInHashHelper()
4027 { 4116 {
4028 Set set; 4117 Set set;
4029 set.add(new int(42)); 4118 set.add(new int(42));
4030 set.add(new int(42)); 4119 set.add(new int(42));
4031 EXPECT_EQ(2u, set.size()); 4120 EXPECT_EQ(2u, set.size());
4032 for (typename Set::iterator it = set.begin(); it != set.end(); ++it) { 4121 for (typename Set::iterator it = set.begin(); it != set.end(); ++it) {
4033 EXPECT_EQ(42, **it); 4122 EXPECT_EQ(42, **it);
4034 delete *it; 4123 delete *it;
(...skipping 1932 matching lines...) Expand 10 before | Expand all | Expand 10 after
5967 { 6056 {
5968 Persistent<ClassWithMember> object = ClassWithMember::create(); 6057 Persistent<ClassWithMember> object = ClassWithMember::create();
5969 EXPECT_EQ(0, object->traceCount()); 6058 EXPECT_EQ(0, object->traceCount());
5970 TestMixinAllocatingObject* mixin = TestMixinAllocatingObject::create(object. get()); 6059 TestMixinAllocatingObject* mixin = TestMixinAllocatingObject::create(object. get());
5971 EXPECT_TRUE(mixin); 6060 EXPECT_TRUE(mixin);
5972 EXPECT_GT(object->traceCount(), 0); 6061 EXPECT_GT(object->traceCount(), 0);
5973 EXPECT_GT(mixin->traceCount(), 0); 6062 EXPECT_GT(mixin->traceCount(), 0);
5974 } 6063 }
5975 6064
5976 } // namespace blink 6065 } // namespace blink
OLDNEW
« no previous file with comments | « Source/platform/heap/Heap.cpp ('k') | Source/wtf/Vector.h » ('j') | Source/wtf/Vector.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698