| OLD | NEW |
| 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 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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::Persistent<v8::Context> env = v8::Context::New(); | 254 { |
| 255 env.Dispose(env->GetIsolate()); | 255 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 256 v8::HandleScope scope(isolate); |
| 257 v8::Context::New(isolate); |
| 258 } |
| 256 WriteToFile(FLAG_testing_serialization_file); | 259 WriteToFile(FLAG_testing_serialization_file); |
| 257 } | 260 } |
| 258 | 261 |
| 259 | 262 |
| 260 // Test that the whole heap can be serialized. | 263 // Test that the whole heap can be serialized. |
| 261 TEST(Serialize) { | 264 TEST(Serialize) { |
| 262 if (!Snapshot::HaveASnapshotToStartFrom()) { | 265 if (!Snapshot::HaveASnapshotToStartFrom()) { |
| 263 Serializer::Enable(); | 266 Serializer::Enable(); |
| 264 v8::V8::Initialize(); | 267 v8::V8::Initialize(); |
| 265 Serialize(); | 268 Serialize(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 CHECK(!FACTORY->InternalizeOneByteString( | 300 CHECK(!FACTORY->InternalizeOneByteString( |
| 298 STATIC_ASCII_VECTOR("Empty"))->IsFailure()); | 301 STATIC_ASCII_VECTOR("Empty"))->IsFailure()); |
| 299 } | 302 } |
| 300 | 303 |
| 301 | 304 |
| 302 DEPENDENT_TEST(Deserialize, Serialize) { | 305 DEPENDENT_TEST(Deserialize, Serialize) { |
| 303 // The serialize-deserialize tests only work if the VM is built without | 306 // The serialize-deserialize tests only work if the VM is built without |
| 304 // serialization. That doesn't matter. We don't need to be able to | 307 // serialization. That doesn't matter. We don't need to be able to |
| 305 // serialize a snapshot in a VM that is booted from a snapshot. | 308 // serialize a snapshot in a VM that is booted from a snapshot. |
| 306 if (!Snapshot::HaveASnapshotToStartFrom()) { | 309 if (!Snapshot::HaveASnapshotToStartFrom()) { |
| 307 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 310 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 311 v8::HandleScope scope(isolate); |
| 308 Deserialize(); | 312 Deserialize(); |
| 309 | 313 |
| 310 v8::Persistent<v8::Context> env = v8::Context::New(); | 314 v8::Local<v8::Context> env = v8::Context::New(isolate); |
| 311 env->Enter(); | 315 env->Enter(); |
| 312 | 316 |
| 313 SanityCheck(); | 317 SanityCheck(); |
| 314 } | 318 } |
| 315 } | 319 } |
| 316 | 320 |
| 317 | 321 |
| 318 DEPENDENT_TEST(DeserializeFromSecondSerialization, SerializeTwice) { | 322 DEPENDENT_TEST(DeserializeFromSecondSerialization, SerializeTwice) { |
| 319 if (!Snapshot::HaveASnapshotToStartFrom()) { | 323 if (!Snapshot::HaveASnapshotToStartFrom()) { |
| 320 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 324 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 325 v8::HandleScope scope(isolate); |
| 321 Deserialize(); | 326 Deserialize(); |
| 322 | 327 |
| 323 v8::Persistent<v8::Context> env = v8::Context::New(); | 328 v8::Local<v8::Context> env = v8::Context::New(isolate); |
| 324 env->Enter(); | 329 env->Enter(); |
| 325 | 330 |
| 326 SanityCheck(); | 331 SanityCheck(); |
| 327 } | 332 } |
| 328 } | 333 } |
| 329 | 334 |
| 330 | 335 |
| 331 DEPENDENT_TEST(DeserializeAndRunScript2, Serialize) { | 336 DEPENDENT_TEST(DeserializeAndRunScript2, Serialize) { |
| 332 if (!Snapshot::HaveASnapshotToStartFrom()) { | 337 if (!Snapshot::HaveASnapshotToStartFrom()) { |
| 333 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 338 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 339 v8::HandleScope scope(isolate); |
| 334 Deserialize(); | 340 Deserialize(); |
| 335 | 341 |
| 336 v8::Persistent<v8::Context> env = v8::Context::New(); | 342 v8::Local<v8::Context> env = v8::Context::New(isolate); |
| 337 env->Enter(); | 343 env->Enter(); |
| 338 | 344 |
| 339 const char* c_source = "\"1234\".length"; | 345 const char* c_source = "\"1234\".length"; |
| 340 v8::Local<v8::String> source = v8::String::New(c_source); | 346 v8::Local<v8::String> source = v8::String::New(c_source); |
| 341 v8::Local<v8::Script> script = v8::Script::Compile(source); | 347 v8::Local<v8::Script> script = v8::Script::Compile(source); |
| 342 CHECK_EQ(4, script->Run()->Int32Value()); | 348 CHECK_EQ(4, script->Run()->Int32Value()); |
| 343 } | 349 } |
| 344 } | 350 } |
| 345 | 351 |
| 346 | 352 |
| 347 DEPENDENT_TEST(DeserializeFromSecondSerializationAndRunScript2, | 353 DEPENDENT_TEST(DeserializeFromSecondSerializationAndRunScript2, |
| 348 SerializeTwice) { | 354 SerializeTwice) { |
| 349 if (!Snapshot::HaveASnapshotToStartFrom()) { | 355 if (!Snapshot::HaveASnapshotToStartFrom()) { |
| 350 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 356 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 357 v8::HandleScope scope(isolate); |
| 351 Deserialize(); | 358 Deserialize(); |
| 352 | 359 |
| 353 v8::Persistent<v8::Context> env = v8::Context::New(); | 360 v8::Local<v8::Context> env = v8::Context::New(isolate); |
| 354 env->Enter(); | 361 env->Enter(); |
| 355 | 362 |
| 356 const char* c_source = "\"1234\".length"; | 363 const char* c_source = "\"1234\".length"; |
| 357 v8::Local<v8::String> source = v8::String::New(c_source); | 364 v8::Local<v8::String> source = v8::String::New(c_source); |
| 358 v8::Local<v8::Script> script = v8::Script::Compile(source); | 365 v8::Local<v8::Script> script = v8::Script::Compile(source); |
| 359 CHECK_EQ(4, script->Run()->Int32Value()); | 366 CHECK_EQ(4, script->Run()->Int32Value()); |
| 360 } | 367 } |
| 361 } | 368 } |
| 362 | 369 |
| 363 | 370 |
| 364 TEST(PartialSerialization) { | 371 TEST(PartialSerialization) { |
| 365 if (!Snapshot::HaveASnapshotToStartFrom()) { | 372 if (!Snapshot::HaveASnapshotToStartFrom()) { |
| 366 Serializer::Enable(); | 373 Serializer::Enable(); |
| 367 v8::V8::Initialize(); | 374 v8::V8::Initialize(); |
| 368 Isolate* isolate = Isolate::Current(); | 375 Isolate* isolate = Isolate::Current(); |
| 369 Heap* heap = isolate->heap(); | 376 Heap* heap = isolate->heap(); |
| 370 | 377 |
| 371 v8::Persistent<v8::Context> env = v8::Context::New(); | 378 v8::Persistent<v8::Context> env; |
| 379 { |
| 380 HandleScope scope(isolate); |
| 381 env.Reset(v8::Isolate::GetCurrent(), |
| 382 v8::Context::New(v8::Isolate::GetCurrent())); |
| 383 } |
| 372 ASSERT(!env.IsEmpty()); | 384 ASSERT(!env.IsEmpty()); |
| 373 env->Enter(); | 385 env->Enter(); |
| 374 // Make sure all builtin scripts are cached. | 386 // Make sure all builtin scripts are cached. |
| 375 { HandleScope scope(isolate); | 387 { HandleScope scope(isolate); |
| 376 for (int i = 0; i < Natives::GetBuiltinsCount(); i++) { | 388 for (int i = 0; i < Natives::GetBuiltinsCount(); i++) { |
| 377 isolate->bootstrapper()->NativesSourceLookup(i); | 389 isolate->bootstrapper()->NativesSourceLookup(i); |
| 378 } | 390 } |
| 379 } | 391 } |
| 380 heap->CollectAllGarbage(Heap::kNoGCFlags); | 392 heap->CollectAllGarbage(Heap::kNoGCFlags); |
| 381 heap->CollectAllGarbage(Heap::kNoGCFlags); | 393 heap->CollectAllGarbage(Heap::kNoGCFlags); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 } | 507 } |
| 496 | 508 |
| 497 | 509 |
| 498 TEST(ContextSerialization) { | 510 TEST(ContextSerialization) { |
| 499 if (!Snapshot::HaveASnapshotToStartFrom()) { | 511 if (!Snapshot::HaveASnapshotToStartFrom()) { |
| 500 Serializer::Enable(); | 512 Serializer::Enable(); |
| 501 v8::V8::Initialize(); | 513 v8::V8::Initialize(); |
| 502 Isolate* isolate = Isolate::Current(); | 514 Isolate* isolate = Isolate::Current(); |
| 503 Heap* heap = isolate->heap(); | 515 Heap* heap = isolate->heap(); |
| 504 | 516 |
| 505 v8::Persistent<v8::Context> env = v8::Context::New(); | 517 v8::Persistent<v8::Context> env; |
| 518 { |
| 519 HandleScope scope(isolate); |
| 520 env.Reset(v8::Isolate::GetCurrent(), |
| 521 v8::Context::New(v8::Isolate::GetCurrent())); |
| 522 } |
| 506 ASSERT(!env.IsEmpty()); | 523 ASSERT(!env.IsEmpty()); |
| 507 env->Enter(); | 524 env->Enter(); |
| 508 // Make sure all builtin scripts are cached. | 525 // Make sure all builtin scripts are cached. |
| 509 { HandleScope scope(isolate); | 526 { HandleScope scope(isolate); |
| 510 for (int i = 0; i < Natives::GetBuiltinsCount(); i++) { | 527 for (int i = 0; i < Natives::GetBuiltinsCount(); i++) { |
| 511 isolate->bootstrapper()->NativesSourceLookup(i); | 528 isolate->bootstrapper()->NativesSourceLookup(i); |
| 512 } | 529 } |
| 513 } | 530 } |
| 514 // If we don't do this then we end up with a stray root pointing at the | 531 // If we don't do this then we end up with a stray root pointing at the |
| 515 // context even after we have disposed of env. | 532 // context even after we have disposed of env. |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 600 TEST(TestThatAlwaysFails) { | 617 TEST(TestThatAlwaysFails) { |
| 601 bool ArtificialFailure = false; | 618 bool ArtificialFailure = false; |
| 602 CHECK(ArtificialFailure); | 619 CHECK(ArtificialFailure); |
| 603 } | 620 } |
| 604 | 621 |
| 605 | 622 |
| 606 DEPENDENT_TEST(DependentTestThatAlwaysFails, TestThatAlwaysSucceeds) { | 623 DEPENDENT_TEST(DependentTestThatAlwaysFails, TestThatAlwaysSucceeds) { |
| 607 bool ArtificialFailure2 = false; | 624 bool ArtificialFailure2 = false; |
| 608 CHECK(ArtificialFailure2); | 625 CHECK(ArtificialFailure2); |
| 609 } | 626 } |
| OLD | NEW |