[ext-code-space] Introduce managed-inl.h and global-handles-inl.h

... and move methods that use XXX::cast() there.
This will untangle the include cycle that'll happen in a follow-up CLs.

Bug: v8:11880
Change-Id: Iba46bc9b0e0df9530197f57d0469456eb9006e66
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3164456
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: Dominik Inführ <dinfuehr@chromium.org>
Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/main@{#76932}
This commit is contained in:
Igor Sheludko 2021-09-17 16:40:54 +02:00 committed by V8 LUCI CQ
parent f5eee56fa8
commit 8efa70f076
43 changed files with 154 additions and 62 deletions

View File

@ -2771,6 +2771,7 @@ v8_header_set("v8_internal_headers") {
"src/extensions/ignition-statistics-extension.h",
"src/extensions/statistics-extension.h",
"src/extensions/trigger-failure-extension.h",
"src/handles/global-handles-inl.h",
"src/handles/global-handles.h",
"src/handles/handles-inl.h",
"src/handles/handles.h",
@ -3024,6 +3025,7 @@ v8_header_set("v8_internal_headers") {
"src/objects/lookup-cache.h",
"src/objects/lookup-inl.h",
"src/objects/lookup.h",
"src/objects/managed-inl.h",
"src/objects/managed.h",
"src/objects/map-inl.h",
"src/objects/map-updater.h",

View File

@ -12,6 +12,7 @@
#include "src/baseline/baseline-compiler.h"
#include "src/codegen/compiler.h"
#include "src/execution/isolate.h"
#include "src/handles/global-handles-inl.h"
#include "src/heap/factory-inl.h"
#include "src/heap/heap-inl.h"
#include "src/objects/fixed-array-inl.h"

View File

@ -10,7 +10,7 @@
#include "src/debug/debug.h"
#include "src/execution/isolate.h"
#include "src/execution/protectors-inl.h"
#include "src/handles/global-handles.h"
#include "src/handles/global-handles-inl.h"
#include "src/logging/counters.h"
#include "src/objects/contexts.h"
#include "src/objects/elements-inl.h"

View File

@ -8,7 +8,7 @@
#include "src/base/platform/time.h"
#include "src/codegen/compiler.h"
#include "src/flags/flags.h"
#include "src/handles/global-handles.h"
#include "src/handles/global-handles-inl.h"
#include "src/logging/counters.h"
#include "src/logging/runtime-call-stats-scope.h"
#include "src/objects/objects-inl.h"

View File

@ -52,7 +52,7 @@
#include "src/interpreter/interpreter.h"
#include "src/logging/counters.h"
#include "src/logging/log-utils.h"
#include "src/objects/managed.h"
#include "src/objects/managed-inl.h"
#include "src/objects/objects-inl.h"
#include "src/objects/objects.h"
#include "src/parsing/parse-info.h"

View File

@ -24,7 +24,7 @@
#include "src/execution/frames-inl.h"
#include "src/execution/isolate-inl.h"
#include "src/execution/v8threads.h"
#include "src/handles/global-handles.h"
#include "src/handles/global-handles-inl.h"
#include "src/heap/heap-inl.h" // For NextDebuggingId.
#include "src/init/bootstrapper.h"
#include "src/interpreter/bytecode-array-iterator.h"

View File

@ -52,6 +52,7 @@
#include "src/execution/simulator.h"
#include "src/execution/v8threads.h"
#include "src/execution/vm-state-inl.h"
#include "src/handles/global-handles-inl.h"
#include "src/handles/persistent-handles.h"
#include "src/heap/heap-inl.h"
#include "src/heap/read-only-heap.h"
@ -74,6 +75,7 @@
#include "src/objects/js-array-inl.h"
#include "src/objects/js-generator-inl.h"
#include "src/objects/js-weak-refs-inl.h"
#include "src/objects/managed-inl.h"
#include "src/objects/module-inl.h"
#include "src/objects/promise-inl.h"
#include "src/objects/prototype.h"

View File

@ -0,0 +1,33 @@
// Copyright 2021 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.
#ifndef V8_HANDLES_GLOBAL_HANDLES_INL_H_
#define V8_HANDLES_GLOBAL_HANDLES_INL_H_
#include "src/handles/global-handles.h"
#include "src/handles/handles-inl.h"
#include "src/objects/heap-object-inl.h"
namespace v8 {
namespace internal {
template <typename T>
Handle<T> GlobalHandles::Create(T value) {
static_assert(std::is_base_of<Object, T>::value, "static type violation");
// The compiler should only pick this method if T is not Object.
static_assert(!std::is_same<Object, T>::value, "compiler error");
return Handle<T>::cast(Create(Object(value)));
}
template <typename T>
T GlobalHandleVector<T>::Pop() {
T obj = T::cast(Object(locations_.back()));
locations_.pop_back();
return obj;
}
} // namespace internal
} // namespace v8
#endif // V8_HANDLES_GLOBAL_HANDLES_INL_H_

View File

@ -15,6 +15,7 @@
#include "include/v8-profiler.h"
#include "src/handles/handles.h"
#include "src/heap/heap.h"
#include "src/objects/heap-object.h"
#include "src/objects/objects.h"
#include "src/utils/utils.h"
@ -101,12 +102,7 @@ class V8_EXPORT_PRIVATE GlobalHandles final {
Handle<Object> Create(Address value);
template <typename T>
Handle<T> Create(T value) {
static_assert(std::is_base_of<Object, T>::value, "static type violation");
// The compiler should only pick this method if T is not Object.
static_assert(!std::is_same<Object, T>::value, "compiler error");
return Handle<T>::cast(Create(Object(value)));
}
inline Handle<T> Create(T value);
Handle<Object> CreateTraced(Object value, Address* slot, bool has_destructor,
bool is_on_stack);
@ -358,11 +354,7 @@ class GlobalHandleVector {
void Push(T val) { locations_.push_back(val.ptr()); }
// Handles into the GlobalHandleVector become invalid when they are removed,
// so "pop" returns a raw object rather than a handle.
T Pop() {
T obj = T::cast(Object(locations_.back()));
locations_.pop_back();
return obj;
}
inline T Pop();
Iterator begin() { return Iterator(locations_.begin()); }
Iterator end() { return Iterator(locations_.end()); }

View File

@ -31,7 +31,7 @@
#include "src/execution/runtime-profiler.h"
#include "src/execution/v8threads.h"
#include "src/execution/vm-state-inl.h"
#include "src/handles/global-handles.h"
#include "src/handles/global-handles-inl.h"
#include "src/heap/array-buffer-sweeper.h"
#include "src/heap/barrier.h"
#include "src/heap/base/stack.h"

View File

@ -7,6 +7,7 @@
#include "include/v8-local-handle.h"
#include "src/api/api-inl.h"
#include "src/execution/isolate-inl.h"
#include "src/handles/global-handles-inl.h"
#include "src/heap/factory-inl.h"
#include "src/heap/incremental-marking.h"
#include "src/heap/marking-worklist.h"

View File

@ -6,7 +6,7 @@
#define V8_OBJECTS_EMBEDDER_DATA_ARRAY_INL_H_
#include "src/objects/embedder-data-array.h"
#include "src/objects/heap-object-inl.h"
#include "src/objects/instance-type-inl.h"
#include "src/objects/maybe-object-inl.h"

View File

@ -23,6 +23,7 @@
#include "src/objects/js-locale-inl.h"
#include "src/objects/js-locale.h"
#include "src/objects/js-number-format-inl.h"
#include "src/objects/managed-inl.h"
#include "src/objects/objects-inl.h"
#include "src/objects/option-utils.h"
#include "src/objects/property-descriptor.h"

View File

@ -10,6 +10,7 @@
#include "src/objects/intl-objects.h"
#include "src/objects/js-break-iterator-inl.h"
#include "src/objects/managed-inl.h"
#include "src/objects/option-utils.h"
#include "unicode/brkiter.h"

View File

@ -11,6 +11,7 @@
#include "src/execution/isolate.h"
#include "src/objects/js-collator-inl.h"
#include "src/objects/js-locale.h"
#include "src/objects/managed-inl.h"
#include "src/objects/objects-inl.h"
#include "src/objects/option-utils.h"
#include "unicode/coll.h"

View File

@ -20,6 +20,7 @@
#include "src/heap/factory.h"
#include "src/objects/intl-objects.h"
#include "src/objects/js-date-time-format-inl.h"
#include "src/objects/managed-inl.h"
#include "src/objects/option-utils.h"
#include "unicode/calendar.h"
#include "unicode/dtitvfmt.h"

View File

@ -15,7 +15,7 @@
#include "src/heap/factory.h"
#include "src/objects/intl-objects.h"
#include "src/objects/js-display-names-inl.h"
#include "src/objects/managed.h"
#include "src/objects/managed-inl.h"
#include "src/objects/objects-inl.h"
#include "src/objects/option-utils.h"
#include "unicode/dtfmtsym.h"

View File

@ -18,7 +18,7 @@
#include "src/objects/intl-objects.h"
#include "src/objects/js-array-inl.h"
#include "src/objects/js-list-format-inl.h"
#include "src/objects/managed.h"
#include "src/objects/managed-inl.h"
#include "src/objects/objects-inl.h"
#include "src/objects/option-utils.h"
#include "unicode/fieldpos.h"

View File

@ -15,10 +15,10 @@
#include "src/api/api.h"
#include "src/execution/isolate.h"
#include "src/handles/global-handles.h"
#include "src/heap/factory.h"
#include "src/objects/intl-objects.h"
#include "src/objects/js-locale-inl.h"
#include "src/objects/managed-inl.h"
#include "src/objects/objects-inl.h"
#include "src/objects/option-utils.h"
#include "unicode/calendar.h"

View File

@ -14,6 +14,7 @@
#include "src/execution/isolate.h"
#include "src/objects/intl-objects.h"
#include "src/objects/js-number-format-inl.h"
#include "src/objects/managed-inl.h"
#include "src/objects/objects-inl.h"
#include "src/objects/option-utils.h"
#include "unicode/currunit.h"

View File

@ -12,6 +12,7 @@
#include "src/objects/intl-objects.h"
#include "src/objects/js-number-format.h"
#include "src/objects/js-plural-rules-inl.h"
#include "src/objects/managed-inl.h"
#include "src/objects/option-utils.h"
#include "unicode/locid.h"
#include "unicode/numberformatter.h"

View File

@ -17,6 +17,7 @@
#include "src/objects/intl-objects.h"
#include "src/objects/js-number-format.h"
#include "src/objects/js-relative-time-format-inl.h"
#include "src/objects/managed-inl.h"
#include "src/objects/objects-inl.h"
#include "src/objects/option-utils.h"
#include "unicode/decimfmt.h"

View File

@ -17,7 +17,7 @@
#include "src/objects/intl-objects.h"
#include "src/objects/js-segment-iterator-inl.h"
#include "src/objects/js-segments.h"
#include "src/objects/managed.h"
#include "src/objects/managed-inl.h"
#include "src/objects/objects-inl.h"
#include "unicode/brkiter.h"

View File

@ -16,7 +16,7 @@
#include "src/heap/factory.h"
#include "src/objects/intl-objects.h"
#include "src/objects/js-segmenter-inl.h"
#include "src/objects/managed.h"
#include "src/objects/managed-inl.h"
#include "src/objects/objects-inl.h"
#include "src/objects/option-utils.h"
#include "unicode/brkiter.h"

View File

@ -18,7 +18,7 @@
#include "src/objects/js-segment-iterator.h"
#include "src/objects/js-segmenter-inl.h"
#include "src/objects/js-segments-inl.h"
#include "src/objects/managed.h"
#include "src/objects/managed-inl.h"
#include "src/objects/objects-inl.h"
#include "unicode/brkiter.h"

64
src/objects/managed-inl.h Normal file
View File

@ -0,0 +1,64 @@
// Copyright 2021 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.
#ifndef V8_OBJECTS_MANAGED_INL_H_
#define V8_OBJECTS_MANAGED_INL_H_
#include "src/handles/global-handles-inl.h"
#include "src/objects/managed.h"
namespace v8 {
namespace internal {
// static
template <class CppType>
template <typename... Args>
Handle<Managed<CppType>> Managed<CppType>::Allocate(Isolate* isolate,
size_t estimated_size,
Args&&... args) {
return FromSharedPtr(isolate, estimated_size,
std::make_shared<CppType>(std::forward<Args>(args)...));
}
// static
template <class CppType>
Handle<Managed<CppType>> Managed<CppType>::FromRawPtr(Isolate* isolate,
size_t estimated_size,
CppType* ptr) {
return FromSharedPtr(isolate, estimated_size, std::shared_ptr<CppType>{ptr});
}
// static
template <class CppType>
Handle<Managed<CppType>> Managed<CppType>::FromUniquePtr(
Isolate* isolate, size_t estimated_size,
std::unique_ptr<CppType> unique_ptr) {
return FromSharedPtr(isolate, estimated_size, std::move(unique_ptr));
}
// static
template <class CppType>
Handle<Managed<CppType>> Managed<CppType>::FromSharedPtr(
Isolate* isolate, size_t estimated_size,
std::shared_ptr<CppType> shared_ptr) {
reinterpret_cast<v8::Isolate*>(isolate)
->AdjustAmountOfExternalAllocatedMemory(estimated_size);
auto destructor = new ManagedPtrDestructor(
estimated_size, new std::shared_ptr<CppType>{std::move(shared_ptr)},
Destructor);
Handle<Managed<CppType>> handle = Handle<Managed<CppType>>::cast(
isolate->factory()->NewForeign(reinterpret_cast<Address>(destructor)));
Handle<Object> global_handle = isolate->global_handles()->Create(*handle);
destructor->global_handle_location_ = global_handle.location();
GlobalHandles::MakeWeak(destructor->global_handle_location_, destructor,
&ManagedObjectFinalizer,
v8::WeakCallbackType::kParameter);
isolate->RegisterManagedPtrDestructor(destructor);
return handle;
}
} // namespace internal
} // namespace v8
#endif // V8_OBJECTS_MANAGED_INL_H_

View File

@ -4,6 +4,8 @@
#include "src/objects/managed.h"
#include "src/handles/global-handles-inl.h"
namespace v8 {
namespace internal {

View File

@ -7,7 +7,6 @@
#include <memory>
#include "src/execution/isolate.h"
#include "src/handles/global-handles.h"
#include "src/handles/handles.h"
#include "src/heap/factory.h"
#include "src/objects/foreign.h"
@ -65,49 +64,25 @@ class Managed : public Foreign {
template <typename... Args>
static Handle<Managed<CppType>> Allocate(Isolate* isolate,
size_t estimated_size,
Args&&... args) {
return FromSharedPtr(
isolate, estimated_size,
std::make_shared<CppType>(std::forward<Args>(args)...));
}
Args&&... args);
// Create a {Managed<CppType>} from an existing raw {CppType*}. The returned
// object will now own the memory pointed to by {CppType}.
static Handle<Managed<CppType>> FromRawPtr(Isolate* isolate,
size_t estimated_size,
CppType* ptr) {
return FromSharedPtr(isolate, estimated_size,
std::shared_ptr<CppType>{ptr});
}
CppType* ptr);
// Create a {Managed<CppType>} from an existing {std::unique_ptr<CppType>}.
// The returned object will now own the memory pointed to by {CppType}, and
// the unique pointer will be released.
static Handle<Managed<CppType>> FromUniquePtr(
Isolate* isolate, size_t estimated_size,
std::unique_ptr<CppType> unique_ptr) {
return FromSharedPtr(isolate, estimated_size, std::move(unique_ptr));
}
std::unique_ptr<CppType> unique_ptr);
// Create a {Managed<CppType>} from an existing {std::shared_ptr<CppType>}.
static Handle<Managed<CppType>> FromSharedPtr(
Isolate* isolate, size_t estimated_size,
std::shared_ptr<CppType> shared_ptr) {
reinterpret_cast<v8::Isolate*>(isolate)
->AdjustAmountOfExternalAllocatedMemory(estimated_size);
auto destructor = new ManagedPtrDestructor(
estimated_size, new std::shared_ptr<CppType>{std::move(shared_ptr)},
Destructor);
Handle<Managed<CppType>> handle = Handle<Managed<CppType>>::cast(
isolate->factory()->NewForeign(reinterpret_cast<Address>(destructor)));
Handle<Object> global_handle = isolate->global_handles()->Create(*handle);
destructor->global_handle_location_ = global_handle.location();
GlobalHandles::MakeWeak(destructor->global_handle_location_, destructor,
&ManagedObjectFinalizer,
v8::WeakCallbackType::kParameter);
isolate->RegisterManagedPtrDestructor(destructor);
return handle;
}
std::shared_ptr<CppType> shared_ptr);
private:
// Internally this {Foreign} object stores a pointer to a new

View File

@ -15,6 +15,7 @@
#include "src/base/platform/wrappers.h"
#include "src/execution/isolate.h"
#include "src/flags/flags.h"
#include "src/handles/global-handles-inl.h"
#include "src/handles/handles-inl.h"
#include "src/handles/maybe-handles-inl.h"
#include "src/heap/factory.h"

View File

@ -5,7 +5,7 @@
#include "src/profiler/allocation-tracker.h"
#include "src/execution/frames-inl.h"
#include "src/handles/global-handles.h"
#include "src/handles/global-handles-inl.h"
#include "src/objects/objects-inl.h"
#include "src/profiler/heap-snapshot-generator-inl.h"

View File

@ -4,7 +4,8 @@
#include "src/profiler/weak-code-registry.h"
#include "src/handles/global-handles.h"
#include "src/handles/global-handles-inl.h"
#include "src/objects/code-inl.h"
#include "src/objects/instance-type-inl.h"
namespace v8 {

View File

@ -6,6 +6,7 @@
#include "src/codegen/assembler-inl.h"
#include "src/common/globals.h"
#include "src/handles/global-handles-inl.h"
#include "src/heap/heap-inl.h" // For Space::identity().
#include "src/heap/memory-chunk-inl.h"
#include "src/heap/read-only-heap.h"
@ -48,6 +49,10 @@ Serializer::Serializer(Isolate* isolate, Snapshot::SerializerFlags flags)
#endif // OBJECT_PRINT
}
#ifdef DEBUG
void Serializer::PopStack() { stack_.Pop(); }
#endif
void Serializer::CountAllocation(Map map, int size, SnapshotSpace space) {
DCHECK(FLAG_serialization_statistics);

View File

@ -280,7 +280,7 @@ class Serializer : public SerializerDeserializer {
#ifdef DEBUG
void PushStack(Handle<HeapObject> o) { stack_.Push(*o); }
void PopStack() { stack_.Pop(); }
void PopStack();
void PrintStack();
void PrintStack(std::ostream&);
#endif // DEBUG

View File

@ -32,7 +32,7 @@
#include "src/builtins/builtins.h"
#include "src/compiler/wasm-compiler.h"
#include "src/objects/js-collection-inl.h"
#include "src/objects/managed.h"
#include "src/objects/managed-inl.h"
#include "src/objects/stack-frame-info-inl.h"
#include "src/wasm/leb-helper.h"
#include "src/wasm/module-instantiate.h"

View File

@ -16,6 +16,7 @@
#include "src/base/platform/time.h"
#include "src/base/utils/random-number-generator.h"
#include "src/compiler/wasm-compiler.h"
#include "src/handles/global-handles-inl.h"
#include "src/heap/heap-inl.h" // For CodeSpaceMemoryModificationScope.
#include "src/logging/counters-scopes.h"
#include "src/logging/metrics.h"

View File

@ -11,9 +11,11 @@
#include "src/diagnostics/compilation-statistics.h"
#include "src/execution/frames.h"
#include "src/execution/v8threads.h"
#include "src/handles/global-handles-inl.h"
#include "src/logging/counters.h"
#include "src/objects/heap-number.h"
#include "src/objects/js-promise.h"
#include "src/objects/managed-inl.h"
#include "src/objects/objects-inl.h"
#include "src/strings/string-hasher-inl.h"
#include "src/utils/ostreams.h"

View File

@ -19,12 +19,14 @@
#include "src/execution/execution.h"
#include "src/execution/frames-inl.h"
#include "src/execution/isolate.h"
#include "src/handles/global-handles-inl.h"
#include "src/handles/handles.h"
#include "src/heap/factory.h"
#include "src/init/v8.h"
#include "src/objects/fixed-array.h"
#include "src/objects/instance-type.h"
#include "src/objects/js-promise-inl.h"
#include "src/objects/managed-inl.h"
#include "src/objects/objects-inl.h"
#include "src/objects/templates.h"
#include "src/parsing/parse-info.h"

View File

@ -12,6 +12,7 @@
#include "src/debug/debug-interface.h"
#include "src/logging/counters.h"
#include "src/objects/debug-objects-inl.h"
#include "src/objects/managed-inl.h"
#include "src/objects/objects-inl.h"
#include "src/objects/shared-function-info.h"
#include "src/objects/struct-inl.h"

View File

@ -40,7 +40,7 @@
#include "src/debug/debug.h"
#include "src/deoptimizer/deoptimizer.h"
#include "src/execution/execution.h"
#include "src/handles/global-handles.h"
#include "src/handles/global-handles-inl.h"
#include "src/heap/combined-heap.h"
#include "src/heap/factory.h"
#include "src/heap/gc-tracer.h"
@ -60,7 +60,7 @@
#include "src/objects/heap-number-inl.h"
#include "src/objects/js-array-inl.h"
#include "src/objects/js-collection-inl.h"
#include "src/objects/managed.h"
#include "src/objects/managed-inl.h"
#include "src/objects/objects-inl.h"
#include "src/objects/slots.h"
#include "src/objects/stack-frame-info-inl.h"

View File

@ -6,8 +6,7 @@
#include <stdlib.h>
#include <string.h>
#include "src/objects/managed.h"
#include "src/objects/managed-inl.h"
#include "src/objects/objects-inl.h"
#include "test/cctest/cctest.h"

View File

@ -28,7 +28,7 @@
#include <utility>
#include "src/execution/isolate.h"
#include "src/handles/global-handles.h"
#include "src/handles/global-handles-inl.h"
#include "src/heap/factory.h"
#include "src/heap/heap-inl.h"
#include "src/objects/hash-table-inl.h"

View File

@ -28,7 +28,7 @@
#include <utility>
#include "src/execution/isolate.h"
#include "src/handles/global-handles.h"
#include "src/handles/global-handles-inl.h"
#include "src/heap/factory.h"
#include "src/heap/heap-inl.h"
#include "src/objects/hash-table-inl.h"

View File

@ -12,6 +12,7 @@
#include "src/codegen/assembler-inl.h"
#include "src/common/globals.h"
#include "src/compiler/wasm-compiler.h"
#include "src/handles/global-handles-inl.h"
#include "src/numbers/conversions.h"
#include "src/objects/objects-inl.h"
#include "src/utils/boxed-float.h"