OLD | NEW |
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 #include "vm/snapshot.h" | 5 #include "vm/snapshot.h" |
6 | 6 |
7 #include "platform/assert.h" | 7 #include "platform/assert.h" |
8 #include "vm/bootstrap.h" | 8 #include "vm/bootstrap.h" |
9 #include "vm/class_finalizer.h" | 9 #include "vm/class_finalizer.h" |
10 #include "vm/dart.h" | 10 #include "vm/dart.h" |
(...skipping 2208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2219 return false; | 2219 return false; |
2220 } | 2220 } |
2221 | 2221 |
2222 | 2222 |
2223 void SnapshotWriter::WriteObjectImpl(RawObject* raw, bool as_reference) { | 2223 void SnapshotWriter::WriteObjectImpl(RawObject* raw, bool as_reference) { |
2224 // First check if object can be written as a simple predefined type. | 2224 // First check if object can be written as a simple predefined type. |
2225 if (CheckAndWritePredefinedObject(raw)) { | 2225 if (CheckAndWritePredefinedObject(raw)) { |
2226 return; | 2226 return; |
2227 } | 2227 } |
2228 | 2228 |
2229 if (as_reference && !raw->IsCanonical()) { | 2229 // Objects are usually writen as references to avoid deep recursion, but in |
2230 WriteObjectRef(raw); | 2230 // some places we know we are dealing with leaf or shallow objects and write |
2231 } else { | 2231 // them inline. |
| 2232 // Code and Instructions are written inline so that Functions and Code |
| 2233 // can patch their entry points in their ReadFrom's. TODO(rmacnak): Remove the |
| 2234 // special case for Code and Instructions and patch entries after the whole |
| 2235 // graph has been loaded. |
| 2236 if (!as_reference || |
| 2237 raw->IsCanonical() || |
| 2238 raw->IsCode() || |
| 2239 raw->IsInstructions()) { |
2232 // Object is being serialized, add it to the forward ref list and mark | 2240 // Object is being serialized, add it to the forward ref list and mark |
2233 // it so that future references to this object in the snapshot will use | 2241 // it so that future references to this object in the snapshot will use |
2234 // an object id, instead of trying to serialize it again. | 2242 // an object id, instead of trying to serialize it again. |
2235 forward_list_->MarkAndAddObject(raw, kIsSerialized); | 2243 forward_list_->MarkAndAddObject(raw, kIsSerialized); |
2236 | 2244 |
2237 WriteInlinedObject(raw); | 2245 WriteInlinedObject(raw); |
| 2246 } else { |
| 2247 WriteObjectRef(raw); |
2238 } | 2248 } |
2239 } | 2249 } |
2240 | 2250 |
2241 | 2251 |
2242 void SnapshotWriter::WriteObjectRef(RawObject* raw) { | 2252 void SnapshotWriter::WriteObjectRef(RawObject* raw) { |
2243 NoSafepointScope no_safepoint; | 2253 NoSafepointScope no_safepoint; |
2244 RawClass* cls = class_table_->At(raw->GetClassId()); | 2254 RawClass* cls = class_table_->At(raw->GetClassId()); |
2245 intptr_t class_id = cls->ptr()->id_; | 2255 intptr_t class_id = cls->ptr()->id_; |
2246 ASSERT(class_id == raw->GetClassId()); | 2256 ASSERT(class_id == raw->GetClassId()); |
2247 if (class_id >= kNumPredefinedCids || | 2257 if (class_id >= kNumPredefinedCids || |
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2801 NoSafepointScope no_safepoint; | 2811 NoSafepointScope no_safepoint; |
2802 WriteObject(obj.raw()); | 2812 WriteObject(obj.raw()); |
2803 UnmarkAll(); | 2813 UnmarkAll(); |
2804 } else { | 2814 } else { |
2805 ThrowException(exception_type(), exception_msg()); | 2815 ThrowException(exception_type(), exception_msg()); |
2806 } | 2816 } |
2807 } | 2817 } |
2808 | 2818 |
2809 | 2819 |
2810 } // namespace dart | 2820 } // namespace dart |
OLD | NEW |