xref: /aosp_15_r20/art/profman/inline_cache_format_util.cc (revision 795d594fd825385562da6b089ea9b2033f3abf5a)
1 /*
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "inline_cache_format_util.h"
18 
19 #include "profile/profile_compilation_info.h"
20 
21 namespace art {
22 
GetInlineCacheLine(const SafeMap<TypeReference,FlattenProfileData::ItemMetadata::InlineCacheInfo,TypeReferenceValueComparator> & inline_cache)23 std::string GetInlineCacheLine(const SafeMap<TypeReference,
24                                              FlattenProfileData::ItemMetadata::InlineCacheInfo,
25                                              TypeReferenceValueComparator>& inline_cache) {
26   if (inline_cache.empty()) {
27     return "";
28   }
29   std::ostringstream dump_ic;
30   dump_ic << kProfileParsingInlineChacheSep;
31   for (const auto& [target_ref, inline_cache_data] : inline_cache) {
32     dump_ic << kProfileParsingInlineChacheTargetSep;
33     dump_ic << target_ref.dex_file->GetTypeDescriptor(
34         target_ref.dex_file->GetTypeId(target_ref.TypeIndex()));
35     if (inline_cache_data.is_missing_types_) {
36       dump_ic << kMissingTypesMarker;
37     } else if (inline_cache_data.is_megamorphic_) {
38       dump_ic << kMegamorphicTypesMarker;
39     } else {
40       bool first = true;
41       for (const std::string& cls : inline_cache_data.classes_) {
42         if (!first) {
43           dump_ic << kProfileParsingTypeSep;
44         }
45         first = false;
46         dump_ic << cls;
47       }
48     }
49   }
50   return dump_ic.str();
51 }
52 
53 }  // namespace art
54