Commit 1692380f authored by jochen's avatar jochen Committed by Commit bot

Revert of Reland "LayoutDescriptor should inherit from JSTypedArray" (patchset...

Revert of Reland "LayoutDescriptor should inherit from JSTypedArray" (patchset #3 id:40001 of https://codereview.chromium.org/1094333002/)

Reason for revert:
Breaks gbemu

Original issue's description:
> Reland "LayoutDescriptor should inherit from JSTypedArray"
>
> Original issue's description:
> > LayoutDescriptor should inherit from JSTypedArray
> >
> > It can't just inherit from a FixedTypedArray-like type, as we soon
> > assume that a FixedTypedArray-like type is always held by an
> > ArrayBufferView-like type
> >
> > BUG=v8:3996
> > R=ishell@chromium.org,verwaest@chromium.org
> > LOG=n
>
> BUG=v8:3996
> R=ishell@chromium.org,verwaest@chromium.org
> LOG=n

TBR=ishell@chromium.org,verwaest@chromium.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=v8:3996

Review URL: https://codereview.chromium.org/1080403004

Cr-Commit-Position: refs/heads/master@{#27975}
parent d1597b7d
......@@ -1825,38 +1825,9 @@ size_t GetExternalArrayElementSize(ExternalArrayType type) {
case kExternal##Type##Array: \
return size;
TYPED_ARRAYS(TYPED_ARRAY_CASE)
default:
UNREACHABLE();
return 0;
}
#undef TYPED_ARRAY_CASE
}
size_t GetFixedTypedArraysElementSize(ElementsKind kind) {
switch (kind) {
#define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \
case TYPE##_ELEMENTS: \
return size;
TYPED_ARRAYS(TYPED_ARRAY_CASE)
default:
UNREACHABLE();
return 0;
}
#undef TYPED_ARRAY_CASE
}
ExternalArrayType GetArrayTypeFromElementsKind(ElementsKind kind) {
switch (kind) {
#define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \
case TYPE##_ELEMENTS: \
return kExternal##Type##Array;
TYPED_ARRAYS(TYPED_ARRAY_CASE)
default:
UNREACHABLE();
return kExternalInt8Array;
}
UNREACHABLE();
return 0;
#undef TYPED_ARRAY_CASE
}
......@@ -1878,23 +1849,6 @@ JSFunction* GetTypedArrayFun(ExternalArrayType type, Isolate* isolate) {
}
JSFunction* GetTypedArrayFun(ElementsKind elements_kind, Isolate* isolate) {
Context* native_context = isolate->context()->native_context();
switch (elements_kind) {
#define TYPED_ARRAY_FUN(Type, type, TYPE, ctype, size) \
case TYPE##_ELEMENTS: \
return native_context->type##_array_fun();
TYPED_ARRAYS(TYPED_ARRAY_FUN)
#undef TYPED_ARRAY_FUN
default:
UNREACHABLE();
return NULL;
}
}
void SetupArrayBufferView(i::Isolate* isolate,
i::Handle<i::JSArrayBufferView> obj,
i::Handle<i::JSArrayBuffer> buffer,
......@@ -1936,16 +1890,6 @@ Handle<JSTypedArray> Factory::NewJSTypedArray(ExternalArrayType type) {
}
Handle<JSTypedArray> Factory::NewJSTypedArray(ElementsKind elements_kind) {
Handle<JSFunction> typed_array_fun_handle(
GetTypedArrayFun(elements_kind, isolate()));
CALL_HEAP_FUNCTION(
isolate(), isolate()->heap()->AllocateJSObject(*typed_array_fun_handle),
JSTypedArray);
}
Handle<JSTypedArray> Factory::NewJSTypedArray(ExternalArrayType type,
Handle<JSArrayBuffer> buffer,
size_t byte_offset,
......@@ -1974,35 +1918,6 @@ Handle<JSTypedArray> Factory::NewJSTypedArray(ExternalArrayType type,
}
Handle<JSTypedArray> Factory::NewJSTypedArray(ElementsKind elements_kind,
size_t number_of_elements) {
Handle<JSTypedArray> obj = NewJSTypedArray(elements_kind);
size_t element_size = GetFixedTypedArraysElementSize(elements_kind);
ExternalArrayType array_type = GetArrayTypeFromElementsKind(elements_kind);
CHECK(number_of_elements <=
(std::numeric_limits<size_t>::max() / element_size));
CHECK(number_of_elements <= static_cast<size_t>(Smi::kMaxValue));
size_t byte_length = number_of_elements * element_size;
obj->set_byte_offset(Smi::FromInt(0));
i::Handle<i::Object> byte_length_object =
isolate()->factory()->NewNumberFromSize(byte_length);
obj->set_byte_length(*byte_length_object);
Handle<Object> length_object = NewNumberFromSize(number_of_elements);
obj->set_length(*length_object);
obj->set_buffer(Smi::FromInt(0));
obj->set_weak_next(isolate()->heap()->undefined_value());
Handle<FixedTypedArrayBase> elements =
isolate()->factory()->NewFixedTypedArray(
static_cast<int>(number_of_elements), array_type);
obj->set_elements(*elements);
return obj;
}
Handle<JSDataView> Factory::NewJSDataView(Handle<JSArrayBuffer> buffer,
size_t byte_offset,
size_t byte_length) {
......
......@@ -448,17 +448,11 @@ class Factory final {
Handle<JSTypedArray> NewJSTypedArray(ExternalArrayType type);
Handle<JSTypedArray> NewJSTypedArray(ElementsKind elements_kind);
// Creates a new JSTypedArray with the specified buffer.
Handle<JSTypedArray> NewJSTypedArray(ExternalArrayType type,
Handle<JSArrayBuffer> buffer,
size_t byte_offset, size_t length);
// Creates a new on-heap JSTypedArray.
Handle<JSTypedArray> NewJSTypedArray(ElementsKind elements_kind,
size_t number_of_elements);
Handle<JSDataView> NewJSDataView();
Handle<JSDataView> NewJSDataView(Handle<JSArrayBuffer> buffer,
size_t byte_offset, size_t byte_length);
......
......@@ -22,7 +22,7 @@ Handle<LayoutDescriptor> LayoutDescriptor::New(Isolate* isolate, int length) {
}
length = GetSlowModeBackingStoreLength(length);
return Handle<LayoutDescriptor>::cast(
isolate->factory()->NewJSTypedArray(UINT32_ELEMENTS, length));
isolate->factory()->NewFixedTypedArray(length, kExternalUint32Array));
}
......@@ -48,7 +48,7 @@ bool LayoutDescriptor::GetIndexes(int field_index, int* layout_word_index,
}
*layout_word_index = field_index / kNumberOfBits;
CHECK((!IsSmi() && (*layout_word_index < Smi::cast(length())->value())) ||
CHECK((!IsSmi() && (*layout_word_index < length())) ||
(IsSmi() && (*layout_word_index < 1)));
*layout_bit_index = field_index % kNumberOfBits;
......@@ -123,20 +123,7 @@ bool LayoutDescriptor::IsSlowLayout() { return !IsSmi(); }
int LayoutDescriptor::capacity() {
return IsSlowLayout() ? (Smi::cast(length())->value() * kNumberOfBits)
: kSmiValueSize;
}
uint32_t LayoutDescriptor::get_scalar(int index) {
DCHECK(IsSlowLayout());
return GcSafeElements()->get_scalar(index);
}
void LayoutDescriptor::set(int index, uint32_t value) {
DCHECK(IsSlowLayout());
GcSafeElements()->set(index, value);
return IsSlowLayout() ? (length() * kNumberOfBits) : kSmiValueSize;
}
......@@ -227,16 +214,6 @@ LayoutDescriptor* LayoutDescriptor::Initialize(
}
FixedTypedArray<Uint32ArrayTraits>* LayoutDescriptor::GcSafeElements() {
MapWord map_word = HeapObject::cast(elements())->map_word();
if (map_word.IsForwardingAddress()) {
return FixedTypedArray<Uint32ArrayTraits>::cast(
map_word.ToForwardingAddress());
}
return FixedTypedArray<Uint32ArrayTraits>::cast(elements());
}
// InobjectPropertiesHelper is a helper class for querying whether inobject
// property at offset is Double or not.
LayoutDescriptorHelper::LayoutDescriptorHelper(Map* map)
......
......@@ -106,11 +106,8 @@ Handle<LayoutDescriptor> LayoutDescriptor::EnsureCapacity(
DCHECK(new_layout_descriptor->IsSlowLayout());
if (layout_descriptor->IsSlowLayout()) {
DisallowHeapAllocation no_gc;
Handle<FixedTypedArrayBase> elements(layout_descriptor->GcSafeElements());
Handle<FixedTypedArrayBase> new_elements(
new_layout_descriptor->GcSafeElements());
memcpy(new_elements->DataPtr(), elements->DataPtr(), elements->DataSize());
memcpy(new_layout_descriptor->DataPtr(), layout_descriptor->DataPtr(),
layout_descriptor->DataSize());
return new_layout_descriptor;
} else {
// Fast layout.
......@@ -153,7 +150,7 @@ bool LayoutDescriptor::IsTagged(int field_index, int max_sequence_length,
// This is a contiguous sequence till the end of current word, proceed
// counting in the subsequent words.
if (IsSlowLayout()) {
int len = Smi::cast(length())->value();
int len = length();
++layout_word_index;
for (; layout_word_index < len; layout_word_index++) {
value = get_scalar(layout_word_index);
......@@ -244,20 +241,13 @@ LayoutDescriptor* LayoutDescriptor::Trim(Heap* heap, Map* map,
// Trim, clean and reinitialize this slow-mode layout descriptor.
int array_length = GetSlowModeBackingStoreLength(layout_descriptor_length);
int current_length = Smi::cast(length())->value();
int current_length = length();
if (current_length != array_length) {
DCHECK_LT(array_length, current_length);
int delta = current_length - array_length;
heap->RightTrimFixedArray<Heap::SEQUENTIAL_TO_SWEEPER>(elements(), delta);
set_byte_length(Smi::FromInt(array_length * 4));
set_length(Smi::FromInt(array_length));
}
{
DisallowHeapAllocation no_gc;
Handle<FixedTypedArrayBase> fixed_array(
FixedTypedArrayBase::cast(elements()));
memset(fixed_array->DataPtr(), 0, fixed_array->DataSize());
heap->RightTrimFixedArray<Heap::SEQUENTIAL_TO_SWEEPER>(this, delta);
}
memset(DataPtr(), 0, DataSize());
LayoutDescriptor* layout_descriptor =
Initialize(this, map, descriptors, num_descriptors);
DCHECK_EQ(this, layout_descriptor);
......
......@@ -22,7 +22,7 @@ namespace internal {
// of the descriptor then the field is also considered tagged.
// Once a layout descriptor is created it is allowed only to append properties
// to it.
class LayoutDescriptor : public JSTypedArray {
class LayoutDescriptor : public FixedTypedArray<Uint32ArrayTraits> {
public:
V8_INLINE bool IsTagged(int field_index);
......@@ -89,17 +89,12 @@ class LayoutDescriptor : public JSTypedArray {
// Capacity of layout descriptors in bits.
V8_INLINE int capacity();
V8_INLINE uint32_t get_scalar(int index);
V8_INLINE void set(int index, uint32_t value);
static Handle<LayoutDescriptor> NewForTesting(Isolate* isolate, int length);
LayoutDescriptor* SetTaggedForTesting(int field_index, bool tagged);
private:
static const int kNumberOfBits = 32;
V8_INLINE FixedTypedArray<Uint32ArrayTraits>* GcSafeElements();
V8_INLINE static Handle<LayoutDescriptor> New(Isolate* isolate, int length);
V8_INLINE static LayoutDescriptor* FromSmi(Smi* smi);
......
......@@ -716,7 +716,9 @@ bool Object::IsDescriptorArray() const {
bool Object::IsArrayList() const { return IsFixedArray(); }
bool Object::IsLayoutDescriptor() const { return IsSmi() || IsJSTypedArray(); }
bool Object::IsLayoutDescriptor() const {
return IsSmi() || IsFixedTypedArrayBase();
}
bool Object::IsTransitionArray() const {
......
......@@ -1065,7 +1065,7 @@ void LayoutDescriptor::Print(std::ostream& os) { // NOLINT
PrintBitMask(os, static_cast<uint32_t>(Smi::cast(this)->value()));
} else {
os << "slow";
int len = Smi::cast(length())->value();
int len = length();
for (int i = 0; i < len; i++) {
if (i > 0) os << " |";
PrintBitMask(os, get_scalar(i));
......
......@@ -581,7 +581,7 @@ TEST(LayoutDescriptorCreateNewSlow) {
LayoutDescriptor* layout_desc = *layout_descriptor;
CHECK_EQ(layout_desc, LayoutDescriptor::cast(layout_desc));
CHECK_EQ(layout_desc, LayoutDescriptor::cast_gc_safe(layout_desc));
CHECK(layout_descriptor->IsJSTypedArray());
CHECK(layout_descriptor->IsFixedTypedArrayBase());
// Now make it look like a forwarding pointer to layout_descriptor_copy.
MapWord map_word = layout_desc->map_word();
CHECK(!map_word.IsForwardingAddress());
......@@ -935,7 +935,7 @@ TEST(DescriptorArrayTrimming) {
CHECK(map->layout_descriptor()->IsConsistentWithMap(*map, true));
CHECK(map->layout_descriptor()->IsSlowLayout());
CHECK(map->owns_descriptors());
CHECK_EQ(2, Smi::cast(map->layout_descriptor()->length())->value());
CHECK_EQ(2, map->layout_descriptor()->length());
{
// Add transitions to double fields.
......@@ -954,7 +954,7 @@ TEST(DescriptorArrayTrimming) {
CHECK_EQ(map->layout_descriptor(), tmp_map->layout_descriptor());
}
CHECK(map->layout_descriptor()->IsSlowLayout());
CHECK_EQ(4, Smi::cast(map->layout_descriptor()->length())->value());
CHECK_EQ(4, map->layout_descriptor()->length());
// The unused tail of the layout descriptor is now "durty" because of sharing.
CHECK(map->layout_descriptor()->IsConsistentWithMap(*map));
......@@ -974,7 +974,7 @@ TEST(DescriptorArrayTrimming) {
CHECK_EQ(map->NumberOfOwnDescriptors(),
map->instance_descriptors()->number_of_descriptors());
CHECK(map->layout_descriptor()->IsSlowLayout());
CHECK_EQ(2, Smi::cast(map->layout_descriptor()->length())->value());
CHECK_EQ(2, map->layout_descriptor()->length());
{
// Add transitions to tagged fields.
......
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