OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_SCOPEINFO_H_ | 5 #ifndef V8_SCOPEINFO_H_ |
6 #define V8_SCOPEINFO_H_ | 6 #define V8_SCOPEINFO_H_ |
7 | 7 |
8 #include "src/allocation.h" | 8 #include "src/allocation.h" |
9 #include "src/variables.h" | 9 #include "src/variables.h" |
10 #include "src/zone-inl.h" | 10 #include "src/zone-inl.h" |
11 | 11 |
12 namespace v8 { | 12 namespace v8 { |
13 namespace internal { | 13 namespace internal { |
14 | 14 |
15 // Cache for mapping (data, property name) into context slot index. | 15 // Cache for mapping (data, property name) into context slot index. |
16 // The cache contains both positive and negative results. | 16 // The cache contains both positive and negative results. |
17 // Slot index equals -1 means the property is absent. | 17 // Slot index equals -1 means the property is absent. |
18 // Cleared at startup and prior to mark sweep collection. | 18 // Cleared at startup and prior to mark sweep collection. |
19 class ContextSlotCache { | 19 class ContextSlotCache { |
20 public: | 20 public: |
21 // Lookup context slot index for (data, name). | 21 // Lookup context slot index for (data, name). |
22 // If absent, kNotFound is returned. | 22 // If absent, kNotFound is returned. |
23 int Lookup(Object* data, | 23 int Lookup(Object* data, String* name, VariableMode* mode, |
24 String* name, | 24 InitializationFlag* init_flag, |
25 VariableMode* mode, | 25 MaybeAssignedFlag* maybe_assigned_flag); |
26 InitializationFlag* init_flag); | |
27 | 26 |
28 // Update an element in the cache. | 27 // Update an element in the cache. |
29 void Update(Handle<Object> data, | 28 void Update(Handle<Object> data, Handle<String> name, VariableMode mode, |
30 Handle<String> name, | |
31 VariableMode mode, | |
32 InitializationFlag init_flag, | 29 InitializationFlag init_flag, |
33 int slot_index); | 30 MaybeAssignedFlag maybe_assigned_flag, int slot_index); |
34 | 31 |
35 // Clear the cache. | 32 // Clear the cache. |
36 void Clear(); | 33 void Clear(); |
37 | 34 |
38 static const int kNotFound = -2; | 35 static const int kNotFound = -2; |
39 | 36 |
40 private: | 37 private: |
41 ContextSlotCache() { | 38 ContextSlotCache() { |
42 for (int i = 0; i < kLength; ++i) { | 39 for (int i = 0; i < kLength; ++i) { |
43 keys_[i].data = NULL; | 40 keys_[i].data = NULL; |
44 keys_[i].name = NULL; | 41 keys_[i].name = NULL; |
45 values_[i] = kNotFound; | 42 values_[i] = kNotFound; |
46 } | 43 } |
47 } | 44 } |
48 | 45 |
49 inline static int Hash(Object* data, String* name); | 46 inline static int Hash(Object* data, String* name); |
50 | 47 |
51 #ifdef DEBUG | 48 #ifdef DEBUG |
52 void ValidateEntry(Handle<Object> data, | 49 void ValidateEntry(Handle<Object> data, Handle<String> name, |
53 Handle<String> name, | 50 VariableMode mode, InitializationFlag init_flag, |
54 VariableMode mode, | 51 MaybeAssignedFlag maybe_assigned_flag, int slot_index); |
55 InitializationFlag init_flag, | |
56 int slot_index); | |
57 #endif | 52 #endif |
58 | 53 |
59 static const int kLength = 256; | 54 static const int kLength = 256; |
60 struct Key { | 55 struct Key { |
61 Object* data; | 56 Object* data; |
62 String* name; | 57 String* name; |
63 }; | 58 }; |
64 | 59 |
65 struct Value { | 60 struct Value { |
66 Value(VariableMode mode, | 61 Value(VariableMode mode, InitializationFlag init_flag, |
67 InitializationFlag init_flag, | 62 MaybeAssignedFlag maybe_assigned_flag, int index) { |
68 int index) { | |
69 ASSERT(ModeField::is_valid(mode)); | 63 ASSERT(ModeField::is_valid(mode)); |
70 ASSERT(InitField::is_valid(init_flag)); | 64 ASSERT(InitField::is_valid(init_flag)); |
| 65 ASSERT(MaybeAssignedField::is_valid(maybe_assigned_flag)); |
71 ASSERT(IndexField::is_valid(index)); | 66 ASSERT(IndexField::is_valid(index)); |
72 value_ = ModeField::encode(mode) | | 67 value_ = ModeField::encode(mode) | IndexField::encode(index) | |
73 IndexField::encode(index) | | 68 InitField::encode(init_flag) | |
74 InitField::encode(init_flag); | 69 MaybeAssignedField::encode(maybe_assigned_flag); |
75 ASSERT(mode == this->mode()); | 70 ASSERT(mode == this->mode()); |
76 ASSERT(init_flag == this->initialization_flag()); | 71 ASSERT(init_flag == this->initialization_flag()); |
| 72 ASSERT(maybe_assigned_flag == this->maybe_assigned_flag()); |
77 ASSERT(index == this->index()); | 73 ASSERT(index == this->index()); |
78 } | 74 } |
79 | 75 |
80 explicit inline Value(uint32_t value) : value_(value) {} | 76 explicit inline Value(uint32_t value) : value_(value) {} |
81 | 77 |
82 uint32_t raw() { return value_; } | 78 uint32_t raw() { return value_; } |
83 | 79 |
84 VariableMode mode() { return ModeField::decode(value_); } | 80 VariableMode mode() { return ModeField::decode(value_); } |
85 | 81 |
86 InitializationFlag initialization_flag() { | 82 InitializationFlag initialization_flag() { |
87 return InitField::decode(value_); | 83 return InitField::decode(value_); |
88 } | 84 } |
89 | 85 |
| 86 MaybeAssignedFlag maybe_assigned_flag() { |
| 87 return MaybeAssignedField::decode(value_); |
| 88 } |
| 89 |
90 int index() { return IndexField::decode(value_); } | 90 int index() { return IndexField::decode(value_); } |
91 | 91 |
92 // Bit fields in value_ (type, shift, size). Must be public so the | 92 // Bit fields in value_ (type, shift, size). Must be public so the |
93 // constants can be embedded in generated code. | 93 // constants can be embedded in generated code. |
94 class ModeField: public BitField<VariableMode, 0, 4> {}; | 94 class ModeField : public BitField<VariableMode, 0, 4> {}; |
95 class InitField: public BitField<InitializationFlag, 4, 1> {}; | 95 class InitField : public BitField<InitializationFlag, 4, 1> {}; |
96 class IndexField: public BitField<int, 5, 32-5> {}; | 96 class MaybeAssignedField : public BitField<MaybeAssignedFlag, 5, 1> {}; |
| 97 class IndexField : public BitField<int, 6, 32 - 6> {}; |
97 | 98 |
98 private: | 99 private: |
99 uint32_t value_; | 100 uint32_t value_; |
100 }; | 101 }; |
101 | 102 |
102 Key keys_[kLength]; | 103 Key keys_[kLength]; |
103 uint32_t values_[kLength]; | 104 uint32_t values_[kLength]; |
104 | 105 |
105 friend class Isolate; | 106 friend class Isolate; |
106 DISALLOW_COPY_AND_ASSIGN(ContextSlotCache); | 107 DISALLOW_COPY_AND_ASSIGN(ContextSlotCache); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 } | 165 } |
165 void set_index(int i, int index) { | 166 void set_index(int i, int index) { |
166 set(index_offset(i), Smi::FromInt(index)); | 167 set(index_offset(i), Smi::FromInt(index)); |
167 } | 168 } |
168 }; | 169 }; |
169 | 170 |
170 | 171 |
171 } } // namespace v8::internal | 172 } } // namespace v8::internal |
172 | 173 |
173 #endif // V8_SCOPEINFO_H_ | 174 #endif // V8_SCOPEINFO_H_ |
OLD | NEW |