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

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

Issue 640303006: Weak Cells (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Skip cleared weak cells Created 6 years, 2 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 | « src/objects-printer.cc ('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 4265 matching lines...) Expand 10 before | Expand all | Expand 10 after
4276 " var proto = {'name' : 'weak'};" 4276 " var proto = {'name' : 'weak'};"
4277 " var obj = Object.create(proto);" 4277 " var obj = Object.create(proto);"
4278 " compareNilIC(obj);" 4278 " compareNilIC(obj);"
4279 " compareNilIC(obj);" 4279 " compareNilIC(obj);"
4280 " compareNilIC(obj);" 4280 " compareNilIC(obj);"
4281 " return proto;" 4281 " return proto;"
4282 " })();"); 4282 " })();");
4283 } 4283 }
4284 4284
4285 4285
4286 TEST(WeakCell) {
4287 CcTest::InitializeVM();
4288 Isolate* isolate = CcTest::i_isolate();
4289 v8::internal::Heap* heap = CcTest::heap();
4290 v8::internal::Factory* factory = isolate->factory();
4291
4292 HandleScope outer_scope(isolate);
4293 Handle<WeakCell> weak_cell1;
4294 {
4295 HandleScope inner_scope(isolate);
4296 Handle<HeapObject> value = factory->NewFixedArray(1, NOT_TENURED);
4297 weak_cell1 = inner_scope.CloseAndEscape(factory->NewWeakCell(value));
4298 }
4299
4300 Handle<FixedArray> survivor = factory->NewFixedArray(1, NOT_TENURED);
4301 Handle<WeakCell> weak_cell2;
4302 {
4303 HandleScope inner_scope(isolate);
4304 weak_cell2 = inner_scope.CloseAndEscape(factory->NewWeakCell(survivor));
4305 }
4306 CHECK(weak_cell1->value()->IsFixedArray());
4307 CHECK_EQ(*survivor, weak_cell2->value());
4308 heap->CollectGarbage(NEW_SPACE);
4309 CHECK(weak_cell1->value()->IsFixedArray());
4310 CHECK_EQ(*survivor, weak_cell2->value());
4311 heap->CollectGarbage(NEW_SPACE);
4312 CHECK(weak_cell1->value()->IsFixedArray());
4313 CHECK_EQ(*survivor, weak_cell2->value());
4314 heap->CollectAllAvailableGarbage();
4315 CHECK_EQ(*survivor, weak_cell2->value());
4316 CHECK(weak_cell2->value()->IsFixedArray());
4317 }
4318
4319
4320 TEST(WeakCellsWithIncrementalMarking) {
4321 CcTest::InitializeVM();
4322 Isolate* isolate = CcTest::i_isolate();
4323 v8::internal::Heap* heap = CcTest::heap();
4324 v8::internal::Factory* factory = isolate->factory();
4325
4326 const int N = 16;
4327 HandleScope outer_scope(isolate);
4328 Handle<FixedArray> survivor = factory->NewFixedArray(1, NOT_TENURED);
4329 Handle<WeakCell> weak_cells[N];
4330
4331 for (int i = 0; i < N; i++) {
4332 HandleScope inner_scope(isolate);
4333 Handle<HeapObject> value =
4334 i == 0 ? survivor : factory->NewFixedArray(1, NOT_TENURED);
4335 Handle<WeakCell> weak_cell = factory->NewWeakCell(value);
4336 CHECK(weak_cell->value()->IsFixedArray());
4337 IncrementalMarking* marking = heap->incremental_marking();
4338 if (marking->IsStopped()) marking->Start();
4339 marking->Step(128, IncrementalMarking::NO_GC_VIA_STACK_GUARD);
4340 heap->CollectGarbage(NEW_SPACE);
4341 CHECK(weak_cell->value()->IsFixedArray());
4342 weak_cells[i] = inner_scope.CloseAndEscape(weak_cell);
4343 }
4344 heap->CollectAllGarbage(Heap::kNoGCFlags);
4345 CHECK_EQ(*survivor, weak_cells[0]->value());
4346 for (int i = 1; i < N; i++) {
4347 CHECK(weak_cells[i]->value()->IsUndefined());
4348 }
4349 }
4350
4351
4286 #ifdef DEBUG 4352 #ifdef DEBUG
4287 TEST(AddInstructionChangesNewSpacePromotion) { 4353 TEST(AddInstructionChangesNewSpacePromotion) {
4288 i::FLAG_allow_natives_syntax = true; 4354 i::FLAG_allow_natives_syntax = true;
4289 i::FLAG_expose_gc = true; 4355 i::FLAG_expose_gc = true;
4290 i::FLAG_stress_compaction = true; 4356 i::FLAG_stress_compaction = true;
4291 i::FLAG_gc_interval = 1000; 4357 i::FLAG_gc_interval = 1000;
4292 CcTest::InitializeVM(); 4358 CcTest::InitializeVM();
4293 if (!i::FLAG_allocation_site_pretenuring) return; 4359 if (!i::FLAG_allocation_site_pretenuring) return;
4294 v8::HandleScope scope(CcTest::isolate()); 4360 v8::HandleScope scope(CcTest::isolate());
4295 Isolate* isolate = CcTest::i_isolate(); 4361 Isolate* isolate = CcTest::i_isolate();
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
4547 #ifdef DEBUG 4613 #ifdef DEBUG
4548 TEST(PathTracer) { 4614 TEST(PathTracer) {
4549 CcTest::InitializeVM(); 4615 CcTest::InitializeVM();
4550 v8::HandleScope scope(CcTest::isolate()); 4616 v8::HandleScope scope(CcTest::isolate());
4551 4617
4552 v8::Local<v8::Value> result = CompileRun("'abc'"); 4618 v8::Local<v8::Value> result = CompileRun("'abc'");
4553 Handle<Object> o = v8::Utils::OpenHandle(*result); 4619 Handle<Object> o = v8::Utils::OpenHandle(*result);
4554 CcTest::i_isolate()->heap()->TracePathToObject(*o); 4620 CcTest::i_isolate()->heap()->TracePathToObject(*o);
4555 } 4621 }
4556 #endif // DEBUG 4622 #endif // DEBUG
OLDNEW
« no previous file with comments | « src/objects-printer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698