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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 Loading... |
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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 v8::Context::New(isolate); | 257 v8::Context::New(isolate); |
258 } | 258 } |
259 WriteToFile(reinterpret_cast<Isolate*>(isolate), | 259 WriteToFile(reinterpret_cast<Isolate*>(isolate), |
260 FLAG_testing_serialization_file); | 260 FLAG_testing_serialization_file); |
261 } | 261 } |
262 | 262 |
263 | 263 |
264 // Test that the whole heap can be serialized. | 264 // Test that the whole heap can be serialized. |
265 UNINITIALIZED_TEST(Serialize) { | 265 UNINITIALIZED_TEST(Serialize) { |
266 if (!Snapshot::HaveASnapshotToStartFrom()) { | 266 if (!Snapshot::HaveASnapshotToStartFrom()) { |
267 Serializer::Enable(Isolate::Current()); | 267 Serializer::Enable(CcTest::i_isolate()); |
268 v8::V8::Initialize(); | 268 v8::V8::Initialize(); |
269 Serialize(); | 269 Serialize(); |
270 } | 270 } |
271 } | 271 } |
272 | 272 |
273 | 273 |
274 // Test that heap serialization is non-destructive. | 274 // Test that heap serialization is non-destructive. |
275 UNINITIALIZED_TEST(SerializeTwice) { | 275 UNINITIALIZED_TEST(SerializeTwice) { |
276 if (!Snapshot::HaveASnapshotToStartFrom()) { | 276 if (!Snapshot::HaveASnapshotToStartFrom()) { |
277 Serializer::Enable(Isolate::Current()); | 277 Serializer::Enable(CcTest::i_isolate()); |
278 v8::V8::Initialize(); | 278 v8::V8::Initialize(); |
279 Serialize(); | 279 Serialize(); |
280 Serialize(); | 280 Serialize(); |
281 } | 281 } |
282 } | 282 } |
283 | 283 |
284 | 284 |
285 //---------------------------------------------------------------------------- | 285 //---------------------------------------------------------------------------- |
286 // Tests that the heap can be deserialized. | 286 // Tests that the heap can be deserialized. |
287 | 287 |
288 static void Deserialize() { | 288 static void Deserialize() { |
289 CHECK(Snapshot::Initialize(FLAG_testing_serialization_file)); | 289 CHECK(Snapshot::Initialize(FLAG_testing_serialization_file)); |
290 } | 290 } |
291 | 291 |
292 | 292 |
293 static void SanityCheck() { | 293 static void SanityCheck() { |
294 Isolate* isolate = Isolate::Current(); | 294 Isolate* isolate = CcTest::i_isolate(); |
295 v8::HandleScope scope(CcTest::isolate()); | 295 v8::HandleScope scope(CcTest::isolate()); |
296 #ifdef VERIFY_HEAP | 296 #ifdef VERIFY_HEAP |
297 HEAP->Verify(); | 297 HEAP->Verify(); |
298 #endif | 298 #endif |
299 CHECK(isolate->global_object()->IsJSObject()); | 299 CHECK(isolate->global_object()->IsJSObject()); |
300 CHECK(isolate->native_context()->IsContext()); | 300 CHECK(isolate->native_context()->IsContext()); |
301 CHECK(HEAP->string_table()->IsStringTable()); | 301 CHECK(HEAP->string_table()->IsStringTable()); |
302 CHECK(!isolate->factory()->InternalizeOneByteString( | 302 CHECK(!isolate->factory()->InternalizeOneByteString( |
303 STATIC_ASCII_VECTOR("Empty"))->IsFailure()); | 303 STATIC_ASCII_VECTOR("Empty"))->IsFailure()); |
304 } | 304 } |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 const char* c_source = "\"1234\".length"; | 365 const char* c_source = "\"1234\".length"; |
366 v8::Local<v8::String> source = v8::String::New(c_source); | 366 v8::Local<v8::String> source = v8::String::New(c_source); |
367 v8::Local<v8::Script> script = v8::Script::Compile(source); | 367 v8::Local<v8::Script> script = v8::Script::Compile(source); |
368 CHECK_EQ(4, script->Run()->Int32Value()); | 368 CHECK_EQ(4, script->Run()->Int32Value()); |
369 } | 369 } |
370 } | 370 } |
371 | 371 |
372 | 372 |
373 UNINITIALIZED_TEST(PartialSerialization) { | 373 UNINITIALIZED_TEST(PartialSerialization) { |
374 if (!Snapshot::HaveASnapshotToStartFrom()) { | 374 if (!Snapshot::HaveASnapshotToStartFrom()) { |
375 Isolate* isolate = Isolate::Current(); | 375 Isolate* isolate = CcTest::i_isolate(); |
376 Serializer::Enable(isolate); | 376 Serializer::Enable(isolate); |
377 v8::V8::Initialize(); | 377 v8::V8::Initialize(); |
378 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); | 378 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); |
379 Heap* heap = isolate->heap(); | 379 Heap* heap = isolate->heap(); |
380 | 380 |
381 v8::Persistent<v8::Context> env; | 381 v8::Persistent<v8::Context> env; |
382 { | 382 { |
383 HandleScope scope(isolate); | 383 HandleScope scope(isolate); |
384 env.Reset(v8_isolate, v8::Context::New(v8_isolate)); | 384 env.Reset(v8_isolate, v8::Context::New(v8_isolate)); |
385 } | 385 } |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 OS::SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); | 488 OS::SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); |
489 | 489 |
490 CHECK(Snapshot::Initialize(startup_name.start())); | 490 CHECK(Snapshot::Initialize(startup_name.start())); |
491 startup_name.Dispose(); | 491 startup_name.Dispose(); |
492 | 492 |
493 const char* file_name = FLAG_testing_serialization_file; | 493 const char* file_name = FLAG_testing_serialization_file; |
494 | 494 |
495 int snapshot_size = 0; | 495 int snapshot_size = 0; |
496 byte* snapshot = ReadBytes(file_name, &snapshot_size); | 496 byte* snapshot = ReadBytes(file_name, &snapshot_size); |
497 | 497 |
498 Isolate* isolate = Isolate::Current(); | 498 Isolate* isolate = CcTest::i_isolate(); |
499 Object* root; | 499 Object* root; |
500 { | 500 { |
501 SnapshotByteSource source(snapshot, snapshot_size); | 501 SnapshotByteSource source(snapshot, snapshot_size); |
502 Deserializer deserializer(&source); | 502 Deserializer deserializer(&source); |
503 ReserveSpaceForSnapshot(&deserializer, file_name); | 503 ReserveSpaceForSnapshot(&deserializer, file_name); |
504 deserializer.DeserializePartial(isolate, &root); | 504 deserializer.DeserializePartial(isolate, &root); |
505 CHECK(root->IsString()); | 505 CHECK(root->IsString()); |
506 } | 506 } |
507 HandleScope handle_scope(isolate); | 507 HandleScope handle_scope(isolate); |
508 Handle<Object> root_handle(root, isolate); | 508 Handle<Object> root_handle(root, isolate); |
509 | 509 |
510 | 510 |
511 Object* root2; | 511 Object* root2; |
512 { | 512 { |
513 SnapshotByteSource source(snapshot, snapshot_size); | 513 SnapshotByteSource source(snapshot, snapshot_size); |
514 Deserializer deserializer(&source); | 514 Deserializer deserializer(&source); |
515 ReserveSpaceForSnapshot(&deserializer, file_name); | 515 ReserveSpaceForSnapshot(&deserializer, file_name); |
516 deserializer.DeserializePartial(isolate, &root2); | 516 deserializer.DeserializePartial(isolate, &root2); |
517 CHECK(root2->IsString()); | 517 CHECK(root2->IsString()); |
518 CHECK(*root_handle == root2); | 518 CHECK(*root_handle == root2); |
519 } | 519 } |
520 } | 520 } |
521 } | 521 } |
522 | 522 |
523 | 523 |
524 UNINITIALIZED_TEST(ContextSerialization) { | 524 UNINITIALIZED_TEST(ContextSerialization) { |
525 if (!Snapshot::HaveASnapshotToStartFrom()) { | 525 if (!Snapshot::HaveASnapshotToStartFrom()) { |
526 Isolate* isolate = Isolate::Current(); | 526 Isolate* isolate = CcTest::i_isolate(); |
527 Serializer::Enable(isolate); | 527 Serializer::Enable(isolate); |
528 v8::V8::Initialize(); | 528 v8::V8::Initialize(); |
529 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); | 529 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); |
530 Heap* heap = isolate->heap(); | 530 Heap* heap = isolate->heap(); |
531 | 531 |
532 v8::Persistent<v8::Context> env; | 532 v8::Persistent<v8::Context> env; |
533 { | 533 { |
534 HandleScope scope(isolate); | 534 HandleScope scope(isolate); |
535 env.Reset(v8_isolate, v8::Context::New(v8_isolate)); | 535 env.Reset(v8_isolate, v8::Context::New(v8_isolate)); |
536 } | 536 } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
600 OS::SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); | 600 OS::SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); |
601 | 601 |
602 CHECK(Snapshot::Initialize(startup_name.start())); | 602 CHECK(Snapshot::Initialize(startup_name.start())); |
603 startup_name.Dispose(); | 603 startup_name.Dispose(); |
604 | 604 |
605 const char* file_name = FLAG_testing_serialization_file; | 605 const char* file_name = FLAG_testing_serialization_file; |
606 | 606 |
607 int snapshot_size = 0; | 607 int snapshot_size = 0; |
608 byte* snapshot = ReadBytes(file_name, &snapshot_size); | 608 byte* snapshot = ReadBytes(file_name, &snapshot_size); |
609 | 609 |
610 Isolate* isolate = Isolate::Current(); | 610 Isolate* isolate = CcTest::i_isolate(); |
611 Object* root; | 611 Object* root; |
612 { | 612 { |
613 SnapshotByteSource source(snapshot, snapshot_size); | 613 SnapshotByteSource source(snapshot, snapshot_size); |
614 Deserializer deserializer(&source); | 614 Deserializer deserializer(&source); |
615 ReserveSpaceForSnapshot(&deserializer, file_name); | 615 ReserveSpaceForSnapshot(&deserializer, file_name); |
616 deserializer.DeserializePartial(isolate, &root); | 616 deserializer.DeserializePartial(isolate, &root); |
617 CHECK(root->IsContext()); | 617 CHECK(root->IsContext()); |
618 } | 618 } |
619 HandleScope handle_scope(isolate); | 619 HandleScope handle_scope(isolate); |
620 Handle<Object> root_handle(root, isolate); | 620 Handle<Object> root_handle(root, isolate); |
(...skipping 19 matching lines...) Expand all Loading... |
640 TEST(TestThatAlwaysFails) { | 640 TEST(TestThatAlwaysFails) { |
641 bool ArtificialFailure = false; | 641 bool ArtificialFailure = false; |
642 CHECK(ArtificialFailure); | 642 CHECK(ArtificialFailure); |
643 } | 643 } |
644 | 644 |
645 | 645 |
646 DEPENDENT_TEST(DependentTestThatAlwaysFails, TestThatAlwaysSucceeds) { | 646 DEPENDENT_TEST(DependentTestThatAlwaysFails, TestThatAlwaysSucceeds) { |
647 bool ArtificialFailure2 = false; | 647 bool ArtificialFailure2 = false; |
648 CHECK(ArtificialFailure2); | 648 CHECK(ArtificialFailure2); |
649 } | 649 } |
OLD | NEW |