Skip to content

Commit

Permalink
Bug 929236 - Cache asm.js compiled code in Gecko (r=janv)
Browse files Browse the repository at this point in the history
--HG--
extra : rebase_source : 1c97962da0044858c583fc45e69dd22e519b8066
  • Loading branch information
Luke Wagner committed Nov 18, 2013
1 parent 1c6f4ab commit 5ed834b
Show file tree
Hide file tree
Showing 21 changed files with 1,567 additions and 12 deletions.
1,269 changes: 1,269 additions & 0 deletions dom/asmjscache/AsmJSCache.cpp

Large diffs are not rendered by default.

86 changes: 86 additions & 0 deletions dom/asmjscache/AsmJSCache.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/* 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"

class nsIPrincipal;

namespace mozilla {
namespace dom {

namespace quota {
class Client;
}

namespace asmjscache {

class PAsmJSCacheEntryChild;
class PAsmJSCacheEntryParent;

enum OpenMode
{
eOpenForRead,
eOpenForWrite,
NUM_OPEN_MODES
};

// Implementation of AsmJSCacheOps, installed by nsJSEnvironment:

bool
OpenEntryForRead(JS::Handle<JSObject*> aGlobal, size_t* aSize,
const uint8_t** aMemory, intptr_t *aHandle);
void
CloseEntryForRead(JS::Handle<JSObject*> aGlobal, size_t aSize,
const uint8_t* aMemory, intptr_t aHandle);
bool
OpenEntryForWrite(JS::Handle<JSObject*> aGlobal, size_t aSize,
uint8_t** aMemory, intptr_t* aHandle);
void
CloseEntryForWrite(JS::Handle<JSObject*> aGlobal, size_t aSize,
uint8_t* aMemory, intptr_t aHandle);
bool
GetBuildId(js::Vector<char>* aBuildId);

// Called from QuotaManager.cpp:

quota::Client*
CreateClient();

// Called from ipc/ContentParent.cpp:

PAsmJSCacheEntryParent*
AllocEntryParent(OpenMode aOpenMode, uint32_t aSizeToWrite,
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> :
public EnumSerializer<mozilla::dom::asmjscache::OpenMode,
mozilla::dom::asmjscache::eOpenForRead,
mozilla::dom::asmjscache::NUM_OPEN_MODES>
{ };

} // namespace IPC

#endif // mozilla_dom_asmjscache_asmjscache_h
24 changes: 24 additions & 0 deletions dom/asmjscache/PAsmJSCacheEntry.ipdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* 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/. */

include protocol PContent;

namespace mozilla {
namespace dom {
namespace asmjscache {

protocol PAsmJSCacheEntry
{
manager PContent;

child:
OnOpen(int64_t fileSize, FileDescriptor fileDesc);

both:
__delete__();
};

} // namespace asmjscache
} // namespace dom
} // namespace mozilla
25 changes: 25 additions & 0 deletions dom/asmjscache/moz.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# 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/.

EXPORTS.mozilla.dom.asmjscache += [
'AsmJSCache.h'
]

SOURCES += [
'AsmJSCache.cpp'
]

IPDL_SOURCES += [
'PAsmJSCacheEntry.ipdl'
]

FAIL_ON_WARNINGS = True

MSVC_ENABLE_PGO = True

include('/ipc/chromium/chromium-config.mozbuild')

FINAL_LIBRARY = 'gklayout'
11 changes: 11 additions & 0 deletions dom/base/nsJSEnvironment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
#include "mozilla/Telemetry.h"
#include "mozilla/dom/BindingUtils.h"
#include "mozilla/Attributes.h"
#include "mozilla/dom/asmjscache/AsmJSCache.h"
#include "mozilla/dom/CanvasRenderingContext2DBinding.h"
#include "mozilla/CycleCollectedJSRuntime.h"
#include "mozilla/ContentEvents.h"
Expand Down Expand Up @@ -2878,6 +2879,16 @@ nsJSContext::EnsureStatics()
};
SetDOMCallbacks(sRuntime, &DOMcallbacks);

// Set up the asm.js cache callbacks
static JS::AsmJSCacheOps asmJSCacheOps = {
asmjscache::OpenEntryForRead,
asmjscache::CloseEntryForRead,
asmjscache::OpenEntryForWrite,
asmjscache::CloseEntryForWrite,
asmjscache::GetBuildId
};
JS::SetAsmJSCacheOps(sRuntime, &asmJSCacheOps);

// Set these global xpconnect options...
Preferences::RegisterCallbackAndCall(ReportAllJSExceptionsPrefChangedCallback,
"dom.report_all_js_exceptions");
Expand Down
1 change: 0 additions & 1 deletion dom/indexedDB/Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

#include "mozilla/dom/quota/Client.h"

#define IDB_DIRECTORY_NAME "idb"
#define JOURNAL_DIRECTORY_NAME "journals"

BEGIN_INDEXEDDB_NAMESPACE
Expand Down
4 changes: 2 additions & 2 deletions dom/indexedDB/IDBFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,8 +648,8 @@ IDBFactory::OpenInternal(const nsAString& aName,
}
else if (aDeleting) {
nsCString databaseId;
QuotaManager::GetStorageId(aPersistenceType, aASCIIOrigin, aName,
databaseId);
QuotaManager::GetStorageId(aPersistenceType, aASCIIOrigin, Client::IDB,
aName, databaseId);
MOZ_ASSERT(!databaseId.IsEmpty());

IndexedDBDeleteDatabaseRequestChild* actor =
Expand Down
4 changes: 2 additions & 2 deletions dom/indexedDB/OpenDatabaseHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1717,8 +1717,8 @@ NS_IMPL_ISUPPORTS1(OpenDatabaseHelper, nsIRunnable)
nsresult
OpenDatabaseHelper::Init()
{
QuotaManager::GetStorageId(mPersistenceType, mASCIIOrigin, mName,
mDatabaseId);
QuotaManager::GetStorageId(mPersistenceType, mASCIIOrigin, Client::IDB,
mName, mDatabaseId);
MOZ_ASSERT(!mDatabaseId.IsEmpty());

return NS_OK;
Expand Down
6 changes: 4 additions & 2 deletions dom/indexedDB/ipc/IndexedDBChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "mozilla/Assertions.h"
#include "mozilla/dom/ContentChild.h"
#include "mozilla/dom/quota/Client.h"
#include "mozilla/dom/quota/QuotaManager.h"

#include "AsyncConnectionHelper.h"
Expand All @@ -23,6 +24,7 @@
USING_INDEXEDDB_NAMESPACE

using namespace mozilla::dom;
using mozilla::dom::quota::Client;
using mozilla::dom::quota::QuotaManager;

namespace {
Expand Down Expand Up @@ -288,8 +290,8 @@ IndexedDBDatabaseChild::EnsureDatabase(
databaseId = mDatabase->Id();
}
else {
QuotaManager::GetStorageId(aDBInfo.persistenceType,
aDBInfo.origin, aDBInfo.name, databaseId);
QuotaManager::GetStorageId(aDBInfo.persistenceType, aDBInfo.origin,
Client::IDB, aDBInfo.name, databaseId);
}
MOZ_ASSERT(!databaseId.IsEmpty());

Expand Down
18 changes: 18 additions & 0 deletions dom/ipc/ContentChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include "TabChild.h"

#include "mozilla/Attributes.h"
#include "mozilla/dom/asmjscache/AsmJSCache.h"
#include "mozilla/dom/asmjscache/PAsmJSCacheEntryChild.h"
#include "mozilla/dom/ExternalHelperAppChild.h"
#include "mozilla/dom/PCrashReporterChild.h"
#include "mozilla/dom/DOMStorageIPC.h"
Expand Down Expand Up @@ -867,6 +869,22 @@ ContentChild::DeallocPIndexedDBChild(PIndexedDBChild* aActor)
return true;
}

asmjscache::PAsmJSCacheEntryChild*
ContentChild::AllocPAsmJSCacheEntryChild(const asmjscache::OpenMode& aOpenMode,
const int64_t& aSizeToWrite,
const IPC::Principal& aPrincipal)
{
NS_NOTREACHED("Should never get here!");
return nullptr;
}

bool
ContentChild::DeallocPAsmJSCacheEntryChild(PAsmJSCacheEntryChild* aActor)
{
asmjscache::DeallocEntryChild(aActor);
return true;
}

PTestShellChild*
ContentChild::AllocPTestShellChild()
{
Expand Down
7 changes: 7 additions & 0 deletions dom/ipc/ContentChild.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,13 @@ class ContentChild : public PContentChild
virtual PFMRadioChild* AllocPFMRadioChild();
virtual bool DeallocPFMRadioChild(PFMRadioChild* aActor);

virtual PAsmJSCacheEntryChild* AllocPAsmJSCacheEntryChild(
const asmjscache::OpenMode& aOpenMode,
const int64_t& aSizeToWrite,
const IPC::Principal& aPrincipal) MOZ_OVERRIDE;
virtual bool DeallocPAsmJSCacheEntryChild(
PAsmJSCacheEntryChild* aActor) MOZ_OVERRIDE;

virtual PSpeechSynthesisChild* AllocPSpeechSynthesisChild();
virtual bool DeallocPSpeechSynthesisChild(PSpeechSynthesisChild* aActor);

Expand Down
17 changes: 17 additions & 0 deletions dom/ipc/ContentParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "IndexedDatabaseManager.h"
#include "mozIApplication.h"
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/dom/asmjscache/AsmJSCache.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/ExternalHelperAppParent.h"
#include "mozilla/dom/PMemoryReportRequestParent.h"
Expand Down Expand Up @@ -2448,6 +2449,22 @@ ContentParent::DeallocPFMRadioParent(PFMRadioParent* aActor)
#endif
}

asmjscache::PAsmJSCacheEntryParent*
ContentParent::AllocPAsmJSCacheEntryParent(
const asmjscache::OpenMode& aOpenMode,
const int64_t& aSizeToWrite,
const IPC::Principal& aPrincipal)
{
return asmjscache::AllocEntryParent(aOpenMode, aSizeToWrite, aPrincipal);
}

bool
ContentParent::DeallocPAsmJSCacheEntryParent(PAsmJSCacheEntryParent* aActor)
{
asmjscache::DeallocEntryParent(aActor);
return true;
}

PSpeechSynthesisParent*
ContentParent::AllocPSpeechSynthesisParent()
{
Expand Down
7 changes: 7 additions & 0 deletions dom/ipc/ContentParent.h
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,13 @@ class ContentParent : public PContentParent
virtual PFMRadioParent* AllocPFMRadioParent();
virtual bool DeallocPFMRadioParent(PFMRadioParent* aActor);

virtual PAsmJSCacheEntryParent* AllocPAsmJSCacheEntryParent(
const asmjscache::OpenMode& aOpenMode,
const int64_t& aSizeToWrite,
const IPC::Principal& aPrincipal) MOZ_OVERRIDE;
virtual bool DeallocPAsmJSCacheEntryParent(
PAsmJSCacheEntryParent* aActor) MOZ_OVERRIDE;

virtual PSpeechSynthesisParent* AllocPSpeechSynthesisParent();
virtual bool DeallocPSpeechSynthesisParent(PSpeechSynthesisParent* aActor);
virtual bool RecvPSpeechSynthesisConstructor(PSpeechSynthesisParent* aActor);
Expand Down
6 changes: 6 additions & 0 deletions dom/ipc/PContent.ipdl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* 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/. */

include protocol PAsmJSCacheEntry;
include protocol PBlob;
include protocol PBluetooth;
include protocol PBrowser;
Expand Down Expand Up @@ -40,6 +41,7 @@ using struct IPC::Permission from "mozilla/net/NeckoMessageUtils.h";
using class IPC::Principal from "mozilla/dom/PermissionMessageUtils.h";
using struct mozilla::null_t from "ipc/IPCMessageUtils.h";
using struct mozilla::void_t from "ipc/IPCMessageUtils.h";
using mozilla::dom::asmjscache::OpenMode from "mozilla/dom/asmjscache/AsmJSCache.h";
using mozilla::dom::AudioChannelType from "AudioChannelCommon.h";
using mozilla::dom::AudioChannelState from "AudioChannelCommon.h";
using mozilla::dom::NativeThreadId from "mozilla/dom/TabMessageUtils.h";
Expand Down Expand Up @@ -175,6 +177,7 @@ intr protocol PContent
parent opens PCompositor;
parent opens PImageBridge;

manages PAsmJSCacheEntry;
manages PBlob;
manages PBluetooth;
manages PBrowser;
Expand Down Expand Up @@ -357,6 +360,9 @@ parent:

PFMRadio();

PAsmJSCacheEntry(OpenMode openMode, int64_t sizeToWrite,
Principal principal);

// Services remoting

async StartVisitedQuery(URIParams uri);
Expand Down
1 change: 1 addition & 0 deletions dom/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ PARALLEL_DIRS += [
'encoding',
'file',
'fmradio',
'asmjscache',
'media',
'messages',
'power',
Expand Down
15 changes: 13 additions & 2 deletions dom/quota/Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
class nsIOfflineStorage;
class nsIRunnable;

#define IDB_DIRECTORY_NAME "idb"
#define ASMJSCACHE_DIRECTORY_NAME "asmjs"

BEGIN_QUOTA_NAMESPACE

class OriginOrPatternString;
Expand All @@ -35,6 +38,7 @@ class Client
IDB = 0,
//LS,
//APPCACHE,
ASMJS,
TYPE_MAX
};

Expand All @@ -46,7 +50,11 @@ class Client
{
switch (aType) {
case IDB:
aText.AssignLiteral("idb");
aText.AssignLiteral(IDB_DIRECTORY_NAME);
break;

case ASMJS:
aText.AssignLiteral(ASMJSCACHE_DIRECTORY_NAME);
break;

case TYPE_MAX:
Expand All @@ -61,9 +69,12 @@ class Client
static nsresult
TypeFromText(const nsAString& aText, Type& aType)
{
if (aText.EqualsLiteral("idb")) {
if (aText.EqualsLiteral(IDB_DIRECTORY_NAME)) {
aType = IDB;
}
else if (aText.EqualsLiteral(ASMJSCACHE_DIRECTORY_NAME)) {
aType = ASMJS;
}
else {
return NS_ERROR_FAILURE;
}
Expand Down
Loading

0 comments on commit 5ed834b

Please sign in to comment.