| 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 VariableLocation* location, InitializationFlag* init_flag, | 24 InitializationFlag* init_flag, |
| 25 MaybeAssignedFlag* maybe_assigned_flag); | 25 MaybeAssignedFlag* maybe_assigned_flag); |
| 26 | 26 |
| 27 // Update an element in the cache. | 27 // Update an element in the cache. |
| 28 void Update(Handle<Object> data, Handle<String> name, VariableMode mode, | 28 void Update(Handle<Object> data, Handle<String> name, VariableMode mode, |
| 29 VariableLocation location, InitializationFlag init_flag, | 29 InitializationFlag init_flag, |
| 30 MaybeAssignedFlag maybe_assigned_flag, int slot_index); | 30 MaybeAssignedFlag maybe_assigned_flag, int slot_index); |
| 31 | 31 |
| 32 // Clear the cache. | 32 // Clear the cache. |
| 33 void Clear(); | 33 void Clear(); |
| 34 | 34 |
| 35 static const int kNotFound = -2; | 35 static const int kNotFound = -2; |
| 36 | 36 |
| 37 private: | 37 private: |
| 38 ContextSlotCache() { | 38 ContextSlotCache() { |
| 39 for (int i = 0; i < kLength; ++i) { | 39 for (int i = 0; i < kLength; ++i) { |
| 40 keys_[i].data = NULL; | 40 keys_[i].data = NULL; |
| 41 keys_[i].name = NULL; | 41 keys_[i].name = NULL; |
| 42 values_[i] = kNotFound; | 42 values_[i] = kNotFound; |
| 43 } | 43 } |
| 44 } | 44 } |
| 45 | 45 |
| 46 inline static int Hash(Object* data, String* name); | 46 inline static int Hash(Object* data, String* name); |
| 47 | 47 |
| 48 #ifdef DEBUG | 48 #ifdef DEBUG |
| 49 void ValidateEntry(Handle<Object> data, Handle<String> name, | 49 void ValidateEntry(Handle<Object> data, Handle<String> name, |
| 50 VariableMode mode, VariableLocation location, | 50 VariableMode mode, InitializationFlag init_flag, |
| 51 InitializationFlag init_flag, | |
| 52 MaybeAssignedFlag maybe_assigned_flag, int slot_index); | 51 MaybeAssignedFlag maybe_assigned_flag, int slot_index); |
| 53 #endif | 52 #endif |
| 54 | 53 |
| 55 static const int kLength = 256; | 54 static const int kLength = 256; |
| 56 struct Key { | 55 struct Key { |
| 57 Object* data; | 56 Object* data; |
| 58 String* name; | 57 String* name; |
| 59 }; | 58 }; |
| 60 | 59 |
| 61 struct Value { | 60 struct Value { |
| 62 enum VariableLocationFlag { kContext, kGlobal }; | 61 Value(VariableMode mode, InitializationFlag init_flag, |
| 63 | 62 MaybeAssignedFlag maybe_assigned_flag, int index) { |
| 64 Value(VariableMode mode, VariableLocation location, | |
| 65 InitializationFlag init_flag, MaybeAssignedFlag maybe_assigned_flag, | |
| 66 int index) { | |
| 67 DCHECK(location == VariableLocation::CONTEXT || | |
| 68 location == VariableLocation::GLOBAL); | |
| 69 VariableLocationFlag location_flag = | |
| 70 location == VariableLocation::CONTEXT ? kContext : kGlobal; | |
| 71 DCHECK(ModeField::is_valid(mode)); | 63 DCHECK(ModeField::is_valid(mode)); |
| 72 DCHECK(VariableLocationField::is_valid(location_flag)); | |
| 73 DCHECK(InitField::is_valid(init_flag)); | 64 DCHECK(InitField::is_valid(init_flag)); |
| 74 DCHECK(MaybeAssignedField::is_valid(maybe_assigned_flag)); | 65 DCHECK(MaybeAssignedField::is_valid(maybe_assigned_flag)); |
| 75 DCHECK(IndexField::is_valid(index)); | 66 DCHECK(IndexField::is_valid(index)); |
| 76 value_ = ModeField::encode(mode) | IndexField::encode(index) | | 67 value_ = ModeField::encode(mode) | IndexField::encode(index) | |
| 77 VariableLocationField::encode(location_flag) | | |
| 78 InitField::encode(init_flag) | | 68 InitField::encode(init_flag) | |
| 79 MaybeAssignedField::encode(maybe_assigned_flag); | 69 MaybeAssignedField::encode(maybe_assigned_flag); |
| 80 DCHECK(mode == this->mode()); | 70 DCHECK(mode == this->mode()); |
| 81 DCHECK(location == this->location()); | |
| 82 DCHECK(init_flag == this->initialization_flag()); | 71 DCHECK(init_flag == this->initialization_flag()); |
| 83 DCHECK(maybe_assigned_flag == this->maybe_assigned_flag()); | 72 DCHECK(maybe_assigned_flag == this->maybe_assigned_flag()); |
| 84 DCHECK(index == this->index()); | 73 DCHECK(index == this->index()); |
| 85 } | 74 } |
| 86 | 75 |
| 87 explicit inline Value(uint32_t value) : value_(value) {} | 76 explicit inline Value(uint32_t value) : value_(value) {} |
| 88 | 77 |
| 89 uint32_t raw() { return value_; } | 78 uint32_t raw() { return value_; } |
| 90 | 79 |
| 91 VariableMode mode() { return ModeField::decode(value_); } | 80 VariableMode mode() { return ModeField::decode(value_); } |
| 92 | 81 |
| 93 VariableLocation location() { | |
| 94 switch (VariableLocationField::decode(value_)) { | |
| 95 case kContext: | |
| 96 return VariableLocation::CONTEXT; | |
| 97 case kGlobal: | |
| 98 return VariableLocation::GLOBAL; | |
| 99 } | |
| 100 UNREACHABLE(); | |
| 101 return VariableLocation::CONTEXT; | |
| 102 } | |
| 103 | |
| 104 InitializationFlag initialization_flag() { | 82 InitializationFlag initialization_flag() { |
| 105 return InitField::decode(value_); | 83 return InitField::decode(value_); |
| 106 } | 84 } |
| 107 | 85 |
| 108 MaybeAssignedFlag maybe_assigned_flag() { | 86 MaybeAssignedFlag maybe_assigned_flag() { |
| 109 return MaybeAssignedField::decode(value_); | 87 return MaybeAssignedField::decode(value_); |
| 110 } | 88 } |
| 111 | 89 |
| 112 int index() { return IndexField::decode(value_); } | 90 int index() { return IndexField::decode(value_); } |
| 113 | 91 |
| 114 // 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 |
| 115 // constants can be embedded in generated code. | 93 // constants can be embedded in generated code. |
| 116 class ModeField : public BitField<VariableMode, 0, 4> {}; | 94 class ModeField : public BitField<VariableMode, 0, 4> {}; |
| 117 class InitField : public BitField<InitializationFlag, 4, 1> {}; | 95 class InitField : public BitField<InitializationFlag, 4, 1> {}; |
| 118 class MaybeAssignedField : public BitField<MaybeAssignedFlag, 5, 1> {}; | 96 class MaybeAssignedField : public BitField<MaybeAssignedFlag, 5, 1> {}; |
| 119 class VariableLocationField : public BitField<VariableLocationFlag, 6, 1> { | 97 class IndexField : public BitField<int, 6, 32 - 6> {}; |
| 120 }; | |
| 121 class IndexField : public BitField<int, 7, 32 - 7> {}; | |
| 122 | 98 |
| 123 private: | 99 private: |
| 124 uint32_t value_; | 100 uint32_t value_; |
| 125 }; | 101 }; |
| 126 | 102 |
| 127 Key keys_[kLength]; | 103 Key keys_[kLength]; |
| 128 uint32_t values_[kLength]; | 104 uint32_t values_[kLength]; |
| 129 | 105 |
| 130 friend class Isolate; | 106 friend class Isolate; |
| 131 DISALLOW_COPY_AND_ASSIGN(ContextSlotCache); | 107 DISALLOW_COPY_AND_ASSIGN(ContextSlotCache); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 } | 165 } |
| 190 void set_index(int i, int index) { | 166 void set_index(int i, int index) { |
| 191 set(index_offset(i), Smi::FromInt(index)); | 167 set(index_offset(i), Smi::FromInt(index)); |
| 192 } | 168 } |
| 193 }; | 169 }; |
| 194 | 170 |
| 195 | 171 |
| 196 } } // namespace v8::internal | 172 } } // namespace v8::internal |
| 197 | 173 |
| 198 #endif // V8_SCOPEINFO_H_ | 174 #endif // V8_SCOPEINFO_H_ |
| OLD | NEW |