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

Side by Side Diff: runtime/vm/snapshot.cc

Issue 1336763002: Last snapshot bits to get working precompiled hello_world on x64. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 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 #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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 field_(Field::Handle(zone_)), 191 field_(Field::Handle(zone_)),
192 str_(String::Handle(zone_)), 192 str_(String::Handle(zone_)),
193 library_(Library::Handle(zone_)), 193 library_(Library::Handle(zone_)),
194 type_(AbstractType::Handle(zone_)), 194 type_(AbstractType::Handle(zone_)),
195 type_arguments_(TypeArguments::Handle(zone_)), 195 type_arguments_(TypeArguments::Handle(zone_)),
196 tokens_(Array::Handle(zone_)), 196 tokens_(Array::Handle(zone_)),
197 stream_(TokenStream::Handle(zone_)), 197 stream_(TokenStream::Handle(zone_)),
198 data_(ExternalTypedData::Handle(zone_)), 198 data_(ExternalTypedData::Handle(zone_)),
199 typed_data_(TypedData::Handle(zone_)), 199 typed_data_(TypedData::Handle(zone_)),
200 code_(Code::Handle(zone_)), 200 code_(Code::Handle(zone_)),
201 function_(Function::Handle(zone_)),
202 megamorphic_cache_(MegamorphicCache::Handle(zone_)),
201 error_(UnhandledException::Handle(zone_)), 203 error_(UnhandledException::Handle(zone_)),
202 max_vm_isolate_object_id_( 204 max_vm_isolate_object_id_(
203 (kind == Snapshot::kFull) ? 205 (kind == Snapshot::kFull) ?
204 Object::vm_isolate_snapshot_object_table().Length() : 0), 206 Object::vm_isolate_snapshot_object_table().Length() : 0),
205 backward_references_(backward_refs), 207 backward_references_(backward_refs),
206 instructions_reader_(NULL) { 208 instructions_reader_(NULL) {
207 if (instructions_buffer != NULL) { 209 if (instructions_buffer != NULL) {
208 instructions_reader_ = new InstructionsReader(instructions_buffer); 210 instructions_reader_ = new InstructionsReader(instructions_buffer);
209 } 211 }
210 } 212 }
(...skipping 923 matching lines...) Expand 10 before | Expand all | Expand 10 after
1134 } 1136 }
1135 1137
1136 1138
1137 RawStacktrace* SnapshotReader::NewStacktrace() { 1139 RawStacktrace* SnapshotReader::NewStacktrace() {
1138 ALLOC_NEW_OBJECT(Stacktrace); 1140 ALLOC_NEW_OBJECT(Stacktrace);
1139 } 1141 }
1140 1142
1141 1143
1142 int32_t InstructionsWriter::GetOffsetFor(RawInstructions* instructions) { 1144 int32_t InstructionsWriter::GetOffsetFor(RawInstructions* instructions) {
1143 intptr_t offset = next_offset_; 1145 intptr_t offset = next_offset_;
1144 next_offset_ += instructions->Size(); 1146 next_offset_ += instructions->Size();
siva 2015/09/15 23:22:01 if you used instructions->SizeFromClass() you woul
rmacnak 2015/09/16 01:34:45 Using Instructions::InstanceSize instead.
1145 instructions_.Add(InstructionsData(instructions)); 1147 instructions_.Add(InstructionsData(instructions));
1146 return offset; 1148 return offset;
1147 } 1149 }
1148 1150
1149 1151
1150 static void EnsureIdentifier(char* label) { 1152 static void EnsureIdentifier(char* label) {
1151 for (char c = *label; c != '\0'; c = *++label) { 1153 for (char c = *label; c != '\0'; c = *++label) {
1152 if (((c >= 'a') && (c <= 'z')) || 1154 if (((c >= 'a') && (c <= 'z')) ||
1153 ((c >= 'A') && (c <= 'Z')) || 1155 ((c >= 'A') && (c <= 'Z')) ||
1154 ((c >= '0') && (c <= '9'))) { 1156 ((c >= '0') && (c <= '9'))) {
(...skipping 11 matching lines...) Expand all
1166 // will allocate on the Dart heap. 1168 // will allocate on the Dart heap.
1167 for (intptr_t i = 0; i < instructions_.length(); i++) { 1169 for (intptr_t i = 0; i < instructions_.length(); i++) {
1168 InstructionsData& data = instructions_[i]; 1170 InstructionsData& data = instructions_[i];
1169 data.insns_ = &Instructions::Handle(Z, data.raw_insns_); 1171 data.insns_ = &Instructions::Handle(Z, data.raw_insns_);
1170 ASSERT(data.raw_code_ != NULL); 1172 ASSERT(data.raw_code_ != NULL);
1171 data.code_ = &Code::Handle(Z, data.raw_code_); 1173 data.code_ = &Code::Handle(Z, data.raw_code_);
1172 } 1174 }
1173 1175
1174 stream_.Print(".text\n"); 1176 stream_.Print(".text\n");
1175 stream_.Print(".globl _kInstructionsSnapshot\n"); 1177 stream_.Print(".globl _kInstructionsSnapshot\n");
1176 stream_.Print(".balign %" Pd ", 0\n", OS::PreferredCodeAlignment()); 1178 stream_.Print(".balign %" Pd ", 0\n", OS::kMaxPreferredCodeAlignment);
1177 stream_.Print("_kInstructionsSnapshot:\n"); 1179 stream_.Print("_kInstructionsSnapshot:\n");
1178 1180
1181 // This head also provides the gap to make the instructions snapshot
1182 // look like a HeapPage.
1183 intptr_t instructions_length = next_offset_;
1184 WriteWordLiteral(instructions_length);
1185 intptr_t header_words = HeaderSize() / sizeof(uword);
1186 for (intptr_t i = 1; i < header_words; i++) {
1187 WriteWordLiteral(0);
1188 }
1189
1179 Object& owner = Object::Handle(Z); 1190 Object& owner = Object::Handle(Z);
1180 String& str = String::Handle(Z); 1191 String& str = String::Handle(Z);
1181 1192
1182 for (intptr_t i = 0; i < instructions_.length(); i++) { 1193 for (intptr_t i = 0; i < instructions_.length(); i++) {
1183 const Instructions& insns = *instructions_[i].insns_; 1194 const Instructions& insns = *instructions_[i].insns_;
1184 const Code& code = *instructions_[i].code_; 1195 const Code& code = *instructions_[i].code_;
1185 1196
1186 ASSERT(insns.raw()->Size() % sizeof(uint64_t) == 0); 1197 ASSERT(insns.raw()->Size() % sizeof(uint64_t) == 0);
1187 1198
1188 { 1199 {
1189 // 1. Write from the header to the entry point. 1200 // 1. Write from the header to the entry point.
1190 NoSafepointScope no_safepoint; 1201 NoSafepointScope no_safepoint;
1191 uword beginning = reinterpret_cast<uword>(insns.raw()) - kHeapObjectTag; 1202
1203 uword beginning = reinterpret_cast<uword>(insns.raw_ptr());
1192 uword entry = beginning + Instructions::HeaderSize(); 1204 uword entry = beginning + Instructions::HeaderSize();
1193 1205
1194 ASSERT(Utils::IsAligned(beginning, sizeof(uint64_t))); 1206 ASSERT(Utils::IsAligned(beginning, sizeof(uint64_t)));
1195 ASSERT(Utils::IsAligned(entry, sizeof(uint64_t))); 1207 ASSERT(Utils::IsAligned(entry, sizeof(uint64_t)));
1196 1208
1197 for (uint64_t* cursor = reinterpret_cast<uint64_t*>(beginning); 1209 // Write Instructions with the mark and VM heap bits set.
1198 cursor < reinterpret_cast<uint64_t*>(entry); 1210 uword marked_tags = insns.raw_ptr()->tags_;
1211 marked_tags = RawObject::VMHeapObjectTag::update(true, marked_tags);
1212 marked_tags = RawObject::MarkBit::update(true, marked_tags);
1213
1214 WriteWordLiteral(marked_tags);
1215 beginning += sizeof(uword);
1216
1217 for (uword* cursor = reinterpret_cast<uword*>(beginning);
1218 cursor < reinterpret_cast<uword*>(entry);
1199 cursor++) { 1219 cursor++) {
1200 stream_.Print(".quad 0x%0.16" Px64 "\n", *cursor); 1220 WriteWordLiteral(*cursor);
1201 } 1221 }
1202 } 1222 }
1203 1223
1204 // 2. Write a label at the entry point. 1224 // 2. Write a label at the entry point.
1205 owner = code.owner(); 1225 owner = code.owner();
1206 if (owner.IsNull()) { 1226 if (owner.IsNull()) {
1207 const char* name = StubCode::NameOfStub(insns.EntryPoint()); 1227 const char* name = StubCode::NameOfStub(insns.EntryPoint());
1208 stream_.Print("Precompiled_Stub_%s:\n", name); 1228 stream_.Print("Precompiled_Stub_%s:\n", name);
1209 } else if (owner.IsClass()) { 1229 } else if (owner.IsClass()) {
1210 str = Class::Cast(owner).Name(); 1230 str = Class::Cast(owner).Name();
(...skipping 12 matching lines...) Expand all
1223 // 3. Write from the entry point to the end. 1243 // 3. Write from the entry point to the end.
1224 NoSafepointScope no_safepoint; 1244 NoSafepointScope no_safepoint;
1225 uword beginning = reinterpret_cast<uword>(insns.raw()) - kHeapObjectTag; 1245 uword beginning = reinterpret_cast<uword>(insns.raw()) - kHeapObjectTag;
1226 uword entry = beginning + Instructions::HeaderSize(); 1246 uword entry = beginning + Instructions::HeaderSize();
1227 uword end = beginning + insns.raw()->Size(); 1247 uword end = beginning + insns.raw()->Size();
1228 1248
1229 ASSERT(Utils::IsAligned(beginning, sizeof(uint64_t))); 1249 ASSERT(Utils::IsAligned(beginning, sizeof(uint64_t)));
1230 ASSERT(Utils::IsAligned(entry, sizeof(uint64_t))); 1250 ASSERT(Utils::IsAligned(entry, sizeof(uint64_t)));
1231 ASSERT(Utils::IsAligned(end, sizeof(uint64_t))); 1251 ASSERT(Utils::IsAligned(end, sizeof(uint64_t)));
1232 1252
1233 for (uint64_t* cursor = reinterpret_cast<uint64_t*>(entry); 1253 for (uword* cursor = reinterpret_cast<uword*>(entry);
1234 cursor < reinterpret_cast<uint64_t*>(end); 1254 cursor < reinterpret_cast<uword*>(end);
1235 cursor++) { 1255 cursor++) {
1236 stream_.Print(".quad 0x%0.16" Px64 "\n", *cursor); 1256 WriteWordLiteral(*cursor);
1237 } 1257 }
1238 } 1258 }
1239 } 1259 }
1240 } 1260 }
1241 1261
1242 1262
1243 RawInstructions* InstructionsReader::GetInstructionsAt(int32_t offset, 1263 RawInstructions* InstructionsReader::GetInstructionsAt(int32_t offset,
1244 uword expected_tags) { 1264 uword expected_tags) {
1245 ASSERT(Utils::IsAligned(offset, OS::PreferredCodeAlignment())); 1265 ASSERT(Utils::IsAligned(offset, OS::PreferredCodeAlignment()));
1246 1266
1247 RawInstructions* result = 1267 RawInstructions* result =
1248 reinterpret_cast<RawInstructions*>( 1268 reinterpret_cast<RawInstructions*>(
1249 reinterpret_cast<uword>(buffer_) + offset + kHeapObjectTag); 1269 reinterpret_cast<uword>(buffer_) + offset + kHeapObjectTag);
1250 1270
1251 uword actual_tags = result->ptr()->tags_; 1271 uword actual_tags = result->ptr()->tags_;
1252 if (actual_tags != expected_tags) { 1272 if (actual_tags != expected_tags) {
1253 FATAL2("Instructions tag mismatch: expected %" Pd ", saw %" Pd, 1273 FATAL2("Instructions tag mismatch: expected %" Pd ", saw %" Pd,
1254 expected_tags, 1274 expected_tags,
1255 actual_tags); 1275 actual_tags);
1256 } 1276 }
1257 1277
1258 // TODO(rmacnak): The above contains stale pointers to a Code and an 1278 ASSERT(result->IsMarked());
1259 // ObjectPool. Return the actual result after calling convention change. 1279
1260 return Instructions::null(); 1280 return result;
1261 } 1281 }
1262 1282
1263 1283
1264 intptr_t SnapshotReader::LookupInternalClass(intptr_t class_header) { 1284 intptr_t SnapshotReader::LookupInternalClass(intptr_t class_header) {
1265 // If the header is an object Id, lookup singleton VM classes or classes 1285 // If the header is an object Id, lookup singleton VM classes or classes
1266 // stored in the object store. 1286 // stored in the object store.
1267 if (IsVMIsolateObject(class_header)) { 1287 if (IsVMIsolateObject(class_header)) {
1268 intptr_t class_id = GetVMIsolateObjectId(class_header); 1288 intptr_t class_id = GetVMIsolateObjectId(class_header);
1269 ASSERT(IsSingletonClassId(class_id)); 1289 ASSERT(IsSingletonClassId(class_id));
1270 return class_id; 1290 return class_id;
(...skipping 1517 matching lines...) Expand 10 before | Expand all | Expand 10 after
2788 NoSafepointScope no_safepoint; 2808 NoSafepointScope no_safepoint;
2789 WriteObject(obj.raw()); 2809 WriteObject(obj.raw());
2790 UnmarkAll(); 2810 UnmarkAll();
2791 } else { 2811 } else {
2792 ThrowException(exception_type(), exception_msg()); 2812 ThrowException(exception_type(), exception_msg());
2793 } 2813 }
2794 } 2814 }
2795 2815
2796 2816
2797 } // namespace dart 2817 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698