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 stub
16 // data. There are two kinds of stubs: optimized stubs and fallback stubs (the
17 // latter also includes stubs that can make non-tail calls that can GC).
18 //
19 // Optimized stubs are allocated per-compartment and are always purged when
20 // JIT-code is discarded. Fallback stubs are allocated per BaselineScript and
21 // are only destroyed when the BaselineScript is destroyed.
22 class ICStubSpace {
23  protected:
24   LifoAlloc allocator_;
25 
ICStubSpace(size_t chunkSize)26   explicit ICStubSpace(size_t chunkSize) : allocator_(chunkSize) {}
27 
28  public:
alloc(size_t size)29   inline void* alloc(size_t size) { return allocator_.alloc(size); }
30 
31   JS_DECLARE_NEW_METHODS(allocate, alloc, inline)
32 
33   void freeAllAfterMinorGC(JS::Zone* zone);
34 
35 #ifdef DEBUG
isEmpty()36   bool isEmpty() const { return allocator_.isEmpty(); }
37 #endif
38 
sizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf)39   size_t sizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) const {
40     return allocator_.sizeOfExcludingThis(mallocSizeOf);
41   }
42 };
43 
44 // Space for optimized stubs. Every JitRealm has a single
45 // OptimizedICStubSpace.
46 struct OptimizedICStubSpace : public ICStubSpace {
47   static const size_t STUB_DEFAULT_CHUNK_SIZE = 4096;
48 
49  public:
OptimizedICStubSpaceOptimizedICStubSpace50   OptimizedICStubSpace() : ICStubSpace(STUB_DEFAULT_CHUNK_SIZE) {}
51 };
52 
53 // Space for fallback stubs. Every BaselineScript has a
54 // FallbackICStubSpace.
55 struct FallbackICStubSpace : public ICStubSpace {
56   static const size_t STUB_DEFAULT_CHUNK_SIZE = 4096;
57 
58  public:
FallbackICStubSpaceFallbackICStubSpace59   FallbackICStubSpace() : ICStubSpace(STUB_DEFAULT_CHUNK_SIZE) {}
60 };
61 
62 }  // namespace jit
63 }  // namespace js
64 
65 #endif /* jit_ICStubSpace_h */
66