11cb0ef41Sopenharmony_ci// Copyright 2019 the V8 project authors. All rights reserved. 21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be 31cb0ef41Sopenharmony_ci// found in the LICENSE file. 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ci#include "heap-constants.h" 61cb0ef41Sopenharmony_ci#include "src/common/globals.h" 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_cinamespace d = v8::debug_helper; 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_cinamespace v8 { 111cb0ef41Sopenharmony_cinamespace internal { 121cb0ef41Sopenharmony_cinamespace debug_helper_internal { 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_cistd::string FindKnownObject(uintptr_t address, 151cb0ef41Sopenharmony_ci const d::HeapAddresses& heap_addresses) { 161cb0ef41Sopenharmony_ci uintptr_t containing_page = address & ~i::kPageAlignmentMask; 171cb0ef41Sopenharmony_ci uintptr_t offset_in_page = address & i::kPageAlignmentMask; 181cb0ef41Sopenharmony_ci 191cb0ef41Sopenharmony_ci // If there's a match with a known page, then search only that page. 201cb0ef41Sopenharmony_ci if (containing_page == heap_addresses.map_space_first_page) { 211cb0ef41Sopenharmony_ci return FindKnownObjectInMapSpace(offset_in_page); 221cb0ef41Sopenharmony_ci } 231cb0ef41Sopenharmony_ci if (containing_page == heap_addresses.old_space_first_page) { 241cb0ef41Sopenharmony_ci return FindKnownObjectInOldSpace(offset_in_page); 251cb0ef41Sopenharmony_ci } 261cb0ef41Sopenharmony_ci if (containing_page == heap_addresses.read_only_space_first_page) { 271cb0ef41Sopenharmony_ci return FindKnownObjectInReadOnlySpace(offset_in_page); 281cb0ef41Sopenharmony_ci } 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_ci // For any unknown pages, compile a list of things this object might be. 311cb0ef41Sopenharmony_ci std::string result; 321cb0ef41Sopenharmony_ci if (heap_addresses.map_space_first_page == 0) { 331cb0ef41Sopenharmony_ci std::string sub_result = FindKnownObjectInMapSpace(offset_in_page); 341cb0ef41Sopenharmony_ci if (!sub_result.empty()) { 351cb0ef41Sopenharmony_ci result += "maybe " + sub_result; 361cb0ef41Sopenharmony_ci } 371cb0ef41Sopenharmony_ci } 381cb0ef41Sopenharmony_ci if (heap_addresses.old_space_first_page == 0) { 391cb0ef41Sopenharmony_ci std::string sub_result = FindKnownObjectInOldSpace(offset_in_page); 401cb0ef41Sopenharmony_ci if (!sub_result.empty()) { 411cb0ef41Sopenharmony_ci result = (result.empty() ? "" : result + ", ") + "maybe " + sub_result; 421cb0ef41Sopenharmony_ci } 431cb0ef41Sopenharmony_ci } 441cb0ef41Sopenharmony_ci if (heap_addresses.read_only_space_first_page == 0) { 451cb0ef41Sopenharmony_ci std::string sub_result = FindKnownObjectInReadOnlySpace(offset_in_page); 461cb0ef41Sopenharmony_ci if (!sub_result.empty()) { 471cb0ef41Sopenharmony_ci result = (result.empty() ? "" : result + ", ") + "maybe " + sub_result; 481cb0ef41Sopenharmony_ci } 491cb0ef41Sopenharmony_ci } 501cb0ef41Sopenharmony_ci 511cb0ef41Sopenharmony_ci return result; 521cb0ef41Sopenharmony_ci} 531cb0ef41Sopenharmony_ci 541cb0ef41Sopenharmony_ciKnownInstanceType FindKnownMapInstanceTypes( 551cb0ef41Sopenharmony_ci uintptr_t address, const d::HeapAddresses& heap_addresses) { 561cb0ef41Sopenharmony_ci uintptr_t containing_page = address & ~i::kPageAlignmentMask; 571cb0ef41Sopenharmony_ci uintptr_t offset_in_page = address & i::kPageAlignmentMask; 581cb0ef41Sopenharmony_ci 591cb0ef41Sopenharmony_ci // If there's a match with a known page, then search only that page. 601cb0ef41Sopenharmony_ci if (containing_page == heap_addresses.map_space_first_page) { 611cb0ef41Sopenharmony_ci return KnownInstanceType( 621cb0ef41Sopenharmony_ci FindKnownMapInstanceTypeInMapSpace(offset_in_page)); 631cb0ef41Sopenharmony_ci } 641cb0ef41Sopenharmony_ci if (containing_page == heap_addresses.old_space_first_page) { 651cb0ef41Sopenharmony_ci return KnownInstanceType( 661cb0ef41Sopenharmony_ci FindKnownMapInstanceTypeInOldSpace(offset_in_page)); 671cb0ef41Sopenharmony_ci } 681cb0ef41Sopenharmony_ci if (containing_page == heap_addresses.read_only_space_first_page) { 691cb0ef41Sopenharmony_ci return KnownInstanceType( 701cb0ef41Sopenharmony_ci FindKnownMapInstanceTypeInReadOnlySpace(offset_in_page)); 711cb0ef41Sopenharmony_ci } 721cb0ef41Sopenharmony_ci 731cb0ef41Sopenharmony_ci // For any unknown pages, compile a list of things this object might be. 741cb0ef41Sopenharmony_ci KnownInstanceType result; 751cb0ef41Sopenharmony_ci if (heap_addresses.map_space_first_page == 0) { 761cb0ef41Sopenharmony_ci int sub_result = FindKnownMapInstanceTypeInMapSpace(offset_in_page); 771cb0ef41Sopenharmony_ci if (sub_result >= 0) { 781cb0ef41Sopenharmony_ci result.types.push_back(static_cast<i::InstanceType>(sub_result)); 791cb0ef41Sopenharmony_ci } 801cb0ef41Sopenharmony_ci } 811cb0ef41Sopenharmony_ci if (heap_addresses.old_space_first_page == 0) { 821cb0ef41Sopenharmony_ci int sub_result = FindKnownMapInstanceTypeInOldSpace(offset_in_page); 831cb0ef41Sopenharmony_ci if (sub_result >= 0) { 841cb0ef41Sopenharmony_ci result.types.push_back(static_cast<i::InstanceType>(sub_result)); 851cb0ef41Sopenharmony_ci } 861cb0ef41Sopenharmony_ci } 871cb0ef41Sopenharmony_ci if (heap_addresses.read_only_space_first_page == 0) { 881cb0ef41Sopenharmony_ci int sub_result = FindKnownMapInstanceTypeInReadOnlySpace(offset_in_page); 891cb0ef41Sopenharmony_ci if (sub_result >= 0) { 901cb0ef41Sopenharmony_ci result.types.push_back(static_cast<i::InstanceType>(sub_result)); 911cb0ef41Sopenharmony_ci } 921cb0ef41Sopenharmony_ci } 931cb0ef41Sopenharmony_ci 941cb0ef41Sopenharmony_ci return result; 951cb0ef41Sopenharmony_ci} 961cb0ef41Sopenharmony_ci 971cb0ef41Sopenharmony_ci} // namespace debug_helper_internal 981cb0ef41Sopenharmony_ci} // namespace internal 991cb0ef41Sopenharmony_ci} // namespace v8 100