Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 341 int CountHandles() const { | 341 int CountHandles() const { |
| 342 return CountScopedHandles(); | 342 return CountScopedHandles(); |
| 343 } | 343 } |
| 344 | 344 |
| 345 private: | 345 private: |
| 346 WeakPersistentHandle* free_list_; | 346 WeakPersistentHandle* free_list_; |
| 347 DISALLOW_COPY_AND_ASSIGN(WeakPersistentHandles); | 347 DISALLOW_COPY_AND_ASSIGN(WeakPersistentHandles); |
| 348 }; | 348 }; |
| 349 | 349 |
| 350 | 350 |
| 351 class WeakReference { | |
| 352 public: | |
| 353 WeakReference(Dart_Handle* keys, intptr_t keys_length, | |
| 354 Dart_Handle* values, intptr_t values_length) | |
| 355 : next_(NULL), | |
| 356 keys_(keys), num_keys_(keys_length), | |
| 357 values_(values), num_values_(values_length) { | |
| 358 } | |
| 359 ~WeakReference() {} | |
| 360 | |
| 361 WeakReference* next() { return next_; } | |
|
siva
2012/03/02 18:30:33
next() const { ... }
Ditto comment for other acce
cshapiro
2012/03/03 00:03:23
Right. Done.
| |
| 362 void set_next(WeakReference* next) { next_ = next; } | |
|
siva
2012/03/02 18:30:33
Do next and set_next have to be part of the public
cshapiro
2012/03/03 00:03:23
Done.
In fact, I added this method before I had P
| |
| 363 | |
| 364 intptr_t num_keys() { return num_keys_; } | |
| 365 RawObject** get_key(intptr_t i) { | |
| 366 ASSERT(i >= 0); | |
| 367 ASSERT(i < num_keys_); | |
| 368 return reinterpret_cast<RawObject**>(keys_[i]); | |
| 369 } | |
| 370 | |
| 371 intptr_t num_values() { return num_values_; } | |
| 372 RawObject** get_value(intptr_t i) { | |
| 373 ASSERT(i >= 0); | |
| 374 ASSERT(i < num_values_); | |
| 375 return reinterpret_cast<RawObject**>(values_[i]); | |
| 376 } | |
| 377 | |
| 378 static WeakReference* Pop(WeakReference** queue) { | |
|
siva
2012/03/02 18:30:33
ASSERT(queue != NULL);
cshapiro
2012/03/03 00:03:23
Done.
| |
| 379 WeakReference* head = *queue; | |
| 380 if (head != NULL) { | |
| 381 *queue = head->next(); | |
| 382 head->set_next(NULL); | |
| 383 } | |
| 384 return head; | |
| 385 } | |
| 386 | |
| 387 static void Push(WeakReference* reference, WeakReference** queue) { | |
|
siva
2012/03/02 18:30:33
ASSERT(queue != NULL);
ASSERT(reference != NULL);
cshapiro
2012/03/03 00:03:23
Also done. Thanks!
| |
| 388 reference->set_next(*queue); | |
| 389 *queue = reference; | |
| 390 } | |
| 391 | |
| 392 private: | |
| 393 WeakReference* next_; | |
| 394 Dart_Handle* keys_; | |
| 395 intptr_t num_keys_; | |
| 396 Dart_Handle* values_; | |
| 397 intptr_t num_values_; | |
| 398 DISALLOW_COPY_AND_ASSIGN(WeakReference); | |
| 399 }; | |
| 400 | |
| 401 | |
| 351 // Structure used for the implementation of local scopes used in dart_api. | 402 // Structure used for the implementation of local scopes used in dart_api. |
| 352 // These local scopes manage handles and memory allocated in the scope. | 403 // These local scopes manage handles and memory allocated in the scope. |
| 353 class ApiLocalScope { | 404 class ApiLocalScope { |
| 354 public: | 405 public: |
| 355 ApiLocalScope(ApiLocalScope* previous, uword stack_marker) : | 406 ApiLocalScope(ApiLocalScope* previous, uword stack_marker) : |
| 356 previous_(previous), stack_marker_(stack_marker) { } | 407 previous_(previous), stack_marker_(stack_marker) { } |
| 357 ~ApiLocalScope() { | 408 ~ApiLocalScope() { |
| 358 previous_ = NULL; | 409 previous_ = NULL; |
| 359 } | 410 } |
| 360 | 411 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 373 | 424 |
| 374 DISALLOW_COPY_AND_ASSIGN(ApiLocalScope); | 425 DISALLOW_COPY_AND_ASSIGN(ApiLocalScope); |
| 375 }; | 426 }; |
| 376 | 427 |
| 377 | 428 |
| 378 // Implementation of the API State used in dart api for maintaining | 429 // Implementation of the API State used in dart api for maintaining |
| 379 // local scopes, persistent handles etc. These are setup on a per isolate | 430 // local scopes, persistent handles etc. These are setup on a per isolate |
| 380 // basis and destroyed when the isolate is shutdown. | 431 // basis and destroyed when the isolate is shutdown. |
| 381 class ApiState { | 432 class ApiState { |
| 382 public: | 433 public: |
| 383 ApiState() : top_scope_(NULL), null_(NULL), true_(NULL), false_(NULL) { } | 434 ApiState() : top_scope_(NULL), delayed_weak_references_(NULL), |
| 435 null_(NULL), true_(NULL), false_(NULL) { } | |
| 384 ~ApiState() { | 436 ~ApiState() { |
| 385 while (top_scope_ != NULL) { | 437 while (top_scope_ != NULL) { |
| 386 ApiLocalScope* scope = top_scope_; | 438 ApiLocalScope* scope = top_scope_; |
| 387 top_scope_ = top_scope_->previous(); | 439 top_scope_ = top_scope_->previous(); |
| 388 delete scope; | 440 delete scope; |
| 389 } | 441 } |
| 390 if (null_ != NULL) { | 442 if (null_ != NULL) { |
| 391 persistent_handles().FreeHandle(null_); | 443 persistent_handles().FreeHandle(null_); |
| 392 null_ = NULL; | 444 null_ = NULL; |
| 393 } | 445 } |
| 394 if (true_ != NULL) { | 446 if (true_ != NULL) { |
| 395 persistent_handles().FreeHandle(true_); | 447 persistent_handles().FreeHandle(true_); |
| 396 true_ = NULL; | 448 true_ = NULL; |
| 397 } | 449 } |
| 398 if (false_ != NULL) { | 450 if (false_ != NULL) { |
| 399 persistent_handles().FreeHandle(false_); | 451 persistent_handles().FreeHandle(false_); |
| 400 false_ = NULL; | 452 false_ = NULL; |
| 401 } | 453 } |
| 402 } | 454 } |
| 403 | 455 |
| 404 // Accessors. | 456 // Accessors. |
| 405 ApiLocalScope* top_scope() const { return top_scope_; } | 457 ApiLocalScope* top_scope() const { return top_scope_; } |
| 406 void set_top_scope(ApiLocalScope* value) { top_scope_ = value; } | 458 void set_top_scope(ApiLocalScope* value) { top_scope_ = value; } |
| 407 PersistentHandles& persistent_handles() { return persistent_handles_; } | 459 PersistentHandles& persistent_handles() { return persistent_handles_; } |
| 408 WeakPersistentHandles& weak_persistent_handles() { | 460 WeakPersistentHandles& weak_persistent_handles() { |
| 409 return weak_persistent_handles_; | 461 return weak_persistent_handles_; |
| 410 } | 462 } |
| 411 | 463 WeakReference* delayed_weak_references() { return delayed_weak_references_; } |
| 464 void set_delayed_weak_references(WeakReference* reference) { | |
| 465 delayed_weak_references_ = reference; | |
| 466 } | |
| 412 void UnwindScopes(uword sp) { | 467 void UnwindScopes(uword sp) { |
| 413 while (top_scope_ != NULL && top_scope_->stack_marker() < sp) { | 468 while (top_scope_ != NULL && top_scope_->stack_marker() < sp) { |
| 414 ApiLocalScope* scope = top_scope_; | 469 ApiLocalScope* scope = top_scope_; |
| 415 top_scope_ = top_scope_->previous(); | 470 top_scope_ = top_scope_->previous(); |
| 416 delete scope; | 471 delete scope; |
| 417 } | 472 } |
| 418 } | 473 } |
| 419 | 474 |
| 420 void VisitObjectPointers(ObjectPointerVisitor* visitor) { | 475 void VisitObjectPointers(ObjectPointerVisitor* visitor) { |
| 421 ApiLocalScope* scope = top_scope_; | 476 ApiLocalScope* scope = top_scope_; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 499 if (false_ == NULL) { | 554 if (false_ == NULL) { |
| 500 DARTSCOPE(Isolate::Current()); | 555 DARTSCOPE(Isolate::Current()); |
| 501 | 556 |
| 502 const Object& false_object = Object::Handle(Bool::False()); | 557 const Object& false_object = Object::Handle(Bool::False()); |
| 503 false_ = persistent_handles().AllocateHandle(); | 558 false_ = persistent_handles().AllocateHandle(); |
| 504 false_->set_raw(false_object); | 559 false_->set_raw(false_object); |
| 505 } | 560 } |
| 506 return false_; | 561 return false_; |
| 507 } | 562 } |
| 508 | 563 |
| 564 void DelayWeakReference(WeakReference* reference) { | |
| 565 WeakReference::Push(reference, &delayed_weak_references_); | |
| 566 } | |
| 567 | |
| 509 private: | 568 private: |
| 510 PersistentHandles persistent_handles_; | 569 PersistentHandles persistent_handles_; |
| 511 WeakPersistentHandles weak_persistent_handles_; | 570 WeakPersistentHandles weak_persistent_handles_; |
| 512 ApiLocalScope* top_scope_; | 571 ApiLocalScope* top_scope_; |
| 572 WeakReference* delayed_weak_references_; | |
| 513 | 573 |
| 514 // Persistent handles to important objects. | 574 // Persistent handles to important objects. |
| 515 PersistentHandle* null_; | 575 PersistentHandle* null_; |
| 516 PersistentHandle* true_; | 576 PersistentHandle* true_; |
| 517 PersistentHandle* false_; | 577 PersistentHandle* false_; |
| 518 | 578 |
| 519 DISALLOW_COPY_AND_ASSIGN(ApiState); | 579 DISALLOW_COPY_AND_ASSIGN(ApiState); |
| 520 }; | 580 }; |
| 521 | 581 |
| 522 | 582 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 559 ApiNativeScope::Current()->zone()->GetBaseZone()) {} | 619 ApiNativeScope::Current()->zone()->GetBaseZone()) {} |
| 560 ApiGrowableArray() | 620 ApiGrowableArray() |
| 561 : BaseGrowableArray<T, ValueObject>( | 621 : BaseGrowableArray<T, ValueObject>( |
| 562 ApiNativeScope::Current()->zone()->GetBaseZone()) {} | 622 ApiNativeScope::Current()->zone()->GetBaseZone()) {} |
| 563 }; | 623 }; |
| 564 | 624 |
| 565 | 625 |
| 566 } // namespace dart | 626 } // namespace dart |
| 567 | 627 |
| 568 #endif // VM_DART_API_STATE_H_ | 628 #endif // VM_DART_API_STATE_H_ |
| OLD | NEW |