1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=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 file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_asmjscache_asmjscache_h
8 #define mozilla_dom_asmjscache_asmjscache_h
10 #include "ipc/IPCMessageUtils.h"
11 #include "js/TypeDecls.h"
12 #include "js/Vector.h"
24 namespace asmjscache
{
26 class PAsmJSCacheEntryChild
;
27 class PAsmJSCacheEntryParent
;
36 // Each origin stores a fixed size (kNumEntries) LRU cache of compiled asm.js
37 // modules. Each compiled asm.js module is stored in a separate file with one
38 // extra metadata file that stores the LRU cache and enough information for a
39 // client to pick which cached module's file to open.
42 static const unsigned kNumEntries
= 16;
43 static const unsigned kLastEntry
= kNumEntries
- 1;
50 unsigned mModuleIndex
;
59 Entry mEntries
[kNumEntries
];
62 // Parameters specific to opening a cache entry for writing
80 // Parameters specific to opening a cache entry for reading
83 const char16_t
* mBegin
;
84 const char16_t
* mLimit
;
92 // Implementation of AsmJSCacheOps, installed for the main JSRuntime by
93 // nsJSEnvironment.cpp and DOM Worker JSRuntimes in RuntimeService.cpp.
95 // The Open* functions cannot be called directly from AsmJSCacheOps: they take
96 // an nsIPrincipal as the first argument instead of a Handle<JSObject*>. The
97 // caller must map the object to an nsIPrincipal.
99 // These methods may be called off the main thread and guarantee not to
100 // access the given aPrincipal except on the main thread. In exchange, the
101 // caller must ensure the given principal is alive from when OpenEntryForX is
102 // called to when CloseEntryForX returns.
105 OpenEntryForRead(nsIPrincipal
* aPrincipal
,
106 const char16_t
* aBegin
,
107 const char16_t
* aLimit
,
109 const uint8_t** aMemory
,
112 CloseEntryForRead(size_t aSize
,
113 const uint8_t* aMemory
,
116 OpenEntryForWrite(nsIPrincipal
* aPrincipal
,
118 const char16_t
* aBegin
,
119 const char16_t
* aEnd
,
124 CloseEntryForWrite(size_t aSize
,
129 GetBuildId(JS::BuildIdCharVector
* aBuildId
);
131 // Called from QuotaManager.cpp:
136 // Called from ipc/ContentParent.cpp:
138 PAsmJSCacheEntryParent
*
139 AllocEntryParent(OpenMode aOpenMode
, WriteParams aWriteParams
,
140 nsIPrincipal
* aPrincipal
);
143 DeallocEntryParent(PAsmJSCacheEntryParent
* aActor
);
145 // Called from ipc/ContentChild.cpp:
148 DeallocEntryChild(PAsmJSCacheEntryChild
* aActor
);
150 } // namespace asmjscache
152 } // namespace mozilla
157 struct ParamTraits
<mozilla::dom::asmjscache::OpenMode
> :
158 public ContiguousEnumSerializer
<mozilla::dom::asmjscache::OpenMode
,
159 mozilla::dom::asmjscache::eOpenForRead
,
160 mozilla::dom::asmjscache::NUM_OPEN_MODES
>
164 struct ParamTraits
<mozilla::dom::asmjscache::Metadata
>
166 typedef mozilla::dom::asmjscache::Metadata paramType
;
167 static void Write(Message
* aMsg
, const paramType
& aParam
);
168 static bool Read(const Message
* aMsg
, void** aIter
, paramType
* aResult
);
169 static void Log(const paramType
& aParam
, std::wstring
* aLog
);
173 struct ParamTraits
<mozilla::dom::asmjscache::WriteParams
>
175 typedef mozilla::dom::asmjscache::WriteParams paramType
;
176 static void Write(Message
* aMsg
, const paramType
& aParam
);
177 static bool Read(const Message
* aMsg
, void** aIter
, paramType
* aResult
);
178 static void Log(const paramType
& aParam
, std::wstring
* aLog
);
182 struct ParamTraits
<JS::AsmJSCacheResult
> :
183 public ContiguousEnumSerializer
<JS::AsmJSCacheResult
,
185 JS::AsmJSCache_LIMIT
>
190 #endif // mozilla_dom_asmjscache_asmjscache_h