| OLD | NEW |
| 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 24 matching lines...) Expand all Loading... |
| 35 #include "platform/heap/HeapLinkedStack.h" | 35 #include "platform/heap/HeapLinkedStack.h" |
| 36 #include "platform/heap/HeapTerminatedArrayBuilder.h" | 36 #include "platform/heap/HeapTerminatedArrayBuilder.h" |
| 37 #include "platform/heap/ThreadState.h" | 37 #include "platform/heap/ThreadState.h" |
| 38 #include "platform/heap/Visitor.h" | 38 #include "platform/heap/Visitor.h" |
| 39 #include "public/platform/Platform.h" | 39 #include "public/platform/Platform.h" |
| 40 #include "wtf/HashTraits.h" | 40 #include "wtf/HashTraits.h" |
| 41 #include "wtf/LinkedHashSet.h" | 41 #include "wtf/LinkedHashSet.h" |
| 42 | 42 |
| 43 #include <gtest/gtest.h> | 43 #include <gtest/gtest.h> |
| 44 | 44 |
| 45 namespace WebCore { | 45 namespace blink { |
| 46 | 46 |
| 47 class IntWrapper : public GarbageCollectedFinalized<IntWrapper> { | 47 class IntWrapper : public GarbageCollectedFinalized<IntWrapper> { |
| 48 public: | 48 public: |
| 49 static IntWrapper* create(int x) | 49 static IntWrapper* create(int x) |
| 50 { | 50 { |
| 51 return new IntWrapper(x); | 51 return new IntWrapper(x); |
| 52 } | 52 } |
| 53 | 53 |
| 54 virtual ~IntWrapper() | 54 virtual ~IntWrapper() |
| 55 { | 55 { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 visitor->trace(first); | 145 visitor->trace(first); |
| 146 return false; | 146 return false; |
| 147 } | 147 } |
| 148 }; | 148 }; |
| 149 | 149 |
| 150 } | 150 } |
| 151 | 151 |
| 152 namespace WTF { | 152 namespace WTF { |
| 153 | 153 |
| 154 template<typename T> struct DefaultHash; | 154 template<typename T> struct DefaultHash; |
| 155 template<> struct DefaultHash<WebCore::ThreadMarker> { | 155 template<> struct DefaultHash<blink::ThreadMarker> { |
| 156 typedef WebCore::ThreadMarkerHash Hash; | 156 typedef blink::ThreadMarkerHash Hash; |
| 157 }; | 157 }; |
| 158 | 158 |
| 159 // ThreadMarkerHash is the default hash for ThreadMarker | 159 // ThreadMarkerHash is the default hash for ThreadMarker |
| 160 template<> struct HashTraits<WebCore::ThreadMarker> : GenericHashTraits<WebCore:
:ThreadMarker> { | 160 template<> struct HashTraits<blink::ThreadMarker> : GenericHashTraits<blink::Thr
eadMarker> { |
| 161 static const bool emptyValueIsZero = true; | 161 static const bool emptyValueIsZero = true; |
| 162 static void constructDeletedValue(WebCore::ThreadMarker& slot) { new (NotNul
l, &slot) WebCore::ThreadMarker(HashTableDeletedValue); } | 162 static void constructDeletedValue(blink::ThreadMarker& slot) { new (NotNull,
&slot) blink::ThreadMarker(HashTableDeletedValue); } |
| 163 static bool isDeletedValue(const WebCore::ThreadMarker& slot) { return slot.
isHashTableDeletedValue(); } | 163 static bool isDeletedValue(const blink::ThreadMarker& slot) { return slot.is
HashTableDeletedValue(); } |
| 164 }; | 164 }; |
| 165 | 165 |
| 166 // The hash algorithm for our custom pair class is just the standard double | 166 // The hash algorithm for our custom pair class is just the standard double |
| 167 // hash for pairs. Note that this means you can't mutate either of the parts of | 167 // hash for pairs. Note that this means you can't mutate either of the parts of |
| 168 // the pair while they are in the hash table, as that would change their hash | 168 // the pair while they are in the hash table, as that would change their hash |
| 169 // code and thus their preferred placement in the table. | 169 // code and thus their preferred placement in the table. |
| 170 template<> struct DefaultHash<WebCore::PairWithWeakHandling> { | 170 template<> struct DefaultHash<blink::PairWithWeakHandling> { |
| 171 typedef PairHash<WebCore::Member<WebCore::IntWrapper>, WebCore::WeakMember<W
ebCore::IntWrapper> > Hash; | 171 typedef PairHash<blink::Member<blink::IntWrapper>, blink::WeakMember<blink::
IntWrapper> > Hash; |
| 172 }; | 172 }; |
| 173 | 173 |
| 174 // Custom traits for the pair. These are weakness handling traits, which means | 174 // Custom traits for the pair. These are weakness handling traits, which means |
| 175 // PairWithWeakHandling must implement the traceInCollection method. | 175 // PairWithWeakHandling must implement the traceInCollection method. |
| 176 // In addition, these traits are concerned with the two magic values for the | 176 // In addition, these traits are concerned with the two magic values for the |
| 177 // object, that represent empty and deleted slots in the hash table. The | 177 // object, that represent empty and deleted slots in the hash table. The |
| 178 // SimpleClassHashTraits allow empty slots in the table to be initialzed with | 178 // SimpleClassHashTraits allow empty slots in the table to be initialzed with |
| 179 // memset to zero, and we use -1 in the first part of the pair to represent | 179 // memset to zero, and we use -1 in the first part of the pair to represent |
| 180 // deleted slots. | 180 // deleted slots. |
| 181 template<> struct HashTraits<WebCore::PairWithWeakHandling> : WebCore::WeakHandl
ingHashTraits<WebCore::PairWithWeakHandling> { | 181 template<> struct HashTraits<blink::PairWithWeakHandling> : blink::WeakHandlingH
ashTraits<blink::PairWithWeakHandling> { |
| 182 static const bool needsDestruction = false; | 182 static const bool needsDestruction = false; |
| 183 static const bool hasIsEmptyValueFunction = true; | 183 static const bool hasIsEmptyValueFunction = true; |
| 184 static bool isEmptyValue(const WebCore::PairWithWeakHandling& value) { retur
n !value.first; } | 184 static bool isEmptyValue(const blink::PairWithWeakHandling& value) { return
!value.first; } |
| 185 static void constructDeletedValue(WebCore::PairWithWeakHandling& slot) { new
(NotNull, &slot) WebCore::PairWithWeakHandling(HashTableDeletedValue); } | 185 static void constructDeletedValue(blink::PairWithWeakHandling& slot) { new (
NotNull, &slot) blink::PairWithWeakHandling(HashTableDeletedValue); } |
| 186 static bool isDeletedValue(const WebCore::PairWithWeakHandling& value) { ret
urn value.isHashTableDeletedValue(); } | 186 static bool isDeletedValue(const blink::PairWithWeakHandling& value) { retur
n value.isHashTableDeletedValue(); } |
| 187 }; | 187 }; |
| 188 | 188 |
| 189 } | 189 } |
| 190 | 190 |
| 191 namespace WebCore { | 191 namespace blink { |
| 192 | 192 |
| 193 class TestGCScope { | 193 class TestGCScope { |
| 194 public: | 194 public: |
| 195 explicit TestGCScope(ThreadState::StackState state) | 195 explicit TestGCScope(ThreadState::StackState state) |
| 196 : m_state(ThreadState::current()) | 196 : m_state(ThreadState::current()) |
| 197 , m_safePointScope(state) | 197 , m_safePointScope(state) |
| 198 , m_parkedAllThreads(false) | 198 , m_parkedAllThreads(false) |
| 199 { | 199 { |
| 200 m_state->checkThread(); | 200 m_state->checkThread(); |
| 201 EXPECT_FALSE(m_state->isInGC()); | 201 EXPECT_FALSE(m_state->isInGC()); |
| (...skipping 1136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1338 | 1338 |
| 1339 IntWrapper* payload() const { return m_payload; } | 1339 IntWrapper* payload() const { return m_payload; } |
| 1340 | 1340 |
| 1341 private: | 1341 private: |
| 1342 Member<IntWrapper> m_payload; | 1342 Member<IntWrapper> m_payload; |
| 1343 bool m_isLast; | 1343 bool m_isLast; |
| 1344 }; | 1344 }; |
| 1345 | 1345 |
| 1346 } // WebCore namespace | 1346 } // WebCore namespace |
| 1347 | 1347 |
| 1348 WTF_ALLOW_MOVE_INIT_AND_COMPARE_WITH_MEM_FUNCTIONS(WebCore::VectorObject); | 1348 WTF_ALLOW_MOVE_INIT_AND_COMPARE_WITH_MEM_FUNCTIONS(blink::VectorObject); |
| 1349 WTF_ALLOW_MOVE_INIT_AND_COMPARE_WITH_MEM_FUNCTIONS(WebCore::VectorObjectInherite
dTrace); | 1349 WTF_ALLOW_MOVE_INIT_AND_COMPARE_WITH_MEM_FUNCTIONS(blink::VectorObjectInheritedT
race); |
| 1350 WTF_ALLOW_MOVE_INIT_AND_COMPARE_WITH_MEM_FUNCTIONS(WebCore::VectorObjectNoTrace)
; | 1350 WTF_ALLOW_MOVE_INIT_AND_COMPARE_WITH_MEM_FUNCTIONS(blink::VectorObjectNoTrace); |
| 1351 | 1351 |
| 1352 namespace WebCore { | 1352 namespace blink { |
| 1353 | 1353 |
| 1354 class OneKiloByteObject : public GarbageCollectedFinalized<OneKiloByteObject> { | 1354 class OneKiloByteObject : public GarbageCollectedFinalized<OneKiloByteObject> { |
| 1355 public: | 1355 public: |
| 1356 ~OneKiloByteObject() { s_destructorCalls++; } | 1356 ~OneKiloByteObject() { s_destructorCalls++; } |
| 1357 char* data() { return m_data; } | 1357 char* data() { return m_data; } |
| 1358 void trace(Visitor* visitor) { } | 1358 void trace(Visitor* visitor) { } |
| 1359 static int s_destructorCalls; | 1359 static int s_destructorCalls; |
| 1360 | 1360 |
| 1361 private: | 1361 private: |
| 1362 static const size_t s_length = 1024; | 1362 static const size_t s_length = 1024; |
| (...skipping 3472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4835 }; | 4835 }; |
| 4836 | 4836 |
| 4837 volatile uintptr_t DeadBitTester::s_workerObjectPointer = 0; | 4837 volatile uintptr_t DeadBitTester::s_workerObjectPointer = 0; |
| 4838 | 4838 |
| 4839 TEST(HeapTest, ObjectDeadBit) | 4839 TEST(HeapTest, ObjectDeadBit) |
| 4840 { | 4840 { |
| 4841 DeadBitTester::test(); | 4841 DeadBitTester::test(); |
| 4842 } | 4842 } |
| 4843 | 4843 |
| 4844 } // WebCore namespace | 4844 } // WebCore namespace |
| OLD | NEW |