| 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 // only and objects that can be used on any thread. | 73 // only and objects that can be used on any thread. |
| 74 // | 74 // |
| 75 // For objects that can only be used on the main thread we avoid going | 75 // For objects that can only be used on the main thread we avoid going |
| 76 // through thread-local storage to get to the thread state. | 76 // through thread-local storage to get to the thread state. |
| 77 // | 77 // |
| 78 // FIXME: We should evaluate the performance gain. Having | 78 // FIXME: We should evaluate the performance gain. Having |
| 79 // ThreadAffinity is complicating the implementation and we should get | 79 // ThreadAffinity is complicating the implementation and we should get |
| 80 // rid of it if it is fast enough to go through thread-local storage | 80 // rid of it if it is fast enough to go through thread-local storage |
| 81 // always. | 81 // always. |
| 82 enum ThreadAffinity { | 82 enum ThreadAffinity { |
| 83 AnyThread, | 83 AnyThreadAffinity, |
| 84 MainThreadOnly, | 84 MainThreadAffinity, |
| 85 }; | 85 }; |
| 86 | 86 |
| 87 // FIXME: These forward declarations violate dependency rules. Remove them. | 87 class MainThreadOnly { }; |
| 88 // Ideally we want to provide a USED_IN_MAIN_THREAD_ONLY(T) macro, which | |
| 89 // indicates that classes in T's hierarchy are used only by the main thread. | |
| 90 class Node; | |
| 91 class NodeList; | |
| 92 | 88 |
| 93 template<typename T, | 89 template<typename T, bool mainThreadOnly = WTF::IsSubclass<typename WTF::RemoveC
onst<T>::Type, MainThreadOnly>::value> struct DefaultThreadingTrait; |
| 94 bool mainThreadOnly = WTF::IsSubclass<typename WTF::RemoveConst<T>::Type, No
de>::value | |
| 95 || WTF::IsSubclass<typename WTF::RemoveConst<T>::Type, NodeList>::value>
struct DefaultThreadingTrait; | |
| 96 | 90 |
| 97 template<typename T> | 91 template<typename T> |
| 98 struct DefaultThreadingTrait<T, false> { | 92 struct DefaultThreadingTrait<T, false> { |
| 99 static const ThreadAffinity Affinity = AnyThread; | 93 static const ThreadAffinity Affinity = AnyThreadAffinity; |
| 100 }; | 94 }; |
| 101 | 95 |
| 102 template<typename T> | 96 template<typename T> |
| 103 struct DefaultThreadingTrait<T, true> { | 97 struct DefaultThreadingTrait<T, true> { |
| 104 static const ThreadAffinity Affinity = MainThreadOnly; | 98 static const ThreadAffinity Affinity = MainThreadAffinity; |
| 105 }; | 99 }; |
| 106 | 100 |
| 107 template<typename T> | 101 template<typename T> |
| 108 struct ThreadingTrait { | 102 struct ThreadingTrait { |
| 109 static const ThreadAffinity Affinity = DefaultThreadingTrait<T>::Affinity; | 103 static const ThreadAffinity Affinity = DefaultThreadingTrait<T>::Affinity; |
| 110 }; | 104 }; |
| 111 | 105 |
| 112 // Marks the specified class as being used from multiple threads. When | |
| 113 // a class is used from multiple threads we go through thread local | |
| 114 // storage to get the heap in which to allocate an object of that type | |
| 115 // and when allocating a Persistent handle for an object with that | |
| 116 // type. Notice that marking the base class does not automatically | |
| 117 // mark its descendants and they have to be explicitly marked. | |
| 118 #define USED_FROM_MULTIPLE_THREADS(Class) \ | |
| 119 class Class; \ | |
| 120 template<> struct ThreadingTrait<Class> { \ | |
| 121 static const ThreadAffinity Affinity = AnyThread; \ | |
| 122 } | |
| 123 | |
| 124 #define USED_FROM_MULTIPLE_THREADS_NAMESPACE(Namespace, Class) \ | |
| 125 namespace Namespace { \ | |
| 126 class Class; \ | |
| 127 } \ | |
| 128 namespace blink { \ | |
| 129 template<> struct ThreadingTrait<Namespace::Class> { \ | |
| 130 static const ThreadAffinity Affinity = AnyThread; \ | |
| 131 }; \ | |
| 132 } | |
| 133 | |
| 134 template<typename U> class ThreadingTrait<const U> : public ThreadingTrait<U> {
}; | 106 template<typename U> class ThreadingTrait<const U> : public ThreadingTrait<U> {
}; |
| 135 | 107 |
| 136 // Declare that a class has a pre-finalizer function. The function is called in | 108 // Declare that a class has a pre-finalizer function. The function is called in |
| 137 // the object's owner thread, and can access Member<>s to other | 109 // the object's owner thread, and can access Member<>s to other |
| 138 // garbage-collected objects allocated in the thread. However we must not | 110 // garbage-collected objects allocated in the thread. However we must not |
| 139 // allocate new garbage-collected objects, nor update Member<> and Persistent<> | 111 // allocate new garbage-collected objects, nor update Member<> and Persistent<> |
| 140 // pointers. | 112 // pointers. |
| 141 // | 113 // |
| 142 // This feature is similar to the HeapHashMap<WeakMember<Foo>, OwnPtr<Disposer>> | 114 // This feature is similar to the HeapHashMap<WeakMember<Foo>, OwnPtr<Disposer>> |
| 143 // idiom. The difference between this and the idiom is that pre-finalizer | 115 // idiom. The difference between this and the idiom is that pre-finalizer |
| (...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 820 | 792 |
| 821 #if defined(ADDRESS_SANITIZER) | 793 #if defined(ADDRESS_SANITIZER) |
| 822 void* m_asanFakeStack; | 794 void* m_asanFakeStack; |
| 823 #endif | 795 #endif |
| 824 | 796 |
| 825 Vector<PageMemoryRegion*> m_allocatedRegionsSinceLastGC; | 797 Vector<PageMemoryRegion*> m_allocatedRegionsSinceLastGC; |
| 826 }; | 798 }; |
| 827 | 799 |
| 828 template<ThreadAffinity affinity> class ThreadStateFor; | 800 template<ThreadAffinity affinity> class ThreadStateFor; |
| 829 | 801 |
| 830 template<> class ThreadStateFor<MainThreadOnly> { | 802 template<> class ThreadStateFor<MainThreadAffinity> { |
| 831 public: | 803 public: |
| 832 static ThreadState* state() | 804 static ThreadState* state() |
| 833 { | 805 { |
| 834 // This specialization must only be used from the main thread. | 806 // This specialization must only be used from the main thread. |
| 835 ASSERT(ThreadState::current()->isMainThread()); | 807 ASSERT(ThreadState::current()->isMainThread()); |
| 836 return ThreadState::mainThreadState(); | 808 return ThreadState::mainThreadState(); |
| 837 } | 809 } |
| 838 }; | 810 }; |
| 839 | 811 |
| 840 template<> class ThreadStateFor<AnyThread> { | 812 template<> class ThreadStateFor<AnyThreadAffinity> { |
| 841 public: | 813 public: |
| 842 static ThreadState* state() { return ThreadState::current(); } | 814 static ThreadState* state() { return ThreadState::current(); } |
| 843 }; | 815 }; |
| 844 | 816 |
| 845 // The SafePointAwareMutexLocker is used to enter a safepoint while waiting for | 817 // The SafePointAwareMutexLocker is used to enter a safepoint while waiting for |
| 846 // a mutex lock. It also ensures that the lock is not held while waiting for a G
C | 818 // a mutex lock. It also ensures that the lock is not held while waiting for a G
C |
| 847 // to complete in the leaveSafePoint method, by releasing the lock if the | 819 // to complete in the leaveSafePoint method, by releasing the lock if the |
| 848 // leaveSafePoint method cannot complete without blocking, see | 820 // leaveSafePoint method cannot complete without blocking, see |
| 849 // SafePointBarrier::checkAndPark. | 821 // SafePointBarrier::checkAndPark. |
| 850 class SafePointAwareMutexLocker { | 822 class SafePointAwareMutexLocker { |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 942 // whether the page is part of a terminting thread or | 914 // whether the page is part of a terminting thread or |
| 943 // if the page is traced after being terminated (orphaned). | 915 // if the page is traced after being terminated (orphaned). |
| 944 uintptr_t m_terminating : 1; | 916 uintptr_t m_terminating : 1; |
| 945 uintptr_t m_tracedAfterOrphaned : 1; | 917 uintptr_t m_tracedAfterOrphaned : 1; |
| 946 uintptr_t m_promptlyFreedSize : 17; // == blinkPageSizeLog2 | 918 uintptr_t m_promptlyFreedSize : 17; // == blinkPageSizeLog2 |
| 947 }; | 919 }; |
| 948 | 920 |
| 949 } | 921 } |
| 950 | 922 |
| 951 #endif // ThreadState_h | 923 #endif // ThreadState_h |
| OLD | NEW |