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

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

Issue 2672833003: Fix for issue #28606. Removed loop which iterated over all threads in the thread registry to check … (Closed)
Patch Set: Created 3 years, 10 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 RUNTIME_VM_DART_API_STATE_H_ 5 #ifndef RUNTIME_VM_DART_API_STATE_H_
6 #define RUNTIME_VM_DART_API_STATE_H_ 6 #define RUNTIME_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 438 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 static const int kPersistentHandlesPerChunk = 64; 449 static const int kPersistentHandlesPerChunk = 64;
450 static const int kOffsetOfRawPtrInPersistentHandle = 0; 450 static const int kOffsetOfRawPtrInPersistentHandle = 0;
451 class PersistentHandles : Handles<kPersistentHandleSizeInWords, 451 class PersistentHandles : Handles<kPersistentHandleSizeInWords,
452 kPersistentHandlesPerChunk, 452 kPersistentHandlesPerChunk,
453 kOffsetOfRawPtrInPersistentHandle> { 453 kOffsetOfRawPtrInPersistentHandle> {
454 public: 454 public:
455 PersistentHandles() 455 PersistentHandles()
456 : Handles<kPersistentHandleSizeInWords, 456 : Handles<kPersistentHandleSizeInWords,
457 kPersistentHandlesPerChunk, 457 kPersistentHandlesPerChunk,
458 kOffsetOfRawPtrInPersistentHandle>(), 458 kOffsetOfRawPtrInPersistentHandle>(),
459 mutex_(new Mutex()),
bkonyi 2017/02/02 22:22:34 It looks like PersistentHandles contains shared ha
bkonyi 2017/02/02 22:43:03 As discussed with Siva, this isn't needed. Removed
siva 2017/02/02 22:51:13 FinalizablePersistentHandles has a lock because we
459 free_list_(NULL) { 460 free_list_(NULL) {
460 if (FLAG_trace_handles) { 461 if (FLAG_trace_handles) {
461 OS::PrintErr("*** Starting a new Persistent handle block 0x%" Px "\n", 462 OS::PrintErr("*** Starting a new Persistent handle block 0x%" Px "\n",
462 reinterpret_cast<intptr_t>(this)); 463 reinterpret_cast<intptr_t>(this));
463 } 464 }
464 } 465 }
465 ~PersistentHandles() { 466 ~PersistentHandles() {
467 delete mutex_;
466 free_list_ = NULL; 468 free_list_ = NULL;
467 if (FLAG_trace_handles) { 469 if (FLAG_trace_handles) {
468 OS::PrintErr("*** Handle Counts for 0x(%" Px "):Scoped = %d\n", 470 OS::PrintErr("*** Handle Counts for 0x(%" Px "):Scoped = %d\n",
469 reinterpret_cast<intptr_t>(this), CountHandles()); 471 reinterpret_cast<intptr_t>(this), CountHandles());
470 OS::PrintErr("*** Deleting Persistent handle block 0x%" Px "\n", 472 OS::PrintErr("*** Deleting Persistent handle block 0x%" Px "\n",
471 reinterpret_cast<intptr_t>(this)); 473 reinterpret_cast<intptr_t>(this));
472 } 474 }
473 } 475 }
474 476
475 // Accessors. 477 // Accessors.
476 PersistentHandle* free_list() const { return free_list_; } 478 PersistentHandle* free_list() const { return free_list_; }
477 void set_free_list(PersistentHandle* value) { free_list_ = value; } 479 void set_free_list(PersistentHandle* value) { free_list_ = value; }
478 480
479 // Visit all object pointers stored in the various handles. 481 // Visit all object pointers stored in the various handles.
480 void VisitObjectPointers(ObjectPointerVisitor* visitor) { 482 void VisitObjectPointers(ObjectPointerVisitor* visitor) {
483 MutexLocker ml(mutex_);
481 Handles<kPersistentHandleSizeInWords, kPersistentHandlesPerChunk, 484 Handles<kPersistentHandleSizeInWords, kPersistentHandlesPerChunk,
482 kOffsetOfRawPtrInPersistentHandle>::VisitObjectPointers(visitor); 485 kOffsetOfRawPtrInPersistentHandle>::VisitObjectPointers(visitor);
483 } 486 }
484 487
485 // Visit all the handles. 488 // Visit all the handles.
486 void Visit(HandleVisitor* visitor) { 489 void Visit(HandleVisitor* visitor) {
490 MutexLocker ml(mutex_);
487 Handles<kPersistentHandleSizeInWords, kPersistentHandlesPerChunk, 491 Handles<kPersistentHandleSizeInWords, kPersistentHandlesPerChunk,
488 kOffsetOfRawPtrInPersistentHandle>::Visit(visitor); 492 kOffsetOfRawPtrInPersistentHandle>::Visit(visitor);
489 } 493 }
490 494
491 // Allocates a persistent handle, these have to be destroyed explicitly 495 // Allocates a persistent handle, these have to be destroyed explicitly
492 // by calling FreeHandle. 496 // by calling FreeHandle.
493 PersistentHandle* AllocateHandle() { 497 PersistentHandle* AllocateHandle() {
498 MutexLocker ml(mutex_);
494 PersistentHandle* handle; 499 PersistentHandle* handle;
495 if (free_list_ != NULL) { 500 if (free_list_ != NULL) {
496 handle = free_list_; 501 handle = free_list_;
497 free_list_ = handle->Next(); 502 free_list_ = handle->Next();
498 } else { 503 } else {
499 handle = reinterpret_cast<PersistentHandle*>(AllocateScopedHandle()); 504 handle = reinterpret_cast<PersistentHandle*>(AllocateScopedHandle());
500 } 505 }
501 handle->set_raw(Object::null()); 506 handle->set_raw(Object::null());
502 return handle; 507 return handle;
503 } 508 }
504 509
505 void FreeHandle(PersistentHandle* handle) { 510 void FreeHandle(PersistentHandle* handle) {
511 MutexLocker ml(mutex_);
506 handle->FreeHandle(free_list()); 512 handle->FreeHandle(free_list());
507 set_free_list(handle); 513 set_free_list(handle);
508 } 514 }
509 515
510 // Validate if passed in handle is a Persistent Handle. 516 // Validate if passed in handle is a Persistent Handle.
511 bool IsValidHandle(Dart_PersistentHandle object) const { 517 bool IsValidHandle(Dart_PersistentHandle object) const {
518 MutexLocker ml(mutex_);
512 return IsValidScopedHandle(reinterpret_cast<uword>(object)); 519 return IsValidScopedHandle(reinterpret_cast<uword>(object));
513 } 520 }
514 521
515 bool IsFreeHandle(Dart_PersistentHandle object) const { 522 bool IsFreeHandle(Dart_PersistentHandle object) const {
523 MutexLocker ml(mutex_);
516 PersistentHandle* handle = free_list_; 524 PersistentHandle* handle = free_list_;
517 while (handle != NULL) { 525 while (handle != NULL) {
518 if (handle == reinterpret_cast<PersistentHandle*>(object)) { 526 if (handle == reinterpret_cast<PersistentHandle*>(object)) {
519 return true; 527 return true;
520 } 528 }
521 handle = handle->Next(); 529 handle = handle->Next();
522 } 530 }
523 return false; 531 return false;
524 } 532 }
525 533
526 // Returns a count of active handles (used for testing purposes). 534 // Returns a count of active handles (used for testing purposes).
527 int CountHandles() const { return CountScopedHandles(); } 535 int CountHandles() const { return CountScopedHandles(); }
528 536
529 private: 537 private:
538 Mutex* mutex_;
530 PersistentHandle* free_list_; 539 PersistentHandle* free_list_;
531 DISALLOW_COPY_AND_ASSIGN(PersistentHandles); 540 DISALLOW_COPY_AND_ASSIGN(PersistentHandles);
532 }; 541 };
533 542
534 543
535 // Finalizable persistent handles repository structure. 544 // Finalizable persistent handles repository structure.
536 static const int kFinalizablePersistentHandleSizeInWords = 545 static const int kFinalizablePersistentHandleSizeInWords =
537 sizeof(FinalizablePersistentHandle) / kWordSize; 546 sizeof(FinalizablePersistentHandle) / kWordSize;
538 static const int kFinalizablePersistentHandlesPerChunk = 64; 547 static const int kFinalizablePersistentHandlesPerChunk = 64;
539 static const int kOffsetOfRawPtrInFinalizablePersistentHandle = 0; 548 static const int kOffsetOfRawPtrInFinalizablePersistentHandle = 0;
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
861 ref->set_callback(callback); 870 ref->set_callback(callback);
862 ref->set_is_queued_for_finalization(false); 871 ref->set_is_queued_for_finalization(false);
863 // This may trigger GC, so it must be called last. 872 // This may trigger GC, so it must be called last.
864 ref->SetExternalSize(external_size, isolate); 873 ref->SetExternalSize(external_size, isolate);
865 return ref; 874 return ref;
866 } 875 }
867 876
868 } // namespace dart 877 } // namespace dart
869 878
870 #endif // RUNTIME_VM_DART_API_STATE_H_ 879 #endif // RUNTIME_VM_DART_API_STATE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698