From 1dc858d65f6df98a05ea2d68eba39f396b42bf1b Mon Sep 17 00:00:00 2001 From: Sidorov Aleksei Date: Tue, 17 Jan 2023 12:45:30 +0300 Subject: [PATCH] [Compiler] Fix OSR compilation for Dynamic Languages Signed-off-by: Sidorov Aleksei --- compiler/optimizer/ecma_pipeline.cpp | 1 - runtime/asm_defines/asm_defines.def | 1 + runtime/asm_defines/defines.h | 1 + runtime/ecma_language_context.cpp | 18 ++++++++++++++++++ runtime/ecma_language_context.h | 3 +++ 5 files changed, 23 insertions(+), 1 deletion(-) diff --git a/compiler/optimizer/ecma_pipeline.cpp b/compiler/optimizer/ecma_pipeline.cpp index 276015b0a..c82c73ea8 100644 --- a/compiler/optimizer/ecma_pipeline.cpp +++ b/compiler/optimizer/ecma_pipeline.cpp @@ -54,7 +54,6 @@ bool EcmaPipeline::RunOptimizations() { auto graph = GetGraph(); - ASSERT(!graph->IsOsrMode() && "We don't support OSR in JS yet"); graph->RunPass(); // TODO(schernykh): Find way to inline in AOT and OSR mode if (!graph->IsAotMode() && !graph->IsOsrMode()) { diff --git a/runtime/asm_defines/asm_defines.def b/runtime/asm_defines/asm_defines.def index 879225c41..8786a3f7e 100644 --- a/runtime/asm_defines/asm_defines.def +++ b/runtime/asm_defines/asm_defines.def @@ -2,6 +2,7 @@ * Copyright (c) Huawei Technologies Co., Ltd. 2019-2021. All rights reserved. */ +DEFINE_VALUE(ECMA_IFRAME_EXT_SIZE, panda::ecmascript::JSExtFrame::GetExtSize()) DEFINE_VALUE(ECMASCRIPT_ENVIRONMENT_SIZE, panda::ecmascript::EcmascriptEnvironment::GetSize()) DEFINE_VALUE(ECMASCRIPT_ENVIRONMENT_PREV_ENVIRONMENT_OFFSET, panda::ecmascript::EcmascriptEnvironment::GetPrevEnvironmentOffset()) DEFINE_VALUE(ECMASCRIPT_ENVIRONMENT_CONSTANT_POOL_OFFSET, panda::ecmascript::EcmascriptEnvironment::GetConstantPoolOffset()) diff --git a/runtime/asm_defines/defines.h b/runtime/asm_defines/defines.h index ea28c137b..db058e031 100644 --- a/runtime/asm_defines/defines.h +++ b/runtime/asm_defines/defines.h @@ -19,6 +19,7 @@ #include "plugins/ecmascript/compiler/ecmascript_extensions/ecmascript_environment.h" #include "plugins/ecmascript/runtime/ic/ic_handler.h" #include "plugins/ecmascript/runtime/ic/proto_change_details.h" +#include "plugins/ecmascript/runtime/interpreter/js_frame.h" #include "plugins/ecmascript/runtime/js_array.h" #include "plugins/ecmascript/runtime/js_function.h" #include "plugins/ecmascript/runtime/js_tagged_value.h" diff --git a/runtime/ecma_language_context.cpp b/runtime/ecma_language_context.cpp index 45f1c3ca7..6d879bb1b 100644 --- a/runtime/ecma_language_context.cpp +++ b/runtime/ecma_language_context.cpp @@ -135,4 +135,22 @@ void EcmaLanguageContext::RestorePrevEnv() const js_thread->SetEcmascriptEnv(prev_env); } +void EcmaLanguageContext::InitializeOsrCframeSlots(ManagedThread *thread, Span param_slots, + Span lang_ext_slots) const +{ + auto *cframe_js_env {reinterpret_cast(lang_ext_slots.Data())}; + CHECK_GE(lang_ext_slots.SizeBytes(), sizeof(ecmascript::EcmascriptEnvironment)); + + auto *js_thread {JSThread::Cast(thread)}; + auto *js_env {ecmascript::JSFrame::GetJSEnv(js_thread->GetCurrentFrame())}; + cframe_js_env->SetConstantPool(js_env->GetConstantPool()); + cframe_js_env->SetLexicalEnv(js_env->GetLexicalEnv()); + cframe_js_env->SetThisFunc(js_env->GetThisFunc()); + cframe_js_env->SetPrevEnvironment(js_env->GetPrevEnvironment()); + + std::fill(param_slots.begin(), param_slots.end(), TaggedValue::VALUE_UNDEFINED); + + js_thread->SetEcmascriptEnv(cframe_js_env); +} + } // namespace panda diff --git a/runtime/ecma_language_context.h b/runtime/ecma_language_context.h index 9259b5575..0b8b474e3 100644 --- a/runtime/ecma_language_context.h +++ b/runtime/ecma_language_context.h @@ -304,6 +304,9 @@ public: { return false; } + + void InitializeOsrCframeSlots(ManagedThread *thread, Span param_slots, + Span lang_ext_slots) const override; }; } // namespace panda -- Gitee