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

Side by Side Diff: src/vm/program.cc

Issue 2067483002: More compact snapshots. (Closed) Base URL: git@github.com:dartino/sdk.git@master
Patch Set: Feedback Created 4 years, 6 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 | « src/vm/program.h ('k') | src/vm/session.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) 2014, the Dartino project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dartino 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.md file. 3 // BSD-style license that can be found in the LICENSE.md file.
4 4
5 #include "src/vm/program.h" 5 #include "src/vm/program.h"
6 6
7 #include <stdlib.h> 7 #include <stdlib.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include "src/shared/assert.h" 10 #include "src/shared/assert.h"
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 119
120 AddToProcessList(process); 120 AddToProcessList(process);
121 return process; 121 return process;
122 } 122 }
123 123
124 Process* Program::ProcessSpawnForMain(List<List<uint8>> arguments) { 124 Process* Program::ProcessSpawnForMain(List<List<uint8>> arguments) {
125 if (Flags::print_program_statistics) { 125 if (Flags::print_program_statistics) {
126 PrintStatistics(); 126 PrintStatistics();
127 } 127 }
128 128
129 VerifyObjectPlacements();
130
129 Process* process = SpawnProcess(NULL); 131 Process* process = SpawnProcess(NULL);
130 132
131 // TODO(erikcorry): This is not valid for multiple programs, where the 133 // TODO(erikcorry): This is not valid for multiple programs, where the
132 // process creation could fail. 134 // process creation could fail.
133 ASSERT(!process->AllocationFailed()); 135 ASSERT(!process->AllocationFailed());
134 136
135 process->set_arguments(arguments); 137 process->set_arguments(arguments);
136 138
137 Stack* stack = process->stack(); 139 Stack* stack = process->stack();
138 140
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 347
346 void Program::FinishProgramGC() { 348 void Program::FinishProgramGC() {
347 // Uncook process 349 // Uncook process
348 UncookAndUnchainStacks(); 350 UncookAndUnchainStacks();
349 351
350 FinishProgramGCVisitor visitor; 352 FinishProgramGCVisitor visitor;
351 VisitProcesses(&visitor); 353 VisitProcesses(&visitor);
352 354
353 if (debug_info_ != NULL) debug_info_->UpdateBreakpoints(); 355 if (debug_info_ != NULL) debug_info_->UpdateBreakpoints();
354 356
357 VerifyObjectPlacements();
358
355 if (Flags::validate_heaps) ValidateHeapsAreConsistent(); 359 if (Flags::validate_heaps) ValidateHeapsAreConsistent();
356 } 360 }
357 361
358 uword Program::OffsetOf(HeapObject* object) { 362 uword Program::OffsetOf(HeapObject* object) {
359 ASSERT(is_optimized()); 363 ASSERT(is_optimized());
360 return heap()->space()->OffsetOf(object); 364 return heap()->space()->OffsetOf(object);
361 } 365 }
362 366
363 HeapObject *Program::ObjectAtOffset(uword offset) { 367 HeapObject *Program::ObjectAtOffset(uword offset) {
364 ASSERT(was_loaded_from_snapshot()); 368 ASSERT(was_loaded_from_snapshot());
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
798 // allocations, instead allocate new chunks. 802 // allocations, instead allocate new chunks.
799 NoAllocationFailureScope scope(heap_.space()); 803 NoAllocationFailureScope scope(heap_.space());
800 804
801 // Create null as the first object other allocated objects can use 805 // Create null as the first object other allocated objects can use
802 // null_object for initial values. 806 // null_object for initial values.
803 InstanceFormat null_format = 807 InstanceFormat null_format =
804 InstanceFormat::instance_format(0, InstanceFormat::NULL_MARKER); 808 InstanceFormat::instance_format(0, InstanceFormat::NULL_MARKER);
805 null_object_ = 809 null_object_ =
806 reinterpret_cast<Instance*>(heap()->Allocate(null_format.fixed_size())); 810 reinterpret_cast<Instance*>(heap()->Allocate(null_format.fixed_size()));
807 811
812 InstanceFormat false_format =
813 InstanceFormat::instance_format(0, InstanceFormat::FALSE_MARKER);
814 uword false_address =
815 HeapObject::cast(heap()->Allocate(false_format.fixed_size()))->address();
816 InstanceFormat true_format =
817 InstanceFormat::instance_format(0, InstanceFormat::TRUE_MARKER);
818 uword true_address =
819 HeapObject::cast(heap()->Allocate(true_format.fixed_size()))->address();
820
808 meta_class_ = Class::cast(heap()->CreateMetaClass()); 821 meta_class_ = Class::cast(heap()->CreateMetaClass());
809 822
810 { 823 {
811 InstanceFormat format = InstanceFormat::array_format(); 824 InstanceFormat format = InstanceFormat::array_format();
812 array_class_ = 825 array_class_ =
813 Class::cast(heap()->CreateClass(format, meta_class_, null_object_)); 826 Class::cast(heap()->CreateClass(format, meta_class_, null_object_));
814 } 827 }
815 828
816 empty_array_ = Array::cast(CreateArray(0)); 829 empty_array_ = Array::cast(CreateArray(0));
817 830
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
984 } 997 }
985 998
986 { // Create the bool class. 999 { // Create the bool class.
987 InstanceFormat format = InstanceFormat::instance_format(0); 1000 InstanceFormat format = InstanceFormat::instance_format(0);
988 bool_class_ = 1001 bool_class_ =
989 Class::cast(heap()->CreateClass(format, meta_class_, null_object_)); 1002 Class::cast(heap()->CreateClass(format, meta_class_, null_object_));
990 bool_class_->set_super_class(object_class_); 1003 bool_class_->set_super_class(object_class_);
991 } 1004 }
992 1005
993 { // Create False class and the false object. 1006 { // Create False class and the false object.
994 InstanceFormat format = 1007 Class* false_class = Class::cast(
995 InstanceFormat::instance_format(0, InstanceFormat::FALSE_MARKER); 1008 heap()->CreateClass(false_format, meta_class_, null_object_));
996 Class* false_class =
997 Class::cast(heap()->CreateClass(format, meta_class_, null_object_));
998 false_class->set_super_class(bool_class_); 1009 false_class->set_super_class(bool_class_);
999 false_class->set_methods(empty_array_); 1010 false_class->set_methods(empty_array_);
1000 false_object_ = Instance::cast( 1011 false_object_ = Instance::cast(
1001 heap()->CreateInstance(false_class, null_object(), true)); 1012 heap()->CreateBooleanObject(false_address, false_class, null_object()));
1002 } 1013 }
1003 1014
1004 { // Create True class and the true object. 1015 { // Create True class and the true object.
1005 InstanceFormat format = 1016 Class* true_class = Class::cast(
1006 InstanceFormat::instance_format(0, InstanceFormat::TRUE_MARKER); 1017 heap()->CreateClass(true_format, meta_class_, null_object_));
1007 Class* true_class =
1008 Class::cast(heap()->CreateClass(format, meta_class_, null_object_));
1009 true_class->set_super_class(bool_class_); 1018 true_class->set_super_class(bool_class_);
1010 true_class->set_methods(empty_array_); 1019 true_class->set_methods(empty_array_);
1011 true_object_ = 1020 true_object_ = Instance::cast(
1012 Instance::cast(heap()->CreateInstance(true_class, null_object(), true)); 1021 heap()->CreateBooleanObject(true_address, true_class, null_object()));
1013 } 1022 }
1014 1023
1015 { // Create stack overflow error object. 1024 { // Create stack overflow error object.
1016 InstanceFormat format = InstanceFormat::instance_format(0); 1025 InstanceFormat format = InstanceFormat::instance_format(0);
1017 stack_overflow_error_class_ = 1026 stack_overflow_error_class_ =
1018 Class::cast(heap()->CreateClass(format, meta_class_, null_object_)); 1027 Class::cast(heap()->CreateClass(format, meta_class_, null_object_));
1019 stack_overflow_error_ = Instance::cast(heap()->CreateInstance( 1028 stack_overflow_error_ = Instance::cast(heap()->CreateInstance(
1020 stack_overflow_error_class_, null_object(), true)); 1029 stack_overflow_error_class_, null_object(), true));
1021 } 1030 }
1022 1031
1023 // Create the retry after gc failure object payload. 1032 // Create the retry after gc failure object payload.
1024 raw_retry_after_gc_ = OneByteString::cast( 1033 raw_retry_after_gc_ = OneByteString::cast(
1025 CreateStringFromAscii(StringFromCharZ("Retry after GC."))); 1034 CreateStringFromAscii(StringFromCharZ("Retry after GC.")));
1026 1035
1027 // Create the failure object payloads. These need to be kept in sync with the 1036 // Create the failure object payloads. These need to be kept in sync with the
1028 // constants in lib/system/system.dart. 1037 // constants in lib/system/system.dart.
1029 raw_wrong_argument_type_ = OneByteString::cast( 1038 raw_wrong_argument_type_ = OneByteString::cast(
1030 CreateStringFromAscii(StringFromCharZ("Wrong argument type."))); 1039 CreateStringFromAscii(StringFromCharZ("Wrong argument type.")));
1031 1040
1032 raw_index_out_of_bounds_ = OneByteString::cast( 1041 raw_index_out_of_bounds_ = OneByteString::cast(
1033 CreateStringFromAscii(StringFromCharZ("Index out of bounds."))); 1042 CreateStringFromAscii(StringFromCharZ("Index out of bounds.")));
1034 1043
1035 raw_illegal_state_ = OneByteString::cast( 1044 raw_illegal_state_ = OneByteString::cast(
1036 CreateStringFromAscii(StringFromCharZ("Illegal state."))); 1045 CreateStringFromAscii(StringFromCharZ("Illegal state.")));
1037 1046
1038 native_failure_result_ = null_object_; 1047 native_failure_result_ = null_object_;
1048 VerifyObjectPlacements();
1049 }
1050
1051 void Program::VerifyObjectPlacements() {
1052 uword n = reinterpret_cast<uword>(null_object_);
1053 uword f = reinterpret_cast<uword>(false_object_);
1054 uword t = reinterpret_cast<uword>(true_object_);
1055 ASSERT(f - n == 2 * kWordSize);
1056 ASSERT(t - f == 2 * kWordSize);
1039 } 1057 }
1040 1058
1041 void Program::IterateRoots(PointerVisitor* visitor) { 1059 void Program::IterateRoots(PointerVisitor* visitor) {
1060 VerifyObjectPlacements();
1061
1042 IterateRootsIgnoringSession(visitor); 1062 IterateRootsIgnoringSession(visitor);
1043 if (debug_info_ != NULL) { 1063 if (debug_info_ != NULL) {
1044 debug_info_->VisitProgramPointers(visitor); 1064 debug_info_->VisitProgramPointers(visitor);
1045 } 1065 }
1046 if (session_ != NULL) { 1066 if (session_ != NULL) {
1047 session_->IteratePointers(visitor); 1067 session_->IteratePointers(visitor);
1048 } 1068 }
1049 } 1069 }
1050 1070
1051 void Program::IterateRootsIgnoringSession(PointerVisitor* visitor) { 1071 void Program::IterateRootsIgnoringSession(PointerVisitor* visitor) {
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
1322 if (reinterpret_cast<Type*>(address) == field_name##_) { \ 1342 if (reinterpret_cast<Type*>(address) == field_name##_) { \
1323 fprintf(stderr, "0x%zx is " #field_name "\n", \ 1343 fprintf(stderr, "0x%zx is " #field_name "\n", \
1324 static_cast<size_t>(address)); \ 1344 static_cast<size_t>(address)); \
1325 } 1345 }
1326 ROOTS_DO(CHECK_FOR_ROOT) 1346 ROOTS_DO(CHECK_FOR_ROOT)
1327 #undef CHECK_FOR_ROOT 1347 #undef CHECK_FOR_ROOT
1328 } 1348 }
1329 #endif 1349 #endif
1330 1350
1331 } // namespace dartino 1351 } // namespace dartino
OLDNEW
« no previous file with comments | « src/vm/program.h ('k') | src/vm/session.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698