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

Side by Side Diff: vm/dart_api_state.h

Issue 11879005: Added code to trace zone and handles creation/deletion under flags (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 7 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 | « no previous file | vm/handles.h » ('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 (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #ifndef VM_DART_API_STATE_H_ 5 #ifndef VM_DART_API_STATE_H_
6 #define VM_DART_API_STATE_H_ 6 #define VM_DART_API_STATE_H_
7 7
8 #include "include/dart_api.h" 8 #include "include/dart_api.h"
9 9
10 #include "platform/thread.h" 10 #include "platform/thread.h"
11 #include "vm/dart_api_impl.h" 11 #include "vm/dart_api_impl.h"
12 #include "vm/flags.h" 12 #include "vm/flags.h"
13 #include "vm/growable_array.h" 13 #include "vm/growable_array.h"
14 #include "vm/handles.h" 14 #include "vm/handles.h"
15 #include "vm/object.h" 15 #include "vm/object.h"
16 #include "vm/os.h" 16 #include "vm/os.h"
17 #include "vm/raw_object.h" 17 #include "vm/raw_object.h"
18 #include "vm/visitor.h" 18 #include "vm/visitor.h"
19 19
20 #include "vm/handles_impl.h" 20 #include "vm/handles_impl.h"
21 21
22 namespace dart { 22 namespace dart {
23 23
24 DECLARE_DEBUG_FLAG(bool, trace_zones);
25 DECLARE_DEBUG_FLAG(bool, trace_handles);
26
24 // Implementation of Zone support for very fast allocation of small chunks 27 // Implementation of Zone support for very fast allocation of small chunks
25 // of memory. The chunks cannot be deallocated individually, but instead 28 // of memory. The chunks cannot be deallocated individually, but instead
26 // zones support deallocating all chunks in one fast operation when the 29 // zones support deallocating all chunks in one fast operation when the
27 // scope is exited. 30 // scope is exited.
28 class ApiZone { 31 class ApiZone {
29 public: 32 public:
30 // Create an empty zone. 33 // Create an empty zone.
31 ApiZone() : zone_() { 34 ApiZone() : zone_() {
32 Isolate* isolate = Isolate::Current(); 35 Isolate* isolate = Isolate::Current();
33 Zone* current_zone = isolate != NULL ? isolate->current_zone() : NULL; 36 Zone* current_zone = isolate != NULL ? isolate->current_zone() : NULL;
34 zone_.Link(current_zone); 37 zone_.Link(current_zone);
35 if (isolate != NULL) { 38 if (isolate != NULL) {
36 isolate->set_current_zone(&zone_); 39 isolate->set_current_zone(&zone_);
37 } 40 }
41 #ifdef DEBUG
42 if (FLAG_trace_zones) {
43 OS::PrintErr("*** Starting a new Api zone 0x%"Px"(0x%"Px")\n",
44 reinterpret_cast<intptr_t>(this),
45 reinterpret_cast<intptr_t>(&zone_));
46 }
47 #endif
38 } 48 }
39 49
40 // Delete all memory associated with the zone. 50 // Delete all memory associated with the zone.
41 ~ApiZone() { 51 ~ApiZone() {
42 Isolate* isolate = Isolate::Current(); 52 Isolate* isolate = Isolate::Current();
43 if (isolate != NULL && isolate->current_zone() == &zone_) { 53 if (isolate != NULL && isolate->current_zone() == &zone_) {
44 isolate->set_current_zone(zone_.previous_); 54 isolate->set_current_zone(zone_.previous_);
45 } 55 }
56 #ifdef DEBUG
57 if (FLAG_trace_zones) {
58 OS::PrintErr("*** Deleting Api zone 0x%"Px"(0x%"Px")\n",
59 reinterpret_cast<intptr_t>(this),
60 reinterpret_cast<intptr_t>(&zone_));
61 }
62 #endif
46 } 63 }
47 64
48 // Allocates an array sized to hold 'len' elements of type 65 // Allocates an array sized to hold 'len' elements of type
49 // 'ElementType'. Checks for integer overflow when performing the 66 // 'ElementType'. Checks for integer overflow when performing the
50 // size computation. 67 // size computation.
51 template <class ElementType> 68 template <class ElementType>
52 ElementType* Alloc(intptr_t len) { return zone_.Alloc<ElementType>(len); } 69 ElementType* Alloc(intptr_t len) { return zone_.Alloc<ElementType>(len); }
53 70
54 // Allocates an array sized to hold 'len' elements of type 71 // Allocates an array sized to hold 'len' elements of type
55 // 'ElementType'. The new array is initialized from the memory of 72 // 'ElementType'. The new array is initialized from the memory of
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 // Local handles repository structure. 230 // Local handles repository structure.
214 static const int kLocalHandleSizeInWords = sizeof(LocalHandle) / kWordSize; 231 static const int kLocalHandleSizeInWords = sizeof(LocalHandle) / kWordSize;
215 static const int kLocalHandlesPerChunk = 64; 232 static const int kLocalHandlesPerChunk = 64;
216 static const int kOffsetOfRawPtrInLocalHandle = 0; 233 static const int kOffsetOfRawPtrInLocalHandle = 0;
217 class LocalHandles : Handles<kLocalHandleSizeInWords, 234 class LocalHandles : Handles<kLocalHandleSizeInWords,
218 kLocalHandlesPerChunk, 235 kLocalHandlesPerChunk,
219 kOffsetOfRawPtrInLocalHandle> { 236 kOffsetOfRawPtrInLocalHandle> {
220 public: 237 public:
221 LocalHandles() : Handles<kLocalHandleSizeInWords, 238 LocalHandles() : Handles<kLocalHandleSizeInWords,
222 kLocalHandlesPerChunk, 239 kLocalHandlesPerChunk,
223 kOffsetOfRawPtrInLocalHandle>() { } 240 kOffsetOfRawPtrInLocalHandle>() {
224 ~LocalHandles() { } 241 #ifdef DEBUG
242 if (FLAG_trace_handles) {
243 OS::PrintErr("*** Starting a new Local handle block 0x%"Px"\n",
244 reinterpret_cast<intptr_t>(this));
245 }
246 #endif
247 }
248 ~LocalHandles() {
249 #ifdef DEBUG
250 if (FLAG_trace_handles) {
251 OS::PrintErr("*** Handle Counts for 0x(%"Px"):Scoped = %d\n",
252 reinterpret_cast<intptr_t>(this),
253 CountHandles());
254 OS::PrintErr("*** Deleting Local handle block 0x%"Px"\n",
255 reinterpret_cast<intptr_t>(this));
256 }
257 #endif
258 }
225 259
226 260
227 // Visit all object pointers stored in the various handles. 261 // Visit all object pointers stored in the various handles.
228 void VisitObjectPointers(ObjectPointerVisitor* visitor) { 262 void VisitObjectPointers(ObjectPointerVisitor* visitor) {
229 Handles<kLocalHandleSizeInWords, 263 Handles<kLocalHandleSizeInWords,
230 kLocalHandlesPerChunk, 264 kLocalHandlesPerChunk,
231 kOffsetOfRawPtrInLocalHandle>::VisitObjectPointers(visitor); 265 kOffsetOfRawPtrInLocalHandle>::VisitObjectPointers(visitor);
232 } 266 }
233 267
234 // Allocates a handle in the current handle scope. This handle is valid only 268 // Allocates a handle in the current handle scope. This handle is valid only
(...skipping 23 matching lines...) Expand all
258 sizeof(PersistentHandle) / kWordSize; 292 sizeof(PersistentHandle) / kWordSize;
259 static const int kPersistentHandlesPerChunk = 64; 293 static const int kPersistentHandlesPerChunk = 64;
260 static const int kOffsetOfRawPtrInPersistentHandle = 0; 294 static const int kOffsetOfRawPtrInPersistentHandle = 0;
261 class PersistentHandles : Handles<kPersistentHandleSizeInWords, 295 class PersistentHandles : Handles<kPersistentHandleSizeInWords,
262 kPersistentHandlesPerChunk, 296 kPersistentHandlesPerChunk,
263 kOffsetOfRawPtrInPersistentHandle> { 297 kOffsetOfRawPtrInPersistentHandle> {
264 public: 298 public:
265 PersistentHandles() : Handles<kPersistentHandleSizeInWords, 299 PersistentHandles() : Handles<kPersistentHandleSizeInWords,
266 kPersistentHandlesPerChunk, 300 kPersistentHandlesPerChunk,
267 kOffsetOfRawPtrInPersistentHandle>(), 301 kOffsetOfRawPtrInPersistentHandle>(),
268 free_list_(NULL) { } 302 free_list_(NULL) {
303 #ifdef DEBUG
304 if (FLAG_trace_handles) {
305 OS::PrintErr("*** Starting a new Persistent handle block 0x%"Px"\n",
306 reinterpret_cast<intptr_t>(this));
307 }
308 #endif
309 }
269 ~PersistentHandles() { 310 ~PersistentHandles() {
270 free_list_ = NULL; 311 free_list_ = NULL;
312 #ifdef DEBUG
313 if (FLAG_trace_handles) {
314 OS::PrintErr("*** Handle Counts for 0x(%"Px"):Scoped = %d\n",
315 reinterpret_cast<intptr_t>(this),
316 CountHandles());
317 OS::PrintErr("*** Deleting Persistent handle block 0x%"Px"\n",
318 reinterpret_cast<intptr_t>(this));
319 }
320 #endif
271 } 321 }
272 322
273 // Accessors. 323 // Accessors.
274 PersistentHandle* free_list() const { return free_list_; } 324 PersistentHandle* free_list() const { return free_list_; }
275 void set_free_list(PersistentHandle* value) { free_list_ = value; } 325 void set_free_list(PersistentHandle* value) { free_list_ = value; }
276 326
277 // Visit all object pointers stored in the various handles. 327 // Visit all object pointers stored in the various handles.
278 void VisitObjectPointers(ObjectPointerVisitor* visitor) { 328 void VisitObjectPointers(ObjectPointerVisitor* visitor) {
279 Handles<kPersistentHandleSizeInWords, 329 Handles<kPersistentHandleSizeInWords,
280 kPersistentHandlesPerChunk, 330 kPersistentHandlesPerChunk,
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 ApiNativeScope::Current()->zone()) {} 734 ApiNativeScope::Current()->zone()) {}
685 ApiGrowableArray() 735 ApiGrowableArray()
686 : BaseGrowableArray<T, ValueObject>( 736 : BaseGrowableArray<T, ValueObject>(
687 ApiNativeScope::Current()->zone()) {} 737 ApiNativeScope::Current()->zone()) {}
688 }; 738 };
689 739
690 740
691 } // namespace dart 741 } // namespace dart
692 742
693 #endif // VM_DART_API_STATE_H_ 743 #endif // VM_DART_API_STATE_H_
OLDNEW
« no previous file with comments | « no previous file | vm/handles.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698