v8  3.25.30(node0.11.13)
V8 is Google's open source JavaScript engine
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
elements-kind.cc
Go to the documentation of this file.
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 #include "elements-kind.h"
29 
30 #include "api.h"
31 #include "elements.h"
32 #include "objects.h"
33 
34 namespace v8 {
35 namespace internal {
36 
37 
39  switch (elements_kind) {
43  case UINT8_ELEMENTS:
44  case INT8_ELEMENTS:
46  return 0;
49  case UINT16_ELEMENTS:
50  case INT16_ELEMENTS:
51  return 1;
55  case UINT32_ELEMENTS:
56  case INT32_ELEMENTS:
57  case FLOAT32_ELEMENTS:
58  return 2;
62  case FLOAT64_ELEMENTS:
63  return 3;
64  case FAST_SMI_ELEMENTS:
65  case FAST_ELEMENTS:
70  return kPointerSizeLog2;
71  }
72  UNREACHABLE();
73  return 0;
74 }
75 
76 
79  return accessor->name();
80 }
81 
82 
83 void PrintElementsKind(FILE* out, ElementsKind kind) {
84  PrintF(out, "%s", ElementsKindToString(kind));
85 }
86 
87 
89  if (FLAG_packed_arrays) {
90  return FAST_SMI_ELEMENTS;
91  } else {
93  }
94 }
95 
96 
98  static void Construct(
99  ElementsKind** fast_elements_kind_sequence_ptr) {
100  ElementsKind* fast_elements_kind_sequence =
102  *fast_elements_kind_sequence_ptr = fast_elements_kind_sequence;
104  fast_elements_kind_sequence[0] = FAST_SMI_ELEMENTS;
105  fast_elements_kind_sequence[1] = FAST_HOLEY_SMI_ELEMENTS;
106  fast_elements_kind_sequence[2] = FAST_DOUBLE_ELEMENTS;
107  fast_elements_kind_sequence[3] = FAST_HOLEY_DOUBLE_ELEMENTS;
108  fast_elements_kind_sequence[4] = FAST_ELEMENTS;
109  fast_elements_kind_sequence[5] = FAST_HOLEY_ELEMENTS;
110 
111  // Verify that kFastElementsKindPackedToHoley is correct.
118  }
119 };
120 
121 
122 static LazyInstance<ElementsKind*,
123  InitializeFastElementsKindSequence>::type
124  fast_elements_kind_sequence = LAZY_INSTANCE_INITIALIZER;
125 
126 
128  ASSERT(sequence_number >= 0 &&
129  sequence_number < kFastElementsKindCount);
130  return fast_elements_kind_sequence.Get()[sequence_number];
131 }
132 
133 
135  for (int i = 0; i < kFastElementsKindCount; ++i) {
136  if (fast_elements_kind_sequence.Get()[i] == elements_kind) {
137  return i;
138  }
139  }
140  UNREACHABLE();
141  return 0;
142 }
143 
144 
146  switch (kind) {
147 #define FIXED_TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \
148  case TYPE##_ELEMENTS: return EXTERNAL_##TYPE##_ELEMENTS;
149 
151 #undef FIXED_TYPED_ARRAY_CASE
152  default: {
153  int index = GetSequenceIndexFromFastElementsKind(kind);
154  return GetFastElementsKindFromSequenceIndex(index + 1);
155  }
156  }
157 }
158 
159 
161  bool allow_only_packed) {
162  ASSERT(IsFastElementsKind(elements_kind));
163  ASSERT(elements_kind != TERMINAL_FAST_ELEMENTS_KIND);
164  while (true) {
165  elements_kind = GetNextTransitionElementsKind(elements_kind);
166  if (!IsFastHoleyElementsKind(elements_kind) || !allow_only_packed) {
167  return elements_kind;
168  }
169  }
170  UNREACHABLE();
172 }
173 
174 
176  ElementsKind to_kind) {
177  switch (from_kind) {
178  case FAST_SMI_ELEMENTS:
179  return to_kind != FAST_SMI_ELEMENTS;
181  return to_kind != FAST_SMI_ELEMENTS &&
182  to_kind != FAST_HOLEY_SMI_ELEMENTS;
184  return to_kind != FAST_SMI_ELEMENTS &&
185  to_kind != FAST_HOLEY_SMI_ELEMENTS &&
186  to_kind != FAST_DOUBLE_ELEMENTS;
188  return to_kind == FAST_ELEMENTS ||
189  to_kind == FAST_HOLEY_ELEMENTS;
190  case FAST_ELEMENTS:
191  return to_kind == FAST_HOLEY_ELEMENTS;
192  case FAST_HOLEY_ELEMENTS:
193  return false;
194  default:
195  return false;
196  }
197 }
198 
199 
200 } } // namespace v8::internal
void PrintF(const char *format,...)
Definition: v8utils.cc:40
static void Construct(ElementsKind **fast_elements_kind_sequence_ptr)
#define FIXED_TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size)
#define ASSERT(condition)
Definition: checks.h:329
const int kPointerSizeLog2
Definition: globals.h:281
const int kFastElementsKindCount
Definition: elements-kind.h:90
bool IsFastElementsKind(ElementsKind kind)
int GetSequenceIndexFromFastElementsKind(ElementsKind elements_kind)
#define UNREACHABLE()
Definition: checks.h:52
const int kFastElementsKindPackedToHoley
Definition: elements-kind.h:94
STATIC_ASSERT(sizeof(CPURegister)==sizeof(Register))
ElementsKind GetFastElementsKindFromSequenceIndex(int sequence_number)
bool IsMoreGeneralElementsKindTransition(ElementsKind from_kind, ElementsKind to_kind)
int ElementsKindToShiftSize(ElementsKind elements_kind)
static ElementsAccessor * ForKind(ElementsKind elements_kind)
Definition: elements.h:178
void PrintElementsKind(FILE *out, ElementsKind kind)
const char * ElementsKindToString(ElementsKind kind)
ElementsKind GetInitialFastElementsKind()
ElementsKind GetNextMoreGeneralFastElementsKind(ElementsKind elements_kind, bool allow_only_packed)
#define TYPED_ARRAYS(V)
Definition: objects.h:4663
bool IsFastHoleyElementsKind(ElementsKind kind)
#define LAZY_INSTANCE_INITIALIZER
const char * name() const
Definition: elements.h:47
ElementsKind GetNextTransitionElementsKind(ElementsKind kind)