2018-07-04 18:11:11 +00:00
|
|
|
// Copyright 2018 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-02-14 21:10:30 +00:00
|
|
|
#include "src/heap/heap-inl.h"
|
|
|
|
#include "src/objects/cell.h"
|
|
|
|
#include "src/objects/feedback-cell.h"
|
|
|
|
#include "src/objects/script.h"
|
2019-05-24 13:51:59 +00:00
|
|
|
#include "src/roots/roots-inl.h"
|
2018-07-04 18:11:11 +00:00
|
|
|
#include "test/cctest/cctest.h"
|
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
namespace {
|
2018-12-25 00:19:47 +00:00
|
|
|
AllocationSpace GetSpaceFromObject(Object object) {
|
2019-05-23 07:47:44 +00:00
|
|
|
DCHECK(object.IsHeapObject());
|
2018-07-04 18:11:11 +00:00
|
|
|
return MemoryChunk::FromHeapObject(HeapObject::cast(object))
|
2019-06-04 10:53:21 +00:00
|
|
|
->owner_identity();
|
2018-07-04 18:11:11 +00:00
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2018-09-24 08:27:30 +00:00
|
|
|
#define CHECK_IN_RO_SPACE(type, name, CamelName) \
|
2018-12-20 15:47:47 +00:00
|
|
|
HeapObject name = roots.name(); \
|
2018-07-04 18:11:11 +00:00
|
|
|
CHECK_EQ(RO_SPACE, GetSpaceFromObject(name));
|
|
|
|
|
|
|
|
// The following tests check that all the roots accessible via ReadOnlyRoots are
|
|
|
|
// in RO_SPACE.
|
2018-09-24 10:37:57 +00:00
|
|
|
TEST(TestReadOnlyRoots) {
|
2018-07-04 18:11:11 +00:00
|
|
|
ReadOnlyRoots roots(CcTest::i_isolate());
|
|
|
|
|
2018-09-24 10:37:57 +00:00
|
|
|
READ_ONLY_ROOT_LIST(CHECK_IN_RO_SPACE)
|
2018-07-04 18:11:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#undef CHECK_IN_RO_SPACE
|
|
|
|
|
|
|
|
namespace {
|
2018-07-24 13:11:34 +00:00
|
|
|
bool IsInitiallyMutable(Factory* factory, Address object_address) {
|
2018-10-09 23:19:09 +00:00
|
|
|
// Entries in this list are in STRONG_MUTABLE_MOVABLE_ROOT_LIST, but may
|
|
|
|
// initially point to objects that are in RO_SPACE.
|
2018-07-24 13:11:34 +00:00
|
|
|
#define INITIALLY_READ_ONLY_ROOT_LIST(V) \
|
2018-10-09 14:32:31 +00:00
|
|
|
V(api_private_symbol_table) \
|
|
|
|
V(api_symbol_table) \
|
2018-07-24 13:11:34 +00:00
|
|
|
V(builtins_constants_table) \
|
2018-10-12 07:49:50 +00:00
|
|
|
V(current_microtask) \
|
2018-07-24 13:11:34 +00:00
|
|
|
V(detached_contexts) \
|
2019-01-30 12:06:32 +00:00
|
|
|
V(dirty_js_finalization_groups) \
|
2018-07-24 13:11:34 +00:00
|
|
|
V(feedback_vectors_for_profiling_tools) \
|
2019-09-09 10:19:34 +00:00
|
|
|
V(shared_wasm_memories) \
|
2018-07-24 13:11:34 +00:00
|
|
|
V(materialized_objects) \
|
2018-10-09 14:32:31 +00:00
|
|
|
V(public_symbol_table) \
|
2018-07-24 13:11:34 +00:00
|
|
|
V(retained_maps) \
|
|
|
|
V(retaining_path_targets) \
|
|
|
|
V(serialized_global_proxy_sizes) \
|
2018-11-05 14:21:02 +00:00
|
|
|
V(serialized_objects) \
|
|
|
|
V(weak_refs_keep_during_job)
|
2018-07-04 18:11:11 +00:00
|
|
|
|
|
|
|
#define TEST_CAN_BE_READ_ONLY(name) \
|
2018-07-24 13:11:34 +00:00
|
|
|
if (factory->name().address() == object_address) return false;
|
2018-07-04 18:11:11 +00:00
|
|
|
INITIALLY_READ_ONLY_ROOT_LIST(TEST_CAN_BE_READ_ONLY)
|
|
|
|
#undef TEST_CAN_BE_READ_ONLY
|
|
|
|
#undef INITIALLY_READ_ONLY_ROOT_LIST
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2018-07-24 13:11:34 +00:00
|
|
|
// The CHECK_EQ line is there just to ensure that the root is publicly
|
|
|
|
// accessible from Heap, but ultimately the factory is used as it provides
|
|
|
|
// handles that have the address in the root table.
|
2019-01-22 14:45:10 +00:00
|
|
|
#define CHECK_NOT_IN_RO_SPACE(type, name, CamelName) \
|
|
|
|
Handle<Object> name = factory->name(); \
|
|
|
|
CHECK_EQ(*name, heap->name()); \
|
|
|
|
if (name->IsHeapObject() && IsInitiallyMutable(factory, name.address()) && \
|
|
|
|
!name->IsUndefined(CcTest::i_isolate())) { \
|
|
|
|
CHECK_NE(RO_SPACE, GetSpaceFromObject(HeapObject::cast(*name))); \
|
|
|
|
}
|
2018-07-04 18:11:11 +00:00
|
|
|
|
|
|
|
// The following tests check that all the roots accessible via public Heap
|
|
|
|
// accessors are not in RO_SPACE with the exception of the objects listed in
|
|
|
|
// INITIALLY_READ_ONLY_ROOT_LIST.
|
|
|
|
TEST(TestHeapRootsNotReadOnly) {
|
2018-07-24 13:11:34 +00:00
|
|
|
Factory* factory = CcTest::i_isolate()->factory();
|
2018-07-04 18:11:11 +00:00
|
|
|
Heap* heap = CcTest::i_isolate()->heap();
|
|
|
|
|
2018-09-24 09:25:21 +00:00
|
|
|
MUTABLE_ROOT_LIST(CHECK_NOT_IN_RO_SPACE)
|
2018-07-04 18:11:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#undef CHECK_NOT_IN_RO_SPACE
|
|
|
|
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|