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/snapshot/serialize.h" | 5 #include "src/snapshot/serialize.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 1954 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1965 // Since the allocation size is rounded up to object alignment, there | 1965 // Since the allocation size is rounded up to object alignment, there |
1966 // maybe left-over bytes that need to be padded. | 1966 // maybe left-over bytes that need to be padded. |
1967 int padding_size = allocation_size - SeqString::kHeaderSize - content_size; | 1967 int padding_size = allocation_size - SeqString::kHeaderSize - content_size; |
1968 DCHECK(0 <= padding_size && padding_size < kObjectAlignment); | 1968 DCHECK(0 <= padding_size && padding_size < kObjectAlignment); |
1969 for (int i = 0; i < padding_size; i++) sink_->PutSection(0, "StringPadding"); | 1969 for (int i = 0; i < padding_size; i++) sink_->PutSection(0, "StringPadding"); |
1970 | 1970 |
1971 sink_->Put(kSkip, "SkipAfterString"); | 1971 sink_->Put(kSkip, "SkipAfterString"); |
1972 sink_->PutInt(bytes_to_output, "SkipDistance"); | 1972 sink_->PutInt(bytes_to_output, "SkipDistance"); |
1973 } | 1973 } |
1974 | 1974 |
1975 | 1975 // Clear and later restore the next link in the weak cell or allocation site. |
1976 // Clear and later restore the next link in the weak cell, if the object is one. | 1976 // TODO(all): replace this with proper iteration of weak slots in serializer. |
1977 class UnlinkWeakCellScope { | 1977 class UnlinkWeakNextScope { |
1978 public: | 1978 public: |
1979 explicit UnlinkWeakCellScope(HeapObject* object) : weak_cell_(NULL) { | 1979 explicit UnlinkWeakNextScope(HeapObject* object) : object_(nullptr) { |
1980 if (object->IsWeakCell()) { | 1980 if (object->IsWeakCell()) { |
1981 weak_cell_ = WeakCell::cast(object); | 1981 object_ = object; |
1982 next_ = weak_cell_->next(); | 1982 next_ = WeakCell::cast(object)->next(); |
1983 weak_cell_->clear_next(object->GetHeap()->the_hole_value()); | 1983 WeakCell::cast(object)->clear_next(object->GetHeap()->the_hole_value()); |
| 1984 } else if (object->IsAllocationSite()) { |
| 1985 object_ = object; |
| 1986 next_ = AllocationSite::cast(object)->weak_next(); |
| 1987 AllocationSite::cast(object) |
| 1988 ->set_weak_next(object->GetHeap()->undefined_value()); |
1984 } | 1989 } |
1985 } | 1990 } |
1986 | 1991 |
1987 ~UnlinkWeakCellScope() { | 1992 ~UnlinkWeakNextScope() { |
1988 if (weak_cell_) weak_cell_->set_next(next_, UPDATE_WEAK_WRITE_BARRIER); | 1993 if (object_ != nullptr) { |
| 1994 if (object_->IsWeakCell()) { |
| 1995 WeakCell::cast(object_)->set_next(next_, UPDATE_WEAK_WRITE_BARRIER); |
| 1996 } else { |
| 1997 AllocationSite::cast(object_) |
| 1998 ->set_weak_next(next_, UPDATE_WEAK_WRITE_BARRIER); |
| 1999 } |
| 2000 } |
1989 } | 2001 } |
1990 | 2002 |
1991 private: | 2003 private: |
1992 WeakCell* weak_cell_; | 2004 HeapObject* object_; |
1993 Object* next_; | 2005 Object* next_; |
1994 DisallowHeapAllocation no_gc_; | 2006 DisallowHeapAllocation no_gc_; |
1995 }; | 2007 }; |
1996 | 2008 |
1997 | 2009 |
1998 void Serializer::ObjectSerializer::Serialize() { | 2010 void Serializer::ObjectSerializer::Serialize() { |
1999 if (FLAG_trace_serializer) { | 2011 if (FLAG_trace_serializer) { |
2000 PrintF(" Encoding heap object: "); | 2012 PrintF(" Encoding heap object: "); |
2001 object_->ShortPrint(); | 2013 object_->ShortPrint(); |
2002 PrintF("\n"); | 2014 PrintF("\n"); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2040 | 2052 |
2041 RecursionScope recursion(serializer_); | 2053 RecursionScope recursion(serializer_); |
2042 // Objects that are immediately post processed during deserialization | 2054 // Objects that are immediately post processed during deserialization |
2043 // cannot be deferred, since post processing requires the object content. | 2055 // cannot be deferred, since post processing requires the object content. |
2044 if (recursion.ExceedsMaximum() && CanBeDeferred(object_)) { | 2056 if (recursion.ExceedsMaximum() && CanBeDeferred(object_)) { |
2045 serializer_->QueueDeferredObject(object_); | 2057 serializer_->QueueDeferredObject(object_); |
2046 sink_->Put(kDeferred, "Deferring object content"); | 2058 sink_->Put(kDeferred, "Deferring object content"); |
2047 return; | 2059 return; |
2048 } | 2060 } |
2049 | 2061 |
2050 UnlinkWeakCellScope unlink_weak_cell(object_); | 2062 UnlinkWeakNextScope unlink_weak_next(object_); |
2051 | 2063 |
2052 object_->IterateBody(map->instance_type(), size, this); | 2064 object_->IterateBody(map->instance_type(), size, this); |
2053 OutputRawData(object_->address() + size); | 2065 OutputRawData(object_->address() + size); |
2054 } | 2066 } |
2055 | 2067 |
2056 | 2068 |
2057 void Serializer::ObjectSerializer::SerializeDeferred() { | 2069 void Serializer::ObjectSerializer::SerializeDeferred() { |
2058 if (FLAG_trace_serializer) { | 2070 if (FLAG_trace_serializer) { |
2059 PrintF(" Encoding deferred heap object: "); | 2071 PrintF(" Encoding deferred heap object: "); |
2060 object_->ShortPrint(); | 2072 object_->ShortPrint(); |
2061 PrintF("\n"); | 2073 PrintF("\n"); |
2062 } | 2074 } |
2063 | 2075 |
2064 int size = object_->Size(); | 2076 int size = object_->Size(); |
2065 Map* map = object_->map(); | 2077 Map* map = object_->map(); |
2066 BackReference reference = serializer_->back_reference_map()->Lookup(object_); | 2078 BackReference reference = serializer_->back_reference_map()->Lookup(object_); |
2067 | 2079 |
2068 // Serialize the rest of the object. | 2080 // Serialize the rest of the object. |
2069 CHECK_EQ(0, bytes_processed_so_far_); | 2081 CHECK_EQ(0, bytes_processed_so_far_); |
2070 bytes_processed_so_far_ = kPointerSize; | 2082 bytes_processed_so_far_ = kPointerSize; |
2071 | 2083 |
2072 serializer_->PutAlignmentPrefix(object_); | 2084 serializer_->PutAlignmentPrefix(object_); |
2073 sink_->Put(kNewObject + reference.space(), "deferred object"); | 2085 sink_->Put(kNewObject + reference.space(), "deferred object"); |
2074 serializer_->PutBackReference(object_, reference); | 2086 serializer_->PutBackReference(object_, reference); |
2075 sink_->PutInt(size >> kPointerSizeLog2, "deferred object size"); | 2087 sink_->PutInt(size >> kPointerSizeLog2, "deferred object size"); |
2076 | 2088 |
2077 UnlinkWeakCellScope unlink_weak_cell(object_); | 2089 UnlinkWeakNextScope unlink_weak_next(object_); |
2078 | 2090 |
2079 object_->IterateBody(map->instance_type(), size, this); | 2091 object_->IterateBody(map->instance_type(), size, this); |
2080 OutputRawData(object_->address() + size); | 2092 OutputRawData(object_->address() + size); |
2081 } | 2093 } |
2082 | 2094 |
2083 | 2095 |
2084 void Serializer::ObjectSerializer::VisitPointers(Object** start, | 2096 void Serializer::ObjectSerializer::VisitPointers(Object** start, |
2085 Object** end) { | 2097 Object** end) { |
2086 Object** current = start; | 2098 Object** current = start; |
2087 while (current < end) { | 2099 while (current < end) { |
(...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2856 SerializedCodeData* scd = new SerializedCodeData(cached_data); | 2868 SerializedCodeData* scd = new SerializedCodeData(cached_data); |
2857 SanityCheckResult r = scd->SanityCheck(isolate, source); | 2869 SanityCheckResult r = scd->SanityCheck(isolate, source); |
2858 if (r == CHECK_SUCCESS) return scd; | 2870 if (r == CHECK_SUCCESS) return scd; |
2859 cached_data->Reject(); | 2871 cached_data->Reject(); |
2860 source->GetIsolate()->counters()->code_cache_reject_reason()->AddSample(r); | 2872 source->GetIsolate()->counters()->code_cache_reject_reason()->AddSample(r); |
2861 delete scd; | 2873 delete scd; |
2862 return NULL; | 2874 return NULL; |
2863 } | 2875 } |
2864 } // namespace internal | 2876 } // namespace internal |
2865 } // namespace v8 | 2877 } // namespace v8 |
OLD | NEW |