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

Side by Side Diff: src/serialize.h

Issue 564035: Remove lazy loading of natives files and the natives cache.... (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/partial_snapshots/
Patch Set: Created 10 years, 10 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
« no previous file with comments | « src/runtime.cc ('k') | src/serialize.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 2006-2009 the V8 project authors. All rights reserved. 1 // Copyright 2006-2009 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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 SnapshotByteSource(const byte* array, int length) 113 SnapshotByteSource(const byte* array, int length)
114 : data_(array), length_(length), position_(0) { } 114 : data_(array), length_(length), position_(0) { }
115 115
116 bool HasMore() { return position_ < length_; } 116 bool HasMore() { return position_ < length_; }
117 117
118 int Get() { 118 int Get() {
119 ASSERT(position_ < length_); 119 ASSERT(position_ < length_);
120 return data_[position_++]; 120 return data_[position_++];
121 } 121 }
122 122
123 void CopyRaw(byte* to, int number_of_bytes) { 123 inline void CopyRaw(byte* to, int number_of_bytes);
124 memcpy(to, data_ + position_, number_of_bytes);
125 position_ += number_of_bytes;
126 }
127 124
128 int GetInt() { 125 inline int GetInt();
129 // A little unwind to catch the really small ints.
130 int snapshot_byte = Get();
131 if ((snapshot_byte & 0x80) == 0) {
132 return snapshot_byte;
133 }
134 int accumulator = (snapshot_byte & 0x7f) << 7;
135 while (true) {
136 snapshot_byte = Get();
137 if ((snapshot_byte & 0x80) == 0) {
138 return accumulator | snapshot_byte;
139 }
140 accumulator = (accumulator | (snapshot_byte & 0x7f)) << 7;
141 }
142 UNREACHABLE();
143 return accumulator;
144 }
145 126
146 bool AtEOF() { 127 bool AtEOF() {
147 return position_ == length_; 128 return position_ == length_;
148 } 129 }
149 130
150 int position() { return position_; } 131 int position() { return position_; }
151 132
152 private: 133 private:
153 const byte* data_; 134 const byte* data_;
154 int length_; 135 int length_;
(...skipping 30 matching lines...) Expand all
185 f(14, 32) \ 166 f(14, 32) \
186 f(15, 36) 167 f(15, 36)
187 168
188 // The Serializer/Deserializer class is a common superclass for Serializer and 169 // The Serializer/Deserializer class is a common superclass for Serializer and
189 // Deserializer which is used to store common constants and methods used by 170 // Deserializer which is used to store common constants and methods used by
190 // both. 171 // both.
191 class SerializerDeserializer: public ObjectVisitor { 172 class SerializerDeserializer: public ObjectVisitor {
192 public: 173 public:
193 static void Iterate(ObjectVisitor* visitor); 174 static void Iterate(ObjectVisitor* visitor);
194 static void SetSnapshotCacheSize(int size); 175 static void SetSnapshotCacheSize(int size);
176 #ifdef DEBUG
177 static void StartTracing() { tracing_ = true; }
178 static void StopTracing() { tracing_ = false; }
179 static void Trace(const char *msg, int arg) { if (tracing_) printf("%s %d\n", msg, arg); }
180 static void Trace(const char *msg, const char* arg) { if (tracing_) printf("%s %s\n", msg, arg); }
181 static void Trace(const char *msg, const char* arg1, int arg2) { if (tracing_) printf("%s %s %d\n", msg, arg1, arg2); }
182 static bool tracing() { return tracing_; }
183 #else
184 static void StartTracing() { }
185 static void StopTracing() { }
186 static void Trace(const char *msg, int arg) { }
187 static void Trace(const char *msg, const char* arg) { }
188 static void Trace(const char *msg, const char* arg1, int arg2) { }
189 static bool tracing() { return false; }
190 #endif
195 191
196 protected: 192 protected:
197 enum DataType { 193 enum DataType {
198 RAW_DATA_SERIALIZATION = 0, 194 RAW_DATA_SERIALIZATION = 0,
199 // And 15 common raw lengths. 195 // And 15 common raw lengths.
200 OBJECT_SERIALIZATION = 16, 196 OBJECT_SERIALIZATION = 16,
201 // One variant per space. 197 // One variant per space.
202 CODE_OBJECT_SERIALIZATION = 25, 198 CODE_OBJECT_SERIALIZATION = 25,
203 // One per space (only code spaces in use). 199 // One per space (only code spaces in use).
204 EXTERNAL_REFERENCE_SERIALIZATION = 34, 200 EXTERNAL_REFERENCE_SERIALIZATION = 34,
(...skipping 25 matching lines...) Expand all
230 static const int kSpaceMask = 15; 226 static const int kSpaceMask = 15;
231 227
232 static inline bool SpaceIsLarge(int space) { return space >= kLargeData; } 228 static inline bool SpaceIsLarge(int space) { return space >= kLargeData; }
233 static inline bool SpaceIsPaged(int space) { 229 static inline bool SpaceIsPaged(int space) {
234 return space >= FIRST_PAGED_SPACE && space <= LAST_PAGED_SPACE; 230 return space >= FIRST_PAGED_SPACE && space <= LAST_PAGED_SPACE;
235 } 231 }
236 232
237 static int partial_snapshot_cache_length_; 233 static int partial_snapshot_cache_length_;
238 static const int kPartialSnapshotCacheCapacity = 1024; 234 static const int kPartialSnapshotCacheCapacity = 1024;
239 static Object* partial_snapshot_cache_[]; 235 static Object* partial_snapshot_cache_[];
236 static bool tracing_;
240 }; 237 };
241 238
242 239
240 int SnapshotByteSource::GetInt() {
241 // A little unwind to catch the really small ints.
242 int snapshot_byte = Get();
243 if ((snapshot_byte & 0x80) == 0) {
244 SerializerDeserializer::Trace("Tag IntLastPart", snapshot_byte);
245 return snapshot_byte;
246 }
247 SerializerDeserializer::Trace("Tag IntPart", snapshot_byte);
248 int accumulator = (snapshot_byte & 0x7f) << 7;
249 while (true) {
250 snapshot_byte = Get();
251 if ((snapshot_byte & 0x80) == 0) {
252 SerializerDeserializer::Trace("Tag IntLastPart", snapshot_byte);
253 return accumulator | snapshot_byte;
254 }
255 SerializerDeserializer::Trace("Tag IntPart", snapshot_byte);
256 accumulator = (accumulator | (snapshot_byte & 0x7f)) << 7;
257 }
258 UNREACHABLE();
259 return accumulator;
260 }
261
262
263 void SnapshotByteSource::CopyRaw(byte* to, int number_of_bytes) {
264 if (SerializerDeserializer::tracing()) {
265 for (int i = 0; i < number_of_bytes; i++) {
266 SerializerDeserializer::Trace("Tag Byte", data_[position_ + i]);
267 }
268 }
269 memcpy(to, data_ + position_, number_of_bytes);
270 position_ += number_of_bytes;
271 }
272
243 273
244 // A Deserializer reads a snapshot and reconstructs the Object graph it defines. 274 // A Deserializer reads a snapshot and reconstructs the Object graph it defines.
245 class Deserializer: public SerializerDeserializer { 275 class Deserializer: public SerializerDeserializer {
246 public: 276 public:
247 // Create a deserializer from a snapshot byte source. 277 // Create a deserializer from a snapshot byte source.
248 explicit Deserializer(SnapshotByteSource* source); 278 explicit Deserializer(SnapshotByteSource* source);
249 279
250 virtual ~Deserializer(); 280 virtual ~Deserializer();
251 281
252 // Deserialize the snapshot into an empty heap. 282 // Deserialize the snapshot into an empty heap.
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 SerializeWeakReferences(); 553 SerializeWeakReferences();
524 } 554 }
525 555
526 private: 556 private:
527 virtual int RootIndex(HeapObject* o) { return kInvalidRootIndex; } 557 virtual int RootIndex(HeapObject* o) { return kInvalidRootIndex; }
528 virtual bool ShouldBeInThePartialSnapshotCache(HeapObject* o) { 558 virtual bool ShouldBeInThePartialSnapshotCache(HeapObject* o) {
529 return false; 559 return false;
530 } 560 }
531 }; 561 };
532 562
563
533 } } // namespace v8::internal 564 } } // namespace v8::internal
534 565
535 #endif // V8_SERIALIZE_H_ 566 #endif // V8_SERIALIZE_H_
OLDNEW
« no previous file with comments | « src/runtime.cc ('k') | src/serialize.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698