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

Side by Side Diff: src/serialize.cc

Issue 240193002: Serializer enable/disable flags need thread safety. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Code comment response. Created 6 years, 8 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 | « src/serialize.h ('k') | src/v8.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 } 642 }
643 643
644 644
645 ExternalReferenceDecoder::~ExternalReferenceDecoder() { 645 ExternalReferenceDecoder::~ExternalReferenceDecoder() {
646 for (int type = kFirstTypeCode; type < kTypeCodeCount; ++type) { 646 for (int type = kFirstTypeCode; type < kTypeCodeCount; ++type) {
647 DeleteArray(encodings_[type]); 647 DeleteArray(encodings_[type]);
648 } 648 }
649 DeleteArray(encodings_); 649 DeleteArray(encodings_);
650 } 650 }
651 651
652 652 AtomicWord Serializer::serialization_state_ = SERIALIZER_STATE_UNINITIALIZED;
653 bool Serializer::serialization_enabled_ = false;
654 bool Serializer::too_late_to_enable_now_ = false;
655
656 653
657 class CodeAddressMap: public CodeEventLogger { 654 class CodeAddressMap: public CodeEventLogger {
658 public: 655 public:
659 explicit CodeAddressMap(Isolate* isolate) 656 explicit CodeAddressMap(Isolate* isolate)
660 : isolate_(isolate) { 657 : isolate_(isolate) {
661 isolate->logger()->addCodeEventListener(this); 658 isolate->logger()->addCodeEventListener(this);
662 } 659 }
663 660
664 virtual ~CodeAddressMap() { 661 virtual ~CodeAddressMap() {
665 isolate_->logger()->removeCodeEventListener(this); 662 isolate_->logger()->removeCodeEventListener(this);
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 } 755 }
759 756
760 NameMap address_to_name_map_; 757 NameMap address_to_name_map_;
761 Isolate* isolate_; 758 Isolate* isolate_;
762 }; 759 };
763 760
764 761
765 CodeAddressMap* Serializer::code_address_map_ = NULL; 762 CodeAddressMap* Serializer::code_address_map_ = NULL;
766 763
767 764
768 void Serializer::Enable(Isolate* isolate) { 765 void Serializer::RequestEnable(Isolate* isolate) {
769 if (!serialization_enabled_) {
770 ASSERT(!too_late_to_enable_now_);
771 }
772 if (serialization_enabled_) return;
773 serialization_enabled_ = true;
774 isolate->InitializeLoggingAndCounters(); 766 isolate->InitializeLoggingAndCounters();
775 code_address_map_ = new CodeAddressMap(isolate); 767 code_address_map_ = new CodeAddressMap(isolate);
776 } 768 }
777 769
778 770
779 void Serializer::Disable() { 771 void Serializer::InitializeOncePerProcess() {
780 if (!serialization_enabled_) return; 772 // InitializeOncePerProcess is called by V8::InitializeOncePerProcess, a
781 serialization_enabled_ = false; 773 // method guaranteed to be called only once in a process lifetime.
782 delete code_address_map_; 774 // serialization_state_ is read by many threads, hence the use of
783 code_address_map_ = NULL; 775 // Atomic primitives. Here, we don't need a barrier or mutex to
776 // write it because V8 initialization is done by one thread, and gates
777 // all reads of serialization_state_.
778 ASSERT(NoBarrier_Load(&serialization_state_) ==
779 SERIALIZER_STATE_UNINITIALIZED);
780 SerializationState state = code_address_map_
781 ? SERIALIZER_STATE_ENABLED
782 : SERIALIZER_STATE_DISABLED;
783 NoBarrier_Store(&serialization_state_, state);
784 } 784 }
785 785
786 786
787 void Serializer::TearDown() {
788 // TearDown is called by V8::TearDown() for the default isolate. It's safe
789 // to shut down the serializer by that point. Just to be safe, we restore
790 // serialization_state_ to uninitialized.
791 ASSERT(NoBarrier_Load(&serialization_state_) !=
792 SERIALIZER_STATE_UNINITIALIZED);
793 if (code_address_map_) {
794 ASSERT(NoBarrier_Load(&serialization_state_) ==
795 SERIALIZER_STATE_ENABLED);
796 delete code_address_map_;
797 code_address_map_ = NULL;
798 }
799
800 NoBarrier_Store(&serialization_state_, SERIALIZER_STATE_UNINITIALIZED);
801 }
802
803
787 Deserializer::Deserializer(SnapshotByteSource* source) 804 Deserializer::Deserializer(SnapshotByteSource* source)
788 : isolate_(NULL), 805 : isolate_(NULL),
789 source_(source), 806 source_(source),
790 external_reference_decoder_(NULL) { 807 external_reference_decoder_(NULL) {
791 for (int i = 0; i < LAST_SPACE + 1; i++) { 808 for (int i = 0; i < LAST_SPACE + 1; i++) {
792 reservations_[i] = kUninitializedReservation; 809 reservations_[i] = kUninitializedReservation;
793 } 810 }
794 } 811 }
795 812
796 813
(...skipping 1087 matching lines...) Expand 10 before | Expand all | Expand 10 after
1884 1901
1885 bool SnapshotByteSource::AtEOF() { 1902 bool SnapshotByteSource::AtEOF() {
1886 if (0u + length_ - position_ > 2 * sizeof(uint32_t)) return false; 1903 if (0u + length_ - position_ > 2 * sizeof(uint32_t)) return false;
1887 for (int x = position_; x < length_; x++) { 1904 for (int x = position_; x < length_; x++) {
1888 if (data_[x] != SerializerDeserializer::nop()) return false; 1905 if (data_[x] != SerializerDeserializer::nop()) return false;
1889 } 1906 }
1890 return true; 1907 return true;
1891 } 1908 }
1892 1909
1893 } } // namespace v8::internal 1910 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/serialize.h ('k') | src/v8.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698