| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 | 165 |
| 166 | 166 |
| 167 // Cache for mapping (code, property name) into context slot index. | 167 // Cache for mapping (code, property name) into context slot index. |
| 168 // The cache contains both positive and negative results. | 168 // The cache contains both positive and negative results. |
| 169 // Slot index equals -1 means the property is absent. | 169 // Slot index equals -1 means the property is absent. |
| 170 // Cleared at startup and prior to mark sweep collection. | 170 // Cleared at startup and prior to mark sweep collection. |
| 171 class ContextSlotCache { | 171 class ContextSlotCache { |
| 172 public: | 172 public: |
| 173 // Lookup context slot index for (code, name). | 173 // Lookup context slot index for (code, name). |
| 174 // If absent, kNotFound is returned. | 174 // If absent, kNotFound is returned. |
| 175 static int Lookup(Code* code, | 175 int Lookup(Code* code, String* name, Variable::Mode* mode); |
| 176 String* name, | |
| 177 Variable::Mode* mode); | |
| 178 | 176 |
| 179 // Update an element in the cache. | 177 // Update an element in the cache. |
| 180 static void Update(Code* code, | 178 void Update(Code* code, String* name, Variable::Mode mode, int slot_index); |
| 179 |
| 180 // Clear the cache. |
| 181 void Clear(); |
| 182 |
| 183 static const int kNotFound = -2; |
| 184 private: |
| 185 ContextSlotCache() { |
| 186 for (int i = 0; i < kLength; ++i) { |
| 187 keys_[i].code = NULL; |
| 188 keys_[i].name = NULL; |
| 189 values_[i] = kNotFound; |
| 190 } |
| 191 } |
| 192 |
| 193 inline static int Hash(Code* code, String* name); |
| 194 |
| 195 #ifdef DEBUG |
| 196 void ValidateEntry(Code* code, |
| 181 String* name, | 197 String* name, |
| 182 Variable::Mode mode, | 198 Variable::Mode mode, |
| 183 int slot_index); | 199 int slot_index); |
| 184 | |
| 185 // Clear the cache. | |
| 186 static void Clear(); | |
| 187 | |
| 188 static const int kNotFound = -2; | |
| 189 private: | |
| 190 inline static int Hash(Code* code, String* name); | |
| 191 | |
| 192 #ifdef DEBUG | |
| 193 static void ValidateEntry(Code* code, | |
| 194 String* name, | |
| 195 Variable::Mode mode, | |
| 196 int slot_index); | |
| 197 #endif | 200 #endif |
| 198 | 201 |
| 199 static const int kLength = 256; | 202 static const int kLength = 256; |
| 200 struct Key { | 203 struct Key { |
| 201 Code* code; | 204 Code* code; |
| 202 String* name; | 205 String* name; |
| 203 }; | 206 }; |
| 204 | 207 |
| 205 struct Value { | 208 struct Value { |
| 206 Value(Variable::Mode mode, int index) { | 209 Value(Variable::Mode mode, int index) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 220 int index() { return IndexField::decode(value_); } | 223 int index() { return IndexField::decode(value_); } |
| 221 | 224 |
| 222 // Bit fields in value_ (type, shift, size). Must be public so the | 225 // Bit fields in value_ (type, shift, size). Must be public so the |
| 223 // constants can be embedded in generated code. | 226 // constants can be embedded in generated code. |
| 224 class ModeField: public BitField<Variable::Mode, 0, 3> {}; | 227 class ModeField: public BitField<Variable::Mode, 0, 3> {}; |
| 225 class IndexField: public BitField<int, 3, 32-3> {}; | 228 class IndexField: public BitField<int, 3, 32-3> {}; |
| 226 private: | 229 private: |
| 227 uint32_t value_; | 230 uint32_t value_; |
| 228 }; | 231 }; |
| 229 | 232 |
| 230 static Key keys_[kLength]; | 233 Key keys_[kLength]; |
| 231 static uint32_t values_[kLength]; | 234 uint32_t values_[kLength]; |
| 235 |
| 236 friend class Isolate; |
| 237 DISALLOW_COPY_AND_ASSIGN(ContextSlotCache); |
| 232 }; | 238 }; |
| 233 | 239 |
| 234 | 240 |
| 235 } } // namespace v8::internal | 241 } } // namespace v8::internal |
| 236 | 242 |
| 237 #endif // V8_SCOPEINFO_H_ | 243 #endif // V8_SCOPEINFO_H_ |
| OLD | NEW |