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

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

Issue 1808553002: Precompilation: don't include an object header for instructions in the text section. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 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
« no previous file with comments | « runtime/vm/snapshot.h ('k') | runtime/vm/stack_frame.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 (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 1124 matching lines...) Expand 10 before | Expand all | Expand 10 after
1135 } 1135 }
1136 return Mint::NewCanonical(value); 1136 return Mint::NewCanonical(value);
1137 } 1137 }
1138 1138
1139 1139
1140 RawStacktrace* SnapshotReader::NewStacktrace() { 1140 RawStacktrace* SnapshotReader::NewStacktrace() {
1141 ALLOC_NEW_OBJECT(Stacktrace); 1141 ALLOC_NEW_OBJECT(Stacktrace);
1142 } 1142 }
1143 1143
1144 1144
1145 int32_t InstructionsWriter::GetOffsetFor(RawInstructions* instructions) { 1145 int32_t InstructionsWriter::GetOffsetFor(RawInstructions* instructions,
1146 intptr_t heap_size = instructions->Size(); 1146 RawCode* code) {
1147 #if defined(PRODUCT)
1148 // Instructions are only dedup in product mode because it obfuscates profiler
1149 // results.
1150 for (intptr_t i = 0; i < instructions_.length(); i++) {
1151 if (instructions_[i].raw_insns_ == instructions) {
1152 return instructions_[i].offset_;
1153 }
1154 }
1155 #endif
1156
1157 intptr_t payload_size = instructions->ptr()->size_;
1158 payload_size = Utils::RoundUp(payload_size, OS::PreferredCodeAlignment());
1159
1147 intptr_t offset = next_offset_; 1160 intptr_t offset = next_offset_;
1148 next_offset_ += heap_size; 1161 ASSERT(Utils::IsAligned(next_offset_, OS::PreferredCodeAlignment()));
1149 instructions_.Add(InstructionsData(instructions)); 1162 next_offset_ += payload_size;
1163 ASSERT(Utils::IsAligned(next_offset_, OS::PreferredCodeAlignment()));
1164 instructions_.Add(InstructionsData(instructions, code, offset));
1165
1150 return offset; 1166 return offset;
1151 } 1167 }
1152 1168
1153 1169
1154 int32_t InstructionsWriter::GetObjectOffsetFor(RawObject* raw_object) { 1170 int32_t InstructionsWriter::GetObjectOffsetFor(RawObject* raw_object) {
1155 intptr_t heap_size = raw_object->Size(); 1171 intptr_t heap_size = raw_object->Size();
1156 intptr_t offset = next_object_offset_; 1172 intptr_t offset = next_object_offset_;
1157 next_object_offset_ += heap_size; 1173 next_object_offset_ += heap_size;
1158 objects_.Add(ObjectData(raw_object)); 1174 objects_.Add(ObjectData(raw_object));
1159 return offset; 1175 return offset;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1206 1222
1207 Object& owner = Object::Handle(zone); 1223 Object& owner = Object::Handle(zone);
1208 String& str = String::Handle(zone); 1224 String& str = String::Handle(zone);
1209 1225
1210 for (intptr_t i = 0; i < instructions_.length(); i++) { 1226 for (intptr_t i = 0; i < instructions_.length(); i++) {
1211 const Instructions& insns = *instructions_[i].insns_; 1227 const Instructions& insns = *instructions_[i].insns_;
1212 const Code& code = *instructions_[i].code_; 1228 const Code& code = *instructions_[i].code_;
1213 1229
1214 ASSERT(insns.raw()->Size() % sizeof(uint64_t) == 0); 1230 ASSERT(insns.raw()->Size() % sizeof(uint64_t) == 0);
1215 1231
1216 { 1232 // 1. Write a label at the entry point.
1217 // 1. Write from the header to the entry point.
1218 NoSafepointScope no_safepoint;
1219
1220 uword beginning = reinterpret_cast<uword>(insns.raw_ptr());
1221 uword entry = beginning + Instructions::HeaderSize();
1222
1223 ASSERT(Utils::IsAligned(beginning, sizeof(uint64_t)));
1224 ASSERT(Utils::IsAligned(entry, sizeof(uint64_t)));
1225
1226 // Write Instructions with the mark and VM heap bits set.
1227 uword marked_tags = insns.raw_ptr()->tags_;
1228 marked_tags = RawObject::VMHeapObjectTag::update(true, marked_tags);
1229 marked_tags = RawObject::MarkBit::update(true, marked_tags);
1230
1231 WriteWordLiteral(marked_tags);
1232 beginning += sizeof(uword);
1233
1234 for (uword* cursor = reinterpret_cast<uword*>(beginning);
1235 cursor < reinterpret_cast<uword*>(entry);
1236 cursor++) {
1237 WriteWordLiteral(*cursor);
1238 }
1239 }
1240
1241 // 2. Write a label at the entry point.
1242 owner = code.owner(); 1233 owner = code.owner();
1243 if (owner.IsNull()) { 1234 if (owner.IsNull()) {
1244 const char* name = StubCode::NameOfStub(insns.EntryPoint()); 1235 const char* name = StubCode::NameOfStub(insns.EntryPoint());
1245 stream_.Print("Precompiled_Stub_%s:\n", name); 1236 stream_.Print("Precompiled_Stub_%s:\n", name);
1246 } else if (owner.IsClass()) { 1237 } else if (owner.IsClass()) {
1247 str = Class::Cast(owner).Name(); 1238 str = Class::Cast(owner).Name();
1248 const char* name = str.ToCString(); 1239 const char* name = str.ToCString();
1249 EnsureIdentifier(const_cast<char*>(name)); 1240 EnsureIdentifier(const_cast<char*>(name));
1250 stream_.Print("Precompiled_AllocationStub_%s_%" Pd ":\n", name, i); 1241 stream_.Print("Precompiled_AllocationStub_%s_%" Pd ":\n", name, i);
1251 } else if (owner.IsFunction()) { 1242 } else if (owner.IsFunction()) {
1252 const char* name = Function::Cast(owner).ToQualifiedCString(); 1243 const char* name = Function::Cast(owner).ToQualifiedCString();
1253 EnsureIdentifier(const_cast<char*>(name)); 1244 EnsureIdentifier(const_cast<char*>(name));
1254 stream_.Print("Precompiled_%s_%" Pd ":\n", name, i); 1245 stream_.Print("Precompiled_%s_%" Pd ":\n", name, i);
1255 } else { 1246 } else {
1256 UNREACHABLE(); 1247 UNREACHABLE();
1257 } 1248 }
1258 1249
1259 { 1250 {
1260 // 3. Write from the entry point to the end. 1251 // 2. Write from the entry point to the end.
1261 NoSafepointScope no_safepoint; 1252 NoSafepointScope no_safepoint;
1262 uword beginning = reinterpret_cast<uword>(insns.raw()) - kHeapObjectTag; 1253 uword beginning = reinterpret_cast<uword>(insns.raw()) - kHeapObjectTag;
1263 uword entry = beginning + Instructions::HeaderSize(); 1254 uword entry = beginning + Instructions::HeaderSize();
1264 uword end = beginning + insns.raw()->Size(); 1255 uword payload_size = insns.size();
1256 payload_size = Utils::RoundUp(payload_size, OS::PreferredCodeAlignment());
1257 uword end = entry + payload_size;
1265 1258
1266 ASSERT(Utils::IsAligned(beginning, sizeof(uint64_t))); 1259 ASSERT(Utils::IsAligned(beginning, sizeof(uint64_t)));
1267 ASSERT(Utils::IsAligned(entry, sizeof(uint64_t))); 1260 ASSERT(Utils::IsAligned(entry, sizeof(uint64_t)));
1268 ASSERT(Utils::IsAligned(end, sizeof(uint64_t))); 1261 ASSERT(Utils::IsAligned(end, sizeof(uint64_t)));
1269 1262
1270 for (uword* cursor = reinterpret_cast<uword*>(entry); 1263 for (uword* cursor = reinterpret_cast<uword*>(entry);
1271 cursor < reinterpret_cast<uword*>(end); 1264 cursor < reinterpret_cast<uword*>(end);
1272 cursor++) { 1265 cursor++) {
1273 WriteWordLiteral(*cursor); 1266 WriteWordLiteral(*cursor);
1274 } 1267 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1306 start += sizeof(uword); 1299 start += sizeof(uword);
1307 for (uword* cursor = reinterpret_cast<uword*>(start); 1300 for (uword* cursor = reinterpret_cast<uword*>(start);
1308 cursor < reinterpret_cast<uword*>(end); 1301 cursor < reinterpret_cast<uword*>(end);
1309 cursor++) { 1302 cursor++) {
1310 WriteWordLiteral(*cursor); 1303 WriteWordLiteral(*cursor);
1311 } 1304 }
1312 } 1305 }
1313 } 1306 }
1314 1307
1315 1308
1316 RawInstructions* InstructionsReader::GetInstructionsAt(int32_t offset, 1309 uword InstructionsReader::GetInstructionsAt(int32_t offset) {
1317 uword expected_tags) {
1318 ASSERT(Utils::IsAligned(offset, OS::PreferredCodeAlignment())); 1310 ASSERT(Utils::IsAligned(offset, OS::PreferredCodeAlignment()));
1319 1311 return reinterpret_cast<uword>(instructions_buffer_) + offset;
1320 RawInstructions* result =
1321 reinterpret_cast<RawInstructions*>(
1322 reinterpret_cast<uword>(instructions_buffer_) +
1323 offset + kHeapObjectTag);
1324
1325 #ifdef DEBUG
1326 uword actual_tags = result->ptr()->tags_;
1327 if (actual_tags != expected_tags) {
1328 FATAL2("Instructions tag mismatch: expected %" Pd ", saw %" Pd,
1329 expected_tags,
1330 actual_tags);
1331 }
1332 #endif
1333
1334 ASSERT(result->IsMarked());
1335
1336 return result;
1337 } 1312 }
1338 1313
1339 1314
1340 RawObject* InstructionsReader::GetObjectAt(int32_t offset) { 1315 RawObject* InstructionsReader::GetObjectAt(int32_t offset) {
1341 ASSERT(Utils::IsAligned(offset, kWordSize)); 1316 ASSERT(Utils::IsAligned(offset, kWordSize));
1342 1317
1343 RawObject* result = 1318 RawObject* result =
1344 reinterpret_cast<RawObject*>( 1319 reinterpret_cast<RawObject*>(
1345 reinterpret_cast<uword>(data_buffer_) + offset + kHeapObjectTag); 1320 reinterpret_cast<uword>(data_buffer_) + offset + kHeapObjectTag);
1346 ASSERT(result->IsMarked()); 1321 ASSERT(result->IsMarked());
(...skipping 1340 matching lines...) Expand 10 before | Expand all | Expand 10 after
2687 if (setjmp(*jump.Set()) == 0) { 2662 if (setjmp(*jump.Set()) == 0) {
2688 NoSafepointScope no_safepoint; 2663 NoSafepointScope no_safepoint;
2689 WriteObject(obj.raw()); 2664 WriteObject(obj.raw());
2690 } else { 2665 } else {
2691 ThrowException(exception_type(), exception_msg()); 2666 ThrowException(exception_type(), exception_msg());
2692 } 2667 }
2693 } 2668 }
2694 2669
2695 2670
2696 } // namespace dart 2671 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/snapshot.h ('k') | runtime/vm/stack_frame.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698