Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(337)

Side by Side Diff: src/global-handles.h

Issue 753553002: Phantom references support internal fields (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Don't forget to visit pointers to live objects so they can be updated to new location Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_GLOBAL_HANDLES_H_ 5 #ifndef V8_GLOBAL_HANDLES_H_
6 #define V8_GLOBAL_HANDLES_H_ 6 #define V8_GLOBAL_HANDLES_H_
7 7
8 #include "include/v8.h" 8 #include "include/v8.h"
9 #include "include/v8-profiler.h" 9 #include "include/v8-profiler.h"
10 10
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 // Creates a new global handle that is alive until Destroy is called. 104 // Creates a new global handle that is alive until Destroy is called.
105 Handle<Object> Create(Object* value); 105 Handle<Object> Create(Object* value);
106 106
107 // Copy a global handle 107 // Copy a global handle
108 static Handle<Object> CopyGlobal(Object** location); 108 static Handle<Object> CopyGlobal(Object** location);
109 109
110 // Destroy a global handle. 110 // Destroy a global handle.
111 static void Destroy(Object** location); 111 static void Destroy(Object** location);
112 112
113 typedef WeakCallbackData<v8::Value, void>::Callback WeakCallback; 113 typedef WeakCallbackData<v8::Value, void>::Callback WeakCallback;
114 typedef PhantomCallbackData<void>::Callback PhantomCallback;
114 115
115 // For a phantom weak reference, the callback does not have access to the 116 // For a phantom weak reference, the callback does not have access to the
116 // dying object. Phantom weak references are preferred because they allow 117 // dying object. Phantom weak references are preferred because they allow
117 // memory to be reclaimed in one GC cycle rather than two. However, for 118 // memory to be reclaimed in one GC cycle rather than two. However, for
118 // historical reasons the default is non-phantom. 119 // historical reasons the default is non-phantom.
119 enum PhantomState { Nonphantom, Phantom }; 120 enum PhantomState { Nonphantom, Phantom };
120 121
121 // Make the global handle weak and set the callback parameter for the 122 // Make the global handle weak and set the callback parameter for the
122 // handle. When the garbage collector recognizes that only weak global 123 // handle. When the garbage collector recognizes that only weak global
123 // handles point to an object the callback function is invoked (for each 124 // handles point to an object the callback function is invoked (for each
124 // handle) with the handle and corresponding parameter as arguments. By 125 // handle) with the handle and corresponding parameter as arguments. By
125 // default the handle still contains a pointer to the object that is being 126 // default the handle still contains a pointer to the object that is being
126 // collected. For this reason the object is not collected until the next 127 // collected. For this reason the object is not collected until the next
127 // GC. For a phantom weak handle the handle is cleared (set to a Smi) 128 // GC. For a phantom weak handle the handle is cleared (set to a Smi)
128 // before the callback is invoked, but the handle can still be identified 129 // before the callback is invoked, but the handle can still be identified
129 // in the callback by using the location() of the handle. 130 // in the callback by using the location() of the handle.
130 static void MakeWeak(Object** location, void* parameter, 131 static void MakeWeak(
131 WeakCallback weak_callback, 132 Object** location, void* parameter, WeakCallback weak_callback);
132 PhantomState phantom = Nonphantom); 133
134 static void MakePhantom(
135 Object** location, void* parameter,
136 PhantomCallback weak_callback,
137 int internal_field_index1 = v8::Object::kNoInternalFieldIndex,
138 int internal_field_index2 = v8::Object::kNoInternalFieldIndex);
133 139
134 void RecordStats(HeapStats* stats); 140 void RecordStats(HeapStats* stats);
135 141
136 // Returns the current number of weak handles. 142 // Returns the current number of weak handles.
137 int NumberOfWeakHandles(); 143 int NumberOfWeakHandles();
138 144
139 // Returns the current number of weak handles to global objects. 145 // Returns the current number of weak handles to global objects.
140 // These handles are also included in NumberOfWeakHandles(). 146 // These handles are also included in NumberOfWeakHandles().
141 int NumberOfGlobalObjectWeakHandles(); 147 int NumberOfGlobalObjectWeakHandles();
142 148
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 List<int> new_space_indices_; 384 List<int> new_space_indices_;
379 int singleton_handles_[NUMBER_OF_SINGLETON_HANDLES]; 385 int singleton_handles_[NUMBER_OF_SINGLETON_HANDLES];
380 386
381 DISALLOW_COPY_AND_ASSIGN(EternalHandles); 387 DISALLOW_COPY_AND_ASSIGN(EternalHandles);
382 }; 388 };
383 389
384 390
385 } } // namespace v8::internal 391 } } // namespace v8::internal
386 392
387 #endif // V8_GLOBAL_HANDLES_H_ 393 #endif // V8_GLOBAL_HANDLES_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698