2013-11-19 01:49:53 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2015-05-03 22:32:37 +03:00
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2013-11-19 01:49:53 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_asmjscache_asmjscache_h
|
|
|
|
#define mozilla_dom_asmjscache_asmjscache_h
|
|
|
|
|
|
|
|
#include "ipc/IPCMessageUtils.h"
|
|
|
|
#include "js/TypeDecls.h"
|
|
|
|
#include "js/Vector.h"
|
2013-12-05 08:32:52 +04:00
|
|
|
#include "jsapi.h"
|
2013-11-19 01:49:53 +04:00
|
|
|
|
|
|
|
class nsIPrincipal;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
namespace quota {
|
|
|
|
class Client;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace quota
|
2013-11-19 01:49:53 +04:00
|
|
|
|
|
|
|
namespace asmjscache {
|
|
|
|
|
|
|
|
class PAsmJSCacheEntryChild;
|
|
|
|
class PAsmJSCacheEntryParent;
|
|
|
|
|
|
|
|
enum OpenMode
|
|
|
|
{
|
|
|
|
eOpenForRead,
|
|
|
|
eOpenForWrite,
|
|
|
|
NUM_OPEN_MODES
|
|
|
|
};
|
|
|
|
|
2013-12-05 08:32:52 +04:00
|
|
|
// Each origin stores a fixed size (kNumEntries) LRU cache of compiled asm.js
|
|
|
|
// modules. Each compiled asm.js module is stored in a separate file with one
|
|
|
|
// extra metadata file that stores the LRU cache and enough information for a
|
|
|
|
// client to pick which cached module's file to open.
|
|
|
|
struct Metadata
|
|
|
|
{
|
|
|
|
static const unsigned kNumEntries = 16;
|
|
|
|
static const unsigned kLastEntry = kNumEntries - 1;
|
|
|
|
|
|
|
|
struct Entry
|
|
|
|
{
|
|
|
|
uint32_t mFastHash;
|
|
|
|
uint32_t mNumChars;
|
|
|
|
uint32_t mFullHash;
|
2014-02-14 04:25:39 +04:00
|
|
|
unsigned mModuleIndex;
|
|
|
|
|
|
|
|
void clear() {
|
|
|
|
mFastHash = -1;
|
|
|
|
mNumChars = -1;
|
|
|
|
mFullHash = -1;
|
|
|
|
}
|
2013-12-05 08:32:52 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
Entry mEntries[kNumEntries];
|
|
|
|
};
|
|
|
|
|
|
|
|
// Parameters specific to opening a cache entry for writing
|
|
|
|
struct WriteParams
|
|
|
|
{
|
|
|
|
int64_t mSize;
|
|
|
|
int64_t mFastHash;
|
|
|
|
int64_t mNumChars;
|
|
|
|
int64_t mFullHash;
|
2014-03-06 00:47:10 +04:00
|
|
|
bool mInstalled;
|
2013-12-05 08:32:52 +04:00
|
|
|
|
|
|
|
WriteParams()
|
|
|
|
: mSize(0),
|
|
|
|
mFastHash(0),
|
|
|
|
mNumChars(0),
|
2014-03-06 00:47:10 +04:00
|
|
|
mFullHash(0),
|
|
|
|
mInstalled(false)
|
2013-12-05 08:32:52 +04:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
// Parameters specific to opening a cache entry for reading
|
|
|
|
struct ReadParams
|
|
|
|
{
|
2014-07-22 08:43:21 +04:00
|
|
|
const char16_t* mBegin;
|
|
|
|
const char16_t* mLimit;
|
2013-12-05 08:32:52 +04:00
|
|
|
|
|
|
|
ReadParams()
|
|
|
|
: mBegin(nullptr),
|
|
|
|
mLimit(nullptr)
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2013-12-03 23:31:30 +04:00
|
|
|
// Implementation of AsmJSCacheOps, installed for the main JSRuntime by
|
|
|
|
// nsJSEnvironment.cpp and DOM Worker JSRuntimes in RuntimeService.cpp.
|
|
|
|
//
|
|
|
|
// The Open* functions cannot be called directly from AsmJSCacheOps: they take
|
|
|
|
// an nsIPrincipal as the first argument instead of a Handle<JSObject*>. The
|
|
|
|
// caller must map the object to an nsIPrincipal.
|
|
|
|
//
|
|
|
|
// These methods may be called off the main thread and guarantee not to
|
|
|
|
// access the given aPrincipal except on the main thread. In exchange, the
|
|
|
|
// caller must ensure the given principal is alive from when OpenEntryForX is
|
|
|
|
// called to when CloseEntryForX returns.
|
2013-11-19 01:49:53 +04:00
|
|
|
|
|
|
|
bool
|
2013-12-03 23:31:30 +04:00
|
|
|
OpenEntryForRead(nsIPrincipal* aPrincipal,
|
2014-07-22 08:43:21 +04:00
|
|
|
const char16_t* aBegin,
|
|
|
|
const char16_t* aLimit,
|
2013-11-19 02:02:05 +04:00
|
|
|
size_t* aSize,
|
|
|
|
const uint8_t** aMemory,
|
|
|
|
intptr_t *aHandle);
|
2013-11-19 01:49:53 +04:00
|
|
|
void
|
2014-05-06 21:58:00 +04:00
|
|
|
CloseEntryForRead(size_t aSize,
|
2013-11-19 02:02:05 +04:00
|
|
|
const uint8_t* aMemory,
|
|
|
|
intptr_t aHandle);
|
2014-10-23 02:28:07 +04:00
|
|
|
JS::AsmJSCacheResult
|
2013-12-03 23:31:30 +04:00
|
|
|
OpenEntryForWrite(nsIPrincipal* aPrincipal,
|
2014-03-06 00:47:10 +04:00
|
|
|
bool aInstalled,
|
2014-07-22 08:43:21 +04:00
|
|
|
const char16_t* aBegin,
|
|
|
|
const char16_t* aEnd,
|
2013-11-19 02:02:05 +04:00
|
|
|
size_t aSize,
|
|
|
|
uint8_t** aMemory,
|
|
|
|
intptr_t* aHandle);
|
2013-11-19 01:49:53 +04:00
|
|
|
void
|
2014-05-06 21:58:00 +04:00
|
|
|
CloseEntryForWrite(size_t aSize,
|
2013-11-19 02:02:05 +04:00
|
|
|
uint8_t* aMemory,
|
|
|
|
intptr_t aHandle);
|
2013-12-05 08:32:52 +04:00
|
|
|
|
2013-11-19 01:49:53 +04:00
|
|
|
bool
|
2013-12-05 08:32:52 +04:00
|
|
|
GetBuildId(JS::BuildIdCharVector* aBuildId);
|
2013-11-19 01:49:53 +04:00
|
|
|
|
|
|
|
// Called from QuotaManager.cpp:
|
|
|
|
|
|
|
|
quota::Client*
|
|
|
|
CreateClient();
|
|
|
|
|
|
|
|
// Called from ipc/ContentParent.cpp:
|
|
|
|
|
|
|
|
PAsmJSCacheEntryParent*
|
2013-12-05 08:32:52 +04:00
|
|
|
AllocEntryParent(OpenMode aOpenMode, WriteParams aWriteParams,
|
2013-11-19 01:49:53 +04:00
|
|
|
nsIPrincipal* aPrincipal);
|
|
|
|
|
|
|
|
void
|
|
|
|
DeallocEntryParent(PAsmJSCacheEntryParent* aActor);
|
|
|
|
|
|
|
|
// Called from ipc/ContentChild.cpp:
|
|
|
|
|
|
|
|
void
|
|
|
|
DeallocEntryChild(PAsmJSCacheEntryChild* aActor);
|
|
|
|
|
|
|
|
} // namespace asmjscache
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
namespace IPC {
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct ParamTraits<mozilla::dom::asmjscache::OpenMode> :
|
2014-04-14 18:17:40 +04:00
|
|
|
public ContiguousEnumSerializer<mozilla::dom::asmjscache::OpenMode,
|
|
|
|
mozilla::dom::asmjscache::eOpenForRead,
|
|
|
|
mozilla::dom::asmjscache::NUM_OPEN_MODES>
|
2013-11-19 01:49:53 +04:00
|
|
|
{ };
|
|
|
|
|
2013-12-05 08:32:52 +04:00
|
|
|
template <>
|
|
|
|
struct ParamTraits<mozilla::dom::asmjscache::Metadata>
|
|
|
|
{
|
|
|
|
typedef mozilla::dom::asmjscache::Metadata paramType;
|
|
|
|
static void Write(Message* aMsg, const paramType& aParam);
|
|
|
|
static bool Read(const Message* aMsg, void** aIter, paramType* aResult);
|
|
|
|
static void Log(const paramType& aParam, std::wstring* aLog);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct ParamTraits<mozilla::dom::asmjscache::WriteParams>
|
|
|
|
{
|
|
|
|
typedef mozilla::dom::asmjscache::WriteParams paramType;
|
|
|
|
static void Write(Message* aMsg, const paramType& aParam);
|
|
|
|
static bool Read(const Message* aMsg, void** aIter, paramType* aResult);
|
|
|
|
static void Log(const paramType& aParam, std::wstring* aLog);
|
|
|
|
};
|
|
|
|
|
2014-10-23 02:28:07 +04:00
|
|
|
template <>
|
|
|
|
struct ParamTraits<JS::AsmJSCacheResult> :
|
|
|
|
public ContiguousEnumSerializer<JS::AsmJSCacheResult,
|
|
|
|
JS::AsmJSCache_MIN,
|
|
|
|
JS::AsmJSCache_LIMIT>
|
|
|
|
{ };
|
|
|
|
|
2013-11-19 01:49:53 +04:00
|
|
|
} // namespace IPC
|
|
|
|
|
|
|
|
#endif // mozilla_dom_asmjscache_asmjscache_h
|