Skip to content

Commit

Permalink
Merge mozilla-central to autoland on a CLOSED TREE
Browse files Browse the repository at this point in the history
  • Loading branch information
Tamas Szentpeteri committed Jul 1, 2024
2 parents cfe2231 + 2556e6d commit bc42826
Show file tree
Hide file tree
Showing 37 changed files with 1,968 additions and 2,014 deletions.
24 changes: 14 additions & 10 deletions js/src/builtin/TestingFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1700,6 +1700,7 @@ static bool WasmExtractCode(JSContext* cx, unsigned argc, Value* vp) {
}

wasm::Tier tier = module->module().code().stableTier();
;
if (args.length() > 1 &&
!ConvertToTier(cx, args[1], module->module().code(), &tier)) {
args.rval().setNull();
Expand Down Expand Up @@ -1771,11 +1772,14 @@ static bool DisassembleNative(JSContext* cx, unsigned argc, Value* vp) {

js::wasm::Instance& inst = fun->wasmInstance();
const js::wasm::Code& code = inst.code();
js::wasm::Tier tier = code.bestTier();

const js::wasm::MetadataTier& meta = inst.metadata(tier);

const js::wasm::CodeSegment& segment = code.segment(tier);
const uint32_t funcIndex = code.getFuncIndex(&*fun);
const js::wasm::CodeBlock& codeBlock = inst.code().funcCodeBlock(funcIndex);
const js::wasm::CodeSegment& segment = *codeBlock.segment;
const js::wasm::FuncExport& func = codeBlock.lookupFuncExport(funcIndex);
const js::wasm::CodeRange& codeRange = codeBlock.codeRange(func);
const js::wasm::FuncExport& func = meta.lookupFuncExport(funcIndex);
const js::wasm::CodeRange& codeRange = meta.codeRange(func);

jit_begin = segment.base() + codeRange.begin();
jit_end = segment.base() + codeRange.end();
Expand Down Expand Up @@ -1883,6 +1887,11 @@ static bool ComputeTier(JSContext* cx, const wasm::Code& code,
return false;
}

if (!code.hasTier(*tier)) {
JS_ReportErrorASCII(cx, "function missing selected tier");
return false;
}

return true;
}

Expand Down Expand Up @@ -1915,18 +1924,13 @@ static bool WasmDisassembleFunction(JSContext* cx, const HandleFunction& func,
HandleValue tierSelection, bool asString,
MutableHandleValue rval) {
wasm::Instance& instance = wasm::ExportedFunctionToInstance(func);
uint32_t funcIndex = wasm::ExportedFunctionToFuncIndex(func);
wasm::Tier tier;

if (!ComputeTier(cx, instance.code(), tierSelection, &tier)) {
return false;
}

if (!instance.code().funcHasTier(funcIndex, tier)) {
JS_ReportErrorASCII(cx, "function missing selected tier");
return false;
}

uint32_t funcIndex = wasm::ExportedFunctionToFuncIndex(func);
return DisassembleIt(
cx, asString, rval, [&](void (*captureText)(const char*)) {
instance.disassembleExport(cx, funcIndex, tier, captureText);
Expand Down
11 changes: 6 additions & 5 deletions js/src/jit/CacheIR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11461,11 +11461,12 @@ AttachDecision CallIRGenerator::tryAttachWasmCall(HandleFunction calleeFunc) {
}

wasm::Instance& inst = wasm::ExportedFunctionToInstance(calleeFunc);
uint32_t funcIndex = wasm::ExportedFunctionToFuncIndex(calleeFunc);
const wasm::CodeBlock& codeBlock = inst.code().funcCodeBlock(funcIndex);
const wasm::FuncExport& funcExport = codeBlock.lookupFuncExport(funcIndex);
const wasm::FuncType& sig =
wasm::ExportedFunctionToTypeDef(calleeFunc).funcType();
uint32_t funcIndex = inst.code().getFuncIndex(calleeFunc);

auto bestTier = inst.code().bestTier();
const wasm::FuncExport& funcExport =
inst.metadata(bestTier).lookupFuncExport(funcIndex);
const wasm::FuncType& sig = inst.codeMeta().getFuncExportType(funcExport);

MOZ_ASSERT(!IsInsideNursery(inst.object()));
MOZ_ASSERT(sig.canHaveJitEntry(), "Function should allow a Wasm JitEntry");
Expand Down
2 changes: 1 addition & 1 deletion js/src/jit/CacheIROps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1993,7 +1993,7 @@
argc: Int32Id
flags: CallFlagsImm
argcFixed: UInt32Imm
funcType: RawPointerField
funcExport: RawPointerField
instance: ObjectField

- name: GuardWasmArg
Expand Down
2 changes: 1 addition & 1 deletion js/src/jit/CodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21433,7 +21433,7 @@ void CodeGenerator::emitIonToWasmCallBase(LIonToWasmCallBase<NumDefs>* lir) {
MIonToWasmCall* mir = lir->mir();
const wasm::FuncExport& funcExport = mir->funcExport();
const wasm::FuncType& sig =
mir->instance()->code().getFuncExportType(funcExport);
mir->instance()->codeMeta().getFuncExportType(funcExport);

WasmABIArgGenerator abi;
for (size_t i = 0; i < lir->numOperands(); i++) {
Expand Down
4 changes: 2 additions & 2 deletions js/src/jit/MIR-wasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ MIonToWasmCall* MIonToWasmCall::New(TempAllocator& alloc,
WasmInstanceObject* instanceObj,
const wasm::FuncExport& funcExport) {
const wasm::FuncType& funcType =
instanceObj->instance().code().getFuncExportType(funcExport);
instanceObj->instance().codeMeta().getFuncExportType(funcExport);
const wasm::ValTypeVector& results = funcType.results();
MIRType resultType = MIRType::Value;
// At the JS boundary some wasm types must be represented as a Value, and in
Expand All @@ -879,7 +879,7 @@ MIonToWasmCall* MIonToWasmCall::New(TempAllocator& alloc,
#ifdef DEBUG
bool MIonToWasmCall::isConsistentFloat32Use(MUse* use) const {
const wasm::FuncType& funcType =
instance()->code().getFuncExportType(funcExport_);
instance()->codeMeta().getFuncExportType(funcExport_);
return funcType.args()[use->index()].kind() == wasm::ValType::F32;
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion js/src/jit/WarpCacheIRTranspiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5992,7 +5992,7 @@ bool WarpCacheIRTranspiler::emitCallWasmFunction(
auto* wasmInstanceObj = &instanceObject->as<WasmInstanceObject>();
const wasm::FuncExport* funcExport = wasmFuncExportField(funcExportOffset);
const wasm::FuncType& sig =
wasmInstanceObj->instance().code().getFuncExportType(*funcExport);
wasmInstanceObj->instance().codeMeta().getFuncExportType(*funcExport);

if (!updateCallInfo(callee, flags)) {
return false;
Expand Down
4 changes: 2 additions & 2 deletions js/src/jit/arm/Simulator-arm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2432,14 +2432,14 @@ void Simulator::softwareInterrupt(SimInstruction* instr) {
}

void Simulator::canonicalizeNaN(double* value) {
if (!wasm::CodeExists && !wasm::LookupCodeBlock(get_pc_as<void*>()) &&
if (!wasm::CodeExists && !wasm::LookupCodeSegment(get_pc_as<void*>()) &&
FPSCR_default_NaN_mode_) {
*value = JS::CanonicalizeNaN(*value);
}
}

void Simulator::canonicalizeNaN(float* value) {
if (!wasm::CodeExists && !wasm::LookupCodeBlock(get_pc_as<void*>()) &&
if (!wasm::CodeExists && !wasm::LookupCodeSegment(get_pc_as<void*>()) &&
FPSCR_default_NaN_mode_) {
*value = JS::CanonicalizeNaN(*value);
}
Expand Down
4 changes: 2 additions & 2 deletions js/src/vm/MutexIDs.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
_(WellKnownParserAtomsInit, 100) \
\
_(WasmInitBuiltinThunks, 250) \
_(WasmCodeProtected, 250) \
_(WasmLazyStubsTier1, 250) \
_(WasmLazyStubsTier2, 251) \
\
_(StoreBuffer, 275) \
Expand Down Expand Up @@ -64,7 +64,7 @@
_(SharedImmutableStringsCache, 600) \
_(IrregexpLazyStatic, 600) \
_(ThreadId, 600) \
_(WasmCodeBlockMap, 600) \
_(WasmCodeSegmentMap, 600) \
_(VTuneLock, 600) \
_(ShellTelemetry, 600) \
_(ShellUseCounters, 600)
Expand Down
36 changes: 17 additions & 19 deletions js/src/wasm/WasmBuiltins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -639,13 +639,14 @@ static WasmExceptionObject* GetOrWrapWasmException(JitActivation* activation,
return nullptr;
}

static const wasm::TryNote* FindNonDelegateTryNote(
const wasm::Code& code, const uint8_t* pc, const CodeBlock** codeBlock) {
const wasm::TryNote* tryNote = code.lookupTryNote((void*)pc, codeBlock);
static const wasm::TryNote* FindNonDelegateTryNote(const wasm::Code& code,
const uint8_t* pc,
Tier* tier) {
const wasm::TryNote* tryNote = code.lookupTryNote((void*)pc, tier);
while (tryNote && tryNote->isDelegate()) {
pc = (*codeBlock)->segment->base() + tryNote->delegateOffset();
const wasm::TryNote* delegateTryNote =
code.lookupTryNote((void*)pc, codeBlock);
const wasm::CodeTier& codeTier = code.codeTier(*tier);
pc = codeTier.segment().base() + tryNote->delegateOffset();
const wasm::TryNote* delegateTryNote = code.lookupTryNote((void*)pc, tier);
MOZ_RELEASE_ASSERT(delegateTryNote == nullptr ||
delegateTryNote->tryBodyBegin() <
tryNote->tryBodyBegin());
Expand Down Expand Up @@ -709,11 +710,10 @@ bool wasm::HandleThrow(JSContext* cx, WasmFrameIter& iter,

// Only look for an exception handler if there's a catchable exception.
if (wasmExn) {
Tier tier;
const wasm::Code& code = iter.instance()->code();
const uint8_t* pc = iter.resumePCinCurrentFrame();
const wasm::CodeBlock* codeBlock = nullptr;
const wasm::TryNote* tryNote =
FindNonDelegateTryNote(code, pc, &codeBlock);
const wasm::TryNote* tryNote = FindNonDelegateTryNote(code, pc, &tier);

if (tryNote) {
#ifdef ENABLE_WASM_TAIL_CALLS
Expand All @@ -736,7 +736,7 @@ bool wasm::HandleThrow(JSContext* cx, WasmFrameIter& iter,
rfe->stackPointer =
(uint8_t*)(rfe->framePointer - tryNote->landingPadFramePushed());
rfe->target =
codeBlock->segment->base() + tryNote->landingPadEntryPoint();
iter.instance()->codeBase(tier) + tryNote->landingPadEntryPoint();

// Make sure to clear trapping state if we got here due to a trap.
if (activation->isWasmTrapping()) {
Expand Down Expand Up @@ -965,12 +965,14 @@ static void* BoxValue_Anyref(Value* rawVal) {
return result.get().forCompiledCode();
}

static int32_t CoerceInPlace_JitEntry(int funcIndex, Instance* instance,
static int32_t CoerceInPlace_JitEntry(int funcExportIndex, Instance* instance,
Value* argv) {
JSContext* cx = TlsContext.get(); // Cold code

const Code& code = instance->code();
const FuncType& funcType = code.getFuncExportType(funcIndex);
const FuncExport& fe =
code.metadata(code.stableTier()).funcExports[funcExportIndex];
const FuncType& funcType = code.codeMeta().getFuncExportType(fe);

for (size_t i = 0; i < funcType.args().length(); i++) {
HandleValue arg = HandleValue::fromMarkedLocation(&argv[i]);
Expand Down Expand Up @@ -1904,12 +1906,6 @@ Mutex initBuiltinThunks(mutexid::WasmInitBuiltinThunks);
Atomic<const BuiltinThunks*> builtinThunks;

bool wasm::EnsureBuiltinThunksInitialized() {
AutoMarkJitCodeWritableForThread writable;
return EnsureBuiltinThunksInitialized(writable);
}

bool wasm::EnsureBuiltinThunksInitialized(
AutoMarkJitCodeWritableForThread& writable) {
LockGuard<Mutex> guard(initBuiltinThunks);
if (builtinThunks) {
return true;
Expand Down Expand Up @@ -2014,6 +2010,8 @@ bool wasm::EnsureBuiltinThunksInitialized(
return false;
}

AutoMarkJitCodeWritableForThread writable;

masm.executableCopy(thunks->codeBase);
memset(thunks->codeBase + masm.bytesNeeded(), 0,
allocSize - masm.bytesNeeded());
Expand Down Expand Up @@ -2150,7 +2148,7 @@ void* wasm::MaybeGetBuiltinThunk(JSFunction* f, const FuncType& funcType) {
}

bool wasm::LookupBuiltinThunk(void* pc, const CodeRange** codeRange,
const uint8_t** codeBase) {
uint8_t** codeBase) {
if (!builtinThunks) {
return false;
}
Expand Down
7 changes: 2 additions & 5 deletions js/src/wasm/WasmBuiltins.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@

namespace js {
namespace jit {
class AutoMarkJitCodeWritableForThread;
struct ResumeFromException;
} // namespace jit
}
namespace wasm {

class WasmFrameIter;
Expand Down Expand Up @@ -304,7 +303,7 @@ bool NeedsBuiltinThunk(SymbolicAddress sym);
// CodeRange is relative to.

bool LookupBuiltinThunk(void* pc, const CodeRange** codeRange,
const uint8_t** codeBase);
uint8_t** codeBase);

// EnsureBuiltinThunksInitialized() must be called, and must succeed, before
// SymbolicAddressTarget() or MaybeGetBuiltinThunk(). This function creates all
Expand All @@ -313,8 +312,6 @@ bool LookupBuiltinThunk(void* pc, const CodeRange** codeRange,
// executable code has been released.

bool EnsureBuiltinThunksInitialized();
bool EnsureBuiltinThunksInitialized(
jit::AutoMarkJitCodeWritableForThread& writable);

bool HandleThrow(JSContext* cx, WasmFrameIter& iter,
jit::ResumeFromException* rfe);
Expand Down
Loading

0 comments on commit bc42826

Please sign in to comment.