offline_profiling_info.cc revision fe297a96bc6d3da11579709add9b4568730d2b4f
1/* 2 * Copyright (C) 2015 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 "offline_profiling_info.h" 18 19#include "errno.h" 20#include <limits.h> 21#include <vector> 22#include <sys/file.h> 23#include <sys/stat.h> 24#include <sys/uio.h> 25 26#include "art_method-inl.h" 27#include "base/mutex.h" 28#include "base/scoped_flock.h" 29#include "base/stl_util.h" 30#include "base/systrace.h" 31#include "base/unix_file/fd_file.h" 32#include "jit/profiling_info.h" 33#include "os.h" 34#include "safe_map.h" 35 36namespace art { 37 38const uint8_t ProfileCompilationInfo::kProfileMagic[] = { 'p', 'r', 'o', '\0' }; 39const uint8_t ProfileCompilationInfo::kProfileVersion[] = { '0', '0', '1', '\0' }; 40 41static constexpr uint16_t kMaxDexFileKeyLength = PATH_MAX; 42 43// Transform the actual dex location into relative paths. 44// Note: this is OK because we don't store profiles of different apps into the same file. 45// Apps with split apks don't cause trouble because each split has a different name and will not 46// collide with other entries. 47std::string ProfileCompilationInfo::GetProfileDexFileKey(const std::string& dex_location) { 48 DCHECK(!dex_location.empty()); 49 size_t last_sep_index = dex_location.find_last_of('/'); 50 if (last_sep_index == std::string::npos) { 51 return dex_location; 52 } else { 53 DCHECK(last_sep_index < dex_location.size()); 54 return dex_location.substr(last_sep_index + 1); 55 } 56} 57 58bool ProfileCompilationInfo::AddMethodsAndClasses( 59 const std::vector<ArtMethod*>& methods, 60 const std::set<DexCacheResolvedClasses>& resolved_classes) { 61 ScopedObjectAccess soa(Thread::Current()); 62 for (ArtMethod* method : methods) { 63 const DexFile* dex_file = method->GetDexFile(); 64 if (!AddMethodIndex(GetProfileDexFileKey(dex_file->GetLocation()), 65 dex_file->GetLocationChecksum(), 66 method->GetDexMethodIndex())) { 67 return false; 68 } 69 } 70 for (const DexCacheResolvedClasses& dex_cache : resolved_classes) { 71 if (!AddResolvedClasses(dex_cache)) { 72 return false; 73 } 74 } 75 return true; 76} 77 78bool ProfileCompilationInfo::MergeAndSave(const std::string& filename, 79 uint64_t* bytes_written, 80 bool force) { 81 ScopedTrace trace(__PRETTY_FUNCTION__); 82 ScopedFlock flock; 83 std::string error; 84 if (!flock.Init(filename.c_str(), O_RDWR | O_NOFOLLOW | O_CLOEXEC, /* block */ false, &error)) { 85 LOG(WARNING) << "Couldn't lock the profile file " << filename << ": " << error; 86 return false; 87 } 88 89 int fd = flock.GetFile()->Fd(); 90 91 // Load the file but keep a copy around to be able to infer if the content has changed. 92 ProfileCompilationInfo fileInfo; 93 ProfileLoadSatus status = fileInfo.LoadInternal(fd, &error); 94 if (status == kProfileLoadSuccess) { 95 // Merge the content of file into the current object. 96 if (MergeWith(fileInfo)) { 97 // If after the merge we have the same data as what is the file there's no point 98 // in actually doing the write. The file will be exactly the same as before. 99 if (Equals(fileInfo)) { 100 if (bytes_written != nullptr) { 101 *bytes_written = 0; 102 } 103 return true; 104 } 105 } else { 106 LOG(WARNING) << "Could not merge previous profile data from file " << filename; 107 if (!force) { 108 return false; 109 } 110 } 111 } else if (force && 112 ((status == kProfileLoadVersionMismatch) || (status == kProfileLoadBadData))) { 113 // Log a warning but don't return false. We will clear the profile anyway. 114 LOG(WARNING) << "Clearing bad or obsolete profile data from file " 115 << filename << ": " << error; 116 } else { 117 LOG(WARNING) << "Could not load profile data from file " << filename << ": " << error; 118 return false; 119 } 120 121 // We need to clear the data because we don't support appending to the profiles yet. 122 if (!flock.GetFile()->ClearContent()) { 123 PLOG(WARNING) << "Could not clear profile file: " << filename; 124 return false; 125 } 126 127 // This doesn't need locking because we are trying to lock the file for exclusive 128 // access and fail immediately if we can't. 129 bool result = Save(fd); 130 if (result) { 131 VLOG(profiler) << "Successfully saved profile info to " << filename 132 << " Size: " << GetFileSizeBytes(filename); 133 if (bytes_written != nullptr) { 134 *bytes_written = GetFileSizeBytes(filename); 135 } 136 } else { 137 VLOG(profiler) << "Failed to save profile info to " << filename; 138 } 139 return result; 140} 141 142// Returns true if all the bytes were successfully written to the file descriptor. 143static bool WriteBuffer(int fd, const uint8_t* buffer, size_t byte_count) { 144 while (byte_count > 0) { 145 int bytes_written = TEMP_FAILURE_RETRY(write(fd, buffer, byte_count)); 146 if (bytes_written == -1) { 147 return false; 148 } 149 byte_count -= bytes_written; // Reduce the number of remaining bytes. 150 buffer += bytes_written; // Move the buffer forward. 151 } 152 return true; 153} 154 155// Add the string bytes to the buffer. 156static void AddStringToBuffer(std::vector<uint8_t>* buffer, const std::string& value) { 157 buffer->insert(buffer->end(), value.begin(), value.end()); 158} 159 160// Insert each byte, from low to high into the buffer. 161template <typename T> 162static void AddUintToBuffer(std::vector<uint8_t>* buffer, T value) { 163 for (size_t i = 0; i < sizeof(T); i++) { 164 buffer->push_back((value >> (i * kBitsPerByte)) & 0xff); 165 } 166} 167 168static constexpr size_t kLineHeaderSize = 169 3 * sizeof(uint16_t) + // method_set.size + class_set.size + dex_location.size 170 sizeof(uint32_t); // checksum 171 172/** 173 * Serialization format: 174 * magic,version,number_of_lines 175 * dex_location1,number_of_methods1,number_of_classes1,dex_location_checksum1, \ 176 * method_id11,method_id12...,class_id1,class_id2... 177 * dex_location2,number_of_methods2,number_of_classes2,dex_location_checksum2, \ 178 * method_id21,method_id22...,,class_id1,class_id2... 179 * ..... 180 **/ 181bool ProfileCompilationInfo::Save(int fd) { 182 ScopedTrace trace(__PRETTY_FUNCTION__); 183 DCHECK_GE(fd, 0); 184 185 // Cache at most 5KB before writing. 186 static constexpr size_t kMaxSizeToKeepBeforeWriting = 5 * KB; 187 // Use a vector wrapper to avoid keeping track of offsets when we add elements. 188 std::vector<uint8_t> buffer; 189 WriteBuffer(fd, kProfileMagic, sizeof(kProfileMagic)); 190 WriteBuffer(fd, kProfileVersion, sizeof(kProfileVersion)); 191 AddUintToBuffer(&buffer, static_cast<uint16_t>(info_.size())); 192 193 for (const auto& it : info_) { 194 if (buffer.size() > kMaxSizeToKeepBeforeWriting) { 195 if (!WriteBuffer(fd, buffer.data(), buffer.size())) { 196 return false; 197 } 198 buffer.clear(); 199 } 200 const std::string& dex_location = it.first; 201 const DexFileData& dex_data = it.second; 202 if (dex_data.method_set.empty() && dex_data.class_set.empty()) { 203 continue; 204 } 205 206 if (dex_location.size() >= kMaxDexFileKeyLength) { 207 LOG(WARNING) << "DexFileKey exceeds allocated limit"; 208 return false; 209 } 210 211 // Make sure that the buffer has enough capacity to avoid repeated resizings 212 // while we add data. 213 size_t required_capacity = buffer.size() + 214 kLineHeaderSize + 215 dex_location.size() + 216 sizeof(uint16_t) * (dex_data.class_set.size() + dex_data.method_set.size()); 217 218 buffer.reserve(required_capacity); 219 220 DCHECK_LE(dex_location.size(), std::numeric_limits<uint16_t>::max()); 221 DCHECK_LE(dex_data.method_set.size(), std::numeric_limits<uint16_t>::max()); 222 DCHECK_LE(dex_data.class_set.size(), std::numeric_limits<uint16_t>::max()); 223 AddUintToBuffer(&buffer, static_cast<uint16_t>(dex_location.size())); 224 AddUintToBuffer(&buffer, static_cast<uint16_t>(dex_data.method_set.size())); 225 AddUintToBuffer(&buffer, static_cast<uint16_t>(dex_data.class_set.size())); 226 AddUintToBuffer(&buffer, dex_data.checksum); // uint32_t 227 228 AddStringToBuffer(&buffer, dex_location); 229 230 for (auto method_it : dex_data.method_set) { 231 AddUintToBuffer(&buffer, method_it); 232 } 233 for (auto class_id : dex_data.class_set) { 234 AddUintToBuffer(&buffer, class_id); 235 } 236 DCHECK_EQ(required_capacity, buffer.size()) 237 << "Failed to add the expected number of bytes in the buffer"; 238 } 239 240 return WriteBuffer(fd, buffer.data(), buffer.size()); 241} 242 243ProfileCompilationInfo::DexFileData* ProfileCompilationInfo::GetOrAddDexFileData( 244 const std::string& dex_location, 245 uint32_t checksum) { 246 auto info_it = info_.find(dex_location); 247 if (info_it == info_.end()) { 248 info_it = info_.Put(dex_location, DexFileData(checksum)); 249 } 250 if (info_it->second.checksum != checksum) { 251 LOG(WARNING) << "Checksum mismatch for dex " << dex_location; 252 return nullptr; 253 } 254 return &info_it->second; 255} 256 257bool ProfileCompilationInfo::AddResolvedClasses(const DexCacheResolvedClasses& classes) { 258 const std::string dex_location = GetProfileDexFileKey(classes.GetDexLocation()); 259 const uint32_t checksum = classes.GetLocationChecksum(); 260 DexFileData* const data = GetOrAddDexFileData(dex_location, checksum); 261 if (data == nullptr) { 262 return false; 263 } 264 data->class_set.insert(classes.GetClasses().begin(), classes.GetClasses().end()); 265 return true; 266} 267 268bool ProfileCompilationInfo::AddMethodIndex(const std::string& dex_location, 269 uint32_t checksum, 270 uint16_t method_idx) { 271 DexFileData* const data = GetOrAddDexFileData(dex_location, checksum); 272 if (data == nullptr) { 273 return false; 274 } 275 data->method_set.insert(method_idx); 276 return true; 277} 278 279bool ProfileCompilationInfo::AddClassIndex(const std::string& dex_location, 280 uint32_t checksum, 281 uint16_t class_idx) { 282 DexFileData* const data = GetOrAddDexFileData(dex_location, checksum); 283 if (data == nullptr) { 284 return false; 285 } 286 data->class_set.insert(class_idx); 287 return true; 288} 289 290bool ProfileCompilationInfo::ProcessLine(SafeBuffer& line_buffer, 291 uint16_t method_set_size, 292 uint16_t class_set_size, 293 uint32_t checksum, 294 const std::string& dex_location) { 295 for (uint16_t i = 0; i < method_set_size; i++) { 296 uint16_t method_idx = line_buffer.ReadUintAndAdvance<uint16_t>(); 297 if (!AddMethodIndex(dex_location, checksum, method_idx)) { 298 return false; 299 } 300 } 301 302 for (uint16_t i = 0; i < class_set_size; i++) { 303 uint16_t class_def_idx = line_buffer.ReadUintAndAdvance<uint16_t>(); 304 if (!AddClassIndex(dex_location, checksum, class_def_idx)) { 305 return false; 306 } 307 } 308 return true; 309} 310 311// Tests for EOF by trying to read 1 byte from the descriptor. 312// Returns: 313// 0 if the descriptor is at the EOF, 314// -1 if there was an IO error 315// 1 if the descriptor has more content to read 316static int testEOF(int fd) { 317 uint8_t buffer[1]; 318 return TEMP_FAILURE_RETRY(read(fd, buffer, 1)); 319} 320 321// Reads an uint value previously written with AddUintToBuffer. 322template <typename T> 323T ProfileCompilationInfo::SafeBuffer::ReadUintAndAdvance() { 324 static_assert(std::is_unsigned<T>::value, "Type is not unsigned"); 325 CHECK_LE(ptr_current_ + sizeof(T), ptr_end_); 326 T value = 0; 327 for (size_t i = 0; i < sizeof(T); i++) { 328 value += ptr_current_[i] << (i * kBitsPerByte); 329 } 330 ptr_current_ += sizeof(T); 331 return value; 332} 333 334bool ProfileCompilationInfo::SafeBuffer::CompareAndAdvance(const uint8_t* data, size_t data_size) { 335 if (ptr_current_ + data_size > ptr_end_) { 336 return false; 337 } 338 if (memcmp(ptr_current_, data, data_size) == 0) { 339 ptr_current_ += data_size; 340 return true; 341 } 342 return false; 343} 344 345ProfileCompilationInfo::ProfileLoadSatus ProfileCompilationInfo::SafeBuffer::FillFromFd( 346 int fd, 347 const std::string& source, 348 /*out*/std::string* error) { 349 size_t byte_count = ptr_end_ - ptr_current_; 350 uint8_t* buffer = ptr_current_; 351 while (byte_count > 0) { 352 int bytes_read = TEMP_FAILURE_RETRY(read(fd, buffer, byte_count)); 353 if (bytes_read == 0) { 354 *error += "Profile EOF reached prematurely for " + source; 355 return kProfileLoadBadData; 356 } else if (bytes_read < 0) { 357 *error += "Profile IO error for " + source + strerror(errno); 358 return kProfileLoadIOError; 359 } 360 byte_count -= bytes_read; 361 buffer += bytes_read; 362 } 363 return kProfileLoadSuccess; 364} 365 366ProfileCompilationInfo::ProfileLoadSatus ProfileCompilationInfo::ReadProfileHeader( 367 int fd, 368 /*out*/uint16_t* number_of_lines, 369 /*out*/std::string* error) { 370 // Read magic and version 371 const size_t kMagicVersionSize = 372 sizeof(kProfileMagic) + 373 sizeof(kProfileVersion) + 374 sizeof(uint16_t); // number of lines 375 376 SafeBuffer safe_buffer(kMagicVersionSize); 377 378 ProfileLoadSatus status = safe_buffer.FillFromFd(fd, "ReadProfileHeader", error); 379 if (status != kProfileLoadSuccess) { 380 return status; 381 } 382 383 if (!safe_buffer.CompareAndAdvance(kProfileMagic, sizeof(kProfileMagic))) { 384 *error = "Profile missing magic"; 385 return kProfileLoadVersionMismatch; 386 } 387 if (!safe_buffer.CompareAndAdvance(kProfileVersion, sizeof(kProfileVersion))) { 388 *error = "Profile version mismatch"; 389 return kProfileLoadVersionMismatch; 390 } 391 *number_of_lines = safe_buffer.ReadUintAndAdvance<uint16_t>(); 392 return kProfileLoadSuccess; 393} 394 395ProfileCompilationInfo::ProfileLoadSatus ProfileCompilationInfo::ReadProfileLineHeader( 396 int fd, 397 /*out*/ProfileLineHeader* line_header, 398 /*out*/std::string* error) { 399 SafeBuffer header_buffer(kLineHeaderSize); 400 ProfileLoadSatus status = header_buffer.FillFromFd(fd, "ReadProfileHeader", error); 401 if (status != kProfileLoadSuccess) { 402 return status; 403 } 404 405 uint16_t dex_location_size = header_buffer.ReadUintAndAdvance<uint16_t>(); 406 line_header->method_set_size = header_buffer.ReadUintAndAdvance<uint16_t>(); 407 line_header->class_set_size = header_buffer.ReadUintAndAdvance<uint16_t>(); 408 line_header->checksum = header_buffer.ReadUintAndAdvance<uint32_t>(); 409 410 if (dex_location_size == 0 || dex_location_size > kMaxDexFileKeyLength) { 411 *error = "DexFileKey has an invalid size: " + std::to_string(dex_location_size); 412 return kProfileLoadBadData; 413 } 414 415 SafeBuffer location_buffer(dex_location_size); 416 status = location_buffer.FillFromFd(fd, "ReadProfileHeaderDexLocation", error); 417 if (status != kProfileLoadSuccess) { 418 return status; 419 } 420 line_header->dex_location.assign( 421 reinterpret_cast<char*>(location_buffer.Get()), dex_location_size); 422 return kProfileLoadSuccess; 423} 424 425ProfileCompilationInfo::ProfileLoadSatus ProfileCompilationInfo::ReadProfileLine( 426 int fd, 427 const ProfileLineHeader& line_header, 428 /*out*/std::string* error) { 429 // Make sure that we don't try to read everything in memory (in case the profile if full). 430 // Split readings in chunks of at most 10kb. 431 static constexpr uint16_t kMaxNumberOfEntriesToRead = 5120; 432 uint16_t methods_left_to_read = line_header.method_set_size; 433 uint16_t classes_left_to_read = line_header.class_set_size; 434 435 while ((methods_left_to_read > 0) || (classes_left_to_read > 0)) { 436 uint16_t methods_to_read = std::min(kMaxNumberOfEntriesToRead, methods_left_to_read); 437 uint16_t max_classes_to_read = kMaxNumberOfEntriesToRead - methods_to_read; 438 uint16_t classes_to_read = std::min(max_classes_to_read, classes_left_to_read); 439 440 size_t line_size = sizeof(uint16_t) * (methods_to_read + classes_to_read); 441 SafeBuffer line_buffer(line_size); 442 443 ProfileLoadSatus status = line_buffer.FillFromFd(fd, "ReadProfileLine", error); 444 if (status != kProfileLoadSuccess) { 445 return status; 446 } 447 if (!ProcessLine(line_buffer, 448 methods_to_read, 449 classes_to_read, 450 line_header.checksum, 451 line_header.dex_location)) { 452 *error = "Error when reading profile file line"; 453 return kProfileLoadBadData; 454 } 455 methods_left_to_read -= methods_to_read; 456 classes_left_to_read -= classes_to_read; 457 } 458 return kProfileLoadSuccess; 459} 460 461bool ProfileCompilationInfo::Load(int fd) { 462 std::string error; 463 ProfileLoadSatus status = LoadInternal(fd, &error); 464 465 if (status == kProfileLoadSuccess) { 466 return true; 467 } else { 468 PLOG(WARNING) << "Error when reading profile " << error; 469 return false; 470 } 471} 472 473ProfileCompilationInfo::ProfileLoadSatus ProfileCompilationInfo::LoadInternal( 474 int fd, std::string* error) { 475 ScopedTrace trace(__PRETTY_FUNCTION__); 476 DCHECK_GE(fd, 0); 477 478 struct stat stat_buffer; 479 if (fstat(fd, &stat_buffer) != 0) { 480 return kProfileLoadIOError; 481 } 482 // We allow empty profile files. 483 // Profiles may be created by ActivityManager or installd before we manage to 484 // process them in the runtime or profman. 485 if (stat_buffer.st_size == 0) { 486 return kProfileLoadSuccess; 487 } 488 // Read profile header: magic + version + number_of_lines. 489 uint16_t number_of_lines; 490 ProfileLoadSatus status = ReadProfileHeader(fd, &number_of_lines, error); 491 if (status != kProfileLoadSuccess) { 492 return status; 493 } 494 495 while (number_of_lines > 0) { 496 ProfileLineHeader line_header; 497 // First, read the line header to get the amount of data we need to read. 498 status = ReadProfileLineHeader(fd, &line_header, error); 499 if (status != kProfileLoadSuccess) { 500 return status; 501 } 502 503 // Now read the actual profile line. 504 status = ReadProfileLine(fd, line_header, error); 505 if (status != kProfileLoadSuccess) { 506 return status; 507 } 508 number_of_lines--; 509 } 510 511 // Check that we read everything and that profiles don't contain junk data. 512 int result = testEOF(fd); 513 if (result == 0) { 514 return kProfileLoadSuccess; 515 } else if (result < 0) { 516 return kProfileLoadIOError; 517 } else { 518 *error = "Unexpected content in the profile file"; 519 return kProfileLoadBadData; 520 } 521} 522 523bool ProfileCompilationInfo::MergeWith(const ProfileCompilationInfo& other) { 524 // First verify that all checksums match. This will avoid adding garbage to 525 // the current profile info. 526 // Note that the number of elements should be very small, so this should not 527 // be a performance issue. 528 for (const auto& other_it : other.info_) { 529 auto info_it = info_.find(other_it.first); 530 if ((info_it != info_.end()) && (info_it->second.checksum != other_it.second.checksum)) { 531 LOG(WARNING) << "Checksum mismatch for dex " << other_it.first; 532 return false; 533 } 534 } 535 // All checksums match. Import the data. 536 for (const auto& other_it : other.info_) { 537 const std::string& other_dex_location = other_it.first; 538 const DexFileData& other_dex_data = other_it.second; 539 auto info_it = info_.find(other_dex_location); 540 if (info_it == info_.end()) { 541 info_it = info_.Put(other_dex_location, DexFileData(other_dex_data.checksum)); 542 } 543 info_it->second.method_set.insert(other_dex_data.method_set.begin(), 544 other_dex_data.method_set.end()); 545 info_it->second.class_set.insert(other_dex_data.class_set.begin(), 546 other_dex_data.class_set.end()); 547 } 548 return true; 549} 550 551bool ProfileCompilationInfo::ContainsMethod(const MethodReference& method_ref) const { 552 auto info_it = info_.find(GetProfileDexFileKey(method_ref.dex_file->GetLocation())); 553 if (info_it != info_.end()) { 554 if (method_ref.dex_file->GetLocationChecksum() != info_it->second.checksum) { 555 return false; 556 } 557 const std::set<uint16_t>& methods = info_it->second.method_set; 558 return methods.find(method_ref.dex_method_index) != methods.end(); 559 } 560 return false; 561} 562 563uint32_t ProfileCompilationInfo::GetNumberOfMethods() const { 564 uint32_t total = 0; 565 for (const auto& it : info_) { 566 total += it.second.method_set.size(); 567 } 568 return total; 569} 570 571uint32_t ProfileCompilationInfo::GetNumberOfResolvedClasses() const { 572 uint32_t total = 0; 573 for (const auto& it : info_) { 574 total += it.second.class_set.size(); 575 } 576 return total; 577} 578 579std::string ProfileCompilationInfo::DumpInfo(const std::vector<const DexFile*>* dex_files, 580 bool print_full_dex_location) const { 581 std::ostringstream os; 582 if (info_.empty()) { 583 return "ProfileInfo: empty"; 584 } 585 586 os << "ProfileInfo:"; 587 588 const std::string kFirstDexFileKeySubstitute = ":classes.dex"; 589 for (const auto& it : info_) { 590 os << "\n"; 591 const std::string& location = it.first; 592 const DexFileData& dex_data = it.second; 593 if (print_full_dex_location) { 594 os << location; 595 } else { 596 // Replace the (empty) multidex suffix of the first key with a substitute for easier reading. 597 std::string multidex_suffix = DexFile::GetMultiDexSuffix(location); 598 os << (multidex_suffix.empty() ? kFirstDexFileKeySubstitute : multidex_suffix); 599 } 600 const DexFile* dex_file = nullptr; 601 if (dex_files != nullptr) { 602 for (size_t i = 0; i < dex_files->size(); i++) { 603 if (location == (*dex_files)[i]->GetLocation()) { 604 dex_file = (*dex_files)[i]; 605 } 606 } 607 } 608 os << "\n\tmethods: "; 609 for (const auto method_it : dex_data.method_set) { 610 if (dex_file != nullptr) { 611 os << "\n\t\t" << PrettyMethod(method_it, *dex_file, true); 612 } else { 613 os << method_it << ","; 614 } 615 } 616 os << "\n\tclasses: "; 617 for (const auto class_it : dex_data.class_set) { 618 if (dex_file != nullptr) { 619 os << "\n\t\t" << PrettyType(class_it, *dex_file); 620 } else { 621 os << class_it << ","; 622 } 623 } 624 } 625 return os.str(); 626} 627 628bool ProfileCompilationInfo::Equals(const ProfileCompilationInfo& other) { 629 return info_.Equals(other.info_); 630} 631 632std::set<DexCacheResolvedClasses> ProfileCompilationInfo::GetResolvedClasses() const { 633 std::set<DexCacheResolvedClasses> ret; 634 for (auto&& pair : info_) { 635 const std::string& profile_key = pair.first; 636 const DexFileData& data = pair.second; 637 DexCacheResolvedClasses classes(profile_key, data.checksum); 638 classes.AddClasses(data.class_set.begin(), data.class_set.end()); 639 ret.insert(classes); 640 } 641 return ret; 642} 643 644void ProfileCompilationInfo::ClearResolvedClasses() { 645 for (auto& pair : info_) { 646 pair.second.class_set.clear(); 647 } 648} 649 650} // namespace art 651