1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- 2 * vim: set ts=8 sts=2 et sw=2 tw=80: 3 * This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef jit_ICStubSpace_h 8 #define jit_ICStubSpace_h 9 10 #include "ds/LifoAlloc.h" 11 12 namespace js { 13 namespace jit { 14 15 // ICStubSpace is an abstraction for allocation policy and storage for CacheIR 16 // stub data. There are two kinds of Baseline CacheIR stubs: 17 // 18 // (1) CacheIR stubs that can make non-tail calls that can GC. These are 19 // allocated in a LifoAlloc stored in JitScript. 20 // See JitScriptICStubSpace. 21 // 22 // (2) Other CacheIR stubs (aka optimized IC stubs). Allocated in a per-Zone 23 // LifoAlloc and purged when JIT-code is discarded. 24 // See OptimizedICStubSpace. 25 class ICStubSpace { 26 protected: 27 LifoAlloc allocator_; 28 ICStubSpace(size_t chunkSize)29 explicit ICStubSpace(size_t chunkSize) : allocator_(chunkSize) {} 30 31 public: alloc(size_t size)32 inline void* alloc(size_t size) { return allocator_.alloc(size); } 33 34 JS_DECLARE_NEW_METHODS(allocate, alloc, inline) 35 36 void freeAllAfterMinorGC(JS::Zone* zone); 37 38 #ifdef DEBUG isEmpty()39 bool isEmpty() const { return allocator_.isEmpty(); } 40 #endif 41 sizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf)42 size_t sizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) const { 43 return allocator_.sizeOfExcludingThis(mallocSizeOf); 44 } 45 }; 46 47 // Space for optimized stubs. Every JitZone has a single OptimizedICStubSpace. 48 struct OptimizedICStubSpace : public ICStubSpace { 49 static const size_t STUB_DEFAULT_CHUNK_SIZE = 4096; 50 51 public: OptimizedICStubSpaceOptimizedICStubSpace52 OptimizedICStubSpace() : ICStubSpace(STUB_DEFAULT_CHUNK_SIZE) {} 53 }; 54 55 // Space for Can-GC stubs. Every JitScript has a JitScriptICStubSpace. 56 struct JitScriptICStubSpace : public ICStubSpace { 57 static const size_t STUB_DEFAULT_CHUNK_SIZE = 4096; 58 59 public: JitScriptICStubSpaceJitScriptICStubSpace60 JitScriptICStubSpace() : ICStubSpace(STUB_DEFAULT_CHUNK_SIZE) {} 61 }; 62 63 } // namespace jit 64 } // namespace js 65 66 #endif /* jit_ICStubSpace_h */ 67