v8  3.14.5(node0.10.28)
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 
38 void PrintElementsKind(FILE* out, ElementsKind kind) {
40  PrintF(out, "%s", accessor->name());
41 }
42 
43 
45  if (FLAG_packed_arrays) {
46  return FAST_SMI_ELEMENTS;
47  } else {
49  }
50 }
51 
52 
54  static void Construct(
55  ElementsKind** fast_elements_kind_sequence_ptr) {
56  ElementsKind* fast_elements_kind_sequence =
58  *fast_elements_kind_sequence_ptr = fast_elements_kind_sequence;
60  fast_elements_kind_sequence[0] = FAST_SMI_ELEMENTS;
61  fast_elements_kind_sequence[1] = FAST_HOLEY_SMI_ELEMENTS;
62  fast_elements_kind_sequence[2] = FAST_DOUBLE_ELEMENTS;
63  fast_elements_kind_sequence[3] = FAST_HOLEY_DOUBLE_ELEMENTS;
64  fast_elements_kind_sequence[4] = FAST_ELEMENTS;
65  fast_elements_kind_sequence[5] = FAST_HOLEY_ELEMENTS;
66  }
67 };
68 
69 
70 static LazyInstance<ElementsKind*,
71  InitializeFastElementsKindSequence>::type
72  fast_elements_kind_sequence = LAZY_INSTANCE_INITIALIZER;
73 
74 
76  ASSERT(sequence_number >= 0 &&
77  sequence_number < kFastElementsKindCount);
78  return fast_elements_kind_sequence.Get()[sequence_number];
79 }
80 
82  for (int i = 0; i < kFastElementsKindCount; ++i) {
83  if (fast_elements_kind_sequence.Get()[i] == elements_kind) {
84  return i;
85  }
86  }
87  UNREACHABLE();
88  return 0;
89 }
90 
91 
93  bool allow_only_packed) {
94  ASSERT(IsFastElementsKind(elements_kind));
95  ASSERT(elements_kind != TERMINAL_FAST_ELEMENTS_KIND);
96  while (true) {
97  int index =
98  GetSequenceIndexFromFastElementsKind(elements_kind) + 1;
99  elements_kind = GetFastElementsKindFromSequenceIndex(index);
100  if (!IsFastHoleyElementsKind(elements_kind) || !allow_only_packed) {
101  return elements_kind;
102  }
103  }
104  UNREACHABLE();
106 }
107 
108 
110  ElementsKind to_kind) {
111  switch (from_kind) {
112  case FAST_SMI_ELEMENTS:
113  return to_kind != FAST_SMI_ELEMENTS;
115  return to_kind != FAST_SMI_ELEMENTS &&
116  to_kind != FAST_HOLEY_SMI_ELEMENTS;
118  return to_kind != FAST_SMI_ELEMENTS &&
119  to_kind != FAST_HOLEY_SMI_ELEMENTS &&
120  to_kind != FAST_DOUBLE_ELEMENTS;
122  return to_kind == FAST_ELEMENTS ||
123  to_kind == FAST_HOLEY_ELEMENTS;
124  case FAST_ELEMENTS:
125  return to_kind == FAST_HOLEY_ELEMENTS;
126  case FAST_HOLEY_ELEMENTS:
127  return false;
128  default:
129  return false;
130  }
131 }
132 
133 
134 } } // namespace v8::internal
void PrintF(const char *format,...)
Definition: v8utils.cc:40
static void Construct(ElementsKind **fast_elements_kind_sequence_ptr)
#define ASSERT(condition)
Definition: checks.h:270
const int kFastElementsKindCount
Definition: elements-kind.h:77
bool IsFastElementsKind(ElementsKind kind)
int GetSequenceIndexFromFastElementsKind(ElementsKind elements_kind)
#define UNREACHABLE()
Definition: checks.h:50
STATIC_ASSERT((FixedDoubleArray::kHeaderSize &kDoubleAlignmentMask)==0)
ElementsKind GetFastElementsKindFromSequenceIndex(int sequence_number)
bool IsMoreGeneralElementsKindTransition(ElementsKind from_kind, ElementsKind to_kind)
static ElementsAccessor * ForKind(ElementsKind elements_kind)
Definition: elements.h:134
void PrintElementsKind(FILE *out, ElementsKind kind)
ElementsKind GetInitialFastElementsKind()
ElementsKind GetNextMoreGeneralFastElementsKind(ElementsKind elements_kind, bool allow_only_packed)
bool IsFastHoleyElementsKind(ElementsKind kind)
#define LAZY_INSTANCE_INITIALIZER
const char * name() const
Definition: elements.h:47