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

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

Issue 146213004: A64: Synchronize with r16849. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/a64
Patch Set: Created 6 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 | « test/cctest/test-regexp.cc ('k') | test/cctest/test-spaces.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 2007-2010 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
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 return &local_counters[hash]; 77 return &local_counters[hash];
78 } 78 }
79 hash = (hash + 1) % kCounters; 79 hash = (hash + 1) % kCounters;
80 ASSERT(hash != original_hash); // Hash table has been filled up. 80 ASSERT(hash != original_hash); // Hash table has been filled up.
81 } 81 }
82 } 82 }
83 83
84 84
85 template <class T> 85 template <class T>
86 static Address AddressOf(T id) { 86 static Address AddressOf(T id) {
87 return ExternalReference(id, i::Isolate::Current()).address(); 87 return ExternalReference(id, CcTest::i_isolate()).address();
88 } 88 }
89 89
90 90
91 template <class T> 91 template <class T>
92 static uint32_t Encode(const ExternalReferenceEncoder& encoder, T id) { 92 static uint32_t Encode(const ExternalReferenceEncoder& encoder, T id) {
93 return encoder.Encode(AddressOf(id)); 93 return encoder.Encode(AddressOf(id));
94 } 94 }
95 95
96 96
97 static int make_code(TypeCode type, int id) { 97 static int make_code(TypeCode type, int id) {
98 return static_cast<uint32_t>(type) << kReferenceTypeShift | id; 98 return static_cast<uint32_t>(type) << kReferenceTypeShift | id;
99 } 99 }
100 100
101 101
102 TEST(ExternalReferenceEncoder) { 102 TEST(ExternalReferenceEncoder) {
103 Isolate* isolate = i::Isolate::Current(); 103 Isolate* isolate = CcTest::i_isolate();
104 isolate->stats_table()->SetCounterFunction(counter_function); 104 isolate->stats_table()->SetCounterFunction(counter_function);
105 v8::V8::Initialize(); 105 v8::V8::Initialize();
106 106
107 ExternalReferenceEncoder encoder(isolate); 107 ExternalReferenceEncoder encoder(isolate);
108 CHECK_EQ(make_code(BUILTIN, Builtins::kArrayCode), 108 CHECK_EQ(make_code(BUILTIN, Builtins::kArrayCode),
109 Encode(encoder, Builtins::kArrayCode)); 109 Encode(encoder, Builtins::kArrayCode));
110 CHECK_EQ(make_code(v8::internal::RUNTIME_FUNCTION, Runtime::kAbort), 110 CHECK_EQ(make_code(v8::internal::RUNTIME_FUNCTION, Runtime::kAbort),
111 Encode(encoder, Runtime::kAbort)); 111 Encode(encoder, Runtime::kAbort));
112 ExternalReference total_compile_size = 112 ExternalReference total_compile_size =
113 ExternalReference(isolate->counters()->total_compile_size()); 113 ExternalReference(isolate->counters()->total_compile_size());
(...skipping 16 matching lines...) Expand all
130 ExternalReference::new_space_start(isolate).address())); 130 ExternalReference::new_space_start(isolate).address()));
131 CHECK_EQ(make_code(UNCLASSIFIED, 3), 131 CHECK_EQ(make_code(UNCLASSIFIED, 3),
132 encoder.Encode( 132 encoder.Encode(
133 ExternalReference::roots_array_start(isolate).address())); 133 ExternalReference::roots_array_start(isolate).address()));
134 CHECK_EQ(make_code(UNCLASSIFIED, 52), 134 CHECK_EQ(make_code(UNCLASSIFIED, 52),
135 encoder.Encode(ExternalReference::cpu_features().address())); 135 encoder.Encode(ExternalReference::cpu_features().address()));
136 } 136 }
137 137
138 138
139 TEST(ExternalReferenceDecoder) { 139 TEST(ExternalReferenceDecoder) {
140 Isolate* isolate = i::Isolate::Current(); 140 Isolate* isolate = CcTest::i_isolate();
141 isolate->stats_table()->SetCounterFunction(counter_function); 141 isolate->stats_table()->SetCounterFunction(counter_function);
142 v8::V8::Initialize(); 142 v8::V8::Initialize();
143 143
144 ExternalReferenceDecoder decoder(isolate); 144 ExternalReferenceDecoder decoder(isolate);
145 CHECK_EQ(AddressOf(Builtins::kArrayCode), 145 CHECK_EQ(AddressOf(Builtins::kArrayCode),
146 decoder.Decode(make_code(BUILTIN, Builtins::kArrayCode))); 146 decoder.Decode(make_code(BUILTIN, Builtins::kArrayCode)));
147 CHECK_EQ(AddressOf(Runtime::kAbort), 147 CHECK_EQ(AddressOf(Runtime::kAbort),
148 decoder.Decode(make_code(v8::internal::RUNTIME_FUNCTION, 148 decoder.Decode(make_code(v8::internal::RUNTIME_FUNCTION,
149 Runtime::kAbort))); 149 Runtime::kAbort)));
150 ExternalReference total_compile_size = 150 ExternalReference total_compile_size =
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 244
245 return true; 245 return true;
246 } 246 }
247 247
248 248
249 static void Serialize() { 249 static void Serialize() {
250 // We have to create one context. One reason for this is so that the builtins 250 // We have to create one context. One reason for this is so that the builtins
251 // can be loaded from v8natives.js and their addresses can be processed. This 251 // can be loaded from v8natives.js and their addresses can be processed. This
252 // will clear the pending fixups array, which would otherwise contain GC roots 252 // will clear the pending fixups array, which would otherwise contain GC roots
253 // that would confuse the serialization/deserialization process. 253 // that would confuse the serialization/deserialization process.
254 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 254 v8::Isolate* isolate = CcTest::isolate();
255 { 255 {
256 v8::HandleScope scope(isolate); 256 v8::HandleScope scope(isolate);
257 v8::Context::New(isolate); 257 v8::Context::New(isolate);
258 } 258 }
259 WriteToFile(reinterpret_cast<Isolate*>(isolate), 259
260 FLAG_testing_serialization_file); 260 Isolate* internal_isolate = CcTest::i_isolate();
261 internal_isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, "serialize");
262 WriteToFile(internal_isolate, FLAG_testing_serialization_file);
261 } 263 }
262 264
263 265
264 // Test that the whole heap can be serialized. 266 // Test that the whole heap can be serialized.
265 TEST(Serialize) { 267 UNINITIALIZED_TEST(Serialize) {
266 if (!Snapshot::HaveASnapshotToStartFrom()) { 268 if (!Snapshot::HaveASnapshotToStartFrom()) {
267 Serializer::Enable(Isolate::Current()); 269 Serializer::Enable(CcTest::i_isolate());
268 v8::V8::Initialize(); 270 v8::V8::Initialize();
269 Serialize(); 271 Serialize();
270 } 272 }
271 } 273 }
272 274
273 275
274 // Test that heap serialization is non-destructive. 276 // Test that heap serialization is non-destructive.
275 TEST(SerializeTwice) { 277 UNINITIALIZED_TEST(SerializeTwice) {
276 if (!Snapshot::HaveASnapshotToStartFrom()) { 278 if (!Snapshot::HaveASnapshotToStartFrom()) {
277 Serializer::Enable(Isolate::Current()); 279 Serializer::Enable(CcTest::i_isolate());
278 v8::V8::Initialize(); 280 v8::V8::Initialize();
279 Serialize(); 281 Serialize();
280 Serialize(); 282 Serialize();
281 } 283 }
282 } 284 }
283 285
284 286
285 //---------------------------------------------------------------------------- 287 //----------------------------------------------------------------------------
286 // Tests that the heap can be deserialized. 288 // Tests that the heap can be deserialized.
287 289
288 static void Deserialize() { 290 static void Deserialize() {
289 CHECK(Snapshot::Initialize(FLAG_testing_serialization_file)); 291 CHECK(Snapshot::Initialize(FLAG_testing_serialization_file));
290 } 292 }
291 293
292 294
293 static void SanityCheck() { 295 static void SanityCheck() {
294 Isolate* isolate = Isolate::Current(); 296 Isolate* isolate = CcTest::i_isolate();
295 v8::HandleScope scope(v8::Isolate::GetCurrent()); 297 v8::HandleScope scope(CcTest::isolate());
296 #ifdef VERIFY_HEAP 298 #ifdef VERIFY_HEAP
297 HEAP->Verify(); 299 CcTest::heap()->Verify();
298 #endif 300 #endif
299 CHECK(isolate->global_object()->IsJSObject()); 301 CHECK(isolate->global_object()->IsJSObject());
300 CHECK(isolate->native_context()->IsContext()); 302 CHECK(isolate->native_context()->IsContext());
301 CHECK(HEAP->string_table()->IsStringTable()); 303 CHECK(CcTest::heap()->string_table()->IsStringTable());
302 CHECK(!isolate->factory()->InternalizeOneByteString( 304 CHECK(!isolate->factory()->InternalizeOneByteString(
303 STATIC_ASCII_VECTOR("Empty"))->IsFailure()); 305 STATIC_ASCII_VECTOR("Empty"))->IsFailure());
304 } 306 }
305 307
306 308
307 DEPENDENT_TEST(Deserialize, Serialize) { 309 DEPENDENT_TEST(Deserialize, Serialize) {
308 // The serialize-deserialize tests only work if the VM is built without 310 // The serialize-deserialize tests only work if the VM is built without
309 // serialization. That doesn't matter. We don't need to be able to 311 // serialization. That doesn't matter. We don't need to be able to
310 // serialize a snapshot in a VM that is booted from a snapshot. 312 // serialize a snapshot in a VM that is booted from a snapshot.
311 if (!Snapshot::HaveASnapshotToStartFrom()) { 313 if (!Snapshot::HaveASnapshotToStartFrom()) {
312 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 314 v8::Isolate* isolate = CcTest::isolate();
313 v8::HandleScope scope(isolate); 315 v8::HandleScope scope(isolate);
314 Deserialize(); 316 Deserialize();
315 317
316 v8::Local<v8::Context> env = v8::Context::New(isolate); 318 v8::Local<v8::Context> env = v8::Context::New(isolate);
317 env->Enter(); 319 env->Enter();
318 320
319 SanityCheck(); 321 SanityCheck();
320 } 322 }
321 } 323 }
322 324
323 325
324 DEPENDENT_TEST(DeserializeFromSecondSerialization, SerializeTwice) { 326 DEPENDENT_TEST(DeserializeFromSecondSerialization, SerializeTwice) {
325 if (!Snapshot::HaveASnapshotToStartFrom()) { 327 if (!Snapshot::HaveASnapshotToStartFrom()) {
326 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 328 v8::Isolate* isolate = CcTest::isolate();
327 v8::HandleScope scope(isolate); 329 v8::HandleScope scope(isolate);
328 Deserialize(); 330 Deserialize();
329 331
330 v8::Local<v8::Context> env = v8::Context::New(isolate); 332 v8::Local<v8::Context> env = v8::Context::New(isolate);
331 env->Enter(); 333 env->Enter();
332 334
333 SanityCheck(); 335 SanityCheck();
334 } 336 }
335 } 337 }
336 338
337 339
338 DEPENDENT_TEST(DeserializeAndRunScript2, Serialize) { 340 DEPENDENT_TEST(DeserializeAndRunScript2, Serialize) {
339 if (!Snapshot::HaveASnapshotToStartFrom()) { 341 if (!Snapshot::HaveASnapshotToStartFrom()) {
340 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 342 v8::Isolate* isolate = CcTest::isolate();
341 v8::HandleScope scope(isolate); 343 v8::HandleScope scope(isolate);
342 Deserialize(); 344 Deserialize();
343 345
344 v8::Local<v8::Context> env = v8::Context::New(isolate); 346 v8::Local<v8::Context> env = v8::Context::New(isolate);
345 env->Enter(); 347 env->Enter();
346 348
347 const char* c_source = "\"1234\".length"; 349 const char* c_source = "\"1234\".length";
348 v8::Local<v8::String> source = v8::String::New(c_source); 350 v8::Local<v8::String> source = v8::String::New(c_source);
349 v8::Local<v8::Script> script = v8::Script::Compile(source); 351 v8::Local<v8::Script> script = v8::Script::Compile(source);
350 CHECK_EQ(4, script->Run()->Int32Value()); 352 CHECK_EQ(4, script->Run()->Int32Value());
351 } 353 }
352 } 354 }
353 355
354 356
355 DEPENDENT_TEST(DeserializeFromSecondSerializationAndRunScript2, 357 DEPENDENT_TEST(DeserializeFromSecondSerializationAndRunScript2,
356 SerializeTwice) { 358 SerializeTwice) {
357 if (!Snapshot::HaveASnapshotToStartFrom()) { 359 if (!Snapshot::HaveASnapshotToStartFrom()) {
358 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 360 v8::Isolate* isolate = CcTest::isolate();
359 v8::HandleScope scope(isolate); 361 v8::HandleScope scope(isolate);
360 Deserialize(); 362 Deserialize();
361 363
362 v8::Local<v8::Context> env = v8::Context::New(isolate); 364 v8::Local<v8::Context> env = v8::Context::New(isolate);
363 env->Enter(); 365 env->Enter();
364 366
365 const char* c_source = "\"1234\".length"; 367 const char* c_source = "\"1234\".length";
366 v8::Local<v8::String> source = v8::String::New(c_source); 368 v8::Local<v8::String> source = v8::String::New(c_source);
367 v8::Local<v8::Script> script = v8::Script::Compile(source); 369 v8::Local<v8::Script> script = v8::Script::Compile(source);
368 CHECK_EQ(4, script->Run()->Int32Value()); 370 CHECK_EQ(4, script->Run()->Int32Value());
369 } 371 }
370 } 372 }
371 373
372 374
373 TEST(PartialSerialization) { 375 UNINITIALIZED_TEST(PartialSerialization) {
374 if (!Snapshot::HaveASnapshotToStartFrom()) { 376 if (!Snapshot::HaveASnapshotToStartFrom()) {
375 Isolate* isolate = Isolate::Current(); 377 Isolate* isolate = CcTest::i_isolate();
376 Serializer::Enable(isolate); 378 Serializer::Enable(isolate);
377 v8::V8::Initialize(); 379 v8::V8::Initialize();
378 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); 380 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate);
379 Heap* heap = isolate->heap(); 381 Heap* heap = isolate->heap();
380 382
381 v8::Persistent<v8::Context> env; 383 v8::Persistent<v8::Context> env;
382 { 384 {
383 HandleScope scope(isolate); 385 HandleScope scope(isolate);
384 env.Reset(v8_isolate, v8::Context::New(v8_isolate)); 386 env.Reset(v8_isolate, v8::Context::New(v8_isolate));
385 } 387 }
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 OS::SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); 490 OS::SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file);
489 491
490 CHECK(Snapshot::Initialize(startup_name.start())); 492 CHECK(Snapshot::Initialize(startup_name.start()));
491 startup_name.Dispose(); 493 startup_name.Dispose();
492 494
493 const char* file_name = FLAG_testing_serialization_file; 495 const char* file_name = FLAG_testing_serialization_file;
494 496
495 int snapshot_size = 0; 497 int snapshot_size = 0;
496 byte* snapshot = ReadBytes(file_name, &snapshot_size); 498 byte* snapshot = ReadBytes(file_name, &snapshot_size);
497 499
498 Isolate* isolate = Isolate::Current(); 500 Isolate* isolate = CcTest::i_isolate();
499 Object* root; 501 Object* root;
500 { 502 {
501 SnapshotByteSource source(snapshot, snapshot_size); 503 SnapshotByteSource source(snapshot, snapshot_size);
502 Deserializer deserializer(&source); 504 Deserializer deserializer(&source);
503 ReserveSpaceForSnapshot(&deserializer, file_name); 505 ReserveSpaceForSnapshot(&deserializer, file_name);
504 deserializer.DeserializePartial(isolate, &root); 506 deserializer.DeserializePartial(isolate, &root);
505 CHECK(root->IsString()); 507 CHECK(root->IsString());
506 } 508 }
507 HandleScope handle_scope(isolate); 509 HandleScope handle_scope(isolate);
508 Handle<Object> root_handle(root, isolate); 510 Handle<Object> root_handle(root, isolate);
509 511
510 512
511 Object* root2; 513 Object* root2;
512 { 514 {
513 SnapshotByteSource source(snapshot, snapshot_size); 515 SnapshotByteSource source(snapshot, snapshot_size);
514 Deserializer deserializer(&source); 516 Deserializer deserializer(&source);
515 ReserveSpaceForSnapshot(&deserializer, file_name); 517 ReserveSpaceForSnapshot(&deserializer, file_name);
516 deserializer.DeserializePartial(isolate, &root2); 518 deserializer.DeserializePartial(isolate, &root2);
517 CHECK(root2->IsString()); 519 CHECK(root2->IsString());
518 CHECK(*root_handle == root2); 520 CHECK(*root_handle == root2);
519 } 521 }
520 } 522 }
521 } 523 }
522 524
523 525
524 TEST(ContextSerialization) { 526 UNINITIALIZED_TEST(ContextSerialization) {
525 if (!Snapshot::HaveASnapshotToStartFrom()) { 527 if (!Snapshot::HaveASnapshotToStartFrom()) {
526 Isolate* isolate = Isolate::Current(); 528 Isolate* isolate = CcTest::i_isolate();
527 Serializer::Enable(isolate); 529 Serializer::Enable(isolate);
528 v8::V8::Initialize(); 530 v8::V8::Initialize();
529 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); 531 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate);
530 Heap* heap = isolate->heap(); 532 Heap* heap = isolate->heap();
531 533
532 v8::Persistent<v8::Context> env; 534 v8::Persistent<v8::Context> env;
533 { 535 {
534 HandleScope scope(isolate); 536 HandleScope scope(isolate);
535 env.Reset(v8_isolate, v8::Context::New(v8_isolate)); 537 env.Reset(v8_isolate, v8::Context::New(v8_isolate));
536 } 538 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 OS::SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); 602 OS::SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file);
601 603
602 CHECK(Snapshot::Initialize(startup_name.start())); 604 CHECK(Snapshot::Initialize(startup_name.start()));
603 startup_name.Dispose(); 605 startup_name.Dispose();
604 606
605 const char* file_name = FLAG_testing_serialization_file; 607 const char* file_name = FLAG_testing_serialization_file;
606 608
607 int snapshot_size = 0; 609 int snapshot_size = 0;
608 byte* snapshot = ReadBytes(file_name, &snapshot_size); 610 byte* snapshot = ReadBytes(file_name, &snapshot_size);
609 611
610 Isolate* isolate = Isolate::Current(); 612 Isolate* isolate = CcTest::i_isolate();
611 Object* root; 613 Object* root;
612 { 614 {
613 SnapshotByteSource source(snapshot, snapshot_size); 615 SnapshotByteSource source(snapshot, snapshot_size);
614 Deserializer deserializer(&source); 616 Deserializer deserializer(&source);
615 ReserveSpaceForSnapshot(&deserializer, file_name); 617 ReserveSpaceForSnapshot(&deserializer, file_name);
616 deserializer.DeserializePartial(isolate, &root); 618 deserializer.DeserializePartial(isolate, &root);
617 CHECK(root->IsContext()); 619 CHECK(root->IsContext());
618 } 620 }
619 HandleScope handle_scope(isolate); 621 HandleScope handle_scope(isolate);
620 Handle<Object> root_handle(root, isolate); 622 Handle<Object> root_handle(root, isolate);
(...skipping 19 matching lines...) Expand all
640 TEST(TestThatAlwaysFails) { 642 TEST(TestThatAlwaysFails) {
641 bool ArtificialFailure = false; 643 bool ArtificialFailure = false;
642 CHECK(ArtificialFailure); 644 CHECK(ArtificialFailure);
643 } 645 }
644 646
645 647
646 DEPENDENT_TEST(DependentTestThatAlwaysFails, TestThatAlwaysSucceeds) { 648 DEPENDENT_TEST(DependentTestThatAlwaysFails, TestThatAlwaysSucceeds) {
647 bool ArtificialFailure2 = false; 649 bool ArtificialFailure2 = false;
648 CHECK(ArtificialFailure2); 650 CHECK(ArtificialFailure2);
649 } 651 }
OLDNEW
« no previous file with comments | « test/cctest/test-regexp.cc ('k') | test/cctest/test-spaces.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698