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

Side by Side Diff: src/handles.h

Issue 3792003: Optimizing HandleScope. Also fixed HandleScope destruction when API getter th... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 years, 2 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/assembler.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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 // handle scope and a new one is created, all allocations will take 100 // handle scope and a new one is created, all allocations will take
101 // place in the new handle scope until it is deleted. After that, 101 // place in the new handle scope until it is deleted. After that,
102 // new handles will again be allocated in the original handle scope. 102 // new handles will again be allocated in the original handle scope.
103 // 103 //
104 // After the handle scope of a local handle has been deleted the 104 // After the handle scope of a local handle has been deleted the
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() : previous_(current_) { 110 HandleScope() : prev_next_(current_.next), prev_limit_(current_.limit) {
111 current_.extensions = 0; 111 current_.level++;
112 } 112 }
113 113
114 ~HandleScope() { 114 ~HandleScope() {
115 Leave(&previous_); 115 current_.next = prev_next_;
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
116 } 124 }
117 125
118 // Counts the number of allocated handles. 126 // Counts the number of allocated handles.
119 static int NumberOfHandles(); 127 static int NumberOfHandles();
120 128
121 // Creates a new handle with the given value. 129 // Creates a new handle with the given value.
122 template <typename T> 130 template <typename T>
123 static inline T** CreateHandle(T* value) { 131 static inline T** CreateHandle(T* value) {
124 internal::Object** cur = current_.next; 132 internal::Object** cur = current_.next;
125 if (cur == current_.limit) cur = Extend(); 133 if (cur == current_.limit) cur = Extend();
126 // Update the current next field, set the value in the created 134 // Update the current next field, set the value in the created
127 // handle, and return the result. 135 // handle, and return the result.
128 ASSERT(cur < current_.limit); 136 ASSERT(cur < current_.limit);
129 current_.next = cur + 1; 137 current_.next = cur + 1;
130 138
131 T** result = reinterpret_cast<T**>(cur); 139 T** result = reinterpret_cast<T**>(cur);
132 *result = value; 140 *result = value;
133 return result; 141 return result;
134 } 142 }
135 143
136 // Deallocates any extensions used by the current scope. 144 // Deallocates any extensions used by the current scope.
137 static void DeleteExtensions(); 145 static void DeleteExtensions();
138 146
139 static Address current_extensions_address();
140 static Address current_next_address(); 147 static Address current_next_address();
141 static Address current_limit_address(); 148 static Address current_limit_address();
149 static Address current_level_address();
142 150
143 private: 151 private:
144 // Prevent heap allocation or illegal handle scopes. 152 // Prevent heap allocation or illegal handle scopes.
145 HandleScope(const HandleScope&); 153 HandleScope(const HandleScope&);
146 void operator=(const HandleScope&); 154 void operator=(const HandleScope&);
147 void* operator new(size_t size); 155 void* operator new(size_t size);
148 void operator delete(void* size_t); 156 void operator delete(void* size_t);
149 157
150 static v8::ImplementationUtilities::HandleScopeData current_; 158 static v8::ImplementationUtilities::HandleScopeData current_;
151 const v8::ImplementationUtilities::HandleScopeData previous_; 159 Object** const prev_next_;
152 160 Object** const prev_limit_;
153 // Pushes a fresh handle scope to be used when allocating new handles.
154 static void Enter(
155 v8::ImplementationUtilities::HandleScopeData* previous) {
156 *previous = current_;
157 current_.extensions = 0;
158 }
159
160 // Re-establishes the previous scope state. Should be called only
161 // once, and only for the current scope.
162 static void Leave(
163 const v8::ImplementationUtilities::HandleScopeData* previous) {
164 if (current_.extensions > 0) {
165 DeleteExtensions();
166 }
167 current_ = *previous;
168 #ifdef DEBUG
169 ZapRange(current_.next, current_.limit);
170 #endif
171 }
172 161
173 // Extend the handle scope making room for more handles. 162 // Extend the handle scope making room for more handles.
174 static internal::Object** Extend(); 163 static internal::Object** Extend();
175 164
176 // Zaps the handles in the half-open interval [start, end). 165 // Zaps the handles in the half-open interval [start, end).
177 static void ZapRange(internal::Object** start, internal::Object** end); 166 static void ZapRange(internal::Object** start, internal::Object** end);
178 167
179 friend class v8::HandleScope; 168 friend class v8::HandleScope;
180 friend class v8::ImplementationUtilities; 169 friend class v8::ImplementationUtilities;
181 }; 170 };
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 344
356 class NoHandleAllocation BASE_EMBEDDED { 345 class NoHandleAllocation BASE_EMBEDDED {
357 public: 346 public:
358 #ifndef DEBUG 347 #ifndef DEBUG
359 NoHandleAllocation() {} 348 NoHandleAllocation() {}
360 ~NoHandleAllocation() {} 349 ~NoHandleAllocation() {}
361 #else 350 #else
362 inline NoHandleAllocation(); 351 inline NoHandleAllocation();
363 inline ~NoHandleAllocation(); 352 inline ~NoHandleAllocation();
364 private: 353 private:
365 int extensions_; 354 int level_;
366 #endif 355 #endif
367 }; 356 };
368 357
369 358
370 // ---------------------------------------------------------------------------- 359 // ----------------------------------------------------------------------------
371 360
372 361
373 // Stack allocated wrapper call for optimizing adding multiple 362 // Stack allocated wrapper call for optimizing adding multiple
374 // properties to an object. 363 // properties to an object.
375 class OptimizedObjectForAddingMultipleProperties BASE_EMBEDDED { 364 class OptimizedObjectForAddingMultipleProperties BASE_EMBEDDED {
376 public: 365 public:
377 OptimizedObjectForAddingMultipleProperties(Handle<JSObject> object, 366 OptimizedObjectForAddingMultipleProperties(Handle<JSObject> object,
378 int expected_property_count, 367 int expected_property_count,
379 bool condition = true); 368 bool condition = true);
380 ~OptimizedObjectForAddingMultipleProperties(); 369 ~OptimizedObjectForAddingMultipleProperties();
381 private: 370 private:
382 bool has_been_transformed_; // Tells whether the object has been transformed. 371 bool has_been_transformed_; // Tells whether the object has been transformed.
383 int unused_property_fields_; // Captures the unused number of field. 372 int unused_property_fields_; // Captures the unused number of field.
384 Handle<JSObject> object_; // The object being optimized. 373 Handle<JSObject> object_; // The object being optimized.
385 }; 374 };
386 375
387 376
388 } } // namespace v8::internal 377 } } // namespace v8::internal
389 378
390 #endif // V8_HANDLES_H_ 379 #endif // V8_HANDLES_H_
OLDNEW
« no previous file with comments | « src/assembler.cc ('k') | src/handles.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698