Bug 1233818 part 7 - Fix AutoPreventBackedgePatching to work without a JitRuntime. r=luke

This commit is contained in:
Jan de Mooij 2015-12-23 11:28:54 +01:00
Родитель 3c8687da7f
Коммит 9c3142bc57
6 изменённых файлов: 41 добавлений и 25 удалений

Просмотреть файл

@ -120,8 +120,8 @@ ExecutablePool::available() const
return m_end - m_freePtr;
}
ExecutableAllocator::ExecutableAllocator(JitRuntime* jrt)
: jrt_(jrt)
ExecutableAllocator::ExecutableAllocator(JSRuntime* rt)
: rt_(rt)
{
MOZ_ASSERT(m_smallPools.empty());
}
@ -213,7 +213,7 @@ ExecutableAllocator::roundUpAllocationSize(size_t request, size_t granularity)
ExecutablePool*
ExecutableAllocator::createPool(size_t n)
{
MOZ_ASSERT(jrt_->preventBackedgePatching());
MOZ_ASSERT(rt_->jitRuntime()->preventBackedgePatching());
size_t allocSize = roundUpAllocationSize(n, pageSize);
if (allocSize == OVERSIZE_ALLOCATION)
@ -245,7 +245,7 @@ void*
ExecutableAllocator::alloc(size_t n, ExecutablePool** poolp, CodeKind type)
{
// Don't race with reprotectAll called from the signal handler.
JitRuntime::AutoPreventBackedgePatching apbp(jrt_);
JitRuntime::AutoPreventBackedgePatching apbp(rt_);
// Caller must ensure 'n' is word-size aligned. If all allocations are
// of word sized quantities, then all subsequent allocations will be
@ -272,7 +272,7 @@ void
ExecutableAllocator::releasePoolPages(ExecutablePool* pool)
{
// Don't race with reprotectAll called from the signal handler.
JitRuntime::AutoPreventBackedgePatching apbp(jrt_);
JitRuntime::AutoPreventBackedgePatching apbp(rt_);
MOZ_ASSERT(pool->m_allocation.pages);
systemRelease(pool->m_allocation);
@ -288,7 +288,7 @@ void
ExecutableAllocator::purge()
{
// Don't race with reprotectAll called from the signal handler.
JitRuntime::AutoPreventBackedgePatching apbp(jrt_);
JitRuntime::AutoPreventBackedgePatching apbp(rt_);
for (size_t i = 0; i < m_smallPools.length(); i++)
m_smallPools[i]->release();

Просмотреть файл

@ -134,12 +134,12 @@ class ExecutableAllocator
#ifdef XP_WIN
mozilla::Maybe<mozilla::non_crypto::XorShift128PlusRNG> randomNumberGenerator;
#endif
JitRuntime* jrt_;
JSRuntime* rt_;
public:
enum ProtectionSetting { Writable, Executable };
explicit ExecutableAllocator(JitRuntime* jrt);
explicit ExecutableAllocator(JSRuntime* rt);
~ExecutableAllocator();
void purge();

Просмотреть файл

@ -165,9 +165,9 @@ jit::InitializeIon()
return true;
}
JitRuntime::JitRuntime()
: execAlloc_(this),
backedgeExecAlloc_(this),
JitRuntime::JitRuntime(JSRuntime* rt)
: execAlloc_(rt),
backedgeExecAlloc_(rt),
exceptionTail_(nullptr),
bailoutTail_(nullptr),
profilerExitFrameTail_(nullptr),
@ -1139,7 +1139,7 @@ IonScript::copyPatchableBackedges(JSContext* cx, JitCode* code,
MacroAssembler& masm)
{
JitRuntime* jrt = cx->runtime()->jitRuntime();
JitRuntime::AutoPreventBackedgePatching apbp(jrt);
JitRuntime::AutoPreventBackedgePatching apbp(cx->runtime());
for (size_t i = 0; i < backedgeEntries_; i++) {
PatchableBackedgeInfo& info = backedges[i];
@ -1373,7 +1373,7 @@ IonScript::unlinkFromRuntime(FreeOp* fop)
// make sure that those backedges are unlinked from the runtime and not
// reclobbered with garbage if an interrupt is requested.
JitRuntime* jrt = fop->runtime()->jitRuntime();
JitRuntime::AutoPreventBackedgePatching apbp(jrt);
JitRuntime::AutoPreventBackedgePatching apbp(fop->runtime());
for (size_t i = 0; i < backedgeEntries_; i++)
jrt->removePatchableBackedge(&backedgeList()[i]);

Просмотреть файл

@ -8,6 +8,7 @@
#define jit_JitCompartment_h
#include "mozilla/Array.h"
#include "mozilla/DebugOnly.h"
#include "mozilla/MemoryReporting.h"
#include "jsweakcache.h"
@ -194,7 +195,7 @@ class JitRuntime
JitCode* generateVMWrapper(JSContext* cx, const VMFunction& f);
public:
JitRuntime();
explicit JitRuntime(JSRuntime* rt);
~JitRuntime();
bool initialize(JSContext* cx);
@ -215,17 +216,32 @@ class JitRuntime
class AutoPreventBackedgePatching
{
mozilla::DebugOnly<JSRuntime*> rt_;
JitRuntime* jrt_;
bool prev_;
public:
explicit AutoPreventBackedgePatching(JitRuntime* jrt) : jrt_(jrt) {
prev_ = jrt->preventBackedgePatching_;
jrt->preventBackedgePatching_ = true;
// This two-arg constructor is provided for JSRuntime::createJitRuntime,
// where we have a JitRuntime but didn't set rt->jitRuntime_ yet.
AutoPreventBackedgePatching(JSRuntime* rt, JitRuntime* jrt)
: rt_(rt), jrt_(jrt)
{
MOZ_ASSERT(CurrentThreadCanAccessRuntime(rt));
if (jrt_) {
prev_ = jrt_->preventBackedgePatching_;
jrt_->preventBackedgePatching_ = true;
}
}
explicit AutoPreventBackedgePatching(JSRuntime* rt)
: AutoPreventBackedgePatching(rt, rt->jitRuntime())
{}
~AutoPreventBackedgePatching() {
MOZ_ASSERT(jrt_ == rt_->jitRuntime());
if (jrt_) {
MOZ_ASSERT(jrt_->preventBackedgePatching_);
jrt_->preventBackedgePatching_ = prev_;
}
}
};
bool preventBackedgePatching() const {
@ -515,7 +531,7 @@ class MOZ_STACK_CLASS AutoWritableJitCode
public:
AutoWritableJitCode(JSRuntime* rt, void* addr, size_t size)
: preventPatching_(rt->jitRuntime()), rt_(rt), addr_(addr), size_(size)
: preventPatching_(rt), rt_(rt), addr_(addr), size_(size)
{
rt_->toggleAutoWritableJitCodeActive(true);
ExecutableAllocator::makeWritable(addr_, size_);

Просмотреть файл

@ -479,9 +479,9 @@ InterruptCheck(JSContext* cx)
gc::MaybeVerifyBarriers(cx);
{
JitRuntime* jrt = cx->runtime()->jitRuntime();
JitRuntime::AutoPreventBackedgePatching apbp(jrt);
jrt->patchIonBackedges(cx->runtime(), JitRuntime::BackedgeLoopHeader);
JSRuntime* rt = cx->runtime();
JitRuntime::AutoPreventBackedgePatching apbp(rt);
rt->jitRuntime()->patchIonBackedges(rt, JitRuntime::BackedgeLoopHeader);
}
return CheckForInterrupt(cx);

Просмотреть файл

@ -158,14 +158,14 @@ JSRuntime::createJitRuntime(JSContext* cx)
MOZ_ASSERT(!jitRuntime_);
jit::JitRuntime* jrt = cx->new_<jit::JitRuntime>();
jit::JitRuntime* jrt = cx->new_<jit::JitRuntime>(cx->runtime());
if (!jrt)
return nullptr;
// Protect jitRuntime_ from being observed (by InterruptRunningJitCode)
// while it is being initialized. Unfortunately, initialization depends on
// jitRuntime_ being non-null, so we can't just wait to assign jitRuntime_.
JitRuntime::AutoPreventBackedgePatching apbp(jrt);
JitRuntime::AutoPreventBackedgePatching apbp(cx->runtime(), jrt);
jitRuntime_ = jrt;
if (!jitRuntime_->initialize(cx)) {