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

Side by Side Diff: src/handles.h

Issue 6697023: Merge 6800:7180 from the bleeding edge branch to the experimental/gc branch. (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/gc/
Patch Set: Created 9 years, 9 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/global-handles.cc ('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 21 matching lines...) Expand all
32 32
33 namespace v8 { 33 namespace v8 {
34 namespace internal { 34 namespace internal {
35 35
36 // ---------------------------------------------------------------------------- 36 // ----------------------------------------------------------------------------
37 // A Handle provides a reference to an object that survives relocation by 37 // A Handle provides a reference to an object that survives relocation by
38 // the garbage collector. 38 // the garbage collector.
39 // Handles are only valid within a HandleScope. 39 // Handles are only valid within a HandleScope.
40 // When a handle is created for an object a cell is allocated in the heap. 40 // When a handle is created for an object a cell is allocated in the heap.
41 41
42 template<class T> 42 template<typename T>
43 class Handle { 43 class Handle {
44 public: 44 public:
45 INLINE(explicit Handle(T** location)) { location_ = location; } 45 INLINE(explicit Handle(T** location)) { location_ = location; }
46 INLINE(explicit Handle(T* obj)); 46 INLINE(explicit Handle(T* obj));
47 47
48 INLINE(Handle()) : location_(NULL) {} 48 INLINE(Handle()) : location_(NULL) {}
49 49
50 // Constructor for handling automatic up casting. 50 // Constructor for handling automatic up casting.
51 // Ex. Handle<JSFunction> can be passed when Handle<Object> is expected. 51 // Ex. Handle<JSFunction> can be passed when Handle<Object> is expected.
52 template <class S> Handle(Handle<S> handle) { 52 template <class S> Handle(Handle<S> handle) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 // garbage collector will no longer track the object stored in the 105 // garbage collector will no longer track the object stored in the
106 // handle and may deallocate it. The behavior of accessing a handle 106 // handle and may deallocate it. The behavior of accessing a handle
107 // for which the handle scope has been deleted is undefined. 107 // for which the handle scope has been deleted is undefined.
108 class HandleScope { 108 class HandleScope {
109 public: 109 public:
110 HandleScope() : prev_next_(current_.next), prev_limit_(current_.limit) { 110 HandleScope() : prev_next_(current_.next), prev_limit_(current_.limit) {
111 current_.level++; 111 current_.level++;
112 } 112 }
113 113
114 ~HandleScope() { 114 ~HandleScope() {
115 current_.next = prev_next_; 115 CloseScope();
116 current_.level--;
117 if (current_.limit != prev_limit_) {
118 current_.limit = prev_limit_;
119 DeleteExtensions();
120 }
121 #ifdef DEBUG
122 ZapRange(prev_next_, prev_limit_);
123 #endif
124 } 116 }
125 117
126 // Counts the number of allocated handles. 118 // Counts the number of allocated handles.
127 static int NumberOfHandles(); 119 static int NumberOfHandles();
128 120
129 // Creates a new handle with the given value. 121 // Creates a new handle with the given value.
130 template <typename T> 122 template <typename T>
131 static inline T** CreateHandle(T* value) { 123 static inline T** CreateHandle(T* value) {
132 internal::Object** cur = current_.next; 124 internal::Object** cur = current_.next;
133 if (cur == current_.limit) cur = Extend(); 125 if (cur == current_.limit) cur = Extend();
134 // Update the current next field, set the value in the created 126 // Update the current next field, set the value in the created
135 // handle, and return the result. 127 // handle, and return the result.
136 ASSERT(cur < current_.limit); 128 ASSERT(cur < current_.limit);
137 current_.next = cur + 1; 129 current_.next = cur + 1;
138 130
139 T** result = reinterpret_cast<T**>(cur); 131 T** result = reinterpret_cast<T**>(cur);
140 *result = value; 132 *result = value;
141 return result; 133 return result;
142 } 134 }
143 135
144 // Deallocates any extensions used by the current scope. 136 // Deallocates any extensions used by the current scope.
145 static void DeleteExtensions(); 137 static void DeleteExtensions();
146 138
147 static Address current_next_address(); 139 static Address current_next_address();
148 static Address current_limit_address(); 140 static Address current_limit_address();
149 static Address current_level_address(); 141 static Address current_level_address();
150 142
143 // Closes the HandleScope (invalidating all handles
144 // created in the scope of the HandleScope) and returns
145 // a Handle backed by the parent scope holding the
146 // value of the argument handle.
147 template <typename T>
148 Handle<T> CloseAndEscape(Handle<T> handle_value) {
149 T* value = *handle_value;
150 // Throw away all handles in the current scope.
151 CloseScope();
152 // Allocate one handle in the parent scope.
153 ASSERT(current_.level > 0);
154 Handle<T> result(CreateHandle<T>(value));
155 // Reinitialize the current scope (so that it's ready
156 // to be used or closed again).
157 prev_next_ = current_.next;
158 prev_limit_ = current_.limit;
159 current_.level++;
160 return result;
161 }
162
151 private: 163 private:
152 // Prevent heap allocation or illegal handle scopes. 164 // Prevent heap allocation or illegal handle scopes.
153 HandleScope(const HandleScope&); 165 HandleScope(const HandleScope&);
154 void operator=(const HandleScope&); 166 void operator=(const HandleScope&);
155 void* operator new(size_t size); 167 void* operator new(size_t size);
156 void operator delete(void* size_t); 168 void operator delete(void* size_t);
157 169
170 inline void CloseScope() {
171 current_.next = prev_next_;
172 current_.level--;
173 if (current_.limit != prev_limit_) {
174 current_.limit = prev_limit_;
175 DeleteExtensions();
176 }
177 #ifdef DEBUG
178 ZapRange(prev_next_, prev_limit_);
179 #endif
180 }
181
158 static v8::ImplementationUtilities::HandleScopeData current_; 182 static v8::ImplementationUtilities::HandleScopeData current_;
159 Object** const prev_next_; 183 // Holds values on entry. The prev_next_ value is never NULL
160 Object** const prev_limit_; 184 // on_entry, but is set to NULL when this scope is closed.
185 Object** prev_next_;
186 Object** prev_limit_;
161 187
162 // Extend the handle scope making room for more handles. 188 // Extend the handle scope making room for more handles.
163 static internal::Object** Extend(); 189 static internal::Object** Extend();
164 190
165 // Zaps the handles in the half-open interval [start, end). 191 // Zaps the handles in the half-open interval [start, end).
166 static void ZapRange(internal::Object** start, internal::Object** end); 192 static void ZapRange(internal::Object** start, internal::Object** end);
167 193
168 friend class v8::HandleScope; 194 friend class v8::HandleScope;
169 friend class v8::ImplementationUtilities; 195 friend class v8::ImplementationUtilities;
170 }; 196 };
(...skipping 19 matching lines...) Expand all
190 // Flattens a string. 216 // Flattens a string.
191 void FlattenString(Handle<String> str); 217 void FlattenString(Handle<String> str);
192 218
193 // Flattens a string and returns the underlying external or sequential 219 // Flattens a string and returns the underlying external or sequential
194 // string. 220 // string.
195 Handle<String> FlattenGetString(Handle<String> str); 221 Handle<String> FlattenGetString(Handle<String> str);
196 222
197 Handle<Object> SetProperty(Handle<JSObject> object, 223 Handle<Object> SetProperty(Handle<JSObject> object,
198 Handle<String> key, 224 Handle<String> key,
199 Handle<Object> value, 225 Handle<Object> value,
200 PropertyAttributes attributes); 226 PropertyAttributes attributes,
227 StrictModeFlag strict_mode);
201 228
202 Handle<Object> SetProperty(Handle<Object> object, 229 Handle<Object> SetProperty(Handle<Object> object,
203 Handle<Object> key, 230 Handle<Object> key,
204 Handle<Object> value, 231 Handle<Object> value,
205 PropertyAttributes attributes); 232 PropertyAttributes attributes,
233 StrictModeFlag strict_mode);
206 234
207 Handle<Object> ForceSetProperty(Handle<JSObject> object, 235 Handle<Object> ForceSetProperty(Handle<JSObject> object,
208 Handle<Object> key, 236 Handle<Object> key,
209 Handle<Object> value, 237 Handle<Object> value,
210 PropertyAttributes attributes); 238 PropertyAttributes attributes);
211 239
212 Handle<Object> SetNormalizedProperty(Handle<JSObject> object, 240 Handle<Object> SetNormalizedProperty(Handle<JSObject> object,
213 Handle<String> key, 241 Handle<String> key,
214 Handle<Object> value, 242 Handle<Object> value,
215 PropertyDetails details); 243 PropertyDetails details);
(...skipping 10 matching lines...) Expand all
226 // Used to set local properties on the object we totally control 254 // Used to set local properties on the object we totally control
227 // and which therefore has no accessors and alikes. 255 // and which therefore has no accessors and alikes.
228 void SetLocalPropertyNoThrow(Handle<JSObject> object, 256 void SetLocalPropertyNoThrow(Handle<JSObject> object,
229 Handle<String> key, 257 Handle<String> key,
230 Handle<Object> value, 258 Handle<Object> value,
231 PropertyAttributes attributes = NONE); 259 PropertyAttributes attributes = NONE);
232 260
233 Handle<Object> SetPropertyWithInterceptor(Handle<JSObject> object, 261 Handle<Object> SetPropertyWithInterceptor(Handle<JSObject> object,
234 Handle<String> key, 262 Handle<String> key,
235 Handle<Object> value, 263 Handle<Object> value,
236 PropertyAttributes attributes); 264 PropertyAttributes attributes,
265 StrictModeFlag strict_mode);
237 266
238 Handle<Object> SetElement(Handle<JSObject> object, 267 MUST_USE_RESULT Handle<Object> SetElement(Handle<JSObject> object,
239 uint32_t index, 268 uint32_t index,
240 Handle<Object> value); 269 Handle<Object> value,
270 StrictModeFlag strict_mode);
241 271
242 Handle<Object> SetOwnElement(Handle<JSObject> object, 272 Handle<Object> SetOwnElement(Handle<JSObject> object,
243 uint32_t index, 273 uint32_t index,
244 Handle<Object> value); 274 Handle<Object> value,
275 StrictModeFlag strict_mode);
245 276
246 Handle<Object> GetProperty(Handle<JSObject> obj, 277 Handle<Object> GetProperty(Handle<JSObject> obj,
247 const char* name); 278 const char* name);
248 279
249 Handle<Object> GetProperty(Handle<Object> obj, 280 Handle<Object> GetProperty(Handle<Object> obj,
250 Handle<Object> key); 281 Handle<Object> key);
251 282
252 Handle<Object> GetElement(Handle<Object> obj, 283 Handle<Object> GetElement(Handle<Object> obj,
253 uint32_t index); 284 uint32_t index);
254 285
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 bool EnsureCompiled(Handle<SharedFunctionInfo> shared, 378 bool EnsureCompiled(Handle<SharedFunctionInfo> shared,
348 ClearExceptionFlag flag); 379 ClearExceptionFlag flag);
349 380
350 bool CompileLazyShared(Handle<SharedFunctionInfo> shared, 381 bool CompileLazyShared(Handle<SharedFunctionInfo> shared,
351 ClearExceptionFlag flag); 382 ClearExceptionFlag flag);
352 383
353 bool CompileLazy(Handle<JSFunction> function, ClearExceptionFlag flag); 384 bool CompileLazy(Handle<JSFunction> function, ClearExceptionFlag flag);
354 385
355 bool CompileLazyInLoop(Handle<JSFunction> function, ClearExceptionFlag flag); 386 bool CompileLazyInLoop(Handle<JSFunction> function, ClearExceptionFlag flag);
356 387
357 bool CompileOptimized(Handle<JSFunction> function, int osr_ast_id); 388 bool CompileOptimized(Handle<JSFunction> function,
389 int osr_ast_id,
390 ClearExceptionFlag flag);
358 391
359 class NoHandleAllocation BASE_EMBEDDED { 392 class NoHandleAllocation BASE_EMBEDDED {
360 public: 393 public:
361 #ifndef DEBUG 394 #ifndef DEBUG
362 NoHandleAllocation() {} 395 NoHandleAllocation() {}
363 ~NoHandleAllocation() {} 396 ~NoHandleAllocation() {}
364 #else 397 #else
365 inline NoHandleAllocation(); 398 inline NoHandleAllocation();
366 inline ~NoHandleAllocation(); 399 inline ~NoHandleAllocation();
367 private: 400 private:
(...skipping 16 matching lines...) Expand all
384 private: 417 private:
385 bool has_been_transformed_; // Tells whether the object has been transformed. 418 bool has_been_transformed_; // Tells whether the object has been transformed.
386 int unused_property_fields_; // Captures the unused number of field. 419 int unused_property_fields_; // Captures the unused number of field.
387 Handle<JSObject> object_; // The object being optimized. 420 Handle<JSObject> object_; // The object being optimized.
388 }; 421 };
389 422
390 423
391 } } // namespace v8::internal 424 } } // namespace v8::internal
392 425
393 #endif // V8_HANDLES_H_ 426 #endif // V8_HANDLES_H_
OLDNEW
« no previous file with comments | « src/global-handles.cc ('k') | src/handles.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698