OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
8 #include "src/api.h" | 8 #include "src/api.h" |
9 #include "src/base/platform/platform.h" | 9 #include "src/base/platform/platform.h" |
10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
(...skipping 1833 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1844 // maybe left-over bytes that need to be padded. | 1844 // maybe left-over bytes that need to be padded. |
1845 int padding_size = allocation_size - SeqString::kHeaderSize - content_size; | 1845 int padding_size = allocation_size - SeqString::kHeaderSize - content_size; |
1846 DCHECK(0 <= padding_size && padding_size < kObjectAlignment); | 1846 DCHECK(0 <= padding_size && padding_size < kObjectAlignment); |
1847 for (int i = 0; i < padding_size; i++) sink_->PutSection(0, "StringPadding"); | 1847 for (int i = 0; i < padding_size; i++) sink_->PutSection(0, "StringPadding"); |
1848 | 1848 |
1849 sink_->Put(kSkip, "SkipAfterString"); | 1849 sink_->Put(kSkip, "SkipAfterString"); |
1850 sink_->PutInt(bytes_to_output, "SkipDistance"); | 1850 sink_->PutInt(bytes_to_output, "SkipDistance"); |
1851 } | 1851 } |
1852 | 1852 |
1853 | 1853 |
| 1854 // Clear and later restore the next link in the weak cell, if the object is one. |
| 1855 class UnlinkWeakCellScope { |
| 1856 public: |
| 1857 explicit UnlinkWeakCellScope(HeapObject* object) : weak_cell_(NULL) { |
| 1858 if (object->IsWeakCell()) { |
| 1859 weak_cell_ = WeakCell::cast(object); |
| 1860 next_ = weak_cell_->next(); |
| 1861 weak_cell_->clear_next(object->GetHeap()); |
| 1862 } |
| 1863 } |
| 1864 |
| 1865 ~UnlinkWeakCellScope() { |
| 1866 if (weak_cell_) weak_cell_->set_next(next_, UPDATE_WEAK_WRITE_BARRIER); |
| 1867 } |
| 1868 |
| 1869 private: |
| 1870 WeakCell* weak_cell_; |
| 1871 Object* next_; |
| 1872 DisallowHeapAllocation no_gc_; |
| 1873 }; |
| 1874 |
| 1875 |
1854 void Serializer::ObjectSerializer::Serialize() { | 1876 void Serializer::ObjectSerializer::Serialize() { |
1855 if (FLAG_trace_serializer) { | 1877 if (FLAG_trace_serializer) { |
1856 PrintF(" Encoding heap object: "); | 1878 PrintF(" Encoding heap object: "); |
1857 object_->ShortPrint(); | 1879 object_->ShortPrint(); |
1858 PrintF("\n"); | 1880 PrintF("\n"); |
1859 } | 1881 } |
1860 | 1882 |
1861 // We cannot serialize typed array objects correctly. | 1883 // We cannot serialize typed array objects correctly. |
1862 DCHECK(!object_->IsJSTypedArray()); | 1884 DCHECK(!object_->IsJSTypedArray()); |
1863 | 1885 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1903 | 1925 |
1904 RecursionScope recursion(serializer_); | 1926 RecursionScope recursion(serializer_); |
1905 // Objects that are immediately post processed during deserialization | 1927 // Objects that are immediately post processed during deserialization |
1906 // cannot be deferred, since post processing requires the object content. | 1928 // cannot be deferred, since post processing requires the object content. |
1907 if (recursion.ExceedsMaximum() && CanBeDeferred(object_)) { | 1929 if (recursion.ExceedsMaximum() && CanBeDeferred(object_)) { |
1908 serializer_->QueueDeferredObject(object_); | 1930 serializer_->QueueDeferredObject(object_); |
1909 sink_->Put(kDeferred, "Deferring object content"); | 1931 sink_->Put(kDeferred, "Deferring object content"); |
1910 return; | 1932 return; |
1911 } | 1933 } |
1912 | 1934 |
| 1935 UnlinkWeakCellScope unlink_weak_cell(object_); |
| 1936 |
1913 object_->IterateBody(map->instance_type(), size, this); | 1937 object_->IterateBody(map->instance_type(), size, this); |
1914 OutputRawData(object_->address() + size); | 1938 OutputRawData(object_->address() + size); |
1915 } | 1939 } |
1916 | 1940 |
1917 | 1941 |
1918 void Serializer::ObjectSerializer::SerializeDeferred() { | 1942 void Serializer::ObjectSerializer::SerializeDeferred() { |
1919 if (FLAG_trace_serializer) { | 1943 if (FLAG_trace_serializer) { |
1920 PrintF(" Encoding deferred heap object: "); | 1944 PrintF(" Encoding deferred heap object: "); |
1921 object_->ShortPrint(); | 1945 object_->ShortPrint(); |
1922 PrintF("\n"); | 1946 PrintF("\n"); |
1923 } | 1947 } |
1924 | 1948 |
1925 int size = object_->Size(); | 1949 int size = object_->Size(); |
1926 Map* map = object_->map(); | 1950 Map* map = object_->map(); |
1927 BackReference reference = serializer_->back_reference_map()->Lookup(object_); | 1951 BackReference reference = serializer_->back_reference_map()->Lookup(object_); |
1928 | 1952 |
1929 // Serialize the rest of the object. | 1953 // Serialize the rest of the object. |
1930 CHECK_EQ(0, bytes_processed_so_far_); | 1954 CHECK_EQ(0, bytes_processed_so_far_); |
1931 bytes_processed_so_far_ = kPointerSize; | 1955 bytes_processed_so_far_ = kPointerSize; |
1932 | 1956 |
1933 sink_->Put(kNewObject + reference.space(), "deferred object"); | 1957 sink_->Put(kNewObject + reference.space(), "deferred object"); |
1934 serializer_->PutBackReference(object_, reference); | 1958 serializer_->PutBackReference(object_, reference); |
1935 sink_->PutInt(size >> kPointerSizeLog2, "deferred object size"); | 1959 sink_->PutInt(size >> kPointerSizeLog2, "deferred object size"); |
1936 | 1960 |
| 1961 UnlinkWeakCellScope unlink_weak_cell(object_); |
| 1962 |
1937 object_->IterateBody(map->instance_type(), size, this); | 1963 object_->IterateBody(map->instance_type(), size, this); |
1938 OutputRawData(object_->address() + size); | 1964 OutputRawData(object_->address() + size); |
1939 } | 1965 } |
1940 | 1966 |
1941 | 1967 |
1942 void Serializer::ObjectSerializer::VisitPointers(Object** start, | 1968 void Serializer::ObjectSerializer::VisitPointers(Object** start, |
1943 Object** end) { | 1969 Object** end) { |
1944 Object** current = start; | 1970 Object** current = start; |
1945 while (current < end) { | 1971 while (current < end) { |
1946 while (current < end && (*current)->IsSmi()) current++; | 1972 while (current < end && (*current)->IsSmi()) current++; |
(...skipping 761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2708 SerializedCodeData* scd = new SerializedCodeData(cached_data); | 2734 SerializedCodeData* scd = new SerializedCodeData(cached_data); |
2709 SanityCheckResult r = scd->SanityCheck(isolate, source); | 2735 SanityCheckResult r = scd->SanityCheck(isolate, source); |
2710 if (r == CHECK_SUCCESS) return scd; | 2736 if (r == CHECK_SUCCESS) return scd; |
2711 cached_data->Reject(); | 2737 cached_data->Reject(); |
2712 source->GetIsolate()->counters()->code_cache_reject_reason()->AddSample(r); | 2738 source->GetIsolate()->counters()->code_cache_reject_reason()->AddSample(r); |
2713 delete scd; | 2739 delete scd; |
2714 return NULL; | 2740 return NULL; |
2715 } | 2741 } |
2716 } // namespace internal | 2742 } // namespace internal |
2717 } // namespace v8 | 2743 } // namespace v8 |
OLD | NEW |