Commit 31a8f215 authored by Sigurd Schneider's avatar Sigurd Schneider Committed by Commit Bot

[cleanup] Move ZoneSplayTree to its own header

Change-Id: I4bd02bdb68727b6242b0fe4b81fd522813b13f39
Bug: v8:8834
Reviewed-on: https://chromium-review.googlesource.com/c/1488755Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Commit-Queue: Sigurd Schneider <sigurds@chromium.org>
Cr-Commit-Position: refs/heads/master@{#59875}
parent 1ad4d187
...@@ -2738,6 +2738,7 @@ v8_source_set("v8_base") { ...@@ -2738,6 +2738,7 @@ v8_source_set("v8_base") {
"src/zone/zone-list-inl.h", "src/zone/zone-list-inl.h",
"src/zone/zone-segment.cc", "src/zone/zone-segment.cc",
"src/zone/zone-segment.h", "src/zone/zone-segment.h",
"src/zone/zone-splay-tree.h",
"src/zone/zone.cc", "src/zone/zone.cc",
"src/zone/zone.h", "src/zone/zone.h",
] ]
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "src/asmjs/asm-scanner.h" #include "src/asmjs/asm-scanner.h"
#include "src/asmjs/asm-types.h" #include "src/asmjs/asm-types.h"
#include "src/base/enum-set.h" #include "src/base/enum-set.h"
#include "src/vector.h"
#include "src/wasm/wasm-module-builder.h" #include "src/wasm/wasm-module-builder.h"
#include "src/zone/zone-containers.h" #include "src/zone/zone-containers.h"
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "src/ast/modules.h" #include "src/ast/modules.h"
#include "src/ast/variables.h" #include "src/ast/variables.h"
#include "src/bailout-reason.h" #include "src/bailout-reason.h"
#include "src/base/threaded-list.h"
#include "src/globals.h" #include "src/globals.h"
#include "src/heap/factory.h" #include "src/heap/factory.h"
#include "src/isolate.h" #include "src/isolate.h"
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "src/ast/ast.h" #include "src/ast/ast.h"
#include "src/base/compiler-specific.h" #include "src/base/compiler-specific.h"
#include "src/base/hashmap.h" #include "src/base/hashmap.h"
#include "src/base/threaded-list.h"
#include "src/function-kind.h" #include "src/function-kind.h"
#include "src/globals.h" #include "src/globals.h"
#include "src/objects.h" #include "src/objects.h"
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define V8_AST_VARIABLES_H_ #define V8_AST_VARIABLES_H_
#include "src/ast/ast-value-factory.h" #include "src/ast/ast-value-factory.h"
#include "src/base/threaded-list.h"
#include "src/globals.h" #include "src/globals.h"
#include "src/zone/zone.h" #include "src/zone/zone.h"
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "src/base/optional.h" #include "src/base/optional.h"
#include "src/handles.h" #include "src/handles.h"
#include "src/maybe-handles.h" #include "src/maybe-handles.h"
#include "src/utils.h"
#include "src/zone/zone-containers.h" #include "src/zone/zone-containers.h"
namespace v8 { namespace v8 {
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "src/globals.h" #include "src/globals.h"
#include "src/handles.h" #include "src/handles.h"
#include "src/maybe-handles.h" #include "src/maybe-handles.h"
#include "src/vector.h"
#include "src/zone/zone-chunk-list.h" #include "src/zone/zone-chunk-list.h"
#include "src/zone/zone-containers.h" #include "src/zone/zone-containers.h"
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "src/objects/js-regexp.h" #include "src/objects/js-regexp.h"
#include "src/regexp/regexp-ast.h" #include "src/regexp/regexp-ast.h"
#include "src/regexp/regexp-macro-assembler.h" #include "src/regexp/regexp-macro-assembler.h"
#include "src/zone/zone-splay-tree.h"
namespace v8 { namespace v8 {
namespace internal { namespace internal {
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "src/allocation.h" #include "src/allocation.h"
#include "src/assert-scope.h" #include "src/assert-scope.h"
#include "src/utils.h"
#include "src/v8memory.h" #include "src/v8memory.h"
#include "src/zone/zone-chunk-list.h" #include "src/zone/zone-chunk-list.h"
#include "src/zone/zone.h" #include "src/zone/zone.h"
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "src/base/compiler-specific.h" #include "src/base/compiler-specific.h"
#include "src/flags.h" #include "src/flags.h"
#include "src/signature.h" #include "src/signature.h"
#include "src/utils.h"
#include "src/v8memory.h" #include "src/v8memory.h"
#include "src/vector.h" #include "src/vector.h"
#include "src/wasm/wasm-result.h" #include "src/wasm/wasm-result.h"
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "src/zone/zone-containers.h" #include "src/zone/zone-containers.h"
#include "src/v8memory.h" #include "src/v8memory.h"
#include "src/vector.h"
#include "src/wasm/leb-helper.h" #include "src/wasm/leb-helper.h"
#include "src/wasm/local-decl-encoder.h" #include "src/wasm/local-decl-encoder.h"
#include "src/wasm/wasm-opcodes.h" #include "src/wasm/wasm-opcodes.h"
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include <stdlib.h> #include <algorithm>
#include "src/base/iterator.h" #include "src/base/iterator.h"
#include "src/globals.h" #include "src/globals.h"
...@@ -301,7 +301,8 @@ void ZoneChunkList<T>::push_back(const T& item) { ...@@ -301,7 +301,8 @@ void ZoneChunkList<T>::push_back(const T& item) {
DCHECK_LE(back_->position_, back_->capacity_); DCHECK_LE(back_->position_, back_->capacity_);
if (back_->position_ == back_->capacity_) { if (back_->position_ == back_->capacity_) {
if (back_->next_ == nullptr) { 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; back_->next_ = chunk;
chunk->previous_ = back_; chunk->previous_ = back_;
} }
......
// 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 <typename Config>
class ZoneSplayTree final : public SplayTree<Config, ZoneAllocationPolicy> {
public:
explicit ZoneSplayTree(Zone* zone)
: SplayTree<Config, ZoneAllocationPolicy>(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<Config, ZoneAllocationPolicy>::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_
...@@ -5,14 +5,12 @@ ...@@ -5,14 +5,12 @@
#ifndef V8_ZONE_ZONE_H_ #ifndef V8_ZONE_ZONE_H_
#define V8_ZONE_ZONE_H_ #define V8_ZONE_ZONE_H_
#include <algorithm>
#include <limits> #include <limits>
#include "src/base/hashmap.h" #include "src/base/hashmap.h"
#include "src/base/logging.h" #include "src/base/logging.h"
#include "src/base/threaded-list.h"
#include "src/globals.h" #include "src/globals.h"
#include "src/splay-tree.h"
#include "src/utils.h"
#include "src/zone/accounting-allocator.h" #include "src/zone/accounting-allocator.h"
#ifndef ZONE_NAME #ifndef ZONE_NAME
...@@ -226,7 +224,7 @@ class ZoneList final { ...@@ -226,7 +224,7 @@ class ZoneList final {
Vector<T> ToVector() const { return Vector<T>(data_, length_); } Vector<T> ToVector() const { return Vector<T>(data_, length_); }
Vector<T> ToVector(int start, int length) const { Vector<T> ToVector(int start, int length) const {
return Vector<T>(data_ + start, Min(length_ - start, length)); return Vector<T>(data_ + start, std::min(length_ - start, length));
} }
Vector<const T> ToConstVector() const { Vector<const T> ToConstVector() const {
...@@ -392,32 +390,6 @@ class ScopedPtrList final { ...@@ -392,32 +390,6 @@ class ScopedPtrList final {
size_t end_; size_t end_;
}; };
// ZoneThreadedList is a special variant of the ThreadedList that can be put
// into a Zone.
template <typename T, typename TLTraits = base::ThreadedListTraits<T>>
using ZoneThreadedList = base::ThreadedListBase<T, ZoneObject, TLTraits>;
// 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 <typename Config>
class ZoneSplayTree final : public SplayTree<Config, ZoneAllocationPolicy> {
public:
explicit ZoneSplayTree(Zone* zone)
: SplayTree<Config, ZoneAllocationPolicy>(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<Config, ZoneAllocationPolicy>::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<ZoneAllocationPolicy> ZoneHashMap; typedef base::PointerTemplateHashMapImpl<ZoneAllocationPolicy> ZoneHashMap;
typedef base::CustomMatcherTemplateHashMapImpl<ZoneAllocationPolicy> typedef base::CustomMatcherTemplateHashMapImpl<ZoneAllocationPolicy>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment