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

[cleanup] Replace ZoneList with ZoneVector in frames, json-parser and

more.

Bug: v8:6333, v8:6921
Change-Id: I442190988f2c853560b28efa54e04ff73f9d94ca
Reviewed-on: https://chromium-review.googlesource.com/718343
Commit-Queue: Peter Marshall <petermarshall@chromium.org>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#49111}
parent e4a97a2e
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "src/visitors.h" #include "src/visitors.h"
#include "src/vm-state-inl.h" #include "src/vm-state-inl.h"
#include "src/wasm/wasm-objects-inl.h" #include "src/wasm/wasm-objects-inl.h"
#include "src/zone/zone-containers.h"
namespace v8 { namespace v8 {
namespace internal { namespace internal {
...@@ -2119,12 +2120,12 @@ static StackFrame* AllocateFrameCopy(StackFrame* frame, Zone* zone) { ...@@ -2119,12 +2120,12 @@ static StackFrame* AllocateFrameCopy(StackFrame* frame, Zone* zone) {
Vector<StackFrame*> CreateStackMap(Isolate* isolate, Zone* zone) { Vector<StackFrame*> CreateStackMap(Isolate* isolate, Zone* zone) {
ZoneList<StackFrame*> list(10, zone); ZoneVector<StackFrame*> frames(zone);
for (StackFrameIterator it(isolate); !it.done(); it.Advance()) { for (StackFrameIterator it(isolate); !it.done(); it.Advance()) {
StackFrame* frame = AllocateFrameCopy(it.frame(), zone); StackFrame* frame = AllocateFrameCopy(it.frame(), zone);
list.Add(frame, zone); frames.push_back(frame);
} }
return list.ToVector(); return Vector<StackFrame*>(frames.data(), frames.size());
} }
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "src/string-hasher.h" #include "src/string-hasher.h"
#include "src/transitions.h" #include "src/transitions.h"
#include "src/unicode-cache.h" #include "src/unicode-cache.h"
#include "src/zone/zone-containers.h"
namespace v8 { namespace v8 {
namespace internal { namespace internal {
...@@ -332,7 +333,7 @@ Handle<Object> JsonParser<seq_one_byte>::ParseJsonObject() { ...@@ -332,7 +333,7 @@ Handle<Object> JsonParser<seq_one_byte>::ParseJsonObject() {
factory()->NewJSObject(object_constructor(), pretenure_); factory()->NewJSObject(object_constructor(), pretenure_);
Handle<Map> map(json_object->map()); Handle<Map> map(json_object->map());
int descriptor = 0; int descriptor = 0;
ZoneList<Handle<Object> > properties(8, zone()); ZoneVector<Handle<Object>> properties(zone());
DCHECK_EQ(c0_, '{'); DCHECK_EQ(c0_, '{');
bool transitioning = true; bool transitioning = true;
...@@ -411,7 +412,7 @@ Handle<Object> JsonParser<seq_one_byte>::ParseJsonObject() { ...@@ -411,7 +412,7 @@ Handle<Object> JsonParser<seq_one_byte>::ParseJsonObject() {
DCHECK(target->instance_descriptors() DCHECK(target->instance_descriptors()
->GetFieldType(descriptor) ->GetFieldType(descriptor)
->NowContains(value)); ->NowContains(value));
properties.Add(value, zone()); properties.push_back(value);
map = target; map = target;
descriptor++; descriptor++;
continue; continue;
...@@ -479,13 +480,13 @@ Handle<Object> JsonParser<seq_one_byte>::ParseJsonObject() { ...@@ -479,13 +480,13 @@ Handle<Object> JsonParser<seq_one_byte>::ParseJsonObject() {
template <bool seq_one_byte> template <bool seq_one_byte>
void JsonParser<seq_one_byte>::CommitStateToJsonObject( void JsonParser<seq_one_byte>::CommitStateToJsonObject(
Handle<JSObject> json_object, Handle<Map> map, Handle<JSObject> json_object, Handle<Map> map,
ZoneList<Handle<Object> >* properties) { ZoneVector<Handle<Object>>* properties) {
JSObject::AllocateStorageForMap(json_object, map); JSObject::AllocateStorageForMap(json_object, map);
DCHECK(!json_object->map()->is_dictionary_map()); DCHECK(!json_object->map()->is_dictionary_map());
DisallowHeapAllocation no_gc; DisallowHeapAllocation no_gc;
DescriptorArray* descriptors = json_object->map()->instance_descriptors(); DescriptorArray* descriptors = json_object->map()->instance_descriptors();
int length = properties->length(); int length = static_cast<int>(properties->size());
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
Handle<Object> value = (*properties)[i]; Handle<Object> value = (*properties)[i];
// Initializing store. // Initializing store.
...@@ -537,7 +538,7 @@ class ElementKindLattice { ...@@ -537,7 +538,7 @@ class ElementKindLattice {
template <bool seq_one_byte> template <bool seq_one_byte>
Handle<Object> JsonParser<seq_one_byte>::ParseJsonArray() { Handle<Object> JsonParser<seq_one_byte>::ParseJsonArray() {
HandleScope scope(isolate()); HandleScope scope(isolate());
ZoneList<Handle<Object> > elements(4, zone()); ZoneVector<Handle<Object>> elements(zone());
DCHECK_EQ(c0_, '['); DCHECK_EQ(c0_, '[');
ElementKindLattice lattice; ElementKindLattice lattice;
...@@ -547,7 +548,7 @@ Handle<Object> JsonParser<seq_one_byte>::ParseJsonArray() { ...@@ -547,7 +548,7 @@ Handle<Object> JsonParser<seq_one_byte>::ParseJsonArray() {
do { do {
Handle<Object> element = ParseJsonValue(); Handle<Object> element = ParseJsonValue();
if (element.is_null()) return ReportUnexpectedCharacter(); if (element.is_null()) return ReportUnexpectedCharacter();
elements.Add(element, zone()); elements.push_back(element);
lattice.Update(element); lattice.Update(element);
} while (MatchSkipWhiteSpace(',')); } while (MatchSkipWhiteSpace(','));
if (c0_ != ']') { if (c0_ != ']') {
...@@ -560,20 +561,21 @@ Handle<Object> JsonParser<seq_one_byte>::ParseJsonArray() { ...@@ -560,20 +561,21 @@ Handle<Object> JsonParser<seq_one_byte>::ParseJsonArray() {
Handle<Object> json_array; Handle<Object> json_array;
const ElementsKind kind = lattice.GetElementsKind(); const ElementsKind kind = lattice.GetElementsKind();
int elements_size = static_cast<int>(elements.size());
switch (kind) { switch (kind) {
case PACKED_ELEMENTS: case PACKED_ELEMENTS:
case PACKED_SMI_ELEMENTS: { case PACKED_SMI_ELEMENTS: {
Handle<FixedArray> elems = Handle<FixedArray> elems =
factory()->NewFixedArray(elements.length(), pretenure_); factory()->NewFixedArray(elements_size, pretenure_);
for (int i = 0; i < elements.length(); i++) elems->set(i, *elements[i]); for (int i = 0; i < elements_size; i++) elems->set(i, *elements[i]);
json_array = factory()->NewJSArrayWithElements(elems, kind, pretenure_); json_array = factory()->NewJSArrayWithElements(elems, kind, pretenure_);
break; break;
} }
case PACKED_DOUBLE_ELEMENTS: { case PACKED_DOUBLE_ELEMENTS: {
Handle<FixedDoubleArray> elems = Handle<FixedDoubleArray>::cast( Handle<FixedDoubleArray> elems = Handle<FixedDoubleArray>::cast(
factory()->NewFixedDoubleArray(elements.length(), pretenure_)); factory()->NewFixedDoubleArray(elements_size, pretenure_));
for (int i = 0; i < elements.length(); i++) { for (int i = 0; i < elements_size; i++) {
elems->set(i, elements[i]->Number()); elems->set(i, elements[i]->Number());
} }
json_array = factory()->NewJSArrayWithElements(elems, kind, pretenure_); json_array = factory()->NewJSArrayWithElements(elems, kind, pretenure_);
......
...@@ -144,7 +144,7 @@ class JsonParser BASE_EMBEDDED { ...@@ -144,7 +144,7 @@ class JsonParser BASE_EMBEDDED {
Zone* zone() { return &zone_; } Zone* zone() { return &zone_; }
void CommitStateToJsonObject(Handle<JSObject> json_object, Handle<Map> map, void CommitStateToJsonObject(Handle<JSObject> json_object, Handle<Map> map,
ZoneList<Handle<Object> >* properties); ZoneVector<Handle<Object>>* properties);
Handle<String> source_; Handle<String> source_;
int source_length_; int source_length_;
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define V8_ZONE_ZONE_HANDLE_SET_H_ #define V8_ZONE_ZONE_HANDLE_SET_H_
#include "src/handles.h" #include "src/handles.h"
#include "src/zone/zone-containers.h"
#include "src/zone/zone.h" #include "src/zone/zone.h"
namespace v8 { namespace v8 {
...@@ -25,7 +26,7 @@ class ZoneHandleSet final { ...@@ -25,7 +26,7 @@ class ZoneHandleSet final {
size_t size() const { size_t size() const {
if ((data_ & kTagMask) == kEmptyTag) return 0; if ((data_ & kTagMask) == kEmptyTag) return 0;
if ((data_ & kTagMask) == kSingletonTag) return 1; if ((data_ & kTagMask) == kSingletonTag) return 1;
return list()->length(); return list()->size();
} }
Handle<T> at(size_t i) const { Handle<T> at(size_t i) const {
...@@ -46,34 +47,35 @@ class ZoneHandleSet final { ...@@ -46,34 +47,35 @@ class ZoneHandleSet final {
data_ = bit_cast<intptr_t>(value) | kSingletonTag; data_ = bit_cast<intptr_t>(value) | kSingletonTag;
} else if ((data_ & kTagMask) == kSingletonTag) { } else if ((data_ & kTagMask) == kSingletonTag) {
if (singleton() == value) return; if (singleton() == value) return;
List* list = new (zone) List(2, zone); List* list = new (zone->New(sizeof(List))) List(zone);
if (singleton() < value) { if (singleton() < value) {
list->Add(singleton(), zone); list->push_back(singleton());
list->Add(value, zone); list->push_back(value);
} else { } else {
list->Add(value, zone); list->push_back(value);
list->Add(singleton(), zone); list->push_back(singleton());
} }
DCHECK(IsAligned(bit_cast<intptr_t>(list), kPointerAlignment)); DCHECK(IsAligned(bit_cast<intptr_t>(list), kPointerAlignment));
data_ = bit_cast<intptr_t>(list) | kListTag; data_ = bit_cast<intptr_t>(list) | kListTag;
} else { } else {
DCHECK_EQ(kListTag, data_ & kTagMask); DCHECK_EQ(kListTag, data_ & kTagMask);
List const* const old_list = list(); List const* const old_list = list();
for (int i = 0; i < old_list->length(); ++i) { for (size_t i = 0; i < old_list->size(); ++i) {
if (old_list->at(i) == value) return; if (old_list->at(i) == value) return;
if (old_list->at(i) > value) break; if (old_list->at(i) > value) break;
} }
List* new_list = new (zone) List(old_list->length() + 1, zone); List* new_list = new (zone->New(sizeof(List))) List(zone);
int i = 0; new_list->reserve(old_list->size() + 1);
for (; i < old_list->length(); ++i) { size_t i = 0;
for (; i < old_list->size(); ++i) {
if (old_list->at(i) > value) break; if (old_list->at(i) > value) break;
new_list->Add(old_list->at(i), zone); new_list->push_back(old_list->at(i));
} }
new_list->Add(value, zone); new_list->push_back(value);
for (; i < old_list->length(); ++i) { for (; i < old_list->size(); ++i) {
new_list->Add(old_list->at(i), zone); new_list->push_back(old_list->at(i));
} }
DCHECK_EQ(old_list->length() + 1, new_list->length()); DCHECK_EQ(old_list->size() + 1, new_list->size());
DCHECK(IsAligned(bit_cast<intptr_t>(new_list), kPointerAlignment)); DCHECK(IsAligned(bit_cast<intptr_t>(new_list), kPointerAlignment));
data_ = bit_cast<intptr_t>(new_list) | kListTag; data_ = bit_cast<intptr_t>(new_list) | kListTag;
} }
...@@ -85,13 +87,18 @@ class ZoneHandleSet final { ...@@ -85,13 +87,18 @@ class ZoneHandleSet final {
if (other.data_ == kEmptyTag) return true; if (other.data_ == kEmptyTag) return true;
if ((data_ & kTagMask) == kSingletonTag) return false; if ((data_ & kTagMask) == kSingletonTag) return false;
DCHECK_EQ(kListTag, data_ & kTagMask); DCHECK_EQ(kListTag, data_ & kTagMask);
List const* cached_list = list();
if ((other.data_ & kTagMask) == kSingletonTag) { if ((other.data_ & kTagMask) == kSingletonTag) {
return list()->Contains(other.singleton()); return std::find(cached_list->begin(), cached_list->end(),
other.singleton()) != cached_list->end();
} }
DCHECK_EQ(kListTag, other.data_ & kTagMask); DCHECK_EQ(kListTag, other.data_ & kTagMask);
// TODO(bmeurer): Optimize this case. // TODO(bmeurer): Optimize this case.
for (int i = 0; i < other.list()->length(); ++i) { for (size_t i = 0; i < other.list()->size(); ++i) {
if (!list()->Contains(other.list()->at(i))) return false; if (std::find(cached_list->begin(), cached_list->end(),
other.list()->at(i)) == cached_list->end()) {
return false;
}
} }
return true; return true;
} }
...@@ -102,7 +109,8 @@ class ZoneHandleSet final { ...@@ -102,7 +109,8 @@ class ZoneHandleSet final {
return singleton() == bit_cast<T**>(other.address()); return singleton() == bit_cast<T**>(other.address());
} }
DCHECK_EQ(kListTag, data_ & kTagMask); DCHECK_EQ(kListTag, data_ & kTagMask);
return list()->Contains(bit_cast<T**>(other.address())); return std::find(list()->begin(), list()->end(),
bit_cast<T**>(other.address())) != list()->end();
} }
void remove(Handle<T> handle, Zone* zone) { void remove(Handle<T> handle, Zone* zone) {
...@@ -124,8 +132,8 @@ class ZoneHandleSet final { ...@@ -124,8 +132,8 @@ class ZoneHandleSet final {
(rhs.data_ & kTagMask) == kListTag) { (rhs.data_ & kTagMask) == kListTag) {
List const* const lhs_list = lhs.list(); List const* const lhs_list = lhs.list();
List const* const rhs_list = rhs.list(); List const* const rhs_list = rhs.list();
if (lhs_list->length() == rhs_list->length()) { if (lhs_list->size() == rhs_list->size()) {
for (int i = 0; i < lhs_list->length(); ++i) { for (size_t i = 0; i < lhs_list->size(); ++i) {
if (lhs_list->at(i) != rhs_list->at(i)) return false; if (lhs_list->at(i) != rhs_list->at(i)) return false;
} }
return true; return true;
...@@ -148,7 +156,7 @@ class ZoneHandleSet final { ...@@ -148,7 +156,7 @@ class ZoneHandleSet final {
inline const_iterator end() const; inline const_iterator end() const;
private: private:
typedef ZoneList<T**> List; typedef ZoneVector<T**> List;
List const* list() const { List const* list() const {
DCHECK_EQ(kListTag, data_ & kTagMask); DCHECK_EQ(kListTag, data_ & kTagMask);
......
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