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

Side by Side Diff: src/serialize.cc

Issue 545026: Add some interfaces to the GC that allow us to reserve space. This is needed... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 10 years, 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 900 matching lines...) Expand 10 before | Expand all | Expand 10 after
911 character = *tag++; 911 character = *tag++;
912 sink_->PutSection(character, "TagCharacter"); 912 sink_->PutSection(character, "TagCharacter");
913 } while (character != 0); 913 } while (character != 0);
914 } 914 }
915 915
916 #endif 916 #endif
917 917
918 Serializer::Serializer(SnapshotByteSink* sink) 918 Serializer::Serializer(SnapshotByteSink* sink)
919 : sink_(sink), 919 : sink_(sink),
920 current_root_index_(0), 920 current_root_index_(0),
921 external_reference_encoder_(NULL) { 921 external_reference_encoder_(NULL),
922 partial_(false) {
922 for (int i = 0; i <= LAST_SPACE; i++) { 923 for (int i = 0; i <= LAST_SPACE; i++) {
923 fullness_[i] = 0; 924 fullness_[i] = 0;
924 } 925 }
925 } 926 }
926 927
927 928
928 void Serializer::Serialize() { 929 void Serializer::Serialize() {
929 // No active threads. 930 // No active threads.
930 CHECK_EQ(NULL, ThreadState::FirstInUse()); 931 CHECK_EQ(NULL, ThreadState::FirstInUse());
931 // No active or weak handles. 932 // No active or weak handles.
932 CHECK(HandleScopeImplementer::instance()->blocks()->is_empty()); 933 CHECK(HandleScopeImplementer::instance()->blocks()->is_empty());
933 CHECK_EQ(0, GlobalHandles::NumberOfWeakHandles()); 934 CHECK_EQ(0, GlobalHandles::NumberOfWeakHandles());
934 CHECK_EQ(NULL, external_reference_encoder_); 935 CHECK_EQ(NULL, external_reference_encoder_);
935 // We don't support serializing installed extensions. 936 // We don't support serializing installed extensions.
936 for (RegisteredExtension* ext = RegisteredExtension::first_extension(); 937 for (RegisteredExtension* ext = RegisteredExtension::first_extension();
937 ext != NULL; 938 ext != NULL;
938 ext = ext->next()) { 939 ext = ext->next()) {
939 CHECK_NE(v8::INSTALLED, ext->state()); 940 CHECK_NE(v8::INSTALLED, ext->state());
940 } 941 }
941 external_reference_encoder_ = new ExternalReferenceEncoder(); 942 external_reference_encoder_ = new ExternalReferenceEncoder();
942 Heap::IterateRoots(this, VISIT_ONLY_STRONG); 943 Heap::IterateRoots(this, VISIT_ONLY_STRONG);
943 delete external_reference_encoder_; 944 delete external_reference_encoder_;
944 external_reference_encoder_ = NULL; 945 external_reference_encoder_ = NULL;
945 SerializationAddressMapper::Zap(); 946 SerializationAddressMapper::Zap();
946 } 947 }
947 948
948 949
950 void Serializer::SerializePartial(Object** object) {
951 partial_ = true;
952 external_reference_encoder_ = new ExternalReferenceEncoder();
953 this->VisitPointer(object);
954 delete external_reference_encoder_;
955 external_reference_encoder_ = NULL;
956 SerializationAddressMapper::Zap();
957 }
958
959
949 void Serializer::VisitPointers(Object** start, Object** end) { 960 void Serializer::VisitPointers(Object** start, Object** end) {
950 for (Object** current = start; current < end; current++) { 961 for (Object** current = start; current < end; current++) {
951 if ((*current)->IsSmi()) { 962 if ((*current)->IsSmi()) {
952 sink_->Put(RAW_DATA_SERIALIZATION, "RawData"); 963 sink_->Put(RAW_DATA_SERIALIZATION, "RawData");
953 sink_->PutInt(kPointerSize, "length"); 964 sink_->PutInt(kPointerSize, "length");
954 for (int i = 0; i < kPointerSize; i++) { 965 for (int i = 0; i < kPointerSize; i++) {
955 sink_->Put(reinterpret_cast<byte*>(current)[i], "Byte"); 966 sink_->Put(reinterpret_cast<byte*>(current)[i], "Byte");
956 } 967 }
957 } else { 968 } else {
958 SerializeObject(*current, TAGGED_REPRESENTATION); 969 SerializeObject(*current, TAGGED_REPRESENTATION);
959 } 970 }
960 } 971 }
961 } 972 }
962 973
963 974
975 int Serializer::RootIndex(HeapObject* heap_object) {
976 for (int i = 0; i < Heap::kRootListLength; i++) {
977 Object* root = Heap::roots_address()[i];
978 if (root == heap_object) return i;
979 }
980 return kInvalidRootIndex;
981 }
982
983
964 void Serializer::SerializeObject( 984 void Serializer::SerializeObject(
965 Object* o, 985 Object* o,
966 ReferenceRepresentation reference_representation) { 986 ReferenceRepresentation reference_representation) {
967 CHECK(o->IsHeapObject()); 987 CHECK(o->IsHeapObject());
968 HeapObject* heap_object = HeapObject::cast(o); 988 HeapObject* heap_object = HeapObject::cast(o);
989 if (partial_) {
990 int root_index = RootIndex(heap_object);
991 if (root_index != kInvalidRootIndex) {
992 sink_->Put(ROOT_SERIALIZATION, "RootSerialization");
993 sink_->PutInt(root_index, "root_index");
994 return;
995 }
996 // TODO(erikcorry): Handle symbols here.
997 }
969 if (SerializationAddressMapper::IsMapped(heap_object)) { 998 if (SerializationAddressMapper::IsMapped(heap_object)) {
970 int space = SpaceOfAlreadySerializedObject(heap_object); 999 int space = SpaceOfAlreadySerializedObject(heap_object);
971 int address = SerializationAddressMapper::MappedTo(heap_object); 1000 int address = SerializationAddressMapper::MappedTo(heap_object);
972 int offset = CurrentAllocationAddress(space) - address; 1001 int offset = CurrentAllocationAddress(space) - address;
973 bool from_start = true; 1002 bool from_start = true;
974 if (SpaceIsPaged(space)) { 1003 if (SpaceIsPaged(space)) {
975 if ((CurrentAllocationAddress(space) >> kPageSizeBits) == 1004 if ((CurrentAllocationAddress(space) >> kPageSizeBits) ==
976 (address >> kPageSizeBits)) { 1005 (address >> kPageSizeBits)) {
977 from_start = false; 1006 from_start = false;
978 address = offset; 1007 address = offset;
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
1221 fullness_[space] = RoundUp(fullness_[space], Page::kPageSize); 1250 fullness_[space] = RoundUp(fullness_[space], Page::kPageSize);
1222 } 1251 }
1223 } 1252 }
1224 int allocation_address = fullness_[space]; 1253 int allocation_address = fullness_[space];
1225 fullness_[space] = allocation_address + size; 1254 fullness_[space] = allocation_address + size;
1226 return allocation_address; 1255 return allocation_address;
1227 } 1256 }
1228 1257
1229 1258
1230 } } // namespace v8::internal 1259 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698