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

Side by Side Diff: vm/allocation.h

Issue 10008030: Inline the StackResource constructor/destructor. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 8 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/allocation.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 (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_ALLOCATION_H_ 5 #ifndef VM_ALLOCATION_H_
6 #define VM_ALLOCATION_H_ 6 #define VM_ALLOCATION_H_
7 7
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "vm/base_isolate.h"
9 #include "vm/globals.h" 10 #include "vm/globals.h"
10 11
11 namespace dart { 12 namespace dart {
12 13
13 // Forward declarations. 14 // Forward declarations.
14 class Isolate; 15 class Isolate;
15 16
16 // Stack allocated objects subclass from this base class. Objects of this type 17 // Stack allocated objects subclass from this base class. Objects of this type
17 // cannot be allocated on either the C or object heaps. Destructors for objects 18 // cannot be allocated on either the C or object heaps. Destructors for objects
18 // of this type will not be run unless the stack is unwound through normal 19 // of this type will not be run unless the stack is unwound through normal
(...skipping 10 matching lines...) Expand all
29 }; 30 };
30 31
31 32
32 // Stack resources subclass from this base class. The VM will ensure that the 33 // Stack resources subclass from this base class. The VM will ensure that the
33 // destructors of these objects are called before the stack is unwound past the 34 // destructors of these objects are called before the stack is unwound past the
34 // objects location on the stack. Use stack resource objects if objects 35 // objects location on the stack. Use stack resource objects if objects
35 // need to be destroyed even in the case of exceptions when a Longjump is done 36 // need to be destroyed even in the case of exceptions when a Longjump is done
36 // to a stack frame above the frame where these objects were allocated. 37 // to a stack frame above the frame where these objects were allocated.
37 class StackResource { 38 class StackResource {
38 public: 39 public:
39 explicit StackResource(Isolate* isolate); 40 explicit StackResource(BaseIsolate* isolate)
40 virtual ~StackResource(); 41 : isolate_(isolate), previous_(NULL) {
42 // We can only have longjumps and exceptions when there is a current
43 // isolate. If there is no current isolate, we don't need to
44 // protect this case.
45 if (isolate) {
46 previous_ = isolate->top_resource();
47 isolate->set_top_resource(this);
48 }
49 }
41 50
42 Isolate* isolate() const { return isolate_; } 51 virtual ~StackResource() {
52 if (isolate()) {
53 StackResource* top = isolate()->top_resource();
54 ASSERT(top == this);
55 isolate()->set_top_resource(previous_);
56 }
57 #if defined(DEBUG)
58 BaseIsolate::AssertCurrent(isolate());
59 #endif
60 }
61
62 BaseIsolate* isolate() const { return isolate_; }
43 63
44 // The delete operator should be private instead of public, but unfortunately 64 // The delete operator should be private instead of public, but unfortunately
45 // the compiler complains when compiling the destructors for subclasses. 65 // the compiler complains when compiling the destructors for subclasses.
46 void operator delete(void* pointer) { UNREACHABLE(); } 66 void operator delete(void* pointer) { UNREACHABLE(); }
47 67
48 private: 68 private:
49 Isolate* isolate_; // Current isolate for this stack resource. 69 BaseIsolate* isolate_; // Current isolate for this stack resource.
50 StackResource* previous_; 70 StackResource* previous_;
51 71
52 void* operator new(uword size); 72 void* operator new(uword size);
53 73
54 DISALLOW_IMPLICIT_CONSTRUCTORS(StackResource); 74 DISALLOW_IMPLICIT_CONSTRUCTORS(StackResource);
55 }; 75 };
56 76
57 77
58 // Static allocated classes only contain static members and can never 78 // Static allocated classes only contain static members and can never
59 // be instantiated in the heap or on the stack. 79 // be instantiated in the heap or on the stack.
(...skipping 27 matching lines...) Expand all
87 // deallocated by invoking DeleteAll() on the zone they live in. 107 // deallocated by invoking DeleteAll() on the zone they live in.
88 void operator delete(void* pointer) { UNREACHABLE(); } 108 void operator delete(void* pointer) { UNREACHABLE(); }
89 109
90 private: 110 private:
91 DISALLOW_COPY_AND_ASSIGN(ZoneAllocated); 111 DISALLOW_COPY_AND_ASSIGN(ZoneAllocated);
92 }; 112 };
93 113
94 } // namespace dart 114 } // namespace dart
95 115
96 #endif // VM_ALLOCATION_H_ 116 #endif // VM_ALLOCATION_H_
OLDNEW
« no previous file with comments | « no previous file | vm/allocation.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698