diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-12 14:27:29 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-13 09:35:20 +0000 |
commit | c30a6232df03e1efbd9f3b226777b07e087a1122 (patch) | |
tree | e992f45784689f373bcc38d1b79a239ebe17ee23 /chromium/v8/src/heap/code-object-registry.cc | |
parent | 7b5b123ac58f58ffde0f4f6e488bcd09aa4decd3 (diff) | |
download | qtwebengine-chromium-85-based.tar.gz |
BASELINE: Update Chromium to 85.0.4183.14085-based
Change-Id: Iaa42f4680837c57725b1344f108c0196741f6057
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/v8/src/heap/code-object-registry.cc')
-rw-r--r-- | chromium/v8/src/heap/code-object-registry.cc | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/chromium/v8/src/heap/code-object-registry.cc b/chromium/v8/src/heap/code-object-registry.cc new file mode 100644 index 00000000000..ebaa29fbaeb --- /dev/null +++ b/chromium/v8/src/heap/code-object-registry.cc @@ -0,0 +1,75 @@ +// Copyright 2020 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "src/heap/code-object-registry.h" + +#include <algorithm> + +#include "src/base/logging.h" + +namespace v8 { +namespace internal { + +void CodeObjectRegistry::RegisterNewlyAllocatedCodeObject(Address code) { + auto result = code_object_registry_newly_allocated_.insert(code); + USE(result); + DCHECK(result.second); +} + +void CodeObjectRegistry::RegisterAlreadyExistingCodeObject(Address code) { + code_object_registry_already_existing_.push_back(code); +} + +void CodeObjectRegistry::Clear() { + code_object_registry_already_existing_.clear(); + code_object_registry_newly_allocated_.clear(); +} + +void CodeObjectRegistry::Finalize() { + code_object_registry_already_existing_.shrink_to_fit(); +} + +bool CodeObjectRegistry::Contains(Address object) const { + return (code_object_registry_newly_allocated_.find(object) != + code_object_registry_newly_allocated_.end()) || + (std::binary_search(code_object_registry_already_existing_.begin(), + code_object_registry_already_existing_.end(), + object)); +} + +Address CodeObjectRegistry::GetCodeObjectStartFromInnerAddress( + Address address) const { + // Let's first find the object which comes right before address in the vector + // of already existing code objects. + Address already_existing_set_ = 0; + Address newly_allocated_set_ = 0; + if (!code_object_registry_already_existing_.empty()) { + auto it = + std::upper_bound(code_object_registry_already_existing_.begin(), + code_object_registry_already_existing_.end(), address); + if (it != code_object_registry_already_existing_.begin()) { + already_existing_set_ = *(--it); + } + } + + // Next, let's find the object which comes right before address in the set + // of newly allocated code objects. + if (!code_object_registry_newly_allocated_.empty()) { + auto it = code_object_registry_newly_allocated_.upper_bound(address); + if (it != code_object_registry_newly_allocated_.begin()) { + newly_allocated_set_ = *(--it); + } + } + + // The code objects which contains address has to be in one of the two + // data structures. + DCHECK(already_existing_set_ != 0 || newly_allocated_set_ != 0); + + // The address which is closest to the given address is the code object. + return already_existing_set_ > newly_allocated_set_ ? already_existing_set_ + : newly_allocated_set_; +} + +} // namespace internal +} // namespace v8 |