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