reason:add assert in asm interpreter

description:add assert in asm interpreter
issue:https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/I603UA?from=project-issue

Signed-off-by: wupengyong <wupengyong@huawei.com>
Change-Id: Ib23b1ec3b78af1600e7a34f81ef9bd9836ee5720
This commit is contained in:
wupengyong 2022-11-08 17:05:30 +08:00
parent 172b46e7ab
commit 380c5905ce
5 changed files with 45 additions and 0 deletions

View File

@ -29,6 +29,7 @@ namespace panda::ecmascript {
#define ECMASCRIPT_ENABLE_SNAPSHOT 0
#define ECMASCRIPT_ENABLE_HEAP_DETAIL_STATISTICS 0
#define ECMASCRIPT_ENABLE_ASM_ASSERT 0
#ifndef NDEBUG
#define ECMASCRIPT_ENABLE_INTERPRETER_LOG 1

View File

@ -3081,6 +3081,7 @@ GateRef StubBuilder::GetMethod(GateRef glue, GateRef obj, GateRef key)
{
Label valueIsCallable(env);
Label valueNotCallable(env);
ASM_ASSERT(GET_MESSAGE_STRING_ID(IsCallable), glue, TaggedIsHeapObject(value), assertLabel);
Branch(IsCallable(value), &valueIsCallable, &valueNotCallable);
Bind(&valueNotCallable);
{
@ -3142,6 +3143,7 @@ GateRef StubBuilder::OrdinaryHasInstance(GateRef glue, GateRef target, GateRef o
// 1. If IsCallable(C) is false, return false.
Label targetIsCallable2(env);
Label targetNotCallable2(env);
ASM_ASSERT(GET_MESSAGE_STRING_ID(IsCallable), glue, TaggedIsHeapObject(target), assertLabel);
Branch(IsCallable(target), &targetIsCallable2, &targetNotCallable2);
Bind(&targetNotCallable2);
{
@ -3155,6 +3157,7 @@ GateRef StubBuilder::OrdinaryHasInstance(GateRef glue, GateRef target, GateRef o
// b. Return InstanceofOperator(O,BC) (see 12.9.4).
Label targetIsBoundFunction(env);
Label targetNotBoundFunction(env);
ASM_ASSERT(GET_MESSAGE_STRING_ID(IsBoundFunction), glue, TaggedIsHeapObject(target), assertLabel1);
Branch(IsBoundFunction(target), &targetIsBoundFunction, &targetNotBoundFunction);
Bind(&targetIsBoundFunction);
{
@ -4952,4 +4955,21 @@ GateRef StubBuilder::SetTypeArrayPropertyByName(GateRef glue, GateRef receiver,
env->SubCfgExit();
return ret;
}
void StubBuilder::Assert(int messageId, int line, GateRef glue, GateRef condition, Label *nextLabel)
{
auto env = GetEnvironment();
Label ok(env);
Label notOk(env);
Branch(condition, &ok, &notOk);
Bind(&ok);
{
Jump(nextLabel);
}
Bind(&notOk);
{
FatalPrint(glue, { Int32(messageId), Int32(line) });
Jump(nextLabel);
}
}
} // namespace panda::ecmascript::kungfu

View File

@ -16,6 +16,7 @@
#ifndef ECMASCRIPT_COMPILER_STUB_BUILDER_H
#define ECMASCRIPT_COMPILER_STUB_BUILDER_H
#include "ecmascript/base/config.h"
#include "ecmascript/compiler/call_signature.h"
#include "ecmascript/compiler/circuit_builder-inl.h"
#include "ecmascript/compiler/variable_type.h"
@ -25,6 +26,20 @@ using namespace panda::ecmascript;
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define DEFVARIABLE(varname, type, val) Variable varname(GetEnvironment(), type, NextVariableId(), val)
#ifndef NDEBUG
#define ASM_ASSERT(messageId, glue, condition, nextLabel) \
Label nextLabel(env); \
Assert(messageId, __LINE__, glue, condition, &nextLabel); \
Bind(&nextLabel)
#elif ECMASCRIPT_ENABLE_ASM_ASSERT
#define ASM_ASSERT(messageId, glue, condition, nextLabel) \
Label nextLabel(env); \
Assert(messageId, __LINE__, glue, condition, &nextLabel); \
Bind(&nextLabel)
#else
#define ASM_ASSERT(messageId, ...) ((void)0)
#endif
class StubBuilder {
public:
explicit StubBuilder(StubBuilder *parent)
@ -508,6 +523,7 @@ public:
inline void SetLength(GateRef glue, GateRef str, GateRef length, bool compressed);
inline void SetRawHashcode(GateRef glue, GateRef str, GateRef rawHashcode);
inline void PGOProfiler(GateRef glue, GateRef func);
void Assert(int messageId, int line, GateRef glue, GateRef condition, Label *nextLabel);
private:
using BinaryOperation = std::function<GateRef(Environment*, GateRef, GateRef)>;
template<OpCode::Op Op>

View File

@ -33,6 +33,9 @@ static std::array<std::string, MessageString::MAX_MESSAGE_COUNT> g_messageString
ASM_INTERPRETER_BC_HELPER_STUB_LIST(DEF_ASM_INTERPRETER_STUB_MESSAGE)
ASM_INTERPRETER_BUILTINS_STUB_LIST(DEF_ASM_INTERPRETER_STUB_MESSAGE)
#undef DEF_ASM_INTERPRETER_STUB_MESSAGE
#define DEF_ISHEAPOBJECT_MESSAGE(name) #name"DebugCheck IR:line:%d",
DEBUG_CHECK_MESSAGE_STRING_LIST(DEF_ISHEAPOBJECT_MESSAGE)
#undef DEF_ISHEAPOBJECT_MESSAGE
};
const std::string& MessageString::GetMessageString(int id)

View File

@ -38,6 +38,10 @@ namespace panda::ecmascript {
V(CanNotGetNotEcmaObject, "Can not get Prototype on non ECMA Object") \
V(InstanceOfErrorTargetNotCallable, "InstanceOf error when target is not Callable")
#define DEBUG_CHECK_MESSAGE_STRING_LIST(V) \
V(IsBoundFunction) \
V(IsCallable)
class MessageString {
public:
enum MessageId {
@ -50,6 +54,7 @@ public:
ASM_INTERPRETER_SECOND_BC_STUB_ID_LIST(DEF_MESSAGE_ID)
ASM_INTERPRETER_BC_HELPER_STUB_LIST(DEF_MESSAGE_ID)
ASM_INTERPRETER_BUILTINS_STUB_LIST(DEF_MESSAGE_ID)
DEBUG_CHECK_MESSAGE_STRING_LIST(DEF_MESSAGE_ID)
#undef DEF_MESSAGE_ID
MAX_MESSAGE_COUNT,
ASM_INTERPRETER_START = Message_INT32_VALUE + 1,