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

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

Issue 1314863003: [heap] More flag cleanup. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Added more comments Created 5 years, 3 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
« no previous file with comments | « test/cctest/test-object-observe.cc ('k') | test/cctest/test-weaksets.cc » ('j') | 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 Handle<JSObject> object = factory->NewJSObjectFromMap(map); 89 Handle<JSObject> object = factory->NewJSObjectFromMap(map);
90 Handle<Smi> smi(Smi::FromInt(23), isolate); 90 Handle<Smi> smi(Smi::FromInt(23), isolate);
91 int32_t hash = Object::GetOrCreateHash(isolate, key)->value(); 91 int32_t hash = Object::GetOrCreateHash(isolate, key)->value();
92 JSWeakCollection::Set(weakmap, key, object, hash); 92 JSWeakCollection::Set(weakmap, key, object, hash);
93 int32_t object_hash = Object::GetOrCreateHash(isolate, object)->value(); 93 int32_t object_hash = Object::GetOrCreateHash(isolate, object)->value();
94 JSWeakCollection::Set(weakmap, object, smi, object_hash); 94 JSWeakCollection::Set(weakmap, object, smi, object_hash);
95 } 95 }
96 CHECK_EQ(2, ObjectHashTable::cast(weakmap->table())->NumberOfElements()); 96 CHECK_EQ(2, ObjectHashTable::cast(weakmap->table())->NumberOfElements());
97 97
98 // Force a full GC. 98 // Force a full GC.
99 heap->CollectAllGarbage(false); 99 heap->CollectAllGarbage("Weakness", Heap::kNoGCFlags);
100 CHECK_EQ(0, NumberOfWeakCalls); 100 CHECK_EQ(0, NumberOfWeakCalls);
101 CHECK_EQ(2, ObjectHashTable::cast(weakmap->table())->NumberOfElements()); 101 CHECK_EQ(2, ObjectHashTable::cast(weakmap->table())->NumberOfElements());
102 CHECK_EQ( 102 CHECK_EQ(
103 0, ObjectHashTable::cast(weakmap->table())->NumberOfDeletedElements()); 103 0, ObjectHashTable::cast(weakmap->table())->NumberOfDeletedElements());
104 104
105 // Make the global reference to the key weak. 105 // Make the global reference to the key weak.
106 { 106 {
107 HandleScope scope(isolate); 107 HandleScope scope(isolate);
108 std::pair<Handle<Object>*, int> handle_and_id(&key, 1234); 108 std::pair<Handle<Object>*, int> handle_and_id(&key, 1234);
109 GlobalHandles::MakeWeak(key.location(), 109 GlobalHandles::MakeWeak(key.location(),
110 reinterpret_cast<void*>(&handle_and_id), 110 reinterpret_cast<void*>(&handle_and_id),
111 &WeakPointerCallback); 111 &WeakPointerCallback);
112 } 112 }
113 CHECK(global_handles->IsWeak(key.location())); 113 CHECK(global_handles->IsWeak(key.location()));
114 114
115 // Force a full GC. 115 // Force a full GC.
116 // Perform two consecutive GCs because the first one will only clear 116 // Perform two consecutive GCs because the first one will only clear
117 // weak references whereas the second one will also clear weak maps. 117 // weak references whereas the second one will also clear weak maps.
118 heap->CollectAllGarbage(false); 118 heap->CollectAllGarbage("Weakness", Heap::kNoGCFlags);
119 CHECK_EQ(1, NumberOfWeakCalls); 119 CHECK_EQ(1, NumberOfWeakCalls);
120 CHECK_EQ(2, ObjectHashTable::cast(weakmap->table())->NumberOfElements()); 120 CHECK_EQ(2, ObjectHashTable::cast(weakmap->table())->NumberOfElements());
121 CHECK_EQ( 121 CHECK_EQ(
122 0, ObjectHashTable::cast(weakmap->table())->NumberOfDeletedElements()); 122 0, ObjectHashTable::cast(weakmap->table())->NumberOfDeletedElements());
123 heap->CollectAllGarbage(false); 123 heap->CollectAllGarbage("Weakness", Heap::kNoGCFlags);
124 CHECK_EQ(1, NumberOfWeakCalls); 124 CHECK_EQ(1, NumberOfWeakCalls);
125 CHECK_EQ(0, ObjectHashTable::cast(weakmap->table())->NumberOfElements()); 125 CHECK_EQ(0, ObjectHashTable::cast(weakmap->table())->NumberOfElements());
126 CHECK_EQ(2, 126 CHECK_EQ(2,
127 ObjectHashTable::cast(weakmap->table())->NumberOfDeletedElements()); 127 ObjectHashTable::cast(weakmap->table())->NumberOfDeletedElements());
128 } 128 }
129 129
130 130
131 TEST(Shrinking) { 131 TEST(Shrinking) {
132 LocalContext context; 132 LocalContext context;
133 Isolate* isolate = GetIsolateFrom(&context); 133 Isolate* isolate = GetIsolateFrom(&context);
(...skipping 17 matching lines...) Expand all
151 } 151 }
152 } 152 }
153 153
154 // Check increased capacity. 154 // Check increased capacity.
155 CHECK_EQ(128, ObjectHashTable::cast(weakmap->table())->Capacity()); 155 CHECK_EQ(128, ObjectHashTable::cast(weakmap->table())->Capacity());
156 156
157 // Force a full GC. 157 // Force a full GC.
158 CHECK_EQ(32, ObjectHashTable::cast(weakmap->table())->NumberOfElements()); 158 CHECK_EQ(32, ObjectHashTable::cast(weakmap->table())->NumberOfElements());
159 CHECK_EQ( 159 CHECK_EQ(
160 0, ObjectHashTable::cast(weakmap->table())->NumberOfDeletedElements()); 160 0, ObjectHashTable::cast(weakmap->table())->NumberOfDeletedElements());
161 heap->CollectAllGarbage(false); 161 heap->CollectAllGarbage("Shrinking", Heap::kNoGCFlags);
162 CHECK_EQ(0, ObjectHashTable::cast(weakmap->table())->NumberOfElements()); 162 CHECK_EQ(0, ObjectHashTable::cast(weakmap->table())->NumberOfElements());
163 CHECK_EQ( 163 CHECK_EQ(
164 32, ObjectHashTable::cast(weakmap->table())->NumberOfDeletedElements()); 164 32, ObjectHashTable::cast(weakmap->table())->NumberOfDeletedElements());
165 165
166 // Check shrunk capacity. 166 // Check shrunk capacity.
167 CHECK_EQ(32, ObjectHashTable::cast(weakmap->table())->Capacity()); 167 CHECK_EQ(32, ObjectHashTable::cast(weakmap->table())->Capacity());
168 } 168 }
169 169
170 170
171 // Test that weak map values on an evacuation candidate which are not reachable 171 // Test that weak map values on an evacuation candidate which are not reachable
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 { 259 {
260 HandleScope scope(isolate); 260 HandleScope scope(isolate);
261 AllocateJSWeakMap(isolate); 261 AllocateJSWeakMap(isolate);
262 SimulateIncrementalMarking(heap); 262 SimulateIncrementalMarking(heap);
263 } 263 }
264 // The weak map is marked black here but leaving the handle scope will make 264 // The weak map is marked black here but leaving the handle scope will make
265 // the object unreachable. Aborting incremental marking will clear all the 265 // the object unreachable. Aborting incremental marking will clear all the
266 // marking bits which makes the weak map garbage. 266 // marking bits which makes the weak map garbage.
267 heap->CollectAllGarbage(); 267 heap->CollectAllGarbage();
268 } 268 }
OLDNEW
« no previous file with comments | « test/cctest/test-object-observe.cc ('k') | test/cctest/test-weaksets.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698