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

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

Issue 677403002: Revert 'Introduce phantom weak handles in the API and use them internally for debug info' (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 1 month 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/globals.h ('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 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 7451 matching lines...) Expand 10 before | Expand all | Expand 10 after
7462 v8::V8::RemoveMessageListeners(MissingScriptInfoMessageListener); 7462 v8::V8::RemoveMessageListeners(MissingScriptInfoMessageListener);
7463 } 7463 }
7464 7464
7465 7465
7466 struct FlagAndPersistent { 7466 struct FlagAndPersistent {
7467 bool flag; 7467 bool flag;
7468 v8::Persistent<v8::Object> handle; 7468 v8::Persistent<v8::Object> handle;
7469 }; 7469 };
7470 7470
7471 7471
7472 static void SetFlag( 7472 static void DisposeAndSetFlag(
7473 const v8::WeakCallbackData<v8::Object, FlagAndPersistent>& data) { 7473 const v8::WeakCallbackData<v8::Object, FlagAndPersistent>& data) {
7474 data.GetParameter()->handle.Reset();
7474 data.GetParameter()->flag = true; 7475 data.GetParameter()->flag = true;
7475 } 7476 }
7476 7477
7477 7478
7478 static void IndependentWeakHandle(bool global_gc, bool interlinked) { 7479 THREADED_TEST(IndependentWeakHandle) {
7479 v8::Isolate* iso = CcTest::isolate(); 7480 v8::Isolate* iso = CcTest::isolate();
7480 v8::HandleScope scope(iso); 7481 v8::HandleScope scope(iso);
7481 v8::Handle<Context> context = Context::New(iso); 7482 v8::Handle<Context> context = Context::New(iso);
7482 Context::Scope context_scope(context); 7483 Context::Scope context_scope(context);
7483 7484
7484 FlagAndPersistent object_a, object_b; 7485 FlagAndPersistent object_a, object_b;
7485 7486
7486 intptr_t big_heap_size;
7487
7488 { 7487 {
7489 v8::HandleScope handle_scope(iso); 7488 v8::HandleScope handle_scope(iso);
7490 Local<Object> a(v8::Object::New(iso)); 7489 object_a.handle.Reset(iso, v8::Object::New(iso));
7491 Local<Object> b(v8::Object::New(iso)); 7490 object_b.handle.Reset(iso, v8::Object::New(iso));
7492 object_a.handle.Reset(iso, a);
7493 object_b.handle.Reset(iso, b);
7494 if (interlinked) {
7495 a->Set(v8_str("x"), b);
7496 b->Set(v8_str("x"), a);
7497 }
7498 if (global_gc) {
7499 CcTest::heap()->CollectAllGarbage(TestHeap::Heap::kNoGCFlags);
7500 } else {
7501 CcTest::heap()->CollectGarbage(i::NEW_SPACE);
7502 }
7503 // We are relying on this creating a big flag array and reserving the space
7504 // up front.
7505 v8::Handle<Value> big_array = CompileRun("new Array(50000)");
7506 a->Set(v8_str("y"), big_array);
7507 big_heap_size = CcTest::heap()->SizeOfObjects();
7508 } 7491 }
7509 7492
7510 object_a.flag = false; 7493 object_a.flag = false;
7511 object_b.flag = false; 7494 object_b.flag = false;
7512 object_a.handle.SetPhantom(&object_a, &SetFlag); 7495 object_a.handle.SetWeak(&object_a, &DisposeAndSetFlag);
7513 object_b.handle.SetPhantom(&object_b, &SetFlag); 7496 object_b.handle.SetWeak(&object_b, &DisposeAndSetFlag);
7514 CHECK(!object_b.handle.IsIndependent()); 7497 CHECK(!object_b.handle.IsIndependent());
7515 object_a.handle.MarkIndependent(); 7498 object_a.handle.MarkIndependent();
7516 object_b.handle.MarkIndependent(); 7499 object_b.handle.MarkIndependent();
7517 CHECK(object_b.handle.IsIndependent()); 7500 CHECK(object_b.handle.IsIndependent());
7518 if (global_gc) { 7501 CcTest::heap()->CollectGarbage(i::NEW_SPACE);
7519 CcTest::heap()->CollectAllGarbage(TestHeap::Heap::kNoGCFlags);
7520 } else {
7521 CcTest::heap()->CollectGarbage(i::NEW_SPACE);
7522 }
7523 // A single GC should be enough to reclaim the memory, since we are using
7524 // phantom handles.
7525 CHECK_LT(CcTest::heap()->SizeOfObjects(), big_heap_size - 200000);
7526 CHECK(object_a.flag); 7502 CHECK(object_a.flag);
7527 CHECK(object_b.flag); 7503 CHECK(object_b.flag);
7528 } 7504 }
7529 7505
7530 7506
7531 THREADED_TEST(IndependentWeakHandle) {
7532 IndependentWeakHandle(false, false);
7533 IndependentWeakHandle(false, true);
7534 IndependentWeakHandle(true, false);
7535 IndependentWeakHandle(true, true);
7536 }
7537
7538
7539 static void InvokeScavenge() { 7507 static void InvokeScavenge() {
7540 CcTest::heap()->CollectGarbage(i::NEW_SPACE); 7508 CcTest::heap()->CollectGarbage(i::NEW_SPACE);
7541 } 7509 }
7542 7510
7543 7511
7544 static void InvokeMarkSweep() { 7512 static void InvokeMarkSweep() {
7545 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 7513 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
7546 } 7514 }
7547 7515
7548 7516
(...skipping 16468 matching lines...) Expand 10 before | Expand all | Expand 10 after
24017 char chunk2[] = 23985 char chunk2[] =
24018 "XX\xec\x92\x81r = 13;\n" 23986 "XX\xec\x92\x81r = 13;\n"
24019 " return foob\xec\x92\x81\xec\x92\x81r;\n" 23987 " return foob\xec\x92\x81\xec\x92\x81r;\n"
24020 "}\n"; 23988 "}\n";
24021 chunk1[strlen(chunk1) - 1] = reference[0]; 23989 chunk1[strlen(chunk1) - 1] = reference[0];
24022 chunk2[0] = reference[1]; 23990 chunk2[0] = reference[1];
24023 chunk2[1] = reference[2]; 23991 chunk2[1] = reference[2];
24024 const char* chunks[] = {chunk1, chunk2, "foo();", NULL}; 23992 const char* chunks[] = {chunk1, chunk2, "foo();", NULL};
24025 RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8); 23993 RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8);
24026 } 23994 }
OLDNEW
« no previous file with comments | « src/globals.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698