LCOV - code coverage report
Current view: top level - test/cctest - test-roots.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 10 10 100.0 %
Date: 2019-04-17 Functions: 5 5 100.0 %

          Line data    Source code
       1             : // Copyright 2018 the V8 project authors. All rights reserved.
       2             : // Use of this source code is governed by a BSD-style license that can be
       3             : // found in the LICENSE file.
       4             : 
       5             : #include "src/heap/heap-inl.h"
       6             : #include "src/objects/cell.h"
       7             : #include "src/objects/feedback-cell.h"
       8             : #include "src/objects/script.h"
       9             : #include "src/roots-inl.h"
      10             : #include "test/cctest/cctest.h"
      11             : 
      12             : namespace v8 {
      13             : namespace internal {
      14             : 
      15             : namespace {
      16             : AllocationSpace GetSpaceFromObject(Object object) {
      17             :   DCHECK(object->IsHeapObject());
      18             :   return MemoryChunk::FromHeapObject(HeapObject::cast(object))
      19             :       ->owner()
      20             :       ->identity();
      21             : }
      22             : }  // namespace
      23             : 
      24             : #define CHECK_IN_RO_SPACE(type, name, CamelName) \
      25             :   HeapObject name = roots.name();                \
      26             :   CHECK_EQ(RO_SPACE, GetSpaceFromObject(name));
      27             : 
      28             : // The following tests check that all the roots accessible via ReadOnlyRoots are
      29             : // in RO_SPACE.
      30       26644 : TEST(TestReadOnlyRoots) {
      31             :   ReadOnlyRoots roots(CcTest::i_isolate());
      32             : 
      33        2675 :   READ_ONLY_ROOT_LIST(CHECK_IN_RO_SPACE)
      34           5 : }
      35             : 
      36             : #undef CHECK_IN_RO_SPACE
      37             : 
      38             : namespace {
      39         280 : bool IsInitiallyMutable(Factory* factory, Address object_address) {
      40             : // Entries in this list are in STRONG_MUTABLE_MOVABLE_ROOT_LIST, but may
      41             : // initially point to objects that are in RO_SPACE.
      42             : #define INITIALLY_READ_ONLY_ROOT_LIST(V)  \
      43             :   V(api_private_symbol_table)             \
      44             :   V(api_symbol_table)                     \
      45             :   V(builtins_constants_table)             \
      46             :   V(current_microtask)                    \
      47             :   V(detached_contexts)                    \
      48             :   V(dirty_js_finalization_groups)         \
      49             :   V(feedback_vectors_for_profiling_tools) \
      50             :   V(materialized_objects)                 \
      51             :   V(noscript_shared_function_infos)       \
      52             :   V(public_symbol_table)                  \
      53             :   V(retained_maps)                        \
      54             :   V(retaining_path_targets)               \
      55             :   V(serialized_global_proxy_sizes)        \
      56             :   V(serialized_objects)                   \
      57             :   V(weak_refs_keep_during_job)
      58             : 
      59             : #define TEST_CAN_BE_READ_ONLY(name) \
      60             :   if (factory->name().address() == object_address) return false;
      61        3675 :   INITIALLY_READ_ONLY_ROOT_LIST(TEST_CAN_BE_READ_ONLY)
      62             : #undef TEST_CAN_BE_READ_ONLY
      63             : #undef INITIALLY_READ_ONLY_ROOT_LIST
      64         205 :   return true;
      65             : }
      66             : }  // namespace
      67             : 
      68             : // The CHECK_EQ line is there just to ensure that the root is publicly
      69             : // accessible from Heap, but ultimately the factory is used as it provides
      70             : // handles that have the address in the root table.
      71             : #define CHECK_NOT_IN_RO_SPACE(type, name, CamelName)                         \
      72             :   Handle<Object> name = factory->name();                                     \
      73             :   CHECK_EQ(*name, heap->name());                                             \
      74             :   if (name->IsHeapObject() && IsInitiallyMutable(factory, name.address()) && \
      75             :       !name->IsUndefined(CcTest::i_isolate())) {                             \
      76             :     CHECK_NE(RO_SPACE, GetSpaceFromObject(HeapObject::cast(*name)));         \
      77             :   }
      78             : 
      79             : // The following tests check that all the roots accessible via public Heap
      80             : // accessors are not in RO_SPACE with the exception of the objects listed in
      81             : // INITIALLY_READ_ONLY_ROOT_LIST.
      82       26644 : TEST(TestHeapRootsNotReadOnly) {
      83             :   Factory* factory = CcTest::i_isolate()->factory();
      84             :   Heap* heap = CcTest::i_isolate()->heap();
      85             : 
      86        1055 :   MUTABLE_ROOT_LIST(CHECK_NOT_IN_RO_SPACE)
      87           5 : }
      88             : 
      89             : #undef CHECK_NOT_IN_RO_SPACE
      90             : 
      91             : }  // namespace internal
      92       79917 : }  // namespace v8

Generated by: LCOV version 1.10