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

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

Issue 14908004: add weakcallback without persistent copying (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: missed some instances Created 7 years, 7 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 | « test/cctest/test-mark-compact.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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 Handle<Object> value) { 58 Handle<Object> value) {
59 Handle<ObjectHashTable> table = PutIntoObjectHashTable( 59 Handle<ObjectHashTable> table = PutIntoObjectHashTable(
60 Handle<ObjectHashTable>(ObjectHashTable::cast(weakmap->table())), 60 Handle<ObjectHashTable>(ObjectHashTable::cast(weakmap->table())),
61 Handle<JSObject>(JSObject::cast(*key)), 61 Handle<JSObject>(JSObject::cast(*key)),
62 value); 62 value);
63 weakmap->set_table(*table); 63 weakmap->set_table(*table);
64 } 64 }
65 65
66 static int NumberOfWeakCalls = 0; 66 static int NumberOfWeakCalls = 0;
67 static void WeakPointerCallback(v8::Isolate* isolate, 67 static void WeakPointerCallback(v8::Isolate* isolate,
68 v8::Persistent<v8::Value> handle, 68 v8::Persistent<v8::Value>* handle,
69 void* id) { 69 void* id) {
70 ASSERT(id == reinterpret_cast<void*>(1234)); 70 ASSERT(id == reinterpret_cast<void*>(1234));
71 NumberOfWeakCalls++; 71 NumberOfWeakCalls++;
72 handle.Dispose(isolate); 72 handle->Dispose(isolate);
73 } 73 }
74 74
75 75
76 TEST(Weakness) { 76 TEST(Weakness) {
77 FLAG_incremental_marking = false; 77 FLAG_incremental_marking = false;
78 LocalContext context; 78 LocalContext context;
79 Isolate* isolate = GetIsolateFrom(&context); 79 Isolate* isolate = GetIsolateFrom(&context);
80 Factory* factory = isolate->factory(); 80 Factory* factory = isolate->factory();
81 Heap* heap = isolate->heap(); 81 Heap* heap = isolate->heap();
82 HandleScope scope(isolate); 82 HandleScope scope(isolate);
(...skipping 24 matching lines...) Expand all
107 CHECK_EQ(0, NumberOfWeakCalls); 107 CHECK_EQ(0, NumberOfWeakCalls);
108 CHECK_EQ(1, ObjectHashTable::cast(weakmap->table())->NumberOfElements()); 108 CHECK_EQ(1, ObjectHashTable::cast(weakmap->table())->NumberOfElements());
109 CHECK_EQ( 109 CHECK_EQ(
110 0, ObjectHashTable::cast(weakmap->table())->NumberOfDeletedElements()); 110 0, ObjectHashTable::cast(weakmap->table())->NumberOfDeletedElements());
111 111
112 // Make the global reference to the key weak. 112 // Make the global reference to the key weak.
113 { 113 {
114 HandleScope scope(isolate); 114 HandleScope scope(isolate);
115 global_handles->MakeWeak(key.location(), 115 global_handles->MakeWeak(key.location(),
116 reinterpret_cast<void*>(1234), 116 reinterpret_cast<void*>(1234),
117 NULL, 117 &WeakPointerCallback,
118 &WeakPointerCallback); 118 NULL);
119 } 119 }
120 CHECK(global_handles->IsWeak(key.location())); 120 CHECK(global_handles->IsWeak(key.location()));
121 121
122 // Force a full GC. 122 // Force a full GC.
123 // Perform two consecutive GCs because the first one will only clear 123 // Perform two consecutive GCs because the first one will only clear
124 // weak references whereas the second one will also clear weak maps. 124 // weak references whereas the second one will also clear weak maps.
125 heap->CollectAllGarbage(false); 125 heap->CollectAllGarbage(false);
126 CHECK_EQ(1, NumberOfWeakCalls); 126 CHECK_EQ(1, NumberOfWeakCalls);
127 CHECK_EQ(1, ObjectHashTable::cast(weakmap->table())->NumberOfElements()); 127 CHECK_EQ(1, ObjectHashTable::cast(weakmap->table())->NumberOfElements());
128 CHECK_EQ( 128 CHECK_EQ(
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 Handle<Smi>(Smi::FromInt(i), isolate)); 242 Handle<Smi>(Smi::FromInt(i), isolate));
243 } 243 }
244 244
245 // Force compacting garbage collection. The subsequent collections are used 245 // Force compacting garbage collection. The subsequent collections are used
246 // to verify that key references were actually updated. 246 // to verify that key references were actually updated.
247 CHECK(FLAG_always_compact); 247 CHECK(FLAG_always_compact);
248 heap->CollectAllGarbage(Heap::kNoGCFlags); 248 heap->CollectAllGarbage(Heap::kNoGCFlags);
249 heap->CollectAllGarbage(Heap::kNoGCFlags); 249 heap->CollectAllGarbage(Heap::kNoGCFlags);
250 heap->CollectAllGarbage(Heap::kNoGCFlags); 250 heap->CollectAllGarbage(Heap::kNoGCFlags);
251 } 251 }
OLDNEW
« no previous file with comments | « test/cctest/test-mark-compact.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698