From 31a8f21576d7d4adca4f4684d54c0bddd9a45cc4 Mon Sep 17 00:00:00 2001 From: Sigurd Schneider Date: Tue, 26 Feb 2019 12:38:00 +0100 Subject: [PATCH] [cleanup] Move ZoneSplayTree to its own header Change-Id: I4bd02bdb68727b6242b0fe4b81fd522813b13f39 Bug: v8:8834 Reviewed-on: https://chromium-review.googlesource.com/c/1488755 Reviewed-by: Toon Verwaest Reviewed-by: Michael Starzinger Reviewed-by: Jakob Gruber Commit-Queue: Sigurd Schneider Cr-Commit-Position: refs/heads/master@{#59875} --- BUILD.gn | 1 + src/asmjs/asm-parser.h | 1 + src/ast/ast.h | 1 + src/ast/scopes.h | 1 + src/ast/variables.h | 1 + .../serializer-for-background-compilation.h | 1 + src/parsing/preparse-data.h | 1 + src/regexp/jsregexp.h | 1 + src/safepoint-table.h | 1 + src/wasm/decoder.h | 1 + src/wasm/wasm-module-builder.h | 1 + src/zone/zone-chunk-list.h | 5 ++- src/zone/zone-splay-tree.h | 38 +++++++++++++++++++ src/zone/zone.h | 32 +--------------- 14 files changed, 54 insertions(+), 32 deletions(-) create mode 100644 src/zone/zone-splay-tree.h diff --git a/BUILD.gn b/BUILD.gn index db7af3dd40..9f8f0e3a3b 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -2738,6 +2738,7 @@ v8_source_set("v8_base") { "src/zone/zone-list-inl.h", "src/zone/zone-segment.cc", "src/zone/zone-segment.h", + "src/zone/zone-splay-tree.h", "src/zone/zone.cc", "src/zone/zone.h", ] diff --git a/src/asmjs/asm-parser.h b/src/asmjs/asm-parser.h index dd8392ddcf..202bac718b 100644 --- a/src/asmjs/asm-parser.h +++ b/src/asmjs/asm-parser.h @@ -11,6 +11,7 @@ #include "src/asmjs/asm-scanner.h" #include "src/asmjs/asm-types.h" #include "src/base/enum-set.h" +#include "src/vector.h" #include "src/wasm/wasm-module-builder.h" #include "src/zone/zone-containers.h" diff --git a/src/ast/ast.h b/src/ast/ast.h index a0a15d0a6a..80f76bd6e4 100644 --- a/src/ast/ast.h +++ b/src/ast/ast.h @@ -11,6 +11,7 @@ #include "src/ast/modules.h" #include "src/ast/variables.h" #include "src/bailout-reason.h" +#include "src/base/threaded-list.h" #include "src/globals.h" #include "src/heap/factory.h" #include "src/isolate.h" diff --git a/src/ast/scopes.h b/src/ast/scopes.h index 849ec52073..732d759757 100644 --- a/src/ast/scopes.h +++ b/src/ast/scopes.h @@ -8,6 +8,7 @@ #include "src/ast/ast.h" #include "src/base/compiler-specific.h" #include "src/base/hashmap.h" +#include "src/base/threaded-list.h" #include "src/function-kind.h" #include "src/globals.h" #include "src/objects.h" diff --git a/src/ast/variables.h b/src/ast/variables.h index 85da412572..6dbb9dbac4 100644 --- a/src/ast/variables.h +++ b/src/ast/variables.h @@ -6,6 +6,7 @@ #define V8_AST_VARIABLES_H_ #include "src/ast/ast-value-factory.h" +#include "src/base/threaded-list.h" #include "src/globals.h" #include "src/zone/zone.h" diff --git a/src/compiler/serializer-for-background-compilation.h b/src/compiler/serializer-for-background-compilation.h index 90c6783304..b6c9bfa125 100644 --- a/src/compiler/serializer-for-background-compilation.h +++ b/src/compiler/serializer-for-background-compilation.h @@ -8,6 +8,7 @@ #include "src/base/optional.h" #include "src/handles.h" #include "src/maybe-handles.h" +#include "src/utils.h" #include "src/zone/zone-containers.h" namespace v8 { diff --git a/src/parsing/preparse-data.h b/src/parsing/preparse-data.h index 3d0854283c..ea9bded9b9 100644 --- a/src/parsing/preparse-data.h +++ b/src/parsing/preparse-data.h @@ -8,6 +8,7 @@ #include "src/globals.h" #include "src/handles.h" #include "src/maybe-handles.h" +#include "src/vector.h" #include "src/zone/zone-chunk-list.h" #include "src/zone/zone-containers.h" diff --git a/src/regexp/jsregexp.h b/src/regexp/jsregexp.h index 9827a29574..109dd91606 100644 --- a/src/regexp/jsregexp.h +++ b/src/regexp/jsregexp.h @@ -10,6 +10,7 @@ #include "src/objects/js-regexp.h" #include "src/regexp/regexp-ast.h" #include "src/regexp/regexp-macro-assembler.h" +#include "src/zone/zone-splay-tree.h" namespace v8 { namespace internal { diff --git a/src/safepoint-table.h b/src/safepoint-table.h index 73678db46a..919c932b15 100644 --- a/src/safepoint-table.h +++ b/src/safepoint-table.h @@ -7,6 +7,7 @@ #include "src/allocation.h" #include "src/assert-scope.h" +#include "src/utils.h" #include "src/v8memory.h" #include "src/zone/zone-chunk-list.h" #include "src/zone/zone.h" diff --git a/src/wasm/decoder.h b/src/wasm/decoder.h index ab8880f50c..f1071dc1b0 100644 --- a/src/wasm/decoder.h +++ b/src/wasm/decoder.h @@ -11,6 +11,7 @@ #include "src/base/compiler-specific.h" #include "src/flags.h" #include "src/signature.h" +#include "src/utils.h" #include "src/v8memory.h" #include "src/vector.h" #include "src/wasm/wasm-result.h" diff --git a/src/wasm/wasm-module-builder.h b/src/wasm/wasm-module-builder.h index 131cda747c..e9b22a392c 100644 --- a/src/wasm/wasm-module-builder.h +++ b/src/wasm/wasm-module-builder.h @@ -9,6 +9,7 @@ #include "src/zone/zone-containers.h" #include "src/v8memory.h" +#include "src/vector.h" #include "src/wasm/leb-helper.h" #include "src/wasm/local-decl-encoder.h" #include "src/wasm/wasm-opcodes.h" diff --git a/src/zone/zone-chunk-list.h b/src/zone/zone-chunk-list.h index fe32e48c0b..a15f27fab1 100644 --- a/src/zone/zone-chunk-list.h +++ b/src/zone/zone-chunk-list.h @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include +#include #include "src/base/iterator.h" #include "src/globals.h" @@ -301,7 +301,8 @@ void ZoneChunkList::push_back(const T& item) { DCHECK_LE(back_->position_, back_->capacity_); if (back_->position_ == back_->capacity_) { if (back_->next_ == nullptr) { - Chunk* chunk = NewChunk(Min(back_->capacity_ << 1, kMaxChunkCapacity)); + constexpr auto max_capacity = kMaxChunkCapacity; + Chunk* chunk = NewChunk(std::min(back_->capacity_ << 1, max_capacity)); back_->next_ = chunk; chunk->previous_ = back_; } diff --git a/src/zone/zone-splay-tree.h b/src/zone/zone-splay-tree.h new file mode 100644 index 0000000000..55a81738b6 --- /dev/null +++ b/src/zone/zone-splay-tree.h @@ -0,0 +1,38 @@ +// Copyright 2019 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_ZONE_ZONE_SPLAY_TREE_H_ +#define V8_ZONE_ZONE_SPLAY_TREE_H_ + +#include "src/splay-tree.h" +#include "src/zone/zone.h" + +namespace v8 { +namespace internal { + +// A zone splay tree. The config type parameter encapsulates the +// different configurations of a concrete splay tree (see splay-tree.h). +// The tree itself and all its elements are allocated in the Zone. +template +class ZoneSplayTree final : public SplayTree { + public: + explicit ZoneSplayTree(Zone* zone) + : SplayTree(ZoneAllocationPolicy(zone)) {} + ~ZoneSplayTree() { + // Reset the root to avoid unneeded iteration over all tree nodes + // in the destructor. For a zone-allocated tree, nodes will be + // freed by the Zone. + SplayTree::ResetRoot(); + } + + void* operator new(size_t size, Zone* zone) { return zone->New(size); } + + void operator delete(void* pointer) { UNREACHABLE(); } + void operator delete(void* pointer, Zone* zone) { UNREACHABLE(); } +}; + +} // namespace internal +} // namespace v8 + +#endif // V8_ZONE_ZONE_SPLAY_TREE_H_ diff --git a/src/zone/zone.h b/src/zone/zone.h index 80f18db2c0..44772f6041 100644 --- a/src/zone/zone.h +++ b/src/zone/zone.h @@ -5,14 +5,12 @@ #ifndef V8_ZONE_ZONE_H_ #define V8_ZONE_ZONE_H_ +#include #include #include "src/base/hashmap.h" #include "src/base/logging.h" -#include "src/base/threaded-list.h" #include "src/globals.h" -#include "src/splay-tree.h" -#include "src/utils.h" #include "src/zone/accounting-allocator.h" #ifndef ZONE_NAME @@ -226,7 +224,7 @@ class ZoneList final { Vector ToVector() const { return Vector(data_, length_); } Vector ToVector(int start, int length) const { - return Vector(data_ + start, Min(length_ - start, length)); + return Vector(data_ + start, std::min(length_ - start, length)); } Vector ToConstVector() const { @@ -392,32 +390,6 @@ class ScopedPtrList final { size_t end_; }; -// ZoneThreadedList is a special variant of the ThreadedList that can be put -// into a Zone. -template > -using ZoneThreadedList = base::ThreadedListBase; - -// A zone splay tree. The config type parameter encapsulates the -// different configurations of a concrete splay tree (see splay-tree.h). -// The tree itself and all its elements are allocated in the Zone. -template -class ZoneSplayTree final : public SplayTree { - public: - explicit ZoneSplayTree(Zone* zone) - : SplayTree(ZoneAllocationPolicy(zone)) {} - ~ZoneSplayTree() { - // Reset the root to avoid unneeded iteration over all tree nodes - // in the destructor. For a zone-allocated tree, nodes will be - // freed by the Zone. - SplayTree::ResetRoot(); - } - - void* operator new(size_t size, Zone* zone) { return zone->New(size); } - - void operator delete(void* pointer) { UNREACHABLE(); } - void operator delete(void* pointer, Zone* zone) { UNREACHABLE(); } -}; - typedef base::PointerTemplateHashMapImpl ZoneHashMap; typedef base::CustomMatcherTemplateHashMapImpl