Chromium Code Reviews| Index: runtime/vm/dart_api_state.h |
| diff --git a/runtime/vm/dart_api_state.h b/runtime/vm/dart_api_state.h |
| index c851b3142194696734f22d4829f846db7a180c1d..0b4e5565a5efbcf92f3ae62067d56a27c71cb87d 100644 |
| --- a/runtime/vm/dart_api_state.h |
| +++ b/runtime/vm/dart_api_state.h |
| @@ -28,10 +28,23 @@ namespace dart { |
| class ApiZone { |
| public: |
| // Create an empty zone. |
| - ApiZone() : zone_() { } |
| + ApiZone() : zone_() { |
| + Isolate* isolate = Isolate::Current(); |
| + Zone* current_zone = isolate != NULL ? isolate->current_zone() : NULL; |
| + zone_.Link(current_zone); |
| + if (isolate != NULL) { |
| + isolate->set_current_zone(&zone_); |
| + } |
| + } |
| // Delete all memory associated with the zone. |
| - ~ApiZone() { } |
| + ~ApiZone() { |
| + Isolate* isolate = Isolate::Current(); |
| + if (isolate != NULL && isolate->current_zone() == &zone_) { |
| + isolate->set_current_zone(zone_.previous_); |
| + } |
| + zone_.Unlink(); |
| + } |
| // Allocates an array sized to hold 'len' elements of type |
| // 'ElementType'. Checks for integer overflow when performing the |
| @@ -61,9 +74,9 @@ class ApiZone { |
| // due to internal fragmentation in the segments. |
| intptr_t SizeInBytes() const { return zone_.SizeInBytes(); } |
| - private: |
| - Zone* GetBaseZone() { return &zone_; } |
| + Zone* GetZone() { return &zone_; } |
| + private: |
| Zone zone_; |
| template<typename T> friend class ApiGrowableArray; |
| @@ -436,7 +449,8 @@ class WeakReferenceSet { |
| class ApiLocalScope { |
| public: |
| ApiLocalScope(ApiLocalScope* previous, uword stack_marker) : |
| - previous_(previous), stack_marker_(stack_marker) { } |
| + previous_(previous), stack_marker_(stack_marker) { |
|
Ivan Posva
2012/10/12 21:46:33
Emptr constructors on one line.
Tom Ball
2012/10/12 22:56:51
Done.
|
| + } |
| ~ApiLocalScope() { |
| previous_ = NULL; |
| } |
| @@ -446,7 +460,7 @@ class ApiLocalScope { |
| uword stack_marker() const { return stack_marker_; } |
| void set_previous(ApiLocalScope* value) { previous_ = value; } |
| LocalHandles* local_handles() { return &local_handles_; } |
| - ApiZone* zone() { return &zone_; } |
| + Zone* zone() { return zone_.GetZone(); } |
| private: |
| ApiLocalScope* previous_; |
| @@ -653,7 +667,7 @@ class ApiNativeScope { |
| Thread::GetThreadLocal(Api::api_native_key_)); |
| } |
| - ApiZone* zone() { return &zone_; } |
| + Zone* zone() { return zone_.GetZone(); } |
| private: |
| ApiZone zone_; |
| @@ -671,10 +685,10 @@ class ApiGrowableArray : public BaseGrowableArray<T, ValueObject> { |
| explicit ApiGrowableArray(int initial_capacity) |
| : BaseGrowableArray<T, ValueObject>( |
| initial_capacity, |
| - ApiNativeScope::Current()->zone()->GetBaseZone()) {} |
| + ApiNativeScope::Current()->zone()) {} |
| ApiGrowableArray() |
| : BaseGrowableArray<T, ValueObject>( |
| - ApiNativeScope::Current()->zone()->GetBaseZone()) {} |
| + ApiNativeScope::Current()->zone()) {} |
| }; |