Files
ark_js_runtime/ecmascript/interpreter/interpreter.cpp
T
zhangyukun 25daaf26ef constuct entry frame of execute with rsp
1. add fp to support discontinuous frame gc and resume rsp
2. assemble execute and impl entry frame with rsp
3. use assembler to refactor .s
Issue:https://gitee.com/openharmony/ark_js_runtime/issues/I52BQE?from=project-issue

Signed-off-by: zhangyukun <zhangyukun8@huawei.com>
Change-Id: I6966672dc065d63144fe7fa145ab76571189d540
2022-05-07 14:13:50 +08:00

86 lines
3.3 KiB
C++

/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ecmascript/interpreter/interpreter.h"
#include "ecmascript/frames.h"
#include "ecmascript/interpreter/frame_handler.h"
namespace panda::ecmascript {
// make EcmaRuntimeCallInfo in stack pointer as fallows:
// +----------------------+ —
// | base.type | ^
// |----------------------| |
// | base.prev | InterpretedEntryFrame
// |----------------------| |
// | pc | v
// |----------------------| —
// | numArgs | ^
// |----------------------| |
// | args... | |
// |----------------------| |
// | this | |
// |----------------------| EcmaRuntimeCallInfo
// | newTarget | |
// |----------------------| |
// | func | v
// +----------------------+ —
EcmaRuntimeCallInfo EcmaInterpreter::NewRuntimeCallInfo(
JSThread *thread, JSHandle<JSTaggedValue> func, JSHandle<JSTaggedValue> thisObj, JSHandle<JSTaggedValue> newTarget,
size_t numArgs)
{
JSTaggedType *sp = const_cast<JSTaggedType *>(thread->GetCurrentSPFrame());
JSTaggedType *newSp = GetNextInterpreterEntryFrameSp(sp);
if (UNLIKELY(thread->DoStackOverflowCheck(newSp - numArgs - RESERVED_CALL_ARGCOUNT))) {
EcmaRuntimeCallInfo ecmaRuntimeCallInfo(thread, INVALID_ARGS_NUMBER, nullptr);
return ecmaRuntimeCallInfo;
}
thread->SetCurrentSPFrame(newSp);
// create entry frame.
InterpretedEntryFrame *entryState = InterpretedEntryFrame::GetFrameFromSp(newSp);
entryState->base.type = FrameType::INTERPRETER_ENTRY_FRAME;
#if ECMASCRIPT_ENABLE_ASM_INTERPRETER_RSP_STACK
entryState->base.prev = sp;
#else
auto leaveFrame = const_cast<JSTaggedType *>(thread->GetLastLeaveFrame());
if (leaveFrame != nullptr) {
entryState->base.prev = leaveFrame;
} else {
entryState->base.prev = sp;
}
#endif
entryState->pc = nullptr;
newSp -= INTERPRETER_ENTRY_FRAME_STATE_SIZE; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
*(--newSp) = JSTaggedValue(static_cast<int32_t>(numArgs)).GetRawData();
newSp -= numArgs; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
*(--newSp) = thisObj.GetTaggedType();
*(--newSp) = newTarget.GetTaggedType();
*(--newSp) = func.GetTaggedType();
EcmaRuntimeCallInfo ecmaRuntimeCallInfo(thread, numArgs, newSp);
return ecmaRuntimeCallInfo;
}
JSTaggedType *EcmaInterpreter::GetNextInterpreterEntryFrameSp(JSTaggedType *sp)
{
#if ECMASCRIPT_ENABLE_ASM_INTERPRETER_RSP_STACK
JSTaggedType *newSp = FrameHandler::GetInterpretedEntryFrameStart(sp);
#else
JSTaggedType *newSp = sp - INTERPRETER_FRAME_STATE_SIZE;
#endif
return newSp;
}
} // namespace panda::ecmascript