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

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

Issue 12729023: first step to remove unsafe handles (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: issue with debug build 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-hashing.cc ('k') | test/cctest/test-heap-profiler.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 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
11 // with the distribution. 11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its 12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived 13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission. 14 // from this software without specific prior written permission.
15 // 15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #include <stdlib.h> 28 #include <stdlib.h>
29 29
30 // TODO(dcarney): remove
31 #define V8_ALLOW_ACCESS_TO_PERSISTENT_ARROW
32 #define V8_ALLOW_ACCESS_TO_PERSISTENT_IMPLICIT
33
30 #include "v8.h" 34 #include "v8.h"
31 35
32 #include "compilation-cache.h" 36 #include "compilation-cache.h"
33 #include "execution.h" 37 #include "execution.h"
34 #include "factory.h" 38 #include "factory.h"
35 #include "macro-assembler.h" 39 #include "macro-assembler.h"
36 #include "global-handles.h" 40 #include "global-handles.h"
37 #include "stub-cache.h" 41 #include "stub-cache.h"
38 #include "cctest.h" 42 #include "cctest.h"
39 43
(...skipping 1246 matching lines...) Expand 10 before | Expand all | Expand 10 after
1286 1290
1287 // Some flags turn Scavenge collections into Mark-sweep collections 1291 // Some flags turn Scavenge collections into Mark-sweep collections
1288 // and hence are incompatible with this test case. 1292 // and hence are incompatible with this test case.
1289 if (FLAG_gc_global || FLAG_stress_compaction) return; 1293 if (FLAG_gc_global || FLAG_stress_compaction) return;
1290 1294
1291 static const int kNumTestContexts = 10; 1295 static const int kNumTestContexts = 10;
1292 1296
1293 Isolate* isolate = Isolate::Current(); 1297 Isolate* isolate = Isolate::Current();
1294 Heap* heap = isolate->heap(); 1298 Heap* heap = isolate->heap();
1295 HandleScope scope(isolate); 1299 HandleScope scope(isolate);
1296 v8::Persistent<v8::Context> ctx[kNumTestContexts]; 1300 v8::Handle<v8::Context> ctx[kNumTestContexts];
1297 1301
1298 CHECK_EQ(0, CountNativeContexts()); 1302 CHECK_EQ(0, CountNativeContexts());
1299 1303
1300 // Create a number of global contests which gets linked together. 1304 // Create a number of global contests which gets linked together.
1301 for (int i = 0; i < kNumTestContexts; i++) { 1305 for (int i = 0; i < kNumTestContexts; i++) {
1302 ctx[i] = v8::Context::New(); 1306 ctx[i] = v8::Context::New(v8::Isolate::GetCurrent());
1303 1307
1304 bool opt = (FLAG_always_opt && i::V8::UseCrankshaft()); 1308 bool opt = (FLAG_always_opt && i::V8::UseCrankshaft());
1305 1309
1306 CHECK_EQ(i + 1, CountNativeContexts()); 1310 CHECK_EQ(i + 1, CountNativeContexts());
1307 1311
1308 ctx[i]->Enter(); 1312 ctx[i]->Enter();
1309 1313
1310 // Create a handle scope so no function objects get stuch in the outer 1314 // Create a handle scope so no function objects get stuch in the outer
1311 // handle scope 1315 // handle scope
1312 HandleScope scope(isolate); 1316 HandleScope scope(isolate);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1359 CHECK_EQ(opt ? 2 : 0, CountOptimizedUserFunctions(ctx[i])); 1363 CHECK_EQ(opt ? 2 : 0, CountOptimizedUserFunctions(ctx[i]));
1360 1364
1361 ctx[i]->Exit(); 1365 ctx[i]->Exit();
1362 } 1366 }
1363 1367
1364 // Force compilation cache cleanup. 1368 // Force compilation cache cleanup.
1365 HEAP->CollectAllGarbage(Heap::kNoGCFlags); 1369 HEAP->CollectAllGarbage(Heap::kNoGCFlags);
1366 1370
1367 // Dispose the native contexts one by one. 1371 // Dispose the native contexts one by one.
1368 for (int i = 0; i < kNumTestContexts; i++) { 1372 for (int i = 0; i < kNumTestContexts; i++) {
1369 ctx[i].Dispose(ctx[i]->GetIsolate()); 1373 // TODO(dcarney): is there a better way to do this?
1374 i::Object** unsafe = reinterpret_cast<i::Object**>(*ctx[i]);
1375 *unsafe = HEAP->undefined_value();
1370 ctx[i].Clear(); 1376 ctx[i].Clear();
1371 1377
1372 // Scavenge treats these references as strong. 1378 // Scavenge treats these references as strong.
1373 for (int j = 0; j < 10; j++) { 1379 for (int j = 0; j < 10; j++) {
1374 HEAP->PerformScavenge(); 1380 HEAP->PerformScavenge();
1375 CHECK_EQ(kNumTestContexts - i, CountNativeContexts()); 1381 CHECK_EQ(kNumTestContexts - i, CountNativeContexts());
1376 } 1382 }
1377 1383
1378 // Mark compact handles the weak references. 1384 // Mark compact handles the weak references.
1379 HEAP->CollectAllGarbage(Heap::kNoGCFlags); 1385 HEAP->CollectAllGarbage(Heap::kNoGCFlags);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1423 } 1429 }
1424 1430
1425 1431
1426 TEST(TestInternalWeakListsTraverseWithGC) { 1432 TEST(TestInternalWeakListsTraverseWithGC) {
1427 v8::V8::Initialize(); 1433 v8::V8::Initialize();
1428 Isolate* isolate = Isolate::Current(); 1434 Isolate* isolate = Isolate::Current();
1429 1435
1430 static const int kNumTestContexts = 10; 1436 static const int kNumTestContexts = 10;
1431 1437
1432 HandleScope scope(isolate); 1438 HandleScope scope(isolate);
1433 v8::Persistent<v8::Context> ctx[kNumTestContexts]; 1439 v8::Handle<v8::Context> ctx[kNumTestContexts];
1434 1440
1435 CHECK_EQ(0, CountNativeContexts()); 1441 CHECK_EQ(0, CountNativeContexts());
1436 1442
1437 // Create an number of contexts and check the length of the weak list both 1443 // Create an number of contexts and check the length of the weak list both
1438 // with and without GCs while iterating the list. 1444 // with and without GCs while iterating the list.
1439 for (int i = 0; i < kNumTestContexts; i++) { 1445 for (int i = 0; i < kNumTestContexts; i++) {
1440 ctx[i] = v8::Context::New(); 1446 ctx[i] = v8::Context::New(v8::Isolate::GetCurrent());
1441 CHECK_EQ(i + 1, CountNativeContexts()); 1447 CHECK_EQ(i + 1, CountNativeContexts());
1442 CHECK_EQ(i + 1, CountNativeContextsWithGC(isolate, i / 2 + 1)); 1448 CHECK_EQ(i + 1, CountNativeContextsWithGC(isolate, i / 2 + 1));
1443 } 1449 }
1444 1450
1445 bool opt = (FLAG_always_opt && i::V8::UseCrankshaft()); 1451 bool opt = (FLAG_always_opt && i::V8::UseCrankshaft());
1446 1452
1447 // Compile a number of functions the length of the weak list of optimized 1453 // Compile a number of functions the length of the weak list of optimized
1448 // functions both with and without GCs while iterating the list. 1454 // functions both with and without GCs while iterating the list.
1449 ctx[0]->Enter(); 1455 ctx[0]->Enter();
1450 const char* source = "function f1() { };" 1456 const char* source = "function f1() { };"
(...skipping 1608 matching lines...) Expand 10 before | Expand all | Expand 10 after
3059 } 3065 }
3060 // An entire block of handles has been filled. 3066 // An entire block of handles has been filled.
3061 // Next handle would require a new block. 3067 // Next handle would require a new block.
3062 ASSERT(data->next == data->limit); 3068 ASSERT(data->next == data->limit);
3063 3069
3064 DeferredHandleScope deferred(isolate); 3070 DeferredHandleScope deferred(isolate);
3065 DummyVisitor visitor; 3071 DummyVisitor visitor;
3066 isolate->handle_scope_implementer()->Iterate(&visitor); 3072 isolate->handle_scope_implementer()->Iterate(&visitor);
3067 deferred.Detach(); 3073 deferred.Detach();
3068 } 3074 }
OLDNEW
« no previous file with comments | « test/cctest/test-hashing.cc ('k') | test/cctest/test-heap-profiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698