diff options
Diffstat (limited to 'chromium/v8/src/global-handles.h')
-rw-r--r-- | chromium/v8/src/global-handles.h | 83 |
1 files changed, 82 insertions, 1 deletions
diff --git a/chromium/v8/src/global-handles.h b/chromium/v8/src/global-handles.h index cd75133a243..4b46aac05d0 100644 --- a/chromium/v8/src/global-handles.h +++ b/chromium/v8/src/global-handles.h @@ -31,6 +31,7 @@ #include "../include/v8.h" #include "../include/v8-profiler.h" +#include "handles.h" #include "list.h" #include "v8utils.h" @@ -127,9 +128,13 @@ class GlobalHandles { // Creates a new global handle that is alive until Destroy is called. Handle<Object> Create(Object* value); + // Copy a global handle + static Handle<Object> CopyGlobal(Object** location); + // Destroy a global handle. static void Destroy(Object** location); + typedef WeakCallbackData<v8::Value, void>::Callback WeakCallback; typedef WeakReferenceCallbacks<v8::Value, void>::Revivable RevivableCallback; // Make the global handle weak and set the callback parameter for the @@ -140,7 +145,14 @@ class GlobalHandles { // reason is that Smi::FromInt(0) does not change during garage collection. static void MakeWeak(Object** location, void* parameter, - RevivableCallback weak_reference_callback); + WeakCallback weak_callback, + RevivableCallback revivable_callback); + + static inline void MakeWeak(Object** location, + void* parameter, + RevivableCallback revivable_callback) { + MakeWeak(location, parameter, NULL, revivable_callback); + } void RecordStats(HeapStats* stats); @@ -331,6 +343,75 @@ class GlobalHandles { }; +class EternalHandles { + public: + enum SingletonHandle { + I18N_TEMPLATE_ONE, + I18N_TEMPLATE_TWO, + + NUMBER_OF_SINGLETON_HANDLES + }; + + EternalHandles(); + ~EternalHandles(); + + int NumberOfHandles() { return size_; } + + // Create an EternalHandle, overwriting the index. + void Create(Isolate* isolate, Object* object, int* index); + + // Grab the handle for an existing EternalHandle. + inline Handle<Object> Get(int index) { + return Handle<Object>(GetLocation(index)); + } + + // Grab the handle for an existing SingletonHandle. + inline Handle<Object> GetSingleton(SingletonHandle singleton) { + ASSERT(Exists(singleton)); + return Get(singleton_handles_[singleton]); + } + + // Checks whether a SingletonHandle has been assigned. + inline bool Exists(SingletonHandle singleton) { + return singleton_handles_[singleton] != kInvalidIndex; + } + + // Assign a SingletonHandle to an empty slot and returns the handle. + Handle<Object> CreateSingleton(Isolate* isolate, + Object* object, + SingletonHandle singleton) { + Create(isolate, object, &singleton_handles_[singleton]); + return Get(singleton_handles_[singleton]); + } + + // Iterates over all handles. + void IterateAllRoots(ObjectVisitor* visitor); + // Iterates over all handles which might be in new space. + void IterateNewSpaceRoots(ObjectVisitor* visitor); + // Rebuilds new space list. + void PostGarbageCollectionProcessing(Heap* heap); + + private: + static const int kInvalidIndex = -1; + static const int kShift = 8; + static const int kSize = 1 << kShift; + static const int kMask = 0xff; + + // Gets the slot for an index + inline Object** GetLocation(int index) { + ASSERT(index >= 0 && index < size_); + return &blocks_[index >> kShift][index & kMask]; + } + + int size_; + List<Object**> blocks_; + List<int> new_space_indices_; + int singleton_handles_[NUMBER_OF_SINGLETON_HANDLES]; + + DISALLOW_COPY_AND_ASSIGN(EternalHandles); +}; + + } } // namespace v8::internal #endif // V8_GLOBAL_HANDLES_H_ |