1/* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16#include "ecmascript/jit/jit_thread.h" 17 18namespace panda::ecmascript { 19JitThread::JitThread(JitVM *jitVM) : JSThread(jitVM, ThreadType::JIT_THREAD) {}; 20 21JSThread *JitThread::GetHostThread() const 22{ 23 return hostThread_; 24} 25 26void JitThread::SetHostThread(JSThread *thread) 27{ 28 hostThread_ = thread; 29} 30 31JitVM *JitThread::GetJitVM() const 32{ 33 return static_cast<JitVM*>(JSThread::GetEcmaVM()); 34} 35 36JitVM *JitVM::Create() 37{ 38 auto vm = new JitVM(); 39 JitThread *thread = new JitThread(vm); 40 vm->jitThread_ = thread; 41 42 // super ecmavm 43 vm->InitializeForJit(thread); 44 return vm; 45} 46 47JitVM::~JitVM() 48{ 49} 50 51void JitVM::Destroy(EcmaVM *compilerVm) 52{ 53 JitVM *jitVM = static_cast<JitVM*>(compilerVm); 54 delete jitVM->jitThread_; 55 jitVM->jitThread_ = nullptr; 56 57 delete jitVM; 58} 59 60void JitVM::SetHostVM(JSThread *hostThread) 61{ 62 hostVm_ = hostThread->GetEcmaVM(); 63 jitThread_->SetHostThread(hostThread); 64 65 const GlobalEnvConstants *constants = hostThread->GlobalConstants(); 66 jitThread_->SetGlobalConstants(constants); 67} 68 69void JitVM::ReSetHostVM() 70{ 71 hostVm_ = nullptr; 72 jitThread_->SetHostThread(nullptr); 73 jitThread_->SetGlobalConstants(nullptr); 74} 75 76} // namespace panda::ecmascript 77