| 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 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 #ifndef Heap_h | 31 #ifndef Heap_h |
| 32 #define Heap_h | 32 #define Heap_h |
| 33 | 33 |
| 34 #include "heap/HeapExport.h" | 34 #include "heap/HeapExport.h" |
| 35 #include "heap/ThreadState.h" | 35 #include "heap/ThreadState.h" |
| 36 #include "heap/Visitor.h" | 36 #include "heap/Visitor.h" |
| 37 | 37 |
| 38 #include "wtf/Assertions.h" | 38 #include "wtf/Assertions.h" |
| 39 #include "wtf/OwnPtr.h" | 39 #include "wtf/OwnPtr.h" |
| 40 #include "wtf/RefCounted.h" |
| 40 | 41 |
| 41 #include <stdint.h> | 42 #include <stdint.h> |
| 42 | 43 |
| 43 namespace WebCore { | 44 namespace WebCore { |
| 44 | 45 |
| 45 // ASAN integration defintions | 46 // ASAN integration defintions |
| 46 #if COMPILER(CLANG) | 47 #if COMPILER(CLANG) |
| 47 #define USE_ASAN (__has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS
__)) | 48 #define USE_ASAN (__has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS
__)) |
| 48 #else | 49 #else |
| 49 #define USE_ASAN 0 | 50 #define USE_ASAN 0 |
| (...skipping 827 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 877 private: | 878 private: |
| 878 void enter() const | 879 void enter() const |
| 879 { | 880 { |
| 880 if (m_active) | 881 if (m_active) |
| 881 ThreadStateFor<Affinity>::state()->enterNoAllocationScope(); | 882 ThreadStateFor<Affinity>::state()->enterNoAllocationScope(); |
| 882 } | 883 } |
| 883 | 884 |
| 884 bool m_active; | 885 bool m_active; |
| 885 }; | 886 }; |
| 886 | 887 |
| 888 #if !ENABLE(OILPAN) |
| 889 template<typename T> |
| 890 class Dummy { |
| 891 public: |
| 892 Dummy() { } |
| 893 ~Dummy() { } |
| 894 }; |
| 895 #endif |
| 896 |
| 887 // Base class for objects allocated in the Blink garbage-collected | 897 // Base class for objects allocated in the Blink garbage-collected |
| 888 // heap. | 898 // heap. |
| 889 // | 899 // |
| 890 // Defines a 'new' operator that allocates the memory in the | 900 // Defines a 'new' operator that allocates the memory in the |
| 891 // heap. 'delete' should not be called on objects that inherit from | 901 // heap. 'delete' should not be called on objects that inherit from |
| 892 // GarbageCollected. | 902 // GarbageCollected. |
| 893 // | 903 // |
| 894 // Instances of GarbageCollected will *NOT* get finalized. Their | 904 // Instances of GarbageCollected will *NOT* get finalized. Their |
| 895 // destructor will not be called. Therefore, only classes that have | 905 // destructor will not be called. Therefore, only classes that have |
| 896 // trivial destructors with no semantic meaning (including all their | 906 // trivial destructors with no semantic meaning (including all their |
| 897 // subclasses) should inherit from GarbageCollected. If there are | 907 // subclasses) should inherit from GarbageCollected. If there are |
| 898 // non-trival destructors in a given class or any of its subclasses, | 908 // non-trival destructors in a given class or any of its subclasses, |
| 899 // GarbageCollectedFinalized should be used which guarantees that the | 909 // GarbageCollectedFinalized should be used which guarantees that the |
| 900 // destructor is called on an instance when the garbage collector | 910 // destructor is called on an instance when the garbage collector |
| 901 // determines that it is no longer reachable. | 911 // determines that it is no longer reachable. |
| 902 template<typename T> | 912 template<typename T> |
| 903 class GarbageCollected { | 913 class GarbageCollected { |
| 904 WTF_MAKE_NONCOPYABLE(GarbageCollected); | 914 WTF_MAKE_NONCOPYABLE(GarbageCollected); |
| 905 | 915 |
| 906 // For now direct allocation of arrays on the heap is not allowed. | 916 // For now direct allocation of arrays on the heap is not allowed. |
| 907 void* operator new[](size_t size); | 917 void* operator new[](size_t size); |
| 908 void operator delete[](void* p); | 918 void operator delete[](void* p); |
| 909 public: | 919 public: |
| 920 #if ENABLE(OILPAN) |
| 921 typedef GarbageCollected<T> FromRefCounted; |
| 922 #else |
| 923 typedef RefCounted<T> FromRefCounted; |
| 924 #endif |
| 925 |
| 910 void* operator new(size_t size) | 926 void* operator new(size_t size) |
| 911 { | 927 { |
| 912 return Heap::allocate<T>(size); | 928 return Heap::allocate<T>(size); |
| 913 } | 929 } |
| 914 | 930 |
| 915 void operator delete(void* p) | 931 void operator delete(void* p) |
| 916 { | 932 { |
| 917 ASSERT_NOT_REACHED(); | 933 ASSERT_NOT_REACHED(); |
| 918 } | 934 } |
| 919 | 935 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 932 // heap. 'delete' should not be called on objects that inherit from | 948 // heap. 'delete' should not be called on objects that inherit from |
| 933 // GarbageCollected. | 949 // GarbageCollected. |
| 934 // | 950 // |
| 935 // Instances of GarbageCollectedFinalized will have their destructor | 951 // Instances of GarbageCollectedFinalized will have their destructor |
| 936 // called when the garbage collector determines that the object is no | 952 // called when the garbage collector determines that the object is no |
| 937 // longer reachable. | 953 // longer reachable. |
| 938 template<typename T> | 954 template<typename T> |
| 939 class GarbageCollectedFinalized : public GarbageCollected<T> { | 955 class GarbageCollectedFinalized : public GarbageCollected<T> { |
| 940 WTF_MAKE_NONCOPYABLE(GarbageCollectedFinalized); | 956 WTF_MAKE_NONCOPYABLE(GarbageCollectedFinalized); |
| 941 | 957 |
| 958 public: |
| 959 #if ENABLE(OILPAN) |
| 960 typedef GarbageCollectedFinalized<T> FromRefCounted; |
| 961 typedef GarbageCollectedFinalized<T> FromNoBase; |
| 962 #else |
| 963 typedef RefCounted<T> FromRefCounted; |
| 964 typedef Dummy<T> FromNoBase; |
| 965 #endif |
| 966 |
| 942 protected: | 967 protected: |
| 943 // Finalize is called when the object is freed from the heap. By | 968 // Finalize is called when the object is freed from the heap. By |
| 944 // default finalization means calling the destructor on the | 969 // default finalization means calling the destructor on the |
| 945 // object. Finalize can be overridden to support calling the | 970 // object. Finalize can be overridden to support calling the |
| 946 // destructor of a subclass. This is useful for objects without | 971 // destructor of a subclass. This is useful for objects without |
| 947 // vtables that require explicit dispatching. | 972 // vtables that require explicit dispatching. |
| 948 void finalize() | 973 void finalize() |
| 949 { | 974 { |
| 950 static_cast<T*>(this)->~T(); | 975 static_cast<T*>(this)->~T(); |
| 951 } | 976 } |
| (...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1631 // to export. This forces it to export all the methods from ThreadHeap. | 1656 // to export. This forces it to export all the methods from ThreadHeap. |
| 1632 template<> void ThreadHeap<FinalizedHeapObjectHeader>::addPageToHeap(const GCInf
o*); | 1657 template<> void ThreadHeap<FinalizedHeapObjectHeader>::addPageToHeap(const GCInf
o*); |
| 1633 template<> void ThreadHeap<HeapObjectHeader>::addPageToHeap(const GCInfo*); | 1658 template<> void ThreadHeap<HeapObjectHeader>::addPageToHeap(const GCInfo*); |
| 1634 extern template class HEAP_EXPORT ThreadHeap<FinalizedHeapObjectHeader>; | 1659 extern template class HEAP_EXPORT ThreadHeap<FinalizedHeapObjectHeader>; |
| 1635 extern template class HEAP_EXPORT ThreadHeap<HeapObjectHeader>; | 1660 extern template class HEAP_EXPORT ThreadHeap<HeapObjectHeader>; |
| 1636 #endif | 1661 #endif |
| 1637 | 1662 |
| 1638 } | 1663 } |
| 1639 | 1664 |
| 1640 #endif // Heap_h | 1665 #endif // Heap_h |
| OLD | NEW |