11cb0ef41Sopenharmony_ci// Copyright 2020 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#ifndef V8_HEAP_CODE_OBJECT_REGISTRY_H_ 61cb0ef41Sopenharmony_ci#define V8_HEAP_CODE_OBJECT_REGISTRY_H_ 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ci#include <vector> 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ci#include "src/base/macros.h" 111cb0ef41Sopenharmony_ci#include "src/base/platform/mutex.h" 121cb0ef41Sopenharmony_ci#include "src/common/globals.h" 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_cinamespace v8 { 151cb0ef41Sopenharmony_cinamespace internal { 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ci// The CodeObjectRegistry holds all start addresses of code objects of a given 181cb0ef41Sopenharmony_ci// MemoryChunk. Each MemoryChunk owns a separate CodeObjectRegistry. The 191cb0ef41Sopenharmony_ci// CodeObjectRegistry allows fast lookup from an inner pointer of a code object 201cb0ef41Sopenharmony_ci// to the actual code object. 211cb0ef41Sopenharmony_ciclass V8_EXPORT_PRIVATE CodeObjectRegistry { 221cb0ef41Sopenharmony_ci public: 231cb0ef41Sopenharmony_ci void RegisterNewlyAllocatedCodeObject(Address code); 241cb0ef41Sopenharmony_ci void RegisterAlreadyExistingCodeObject(Address code); 251cb0ef41Sopenharmony_ci void Clear(); 261cb0ef41Sopenharmony_ci void Finalize(); 271cb0ef41Sopenharmony_ci bool Contains(Address code) const; 281cb0ef41Sopenharmony_ci Address GetCodeObjectStartFromInnerAddress(Address address) const; 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_ci private: 311cb0ef41Sopenharmony_ci // A vector of addresses, which may be sorted. This is set to 'mutable' so 321cb0ef41Sopenharmony_ci // that it can be lazily sorted during GetCodeObjectStartFromInnerAddress. 331cb0ef41Sopenharmony_ci mutable std::vector<Address> code_object_registry_; 341cb0ef41Sopenharmony_ci mutable bool is_sorted_ = true; 351cb0ef41Sopenharmony_ci mutable base::Mutex code_object_registry_mutex_; 361cb0ef41Sopenharmony_ci}; 371cb0ef41Sopenharmony_ci 381cb0ef41Sopenharmony_ci} // namespace internal 391cb0ef41Sopenharmony_ci} // namespace v8 401cb0ef41Sopenharmony_ci 411cb0ef41Sopenharmony_ci#endif // V8_HEAP_CODE_OBJECT_REGISTRY_H_ 42