OLD | NEW |
---|---|
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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
80 uint32_t max_counters_; | 80 uint32_t max_counters_; |
81 uint32_t max_name_size_; | 81 uint32_t max_name_size_; |
82 uint32_t counters_in_use_; | 82 uint32_t counters_in_use_; |
83 Counter counters_[kMaxCounters]; | 83 Counter counters_[kMaxCounters]; |
84 }; | 84 }; |
85 | 85 |
86 | 86 |
87 class Compressor { | 87 class Compressor { |
88 public: | 88 public: |
89 virtual ~Compressor() {} | 89 virtual ~Compressor() {} |
90 virtual bool Compress(i::Vector<char> input) = 0; | 90 virtual bool Compress(i::Vector<unsigned char> input) = 0; |
91 virtual i::Vector<char>* output() = 0; | 91 virtual i::Vector<unsigned char>* output() = 0; |
92 }; | 92 }; |
93 | 93 |
94 | 94 |
95 class PartialSnapshotSink : public i::SnapshotByteSink { | 95 class PartialSnapshotSink : public i::SnapshotByteSink { |
96 public: | 96 public: |
97 PartialSnapshotSink() : data_(), raw_size_(-1) { } | 97 PartialSnapshotSink() : data_(), raw_size_(-1) { } |
98 virtual ~PartialSnapshotSink() { data_.Free(); } | 98 virtual ~PartialSnapshotSink() { data_.Free(); } |
99 virtual void Put(int byte, const char* description) { | 99 virtual void Put(int byte, const char* description) { |
100 data_.Add(byte); | 100 data_.Add(byte); |
101 } | 101 } |
102 virtual int Position() { return data_.length(); } | 102 virtual int Position() { return data_.length(); } |
103 void Print(FILE* fp) { | 103 void Print(FILE* fp) { |
104 int length = Position(); | 104 int length = Position(); |
105 for (int j = 0; j < length; j++) { | 105 for (int j = 0; j < length; j++) { |
106 if ((j & 0x1f) == 0x1f) { | 106 if ((j & 0x1f) == 0x1f) { |
107 fprintf(fp, "\n"); | 107 fprintf(fp, "\n"); |
108 } | 108 } |
109 if (j != 0) { | 109 if (j != 0) { |
110 fprintf(fp, ","); | 110 fprintf(fp, ","); |
111 } | 111 } |
112 fprintf(fp, "%d", at(j)); | 112 fprintf(fp, "%d", at(j)); |
Vyacheslav Egorov (Chromium)
2011/12/12 18:06:17
Instead of using unsigned char you can probably ju
Tobias Burnus
2011/12/12 21:54:00
I agree that the patch will be shorter. I am not s
| |
113 } | 113 } |
114 } | 114 } |
115 char at(int i) { return data_[i]; } | 115 unsigned char at(int i) { return data_[i]; } |
116 bool Compress(Compressor* compressor) { | 116 bool Compress(Compressor* compressor) { |
117 ASSERT_EQ(-1, raw_size_); | 117 ASSERT_EQ(-1, raw_size_); |
118 raw_size_ = data_.length(); | 118 raw_size_ = data_.length(); |
119 if (!compressor->Compress(data_.ToVector())) return false; | 119 if (!compressor->Compress(data_.ToVector())) return false; |
120 data_.Clear(); | 120 data_.Clear(); |
121 data_.AddAll(*compressor->output()); | 121 data_.AddAll(*compressor->output()); |
122 return true; | 122 return true; |
123 } | 123 } |
124 int raw_size() { return raw_size_; } | 124 int raw_size() { return raw_size_; } |
125 | 125 |
126 private: | 126 private: |
127 i::List<char> data_; | 127 i::List<unsigned char> data_; |
128 int raw_size_; | 128 int raw_size_; |
129 }; | 129 }; |
130 | 130 |
131 | 131 |
132 class CppByteSink : public PartialSnapshotSink { | 132 class CppByteSink : public PartialSnapshotSink { |
133 public: | 133 public: |
134 explicit CppByteSink(const char* snapshot_file) { | 134 explicit CppByteSink(const char* snapshot_file) { |
135 fp_ = i::OS::FOpen(snapshot_file, "wb"); | 135 fp_ = i::OS::FOpen(snapshot_file, "wb"); |
136 if (fp_ == NULL) { | 136 if (fp_ == NULL) { |
137 i::PrintF("Unable to write to snapshot file \"%s\"\n", snapshot_file); | 137 i::PrintF("Unable to write to snapshot file \"%s\"\n", snapshot_file); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
225 }; | 225 }; |
226 | 226 |
227 | 227 |
228 #ifdef COMPRESS_STARTUP_DATA_BZ2 | 228 #ifdef COMPRESS_STARTUP_DATA_BZ2 |
229 class BZip2Compressor : public Compressor { | 229 class BZip2Compressor : public Compressor { |
230 public: | 230 public: |
231 BZip2Compressor() : output_(NULL) {} | 231 BZip2Compressor() : output_(NULL) {} |
232 virtual ~BZip2Compressor() { | 232 virtual ~BZip2Compressor() { |
233 delete output_; | 233 delete output_; |
234 } | 234 } |
235 virtual bool Compress(i::Vector<char> input) { | 235 virtual bool Compress(i::Vector<unsigned char> input) { |
236 delete output_; | 236 delete output_; |
237 output_ = new i::ScopedVector<char>((input.length() * 101) / 100 + 1000); | 237 output_ = new i::ScopedVector<unsigned char>((input.length() * 101) / 100 |
Vyacheslav Egorov (Chromium)
2011/12/12 18:06:17
Usually we are leaving operation on the previous l
| |
238 + 1000); | |
238 unsigned int output_length_ = output_->length(); | 239 unsigned int output_length_ = output_->length(); |
239 int result = BZ2_bzBuffToBuffCompress(output_->start(), &output_length_, | 240 int result = BZ2_bzBuffToBuffCompress(output_->start(), &output_length_, |
240 input.start(), input.length(), | 241 input.start(), input.length(), |
241 9, 1, 0); | 242 9, 1, 0); |
242 if (result == BZ_OK) { | 243 if (result == BZ_OK) { |
243 output_->Truncate(output_length_); | 244 output_->Truncate(output_length_); |
244 return true; | 245 return true; |
245 } else { | 246 } else { |
246 fprintf(stderr, "bzlib error code: %d\n", result); | 247 fprintf(stderr, "bzlib error code: %d\n", result); |
247 return false; | 248 return false; |
248 } | 249 } |
249 } | 250 } |
250 virtual i::Vector<char>* output() { return output_; } | 251 virtual i::Vector<unsigned char>* output() { return output_; } |
251 | 252 |
252 private: | 253 private: |
253 i::ScopedVector<char>* output_; | 254 i::ScopedVector<unsigned char>* output_; |
254 }; | 255 }; |
255 | 256 |
256 | 257 |
257 class BZip2Decompressor : public StartupDataDecompressor { | 258 class BZip2Decompressor : public StartupDataDecompressor { |
258 public: | 259 public: |
259 virtual ~BZip2Decompressor() { } | 260 virtual ~BZip2Decompressor() { } |
260 | 261 |
261 protected: | 262 protected: |
262 virtual int DecompressData(char* raw_data, | 263 virtual int DecompressData(unsigned char* raw_data, |
263 int* raw_data_size, | 264 int* raw_data_size, |
264 const char* compressed_data, | 265 const char* compressed_data, |
265 int compressed_data_size) { | 266 int compressed_data_size) { |
266 ASSERT_EQ(StartupData::kBZip2, | 267 ASSERT_EQ(StartupData::kBZip2, |
267 V8::GetCompressedStartupDataAlgorithm()); | 268 V8::GetCompressedStartupDataAlgorithm()); |
268 unsigned int decompressed_size = *raw_data_size; | 269 unsigned int decompressed_size = *raw_data_size; |
269 int result = | 270 int result = |
270 BZ2_bzBuffToBuffDecompress(raw_data, | 271 BZ2_bzBuffToBuffDecompress(raw_data, |
271 &decompressed_size, | 272 &decompressed_size, |
272 const_cast<char*>(compressed_data), | 273 const_cast<unsigned char*>(compressed_data), |
273 compressed_data_size, | 274 compressed_data_size, |
274 0, 1); | 275 0, 1); |
275 if (result == BZ_OK) { | 276 if (result == BZ_OK) { |
276 *raw_data_size = decompressed_size; | 277 *raw_data_size = decompressed_size; |
277 } | 278 } |
278 return result; | 279 return result; |
279 } | 280 } |
280 }; | 281 }; |
281 #endif | 282 #endif |
282 | 283 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
339 sink.WriteSpaceUsed( | 340 sink.WriteSpaceUsed( |
340 partial_ser.CurrentAllocationAddress(i::NEW_SPACE), | 341 partial_ser.CurrentAllocationAddress(i::NEW_SPACE), |
341 partial_ser.CurrentAllocationAddress(i::OLD_POINTER_SPACE), | 342 partial_ser.CurrentAllocationAddress(i::OLD_POINTER_SPACE), |
342 partial_ser.CurrentAllocationAddress(i::OLD_DATA_SPACE), | 343 partial_ser.CurrentAllocationAddress(i::OLD_DATA_SPACE), |
343 partial_ser.CurrentAllocationAddress(i::CODE_SPACE), | 344 partial_ser.CurrentAllocationAddress(i::CODE_SPACE), |
344 partial_ser.CurrentAllocationAddress(i::MAP_SPACE), | 345 partial_ser.CurrentAllocationAddress(i::MAP_SPACE), |
345 partial_ser.CurrentAllocationAddress(i::CELL_SPACE), | 346 partial_ser.CurrentAllocationAddress(i::CELL_SPACE), |
346 partial_ser.CurrentAllocationAddress(i::LO_SPACE)); | 347 partial_ser.CurrentAllocationAddress(i::LO_SPACE)); |
347 return 0; | 348 return 0; |
348 } | 349 } |
OLD | NEW |