Index: src/objects.h |
=================================================================== |
--- src/objects.h (revision 4057) |
+++ src/objects.h (working copy) |
@@ -72,6 +72,7 @@ |
// - Dictionary |
// - SymbolTable |
// - CompilationCacheTable |
+// - CodeCacheHashTable |
// - MapCache |
// - Context |
// - GlobalContext |
@@ -102,6 +103,7 @@ |
// - TypeSwitchInfo |
// - DebugInfo |
// - BreakPointInfo |
+// - CodeCache |
// |
// Formats of Object*: |
// Smi: [31 bit signed int] 0 |
@@ -269,6 +271,7 @@ |
V(SIGNATURE_INFO_TYPE) \ |
V(TYPE_SWITCH_INFO_TYPE) \ |
V(SCRIPT_TYPE) \ |
+ V(CODE_CACHE_TYPE) \ |
\ |
V(JS_VALUE_TYPE) \ |
V(JS_OBJECT_TYPE) \ |
@@ -364,7 +367,8 @@ |
V(OBJECT_TEMPLATE_INFO, ObjectTemplateInfo, object_template_info) \ |
V(SIGNATURE_INFO, SignatureInfo, signature_info) \ |
V(TYPE_SWITCH_INFO, TypeSwitchInfo, type_switch_info) \ |
- V(SCRIPT, Script, script) |
+ V(SCRIPT, Script, script) \ |
+ V(CODE_CACHE, CodeCache, code_cache) |
#ifdef ENABLE_DEBUGGER_SUPPORT |
#define STRUCT_LIST_DEBUGGER(V) \ |
@@ -468,6 +472,7 @@ |
SIGNATURE_INFO_TYPE, |
TYPE_SWITCH_INFO_TYPE, |
SCRIPT_TYPE, |
+ CODE_CACHE_TYPE, |
#ifdef ENABLE_DEBUGGER_SUPPORT |
DEBUG_INFO_TYPE, |
BREAK_POINT_INFO_TYPE, |
@@ -601,6 +606,7 @@ |
inline bool IsDictionary(); |
inline bool IsSymbolTable(); |
inline bool IsCompilationCacheTable(); |
+ inline bool IsCodeCacheHashTable(); |
inline bool IsMapCache(); |
inline bool IsPrimitive(); |
inline bool IsGlobalObject(); |
@@ -2929,7 +2935,7 @@ |
DECL_ACCESSORS(instance_descriptors, DescriptorArray) |
// [stub cache]: contains stubs compiled for this map. |
- DECL_ACCESSORS(code_cache, FixedArray) |
+ DECL_ACCESSORS(code_cache, Object) |
Object* CopyDropDescriptors(); |
@@ -2965,10 +2971,10 @@ |
// Returns the non-negative index of the code object if it is in the |
// cache and -1 otherwise. |
- int IndexInCodeCache(Code* code); |
+ int IndexInCodeCache(String* name, Code* code); |
// Removes a code object from the code cache at the given index. |
- void RemoveFromCodeCache(int index); |
+ void RemoveFromCodeCache(String* name, Code* code, int index); |
// For every transition in this map, makes the transition's |
// target's prototype pointer point back to this map. |
@@ -3033,6 +3039,11 @@ |
static const int kNeedsLoading = 0; |
static const int kIsExtensible = 1; |
+ // Layout of the default cache. It holds alternating name and code objects. |
+ static const int kCodeCacheEntrySize = 2; |
+ static const int kCodeCacheEntryNameOffset = 0; |
+ static const int kCodeCacheEntryCodeOffset = 1; |
+ |
private: |
DISALLOW_IMPLICIT_CONSTRUCTORS(Map); |
}; |
@@ -3716,6 +3727,97 @@ |
}; |
+class CodeCache: public Struct { |
+ public: |
+ DECL_ACCESSORS(default_cache, FixedArray) |
+ DECL_ACCESSORS(normal_type_cache, Object) |
+ |
+ // Add the code object to the cache. |
+ Object* Update(String* name, Code* code); |
+ |
+ // Lookup code object in the cache. Returns code object if found and undefined |
+ // if not. |
+ Object* Lookup(String* name, Code::Flags flags); |
+ |
+ // Get the internal index of a code object in the cache. Returns -1 if the |
+ // code object is not in that cache. This index can be used to later call |
+ // RemoveByIndex. The cache cannot be modified between a call to GetIndex and |
+ // RemoveByIndex. |
+ int GetIndex(String* name, Code* code); |
+ |
+ // Remove an object from the cache with the provided internal index. |
+ void RemoveByIndex(String* name, Code* code, int index); |
+ |
+ static inline CodeCache* cast(Object* obj); |
+ |
+#ifdef DEBUG |
+ void CodeCachePrint(); |
+ void CodeCacheVerify(); |
+#endif |
+ |
+ static const int kDefaultCacheOffset = HeapObject::kHeaderSize; |
+ static const int kNormalTypeCacheOffset = |
+ kDefaultCacheOffset + kPointerSize; |
+ static const int kSize = kNormalTypeCacheOffset + kPointerSize; |
+ |
+ private: |
+ Object* UpdateDefaultCache(String* name, Code* code); |
+ Object* UpdateNormalTypeCache(String* name, Code* code); |
+ Object* LookupDefaultCache(String* name, Code::Flags flags); |
+ Object* LookupNormalTypeCache(String* name, Code::Flags flags); |
+ |
+ // Code cache layout of the default cache. Elements are alternating name and |
+ // code objects for non normal load/store/call IC's. |
+ static const int kCodeCacheEntrySize = 2; |
+ static const int kCodeCacheEntryNameOffset = 0; |
+ static const int kCodeCacheEntryCodeOffset = 1; |
+ |
+ DISALLOW_IMPLICIT_CONSTRUCTORS(CodeCache); |
+}; |
+ |
+ |
+class CodeCacheHashTableShape { |
+ public: |
+ static inline bool IsMatch(HashTableKey* key, Object* value) { |
+ return key->IsMatch(value); |
+ } |
+ |
+ static inline uint32_t Hash(HashTableKey* key) { |
+ return key->Hash(); |
+ } |
+ |
+ static inline uint32_t HashForObject(HashTableKey* key, Object* object) { |
+ return key->HashForObject(object); |
+ } |
+ |
+ static Object* AsObject(HashTableKey* key) { |
+ return key->AsObject(); |
+ } |
+ |
+ static const int kPrefixSize = 0; |
+ static const int kEntrySize = 2; |
+}; |
+ |
+ |
+class CodeCacheHashTable: public HashTable<CodeCacheHashTableShape, |
+ HashTableKey*> { |
+ public: |
+ Object* Lookup(String* name, Code::Flags flags); |
+ Object* Put(String* name, Code* code); |
+ |
+ int GetIndex(String* name, Code::Flags flags); |
+ void RemoveByIndex(int index); |
+ |
+ static inline CodeCacheHashTable* cast(Object* obj); |
+ |
+ // Initial size of the fixed array backing the hash table. |
+ static const int kInitialSize = 64; |
+ |
+ private: |
+ DISALLOW_IMPLICIT_CONSTRUCTORS(CodeCacheHashTable); |
+}; |
+ |
+ |
enum AllowNullsFlag {ALLOW_NULLS, DISALLOW_NULLS}; |
enum RobustnessFlag {ROBUST_STRING_TRAVERSAL, FAST_STRING_TRAVERSAL}; |