1 /** 2 * Copyright (c) 2021-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 PANDA_RUNTIME_TOOLING_PT_THREAD_INFO_H 17 #define PANDA_RUNTIME_TOOLING_PT_THREAD_INFO_H 18 19 #include <cstdint> 20 21 #include "runtime/include/panda_vm.h" 22 #include "runtime/mem/refstorage/global_object_storage.h" 23 #include "pt_hook_type_info.h" 24 #include "thread_sampling_info.h" 25 26 namespace ark::tooling { 27 class PtThreadInfo { 28 public: 29 PtThreadInfo() = default; 30 ~PtThreadInfo()31 ~PtThreadInfo() 32 { 33 ASSERT(managedThreadRef_ == nullptr); 34 } 35 GetHookTypeInfo()36 PtHookTypeInfo &GetHookTypeInfo() 37 { 38 return hookTypeInfo_; 39 } 40 GetSamplingInfo()41 sampler::ThreadSamplingInfo *GetSamplingInfo() 42 { 43 return &samplingInfo_; 44 } 45 SetThreadObjectHeader(ObjectHeader * threadObjectHeader)46 void SetThreadObjectHeader(ObjectHeader *threadObjectHeader) 47 { 48 ASSERT(managedThreadRef_ == nullptr); 49 managedThreadRef_ = PandaVM::GetCurrent()->GetGlobalObjectStorage()->Add(threadObjectHeader, 50 mem::Reference::ObjectType::GLOBAL); 51 } 52 Destroy()53 void Destroy() 54 { 55 if (managedThreadRef_ != nullptr) { 56 PandaVM::GetCurrent()->GetGlobalObjectStorage()->Remove(managedThreadRef_); 57 managedThreadRef_ = nullptr; 58 } 59 } 60 GetThreadObjectHeader()61 ObjectHeader *GetThreadObjectHeader() const 62 { 63 ASSERT(managedThreadRef_ != nullptr); 64 return PandaVM::GetCurrent()->GetGlobalObjectStorage()->Get(managedThreadRef_); 65 } 66 67 private: 68 PtHookTypeInfo hookTypeInfo_ {false}; 69 mem::Reference *managedThreadRef_ {nullptr}; 70 sampler::ThreadSamplingInfo samplingInfo_ {}; 71 72 NO_COPY_SEMANTIC(PtThreadInfo); 73 NO_MOVE_SEMANTIC(PtThreadInfo); 74 }; 75 } // namespace ark::tooling 76 77 #endif // PANDA_RUNTIME_TOOLING_PT_THREAD_INFO_H 78