2012-05-23 14:24:29 +00:00
|
|
|
// Copyright 2012 the V8 project authors. All rights reserved.
|
2014-04-29 06:42:26 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
2012-05-23 14:24:29 +00:00
|
|
|
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/elements-kind.h"
|
2012-05-23 14:24:29 +00:00
|
|
|
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/api.h"
|
2014-06-05 12:14:47 +00:00
|
|
|
#include "src/base/lazy-instance.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/elements.h"
|
|
|
|
#include "src/objects.h"
|
2012-05-23 14:24:29 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
|
2013-11-15 17:24:10 +00:00
|
|
|
int ElementsKindToShiftSize(ElementsKind elements_kind) {
|
|
|
|
switch (elements_kind) {
|
2014-01-16 17:08:45 +00:00
|
|
|
case UINT8_ELEMENTS:
|
|
|
|
case INT8_ELEMENTS:
|
|
|
|
case UINT8_CLAMPED_ELEMENTS:
|
2013-11-15 17:24:10 +00:00
|
|
|
return 0;
|
2014-01-16 17:08:45 +00:00
|
|
|
case UINT16_ELEMENTS:
|
|
|
|
case INT16_ELEMENTS:
|
2013-11-15 17:24:10 +00:00
|
|
|
return 1;
|
2014-01-16 17:08:45 +00:00
|
|
|
case UINT32_ELEMENTS:
|
|
|
|
case INT32_ELEMENTS:
|
|
|
|
case FLOAT32_ELEMENTS:
|
2013-11-15 17:24:10 +00:00
|
|
|
return 2;
|
|
|
|
case FAST_DOUBLE_ELEMENTS:
|
|
|
|
case FAST_HOLEY_DOUBLE_ELEMENTS:
|
2014-01-16 17:08:45 +00:00
|
|
|
case FLOAT64_ELEMENTS:
|
2013-11-15 17:24:10 +00:00
|
|
|
return 3;
|
|
|
|
case FAST_SMI_ELEMENTS:
|
|
|
|
case FAST_ELEMENTS:
|
|
|
|
case FAST_HOLEY_SMI_ELEMENTS:
|
|
|
|
case FAST_HOLEY_ELEMENTS:
|
|
|
|
case DICTIONARY_ELEMENTS:
|
2015-07-02 14:38:37 +00:00
|
|
|
case FAST_SLOPPY_ARGUMENTS_ELEMENTS:
|
|
|
|
case SLOW_SLOPPY_ARGUMENTS_ELEMENTS:
|
2016-01-29 18:57:26 +00:00
|
|
|
case FAST_STRING_WRAPPER_ELEMENTS:
|
|
|
|
case SLOW_STRING_WRAPPER_ELEMENTS:
|
2013-11-15 17:24:10 +00:00
|
|
|
return kPointerSizeLog2;
|
2016-01-29 18:57:26 +00:00
|
|
|
case NO_ELEMENTS:
|
|
|
|
UNREACHABLE();
|
|
|
|
return 0;
|
2013-11-15 17:24:10 +00:00
|
|
|
}
|
|
|
|
UNREACHABLE();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-22 08:37:50 +00:00
|
|
|
int GetDefaultHeaderSizeForElementsKind(ElementsKind elements_kind) {
|
2014-06-12 09:58:10 +00:00
|
|
|
STATIC_ASSERT(FixedArray::kHeaderSize == FixedDoubleArray::kHeaderSize);
|
2015-06-16 07:37:16 +00:00
|
|
|
|
2015-07-28 09:29:34 +00:00
|
|
|
if (IsFixedTypedArrayElementsKind(elements_kind)) {
|
2015-06-16 07:37:16 +00:00
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return FixedArray::kHeaderSize - kHeapObjectTag;
|
|
|
|
}
|
2014-05-22 08:37:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-02 09:18:53 +00:00
|
|
|
const char* ElementsKindToString(ElementsKind kind) {
|
2012-05-23 14:24:29 +00:00
|
|
|
ElementsAccessor* accessor = ElementsAccessor::ForKind(kind);
|
2012-11-02 09:18:53 +00:00
|
|
|
return accessor->name();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-23 14:24:29 +00:00
|
|
|
struct InitializeFastElementsKindSequence {
|
|
|
|
static void Construct(
|
|
|
|
ElementsKind** fast_elements_kind_sequence_ptr) {
|
|
|
|
ElementsKind* fast_elements_kind_sequence =
|
|
|
|
new ElementsKind[kFastElementsKindCount];
|
|
|
|
*fast_elements_kind_sequence_ptr = fast_elements_kind_sequence;
|
|
|
|
STATIC_ASSERT(FAST_SMI_ELEMENTS == FIRST_FAST_ELEMENTS_KIND);
|
|
|
|
fast_elements_kind_sequence[0] = FAST_SMI_ELEMENTS;
|
|
|
|
fast_elements_kind_sequence[1] = FAST_HOLEY_SMI_ELEMENTS;
|
|
|
|
fast_elements_kind_sequence[2] = FAST_DOUBLE_ELEMENTS;
|
|
|
|
fast_elements_kind_sequence[3] = FAST_HOLEY_DOUBLE_ELEMENTS;
|
|
|
|
fast_elements_kind_sequence[4] = FAST_ELEMENTS;
|
|
|
|
fast_elements_kind_sequence[5] = FAST_HOLEY_ELEMENTS;
|
2013-11-14 12:05:09 +00:00
|
|
|
|
|
|
|
// Verify that kFastElementsKindPackedToHoley is correct.
|
|
|
|
STATIC_ASSERT(FAST_SMI_ELEMENTS + kFastElementsKindPackedToHoley ==
|
|
|
|
FAST_HOLEY_SMI_ELEMENTS);
|
|
|
|
STATIC_ASSERT(FAST_DOUBLE_ELEMENTS + kFastElementsKindPackedToHoley ==
|
|
|
|
FAST_HOLEY_DOUBLE_ELEMENTS);
|
|
|
|
STATIC_ASSERT(FAST_ELEMENTS + kFastElementsKindPackedToHoley ==
|
|
|
|
FAST_HOLEY_ELEMENTS);
|
2012-05-23 14:24:29 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-06-05 12:14:47 +00:00
|
|
|
static base::LazyInstance<ElementsKind*,
|
|
|
|
InitializeFastElementsKindSequence>::type
|
2012-05-23 14:24:29 +00:00
|
|
|
fast_elements_kind_sequence = LAZY_INSTANCE_INITIALIZER;
|
|
|
|
|
|
|
|
|
|
|
|
ElementsKind GetFastElementsKindFromSequenceIndex(int sequence_number) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(sequence_number >= 0 &&
|
2012-05-23 14:24:29 +00:00
|
|
|
sequence_number < kFastElementsKindCount);
|
|
|
|
return fast_elements_kind_sequence.Get()[sequence_number];
|
|
|
|
}
|
|
|
|
|
2013-07-05 09:52:11 +00:00
|
|
|
|
2012-05-23 14:24:29 +00:00
|
|
|
int GetSequenceIndexFromFastElementsKind(ElementsKind elements_kind) {
|
|
|
|
for (int i = 0; i < kFastElementsKindCount; ++i) {
|
|
|
|
if (fast_elements_kind_sequence.Get()[i] == elements_kind) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
UNREACHABLE();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-26 12:50:13 +00:00
|
|
|
ElementsKind GetNextTransitionElementsKind(ElementsKind kind) {
|
2015-07-28 09:29:34 +00:00
|
|
|
int index = GetSequenceIndexFromFastElementsKind(kind);
|
|
|
|
return GetFastElementsKindFromSequenceIndex(index + 1);
|
2014-03-26 12:50:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-03 16:25:05 +00:00
|
|
|
static inline bool IsFastTransitionTarget(ElementsKind elements_kind) {
|
|
|
|
return IsFastElementsKind(elements_kind) ||
|
|
|
|
elements_kind == DICTIONARY_ELEMENTS;
|
|
|
|
}
|
|
|
|
|
2012-05-23 14:24:29 +00:00
|
|
|
bool IsMoreGeneralElementsKindTransition(ElementsKind from_kind,
|
|
|
|
ElementsKind to_kind) {
|
2015-07-28 09:29:34 +00:00
|
|
|
if (IsFixedTypedArrayElementsKind(from_kind) ||
|
|
|
|
IsFixedTypedArrayElementsKind(to_kind)) {
|
|
|
|
return false;
|
2014-04-01 16:41:35 +00:00
|
|
|
}
|
2014-04-03 16:25:05 +00:00
|
|
|
if (IsFastElementsKind(from_kind) && IsFastTransitionTarget(to_kind)) {
|
|
|
|
switch (from_kind) {
|
|
|
|
case FAST_SMI_ELEMENTS:
|
|
|
|
return to_kind != FAST_SMI_ELEMENTS;
|
|
|
|
case FAST_HOLEY_SMI_ELEMENTS:
|
|
|
|
return to_kind != FAST_SMI_ELEMENTS &&
|
|
|
|
to_kind != FAST_HOLEY_SMI_ELEMENTS;
|
|
|
|
case FAST_DOUBLE_ELEMENTS:
|
|
|
|
return to_kind != FAST_SMI_ELEMENTS &&
|
|
|
|
to_kind != FAST_HOLEY_SMI_ELEMENTS &&
|
|
|
|
to_kind != FAST_DOUBLE_ELEMENTS;
|
|
|
|
case FAST_HOLEY_DOUBLE_ELEMENTS:
|
|
|
|
return to_kind == FAST_ELEMENTS ||
|
|
|
|
to_kind == FAST_HOLEY_ELEMENTS;
|
|
|
|
case FAST_ELEMENTS:
|
|
|
|
return to_kind == FAST_HOLEY_ELEMENTS;
|
|
|
|
case FAST_HOLEY_ELEMENTS:
|
|
|
|
return false;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
2012-05-23 14:24:29 +00:00
|
|
|
}
|
2014-04-03 16:25:05 +00:00
|
|
|
return false;
|
2012-05-23 14:24:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-01 22:46:54 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|