OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/identity-map.h" | 7 #include "src/identity-map.h" |
8 #include "src/zone.h" | 8 #include "src/zone.h" |
9 | 9 |
10 #include "test/cctest/cctest.h" | 10 #include "test/cctest/cctest.h" |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 // Do an explicit, real GC. | 329 // Do an explicit, real GC. |
330 t.heap()->CollectGarbage(i::NEW_SPACE); | 330 t.heap()->CollectGarbage(i::NEW_SPACE); |
331 | 331 |
332 // Check that searching for the numbers finds the same values. | 332 // Check that searching for the numbers finds the same values. |
333 for (size_t i = 0; i < arraysize(num_keys); i++) { | 333 for (size_t i = 0; i < arraysize(num_keys); i++) { |
334 t.CheckFind(num_keys[i], &num_keys[i]); | 334 t.CheckFind(num_keys[i], &num_keys[i]); |
335 t.CheckGet(num_keys[i], &num_keys[i]); | 335 t.CheckGet(num_keys[i], &num_keys[i]); |
336 } | 336 } |
337 } | 337 } |
338 | 338 |
339 | |
340 TEST(CanonicalHandleScope) { | |
341 Isolate* isolate = CcTest::i_isolate(); | |
342 Heap* heap = CcTest::heap(); | |
343 HandleScope outer(isolate); | |
344 CanonicalHandleScope outer_canonical(isolate); | |
345 | |
346 // Deduplicate smi handles. | |
347 List<Handle<Object> > smi_handles; | |
348 for (int i = 0; i < 100; i++) { | |
349 smi_handles.Add(Handle<Object>(Smi::FromInt(i), isolate)); | |
350 } | |
351 Object** next_handle = isolate->handle_scope_data()->next; | |
352 for (int i = 0; i < 100; i++) { | |
353 Handle<Object> new_smi = Handle<Object>(Smi::FromInt(i), isolate); | |
354 Handle<Object> old_smi = smi_handles[i]; | |
355 CHECK_EQ(new_smi.location(), old_smi.location()); | |
356 } | |
357 // Check that no new handles have been allocated. | |
358 CHECK_EQ(next_handle, isolate->handle_scope_data()->next); | |
359 | |
360 // Deduplicate root list items. | |
361 Handle<String> empty_string(heap->empty_string()); | |
362 Handle<Map> free_space_map(heap->free_space_map()); | |
363 Handle<Symbol> uninitialized_symbol(heap->uninitialized_symbol()); | |
364 CHECK_EQ(isolate->factory()->empty_string().location(), | |
365 empty_string.location()); | |
366 CHECK_EQ(isolate->factory()->free_space_map().location(), | |
367 free_space_map.location()); | |
368 CHECK_EQ(isolate->factory()->uninitialized_symbol().location(), | |
369 uninitialized_symbol.location()); | |
370 // Check that no new handles have been allocated. | |
371 CHECK_EQ(next_handle, isolate->handle_scope_data()->next); | |
372 | |
373 // Test ordinary heap objects. | |
374 Handle<HeapNumber> number1 = isolate->factory()->NewHeapNumber(3.3); | |
375 Handle<String> string1 = | |
376 isolate->factory()->NewStringFromAsciiChecked("test"); | |
377 next_handle = isolate->handle_scope_data()->next; | |
378 Handle<HeapNumber> number2(*number1); | |
379 Handle<String> string2(*string1); | |
380 CHECK_EQ(number1.location(), number2.location()); | |
381 CHECK_EQ(string1.location(), string2.location()); | |
382 heap->CollectAllGarbage(); | |
383 Handle<HeapNumber> number3(*number2); | |
384 Handle<String> string3(*string2); | |
385 CHECK_EQ(number1.location(), number3.location()); | |
386 CHECK_EQ(string1.location(), string3.location()); | |
387 // Check that no new handles have been allocated. | |
388 CHECK_EQ(next_handle, isolate->handle_scope_data()->next); | |
389 | |
390 // Inner handle scope do not create canonical handles. | |
391 { | |
392 HandleScope inner(isolate); | |
393 Handle<HeapNumber> number4(*number1); | |
394 Handle<String> string4(*string1); | |
395 CHECK_NE(number1.location(), number4.location()); | |
396 CHECK_NE(string1.location(), string4.location()); | |
397 | |
398 // Nested canonical scope does not conflict with outer canonical scope, | |
399 // but does not canonicalize across scopes. | |
400 CanonicalHandleScope inner_canonical(isolate); | |
401 Handle<HeapNumber> number5(*number4); | |
402 Handle<String> string5(*string4); | |
403 CHECK_NE(number4.location(), number5.location()); | |
404 CHECK_NE(string4.location(), string5.location()); | |
405 CHECK_NE(number1.location(), number5.location()); | |
406 CHECK_NE(string1.location(), string5.location()); | |
407 | |
408 Handle<HeapNumber> number6(*number1); | |
409 Handle<String> string6(*string1); | |
410 CHECK_NE(number4.location(), number6.location()); | |
411 CHECK_NE(string4.location(), string6.location()); | |
412 CHECK_NE(number1.location(), number6.location()); | |
413 CHECK_NE(string1.location(), string6.location()); | |
414 CHECK_EQ(number5.location(), number6.location()); | |
415 CHECK_EQ(string5.location(), string6.location()); | |
416 } | |
417 } | |
418 | |
419 } // namespace internal | 339 } // namespace internal |
420 } // namespace v8 | 340 } // namespace v8 |
OLD | NEW |