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