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.
|
|
|
|
|
2020-06-17 13:28:23 +00:00
|
|
|
#include "src/common/globals.h"
|
|
|
|
#include "src/heap/basic-memory-chunk.h"
|
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"
|
2022-05-17 00:55:20 +00:00
|
|
|
#include "test/unittests/test-utils.h"
|
|
|
|
#include "testing/gtest/include/gtest/gtest.h"
|
2018-07-04 18:11:11 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
2022-05-17 00:55:20 +00:00
|
|
|
using RootsTest = TestWithIsolate;
|
|
|
|
|
2018-07-04 18:11:11 +00:00
|
|
|
namespace {
|
2018-12-25 00:19:47 +00:00
|
|
|
AllocationSpace GetSpaceFromObject(Object object) {
|
2018-07-04 18:11:11 +00:00
|
|
|
DCHECK(object.IsHeapObject());
|
2020-06-17 13:28:23 +00:00
|
|
|
BasicMemoryChunk* chunk =
|
|
|
|
BasicMemoryChunk::FromHeapObject(HeapObject::cast(object));
|
|
|
|
if (chunk->InReadOnlySpace()) return RO_SPACE;
|
|
|
|
return chunk->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.
|
2022-05-17 00:55:20 +00:00
|
|
|
TEST_F(RootsTest, TestReadOnlyRoots) {
|
|
|
|
ReadOnlyRoots roots(i_isolate());
|
2018-07-04 18:11:11 +00:00
|
|
|
|
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) \
|
[diagnostics] Support --turbo-profiling for builtins
Currently, if d8 is run with the --turbo-profiling flag, it prints info
about every TurboFan-compiled function. This info includes the number of
times that each basic block in the function was run. It also includes
text representations of the function's schedule and code, so that the
person reading the output can associate counters with blocks of code.
The data about each function is currently stored in a
BasicBlockProfiler::Data instance, which is attached to a list owned by
the singleton BasicBlockProfiler. Each Data contains an
std::vector<uint32_t> which represents how many times each block in the
function has executed. The generated code for each block uses a raw
pointer into the storage of that vector to implement incrementing the
counter.
With this change, if you compile with v8_enable_builtins_profiling and
then run with --turbo-profiling, d8 will print that same info about
builtins too.
In order to generate code that can survive being serialized to a
snapshot and reloaded, this change uses counters in the JS heap instead
of a std::vector outside the JS heap. The steps for instrumentation are
as follows:
1. Between scheduling and instruction selection, add code to increment
the counter for each block. The counters array doesn't yet exist at
this point, and allocation is disallowed, so at this point the code
refers to a special marker value.
2. During finalization of the code, allocate a BasicBlockProfilingData
object on the JS heap containing data equivalent to what is stored in
BasicBlockProfiler::Data. This includes a ByteArray that is big
enough to store the counters for each block.
3. Patch the reference in the BuiltinsConstantsTableBuilder so that
instead of referring to the marker object, it now refers to this
ByteArray. Also add the BasicBlockProfilingData object to a list that
is attached to the heap roots so it can be easily accessed for
printing.
Because these steps include modifying the BuiltinsConstantsTableBuilder,
this procedure is only applicable to builtins. Runtime-generated code
still uses raw pointers into std::vector instances. In order to keep
divergence between these code paths to a minimum, most work is done
referring to instances of BasicBlockProfiler::Data (the C++ class), and
functions are provided to copy back and forth between that type and
BasicBlockProfilingData (the JS heap object).
This change is intended only to make --turbo-profiling work consistently
on more kinds of functions, but with some further work, this data could
form the basis for:
- code coverage info for fuzzers, and/or
- hot-path info for profile-guided optimization.
Bug: v8:10470, v8:9119
Change-Id: Ib556a5bc3abe67cdaa2e3ee62702a2a08b11cb61
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2159738
Commit-Queue: Seth Brenith <seth.brenith@microsoft.com>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#67944}
2020-05-21 15:51:40 +00:00
|
|
|
V(basic_block_profiling_data) \
|
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) \
|
|
|
|
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(retaining_path_targets) \
|
|
|
|
V(serialized_global_proxy_sizes) \
|
2018-11-05 14:21:02 +00:00
|
|
|
V(serialized_objects) \
|
2022-04-01 13:01:52 +00:00
|
|
|
IF_WASM(V, wasm_canonical_rtts) \
|
2018-11-05 14:21:02 +00:00
|
|
|
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()) && \
|
2022-05-17 00:55:20 +00:00
|
|
|
!name->IsUndefined(i_isolate())) { \
|
2019-01-22 14:45:10 +00:00
|
|
|
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.
|
2022-05-17 00:55:20 +00:00
|
|
|
TEST_F(RootsTest, TestHeapRootsNotReadOnly) {
|
|
|
|
Factory* factory = i_isolate()->factory();
|
|
|
|
Heap* heap = i_isolate()->heap();
|
2018-07-04 18:11:11 +00:00
|
|
|
|
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
|