Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(195)

Side by Side Diff: src/elements-kind.cc

Issue 10442015: Rollback of r11638, r11636 on trunk branch. (Closed) Base URL: https://v8.googlecode.com/svn/trunk
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/elements-kind.h ('k') | src/factory.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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) {
39 ElementsAccessor* accessor = ElementsAccessor::ForKind(kind);
40 PrintF(out, "%s", accessor->name());
41 }
42
43
44 ElementsKind GetInitialFastElementsKind() {
45 if (FLAG_packed_arrays) {
46 return FAST_SMI_ELEMENTS;
47 } else {
48 return FAST_HOLEY_SMI_ELEMENTS;
49 }
50 }
51
52
53 struct InitializeFastElementsKindSequence {
54 static void Construct(
55 ElementsKind** fast_elements_kind_sequence_ptr) {
56 ElementsKind* fast_elements_kind_sequence =
57 new ElementsKind[kFastElementsKindCount];
58 *fast_elements_kind_sequence_ptr = fast_elements_kind_sequence;
59 STATIC_ASSERT(FAST_SMI_ELEMENTS == FIRST_FAST_ELEMENTS_KIND);
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
75 ElementsKind GetFastElementsKindFromSequenceIndex(int sequence_number) {
76 ASSERT(sequence_number >= 0 &&
77 sequence_number < kFastElementsKindCount);
78 return fast_elements_kind_sequence.Get()[sequence_number];
79 }
80
81 int GetSequenceIndexFromFastElementsKind(ElementsKind elements_kind) {
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
92 ElementsKind GetNextMoreGeneralFastElementsKind(ElementsKind elements_kind,
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();
105 return TERMINAL_FAST_ELEMENTS_KIND;
106 }
107
108
109 bool IsMoreGeneralElementsKindTransition(ElementsKind from_kind,
110 ElementsKind to_kind) {
111 switch (from_kind) {
112 case FAST_SMI_ELEMENTS:
113 return to_kind != FAST_SMI_ELEMENTS;
114 case FAST_HOLEY_SMI_ELEMENTS:
115 return to_kind != FAST_SMI_ELEMENTS &&
116 to_kind != FAST_HOLEY_SMI_ELEMENTS;
117 case FAST_DOUBLE_ELEMENTS:
118 return to_kind != FAST_SMI_ELEMENTS &&
119 to_kind != FAST_HOLEY_SMI_ELEMENTS &&
120 to_kind != FAST_DOUBLE_ELEMENTS;
121 case FAST_HOLEY_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
OLDNEW
« no previous file with comments | « src/elements-kind.h ('k') | src/factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698