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 #ifndef ECMASCRIPT_JIT_JIT_THREAD_H 17 #define ECMASCRIPT_JIT_JIT_THREAD_H 18 19 #include "ecmascript/js_thread.h" 20 #include "ecmascript/ecma_vm.h" 21 #include "ecmascript/mem/heap.h" 22 23 namespace panda::ecmascript { 24 class JitVM; 25 class JitTask; 26 class JitThread final : public JSThread { 27 public: 28 JitThread(JitVM *jitVM); 29 EcmaVM *GetEcmaVM() const; 30 JSThread * PUBLIC_API GetHostThread() const; 31 void SetHostThread(JSThread *thread); 32 JitVM *GetJitVM() const; 33 SetCurrentTask(JitTask * task)34 void SetCurrentTask(JitTask *task) 35 { 36 curJitTask_ = task; 37 } 38 GetCurrentTask()39 JitTask *GetCurrentTask() const 40 { 41 return curJitTask_; 42 } 43 44 JSHandle<JSTaggedValue> PUBLIC_API NewHandle(JSTaggedValue value) const; 45 46 private: 47 JSThread *hostThread_ {nullptr}; 48 JitTask *curJitTask_ {nullptr}; 49 }; 50 51 class JitVM final : public EcmaVM { 52 public: JitVM()53 JitVM() : EcmaVM() {} 54 ~JitVM(); 55 static JitVM *Create(); 56 static void Destroy(EcmaVM *jitvm); 57 GetHostVm()58 EcmaVM *GetHostVm() const 59 { 60 return hostVm_; 61 } 62 63 void SetHostVM(JSThread *hostThread); 64 void ReSetHostVM(); 65 66 private: 67 EcmaVM *hostVm_ {nullptr}; 68 JitThread *jitThread_ {nullptr}; 69 }; 70 } // namespace panda::ecmascript 71 #endif // ECMASCRIPT_JIT_TASK_H 72