Index: src/scopeinfo.h |
=================================================================== |
--- src/scopeinfo.h (revision 2226) |
+++ src/scopeinfo.h (working copy) |
@@ -163,6 +163,75 @@ |
}; |
+// Cache for mapping (code, property name) into context slot index. |
+// The cache contains both positive and negative results. |
+// slot index -1 means the property is absent. |
Mads Ager (chromium)
2009/06/22 08:00:18
Capitalize 'Slot'?
|
+// Cleared at startup and prior to mark sweep collection. |
+class ContextSlotCache { |
+ public: |
+ // Lookup context slot index for (code, name). |
+ // If absent, kNotFound is returned. |
+ static int Lookup(Code* code, |
+ String* name, |
+ Variable::Mode* mode); |
+ |
+ // Update an element in the cache. |
+ static void Update(Code* code, |
+ String* name, |
+ Variable::Mode mode, |
+ int slot_index); |
+ |
+ // Clear the cache. |
+ static void Clear(); |
+ |
+ static const int kNotFound = -2; |
+ private: |
+ inline static int Hash(Code* code, String* name); |
+ |
+#ifdef DEBUG |
+ // Checks whether an entry is valid. |
+ static void Check(Code* code, |
Mads Ager (chromium)
2009/06/22 08:00:18
Use a more telling name such as 'IsValidEntry'?
|
+ String* name, |
+ Variable::Mode mode, |
+ int slot_index); |
+#endif |
+ |
+ static const int kLength = 256; |
+ struct Key { |
+ Code* code; |
+ String* name; |
+ }; |
+ |
+ struct Value { |
+ Value(Variable::Mode mode, int index) { |
+ ASSERT(ModeField::is_valid(mode)); |
+ ASSERT(IndexField::is_valid(index)); |
+ value_ = ModeField::encode(mode) | IndexField::encode(index); |
+ ASSERT(mode == this->mode()); |
+ ASSERT(index == this->index()); |
+ } |
+ |
+ inline Value(uint32_t value) : value_(value) {} |
+ |
+ uint32_t raw() { return value_; } |
+ |
+ Variable::Mode mode() { return ModeField::decode(value_); } |
+ |
+ int index() { return IndexField::decode(value_); } |
+ |
+ // Bit fields in value_ (type, shift, size). Must be public so the |
+ // constants can be embedded in generated code. |
+ class ModeField: public BitField<Variable::Mode, 0, 3> {}; |
+ class IndexField: public BitField<int, 3, 32-3> {}; |
+ private: |
+ uint32_t value_; |
+ }; |
+ |
+ static Key keys_[kLength]; |
+ static uint32_t values_[kLength]; |
+}; |
+ |
+ |
} } // namespace v8::internal |
#endif // V8_SCOPEINFO_H_ |