forked from mirrors/gecko-dev
		
	Bug 1485615 - Move internal ZoneAllocPolicy to gc/Zone.h r=sfink
This commit is contained in:
		
							parent
							
								
									4da01fd496
								
							
						
					
					
						commit
						c52bf800a4
					
				
					 5 changed files with 42 additions and 70 deletions
				
			
		|  | @ -128,40 +128,6 @@ class TempAllocPolicy : public AllocPolicyBase | ||||||
|     } |     } | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| /*
 |  | ||||||
|  * Allocation policy that uses Zone::pod_malloc and friends, so that memory |  | ||||||
|  * pressure is accounted for on the zone. This is suitable for memory associated |  | ||||||
|  * with GC things allocated in the zone. |  | ||||||
|  * |  | ||||||
|  * Since it doesn't hold a JSContext (those may not live long enough), it can't |  | ||||||
|  * report out-of-memory conditions itself; the caller must check for OOM and |  | ||||||
|  * take the appropriate action. |  | ||||||
|  * |  | ||||||
|  * FIXME bug 647103 - replace these *AllocPolicy names. |  | ||||||
|  */ |  | ||||||
| class ZoneAllocPolicy |  | ||||||
| { |  | ||||||
|     JS::Zone* const zone; |  | ||||||
| 
 |  | ||||||
|   public: |  | ||||||
|     MOZ_IMPLICIT ZoneAllocPolicy(JS::Zone* z) : zone(z) {} |  | ||||||
| 
 |  | ||||||
|     // These methods are defined in gc/Zone.h.
 |  | ||||||
|     template <typename T> inline T* maybe_pod_malloc(size_t numElems); |  | ||||||
|     template <typename T> inline T* maybe_pod_calloc(size_t numElems); |  | ||||||
|     template <typename T> inline T* maybe_pod_realloc(T* p, size_t oldSize, size_t newSize); |  | ||||||
|     template <typename T> inline T* pod_malloc(size_t numElems); |  | ||||||
|     template <typename T> inline T* pod_calloc(size_t numElems); |  | ||||||
|     template <typename T> inline T* pod_realloc(T* p, size_t oldSize, size_t newSize); |  | ||||||
| 
 |  | ||||||
|     template <typename T> void free_(T* p, size_t numElems = 0) { js_free(p); } |  | ||||||
|     void reportAllocOverflow() const {} |  | ||||||
| 
 |  | ||||||
|     MOZ_MUST_USE bool checkSimulatedOOM() const { |  | ||||||
|         return !js::oom::ShouldFailWithOOM(); |  | ||||||
|     } |  | ||||||
| }; |  | ||||||
| 
 |  | ||||||
| } /* namespace js */ | } /* namespace js */ | ||||||
| 
 | 
 | ||||||
| #endif /* js_AllocPolicy_h */ | #endif /* js_AllocPolicy_h */ | ||||||
|  |  | ||||||
|  | @ -12,6 +12,7 @@ | ||||||
| #include "jsapi.h" | #include "jsapi.h" | ||||||
| 
 | 
 | ||||||
| #include "builtin/SelfHostingDefines.h" | #include "builtin/SelfHostingDefines.h" | ||||||
|  | #include "gc/Zone.h" | ||||||
| #include "js/GCVector.h" | #include "js/GCVector.h" | ||||||
| #include "js/Id.h" | #include "js/Id.h" | ||||||
| #include "js/UniquePtr.h" | #include "js/UniquePtr.h" | ||||||
|  |  | ||||||
|  | @ -11,6 +11,7 @@ | ||||||
| 
 | 
 | ||||||
| #include "gc/Barrier.h" | #include "gc/Barrier.h" | ||||||
| #include "gc/DeletePolicy.h" | #include "gc/DeletePolicy.h" | ||||||
|  | #include "gc/Zone.h" | ||||||
| #include "js/HashTable.h" | #include "js/HashTable.h" | ||||||
| 
 | 
 | ||||||
| namespace JS { | namespace JS { | ||||||
|  |  | ||||||
|  | @ -757,47 +757,50 @@ class Zone : public JS::shadow::Zone, | ||||||
| 
 | 
 | ||||||
| namespace js { | namespace js { | ||||||
| 
 | 
 | ||||||
| template <typename T> | /*
 | ||||||
| inline T* |  * Allocation policy that uses Zone::pod_malloc and friends, so that memory | ||||||
| ZoneAllocPolicy::maybe_pod_malloc(size_t numElems) |  * pressure is accounted for on the zone. This is suitable for memory associated | ||||||
|  |  * with GC things allocated in the zone. | ||||||
|  |  * | ||||||
|  |  * Since it doesn't hold a JSContext (those may not live long enough), it can't | ||||||
|  |  * report out-of-memory conditions itself; the caller must check for OOM and | ||||||
|  |  * take the appropriate action. | ||||||
|  |  * | ||||||
|  |  * FIXME bug 647103 - replace these *AllocPolicy names. | ||||||
|  |  */ | ||||||
|  | class ZoneAllocPolicy | ||||||
| { | { | ||||||
|     return zone->maybe_pod_malloc<T>(numElems); |     JS::Zone* const zone; | ||||||
| } |  | ||||||
| 
 | 
 | ||||||
| template <typename T> |   public: | ||||||
| inline T* |     MOZ_IMPLICIT ZoneAllocPolicy(JS::Zone* z) : zone(z) {} | ||||||
| ZoneAllocPolicy::maybe_pod_calloc(size_t numElems) |  | ||||||
| { |  | ||||||
|     return zone->maybe_pod_calloc<T>(numElems); |  | ||||||
| } |  | ||||||
| 
 | 
 | ||||||
| template <typename T> |     template <typename T> T* maybe_pod_malloc(size_t numElems) { | ||||||
| inline T* |         return zone->maybe_pod_malloc<T>(numElems); | ||||||
| ZoneAllocPolicy::maybe_pod_realloc(T* p, size_t oldSize, size_t newSize) |     } | ||||||
| { |     template <typename T> T* maybe_pod_calloc(size_t numElems) { | ||||||
|     return zone->maybe_pod_realloc<T>(p, oldSize, newSize); |         return zone->maybe_pod_calloc<T>(numElems); | ||||||
| } |     } | ||||||
|  |     template <typename T> T* maybe_pod_realloc(T* p, size_t oldSize, size_t newSize) { | ||||||
|  |         return zone->maybe_pod_realloc<T>(p, oldSize, newSize); | ||||||
|  |     } | ||||||
|  |     template <typename T> T* pod_malloc(size_t numElems) { | ||||||
|  |         return zone->pod_malloc<T>(numElems); | ||||||
|  |     } | ||||||
|  |     template <typename T> T* pod_calloc(size_t numElems) { | ||||||
|  |         return zone->pod_calloc<T>(numElems); | ||||||
|  |     } | ||||||
|  |     template <typename T> T* pod_realloc(T* p, size_t oldSize, size_t newSize) { | ||||||
|  |         return zone->pod_realloc<T>(p, oldSize, newSize); | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
| template <typename T> |     template <typename T> void free_(T* p, size_t numElems = 0) { js_free(p); } | ||||||
| inline T* |     void reportAllocOverflow() const {} | ||||||
| ZoneAllocPolicy::pod_malloc(size_t numElems) |  | ||||||
| { |  | ||||||
|     return zone->pod_malloc<T>(numElems); |  | ||||||
| } |  | ||||||
| 
 | 
 | ||||||
| template <typename T> |     MOZ_MUST_USE bool checkSimulatedOOM() const { | ||||||
| inline T* |         return !js::oom::ShouldFailWithOOM(); | ||||||
| ZoneAllocPolicy::pod_calloc(size_t numElems) |     } | ||||||
| { | }; | ||||||
|     return zone->pod_calloc<T>(numElems); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| template <typename T> |  | ||||||
| inline T* |  | ||||||
| ZoneAllocPolicy::pod_realloc(T* p, size_t oldSize, size_t newSize) |  | ||||||
| { |  | ||||||
|     return zone->pod_realloc<T>(p, oldSize, newSize); |  | ||||||
| } |  | ||||||
| 
 | 
 | ||||||
| } // namespace js
 | } // namespace js
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -19,6 +19,7 @@ | ||||||
| #include "gc/Barrier.h" | #include "gc/Barrier.h" | ||||||
| #include "gc/Heap.h" | #include "gc/Heap.h" | ||||||
| #include "gc/Marking.h" | #include "gc/Marking.h" | ||||||
|  | #include "gc/Zone.h" | ||||||
| #include "js/AllocPolicy.h" | #include "js/AllocPolicy.h" | ||||||
| #include "js/UbiNode.h" | #include "js/UbiNode.h" | ||||||
| #include "js/Vector.h" | #include "js/Vector.h" | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue
	
	 Jon Coppeard
						Jon Coppeard