Skip to content

Commit

Permalink
Move PutByVal out-of-line
Browse files Browse the repository at this point in the history
Reviewed By: avp

Differential Revision: D68687404

fbshipit-source-id: a6cd81e0d20fe8cb8325de36a9e6f3abbd67bcdc
  • Loading branch information
neildhar authored and facebook-github-bot committed Jan 31, 2025
1 parent d6b6d51 commit 3b43c57
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 79 deletions.
14 changes: 9 additions & 5 deletions include/hermes/VM/Interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,15 @@ class Interpreter {
PinnedHermesValue *frameRegs,
const inst::Inst *ip);

static ExecutionStatus casePutByVal(
Runtime &runtime,
PinnedHermesValue *frameRegs,
const inst::Inst *ip);
static ExecutionStatus casePutByValWithReceiver(
Runtime &runtime,
PinnedHermesValue *frameRegs,
const inst::Inst *ip);

/// Interpreter implementation for creating a RegExp object. Unlike the other
/// out-of-line cases, this takes a CodeBlock* and does not return an
/// ExecutionStatus.
Expand All @@ -284,11 +293,6 @@ class Interpreter {
CodeBlock *curCodeBlock,
const inst::Inst *ip);

static ExecutionStatus casePutByValWithReceiver(
Runtime &runtime,
PinnedHermesValue *frameRegs,
const Inst *ip);

/// \return the `this` to be used for a construct call on \p callee, with \p
/// newTarget as the new.target. We need to take special care when \p callee
/// is a NativeConstructor, ES6 function, or JSCallableProxy. In these cases,
Expand Down
75 changes: 75 additions & 0 deletions lib/VM/Interpreter-slowpaths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,81 @@ ExecutionStatus Interpreter::caseGetByValWithReceiver(
return ExecutionStatus::RETURNED;
}

ExecutionStatus Interpreter::putByValTransient_RJS(
Runtime &runtime,
Handle<> base,
Handle<> name,
Handle<> value,
bool strictMode) {
auto idRes = valueToSymbolID(runtime, name);
if (idRes == ExecutionStatus::EXCEPTION)
return ExecutionStatus::EXCEPTION;

return putByIdTransient_RJS(runtime, base, **idRes, value, strictMode);
}

ExecutionStatus Interpreter::casePutByVal(
Runtime &runtime,
PinnedHermesValue *frameRegs,
const inst::Inst *ip) {
bool strictMode = (ip->opCode == inst::OpCode::PutByValStrict);
if (LLVM_LIKELY(O1REG(PutByValLoose).isObject())) {
auto defaultPropOpFlags = DEFAULT_PROP_OP_FLAGS(strictMode);
auto putRes = JSObject::putComputed_RJS(
Handle<JSObject>::vmcast(&O1REG(PutByValLoose)),
runtime,
Handle<>(&O2REG(PutByValLoose)),
Handle<>(&O3REG(PutByValLoose)),
defaultPropOpFlags);
if (LLVM_UNLIKELY(putRes == ExecutionStatus::EXCEPTION)) {
return ExecutionStatus::EXCEPTION;
}
} else {
// This is the "slow path".
auto retStatus = Interpreter::putByValTransient_RJS(
runtime,
Handle<>(&O1REG(PutByValLoose)),
Handle<>(&O2REG(PutByValLoose)),
Handle<>(&O3REG(PutByValLoose)),
strictMode);
if (LLVM_UNLIKELY(retStatus == ExecutionStatus::EXCEPTION)) {
return ExecutionStatus::EXCEPTION;
}
}
return ExecutionStatus::RETURNED;
}

ExecutionStatus Interpreter::casePutByValWithReceiver(
Runtime &runtime,
PinnedHermesValue *frameRegs,
const inst::Inst *ip) {
auto defaultPropOpFlags =
DEFAULT_PROP_OP_FLAGS(ip->iPutByValWithReceiver.op5);
if (LLVM_LIKELY(O1REG(PutByValWithReceiver).isObject())) {
auto res = JSObject::putComputedWithReceiver_RJS(
Handle<JSObject>::vmcast(&O1REG(PutByValWithReceiver)),
runtime,
Handle<>(&O2REG(PutByValWithReceiver)),
Handle<>(&O3REG(PutByValWithReceiver)),
Handle<>(&O4REG(PutByValWithReceiver)),
defaultPropOpFlags);
if (LLVM_UNLIKELY(res == ExecutionStatus::EXCEPTION)) {
return ExecutionStatus::EXCEPTION;
}
} else {
auto retStatus = Interpreter::putByValTransient_RJS(
runtime,
Handle<>(&O1REG(PutByValLoose)),
Handle<>(&O2REG(PutByValLoose)),
Handle<>(&O3REG(PutByValLoose)),
ip->iPutByValWithReceiver.op5);
if (LLVM_UNLIKELY(retStatus == ExecutionStatus::EXCEPTION)) {
return ExecutionStatus::EXCEPTION;
}
}
return ExecutionStatus::RETURNED;
}

CallResult<HermesValue> Interpreter::createThisImpl(
Runtime &runtime,
PinnedHermesValue *callee,
Expand Down
79 changes: 5 additions & 74 deletions lib/VM/Interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,19 +254,6 @@ CallResult<PseudoHandle<>> Interpreter::handleCallSlowPath(
}
}

ExecutionStatus Interpreter::putByValTransient_RJS(
Runtime &runtime,
Handle<> base,
Handle<> name,
Handle<> value,
bool strictMode) {
auto idRes = valueToSymbolID(runtime, name);
if (idRes == ExecutionStatus::EXCEPTION)
return ExecutionStatus::EXCEPTION;

return putByIdTransient_RJS(runtime, base, **idRes, value, strictMode);
}

static CallResult<HiddenClass *> getHiddenClassForBuffer(
Runtime &runtime,
CodeBlock *curCodeBlock,
Expand Down Expand Up @@ -2272,72 +2259,16 @@ CallResult<HermesValue> Interpreter::interpretFunction(

CASE(PutByValLoose)
CASE(PutByValStrict) {
bool strictMode = (ip->opCode == OpCode::PutByValStrict);
if (LLVM_LIKELY(O1REG(PutByValLoose).isObject())) {
auto defaultPropOpFlags = DEFAULT_PROP_OP_FLAGS(strictMode);
CAPTURE_IP_ASSIGN(
auto putRes,
JSObject::putComputed_RJS(
Handle<JSObject>::vmcast(&O1REG(PutByValLoose)),
runtime,
Handle<>(&O2REG(PutByValLoose)),
Handle<>(&O3REG(PutByValLoose)),
defaultPropOpFlags));
if (LLVM_UNLIKELY(putRes == ExecutionStatus::EXCEPTION)) {
goto exception;
}
} else {
// This is the "slow path".
CAPTURE_IP_ASSIGN(
auto retStatus,
Interpreter::putByValTransient_RJS(
runtime,
Handle<>(&O1REG(PutByValLoose)),
Handle<>(&O2REG(PutByValLoose)),
Handle<>(&O3REG(PutByValLoose)),
strictMode));
if (LLVM_UNLIKELY(retStatus == ExecutionStatus::EXCEPTION)) {
goto exception;
}
}
CAPTURE_IP_ASSIGN(
ExecutionStatus status, casePutByVal(runtime, frameRegs, ip));
if (LLVM_UNLIKELY(status == ExecutionStatus::EXCEPTION))
goto exception;
gcScope.flushToSmallCount(KEEP_HANDLES);
ip = NEXTINST(PutByValLoose);
DISPATCH;
}

CASE(PutByValWithReceiver) {
auto defaultPropOpFlags =
DEFAULT_PROP_OP_FLAGS(ip->iPutByValWithReceiver.op5);
if (LLVM_LIKELY(O1REG(PutByValWithReceiver).isObject())) {
CAPTURE_IP_ASSIGN(
auto res,
JSObject::putComputedWithReceiver_RJS(
Handle<JSObject>::vmcast(&O1REG(PutByValWithReceiver)),
runtime,
Handle<>(&O2REG(PutByValWithReceiver)),
Handle<>(&O3REG(PutByValWithReceiver)),
Handle<>(&O4REG(PutByValWithReceiver)),
defaultPropOpFlags));
if (LLVM_UNLIKELY(res == ExecutionStatus::EXCEPTION)) {
goto exception;
}
} else {
CAPTURE_IP_ASSIGN(
auto retStatus,
Interpreter::putByValTransient_RJS(
runtime,
Handle<>(&O1REG(PutByValLoose)),
Handle<>(&O2REG(PutByValLoose)),
Handle<>(&O3REG(PutByValLoose)),
ip->iPutByValWithReceiver.op5));
if (LLVM_UNLIKELY(retStatus == ExecutionStatus::EXCEPTION)) {
goto exception;
}
}
gcScope.flushToSmallCount(KEEP_HANDLES);
ip = NEXTINST(PutByValWithReceiver);
DISPATCH;
}
CASE_OUTOFLINE(PutByValWithReceiver);

CASE(DefineOwnByIndexL) {
nextIP = NEXTINST(DefineOwnByIndexL);
Expand Down

0 comments on commit 3b43c57

Please sign in to comment.