• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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/pgo_profiler/types/pgo_profile_type.h"
17 #include "ecmascript/pgo_profiler/pgo_profiler_info.h"
18 
19 namespace panda::ecmascript::pgo {
20 const ProfileType ProfileType::PROFILE_TYPE_NONE = ProfileType(0, 0);
21 
ProfileTypeRef(PGOContext & context,const ProfileType & type)22 ProfileTypeRef::ProfileTypeRef(PGOContext &context, const ProfileType &type)
23 {
24     ApEntityId apId(0);
25     context.GetProfileTypePool()->TryAdd(type, apId);
26     UpdateId(apId);
27 }
28 
Remap(const PGOContext & context)29 ProfileTypeRef &ProfileTypeRef::Remap([[maybe_unused]] const PGOContext &context)
30 {
31     LOG_ECMA(ERROR) << "ProfileTypeRef do not support remapping";
32     UNREACHABLE();
33 }
34 
ProfileType(PGOContext & context,ProfileTypeRef typeRef,bool * isValid)35 ProfileType::ProfileType(PGOContext &context, ProfileTypeRef typeRef, bool *isValid)
36 {
37     if (isValid != nullptr) {
38         *isValid = true;
39     }
40     if (!context.GetHeader()->SupportWideProfileType()) {
41         ProfileTypeLegacy legacy(typeRef);
42         UpdateId(legacy.GetId());
43         UpdateKind(legacy.GetKind());
44         return;
45     }
46     const auto *typeEntry = context.GetProfileTypePool()->GetEntry(typeRef.GetId());
47     if (typeEntry == nullptr) {
48         if (isValid != nullptr) {
49             *isValid = false;
50         }
51         LOG_ECMA(ERROR) << "Profile type ref: " << typeRef.GetTypeString() << " not found in ap file.";
52     } else {
53         type_ = typeEntry->GetProfileType().GetRaw();
54     }
55 }
56 
Remap(const PGOContext & context)57 ProfileType &ProfileType::Remap([[maybe_unused]]const PGOContext &context)
58 {
59     if ((GetAbcId() >= PGOAbcFilePool::RESERVED_COUNT) && (!context.GetAbcIdRemap().empty())) {
60         UpdateAbcId(context.GetAbcIdRemap().at(GetAbcId()));
61     }
62     return *this;
63 }
64 } // namespace panda::ecmascript::pgo
65