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

Side by Side Diff: src/handles.h

Issue 18842: Experimental: periodic merge of the bleeding_edge branch to the... (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/toiger/
Patch Set: Created 11 years, 11 months 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 | Annotate | Revision Log
« no previous file with comments | « src/frames.h ('k') | src/handles.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 10 matching lines...) Expand all
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #ifndef V8_HANDLES_H_ 28 #ifndef V8_HANDLES_H_
29 #define V8_HANDLES_H_ 29 #define V8_HANDLES_H_
30 30
31 #include "apiutils.h"
32
31 namespace v8 { namespace internal { 33 namespace v8 { namespace internal {
32 34
33 // ---------------------------------------------------------------------------- 35 // ----------------------------------------------------------------------------
34 // A Handle provides a reference to an object that survives relocation by 36 // A Handle provides a reference to an object that survives relocation by
35 // the garbage collector. 37 // the garbage collector.
36 // Handles are only valid withing a HandleScope. 38 // Handles are only valid within a HandleScope.
37 // When a handle is created for an object a cell is allocated in the heap. 39 // When a handle is created for an object a cell is allocated in the heap.
38 40
39 template<class T> 41 template<class T>
40 class Handle { 42 class Handle {
41 public: 43 public:
42 INLINE(Handle(T** location)) { location_ = location; } 44 INLINE(Handle(T** location)) { location_ = location; }
43 INLINE(explicit Handle(T* obj)); 45 INLINE(explicit Handle(T* obj));
44 46
45 INLINE(Handle()) : location_(NULL) {} 47 INLINE(Handle()) : location_(NULL) {}
46 48
(...skipping 29 matching lines...) Expand all
76 template <class S> static Handle<T> cast(Handle<S> that) { 78 template <class S> static Handle<T> cast(Handle<S> that) {
77 T::cast(*that); 79 T::cast(*that);
78 return Handle<T>(reinterpret_cast<T**>(that.location())); 80 return Handle<T>(reinterpret_cast<T**>(that.location()));
79 } 81 }
80 82
81 static Handle<T> null() { return Handle<T>(); } 83 static Handle<T> null() { return Handle<T>(); }
82 bool is_null() {return location_ == NULL; } 84 bool is_null() {return location_ == NULL; }
83 85
84 // Closes the given scope, but lets this handle escape. See 86 // Closes the given scope, but lets this handle escape. See
85 // implementation in api.h. 87 // implementation in api.h.
86 inline Handle<T> EscapeFrom(HandleScope* scope); 88 inline Handle<T> EscapeFrom(v8::HandleScope* scope);
87 89
88 private: 90 private:
89 T** location_; 91 T** location_;
90 }; 92 };
91 93
92 94
95 // A stack-allocated class that governs a number of local handles.
96 // After a handle scope has been created, all local handles will be
97 // allocated within that handle scope until either the handle scope is
98 // deleted or another handle scope is created. If there is already a
99 // handle scope and a new one is created, all allocations will take
100 // place in the new handle scope until it is deleted. After that,
101 // new handles will again be allocated in the original handle scope.
102 //
103 // After the handle scope of a local handle has been deleted the
104 // garbage collector will no longer track the object stored in the
105 // handle and may deallocate it. The behavior of accessing a handle
106 // for which the handle scope has been deleted is undefined.
107 class HandleScope {
108 public:
109 HandleScope() : previous_(current_) {
110 current_.extensions = 0;
111 }
112
113 ~HandleScope() {
114 Leave(&previous_);
115 }
116
117 // Counts the number of allocated handles.
118 static int NumberOfHandles();
119
120 // Creates a new handle with the given value.
121 static void** CreateHandle(void* value);
122
123 private:
124 // Prevent heap allocation or illegal handle scopes.
125 HandleScope(const HandleScope&);
126 void operator=(const HandleScope&);
127 void* operator new(size_t size);
128 void operator delete(void* size_t);
129
130 static v8::ImplementationUtilities::HandleScopeData current_;
131 const v8::ImplementationUtilities::HandleScopeData previous_;
132
133 // Pushes a fresh handle scope to be used when allocating new handles.
134 static void Enter(
135 v8::ImplementationUtilities::HandleScopeData* previous) {
136 *previous = current_;
137 current_.extensions = 0;
138 }
139
140 // Re-establishes the previous scope state. Should be called only
141 // once, and only for the current scope.
142 static void Leave(
143 const v8::ImplementationUtilities::HandleScopeData* previous) {
144 if (current_.extensions > 0) {
145 DeleteExtensions();
146 }
147 current_ = *previous;
148 #ifdef DEBUG
149 ZapRange(current_.next, current_.limit);
150 #endif
151 }
152
153 // Deallocates any extensions used by the current scope.
154 static void DeleteExtensions();
155
156 // Zaps the handles in the half-open interval [start, end).
157 static void ZapRange(void** start, void** end);
158
159 friend class v8::HandleScope;
160 friend class v8::ImplementationUtilities;
161 };
162
163
93 // ---------------------------------------------------------------------------- 164 // ----------------------------------------------------------------------------
94 // Handle operations. 165 // Handle operations.
95 // They might invoke garbage collection. The result is an handle to 166 // They might invoke garbage collection. The result is an handle to
96 // an object of expected type, or the handle is an error if running out 167 // an object of expected type, or the handle is an error if running out
97 // of space or encounting an internal error. 168 // of space or encountering an internal error.
98 169
99 void NormalizeProperties(Handle<JSObject> object, 170 void NormalizeProperties(Handle<JSObject> object,
100 PropertyNormalizationMode mode); 171 PropertyNormalizationMode mode);
101 void NormalizeElements(Handle<JSObject> object); 172 void NormalizeElements(Handle<JSObject> object);
102 void TransformToFastProperties(Handle<JSObject> object, 173 void TransformToFastProperties(Handle<JSObject> object,
103 int unused_property_fields); 174 int unused_property_fields);
104 void FlattenString(Handle<String> str); 175 void FlattenString(Handle<String> str);
105 176
106 Handle<Object> SetProperty(Handle<JSObject> object, 177 Handle<Object> SetProperty(Handle<JSObject> object,
107 Handle<String> key, 178 Handle<String> key,
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 private: 308 private:
238 bool has_been_transformed_; // Tells whether the object has been transformed. 309 bool has_been_transformed_; // Tells whether the object has been transformed.
239 int unused_property_fields_; // Captures the unused number of field. 310 int unused_property_fields_; // Captures the unused number of field.
240 Handle<JSObject> object_; // The object being optimized. 311 Handle<JSObject> object_; // The object being optimized.
241 }; 312 };
242 313
243 314
244 } } // namespace v8::internal 315 } } // namespace v8::internal
245 316
246 #endif // V8_HANDLES_H_ 317 #endif // V8_HANDLES_H_
OLDNEW
« no previous file with comments | « src/frames.h ('k') | src/handles.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698