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

Side by Side Diff: runtime/vm/dart_api_state.h

Issue 1242343002: Remove more uses of Isolate::current_zone. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 5 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
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/utils.h" 10 #include "platform/utils.h"
(...skipping 17 matching lines...) Expand all
28 DECLARE_DEBUG_FLAG(bool, trace_handles); 28 DECLARE_DEBUG_FLAG(bool, trace_handles);
29 29
30 // Implementation of Zone support for very fast allocation of small chunks 30 // Implementation of Zone support for very fast allocation of small chunks
31 // of memory. The chunks cannot be deallocated individually, but instead 31 // of memory. The chunks cannot be deallocated individually, but instead
32 // zones support deallocating all chunks in one fast operation when the 32 // zones support deallocating all chunks in one fast operation when the
33 // scope is exited. 33 // scope is exited.
34 class ApiZone { 34 class ApiZone {
35 public: 35 public:
36 // Create an empty zone. 36 // Create an empty zone.
37 ApiZone() : zone_() { 37 ApiZone() : zone_() {
38 Isolate* isolate = Isolate::Current(); 38 Thread* thread = Thread::Current();
39 Zone* current_zone = isolate != NULL ? isolate->current_zone() : NULL; 39 Zone* zone = thread != NULL ? thread->zone() : NULL;
40 zone_.Link(current_zone); 40 zone_.Link(zone);
41 if (isolate != NULL) { 41 if (thread != NULL) {
42 isolate->set_current_zone(&zone_); 42 thread->set_zone(&zone_);
43 } 43 }
44 #ifdef DEBUG 44 #ifdef DEBUG
45 if (FLAG_trace_zones) { 45 if (FLAG_trace_zones) {
46 OS::PrintErr("*** Starting a new Api zone 0x%" Px "(0x%" Px ")\n", 46 OS::PrintErr("*** Starting a new Api zone 0x%" Px "(0x%" Px ")\n",
47 reinterpret_cast<intptr_t>(this), 47 reinterpret_cast<intptr_t>(this),
48 reinterpret_cast<intptr_t>(&zone_)); 48 reinterpret_cast<intptr_t>(&zone_));
49 } 49 }
50 #endif 50 #endif
51 } 51 }
52 52
53 // Delete all memory associated with the zone. 53 // Delete all memory associated with the zone.
54 ~ApiZone() { 54 ~ApiZone() {
55 Isolate* isolate = Isolate::Current(); 55 Thread* thread = Thread::Current();
56 #if defined(DEBUG) 56 #if defined(DEBUG)
57 if (isolate == NULL) { 57 if (thread == NULL) {
58 ASSERT(zone_.handles()->CountScopedHandles() == 0); 58 ASSERT(zone_.handles()->CountScopedHandles() == 0);
59 ASSERT(zone_.handles()->CountZoneHandles() == 0); 59 ASSERT(zone_.handles()->CountZoneHandles() == 0);
60 } 60 }
61 #endif 61 #endif
62 if ((isolate != NULL) && (isolate->current_zone() == &zone_)) { 62 if ((thread != NULL) && (thread->zone() == &zone_)) {
63 isolate->set_current_zone(zone_.previous_); 63 thread->set_zone(zone_.previous_);
64 } 64 }
65 #ifdef DEBUG 65 #ifdef DEBUG
66 if (FLAG_trace_zones) { 66 if (FLAG_trace_zones) {
67 OS::PrintErr("*** Deleting Api zone 0x%" Px "(0x%" Px ")\n", 67 OS::PrintErr("*** Deleting Api zone 0x%" Px "(0x%" Px ")\n",
68 reinterpret_cast<intptr_t>(this), 68 reinterpret_cast<intptr_t>(this),
69 reinterpret_cast<intptr_t>(&zone_)); 69 reinterpret_cast<intptr_t>(&zone_));
70 } 70 }
71 #endif 71 #endif
72 } 72 }
73 73
(...skipping 20 matching lines...) Expand all
94 // check for integer overflow. If you use AllocUnsafe, you are 94 // check for integer overflow. If you use AllocUnsafe, you are
95 // responsible for avoiding integer overflow yourself. 95 // responsible for avoiding integer overflow yourself.
96 uword AllocUnsafe(intptr_t size) { return zone_.AllocUnsafe(size); } 96 uword AllocUnsafe(intptr_t size) { return zone_.AllocUnsafe(size); }
97 97
98 // Compute the total size of this zone. This includes wasted space that is 98 // Compute the total size of this zone. This includes wasted space that is
99 // due to internal fragmentation in the segments. 99 // due to internal fragmentation in the segments.
100 intptr_t SizeInBytes() const { return zone_.SizeInBytes(); } 100 intptr_t SizeInBytes() const { return zone_.SizeInBytes(); }
101 101
102 Zone* GetZone() { return &zone_; } 102 Zone* GetZone() { return &zone_; }
103 103
104 void Reinit(Isolate* isolate) { 104 void Reinit(Thread* thread) {
105 if (isolate == NULL) { 105 if (thread == NULL) {
106 zone_.Link(NULL); 106 zone_.Link(NULL);
107 } else { 107 } else {
108 zone_.Link(isolate->current_zone()); 108 zone_.Link(thread->zone());
109 isolate->set_current_zone(&zone_); 109 thread->set_zone(&zone_);
110 } 110 }
111 } 111 }
112 112
113 void Reset(Isolate* isolate) { 113 void Reset(Thread* thread) {
114 if ((isolate != NULL) && (isolate->current_zone() == &zone_)) { 114 if ((thread != NULL) && (thread->zone() == &zone_)) {
115 isolate->set_current_zone(zone_.previous_); 115 thread->set_zone(zone_.previous_);
116 } 116 }
117 zone_.DeleteAll(); 117 zone_.DeleteAll();
118 } 118 }
119 119
120 private: 120 private:
121 Zone zone_; 121 Zone zone_;
122 122
123 template<typename T> friend class ApiGrowableArray; 123 template<typename T> friend class ApiGrowableArray;
124 DISALLOW_COPY_AND_ASSIGN(ApiZone); 124 DISALLOW_COPY_AND_ASSIGN(ApiZone);
125 }; 125 };
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 // These local scopes manage handles and memory allocated in the scope. 585 // These local scopes manage handles and memory allocated in the scope.
586 class ApiLocalScope { 586 class ApiLocalScope {
587 public: 587 public:
588 ApiLocalScope(ApiLocalScope* previous, uword stack_marker) : 588 ApiLocalScope(ApiLocalScope* previous, uword stack_marker) :
589 previous_(previous), stack_marker_(stack_marker) { } 589 previous_(previous), stack_marker_(stack_marker) { }
590 ~ApiLocalScope() { 590 ~ApiLocalScope() {
591 previous_ = NULL; 591 previous_ = NULL;
592 } 592 }
593 593
594 // Reinit the ApiLocalScope to new values. 594 // Reinit the ApiLocalScope to new values.
595 void Reinit(Isolate* isolate, ApiLocalScope* previous, uword stack_marker) { 595 void Reinit(Thread* thread, ApiLocalScope* previous, uword stack_marker) {
596 previous_ = previous; 596 previous_ = previous;
597 stack_marker_ = stack_marker; 597 stack_marker_ = stack_marker;
598 zone_.Reinit(isolate); 598 zone_.Reinit(thread);
599 } 599 }
600 600
601 // Reset the ApiLocalScope so that it can be reused again. 601 // Reset the ApiLocalScope so that it can be reused again.
602 void Reset(Isolate* isolate) { 602 void Reset(Thread* thread) {
603 local_handles_.Reset(); 603 local_handles_.Reset();
604 zone_.Reset(isolate); 604 zone_.Reset(thread);
605 previous_ = NULL; 605 previous_ = NULL;
606 stack_marker_ = 0; 606 stack_marker_ = 0;
607 } 607 }
608 608
609 // Accessors. 609 // Accessors.
610 ApiLocalScope* previous() const { return previous_; } 610 ApiLocalScope* previous() const { return previous_; }
611 uword stack_marker() const { return stack_marker_; } 611 uword stack_marker() const { return stack_marker_; }
612 void set_previous(ApiLocalScope* value) { previous_ = value; } 612 void set_previous(ApiLocalScope* value) { previous_ = value; }
613 LocalHandles* local_handles() { return &local_handles_; } 613 LocalHandles* local_handles() { return &local_handles_; }
614 Zone* zone() { return zone_.GetZone(); } 614 Zone* zone() { return zone_.GetZone(); }
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
991 ref->set_peer(peer); 991 ref->set_peer(peer);
992 ref->set_callback(callback); 992 ref->set_callback(callback);
993 // This may trigger GC, so it must be called last. 993 // This may trigger GC, so it must be called last.
994 ref->SetExternalSize(external_size, isolate); 994 ref->SetExternalSize(external_size, isolate);
995 return ref; 995 return ref;
996 } 996 }
997 997
998 } // namespace dart 998 } // namespace dart
999 999
1000 #endif // VM_DART_API_STATE_H_ 1000 #endif // VM_DART_API_STATE_H_
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | runtime/vm/handles.cc » ('j') | runtime/vm/parser.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698