Commit abaece06 authored by Peter Marshall's avatar Peter Marshall Committed by Commit Bot

[cleanup] Replace List with std::vector in cctests and d8.

Bug: v8:6333
Cq-Include-Trybots: master.tryserver.chromium.linux:linux_chromium_rel_ng
Change-Id: Iabaef0e63c81db503eb2f19bf63a1f77313f2a5a
Reviewed-on: https://chromium-review.googlesource.com/635591
Commit-Queue: Peter Marshall <petermarshall@chromium.org>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47681}
parent 5e6d9093
......@@ -10132,7 +10132,8 @@ unsigned CpuProfileNode::GetNodeId() const {
int CpuProfileNode::GetChildrenCount() const {
return reinterpret_cast<const i::ProfileNode*>(this)->children()->length();
return static_cast<int>(
reinterpret_cast<const i::ProfileNode*>(this)->children()->size());
}
......@@ -10356,7 +10357,7 @@ const HeapGraphNode* HeapSnapshot::GetNodeById(SnapshotObjectId id) const {
int HeapSnapshot::GetNodesCount() const {
return ToInternal(this)->entries().length();
return static_cast<int>(ToInternal(this)->entries().size());
}
......
......@@ -33,7 +33,6 @@
#include "src/basic-block-profiler.h"
#include "src/debug/debug-interface.h"
#include "src/interpreter/interpreter.h"
#include "src/list-inl.h"
#include "src/msan.h"
#include "src/objects-inl.h"
#include "src/objects.h"
......@@ -452,7 +451,7 @@ const base::TimeTicks Shell::kInitialTicks =
Global<Function> Shell::stringify_function_;
base::LazyMutex Shell::workers_mutex_;
bool Shell::allow_new_workers_ = true;
i::List<Worker*> Shell::workers_;
std::vector<Worker*> Shell::workers_;
std::vector<ExternalizedContents> Shell::externalized_contents_;
base::LazyMutex Shell::isolate_status_lock_;
std::map<v8::Isolate*, bool> Shell::isolate_status_;
......@@ -1304,7 +1303,7 @@ void Shell::WorkerNew(const v8::FunctionCallbackInfo<v8::Value>& args) {
{
base::LockGuard<base::Mutex> lock_guard(workers_mutex_.Pointer());
if (workers_.length() >= kMaxWorkers) {
if (workers_.size() >= kMaxWorkers) {
Throw(args.GetIsolate(), "Too many workers, I won't let you create more");
return;
}
......@@ -1318,7 +1317,7 @@ void Shell::WorkerNew(const v8::FunctionCallbackInfo<v8::Value>& args) {
Worker* worker = new Worker;
args.Holder()->SetAlignedPointerInInternalField(0, worker);
workers_.Add(worker);
workers_.push_back(worker);
String::Utf8Value script(args.GetIsolate(), args[0]);
if (!*script) {
......@@ -3087,16 +3086,14 @@ void Shell::CleanupWorkers() {
// Make a copy of workers_, because we don't want to call Worker::Terminate
// while holding the workers_mutex_ lock. Otherwise, if a worker is about to
// create a new Worker, it would deadlock.
i::List<Worker*> workers_copy;
std::vector<Worker*> workers_copy;
{
base::LockGuard<base::Mutex> lock_guard(workers_mutex_.Pointer());
allow_new_workers_ = false;
workers_copy.AddAll(workers_);
workers_.Clear();
workers_copy.swap(workers_);
}
for (int i = 0; i < workers_copy.length(); ++i) {
Worker* worker = workers_copy[i];
for (Worker* worker : workers_copy) {
worker->WaitForThread();
delete worker;
}
......
......@@ -14,7 +14,6 @@
#include "src/allocation.h"
#include "src/base/hashmap.h"
#include "src/base/platform/time.h"
#include "src/list.h"
#include "src/utils.h"
#include "src/base/once.h"
......@@ -481,7 +480,7 @@ class Shell : public i::AllStatic {
static base::LazyMutex workers_mutex_;
static bool allow_new_workers_;
static i::List<Worker*> workers_;
static std::vector<Worker*> workers_;
static std::vector<ExternalizedContents> externalized_contents_;
static void WriteIgnitionDispatchCountersFile(v8::Isolate* isolate);
......
......@@ -27,7 +27,7 @@ HeapSnapshot* HeapGraphEdge::snapshot() const {
int HeapEntry::index() const {
return static_cast<int>(this - &snapshot_->entries().first());
return static_cast<int>(this - &snapshot_->entries().front());
}
......
......@@ -207,7 +207,7 @@ void HeapSnapshot::AddSyntheticRootEntries() {
HeapEntry* HeapSnapshot::AddRootEntry() {
DCHECK(root_index_ == HeapEntry::kNoEntry);
DCHECK(entries_.is_empty()); // Root entry must be the first one.
DCHECK(entries_.empty()); // Root entry must be the first one.
HeapEntry* entry = AddEntry(HeapEntry::kSynthetic,
"",
HeapObjectsMap::kInternalRootObjectId,
......@@ -246,10 +246,9 @@ HeapEntry* HeapSnapshot::AddEntry(HeapEntry::Type type,
SnapshotObjectId id,
size_t size,
unsigned trace_node_id) {
HeapEntry entry(this, type, name, id, size, trace_node_id);
DCHECK(sorted_entries_.is_empty());
entries_.Add(entry);
return &entries_.last();
DCHECK(sorted_entries_.empty());
entries_.emplace_back(this, type, name, id, size, trace_node_id);
return &entries_.back();
}
......@@ -257,20 +256,18 @@ void HeapSnapshot::FillChildren() {
DCHECK(children().empty());
children().resize(edges().size());
int children_index = 0;
for (int i = 0; i < entries().length(); ++i) {
HeapEntry* entry = &entries()[i];
children_index = entry->set_children_index(children_index);
for (HeapEntry& entry : entries()) {
children_index = entry.set_children_index(children_index);
}
DCHECK_EQ(edges().size(), static_cast<size_t>(children_index));
for (size_t i = 0; i < edges().size(); ++i) {
HeapGraphEdge* edge = &edges()[i];
edge->ReplaceToIndexWithEntry(this);
edge->from()->add_child(edge);
for (HeapGraphEdge& edge : edges()) {
edge.ReplaceToIndexWithEntry(this);
edge.from()->add_child(&edge);
}
}
HeapEntry* HeapSnapshot::GetEntryById(SnapshotObjectId id) {
List<HeapEntry*>* entries_by_id = GetSortedEntriesList();
std::vector<HeapEntry*>* entries_by_id = GetSortedEntriesList();
auto it = std::lower_bound(
entries_by_id->begin(), entries_by_id->end(), id,
......@@ -280,23 +277,19 @@ HeapEntry* HeapSnapshot::GetEntryById(SnapshotObjectId id) {
return *it;
}
struct SortByIds {
bool operator()(const HeapEntry* entry1_ptr, const HeapEntry* entry2_ptr) {
return entry1_ptr->id() < entry2_ptr->id();
}
};
template<class T>
static int SortByIds(const T* entry1_ptr,
const T* entry2_ptr) {
if ((*entry1_ptr)->id() == (*entry2_ptr)->id()) return 0;
return (*entry1_ptr)->id() < (*entry2_ptr)->id() ? -1 : 1;
}
List<HeapEntry*>* HeapSnapshot::GetSortedEntriesList() {
if (sorted_entries_.is_empty()) {
sorted_entries_.Allocate(entries_.length());
for (int i = 0; i < entries_.length(); ++i) {
sorted_entries_[i] = &entries_[i];
std::vector<HeapEntry*>* HeapSnapshot::GetSortedEntriesList() {
if (sorted_entries_.empty()) {
sorted_entries_.reserve(entries_.size());
for (HeapEntry& entry : entries_) {
sorted_entries_.push_back(&entry);
}
sorted_entries_.Sort<int (*)(HeapEntry* const*, HeapEntry* const*)>(
SortByIds);
std::sort(sorted_entries_.begin(), sorted_entries_.end(), SortByIds());
}
return &sorted_entries_;
}
......@@ -322,7 +315,7 @@ HeapObjectsMap::HeapObjectsMap(Heap* heap)
// an entry with zero value. Otherwise it's impossible to tell if
// LookupOrInsert has added a new item or just returning exisiting one
// having the value of zero.
entries_.Add(EntryInfo(0, nullptr, 0, true));
entries_.emplace_back(0, nullptr, 0, true);
}
bool HeapObjectsMap::MoveObject(Address from, Address to, int object_size) {
......@@ -382,7 +375,7 @@ SnapshotObjectId HeapObjectsMap::FindEntry(Address addr) {
if (entry == NULL) return 0;
int entry_index = static_cast<int>(reinterpret_cast<intptr_t>(entry->value));
EntryInfo& entry_info = entries_.at(entry_index);
DCHECK(static_cast<uint32_t>(entries_.length()) > entries_map_.occupancy());
DCHECK(static_cast<uint32_t>(entries_.size()) > entries_map_.occupancy());
return entry_info.id;
}
......@@ -390,7 +383,7 @@ SnapshotObjectId HeapObjectsMap::FindEntry(Address addr) {
SnapshotObjectId HeapObjectsMap::FindOrAddEntry(Address addr,
unsigned int size,
bool accessed) {
DCHECK(static_cast<uint32_t>(entries_.length()) > entries_map_.occupancy());
DCHECK(static_cast<uint32_t>(entries_.size()) > entries_map_.occupancy());
base::HashMap::Entry* entry =
entries_map_.LookupOrInsert(addr, ComputePointerHash(addr));
if (entry->value != NULL) {
......@@ -405,11 +398,11 @@ SnapshotObjectId HeapObjectsMap::FindOrAddEntry(Address addr,
entry_info.size = size;
return entry_info.id;
}
entry->value = reinterpret_cast<void*>(entries_.length());
entry->value = reinterpret_cast<void*>(entries_.size());
SnapshotObjectId id = next_id_;
next_id_ += kObjectIdStep;
entries_.Add(EntryInfo(id, addr, size, accessed));
DCHECK(static_cast<uint32_t>(entries_.length()) > entries_map_.occupancy());
entries_.push_back(EntryInfo(id, addr, size, accessed));
DCHECK(static_cast<uint32_t>(entries_.size()) > entries_map_.occupancy());
return id;
}
......@@ -450,9 +443,9 @@ SnapshotObjectId HeapObjectsMap::PushHeapObjectsStats(OutputStream* stream,
time_intervals_.Add(TimeInterval(next_id_));
int prefered_chunk_size = stream->GetChunkSize();
List<v8::HeapStatsUpdate> stats_buffer;
DCHECK(!entries_.is_empty());
EntryInfo* entry_info = &entries_.first();
EntryInfo* end_entry_info = &entries_.last() + 1;
DCHECK(!entries_.empty());
EntryInfo* entry_info = &entries_.front();
EntryInfo* end_entry_info = &entries_.back() + 1;
for (int time_interval_index = 0;
time_interval_index < time_intervals_.length();
++time_interval_index) {
......@@ -496,11 +489,10 @@ SnapshotObjectId HeapObjectsMap::PushHeapObjectsStats(OutputStream* stream,
void HeapObjectsMap::RemoveDeadEntries() {
DCHECK(entries_.length() > 0 &&
entries_.at(0).id == 0 &&
DCHECK(entries_.size() > 0 && entries_.at(0).id == 0 &&
entries_.at(0).addr == NULL);
int first_free_entry = 1;
for (int i = 1; i < entries_.length(); ++i) {
size_t first_free_entry = 1;
for (size_t i = 1; i < entries_.size(); ++i) {
EntryInfo& entry_info = entries_.at(i);
if (entry_info.accessed) {
if (first_free_entry != i) {
......@@ -519,8 +511,9 @@ void HeapObjectsMap::RemoveDeadEntries() {
}
}
}
entries_.Rewind(first_free_entry);
DCHECK(static_cast<uint32_t>(entries_.length()) - 1 ==
entries_.erase(entries_.begin() + first_free_entry, entries_.end());
DCHECK(static_cast<uint32_t>(entries_.size()) - 1 ==
entries_map_.occupancy());
}
......@@ -2643,8 +2636,7 @@ void HeapSnapshotJSONSerializer::SerializeEdges() {
}
}
void HeapSnapshotJSONSerializer::SerializeNode(HeapEntry* entry) {
void HeapSnapshotJSONSerializer::SerializeNode(const HeapEntry* entry) {
// The buffer needs space for 4 unsigned ints, 1 size_t, 5 commas, \n and \0
static const int kBufferSize =
5 * MaxDecimalDigitsIn<sizeof(unsigned)>::kUnsigned // NOLINT
......@@ -2673,9 +2665,9 @@ void HeapSnapshotJSONSerializer::SerializeNode(HeapEntry* entry) {
void HeapSnapshotJSONSerializer::SerializeNodes() {
List<HeapEntry>& entries = snapshot_->entries();
for (int i = 0; i < entries.length(); ++i) {
SerializeNode(&entries[i]);
std::vector<HeapEntry>& entries = snapshot_->entries();
for (const HeapEntry& entry : entries) {
SerializeNode(&entry);
if (writer_->aborted()) return;
}
}
......@@ -2751,7 +2743,7 @@ void HeapSnapshotJSONSerializer::SerializeSnapshot() {
#undef JSON_O
#undef JSON_A
writer_->AddString(",\"node_count\":");
writer_->AddNumber(snapshot_->entries().length());
writer_->AddNumber(static_cast<unsigned>(snapshot_->entries().size()));
writer_->AddString(",\"edge_count\":");
writer_->AddNumber(static_cast<double>(snapshot_->edges().size()));
writer_->AddString(",\"trace_function_count\":");
......
......@@ -107,11 +107,11 @@ class HeapEntry BASE_EMBEDDED {
unsigned trace_node_id);
HeapSnapshot* snapshot() { return snapshot_; }
Type type() { return static_cast<Type>(type_); }
const char* name() { return name_; }
Type type() const { return static_cast<Type>(type_); }
const char* name() const { return name_; }
void set_name(const char* name) { name_ = name; }
SnapshotObjectId id() { return id_; }
size_t self_size() { return self_size_; }
SnapshotObjectId id() const { return id_; }
size_t self_size() const { return self_size_; }
unsigned trace_node_id() const { return trace_node_id_; }
INLINE(int index() const);
int children_count() const { return children_count_; }
......@@ -163,7 +163,7 @@ class HeapSnapshot {
HeapEntry* gc_subroot(int index) {
return &entries_[gc_subroot_indexes_[index]];
}
List<HeapEntry>& entries() { return entries_; }
std::vector<HeapEntry>& entries() { return entries_; }
std::deque<HeapGraphEdge>& edges() { return edges_; }
std::deque<HeapGraphEdge*>& children() { return children_; }
void RememberLastJSObjectId();
......@@ -178,7 +178,7 @@ class HeapSnapshot {
unsigned trace_node_id);
void AddSyntheticRootEntries();
HeapEntry* GetEntryById(SnapshotObjectId id);
List<HeapEntry*>* GetSortedEntriesList();
std::vector<HeapEntry*>* GetSortedEntriesList();
void FillChildren();
void Print(int max_depth);
......@@ -192,10 +192,10 @@ class HeapSnapshot {
int root_index_;
int gc_roots_index_;
int gc_subroot_indexes_[VisitorSynchronization::kNumberOfSyncTags];
List<HeapEntry> entries_;
std::vector<HeapEntry> entries_;
std::deque<HeapGraphEdge> edges_;
std::deque<HeapGraphEdge*> children_;
List<HeapEntry*> sorted_entries_;
std::vector<HeapEntry*> sorted_entries_;
SnapshotObjectId max_snapshot_js_object_id_;
friend class HeapSnapshotTester;
......@@ -259,7 +259,7 @@ class HeapObjectsMap {
SnapshotObjectId next_id_;
base::HashMap entries_map_;
List<EntryInfo> entries_;
std::vector<EntryInfo> entries_;
List<TimeInterval> time_intervals_;
Heap* heap_;
......@@ -588,11 +588,11 @@ class HeapSnapshotJSONSerializer {
}
int GetStringId(const char* s);
int entry_index(HeapEntry* e) { return e->index() * kNodeFieldsCount; }
int entry_index(const HeapEntry* e) { return e->index() * kNodeFieldsCount; }
void SerializeEdge(HeapGraphEdge* edge, bool first_edge);
void SerializeEdges();
void SerializeImpl();
void SerializeNode(HeapEntry* entry);
void SerializeNode(const HeapEntry* entry);
void SerializeNodes();
void SerializeSnapshot();
void SerializeTraceTree();
......
......@@ -202,7 +202,7 @@ ProfileNode* ProfileNode::FindOrAddChild(CodeEntry* entry) {
if (!node) {
node = new ProfileNode(tree_, entry, this);
map_entry->value = node;
children_list_.Add(node);
children_list_.push_back(node);
}
return node;
}
......@@ -348,7 +348,7 @@ class Position {
return node->children()->at(child_idx_);
}
INLINE(bool has_current_child()) {
return child_idx_ < node->children()->length();
return child_idx_ < static_cast<int>(node->children()->size());
}
INLINE(void next_child()) { ++child_idx_; }
......
......@@ -182,7 +182,7 @@ class ProfileNode {
CodeEntry* entry() const { return entry_; }
unsigned self_ticks() const { return self_ticks_; }
const List<ProfileNode*>* children() const { return &children_list_; }
const std::vector<ProfileNode*>* children() const { return &children_list_; }
unsigned id() const { return id_; }
unsigned function_id() const;
ProfileNode* parent() const { return parent_; }
......@@ -212,7 +212,7 @@ class ProfileNode {
unsigned self_ticks_;
// Mapping from CodeEntry* to ProfileNode*
base::CustomMatcherHashMap children_;
List<ProfileNode*> children_list_;
std::vector<ProfileNode*> children_list_;
ProfileNode* parent_;
unsigned id_;
base::CustomMatcherHashMap line_ticks_;
......
......@@ -114,7 +114,6 @@ v8_executable("cctest") {
"test-api.cc",
"test-api.h",
"test-array-list.cc",
"test-ast.cc",
"test-atomicops.cc",
"test-bignum-dtoa.cc",
"test-bignum.cc",
......
......@@ -132,7 +132,6 @@
'test-api-accessors.cc',
'test-api-interceptors.cc',
'test-array-list.cc',
'test-ast.cc',
'test-atomicops.cc',
'test-bignum.cc',
'test-bignum-dtoa.cc',
......
......@@ -217,7 +217,8 @@ TEST(CodeRange) {
code_range.SetUp(code_range_size);
size_t current_allocated = 0;
size_t total_allocated = 0;
List<Block> blocks(1000);
std::vector<Block> blocks;
blocks.reserve(1000);
while (total_allocated < 5 * code_range_size) {
if (current_allocated < code_range_size / 10) {
......@@ -236,19 +237,18 @@ TEST(CodeRange) {
requested, requested - (2 * MemoryAllocator::CodePageGuardSize()),
&allocated);
CHECK(base != NULL);
blocks.Add(Block(base, static_cast<int>(allocated)));
blocks.emplace_back(base, static_cast<int>(allocated));
current_allocated += static_cast<int>(allocated);
total_allocated += static_cast<int>(allocated);
} else {
// Free a block.
int index = Pseudorandom() % blocks.length();
size_t index = Pseudorandom() % blocks.size();
code_range.FreeRawMemory(blocks[index].base, blocks[index].size);
current_allocated -= blocks[index].size;
if (index < blocks.length() - 1) {
blocks[index] = blocks.RemoveLast();
} else {
blocks.RemoveLast();
if (index < blocks.size() - 1) {
blocks[index] = blocks.back();
}
blocks.pop_back();
}
}
}
......
// Copyright 2012 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <stdlib.h>
#include "src/v8.h"
#include "src/ast/ast.h"
#include "src/isolate.h"
#include "src/objects-inl.h"
#include "src/zone/accounting-allocator.h"
#include "test/cctest/cctest.h"
namespace v8 {
namespace internal {
TEST(List) {
v8::V8::Initialize();
Isolate* isolate = CcTest::i_isolate();
List<AstNode*>* list = new List<AstNode*>(0);
CHECK_EQ(0, list->length());
v8::internal::AccountingAllocator allocator;
Zone zone(&allocator, ZONE_NAME);
AstValueFactory value_factory(&zone, isolate->ast_string_constants(),
isolate->heap()->HashSeed());
AstNodeFactory factory(&value_factory, &zone);
AstNode* node = factory.NewEmptyStatement(kNoSourcePosition);
list->Add(node);
CHECK_EQ(1, list->length());
CHECK_EQ(node, list->at(0));
CHECK_EQ(node, list->last());
const int kElements = 100;
for (int i = 0; i < kElements; i++) {
list->Add(node);
}
CHECK_EQ(1 + kElements, list->length());
list->Clear();
CHECK_EQ(0, list->length());
delete list;
}
} // namespace internal
} // namespace v8
......@@ -6,7 +6,6 @@
#include "src/factory.h"
#include "src/isolate.h"
#include "src/list.h"
#include "src/objects.h"
// FIXME(mstarzinger, marja): This is weird, but required because of the missing
// (disallowed) include: src/factory.h -> src/objects-inl.h
......@@ -52,11 +51,13 @@ TEST(CodeCache) {
static const int kEntries = 150;
// Prepare name/code pairs.
List<Handle<Name>> names(kEntries);
List<Handle<Code>> codes(kEntries);
std::vector<Handle<Name>> names;
std::vector<Handle<Code>> codes;
names.reserve(kEntries);
codes.reserve(kEntries);
for (int i = 0; i < kEntries; i++) {
names.Add(isolate->factory()->NewSymbol());
codes.Add(GetDummyCode(isolate));
names.push_back(isolate->factory()->NewSymbol());
codes.push_back(GetDummyCode(isolate));
}
Handle<Name> bad_name = isolate->factory()->NewSymbol();
Code::Flags flags = Code::ComputeFlags(Code::LOAD_IC, kNoExtraICState);
......
......@@ -265,21 +265,21 @@ TEST(TickEvents) {
CHECK(profile);
// Check call trees.
const i::List<ProfileNode*>* top_down_root_children =
const std::vector<ProfileNode*>* top_down_root_children =
profile->top_down()->root()->children();
CHECK_EQ(1, top_down_root_children->length());
CHECK_EQ(0, strcmp("bbb", top_down_root_children->last()->entry()->name()));
const i::List<ProfileNode*>* top_down_bbb_children =
top_down_root_children->last()->children();
CHECK_EQ(1, top_down_bbb_children->length());
CHECK_EQ(0, strcmp("5", top_down_bbb_children->last()->entry()->name()));
const i::List<ProfileNode*>* top_down_stub_children =
top_down_bbb_children->last()->children();
CHECK_EQ(1, top_down_stub_children->length());
CHECK_EQ(0, strcmp("ddd", top_down_stub_children->last()->entry()->name()));
const i::List<ProfileNode*>* top_down_ddd_children =
top_down_stub_children->last()->children();
CHECK_EQ(0, top_down_ddd_children->length());
CHECK_EQ(1, top_down_root_children->size());
CHECK_EQ(0, strcmp("bbb", top_down_root_children->back()->entry()->name()));
const std::vector<ProfileNode*>* top_down_bbb_children =
top_down_root_children->back()->children();
CHECK_EQ(1, top_down_bbb_children->size());
CHECK_EQ(0, strcmp("5", top_down_bbb_children->back()->entry()->name()));
const std::vector<ProfileNode*>* top_down_stub_children =
top_down_bbb_children->back()->children();
CHECK_EQ(1, top_down_stub_children->size());
CHECK_EQ(0, strcmp("ddd", top_down_stub_children->back()->entry()->name()));
const std::vector<ProfileNode*>* top_down_ddd_children =
top_down_stub_children->back()->children();
CHECK(top_down_ddd_children->empty());
isolate->code_event_dispatcher()->RemoveListener(&profiler_listener);
}
......@@ -337,8 +337,8 @@ TEST(Issue1398) {
unsigned actual_depth = 0;
const ProfileNode* node = profile->top_down()->root();
while (node->children()->length() > 0) {
node = node->children()->last();
while (!node->children()->empty()) {
node = node->children()->back();
++actual_depth;
}
......
......@@ -66,11 +66,12 @@ class NamedEntriesDetector {
void CheckAllReachables(i::HeapEntry* root) {
v8::base::HashMap visited;
i::List<i::HeapEntry*> list(10);
list.Add(root);
std::vector<i::HeapEntry*> list;
list.push_back(root);
CheckEntry(root);
while (!list.is_empty()) {
i::HeapEntry* entry = list.RemoveLast();
while (!list.empty()) {
i::HeapEntry* entry = list.back();
list.pop_back();
for (int i = 0; i < entry->children_count(); ++i) {
i::HeapGraphEdge* edge = entry->child(i);
if (edge->type() == i::HeapGraphEdge::kShortcut) continue;
......@@ -81,7 +82,7 @@ class NamedEntriesDetector {
if (entry->value)
continue;
entry->value = reinterpret_cast<void*>(1);
list.Add(child);
list.push_back(child);
CheckEntry(child);
}
}
......@@ -159,14 +160,14 @@ static bool ValidateSnapshot(const v8::HeapSnapshot* snapshot, int depth = 3) {
entry->value = reinterpret_cast<void*>(ref_count + 1);
}
uint32_t unretained_entries_count = 0;
i::List<i::HeapEntry>& entries = heap_snapshot->entries();
for (int i = 0; i < entries.length(); ++i) {
v8::base::HashMap::Entry* entry = visited.Lookup(
reinterpret_cast<void*>(&entries[i]),
static_cast<uint32_t>(reinterpret_cast<uintptr_t>(&entries[i])));
if (!entry && entries[i].id() != 1) {
entries[i].Print("entry with no retainer", "", depth, 0);
++unretained_entries_count;
std::vector<i::HeapEntry>& entries = heap_snapshot->entries();
for (i::HeapEntry& entry : entries) {
v8::base::HashMap::Entry* map_entry = visited.Lookup(
reinterpret_cast<void*>(&entry),
static_cast<uint32_t>(reinterpret_cast<uintptr_t>(&entry)));
if (!map_entry && entry.id() != 1) {
entry.Print("entry with no retainer", "", depth, 0);
++unretained_entries_count;
}
}
return unretained_entries_count == 0;
......@@ -1424,7 +1425,7 @@ class TestRetainedObjectInfo : public v8::RetainedObjectInfo {
label_(label),
element_count_(element_count),
size_(size) {
instances.Add(this);
instances.push_back(this);
}
virtual ~TestRetainedObjectInfo() {}
virtual void Dispose() {
......@@ -1462,7 +1463,7 @@ class TestRetainedObjectInfo : public v8::RetainedObjectInfo {
return NULL;
}
static i::List<TestRetainedObjectInfo*> instances;
static std::vector<TestRetainedObjectInfo*> instances;
private:
bool disposed_;
......@@ -1473,8 +1474,7 @@ class TestRetainedObjectInfo : public v8::RetainedObjectInfo {
intptr_t size_;
};
i::List<TestRetainedObjectInfo*> TestRetainedObjectInfo::instances;
std::vector<TestRetainedObjectInfo*> TestRetainedObjectInfo::instances;
} // namespace
......@@ -1510,14 +1510,14 @@ TEST(HeapSnapshotRetainedObjectInfo) {
p_BBB.SetWrapperClassId(1);
v8::Persistent<v8::String> p_CCC(isolate, v8_str("CCC"));
p_CCC.SetWrapperClassId(2);
CHECK_EQ(0, TestRetainedObjectInfo::instances.length());
CHECK(TestRetainedObjectInfo::instances.empty());
const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot();
CHECK(ValidateSnapshot(snapshot));
CHECK_EQ(3, TestRetainedObjectInfo::instances.length());
for (int i = 0; i < TestRetainedObjectInfo::instances.length(); ++i) {
CHECK(TestRetainedObjectInfo::instances[i]->disposed());
delete TestRetainedObjectInfo::instances[i];
CHECK_EQ(3, TestRetainedObjectInfo::instances.size());
for (TestRetainedObjectInfo* instance : TestRetainedObjectInfo::instances) {
CHECK(instance->disposed());
delete instance;
}
const v8::HeapGraphNode* native_group_aaa = GetNode(
......
......@@ -700,9 +700,9 @@ TEST(CanonicalHandleScope) {
CanonicalHandleScope outer_canonical(isolate);
// Deduplicate smi handles.
List<Handle<Object> > smi_handles;
std::vector<Handle<Object>> smi_handles;
for (int i = 0; i < 100; i++) {
smi_handles.Add(Handle<Object>(Smi::FromInt(i), isolate));
smi_handles.push_back(Handle<Object>(Smi::FromInt(i), isolate));
}
Object** next_handle = isolate->handle_scope_data()->next;
for (int i = 0; i < 100; i++) {
......
......@@ -193,16 +193,16 @@ class IsolateLockingThreadWithLocalContext : public JoinableThread {
v8::Isolate* isolate_;
};
static void StartJoinAndDeleteThreads(const i::List<JoinableThread*>& threads) {
for (int i = 0; i < threads.length(); i++) {
threads[i]->Start();
static void StartJoinAndDeleteThreads(
const std::vector<JoinableThread*>& threads) {
for (const auto& thread : threads) {
thread->Start();
}
for (int i = 0; i < threads.length(); i++) {
threads[i]->Join();
for (const auto& thread : threads) {
thread->Join();
}
for (int i = 0; i < threads.length(); i++) {
delete threads[i];
for (const auto& thread : threads) {
delete thread;
}
}
......@@ -215,12 +215,13 @@ TEST(IsolateLockingStress) {
#else
const int kNThreads = 100;
#endif
i::List<JoinableThread*> threads(kNThreads);
std::vector<JoinableThread*> threads;
threads.reserve(kNThreads);
v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
v8::Isolate* isolate = v8::Isolate::New(create_params);
for (int i = 0; i < kNThreads; i++) {
threads.Add(new IsolateLockingThreadWithLocalContext(isolate));
threads.push_back(new IsolateLockingThreadWithLocalContext(isolate));
}
StartJoinAndDeleteThreads(threads);
isolate->Dispose();
......@@ -262,9 +263,10 @@ TEST(IsolateNestedLocking) {
v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
v8::Isolate* isolate = v8::Isolate::New(create_params);
i::List<JoinableThread*> threads(kNThreads);
std::vector<JoinableThread*> threads;
threads.reserve(kNThreads);
for (int i = 0; i < kNThreads; i++) {
threads.Add(new IsolateNestedLockingThread(isolate));
threads.push_back(new IsolateNestedLockingThread(isolate));
}
StartJoinAndDeleteThreads(threads);
isolate->Dispose();
......@@ -308,10 +310,11 @@ TEST(SeparateIsolatesLocksNonexclusive) {
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
v8::Isolate* isolate1 = v8::Isolate::New(create_params);
v8::Isolate* isolate2 = v8::Isolate::New(create_params);
i::List<JoinableThread*> threads(kNThreads);
std::vector<JoinableThread*> threads;
threads.reserve(kNThreads);
for (int i = 0; i < kNThreads; i++) {
threads.Add(new SeparateIsolatesLocksNonexclusiveThread(isolate1,
isolate2));
threads.push_back(
new SeparateIsolatesLocksNonexclusiveThread(isolate1, isolate2));
}
StartJoinAndDeleteThreads(threads);
isolate2->Dispose();
......@@ -388,12 +391,13 @@ TEST(LockerUnlocker) {
#else
const int kNThreads = 100;
#endif
i::List<JoinableThread*> threads(kNThreads);
std::vector<JoinableThread*> threads;
threads.reserve(kNThreads);
v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
v8::Isolate* isolate = v8::Isolate::New(create_params);
for (int i = 0; i < kNThreads; i++) {
threads.Add(new LockerUnlockerThread(isolate));
threads.push_back(new LockerUnlockerThread(isolate));
}
StartJoinAndDeleteThreads(threads);
isolate->Dispose();
......@@ -445,12 +449,13 @@ TEST(LockTwiceAndUnlock) {
#else
const int kNThreads = 100;
#endif
i::List<JoinableThread*> threads(kNThreads);
std::vector<JoinableThread*> threads;
threads.reserve(kNThreads);
v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
v8::Isolate* isolate = v8::Isolate::New(create_params);
for (int i = 0; i < kNThreads; i++) {
threads.Add(new LockTwiceAndUnlockThread(isolate));
threads.push_back(new LockTwiceAndUnlockThread(isolate));
}
StartJoinAndDeleteThreads(threads);
isolate->Dispose();
......@@ -574,15 +579,15 @@ TEST(LockUnlockLockMultithreaded) {
v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
v8::Isolate* isolate = v8::Isolate::New(create_params);
i::List<JoinableThread*> threads(kNThreads);
std::vector<JoinableThread*> threads;
threads.reserve(kNThreads);
{
v8::Locker locker_(isolate);
v8::Isolate::Scope isolate_scope(isolate);
v8::HandleScope handle_scope(isolate);
v8::Local<v8::Context> context = v8::Context::New(isolate);
for (int i = 0; i < kNThreads; i++) {
threads.Add(new LockUnlockLockThread(
isolate, context));
threads.push_back(new LockUnlockLockThread(isolate, context));
}
}
StartJoinAndDeleteThreads(threads);
......@@ -632,14 +637,15 @@ TEST(LockUnlockLockDefaultIsolateMultithreaded) {
const int kNThreads = 100;
#endif
Local<v8::Context> context;
i::List<JoinableThread*> threads(kNThreads);
std::vector<JoinableThread*> threads;
threads.reserve(kNThreads);
{
v8::Locker locker_(CcTest::isolate());
v8::Isolate::Scope isolate_scope(CcTest::isolate());
v8::HandleScope handle_scope(CcTest::isolate());
context = v8::Context::New(CcTest::isolate());
for (int i = 0; i < kNThreads; i++) {
threads.Add(new LockUnlockLockDefaultIsolateThread(context));
threads.push_back(new LockUnlockLockDefaultIsolateThread(context));
}
}
StartJoinAndDeleteThreads(threads);
......@@ -731,9 +737,10 @@ TEST(ExtensionsRegistration) {
const char* extension_names[] = { "test0", "test1",
"test2", "test3", "test4",
"test5", "test6", "test7" };
i::List<JoinableThread*> threads(kNThreads);
std::vector<JoinableThread*> threads;
threads.reserve(kNThreads);
for (int i = 0; i < kNThreads; i++) {
threads.Add(new IsolateGenesisThread(8, extension_names));
threads.push_back(new IsolateGenesisThread(8, extension_names));
}
StartJoinAndDeleteThreads(threads);
}
......@@ -407,11 +407,10 @@ TEST(RecordTickSample) {
delete entry3;
}
static void CheckNodeIds(ProfileNode* node, unsigned* expectedId) {
static void CheckNodeIds(const ProfileNode* node, unsigned* expectedId) {
CHECK_EQ((*expectedId)++, node->id());
for (int i = 0; i < node->children()->length(); i++) {
CheckNodeIds(node->children()->at(i), expectedId);
for (const ProfileNode* child : *node->children()) {
CheckNodeIds(child, expectedId);
}
}
......@@ -506,8 +505,7 @@ TEST(NoSamples) {
static const ProfileNode* PickChild(const ProfileNode* parent,
const char* name) {
for (int i = 0; i < parent->children()->length(); ++i) {
const ProfileNode* child = parent->children()->at(i);
for (const ProfileNode* child : *parent->children()) {
if (strcmp(child->entry()->name(), name) == 0) return child;
}
return NULL;
......@@ -554,11 +552,10 @@ TEST(RecordStackTraceAtStartProfiling) {
CHECK(const_cast<ProfileNode*>(current));
current = PickChild(current, "c");
CHECK(const_cast<ProfileNode*>(current));
CHECK(current->children()->length() == 0 ||
current->children()->length() == 1);
if (current->children()->length() == 1) {
CHECK(current->children()->empty() || current->children()->size() == 1);
if (current->children()->size() == 1) {
current = PickChild(current, "startProfiling");
CHECK_EQ(0, current->children()->length());
CHECK(current->children()->empty());
}
}
......
......@@ -30,12 +30,12 @@
#include "src/base/platform/platform.h"
#include "src/isolate.h"
#include "src/list-inl.h"
class ThreadIdValidationThread : public v8::base::Thread {
public:
ThreadIdValidationThread(v8::base::Thread* thread_to_start,
i::List<i::ThreadId>* refs, unsigned int thread_no,
std::vector<i::ThreadId>* refs,
unsigned int thread_no,
v8::base::Semaphore* semaphore)
: Thread(Options("ThreadRefValidationThread")),
refs_(refs),
......@@ -57,7 +57,7 @@ class ThreadIdValidationThread : public v8::base::Thread {
}
private:
i::List<i::ThreadId>* refs_;
std::vector<i::ThreadId>* refs_;
int thread_no_;
v8::base::Thread* thread_to_start_;
v8::base::Semaphore* semaphore_;
......@@ -66,16 +66,18 @@ class ThreadIdValidationThread : public v8::base::Thread {
TEST(ThreadIdValidation) {
const int kNThreads = 100;
i::List<ThreadIdValidationThread*> threads(kNThreads);
i::List<i::ThreadId> refs(kNThreads);
std::vector<ThreadIdValidationThread*> threads;
std::vector<i::ThreadId> refs;
threads.reserve(kNThreads);
refs.reserve(kNThreads);
v8::base::Semaphore semaphore(0);
ThreadIdValidationThread* prev = NULL;
for (int i = kNThreads - 1; i >= 0; i--) {
ThreadIdValidationThread* newThread =
new ThreadIdValidationThread(prev, &refs, i, &semaphore);
threads.Add(newThread);
threads.push_back(newThread);
prev = newThread;
refs.Add(i::ThreadId::Invalid());
refs.push_back(i::ThreadId::Invalid());
}
prev->Start();
for (int i = 0; i < kNThreads; i++) {
......
......@@ -6,8 +6,6 @@
#include "src/v8.h"
#include "src/list.h"
#include "src/list-inl.h"
#include "test/cctest/cctest.h"
#include "src/tracing/trace-event.h"
......@@ -34,16 +32,16 @@ struct MockTraceObject {
flags(flags) {}
};
typedef v8::internal::List<MockTraceObject*> MockTraceObjectList;
typedef std::vector<MockTraceObject*> MockTraceObjectList;
class MockTracingController : public v8::TracingController {
public:
MockTracingController() = default;
~MockTracingController() {
for (int i = 0; i < trace_object_list_.length(); ++i) {
for (size_t i = 0; i < trace_object_list_.size(); ++i) {
delete trace_object_list_[i];
}
trace_object_list_.Clear();
trace_object_list_.clear();
}
uint64_t AddTraceEvent(
......@@ -55,7 +53,7 @@ class MockTracingController : public v8::TracingController {
unsigned int flags) override {
MockTraceObject* to = new MockTraceObject(phase, std::string(name), id,
bind_id, num_args, flags);
trace_object_list_.Add(to);
trace_object_list_.push_back(to);
return 0;
}
......@@ -107,7 +105,7 @@ TEST(TraceEventDisabledCategory) {
// Disabled category, will not add events.
TRACE_EVENT_BEGIN0("cat", "e1");
TRACE_EVENT_END0("cat", "e1");
CHECK_EQ(0, GET_TRACE_OBJECTS_LIST->length());
CHECK(GET_TRACE_OBJECTS_LIST->empty());
}
......@@ -118,7 +116,7 @@ TEST(TraceEventNoArgs) {
TRACE_EVENT_BEGIN0("v8-cat", "e1");
TRACE_EVENT_END0("v8-cat", "e1");
CHECK_EQ(2, GET_TRACE_OBJECTS_LIST->length());
CHECK_EQ(2, GET_TRACE_OBJECTS_LIST->size());
CHECK_EQ('B', GET_TRACE_OBJECT(0)->phase);
CHECK_EQ("e1", GET_TRACE_OBJECT(0)->name);
CHECK_EQ(0, GET_TRACE_OBJECT(0)->num_args);
......@@ -137,7 +135,7 @@ TEST(TraceEventWithOneArg) {
TRACE_EVENT_BEGIN1("v8-cat", "e2", "arg1", "abc");
TRACE_EVENT_END1("v8-cat", "e2", "arg1", "abc");
CHECK_EQ(4, GET_TRACE_OBJECTS_LIST->length());
CHECK_EQ(4, GET_TRACE_OBJECTS_LIST->size());
CHECK_EQ(1, GET_TRACE_OBJECT(0)->num_args);
CHECK_EQ(1, GET_TRACE_OBJECT(1)->num_args);
......@@ -154,7 +152,7 @@ TEST(TraceEventWithTwoArgs) {
TRACE_EVENT_BEGIN2("v8-cat", "e2", "arg1", "abc", "arg2", 43);
TRACE_EVENT_END2("v8-cat", "e2", "arg1", "abc", "arg2", 43);
CHECK_EQ(4, GET_TRACE_OBJECTS_LIST->length());
CHECK_EQ(4, GET_TRACE_OBJECTS_LIST->size());
CHECK_EQ(2, GET_TRACE_OBJECT(0)->num_args);
CHECK_EQ(2, GET_TRACE_OBJECT(1)->num_args);
......@@ -168,17 +166,17 @@ TEST(ScopedTraceEvent) {
{ TRACE_EVENT0("v8-cat", "e"); }
CHECK_EQ(1, GET_TRACE_OBJECTS_LIST->length());
CHECK_EQ(1, GET_TRACE_OBJECTS_LIST->size());
CHECK_EQ(0, GET_TRACE_OBJECT(0)->num_args);
{ TRACE_EVENT1("v8-cat", "e1", "arg1", "abc"); }
CHECK_EQ(2, GET_TRACE_OBJECTS_LIST->length());
CHECK_EQ(2, GET_TRACE_OBJECTS_LIST->size());
CHECK_EQ(1, GET_TRACE_OBJECT(1)->num_args);
{ TRACE_EVENT2("v8-cat", "e1", "arg1", "abc", "arg2", 42); }
CHECK_EQ(3, GET_TRACE_OBJECTS_LIST->length());
CHECK_EQ(3, GET_TRACE_OBJECTS_LIST->size());
CHECK_EQ(2, GET_TRACE_OBJECT(2)->num_args);
}
......@@ -197,7 +195,7 @@ TEST(TestEventWithFlow) {
}
{ TRACE_EVENT_WITH_FLOW0("v8-cat", "f3", bind_id, TRACE_EVENT_FLAG_FLOW_IN); }
CHECK_EQ(3, GET_TRACE_OBJECTS_LIST->length());
CHECK_EQ(3, GET_TRACE_OBJECTS_LIST->size());
CHECK_EQ(bind_id, GET_TRACE_OBJECT(0)->bind_id);
CHECK_EQ(TRACE_EVENT_FLAG_FLOW_OUT, GET_TRACE_OBJECT(0)->flags);
CHECK_EQ(bind_id, GET_TRACE_OBJECT(1)->bind_id);
......@@ -215,7 +213,7 @@ TEST(TestEventWithId) {
TRACE_EVENT_ASYNC_BEGIN0("v8-cat", "a1", event_id);
TRACE_EVENT_ASYNC_END0("v8-cat", "a1", event_id);
CHECK_EQ(2, GET_TRACE_OBJECTS_LIST->length());
CHECK_EQ(2, GET_TRACE_OBJECTS_LIST->size());
CHECK_EQ(TRACE_EVENT_PHASE_ASYNC_BEGIN, GET_TRACE_OBJECT(0)->phase);
CHECK_EQ(event_id, GET_TRACE_OBJECT(0)->id);
CHECK_EQ(TRACE_EVENT_PHASE_ASYNC_END, GET_TRACE_OBJECT(1)->phase);
......@@ -231,7 +229,7 @@ TEST(TestEventInContext) {
TRACE_EVENT0("v8-cat", "e");
}
CHECK_EQ(3, GET_TRACE_OBJECTS_LIST->length());
CHECK_EQ(3, GET_TRACE_OBJECTS_LIST->size());
CHECK_EQ(TRACE_EVENT_PHASE_ENTER_CONTEXT, GET_TRACE_OBJECT(0)->phase);
CHECK_EQ("Isolate", GET_TRACE_OBJECT(0)->name);
CHECK_EQ(isolate_id, GET_TRACE_OBJECT(0)->id);
......
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