• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "ecmascript/sustaining_js_handle.h"
18 #include "ecmascript/js_handle.h"
19 
20 namespace panda::ecmascript {
JitThread(JitVM * jitVM)21 JitThread::JitThread(JitVM *jitVM) : JSThread(jitVM, ThreadType::JIT_THREAD) {};
22 
GetHostThread() const23 JSThread *JitThread::GetHostThread() const
24 {
25     return hostThread_;
26 }
27 
SetHostThread(JSThread * thread)28 void JitThread::SetHostThread(JSThread *thread)
29 {
30     hostThread_ = thread;
31 }
32 
GetJitVM() const33 JitVM *JitThread::GetJitVM() const
34 {
35     return static_cast<JitVM*>(JSThread::GetEcmaVM());
36 }
37 
NewHandle(JSTaggedValue value) const38 JSHandle<JSTaggedValue> JitThread::NewHandle(JSTaggedValue value) const
39 {
40     return SustainingJSHandle::NewHandle<JSTaggedValue>(this, value.GetRawData());
41 }
42 
Create()43 JitVM *JitVM::Create()
44 {
45     auto vm = new JitVM();
46     JitThread *thread = new JitThread(vm);
47     vm->jitThread_ = thread;
48 
49     // super ecmavm
50     vm->InitializeForJit(thread);
51     return vm;
52 }
53 
~JitVM()54 JitVM::~JitVM()
55 {
56     jitThread_ = nullptr;
57 }
58 
Destroy(EcmaVM * compilerVm)59 void JitVM::Destroy(EcmaVM *compilerVm)
60 {
61     JitVM *jitVM = static_cast<JitVM*>(compilerVm);
62 
63     delete jitVM;
64 }
65 
SetHostVM(JSThread * hostThread)66 void JitVM::SetHostVM(JSThread *hostThread)
67 {
68     hostVm_ = hostThread->GetEcmaVM();
69     jitThread_->SetHostThread(hostThread);
70 
71     const GlobalEnvConstants *constants = hostThread->GlobalConstants();
72     jitThread_->SetGlobalConstants(constants);
73 }
74 
ReSetHostVM()75 void JitVM::ReSetHostVM()
76 {
77     hostVm_ = nullptr;
78     jitThread_->SetHostThread(nullptr);
79     jitThread_->SetGlobalConstants(nullptr);
80 }
81 
82 }  // namespace panda::ecmascript
83