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

Side by Side Diff: test/cctest/test-serialize.cc

Issue 536077: Implement enough of the partial snapshots that we can deserialize... (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
« no previous file with comments | « src/v8.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2007-2008 the V8 project authors. All rights reserved. 1 // Copyright 2007-2010 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
11 // with the distribution. 11 // with the distribution.
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 v8::Local<v8::String> source = v8::String::New(c_source); 276 v8::Local<v8::String> source = v8::String::New(c_source);
277 v8::Local<v8::Script> script = v8::Script::Compile(source); 277 v8::Local<v8::Script> script = v8::Script::Compile(source);
278 CHECK_EQ(4, script->Run()->Int32Value()); 278 CHECK_EQ(4, script->Run()->Int32Value());
279 } 279 }
280 280
281 281
282 class FileByteSink : public SnapshotByteSink { 282 class FileByteSink : public SnapshotByteSink {
283 public: 283 public:
284 explicit FileByteSink(const char* snapshot_file) { 284 explicit FileByteSink(const char* snapshot_file) {
285 fp_ = OS::FOpen(snapshot_file, "wb"); 285 fp_ = OS::FOpen(snapshot_file, "wb");
286 file_name_ = snapshot_file;
286 if (fp_ == NULL) { 287 if (fp_ == NULL) {
287 PrintF("Unable to write to snapshot file \"%s\"\n", snapshot_file); 288 PrintF("Unable to write to snapshot file \"%s\"\n", snapshot_file);
288 exit(1); 289 exit(1);
289 } 290 }
290 } 291 }
291 virtual ~FileByteSink() { 292 virtual ~FileByteSink() {
292 if (fp_ != NULL) { 293 if (fp_ != NULL) {
293 fclose(fp_); 294 fclose(fp_);
294 } 295 }
295 } 296 }
296 virtual void Put(int byte, const char* description) { 297 virtual void Put(int byte, const char* description) {
297 if (fp_ != NULL) { 298 if (fp_ != NULL) {
298 fputc(byte, fp_); 299 fputc(byte, fp_);
299 } 300 }
300 } 301 }
302 void WriteSpaceUsed(
303 int new_space_used,
304 int pointer_space_used,
305 int data_space_used,
306 int code_space_used,
307 int map_space_used,
308 int cell_space_used,
309 int large_space_used);
301 310
302 private: 311 private:
303 FILE* fp_; 312 FILE* fp_;
313 const char* file_name_;
304 }; 314 };
305 315
306 316
317 void FileByteSink::WriteSpaceUsed(
318 int new_space_used,
319 int pointer_space_used,
320 int data_space_used,
321 int code_space_used,
322 int map_space_used,
323 int cell_space_used,
324 int large_space_used) {
325 int file_name_length = strlen(file_name_) + 10;
326 Vector<char> name = Vector<char>::New(file_name_length + 1);
327 OS::SNPrintF(name, "%s.size", file_name_);
328 FILE* fp = OS::FOpen(name.start(), "wa");
329 fprintf(fp, "new %d\n", new_space_used);
330 fprintf(fp, "pointer %d\n", pointer_space_used);
331 fprintf(fp, "data %d\n", data_space_used);
332 fprintf(fp, "code %d\n", code_space_used);
333 fprintf(fp, "map %d\n", map_space_used);
334 fprintf(fp, "cell %d\n", cell_space_used);
335 fprintf(fp, "large %d\n", large_space_used);
336 fclose(fp);
337 }
338
339
307 TEST(PartialSerialization) { 340 TEST(PartialSerialization) {
308 Serializer::Enable(); 341 Serializer::Enable();
309 v8::V8::Initialize(); 342 v8::V8::Initialize();
310 v8::Persistent<v8::Context> env = v8::Context::New(); 343 v8::Persistent<v8::Context> env = v8::Context::New();
311 env->Enter(); 344 env->Enter();
312 345
313 v8::HandleScope handle_scope; 346 v8::HandleScope handle_scope;
314 v8::Local<v8::String> foo = v8::String::New("foo"); 347 v8::Local<v8::String> foo = v8::String::New("foo");
315 348
316 FileByteSink file(FLAG_testing_serialization_file); 349 FileByteSink file(FLAG_testing_serialization_file);
317 Serializer ser(&file); 350 Serializer ser(&file);
318 i::Handle<i::String> internal_foo = v8::Utils::OpenHandle(*foo); 351 i::Handle<i::String> internal_foo = v8::Utils::OpenHandle(*foo);
319 Object* raw_foo = *internal_foo; 352 Object* raw_foo = *internal_foo;
320 ser.SerializePartial(&raw_foo); 353 ser.SerializePartial(&raw_foo);
354 file.WriteSpaceUsed(ser.CurrentAllocationAddress(NEW_SPACE),
355 ser.CurrentAllocationAddress(OLD_POINTER_SPACE),
356 ser.CurrentAllocationAddress(OLD_DATA_SPACE),
357 ser.CurrentAllocationAddress(CODE_SPACE),
358 ser.CurrentAllocationAddress(MAP_SPACE),
359 ser.CurrentAllocationAddress(CELL_SPACE),
360 ser.CurrentAllocationAddress(LO_SPACE));
361 }
362
363
364 DEPENDENT_TEST(PartialDeserialization, PartialSerialization) {
365 v8::V8::Initialize();
366 const char* file_name = FLAG_testing_serialization_file;
367 int file_name_length = strlen(file_name) + 10;
368 Vector<char> name = Vector<char>::New(file_name_length + 1);
369 OS::SNPrintF(name, "%s.size", file_name);
370 FILE* fp = OS::FOpen(name.start(), "ra");
371 int new_size, pointer_size, data_size, code_size, map_size, cell_size, large_s ize;
Mads Ager (chromium) 2010/01/15 14:11:22 Line length.
372 CHECK_EQ(1, fscanf(fp, "new %d\n", &new_size));
373 CHECK_EQ(1, fscanf(fp, "pointer %d\n", &pointer_size));
374 CHECK_EQ(1, fscanf(fp, "data %d\n", &data_size));
375 CHECK_EQ(1, fscanf(fp, "code %d\n", &code_size));
376 CHECK_EQ(1, fscanf(fp, "map %d\n", &map_size));
377 CHECK_EQ(1, fscanf(fp, "cell %d\n", &cell_size));
378 CHECK_EQ(1, fscanf(fp, "large %d\n", &large_size));
379 fclose(fp);
380 Heap::ReserveSpace(new_size,
381 pointer_size,
382 data_size,
383 code_size,
384 map_size,
385 cell_size,
386 large_size);
387 int snapshot_size = 0;
388 byte* snapshot = ReadBytes(file_name, &snapshot_size);
389 SnapshotByteSource source(snapshot, snapshot_size);
390 Deserializer deserializer(&source);
391 Object* root;
392 deserializer.DeserializePartial(&root);
393 CHECK(root->IsString());
321 } 394 }
322 395
323 396
324 TEST(LinearAllocation) { 397 TEST(LinearAllocation) {
325 v8::V8::Initialize(); 398 v8::V8::Initialize();
326 int new_space_max = 512 * KB; 399 int new_space_max = 512 * KB;
327 for (int size = 1000; size < 5 * MB; size += size >> 1) { 400 for (int size = 1000; size < 5 * MB; size += size >> 1) {
328 int new_space_size = (size < new_space_max) ? size : new_space_max; 401 int new_space_size = (size < new_space_max) ? size : new_space_max;
329 Heap::ReserveSpace( 402 Heap::ReserveSpace(
330 new_space_size, 403 new_space_size,
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 TEST(TestThatAlwaysFails) { 502 TEST(TestThatAlwaysFails) {
430 bool ArtificialFailure = false; 503 bool ArtificialFailure = false;
431 CHECK(ArtificialFailure); 504 CHECK(ArtificialFailure);
432 } 505 }
433 506
434 507
435 DEPENDENT_TEST(DependentTestThatAlwaysFails, TestThatAlwaysSucceeds) { 508 DEPENDENT_TEST(DependentTestThatAlwaysFails, TestThatAlwaysSucceeds) {
436 bool ArtificialFailure2 = false; 509 bool ArtificialFailure2 = false;
437 CHECK(ArtificialFailure2); 510 CHECK(ArtificialFailure2);
438 } 511 }
OLDNEW
« no previous file with comments | « src/v8.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698