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
|
|
|
|
|
|
|
#ifndef V8_ELEMENTS_KIND_H_
|
|
|
|
#define V8_ELEMENTS_KIND_H_
|
|
|
|
|
2014-06-30 13:25:46 +00:00
|
|
|
#include "src/checks.h"
|
2012-05-23 14:24:29 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
enum ElementsKind {
|
|
|
|
// The "fast" kind for elements that only contain SMI values. Must be first
|
|
|
|
// to make it possible to efficiently check maps for this kind.
|
|
|
|
FAST_SMI_ELEMENTS,
|
|
|
|
FAST_HOLEY_SMI_ELEMENTS,
|
|
|
|
|
|
|
|
// The "fast" kind for tagged values. Must be second to make it possible to
|
|
|
|
// efficiently check maps for this and the FAST_SMI_ONLY_ELEMENTS kind
|
|
|
|
// together at once.
|
|
|
|
FAST_ELEMENTS,
|
|
|
|
FAST_HOLEY_ELEMENTS,
|
|
|
|
|
|
|
|
// The "fast" kind for unwrapped, non-tagged double values.
|
|
|
|
FAST_DOUBLE_ELEMENTS,
|
|
|
|
FAST_HOLEY_DOUBLE_ELEMENTS,
|
|
|
|
|
|
|
|
// The "slow" kind.
|
|
|
|
DICTIONARY_ELEMENTS,
|
2014-03-11 14:39:08 +00:00
|
|
|
SLOPPY_ARGUMENTS_ELEMENTS,
|
2012-05-23 14:24:29 +00:00
|
|
|
// The "fast" kind for external arrays
|
2014-01-24 16:01:15 +00:00
|
|
|
EXTERNAL_INT8_ELEMENTS,
|
|
|
|
EXTERNAL_UINT8_ELEMENTS,
|
|
|
|
EXTERNAL_INT16_ELEMENTS,
|
|
|
|
EXTERNAL_UINT16_ELEMENTS,
|
|
|
|
EXTERNAL_INT32_ELEMENTS,
|
|
|
|
EXTERNAL_UINT32_ELEMENTS,
|
|
|
|
EXTERNAL_FLOAT32_ELEMENTS,
|
|
|
|
EXTERNAL_FLOAT64_ELEMENTS,
|
|
|
|
EXTERNAL_UINT8_CLAMPED_ELEMENTS,
|
2012-05-23 14:24:29 +00:00
|
|
|
|
2014-01-16 17:08:45 +00:00
|
|
|
// Fixed typed arrays
|
|
|
|
UINT8_ELEMENTS,
|
|
|
|
INT8_ELEMENTS,
|
|
|
|
UINT16_ELEMENTS,
|
|
|
|
INT16_ELEMENTS,
|
|
|
|
UINT32_ELEMENTS,
|
|
|
|
INT32_ELEMENTS,
|
|
|
|
FLOAT32_ELEMENTS,
|
|
|
|
FLOAT64_ELEMENTS,
|
|
|
|
UINT8_CLAMPED_ELEMENTS,
|
|
|
|
|
2012-05-23 14:24:29 +00:00
|
|
|
// Derived constants from ElementsKind
|
|
|
|
FIRST_ELEMENTS_KIND = FAST_SMI_ELEMENTS,
|
2014-01-16 17:08:45 +00:00
|
|
|
LAST_ELEMENTS_KIND = UINT8_CLAMPED_ELEMENTS,
|
2012-05-23 14:24:29 +00:00
|
|
|
FIRST_FAST_ELEMENTS_KIND = FAST_SMI_ELEMENTS,
|
|
|
|
LAST_FAST_ELEMENTS_KIND = FAST_HOLEY_DOUBLE_ELEMENTS,
|
2014-01-24 16:01:15 +00:00
|
|
|
FIRST_EXTERNAL_ARRAY_ELEMENTS_KIND = EXTERNAL_INT8_ELEMENTS,
|
|
|
|
LAST_EXTERNAL_ARRAY_ELEMENTS_KIND = EXTERNAL_UINT8_CLAMPED_ELEMENTS,
|
2014-01-16 17:08:45 +00:00
|
|
|
FIRST_FIXED_TYPED_ARRAY_ELEMENTS_KIND = UINT8_ELEMENTS,
|
|
|
|
LAST_FIXED_TYPED_ARRAY_ELEMENTS_KIND = UINT8_CLAMPED_ELEMENTS,
|
2012-05-23 14:24:29 +00:00
|
|
|
TERMINAL_FAST_ELEMENTS_KIND = FAST_HOLEY_ELEMENTS
|
|
|
|
};
|
|
|
|
|
|
|
|
const int kElementsKindCount = LAST_ELEMENTS_KIND - FIRST_ELEMENTS_KIND + 1;
|
|
|
|
const int kFastElementsKindCount = LAST_FAST_ELEMENTS_KIND -
|
|
|
|
FIRST_FAST_ELEMENTS_KIND + 1;
|
|
|
|
|
2013-11-14 12:05:09 +00:00
|
|
|
// The number to add to a packed elements kind to reach a holey elements kind
|
|
|
|
const int kFastElementsKindPackedToHoley =
|
|
|
|
FAST_HOLEY_SMI_ELEMENTS - FAST_SMI_ELEMENTS;
|
|
|
|
|
2013-11-15 17:24:10 +00:00
|
|
|
int ElementsKindToShiftSize(ElementsKind elements_kind);
|
2014-05-22 08:37:50 +00:00
|
|
|
int GetDefaultHeaderSizeForElementsKind(ElementsKind elements_kind);
|
2012-11-02 09:18:53 +00:00
|
|
|
const char* ElementsKindToString(ElementsKind kind);
|
2012-05-23 14:24:29 +00:00
|
|
|
|
2014-07-18 07:17:21 +00:00
|
|
|
inline ElementsKind GetInitialFastElementsKind() { return FAST_SMI_ELEMENTS; }
|
2012-05-23 14:24:29 +00:00
|
|
|
|
2014-03-26 12:50:13 +00:00
|
|
|
ElementsKind GetFastElementsKindFromSequenceIndex(int sequence_number);
|
2012-05-23 14:24:29 +00:00
|
|
|
int GetSequenceIndexFromFastElementsKind(ElementsKind elements_kind);
|
|
|
|
|
2014-03-26 12:50:13 +00:00
|
|
|
ElementsKind GetNextTransitionElementsKind(ElementsKind elements_kind);
|
2012-05-23 14:24:29 +00:00
|
|
|
|
2012-06-08 13:06:24 +00:00
|
|
|
inline bool IsDictionaryElementsKind(ElementsKind kind) {
|
|
|
|
return kind == DICTIONARY_ELEMENTS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-22 13:23:27 +00:00
|
|
|
inline bool IsSloppyArgumentsElements(ElementsKind kind) {
|
|
|
|
return kind == SLOPPY_ARGUMENTS_ELEMENTS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-08 13:06:24 +00:00
|
|
|
inline bool IsExternalArrayElementsKind(ElementsKind kind) {
|
|
|
|
return kind >= FIRST_EXTERNAL_ARRAY_ELEMENTS_KIND &&
|
|
|
|
kind <= LAST_EXTERNAL_ARRAY_ELEMENTS_KIND;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-26 12:50:13 +00:00
|
|
|
inline bool IsTerminalElementsKind(ElementsKind kind) {
|
|
|
|
return kind == TERMINAL_FAST_ELEMENTS_KIND ||
|
|
|
|
IsExternalArrayElementsKind(kind);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-16 17:08:45 +00:00
|
|
|
inline bool IsFixedTypedArrayElementsKind(ElementsKind kind) {
|
|
|
|
return kind >= FIRST_FIXED_TYPED_ARRAY_ELEMENTS_KIND &&
|
|
|
|
kind <= LAST_FIXED_TYPED_ARRAY_ELEMENTS_KIND;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-23 14:24:29 +00:00
|
|
|
inline bool IsFastElementsKind(ElementsKind kind) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(FIRST_FAST_ELEMENTS_KIND == 0);
|
2012-05-23 14:24:29 +00:00
|
|
|
return kind <= FAST_HOLEY_DOUBLE_ELEMENTS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-26 12:50:13 +00:00
|
|
|
inline bool IsTransitionElementsKind(ElementsKind kind) {
|
|
|
|
return IsFastElementsKind(kind) || IsFixedTypedArrayElementsKind(kind);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-23 14:24:29 +00:00
|
|
|
inline bool IsFastDoubleElementsKind(ElementsKind kind) {
|
|
|
|
return kind == FAST_DOUBLE_ELEMENTS ||
|
|
|
|
kind == FAST_HOLEY_DOUBLE_ELEMENTS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-28 13:30:16 +00:00
|
|
|
inline bool IsExternalFloatOrDoubleElementsKind(ElementsKind kind) {
|
2014-01-24 16:01:15 +00:00
|
|
|
return kind == EXTERNAL_FLOAT64_ELEMENTS ||
|
|
|
|
kind == EXTERNAL_FLOAT32_ELEMENTS;
|
2013-03-28 13:30:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-16 17:08:45 +00:00
|
|
|
inline bool IsFixedFloatElementsKind(ElementsKind kind) {
|
|
|
|
return kind == FLOAT32_ELEMENTS || kind == FLOAT64_ELEMENTS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-02 09:18:53 +00:00
|
|
|
inline bool IsDoubleOrFloatElementsKind(ElementsKind kind) {
|
|
|
|
return IsFastDoubleElementsKind(kind) ||
|
2014-01-16 17:08:45 +00:00
|
|
|
IsExternalFloatOrDoubleElementsKind(kind) ||
|
|
|
|
IsFixedFloatElementsKind(kind);
|
2012-11-02 09:18:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-23 14:24:29 +00:00
|
|
|
inline bool IsFastSmiOrObjectElementsKind(ElementsKind kind) {
|
|
|
|
return kind == FAST_SMI_ELEMENTS ||
|
|
|
|
kind == FAST_HOLEY_SMI_ELEMENTS ||
|
|
|
|
kind == FAST_ELEMENTS ||
|
|
|
|
kind == FAST_HOLEY_ELEMENTS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline bool IsFastSmiElementsKind(ElementsKind kind) {
|
|
|
|
return kind == FAST_SMI_ELEMENTS ||
|
|
|
|
kind == FAST_HOLEY_SMI_ELEMENTS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline bool IsFastObjectElementsKind(ElementsKind kind) {
|
|
|
|
return kind == FAST_ELEMENTS ||
|
|
|
|
kind == FAST_HOLEY_ELEMENTS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline bool IsFastHoleyElementsKind(ElementsKind kind) {
|
|
|
|
return kind == FAST_HOLEY_SMI_ELEMENTS ||
|
|
|
|
kind == FAST_HOLEY_DOUBLE_ELEMENTS ||
|
|
|
|
kind == FAST_HOLEY_ELEMENTS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline bool IsHoleyElementsKind(ElementsKind kind) {
|
|
|
|
return IsFastHoleyElementsKind(kind) ||
|
|
|
|
kind == DICTIONARY_ELEMENTS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline bool IsFastPackedElementsKind(ElementsKind kind) {
|
|
|
|
return kind == FAST_SMI_ELEMENTS ||
|
|
|
|
kind == FAST_DOUBLE_ELEMENTS ||
|
|
|
|
kind == FAST_ELEMENTS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline ElementsKind GetPackedElementsKind(ElementsKind holey_kind) {
|
|
|
|
if (holey_kind == FAST_HOLEY_SMI_ELEMENTS) {
|
|
|
|
return FAST_SMI_ELEMENTS;
|
|
|
|
}
|
|
|
|
if (holey_kind == FAST_HOLEY_DOUBLE_ELEMENTS) {
|
|
|
|
return FAST_DOUBLE_ELEMENTS;
|
|
|
|
}
|
|
|
|
if (holey_kind == FAST_HOLEY_ELEMENTS) {
|
|
|
|
return FAST_ELEMENTS;
|
|
|
|
}
|
|
|
|
return holey_kind;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline ElementsKind GetHoleyElementsKind(ElementsKind packed_kind) {
|
|
|
|
if (packed_kind == FAST_SMI_ELEMENTS) {
|
|
|
|
return FAST_HOLEY_SMI_ELEMENTS;
|
|
|
|
}
|
|
|
|
if (packed_kind == FAST_DOUBLE_ELEMENTS) {
|
|
|
|
return FAST_HOLEY_DOUBLE_ELEMENTS;
|
|
|
|
}
|
|
|
|
if (packed_kind == FAST_ELEMENTS) {
|
|
|
|
return FAST_HOLEY_ELEMENTS;
|
|
|
|
}
|
|
|
|
return packed_kind;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline ElementsKind FastSmiToObjectElementsKind(ElementsKind from_kind) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(IsFastSmiElementsKind(from_kind));
|
2012-05-23 14:24:29 +00:00
|
|
|
return (from_kind == FAST_SMI_ELEMENTS)
|
|
|
|
? FAST_ELEMENTS
|
|
|
|
: FAST_HOLEY_ELEMENTS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline bool IsSimpleMapChangeTransition(ElementsKind from_kind,
|
|
|
|
ElementsKind to_kind) {
|
|
|
|
return (GetHoleyElementsKind(from_kind) == to_kind) ||
|
|
|
|
(IsFastSmiElementsKind(from_kind) &&
|
|
|
|
IsFastObjectElementsKind(to_kind));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool IsMoreGeneralElementsKindTransition(ElementsKind from_kind,
|
|
|
|
ElementsKind to_kind);
|
|
|
|
|
|
|
|
|
|
|
|
inline bool IsTransitionableFastElementsKind(ElementsKind from_kind) {
|
|
|
|
return IsFastElementsKind(from_kind) &&
|
|
|
|
from_kind != TERMINAL_FAST_ELEMENTS_KIND;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ElementsKind GetNextMoreGeneralFastElementsKind(ElementsKind elements_kind,
|
|
|
|
bool allow_only_packed);
|
|
|
|
|
|
|
|
|
|
|
|
inline bool CanTransitionToMoreGeneralFastElementsKind(
|
|
|
|
ElementsKind elements_kind,
|
|
|
|
bool allow_only_packed) {
|
2012-05-25 09:58:40 +00:00
|
|
|
return IsFastElementsKind(elements_kind) &&
|
|
|
|
(elements_kind != TERMINAL_FAST_ELEMENTS_KIND &&
|
|
|
|
(!allow_only_packed || elements_kind != FAST_ELEMENTS));
|
2012-05-23 14:24:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} } // namespace v8::internal
|
|
|
|
|
|
|
|
#endif // V8_ELEMENTS_KIND_H_
|