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

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

Issue 10824053: Rename WeakReference to WeakReferenceSet. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 4 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 | « runtime/vm/dart_api_impl.cc ('k') | runtime/vm/gc_marker.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_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 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 int CountHandles() const { 354 int CountHandles() const {
355 return CountScopedHandles(); 355 return CountScopedHandles();
356 } 356 }
357 357
358 private: 358 private:
359 FinalizablePersistentHandle* free_list_; 359 FinalizablePersistentHandle* free_list_;
360 DISALLOW_COPY_AND_ASSIGN(FinalizablePersistentHandles); 360 DISALLOW_COPY_AND_ASSIGN(FinalizablePersistentHandles);
361 }; 361 };
362 362
363 363
364 class WeakReference { 364 class WeakReferenceSet {
365 public: 365 public:
366 WeakReference(Dart_Handle* keys, intptr_t keys_length, 366 WeakReferenceSet(Dart_Handle* keys, intptr_t keys_length,
367 Dart_Handle* values, intptr_t values_length) 367 Dart_Handle* values, intptr_t values_length)
368 : next_(NULL), 368 : next_(NULL),
369 keys_(keys), num_keys_(keys_length), 369 keys_(keys), num_keys_(keys_length),
370 values_(values), num_values_(values_length) { 370 values_(values), num_values_(values_length) {
371 } 371 }
372 ~WeakReference() {} 372 ~WeakReferenceSet() {}
373 373
374 WeakReference* next() const { return next_; } 374 WeakReferenceSet* next() const { return next_; }
375 375
376 intptr_t num_keys() const { return num_keys_; } 376 intptr_t num_keys() const { return num_keys_; }
377 RawObject** get_key(intptr_t i) { 377 RawObject** get_key(intptr_t i) {
378 ASSERT(i >= 0); 378 ASSERT(i >= 0);
379 ASSERT(i < num_keys_); 379 ASSERT(i < num_keys_);
380 return reinterpret_cast<RawObject**>(keys_[i]); 380 return reinterpret_cast<RawObject**>(keys_[i]);
381 } 381 }
382 382
383 intptr_t num_values() const { return num_values_; } 383 intptr_t num_values() const { return num_values_; }
384 RawObject** get_value(intptr_t i) { 384 RawObject** get_value(intptr_t i) {
385 ASSERT(i >= 0); 385 ASSERT(i >= 0);
386 ASSERT(i < num_values_); 386 ASSERT(i < num_values_);
387 return reinterpret_cast<RawObject**>(values_[i]); 387 return reinterpret_cast<RawObject**>(values_[i]);
388 } 388 }
389 389
390 static WeakReference* Pop(WeakReference** queue) { 390 static WeakReferenceSet* Pop(WeakReferenceSet** queue) {
391 ASSERT(queue != NULL); 391 ASSERT(queue != NULL);
392 WeakReference* head = *queue; 392 WeakReferenceSet* head = *queue;
393 if (head != NULL) { 393 if (head != NULL) {
394 *queue = head->next(); 394 *queue = head->next();
395 head->next_ = NULL; 395 head->next_ = NULL;
396 } 396 }
397 return head; 397 return head;
398 } 398 }
399 399
400 static void Push(WeakReference* reference, WeakReference** queue) { 400 static void Push(WeakReferenceSet* reference_set, WeakReferenceSet** queue) {
401 ASSERT(reference != NULL); 401 ASSERT(reference_set != NULL);
402 ASSERT(queue != NULL); 402 ASSERT(queue != NULL);
403 reference->next_ = *queue; 403 reference_set->next_ = *queue;
404 *queue = reference; 404 *queue = reference_set;
405 } 405 }
406 406
407 private: 407 private:
408 WeakReference* next_; 408 WeakReferenceSet* next_;
409 Dart_Handle* keys_; 409 Dart_Handle* keys_;
410 intptr_t num_keys_; 410 intptr_t num_keys_;
411 Dart_Handle* values_; 411 Dart_Handle* values_;
412 intptr_t num_values_; 412 intptr_t num_values_;
413 DISALLOW_COPY_AND_ASSIGN(WeakReference); 413 DISALLOW_COPY_AND_ASSIGN(WeakReferenceSet);
414 }; 414 };
415 415
416 416
417 // Structure used for the implementation of local scopes used in dart_api. 417 // Structure used for the implementation of local scopes used in dart_api.
418 // These local scopes manage handles and memory allocated in the scope. 418 // These local scopes manage handles and memory allocated in the scope.
419 class ApiLocalScope { 419 class ApiLocalScope {
420 public: 420 public:
421 ApiLocalScope(ApiLocalScope* previous, uword stack_marker) : 421 ApiLocalScope(ApiLocalScope* previous, uword stack_marker) :
422 previous_(previous), stack_marker_(stack_marker) { } 422 previous_(previous), stack_marker_(stack_marker) { }
423 ~ApiLocalScope() { 423 ~ApiLocalScope() {
(...skipping 15 matching lines...) Expand all
439 439
440 DISALLOW_COPY_AND_ASSIGN(ApiLocalScope); 440 DISALLOW_COPY_AND_ASSIGN(ApiLocalScope);
441 }; 441 };
442 442
443 443
444 // Implementation of the API State used in dart api for maintaining 444 // Implementation of the API State used in dart api for maintaining
445 // local scopes, persistent handles etc. These are setup on a per isolate 445 // local scopes, persistent handles etc. These are setup on a per isolate
446 // basis and destroyed when the isolate is shutdown. 446 // basis and destroyed when the isolate is shutdown.
447 class ApiState { 447 class ApiState {
448 public: 448 public:
449 ApiState() : top_scope_(NULL), delayed_weak_references_(NULL), 449 ApiState() : top_scope_(NULL), delayed_weak_reference_sets_(NULL),
450 null_(NULL), true_(NULL), false_(NULL) { } 450 null_(NULL), true_(NULL), false_(NULL) { }
451 ~ApiState() { 451 ~ApiState() {
452 while (top_scope_ != NULL) { 452 while (top_scope_ != NULL) {
453 ApiLocalScope* scope = top_scope_; 453 ApiLocalScope* scope = top_scope_;
454 top_scope_ = top_scope_->previous(); 454 top_scope_ = top_scope_->previous();
455 delete scope; 455 delete scope;
456 } 456 }
457 if (null_ != NULL) { 457 if (null_ != NULL) {
458 persistent_handles().FreeHandle(null_); 458 persistent_handles().FreeHandle(null_);
459 null_ = NULL; 459 null_ = NULL;
(...skipping 15 matching lines...) Expand all
475 PersistentHandles& persistent_handles() { return persistent_handles_; } 475 PersistentHandles& persistent_handles() { return persistent_handles_; }
476 476
477 FinalizablePersistentHandles& weak_persistent_handles() { 477 FinalizablePersistentHandles& weak_persistent_handles() {
478 return weak_persistent_handles_; 478 return weak_persistent_handles_;
479 } 479 }
480 480
481 FinalizablePersistentHandles& prologue_weak_persistent_handles() { 481 FinalizablePersistentHandles& prologue_weak_persistent_handles() {
482 return prologue_weak_persistent_handles_; 482 return prologue_weak_persistent_handles_;
483 } 483 }
484 484
485 WeakReference* delayed_weak_references() { return delayed_weak_references_; } 485 WeakReferenceSet* delayed_weak_reference_sets() {
486 void set_delayed_weak_references(WeakReference* reference) { 486 return delayed_weak_reference_sets_;
487 delayed_weak_references_ = reference; 487 }
488 void set_delayed_weak_reference_sets(WeakReferenceSet* reference_set) {
489 delayed_weak_reference_sets_ = reference_set;
488 } 490 }
489 491
490 void UnwindScopes(uword sp) { 492 void UnwindScopes(uword sp) {
491 while (top_scope_ != NULL && top_scope_->stack_marker() < sp) { 493 while (top_scope_ != NULL && top_scope_->stack_marker() < sp) {
492 ApiLocalScope* scope = top_scope_; 494 ApiLocalScope* scope = top_scope_;
493 top_scope_ = top_scope_->previous(); 495 top_scope_ = top_scope_->previous();
494 delete scope; 496 delete scope;
495 } 497 }
496 } 498 }
497 499
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 if (false_ == NULL) { 591 if (false_ == NULL) {
590 DARTSCOPE(Isolate::Current()); 592 DARTSCOPE(Isolate::Current());
591 593
592 const Object& false_object = Object::Handle(Bool::False()); 594 const Object& false_object = Object::Handle(Bool::False());
593 false_ = persistent_handles().AllocateHandle(); 595 false_ = persistent_handles().AllocateHandle();
594 false_->set_raw(false_object); 596 false_->set_raw(false_object);
595 } 597 }
596 return false_; 598 return false_;
597 } 599 }
598 600
599 void DelayWeakReference(WeakReference* reference) { 601 void DelayWeakReferenceSet(WeakReferenceSet* reference_set) {
600 WeakReference::Push(reference, &delayed_weak_references_); 602 WeakReferenceSet::Push(reference_set, &delayed_weak_reference_sets_);
601 } 603 }
602 604
603 private: 605 private:
604 PersistentHandles persistent_handles_; 606 PersistentHandles persistent_handles_;
605 FinalizablePersistentHandles weak_persistent_handles_; 607 FinalizablePersistentHandles weak_persistent_handles_;
606 FinalizablePersistentHandles prologue_weak_persistent_handles_; 608 FinalizablePersistentHandles prologue_weak_persistent_handles_;
607 ApiLocalScope* top_scope_; 609 ApiLocalScope* top_scope_;
608 WeakReference* delayed_weak_references_; 610 WeakReferenceSet* delayed_weak_reference_sets_;
609 611
610 // Persistent handles to important objects. 612 // Persistent handles to important objects.
611 PersistentHandle* null_; 613 PersistentHandle* null_;
612 PersistentHandle* true_; 614 PersistentHandle* true_;
613 PersistentHandle* false_; 615 PersistentHandle* false_;
614 616
615 DISALLOW_COPY_AND_ASSIGN(ApiState); 617 DISALLOW_COPY_AND_ASSIGN(ApiState);
616 }; 618 };
617 619
618 620
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 ApiNativeScope::Current()->zone()->GetBaseZone()) {} 657 ApiNativeScope::Current()->zone()->GetBaseZone()) {}
656 ApiGrowableArray() 658 ApiGrowableArray()
657 : BaseGrowableArray<T, ValueObject>( 659 : BaseGrowableArray<T, ValueObject>(
658 ApiNativeScope::Current()->zone()->GetBaseZone()) {} 660 ApiNativeScope::Current()->zone()->GetBaseZone()) {}
659 }; 661 };
660 662
661 663
662 } // namespace dart 664 } // namespace dart
663 665
664 #endif // VM_DART_API_STATE_H_ 666 #endif // VM_DART_API_STATE_H_
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | runtime/vm/gc_marker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698