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/modules.h" | 9 #include "src/modules.h" |
10 #include "src/variables.h" | 10 #include "src/variables.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, String* name, VariableMode* mode, | 23 int Lookup(Object* data, String* name, VariableMode* mode, |
| 24 ContextSlotKindFlag* context_slot_kind, |
24 InitializationFlag* init_flag, | 25 InitializationFlag* init_flag, |
25 MaybeAssignedFlag* maybe_assigned_flag); | 26 MaybeAssignedFlag* maybe_assigned_flag); |
26 | 27 |
27 // Update an element in the cache. | 28 // Update an element in the cache. |
28 void Update(Handle<Object> data, Handle<String> name, VariableMode mode, | 29 void Update(Handle<Object> data, Handle<String> name, VariableMode mode, |
| 30 ContextSlotKindFlag context_slot_kind, |
29 InitializationFlag init_flag, | 31 InitializationFlag init_flag, |
30 MaybeAssignedFlag maybe_assigned_flag, int slot_index); | 32 MaybeAssignedFlag maybe_assigned_flag, int slot_index); |
31 | 33 |
32 // Clear the cache. | 34 // Clear the cache. |
33 void Clear(); | 35 void Clear(); |
34 | 36 |
35 static const int kNotFound = -2; | 37 static const int kNotFound = -2; |
36 | 38 |
37 private: | 39 private: |
38 ContextSlotCache() { | 40 ContextSlotCache() { |
39 for (int i = 0; i < kLength; ++i) { | 41 for (int i = 0; i < kLength; ++i) { |
40 keys_[i].data = NULL; | 42 keys_[i].data = NULL; |
41 keys_[i].name = NULL; | 43 keys_[i].name = NULL; |
42 values_[i] = kNotFound; | 44 values_[i] = kNotFound; |
43 } | 45 } |
44 } | 46 } |
45 | 47 |
46 inline static int Hash(Object* data, String* name); | 48 inline static int Hash(Object* data, String* name); |
47 | 49 |
48 #ifdef DEBUG | 50 #ifdef DEBUG |
49 void ValidateEntry(Handle<Object> data, Handle<String> name, | 51 void ValidateEntry(Handle<Object> data, Handle<String> name, |
50 VariableMode mode, InitializationFlag init_flag, | 52 VariableMode mode, ContextSlotKindFlag context_slot_kind, |
| 53 InitializationFlag init_flag, |
51 MaybeAssignedFlag maybe_assigned_flag, int slot_index); | 54 MaybeAssignedFlag maybe_assigned_flag, int slot_index); |
52 #endif | 55 #endif |
53 | 56 |
54 static const int kLength = 256; | 57 static const int kLength = 256; |
55 struct Key { | 58 struct Key { |
56 Object* data; | 59 Object* data; |
57 String* name; | 60 String* name; |
58 }; | 61 }; |
59 | 62 |
60 struct Value { | 63 struct Value { |
61 Value(VariableMode mode, InitializationFlag init_flag, | 64 Value(VariableMode mode, ContextSlotKindFlag context_slot_kind, |
62 MaybeAssignedFlag maybe_assigned_flag, int index) { | 65 InitializationFlag init_flag, MaybeAssignedFlag maybe_assigned_flag, |
| 66 int index) { |
63 DCHECK(ModeField::is_valid(mode)); | 67 DCHECK(ModeField::is_valid(mode)); |
| 68 DCHECK(ContextSlotKindField::is_valid(context_slot_kind)); |
64 DCHECK(InitField::is_valid(init_flag)); | 69 DCHECK(InitField::is_valid(init_flag)); |
65 DCHECK(MaybeAssignedField::is_valid(maybe_assigned_flag)); | 70 DCHECK(MaybeAssignedField::is_valid(maybe_assigned_flag)); |
66 DCHECK(IndexField::is_valid(index)); | 71 DCHECK(IndexField::is_valid(index)); |
67 value_ = ModeField::encode(mode) | IndexField::encode(index) | | 72 value_ = ModeField::encode(mode) | IndexField::encode(index) | |
| 73 ContextSlotKindField::encode(context_slot_kind) | |
68 InitField::encode(init_flag) | | 74 InitField::encode(init_flag) | |
69 MaybeAssignedField::encode(maybe_assigned_flag); | 75 MaybeAssignedField::encode(maybe_assigned_flag); |
70 DCHECK(mode == this->mode()); | 76 DCHECK(mode == this->mode()); |
| 77 DCHECK(context_slot_kind == this->context_slot_kind()); |
71 DCHECK(init_flag == this->initialization_flag()); | 78 DCHECK(init_flag == this->initialization_flag()); |
72 DCHECK(maybe_assigned_flag == this->maybe_assigned_flag()); | 79 DCHECK(maybe_assigned_flag == this->maybe_assigned_flag()); |
73 DCHECK(index == this->index()); | 80 DCHECK(index == this->index()); |
74 } | 81 } |
75 | 82 |
76 explicit inline Value(uint32_t value) : value_(value) {} | 83 explicit inline Value(uint32_t value) : value_(value) {} |
77 | 84 |
78 uint32_t raw() { return value_; } | 85 uint32_t raw() { return value_; } |
79 | 86 |
80 VariableMode mode() { return ModeField::decode(value_); } | 87 VariableMode mode() { return ModeField::decode(value_); } |
81 | 88 |
82 InitializationFlag initialization_flag() { | 89 InitializationFlag initialization_flag() { |
83 return InitField::decode(value_); | 90 return InitField::decode(value_); |
84 } | 91 } |
85 | 92 |
86 MaybeAssignedFlag maybe_assigned_flag() { | 93 MaybeAssignedFlag maybe_assigned_flag() { |
87 return MaybeAssignedField::decode(value_); | 94 return MaybeAssignedField::decode(value_); |
88 } | 95 } |
89 | 96 |
| 97 ContextSlotKindFlag context_slot_kind() { |
| 98 return ContextSlotKindField::decode(value_); |
| 99 } |
| 100 |
90 int index() { return IndexField::decode(value_); } | 101 int index() { return IndexField::decode(value_); } |
91 | 102 |
92 // Bit fields in value_ (type, shift, size). Must be public so the | 103 // Bit fields in value_ (type, shift, size). Must be public so the |
93 // constants can be embedded in generated code. | 104 // constants can be embedded in generated code. |
94 class ModeField : public BitField<VariableMode, 0, 4> {}; | 105 class ModeField : public BitField<VariableMode, 0, 4> {}; |
95 class InitField : public BitField<InitializationFlag, 4, 1> {}; | 106 class InitField : public BitField<InitializationFlag, 4, 1> {}; |
96 class MaybeAssignedField : public BitField<MaybeAssignedFlag, 5, 1> {}; | 107 class MaybeAssignedField : public BitField<MaybeAssignedFlag, 5, 1> {}; |
97 class IndexField : public BitField<int, 6, 32 - 6> {}; | 108 class ContextSlotKindField : public BitField<ContextSlotKindFlag, 6, 1> {}; |
| 109 class IndexField : public BitField<int, 7, 32 - 7> {}; |
98 | 110 |
99 private: | 111 private: |
100 uint32_t value_; | 112 uint32_t value_; |
101 }; | 113 }; |
102 | 114 |
103 Key keys_[kLength]; | 115 Key keys_[kLength]; |
104 uint32_t values_[kLength]; | 116 uint32_t values_[kLength]; |
105 | 117 |
106 friend class Isolate; | 118 friend class Isolate; |
107 DISALLOW_COPY_AND_ASSIGN(ContextSlotCache); | 119 DISALLOW_COPY_AND_ASSIGN(ContextSlotCache); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 } | 177 } |
166 void set_index(int i, int index) { | 178 void set_index(int i, int index) { |
167 set(index_offset(i), Smi::FromInt(index)); | 179 set(index_offset(i), Smi::FromInt(index)); |
168 } | 180 } |
169 }; | 181 }; |
170 | 182 |
171 | 183 |
172 } } // namespace v8::internal | 184 } } // namespace v8::internal |
173 | 185 |
174 #endif // V8_SCOPEINFO_H_ | 186 #endif // V8_SCOPEINFO_H_ |
OLD | NEW |