fix rsp align issue

Issue:https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/IAZ8UJ

Signed-off-by: zoumujia <zoumujia0920@163.com>
This commit is contained in:
zoumujia 2024-10-23 15:30:11 +08:00
parent be29f2f4b5
commit 4e590cb1ba
8 changed files with 133 additions and 8 deletions

View File

@ -1854,6 +1854,12 @@ void AsmInterpreterCall::ThrowStackOverflowExceptionAndReturn(ExtendedAssembler
__ Pushq(static_cast<int64_t>(FrameType::ASM_BRIDGE_FRAME)); // set frame type
__ Leaq(Operand(rsp, FRAME_SLOT_SIZE), rbp); // skip frame type
Label callRuntime;
// 16 bytes align check
__ Testq(0x8, rsp);
__ Jnz(&callRuntime);
__ PushAlignBytes();
__ Bind(&callRuntime);
__ Pushq(r10); // caller save
__ Pushq(0); // argc
__ Pushq(kungfu::RuntimeStubCSigns::ID_ThrowStackOverflowException); // runtime id
@ -1863,13 +1869,13 @@ void AsmInterpreterCall::ThrowStackOverflowExceptionAndReturn(ExtendedAssembler
__ Callq(r10); // call CallRuntime
__ Addq(2 * FRAME_SLOT_SIZE, rsp); // 2: skip argc and runtime_id
__ Popq(r10);
__ Addq(FRAME_SLOT_SIZE, rsp); // skip frame type
__ Movq(rbp, rsp);
__ Popq(rbp);
__ Ret();
}
void AsmInterpreterCall::ThrowStackOverflowExceptionAndReturnToAotFrame(ExtendedAssembler *assembler, Register glue,
Register fp, Register op)
void AsmInterpreterCall::ThrowStackOverflowExceptionAndReturnToAsmInterpBridgeFrame(ExtendedAssembler *assembler,
Register glue, Register fp, Register op)
{
if (fp != rsp) {
__ Movq(fp, rsp);
@ -1884,6 +1890,12 @@ void AsmInterpreterCall::ThrowStackOverflowExceptionAndReturnToAotFrame(Extended
__ Pushq(static_cast<int64_t>(FrameType::ASM_BRIDGE_FRAME)); // set frame type
__ Leaq(Operand(rsp, FRAME_SLOT_SIZE), rbp); // skip frame type
Label callRuntime;
// 16 bytes align check
__ Testq(0x8, rsp);
__ Jnz(&callRuntime);
__ PushAlignBytes();
__ Bind(&callRuntime);
__ Pushq(r10); // caller save
__ Pushq(0); // argc
__ Pushq(kungfu::RuntimeStubCSigns::ID_ThrowStackOverflowException); // runtime id
@ -1893,10 +1905,13 @@ void AsmInterpreterCall::ThrowStackOverflowExceptionAndReturnToAotFrame(Extended
__ Callq(r10); // call CallRuntime
__ Addq(2 * FRAME_SLOT_SIZE, rsp); // 2: skip argc and runtime_id
__ Popq(r10);
__ Addq(FRAME_SLOT_SIZE, rsp); // skip frame type
__ Popq(rbp);
__ Movq(rbp, rsp);
__ Movq(Operand(rbp, -2 * FRAME_SLOT_SIZE), rbp); // 2: skip returnAddr and frameType in AsmBridgeFrame
__ Popq(rbp);
// Base on PushAsmInterpBridgeFrame, need to skip AsmInterpBridgeFrame size, callee Save Registers(5)
// and PushAlignBytes(1)
int32_t skipNum = AsmInterpretedBridgeFrame::GetSize(false) / FRAME_SLOT_SIZE + 5 + 1;
__ Leaq(Operand(rbp, -skipNum * FRAME_SLOT_SIZE), rsp);
__ Ret();
}

View File

@ -202,7 +202,7 @@ private:
Register op1, Register op2, Label *stackOverflow);
static void ThrowStackOverflowExceptionAndReturn(ExtendedAssembler *assembler, Register glue, Register fp,
Register op);
static void ThrowStackOverflowExceptionAndReturnToAotFrame(ExtendedAssembler *assembler, Register glue,
static void ThrowStackOverflowExceptionAndReturnToAsmInterpBridgeFrame(ExtendedAssembler *assembler, Register glue,
Register fp, Register op);
static void HasPendingException(ExtendedAssembler *assembler, Register threadRegister);
static void PushCallThis(ExtendedAssembler *assembler, JSCallMode mode,

View File

@ -1406,7 +1406,7 @@ void OptimizedCall::DeoptEnterAsmInterp(ExtendedAssembler *assembler)
{
[[maybe_unused]] TempRegisterScope scope(assembler);
Register temp = __ TempRegister();
AsmInterpreterCall::ThrowStackOverflowExceptionAndReturnToAotFrame(assembler,
AsmInterpreterCall::ThrowStackOverflowExceptionAndReturnToAsmInterpBridgeFrame(assembler,
glueRegister, rsp, temp);
}
}

View File

@ -90,6 +90,7 @@ group("ark_aot_ts_test") {
"compiler_test",
"constpool",
"construct_deopt_frame_stack_overflow",
"construct_deopt_frame_stack_overflow2",
"continue_from_finally",
"copyrestargs",
"createarray_meta_data",

View File

@ -0,0 +1,23 @@
# Copyright (c) 2024 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.
import("//arkcompiler/ets_runtime/test/test_helper.gni")
host_aot_test_action("construct_deopt_frame_stack_overflow2") {
deps = []
is_only_typed_path = true
is_enable_pgo = true
is_enable_opt_inlining = true
is_enable_enableArkTools = true
log_option = " --log-info=fatal"
}

View File

@ -0,0 +1,58 @@
/*
* Copyright (c) 2024 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.
*/
function test() {
function f0() {
const o18 = {
proto: "p",
n(a5) {
let v6;
try { v6 = a5(this); } catch (e) { }
function f7() {
return v6;
}
return this;
},
set a(a9) {
},
};
return o18;
}
const v19 = f0();
const v21 = f0();
function f22(a23) {
try { a23.n(f22); } catch (e) { }
const o30 = {
m() {
return a23;
},
proto: a23,
"d": f0,
};
return o30;
}
f22(v21);
const v33 = f22(v19);
const v45 = new Set();
for (let [i71, i72] = (() => {
return [0, 5];
})();
i71 < i72;
) {
i72--;
}
}
test()
print(ArkTools.isAOTCompiled(test));

View File

@ -0,0 +1,14 @@
# Copyright (c) 2024 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.
true

View File

@ -0,0 +1,14 @@
# Copyright (c) 2024 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.
false