Bug 1677426 - Part 4: Include WasmJS.h from Scope.h. r=nbp

Added Scope.h -> WasmJS.h, WasmJS.h -> JSFunction.h dependencies,
and removed WasmJS.h -> Scope.h dependency.

Differential Revision: https://phabricator.services.mozilla.com/D97661
This commit is contained in:
Tooru Fujisawa 2020-12-08 02:04:47 +00:00
Родитель 3882f3a5d2
Коммит 1ae947da06
8 изменённых файлов: 119 добавлений и 47 удалений

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

@ -136,6 +136,14 @@ void JitcodeGlobalEntry::IonEntry::destroy() {
scriptList_ = nullptr;
}
void JitcodeGlobalEntry::BaselineEntry::trackIonAbort(jsbytecode* pc,
const char* message) {
MOZ_ASSERT(script_->containsPC(pc));
MOZ_ASSERT(message);
ionAbortPc_ = pc;
ionAbortMessage_ = message;
}
void* JitcodeGlobalEntry::BaselineEntry::canonicalNativeAddrFor(
void* ptr) const {
// TODO: We can't yet normalize Baseline addresses until we unify

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

@ -7,12 +7,31 @@
#ifndef jit_JitcodeMap_h
#define jit_JitcodeMap_h
#include "jit/CompactBuffer.h"
#include "jit/ExecutableAllocator.h"
#include "jit/shared/Assembler-shared.h"
#include "vm/BytecodeLocation.h" // for BytecodeLocation
#include "mozilla/Assertions.h" // MOZ_ASSERT, MOZ_ASSERT_IF, MOZ_CRASH
#include <stddef.h> // size_t
#include <stdint.h> // uint8_t, uint32_t, uint64_t
#include "jit/CompactBuffer.h" // CompactBufferReader, CompactBufferWriter
#include "jit/shared/Assembler-shared.h" // CodeOffset
#include "js/AllocPolicy.h" // SystemAllocPolicy
#include "js/TypeDecls.h" // jsbytecode
#include "js/Vector.h" // Vector
#include "vm/BytecodeLocation.h" // BytecodeLocation
class JSScript;
class JSTracer;
struct JSRuntime;
class JSScript;
namespace JS {
class Zone;
} // namespace JS
namespace js {
class GCMarker;
namespace jit {
class InlineScriptTree;
@ -309,12 +328,7 @@ class JitcodeGlobalEntry {
const char* str() const { return str_; }
void trackIonAbort(jsbytecode* pc, const char* message) {
MOZ_ASSERT(script_->containsPC(pc));
MOZ_ASSERT(message);
ionAbortPc_ = pc;
ionAbortMessage_ = message;
}
void trackIonAbort(jsbytecode* pc, const char* message);
bool hadIonAbort() const {
MOZ_ASSERT(!ionAbortPc_ || ionAbortMessage_);

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

@ -38,11 +38,15 @@
#ifndef vm_MallocProvider_h
#define vm_MallocProvider_h
#include "mozilla/Attributes.h"
#include "mozilla/Likely.h"
#include "mozilla/Attributes.h" // MOZ_ALWAYS_INLINE
#include "mozilla/Likely.h" // MOZ_LIKELY, MOZ_UNLIKELY
#include "js/UniquePtr.h"
#include "js/Utility.h"
#include <stddef.h> // size_t
#include <stdint.h> // uint8_t
#include "js/AllocPolicy.h" // AllocFunction
#include "js/UniquePtr.h" // UniquePtr
#include "js/Utility.h" // js_malloc, MallocArena, CalculateAllocSize, CalculateAllocSizeWithExtra, JS::FreePolicy
namespace js {

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

@ -36,6 +36,7 @@
#include "vm/ScopeKind.h" // ScopeKind
#include "vm/Shape.h" // Shape
#include "vm/Xdr.h" // XDRResult, XDRState
#include "wasm/WasmJS.h" // WasmInstanceObject
class JSAtom;
class JSFreeOp;
@ -51,7 +52,6 @@ class Zone;
namespace js {
class GenericPrinter;
class WasmInstanceObject; // FIXME: include WasmJS.h
namespace frontend {
struct CompilationAtomCache;

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

@ -1815,11 +1815,28 @@ bool WasmInstanceObject::isNewborn() const {
return getReservedSlot(INSTANCE_SLOT).isUndefined();
}
// WeakScopeMap maps from function index to js::Scope. This maps is weak
// to avoid holding scope objects alive. The scopes are normally created
// during debugging.
//
// This is defined here in order to avoid recursive dependency between
// WasmJS.h and Scope.h.
using WasmFunctionScopeMap =
JS::WeakCache<GCHashMap<uint32_t, WeakHeapPtr<WasmFunctionScope*>,
DefaultHasher<uint32_t>, ZoneAllocPolicy>>;
class WasmInstanceObject::UnspecifiedScopeMap {
public:
WasmFunctionScopeMap& asWasmFunctionScopeMap() {
return *(WasmFunctionScopeMap*)this;
}
};
/* static */
void WasmInstanceObject::finalize(JSFreeOp* fop, JSObject* obj) {
WasmInstanceObject& instance = obj->as<WasmInstanceObject>();
fop->delete_(obj, &instance.exports(), MemoryUse::WasmInstanceExports);
fop->delete_(obj, &instance.scopes(), MemoryUse::WasmInstanceScopes);
fop->delete_(obj, &instance.scopes().asWasmFunctionScopeMap(),
MemoryUse::WasmInstanceScopes);
fop->delete_(obj, &instance.indirectGlobals(),
MemoryUse::WasmInstanceGlobals);
if (!instance.isNewborn()) {
@ -1856,7 +1873,8 @@ WasmInstanceObject* WasmInstanceObject::create(
return nullptr;
}
UniquePtr<ScopeMap> scopes = js::MakeUnique<ScopeMap>(cx->zone(), cx->zone());
UniquePtr<WasmFunctionScopeMap> scopes =
js::MakeUnique<WasmFunctionScopeMap>(cx->zone(), cx->zone());
if (!scopes) {
ReportOutOfMemory(cx);
return nullptr;
@ -2019,8 +2037,8 @@ WasmInstanceObject::ExportMap& WasmInstanceObject::exports() const {
return *(ExportMap*)getReservedSlot(EXPORTS_SLOT).toPrivate();
}
WasmInstanceObject::ScopeMap& WasmInstanceObject::scopes() const {
return *(ScopeMap*)getReservedSlot(SCOPES_SLOT).toPrivate();
WasmInstanceObject::UnspecifiedScopeMap& WasmInstanceObject::scopes() const {
return *(UnspecifiedScopeMap*)(getReservedSlot(SCOPES_SLOT).toPrivate());
}
WasmInstanceObject::GlobalObjectVector& WasmInstanceObject::indirectGlobals()
@ -2142,7 +2160,8 @@ WasmInstanceScope* WasmInstanceObject::getScope(
/* static */
WasmFunctionScope* WasmInstanceObject::getFunctionScope(
JSContext* cx, HandleWasmInstanceObject instanceObj, uint32_t funcIndex) {
if (ScopeMap::Ptr p = instanceObj->scopes().lookup(funcIndex)) {
if (auto p =
instanceObj->scopes().asWasmFunctionScopeMap().lookup(funcIndex)) {
return p->value();
}
@ -2158,7 +2177,8 @@ WasmFunctionScope* WasmInstanceObject::getFunctionScope(
return nullptr;
}
if (!instanceObj->scopes().putNew(funcIndex, funcScope)) {
if (!instanceObj->scopes().asWasmFunctionScopeMap().putNew(funcIndex,
funcScope)) {
ReportOutOfMemory(cx);
return nullptr;
}

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

@ -19,10 +19,36 @@
#ifndef wasm_js_h
#define wasm_js_h
#include "gc/Policy.h"
#include "gc/ZoneAllocator.h"
#include "vm/NativeObject.h"
#include "wasm/WasmTypes.h"
#include "mozilla/Attributes.h" // MOZ_MUST_USE
#include "mozilla/HashTable.h" // DefaultHasher
#include "mozilla/Maybe.h" // mozilla::Maybe
#include <stdint.h> // int32_t, int64_t, uint32_t
#include "gc/Barrier.h" // HeapPtr
#include "gc/ZoneAllocator.h" // ZoneAllocPolicy
#include "js/AllocPolicy.h" // SystemAllocPolicy
#include "js/Class.h" // JSClassOps, ClassSpec
#include "js/GCHashTable.h" // GCHashMap, GCHashSet
#include "js/GCVector.h" // GCVector
#include "js/PropertySpec.h" // JSPropertySpec, JSFunctionSpec
#include "js/RootingAPI.h" // MovableCellHasher
#include "js/SweepingAPI.h" // JS::WeakCache
#include "js/TypeDecls.h" // HandleValue, HandleObject, MutableHandleObject, MutableHandleFunction
#include "js/Vector.h" // JS::Vector
#include "vm/JSFunction.h" // JSFunction
#include "vm/NativeObject.h" // NativeObject
#include "wasm/WasmTypes.h" // MutableHandleWasmInstanceObject, wasm::*
class JSFreeOp;
class JSObject;
class JSTracer;
struct JSContext;
namespace JS {
class CallArgs;
class Value;
} // namespace JS
namespace js {
@ -39,6 +65,8 @@ class SharedArrayRawBuffer;
namespace wasm {
struct ImportValues;
// Return whether WebAssembly can in principle be compiled on this platform (ie
// combination of hardware and OS), assuming at least one of the compilers that
// supports the platform is not disabled by other settings.
@ -322,13 +350,9 @@ class WasmInstanceObject : public NativeObject {
DefaultHasher<uint32_t>, ZoneAllocPolicy>;
ExportMap& exports() const;
// WeakScopeMap maps from function index to js::Scope. This maps is weak
// to avoid holding scope objects alive. The scopes are normally created
// during debugging.
using ScopeMap =
JS::WeakCache<GCHashMap<uint32_t, WeakHeapPtr<WasmFunctionScope*>,
DefaultHasher<uint32_t>, ZoneAllocPolicy>>;
ScopeMap& scopes() const;
// See the definition inside WasmJS.cpp.
class UnspecifiedScopeMap;
UnspecifiedScopeMap& scopes() const;
public:
static const unsigned RESERVED_SLOTS = 6;

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

@ -152,6 +152,22 @@ Value wasm::UnboxAnyRef(AnyRef val) {
return result;
}
/* static */
wasm::FuncRef wasm::FuncRef::fromAnyRefUnchecked(AnyRef p) {
#ifdef DEBUG
Value v = UnboxAnyRef(p);
if (v.isNull()) {
return FuncRef(nullptr);
}
if (v.toObject().is<JSFunction>()) {
return FuncRef(&v.toObject().as<JSFunction>());
}
MOZ_CRASH("Bad value");
#else
return FuncRef(&p.asJSObject()->as<JSFunction>());
#endif
}
Value wasm::UnboxFuncRef(FuncRef val) {
JSFunction* fn = val.asJSFunction();
Value result;

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

@ -39,7 +39,6 @@
#include "js/UniquePtr.h"
#include "js/Utility.h"
#include "js/Vector.h"
#include "vm/JSFunction.h"
#include "vm/MallocProvider.h"
#include "vm/NativeObject.h"
#include "wasm/WasmConstants.h"
@ -934,20 +933,7 @@ class FuncRef {
// Given an AnyRef that represents a possibly-null funcref, turn it into a
// FuncRef.
static FuncRef fromAnyRefUnchecked(AnyRef p) {
#ifdef DEBUG
Value v = UnboxAnyRef(p);
if (v.isNull()) {
return FuncRef(nullptr);
}
if (v.toObject().is<JSFunction>()) {
return FuncRef(&v.toObject().as<JSFunction>());
}
MOZ_CRASH("Bad value");
#else
return FuncRef(&p.asJSObject()->as<JSFunction>());
#endif
}
static FuncRef fromAnyRefUnchecked(AnyRef p);
AnyRef asAnyRef() { return AnyRef::fromJSObject((JSObject*)value_); }