| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 "vm/dart_api_impl.h" | 10 #include "vm/dart_api_impl.h" |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 | 250 |
| 251 DISALLOW_COPY_AND_ASSIGN(ApiLocalScope); | 251 DISALLOW_COPY_AND_ASSIGN(ApiLocalScope); |
| 252 }; | 252 }; |
| 253 | 253 |
| 254 | 254 |
| 255 // Implementation of the API State used in dart api for maintaining | 255 // Implementation of the API State used in dart api for maintaining |
| 256 // local scopes, persistent handles etc. These are setup on a per isolate | 256 // local scopes, persistent handles etc. These are setup on a per isolate |
| 257 // basis and destroyed when the isolate is shutdown. | 257 // basis and destroyed when the isolate is shutdown. |
| 258 class ApiState { | 258 class ApiState { |
| 259 public: | 259 public: |
| 260 ApiState() : top_scope_(NULL), true_(NULL) { } | 260 ApiState() : top_scope_(NULL), null_(NULL), true_(NULL), false_(NULL) { } |
| 261 ~ApiState() { | 261 ~ApiState() { |
| 262 while (top_scope_ != NULL) { | 262 while (top_scope_ != NULL) { |
| 263 ApiLocalScope* scope = top_scope_; | 263 ApiLocalScope* scope = top_scope_; |
| 264 top_scope_ = top_scope_->previous(); | 264 top_scope_ = top_scope_->previous(); |
| 265 delete scope; | 265 delete scope; |
| 266 } | 266 } |
| 267 if (null_ != NULL) { |
| 268 persistent_handles().FreeHandle(null_); |
| 269 null_ = NULL; |
| 270 } |
| 267 if (true_ != NULL) { | 271 if (true_ != NULL) { |
| 268 persistent_handles().FreeHandle(true_); | 272 persistent_handles().FreeHandle(true_); |
| 269 true_ = NULL; | 273 true_ = NULL; |
| 270 } | 274 } |
| 275 if (false_ != NULL) { |
| 276 persistent_handles().FreeHandle(false_); |
| 277 false_ = NULL; |
| 278 } |
| 271 } | 279 } |
| 272 | 280 |
| 273 // Accessors. | 281 // Accessors. |
| 274 ApiLocalScope* top_scope() const { return top_scope_; } | 282 ApiLocalScope* top_scope() const { return top_scope_; } |
| 275 void set_top_scope(ApiLocalScope* value) { top_scope_ = value; } | 283 void set_top_scope(ApiLocalScope* value) { top_scope_ = value; } |
| 276 PersistentHandles& persistent_handles() { return persistent_handles_; } | 284 PersistentHandles& persistent_handles() { return persistent_handles_; } |
| 277 | 285 |
| 278 void UnwindScopes(uword sp) { | 286 void UnwindScopes(uword sp) { |
| 279 while (top_scope_ != NULL && top_scope_->stack_marker() < sp) { | 287 while (top_scope_ != NULL && top_scope_->stack_marker() < sp) { |
| 280 ApiLocalScope* scope = top_scope_; | 288 ApiLocalScope* scope = top_scope_; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 } | 328 } |
| 321 int ZoneSizeInBytes() const { | 329 int ZoneSizeInBytes() const { |
| 322 int total = 0; | 330 int total = 0; |
| 323 ApiLocalScope* scope = top_scope_; | 331 ApiLocalScope* scope = top_scope_; |
| 324 while (scope != NULL) { | 332 while (scope != NULL) { |
| 325 total += scope->zone().SizeInBytes(); | 333 total += scope->zone().SizeInBytes(); |
| 326 scope = scope->previous(); | 334 scope = scope->previous(); |
| 327 } | 335 } |
| 328 return total; | 336 return total; |
| 329 } | 337 } |
| 338 PersistentHandle* Null() { |
| 339 if (null_ == NULL) { |
| 340 Zone zone; // Setup a VM zone as we are creating some handles. |
| 341 HandleScope scope; // Setup a VM handle scope. |
| 342 |
| 343 Object& null_object = Object::Handle(); |
| 344 null_ = persistent_handles().AllocateHandle(); |
| 345 null_->set_raw(null_object); |
| 346 } |
| 347 return null_; |
| 348 } |
| 330 PersistentHandle* True() { | 349 PersistentHandle* True() { |
| 331 if (true_ == NULL) { | 350 if (true_ == NULL) { |
| 332 Zone zone; // Setup a VM zone as we are creating some handles. | 351 Zone zone; // Setup a VM zone as we are creating some handles. |
| 333 HandleScope scope; // Setup a VM handle scope. | 352 HandleScope scope; // Setup a VM handle scope. |
| 334 | 353 |
| 335 const Object& true_object = Object::Handle(Bool::True()); | 354 const Object& true_object = Object::Handle(Bool::True()); |
| 336 true_ = persistent_handles().AllocateHandle(); | 355 true_ = persistent_handles().AllocateHandle(); |
| 337 true_->set_raw(true_object); | 356 true_->set_raw(true_object); |
| 338 } | 357 } |
| 339 return true_; | 358 return true_; |
| 340 } | 359 } |
| 360 PersistentHandle* False() { |
| 361 if (false_ == NULL) { |
| 362 Zone zone; // Setup a VM zone as we are creating some handles. |
| 363 HandleScope scope; // Setup a VM handle scope. |
| 364 |
| 365 const Object& false_object = Object::Handle(Bool::False()); |
| 366 false_ = persistent_handles().AllocateHandle(); |
| 367 false_->set_raw(false_object); |
| 368 } |
| 369 return false_; |
| 370 } |
| 341 | 371 |
| 342 private: | 372 private: |
| 343 PersistentHandles persistent_handles_; | 373 PersistentHandles persistent_handles_; |
| 344 ApiLocalScope* top_scope_; | 374 ApiLocalScope* top_scope_; |
| 345 | 375 |
| 346 // A persistent handle to the "True" object. | 376 // Persistent handles to important objects. |
| 377 PersistentHandle* null_; |
| 347 PersistentHandle* true_; | 378 PersistentHandle* true_; |
| 379 PersistentHandle* false_; |
| 348 | 380 |
| 349 DISALLOW_COPY_AND_ASSIGN(ApiState); | 381 DISALLOW_COPY_AND_ASSIGN(ApiState); |
| 350 }; | 382 }; |
| 351 | 383 |
| 352 } // namespace dart | 384 } // namespace dart |
| 353 | 385 |
| 354 #endif // VM_DART_API_STATE_H_ | 386 #endif // VM_DART_API_STATE_H_ |
| OLD | NEW |