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; 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* JitcodeGlobalEntry::BaselineEntry::canonicalNativeAddrFor(
void* ptr) const { void* ptr) const {
// TODO: We can't yet normalize Baseline addresses until we unify // TODO: We can't yet normalize Baseline addresses until we unify

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

@ -7,12 +7,31 @@
#ifndef jit_JitcodeMap_h #ifndef jit_JitcodeMap_h
#define jit_JitcodeMap_h #define jit_JitcodeMap_h
#include "jit/CompactBuffer.h" #include "mozilla/Assertions.h" // MOZ_ASSERT, MOZ_ASSERT_IF, MOZ_CRASH
#include "jit/ExecutableAllocator.h"
#include "jit/shared/Assembler-shared.h" #include <stddef.h> // size_t
#include "vm/BytecodeLocation.h" // for BytecodeLocation #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 { namespace js {
class GCMarker;
namespace jit { namespace jit {
class InlineScriptTree; class InlineScriptTree;
@ -309,12 +328,7 @@ class JitcodeGlobalEntry {
const char* str() const { return str_; } const char* str() const { return str_; }
void trackIonAbort(jsbytecode* pc, const char* message) { void trackIonAbort(jsbytecode* pc, const char* message);
MOZ_ASSERT(script_->containsPC(pc));
MOZ_ASSERT(message);
ionAbortPc_ = pc;
ionAbortMessage_ = message;
}
bool hadIonAbort() const { bool hadIonAbort() const {
MOZ_ASSERT(!ionAbortPc_ || ionAbortMessage_); MOZ_ASSERT(!ionAbortPc_ || ionAbortMessage_);

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

@ -38,11 +38,15 @@
#ifndef vm_MallocProvider_h #ifndef vm_MallocProvider_h
#define vm_MallocProvider_h #define vm_MallocProvider_h
#include "mozilla/Attributes.h" #include "mozilla/Attributes.h" // MOZ_ALWAYS_INLINE
#include "mozilla/Likely.h" #include "mozilla/Likely.h" // MOZ_LIKELY, MOZ_UNLIKELY
#include "js/UniquePtr.h" #include <stddef.h> // size_t
#include "js/Utility.h" #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 { namespace js {

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

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

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

@ -1815,11 +1815,28 @@ bool WasmInstanceObject::isNewborn() const {
return getReservedSlot(INSTANCE_SLOT).isUndefined(); 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 */ /* static */
void WasmInstanceObject::finalize(JSFreeOp* fop, JSObject* obj) { void WasmInstanceObject::finalize(JSFreeOp* fop, JSObject* obj) {
WasmInstanceObject& instance = obj->as<WasmInstanceObject>(); WasmInstanceObject& instance = obj->as<WasmInstanceObject>();
fop->delete_(obj, &instance.exports(), MemoryUse::WasmInstanceExports); 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(), fop->delete_(obj, &instance.indirectGlobals(),
MemoryUse::WasmInstanceGlobals); MemoryUse::WasmInstanceGlobals);
if (!instance.isNewborn()) { if (!instance.isNewborn()) {
@ -1856,7 +1873,8 @@ WasmInstanceObject* WasmInstanceObject::create(
return nullptr; return nullptr;
} }
UniquePtr<ScopeMap> scopes = js::MakeUnique<ScopeMap>(cx->zone(), cx->zone()); UniquePtr<WasmFunctionScopeMap> scopes =
js::MakeUnique<WasmFunctionScopeMap>(cx->zone(), cx->zone());
if (!scopes) { if (!scopes) {
ReportOutOfMemory(cx); ReportOutOfMemory(cx);
return nullptr; return nullptr;
@ -2019,8 +2037,8 @@ WasmInstanceObject::ExportMap& WasmInstanceObject::exports() const {
return *(ExportMap*)getReservedSlot(EXPORTS_SLOT).toPrivate(); return *(ExportMap*)getReservedSlot(EXPORTS_SLOT).toPrivate();
} }
WasmInstanceObject::ScopeMap& WasmInstanceObject::scopes() const { WasmInstanceObject::UnspecifiedScopeMap& WasmInstanceObject::scopes() const {
return *(ScopeMap*)getReservedSlot(SCOPES_SLOT).toPrivate(); return *(UnspecifiedScopeMap*)(getReservedSlot(SCOPES_SLOT).toPrivate());
} }
WasmInstanceObject::GlobalObjectVector& WasmInstanceObject::indirectGlobals() WasmInstanceObject::GlobalObjectVector& WasmInstanceObject::indirectGlobals()
@ -2142,7 +2160,8 @@ WasmInstanceScope* WasmInstanceObject::getScope(
/* static */ /* static */
WasmFunctionScope* WasmInstanceObject::getFunctionScope( WasmFunctionScope* WasmInstanceObject::getFunctionScope(
JSContext* cx, HandleWasmInstanceObject instanceObj, uint32_t funcIndex) { 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(); return p->value();
} }
@ -2158,7 +2177,8 @@ WasmFunctionScope* WasmInstanceObject::getFunctionScope(
return nullptr; return nullptr;
} }
if (!instanceObj->scopes().putNew(funcIndex, funcScope)) { if (!instanceObj->scopes().asWasmFunctionScopeMap().putNew(funcIndex,
funcScope)) {
ReportOutOfMemory(cx); ReportOutOfMemory(cx);
return nullptr; return nullptr;
} }

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

@ -19,10 +19,36 @@
#ifndef wasm_js_h #ifndef wasm_js_h
#define wasm_js_h #define wasm_js_h
#include "gc/Policy.h" #include "mozilla/Attributes.h" // MOZ_MUST_USE
#include "gc/ZoneAllocator.h" #include "mozilla/HashTable.h" // DefaultHasher
#include "vm/NativeObject.h" #include "mozilla/Maybe.h" // mozilla::Maybe
#include "wasm/WasmTypes.h"
#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 { namespace js {
@ -39,6 +65,8 @@ class SharedArrayRawBuffer;
namespace wasm { namespace wasm {
struct ImportValues;
// Return whether WebAssembly can in principle be compiled on this platform (ie // 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 // combination of hardware and OS), assuming at least one of the compilers that
// supports the platform is not disabled by other settings. // supports the platform is not disabled by other settings.
@ -322,13 +350,9 @@ class WasmInstanceObject : public NativeObject {
DefaultHasher<uint32_t>, ZoneAllocPolicy>; DefaultHasher<uint32_t>, ZoneAllocPolicy>;
ExportMap& exports() const; ExportMap& exports() const;
// WeakScopeMap maps from function index to js::Scope. This maps is weak // See the definition inside WasmJS.cpp.
// to avoid holding scope objects alive. The scopes are normally created class UnspecifiedScopeMap;
// during debugging. UnspecifiedScopeMap& scopes() const;
using ScopeMap =
JS::WeakCache<GCHashMap<uint32_t, WeakHeapPtr<WasmFunctionScope*>,
DefaultHasher<uint32_t>, ZoneAllocPolicy>>;
ScopeMap& scopes() const;
public: public:
static const unsigned RESERVED_SLOTS = 6; static const unsigned RESERVED_SLOTS = 6;

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

@ -152,6 +152,22 @@ Value wasm::UnboxAnyRef(AnyRef val) {
return result; 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) { Value wasm::UnboxFuncRef(FuncRef val) {
JSFunction* fn = val.asJSFunction(); JSFunction* fn = val.asJSFunction();
Value result; Value result;

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

@ -39,7 +39,6 @@
#include "js/UniquePtr.h" #include "js/UniquePtr.h"
#include "js/Utility.h" #include "js/Utility.h"
#include "js/Vector.h" #include "js/Vector.h"
#include "vm/JSFunction.h"
#include "vm/MallocProvider.h" #include "vm/MallocProvider.h"
#include "vm/NativeObject.h" #include "vm/NativeObject.h"
#include "wasm/WasmConstants.h" #include "wasm/WasmConstants.h"
@ -934,20 +933,7 @@ class FuncRef {
// Given an AnyRef that represents a possibly-null funcref, turn it into a // Given an AnyRef that represents a possibly-null funcref, turn it into a
// FuncRef. // FuncRef.
static FuncRef fromAnyRefUnchecked(AnyRef p) { 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
}
AnyRef asAnyRef() { return AnyRef::fromJSObject((JSObject*)value_); } AnyRef asAnyRef() { return AnyRef::fromJSObject((JSObject*)value_); }