Commit 2261a0dd authored by Peter Marshall's avatar Peter Marshall Committed by Commit Bot

[cleanup] Replace List with std::vector in IC, Handle code.

Bug: v8:6333
Change-Id: I53d321292b0a2c7b7f72ee90bd119484f163bdc1
Reviewed-on: https://chromium-review.googlesource.com/637913
Commit-Queue: Peter Marshall <petermarshall@chromium.org>
Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Reviewed-by: 's avatarMarja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47701}
parent 11ba497c
......@@ -5,8 +5,9 @@
#ifndef V8_COLLECTOR_H_
#define V8_COLLECTOR_H_
#include <vector>
#include "src/checks.h"
#include "src/list-inl.h"
#include "src/vector.h"
namespace v8 {
......@@ -32,8 +33,8 @@ class Collector {
virtual ~Collector() {
// Free backing store (in reverse allocation order).
current_chunk_.Dispose();
for (int i = chunks_.length() - 1; i >= 0; i--) {
chunks_.at(i).Dispose();
for (auto rit = chunks_.rbegin(); rit != chunks_.rend(); ++rit) {
rit->Dispose();
}
}
......@@ -86,8 +87,7 @@ class Collector {
void WriteTo(Vector<T> destination) {
DCHECK(size_ <= destination.length());
int position = 0;
for (int i = 0; i < chunks_.length(); i++) {
Vector<T> chunk = chunks_.at(i);
for (const Vector<T>& chunk : chunks_) {
for (int j = 0; j < chunk.length(); j++) {
destination[position] = chunk[j];
position++;
......@@ -111,10 +111,10 @@ class Collector {
// Resets the collector to be empty.
virtual void Reset() {
for (int i = chunks_.length() - 1; i >= 0; i--) {
chunks_.at(i).Dispose();
for (auto rit = chunks_.rbegin(); rit != chunks_.rend(); ++rit) {
rit->Dispose();
}
chunks_.Rewind(0);
chunks_.clear();
index_ = 0;
size_ = 0;
}
......@@ -124,7 +124,7 @@ class Collector {
protected:
static const int kMinCapacity = 16;
List<Vector<T> > chunks_;
std::vector<Vector<T>> chunks_;
Vector<T> current_chunk_; // Block of memory currently being written into.
int index_; // Current index in current chunk.
int size_; // Total number of elements in collector.
......@@ -159,7 +159,7 @@ class Collector {
virtual void NewChunk(int new_capacity) {
Vector<T> new_chunk = Vector<T>::New(new_capacity);
if (index_ > 0) {
chunks_.Add(current_chunk_.SubVector(0, index_));
chunks_.push_back(current_chunk_.SubVector(0, index_));
} else {
current_chunk_.Dispose();
}
......@@ -231,7 +231,8 @@ class SequenceCollector : public Collector<T, growth_factor, max_growth> {
new_chunk[i] = this->current_chunk_[sequence_start_ + i];
}
if (sequence_start_ > 0) {
this->chunks_.Add(this->current_chunk_.SubVector(0, sequence_start_));
this->chunks_.push_back(
this->current_chunk_.SubVector(0, sequence_start_));
} else {
this->current_chunk_.Dispose();
}
......
......@@ -16,7 +16,6 @@
#include "src/dtoa.h"
#include "src/factory.h"
#include "src/handles.h"
#include "src/list-inl.h"
#include "src/strtod.h"
#include "src/utils.h"
......
......@@ -691,7 +691,7 @@ void FeedbackNexus::ConfigureMonomorphic(Handle<Name> name,
void FeedbackNexus::ConfigurePolymorphic(Handle<Name> name,
MapHandles const& maps,
List<Handle<Object>>* handlers) {
ObjectHandles* handlers) {
int receiver_count = static_cast<int>(maps.size());
DCHECK(receiver_count > 1);
Handle<FixedArray> array;
......@@ -782,8 +782,7 @@ MaybeHandle<Object> FeedbackNexus::FindHandlerForMap(Handle<Map> map) const {
return MaybeHandle<Code>();
}
bool FeedbackNexus::FindHandlers(List<Handle<Object>>* code_list,
int length) const {
bool FeedbackNexus::FindHandlers(ObjectHandles* code_list, int length) const {
Object* feedback = GetFeedback();
Isolate* isolate = GetIsolate();
int count = 0;
......@@ -801,7 +800,7 @@ bool FeedbackNexus::FindHandlers(List<Handle<Object>>* code_list,
if (!cell->cleared()) {
Object* code = array->get(i + increment - 1);
DCHECK(IC::IsHandler(code));
code_list->Add(handle(code, isolate));
code_list->push_back(handle(code, isolate));
count++;
}
}
......@@ -810,7 +809,7 @@ bool FeedbackNexus::FindHandlers(List<Handle<Object>>* code_list,
if (!cell->cleared()) {
Object* code = GetFeedbackExtra();
DCHECK(IC::IsHandler(code));
code_list->Add(handle(code, isolate));
code_list->push_back(handle(code, isolate));
count++;
}
}
......@@ -836,15 +835,14 @@ Name* KeyedStoreICNexus::FindFirstName() const {
KeyedAccessStoreMode KeyedStoreICNexus::GetKeyedAccessStoreMode() const {
KeyedAccessStoreMode mode = STANDARD_STORE;
MapHandles maps;
List<Handle<Object>> handlers;
ObjectHandles handlers;
if (GetKeyType() == PROPERTY) return mode;
ExtractMaps(&maps);
FindHandlers(&handlers, static_cast<int>(maps.size()));
for (int i = 0; i < handlers.length(); i++) {
for (const Handle<Object>& maybe_code_handler : handlers) {
// The first handler that isn't the slow handler will have the bits we need.
Handle<Object> maybe_code_handler = handlers.at(i);
Handle<Code> handler;
if (maybe_code_handler->IsTuple3()) {
// Elements transition.
......
......@@ -108,6 +108,8 @@ inline LanguageMode GetLanguageModeFromSlotKind(FeedbackSlotKind kind) {
std::ostream& operator<<(std::ostream& os, FeedbackSlotKind kind);
typedef std::vector<Handle<Object>> ObjectHandles;
class FeedbackMetadata;
// A FeedbackVector has a fixed header with:
......@@ -554,8 +556,7 @@ class FeedbackNexus {
virtual InlineCacheState StateFromFeedback() const = 0;
virtual int ExtractMaps(MapHandles* maps) const;
virtual MaybeHandle<Object> FindHandlerForMap(Handle<Map> map) const;
virtual bool FindHandlers(List<Handle<Object>>* code_list,
int length = -1) const;
virtual bool FindHandlers(ObjectHandles* code_list, int length = -1) const;
virtual Name* FindFirstName() const { return NULL; }
bool IsCleared() {
......@@ -577,7 +578,7 @@ class FeedbackNexus {
Handle<Object> handler);
void ConfigurePolymorphic(Handle<Name> name, MapHandles const& maps,
List<Handle<Object>>* handlers);
ObjectHandles* handlers);
protected:
inline void SetFeedback(Object* feedback,
......@@ -620,8 +621,7 @@ class CallICNexus final : public FeedbackNexus {
MaybeHandle<Object> FindHandlerForMap(Handle<Map> map) const final {
return MaybeHandle<Code>();
}
bool FindHandlers(List<Handle<Object>>* code_list,
int length = -1) const final {
bool FindHandlers(ObjectHandles* code_list, int length = -1) const final {
return length == 0;
}
......@@ -666,8 +666,7 @@ class LoadGlobalICNexus : public FeedbackNexus {
MaybeHandle<Object> FindHandlerForMap(Handle<Map> map) const final {
return MaybeHandle<Code>();
}
bool FindHandlers(List<Handle<Object>>* code_list,
int length = -1) const final {
bool FindHandlers(ObjectHandles* code_list, int length = -1) const final {
return length == 0;
}
......@@ -759,8 +758,7 @@ class BinaryOpICNexus final : public FeedbackNexus {
MaybeHandle<Object> FindHandlerForMap(Handle<Map> map) const final {
return MaybeHandle<Code>();
}
bool FindHandlers(List<Handle<Object>>* code_list,
int length = -1) const final {
bool FindHandlers(ObjectHandles* code_list, int length = -1) const final {
return length == 0;
}
};
......@@ -786,8 +784,7 @@ class CompareICNexus final : public FeedbackNexus {
MaybeHandle<Object> FindHandlerForMap(Handle<Map> map) const final {
return MaybeHandle<Code>();
}
bool FindHandlers(List<Handle<Object>>* code_list,
int length = -1) const final {
bool FindHandlers(ObjectHandles* code_list, int length = -1) const final {
return length == 0;
}
};
......@@ -805,8 +802,7 @@ class ForInICNexus final : public FeedbackNexus {
MaybeHandle<Object> FindHandlerForMap(Handle<Map> map) const final {
return MaybeHandle<Code>();
}
bool FindHandlers(List<Handle<Object>>* code_list,
int length = -1) const final {
bool FindHandlers(ObjectHandles* code_list, int length = -1) const final {
return length == 0;
}
};
......
......@@ -12,7 +12,6 @@
#include "src/assembler.h"
#include "src/base/functional.h"
#include "src/base/platform/platform.h"
#include "src/list-inl.h"
#include "src/ostreams.h"
#include "src/utils.h"
#include "src/wasm/wasm-limits.h"
......@@ -249,8 +248,8 @@ std::ostream& operator<<(std::ostream& os, const Flag& flag) { // NOLINT
// static
List<const char*>* FlagList::argv() {
List<const char*>* args = new List<const char*>(8);
std::vector<const char*>* FlagList::argv() {
std::vector<const char*>* args = new std::vector<const char*>(8);
Flag* args_flag = NULL;
for (size_t i = 0; i < num_flags; ++i) {
Flag* f = &flags[i];
......@@ -264,22 +263,22 @@ List<const char*>* FlagList::argv() {
bool disabled = f->type() == Flag::TYPE_BOOL && !*f->bool_variable();
std::ostringstream os;
os << (disabled ? "--no" : "--") << f->name();
args->Add(StrDup(os.str().c_str()));
args->push_back(StrDup(os.str().c_str()));
}
if (f->type() != Flag::TYPE_BOOL) {
std::ostringstream os;
os << *f;
args->Add(StrDup(os.str().c_str()));
args->push_back(StrDup(os.str().c_str()));
}
}
}
if (args_flag != NULL) {
std::ostringstream os;
os << "--" << args_flag->name();
args->Add(StrDup(os.str().c_str()));
args->push_back(StrDup(os.str().c_str()));
JSArguments jsargs = *args_flag->args_variable();
for (int j = 0; j < jsargs.argc; j++) {
args->Add(StrDup(jsargs[j]));
args->push_back(StrDup(jsargs[j]));
}
}
return args;
......
......@@ -5,6 +5,8 @@
#ifndef V8_FLAGS_H_
#define V8_FLAGS_H_
#include <vector>
#include "src/globals.h"
namespace v8 {
......@@ -24,7 +26,7 @@ class V8_EXPORT_PRIVATE FlagList {
//
// The caller is responsible for disposing the list, as well
// as every element of it.
static List<const char*>* argv();
static std::vector<const char*>* argv();
// Set the flag values by parsing the command line. If remove_flags is
// set, the flags and associated values are removed from (argc,
......
......@@ -11,7 +11,6 @@
#include "src/conversions.h"
#include "src/handles-inl.h"
#include "src/isolate.h"
#include "src/list-inl.h"
#include "src/objects-inl.h"
namespace v8 {
......
This diff is collapsed.
......@@ -6,12 +6,12 @@
#define V8_GLOBAL_HANDLES_H_
#include <type_traits>
#include <vector>
#include "include/v8.h"
#include "include/v8-profiler.h"
#include "src/handles.h"
#include "src/list.h"
#include "src/utils.h"
namespace v8 {
......@@ -92,7 +92,7 @@ class GlobalHandles {
number_of_phantom_handle_resets_ = 0;
}
size_t NumberOfNewSpaceNodes() { return new_space_nodes_.length(); }
size_t NumberOfNewSpaceNodes() { return new_space_nodes_.size(); }
// Clear the weakness of a global handle.
static void* ClearWeakness(Object** location);
......@@ -188,7 +188,7 @@ class GlobalHandles {
// Helpers for PostGarbageCollectionProcessing.
static void InvokeSecondPassPhantomCallbacks(
List<PendingPhantomCallback>* callbacks, Isolate* isolate);
std::vector<PendingPhantomCallback>* callbacks, Isolate* isolate);
int PostScavengeProcessing(int initial_post_gc_processing_count);
int PostMarkSweepProcessing(int initial_post_gc_processing_count);
int DispatchPendingPhantomCallbacks(bool synchronous_second_pass);
......@@ -212,13 +212,13 @@ class GlobalHandles {
// Contains all nodes holding new space objects. Note: when the list
// is accessed, some of the objects may have been promoted already.
List<Node*> new_space_nodes_;
std::vector<Node*> new_space_nodes_;
int post_gc_processing_count_;
size_t number_of_phantom_handle_resets_;
List<PendingPhantomCallback> pending_phantom_callbacks_;
std::vector<PendingPhantomCallback> pending_phantom_callbacks_;
friend class Isolate;
......@@ -311,8 +311,8 @@ class EternalHandles {
}
int size_;
List<Object**> blocks_;
List<int> new_space_indices_;
std::vector<Object**> blocks_;
std::vector<int> new_space_indices_;
int singleton_handles_[NUMBER_OF_SINGLETON_HANDLES];
DISALLOW_COPY_AND_ASSIGN(EternalHandles);
......
......@@ -411,7 +411,7 @@ void IC::ConfigureVectorState(Handle<Name> name, Handle<Map> map,
}
void IC::ConfigureVectorState(Handle<Name> name, MapHandles const& maps,
List<Handle<Object>>* handlers) {
ObjectHandles* handlers) {
DCHECK(!IsLoadGlobalIC());
// Non-keyed ICs don't track the name explicitly.
if (!is_keyed()) name = Handle<Name>::null();
......@@ -518,7 +518,7 @@ bool IC::UpdatePolymorphicIC(Handle<Name> name, Handle<Object> handler) {
if (is_keyed() && state() != RECOMPUTE_HANDLER) return false;
Handle<Map> map = receiver_map();
MapHandles maps;
List<Handle<Object>> handlers;
ObjectHandles handlers;
TargetMaps(&maps);
int number_of_maps = static_cast<int>(maps.size());
......@@ -558,13 +558,13 @@ bool IC::UpdatePolymorphicIC(Handle<Name> name, Handle<Object> handler) {
ConfigureVectorState(name, receiver_map(), handler);
} else {
if (handler_to_overwrite >= 0) {
handlers.Set(handler_to_overwrite, handler);
handlers[handler_to_overwrite] = handler;
if (!map.is_identical_to(maps.at(handler_to_overwrite))) {
maps[handler_to_overwrite] = map;
}
} else {
maps.push_back(map);
handlers.Add(handler);
handlers.push_back(handler);
}
ConfigureVectorState(name, maps, &handlers);
......@@ -581,7 +581,7 @@ void IC::UpdateMonomorphicIC(Handle<Object> handler, Handle<Name> name) {
void IC::CopyICToMegamorphicCache(Handle<Name> name) {
MapHandles maps;
List<Handle<Object>> handlers;
ObjectHandles handlers;
TargetMaps(&maps);
if (!nexus()->FindHandlers(&handlers, static_cast<int>(maps.size()))) return;
for (int i = 0; i < static_cast<int>(maps.size()); i++) {
......@@ -1276,12 +1276,12 @@ void KeyedLoadIC::UpdateLoadElement(Handle<HeapObject> receiver) {
return;
}
List<Handle<Object>> handlers(static_cast<int>(target_receiver_maps.size()));
ObjectHandles handlers;
handlers.reserve(target_receiver_maps.size());
LoadElementPolymorphicHandlers(&target_receiver_maps, &handlers);
DCHECK_LE(1, target_receiver_maps.size());
if (target_receiver_maps.size() == 1) {
ConfigureVectorState(Handle<Name>(), target_receiver_maps[0],
handlers.at(0));
ConfigureVectorState(Handle<Name>(), target_receiver_maps[0], handlers[0]);
} else {
ConfigureVectorState(Handle<Name>(), target_receiver_maps, &handlers);
}
......@@ -1328,8 +1328,8 @@ Handle<Object> KeyedLoadIC::LoadElementHandler(Handle<Map> receiver_map) {
convert_hole_to_undefined, is_js_array);
}
void KeyedLoadIC::LoadElementPolymorphicHandlers(
MapHandles* receiver_maps, List<Handle<Object>>* handlers) {
void KeyedLoadIC::LoadElementPolymorphicHandlers(MapHandles* receiver_maps,
ObjectHandles* handlers) {
// Filter out deprecated maps to ensure their instances get migrated.
receiver_maps->erase(
std::remove_if(
......@@ -1347,7 +1347,7 @@ void KeyedLoadIC::LoadElementPolymorphicHandlers(
receiver_map->NotifyLeafMapLayoutChange();
}
}
handlers->Add(LoadElementHandler(receiver_map));
handlers->push_back(LoadElementHandler(receiver_map));
}
}
......@@ -1959,13 +1959,13 @@ void KeyedStoreIC::UpdateStoreElement(Handle<Map> receiver_map,
}
}
List<Handle<Object>> handlers(static_cast<int>(target_receiver_maps.size()));
ObjectHandles handlers;
handlers.reserve(target_receiver_maps.size());
StoreElementPolymorphicHandlers(&target_receiver_maps, &handlers, store_mode);
if (target_receiver_maps.size() == 0) {
ConfigureVectorState(PREMONOMORPHIC, Handle<Name>());
} else if (target_receiver_maps.size() == 1) {
ConfigureVectorState(Handle<Name>(), target_receiver_maps[0],
handlers.at(0));
ConfigureVectorState(Handle<Name>(), target_receiver_maps[0], handlers[0]);
} else {
ConfigureVectorState(Handle<Name>(), target_receiver_maps, &handlers);
}
......@@ -2032,7 +2032,7 @@ Handle<Object> KeyedStoreIC::StoreElementHandler(
}
void KeyedStoreIC::StoreElementPolymorphicHandlers(
MapHandles* receiver_maps, List<Handle<Object>>* handlers,
MapHandles* receiver_maps, ObjectHandles* handlers,
KeyedAccessStoreMode store_mode) {
DCHECK(store_mode == STANDARD_STORE ||
store_mode == STORE_AND_GROW_NO_TRANSITION ||
......@@ -2097,7 +2097,7 @@ void KeyedStoreIC::StoreElementPolymorphicHandlers(
}
}
DCHECK(!handler.is_null());
handlers->Add(handler);
handlers->push_back(handler);
}
}
......
......@@ -5,6 +5,8 @@
#ifndef V8_IC_H_
#define V8_IC_H_
#include <vector>
#include "src/factory.h"
#include "src/feedback-vector.h"
#include "src/macro-assembler.h"
......@@ -93,7 +95,7 @@ class IC {
Handle<Object> handler);
// Configure the vector for POLYMORPHIC.
void ConfigureVectorState(Handle<Name> name, MapHandles const& maps,
List<Handle<Object>>* handlers);
ObjectHandles* handlers);
char TransitionMarkFromState(IC::State state);
void TraceIC(const char* type, Handle<Object> name);
......@@ -314,7 +316,7 @@ class KeyedLoadIC : public LoadIC {
Handle<Object> LoadElementHandler(Handle<Map> receiver_map);
void LoadElementPolymorphicHandlers(MapHandles* receiver_maps,
List<Handle<Object>>* handlers);
ObjectHandles* handlers);
};
......@@ -403,7 +405,7 @@ class KeyedStoreIC : public StoreIC {
KeyedAccessStoreMode store_mode);
void StoreElementPolymorphicHandlers(MapHandles* receiver_maps,
List<Handle<Object>>* handlers,
ObjectHandles* handlers,
KeyedAccessStoreMode store_mode);
friend class IC;
......
......@@ -6,7 +6,6 @@
#include "src/ast/ast-value-factory.h"
#include "src/ast/ast.h"
#include "src/list-inl.h"
#include "src/objects-inl.h"
namespace v8 {
......
......@@ -13,7 +13,6 @@
#include "src/ast/ast-value-factory.h"
#include "src/char-predicates-inl.h"
#include "src/conversions-inl.h"
#include "src/list-inl.h"
#include "src/parsing/duplicate-finder.h" // For Scanner::FindSymbol
namespace v8 {
......
......@@ -6,7 +6,6 @@
#include "src/external-reference-table.h"
#include "src/ic/stub-cache.h"
#include "src/list-inl.h"
#include "src/objects-inl.h"
namespace v8 {
......
......@@ -8,7 +8,6 @@
#include "src/base/platform/time.h"
#include "src/flags.h"
#include "src/isolate.h"
#include "src/list-inl.h"
#include "src/objects-inl.h"
#include "src/v8.h"
......@@ -101,9 +100,9 @@ SaveFlags::SaveFlags() { non_default_flags_ = FlagList::argv(); }
SaveFlags::~SaveFlags() {
FlagList::ResetAllFlags();
int argc = non_default_flags_->length();
int argc = static_cast<int>(non_default_flags_->size());
FlagList::SetFlagsFromCommandLine(
&argc, const_cast<char**>(non_default_flags_->begin()),
&argc, const_cast<char**>(non_default_flags_->data()),
false /* remove_flags */);
for (auto flag = non_default_flags_->begin();
flag != non_default_flags_->end(); ++flag) {
......
......@@ -5,10 +5,11 @@
#ifndef V8_UNITTESTS_TEST_UTILS_H_
#define V8_UNITTESTS_TEST_UTILS_H_
#include <vector>
#include "include/v8.h"
#include "src/base/macros.h"
#include "src/base/utils/random-number-generator.h"
#include "src/list.h"
#include "src/zone/accounting-allocator.h"
#include "src/zone/zone.h"
#include "testing/gtest-support.h"
......@@ -142,7 +143,7 @@ class SaveFlags {
~SaveFlags();
private:
List<const char*>* non_default_flags_;
std::vector<const char*>* non_default_flags_;
DISALLOW_COPY_AND_ASSIGN(SaveFlags);
};
......
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