OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 7469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7480 v8::V8::RemoveMessageListeners(MissingScriptInfoMessageListener); | 7480 v8::V8::RemoveMessageListeners(MissingScriptInfoMessageListener); |
7481 } | 7481 } |
7482 | 7482 |
7483 | 7483 |
7484 struct FlagAndPersistent { | 7484 struct FlagAndPersistent { |
7485 bool flag; | 7485 bool flag; |
7486 v8::Persistent<v8::Object> handle; | 7486 v8::Persistent<v8::Object> handle; |
7487 }; | 7487 }; |
7488 | 7488 |
7489 | 7489 |
7490 static void DisposeAndSetFlag( | 7490 static void SetFlag( |
7491 const v8::WeakCallbackData<v8::Object, FlagAndPersistent>& data) { | 7491 const v8::WeakCallbackData<v8::Object, FlagAndPersistent>& data) { |
7492 data.GetParameter()->handle.Reset(); | |
7493 data.GetParameter()->flag = true; | 7492 data.GetParameter()->flag = true; |
7494 } | 7493 } |
7495 | 7494 |
7496 | 7495 |
7497 THREADED_TEST(IndependentWeakHandle) { | 7496 static void IndependentWeakHandle(bool global_gc, bool interlinked) { |
7498 v8::Isolate* iso = CcTest::isolate(); | 7497 v8::Isolate* iso = CcTest::isolate(); |
7499 v8::HandleScope scope(iso); | 7498 v8::HandleScope scope(iso); |
7500 v8::Handle<Context> context = Context::New(iso); | 7499 v8::Handle<Context> context = Context::New(iso); |
7501 Context::Scope context_scope(context); | 7500 Context::Scope context_scope(context); |
7502 | 7501 |
7503 FlagAndPersistent object_a, object_b; | 7502 FlagAndPersistent object_a, object_b; |
7504 | 7503 |
| 7504 intptr_t big_heap_size; |
| 7505 |
| 7506 { |
| 7507 v8::HandleScope handle_scope(iso); |
| 7508 Local<Object> a(v8::Object::New(iso)); |
| 7509 Local<Object> b(v8::Object::New(iso)); |
| 7510 object_a.handle.Reset(iso, a); |
| 7511 object_b.handle.Reset(iso, b); |
| 7512 if (interlinked) { |
| 7513 a->Set(v8_str("x"), b); |
| 7514 b->Set(v8_str("x"), a); |
| 7515 } |
| 7516 if (global_gc) { |
| 7517 CcTest::heap()->CollectAllGarbage(TestHeap::Heap::kNoGCFlags); |
| 7518 } else { |
| 7519 CcTest::heap()->CollectGarbage(i::NEW_SPACE); |
| 7520 } |
| 7521 // We are relying on this creating a big flag array and reserving the space |
| 7522 // up front. |
| 7523 v8::Handle<Value> big_array = CompileRun("new Array(50000)"); |
| 7524 a->Set(v8_str("y"), big_array); |
| 7525 big_heap_size = CcTest::heap()->SizeOfObjects(); |
| 7526 } |
| 7527 |
| 7528 object_a.flag = false; |
| 7529 object_b.flag = false; |
| 7530 object_a.handle.SetPhantom(&object_a, &SetFlag); |
| 7531 object_b.handle.SetPhantom(&object_b, &SetFlag); |
| 7532 CHECK(!object_b.handle.IsIndependent()); |
| 7533 object_a.handle.MarkIndependent(); |
| 7534 object_b.handle.MarkIndependent(); |
| 7535 CHECK(object_b.handle.IsIndependent()); |
| 7536 if (global_gc) { |
| 7537 CcTest::heap()->CollectAllGarbage(TestHeap::Heap::kNoGCFlags); |
| 7538 } else { |
| 7539 CcTest::heap()->CollectGarbage(i::NEW_SPACE); |
| 7540 } |
| 7541 // A single GC should be enough to reclaim the memory, since we are using |
| 7542 // phantom handles. |
| 7543 CHECK_LT(CcTest::heap()->SizeOfObjects(), big_heap_size - 200000); |
| 7544 CHECK(object_a.flag); |
| 7545 CHECK(object_b.flag); |
| 7546 } |
| 7547 |
| 7548 |
| 7549 THREADED_TEST(IndependentWeakHandle) { |
| 7550 IndependentWeakHandle(false, false); |
| 7551 IndependentWeakHandle(false, true); |
| 7552 IndependentWeakHandle(true, false); |
| 7553 IndependentWeakHandle(true, true); |
| 7554 } |
| 7555 |
| 7556 |
| 7557 static void ResetUseValueAndSetFlag( |
| 7558 const v8::WeakCallbackData<v8::Object, FlagAndPersistent>& data) { |
| 7559 // Blink will reset the handle, and then use the other handle, so they |
| 7560 // can't use the same backing slot. |
| 7561 data.GetParameter()->handle.Reset(); |
| 7562 data.GetValue()->IsBoolean(); // Make sure the handle still works. |
| 7563 data.GetParameter()->flag = true; |
| 7564 } |
| 7565 |
| 7566 |
| 7567 static void ResetWeakHandle(bool global_gc) { |
| 7568 v8::Isolate* iso = CcTest::isolate(); |
| 7569 v8::HandleScope scope(iso); |
| 7570 v8::Handle<Context> context = Context::New(iso); |
| 7571 Context::Scope context_scope(context); |
| 7572 |
| 7573 FlagAndPersistent object_a, object_b; |
| 7574 |
7505 { | 7575 { |
7506 v8::HandleScope handle_scope(iso); | 7576 v8::HandleScope handle_scope(iso); |
7507 object_a.handle.Reset(iso, v8::Object::New(iso)); | 7577 Local<Object> a(v8::Object::New(iso)); |
7508 object_b.handle.Reset(iso, v8::Object::New(iso)); | 7578 Local<Object> b(v8::Object::New(iso)); |
| 7579 object_a.handle.Reset(iso, a); |
| 7580 object_b.handle.Reset(iso, b); |
| 7581 if (global_gc) { |
| 7582 CcTest::heap()->CollectAllGarbage(TestHeap::Heap::kNoGCFlags); |
| 7583 } else { |
| 7584 CcTest::heap()->CollectGarbage(i::NEW_SPACE); |
| 7585 } |
7509 } | 7586 } |
7510 | 7587 |
7511 object_a.flag = false; | 7588 object_a.flag = false; |
7512 object_b.flag = false; | 7589 object_b.flag = false; |
7513 object_a.handle.SetWeak(&object_a, &DisposeAndSetFlag); | 7590 object_a.handle.SetWeak(&object_a, &ResetUseValueAndSetFlag); |
7514 object_b.handle.SetWeak(&object_b, &DisposeAndSetFlag); | 7591 object_b.handle.SetWeak(&object_b, &ResetUseValueAndSetFlag); |
7515 CHECK(!object_b.handle.IsIndependent()); | 7592 if (!global_gc) { |
7516 object_a.handle.MarkIndependent(); | 7593 object_a.handle.MarkIndependent(); |
7517 object_b.handle.MarkIndependent(); | 7594 object_b.handle.MarkIndependent(); |
7518 CHECK(object_b.handle.IsIndependent()); | 7595 CHECK(object_b.handle.IsIndependent()); |
7519 CcTest::heap()->CollectGarbage(i::NEW_SPACE); | 7596 } |
| 7597 if (global_gc) { |
| 7598 CcTest::heap()->CollectAllGarbage(TestHeap::Heap::kNoGCFlags); |
| 7599 } else { |
| 7600 CcTest::heap()->CollectGarbage(i::NEW_SPACE); |
| 7601 } |
7520 CHECK(object_a.flag); | 7602 CHECK(object_a.flag); |
7521 CHECK(object_b.flag); | 7603 CHECK(object_b.flag); |
7522 } | 7604 } |
7523 | 7605 |
7524 | 7606 |
| 7607 THREADED_TEST(ResetWeakHandle) { |
| 7608 ResetWeakHandle(false); |
| 7609 ResetWeakHandle(true); |
| 7610 } |
| 7611 |
| 7612 |
7525 static void InvokeScavenge() { | 7613 static void InvokeScavenge() { |
7526 CcTest::heap()->CollectGarbage(i::NEW_SPACE); | 7614 CcTest::heap()->CollectGarbage(i::NEW_SPACE); |
7527 } | 7615 } |
7528 | 7616 |
7529 | 7617 |
7530 static void InvokeMarkSweep() { | 7618 static void InvokeMarkSweep() { |
7531 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 7619 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); |
7532 } | 7620 } |
7533 | 7621 |
7534 | 7622 |
(...skipping 16510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
24045 char chunk2[] = | 24133 char chunk2[] = |
24046 "XX\xec\x92\x81r = 13;\n" | 24134 "XX\xec\x92\x81r = 13;\n" |
24047 " return foob\xec\x92\x81\xec\x92\x81r;\n" | 24135 " return foob\xec\x92\x81\xec\x92\x81r;\n" |
24048 "}\n"; | 24136 "}\n"; |
24049 chunk1[strlen(chunk1) - 1] = reference[0]; | 24137 chunk1[strlen(chunk1) - 1] = reference[0]; |
24050 chunk2[0] = reference[1]; | 24138 chunk2[0] = reference[1]; |
24051 chunk2[1] = reference[2]; | 24139 chunk2[1] = reference[2]; |
24052 const char* chunks[] = {chunk1, chunk2, "foo();", NULL}; | 24140 const char* chunks[] = {chunk1, chunk2, "foo();", NULL}; |
24053 RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8); | 24141 RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8); |
24054 } | 24142 } |
OLD | NEW |