18c73676c1
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}
92 lines
3.2 KiB
C++
92 lines
3.2 KiB
C++
// 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.
|
|
|
|
#include "src/heap/heap-inl.h"
|
|
#include "src/heap/memory-chunk-inl.h"
|
|
#include "src/objects/cell.h"
|
|
#include "src/objects/feedback-cell.h"
|
|
#include "src/objects/script.h"
|
|
#include "src/roots/roots-inl.h"
|
|
#include "test/cctest/cctest.h"
|
|
|
|
namespace v8 {
|
|
namespace internal {
|
|
|
|
namespace {
|
|
AllocationSpace GetSpaceFromObject(Object object) {
|
|
DCHECK(object.IsHeapObject());
|
|
return MemoryChunk::FromHeapObject(HeapObject::cast(object))
|
|
->owner_identity();
|
|
}
|
|
} // namespace
|
|
|
|
#define CHECK_IN_RO_SPACE(type, name, CamelName) \
|
|
HeapObject name = roots.name(); \
|
|
CHECK_EQ(RO_SPACE, GetSpaceFromObject(name));
|
|
|
|
// The following tests check that all the roots accessible via ReadOnlyRoots are
|
|
// in RO_SPACE.
|
|
TEST(TestReadOnlyRoots) {
|
|
ReadOnlyRoots roots(CcTest::i_isolate());
|
|
|
|
READ_ONLY_ROOT_LIST(CHECK_IN_RO_SPACE)
|
|
}
|
|
|
|
#undef CHECK_IN_RO_SPACE
|
|
|
|
namespace {
|
|
bool IsInitiallyMutable(Factory* factory, Address object_address) {
|
|
// Entries in this list are in STRONG_MUTABLE_MOVABLE_ROOT_LIST, but may
|
|
// initially point to objects that are in RO_SPACE.
|
|
#define INITIALLY_READ_ONLY_ROOT_LIST(V) \
|
|
V(api_private_symbol_table) \
|
|
V(api_symbol_table) \
|
|
V(basic_block_profiling_data) \
|
|
V(builtins_constants_table) \
|
|
V(current_microtask) \
|
|
V(detached_contexts) \
|
|
V(feedback_vectors_for_profiling_tools) \
|
|
V(shared_wasm_memories) \
|
|
V(materialized_objects) \
|
|
V(public_symbol_table) \
|
|
V(retaining_path_targets) \
|
|
V(serialized_global_proxy_sizes) \
|
|
V(serialized_objects) \
|
|
V(weak_refs_keep_during_job)
|
|
|
|
#define TEST_CAN_BE_READ_ONLY(name) \
|
|
if (factory->name().address() == object_address) return false;
|
|
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
|
|
|
|
// 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.
|
|
#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))); \
|
|
}
|
|
|
|
// 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) {
|
|
Factory* factory = CcTest::i_isolate()->factory();
|
|
Heap* heap = CcTest::i_isolate()->heap();
|
|
|
|
MUTABLE_ROOT_LIST(CHECK_NOT_IN_RO_SPACE)
|
|
}
|
|
|
|
#undef CHECK_NOT_IN_RO_SPACE
|
|
|
|
} // namespace internal
|
|
} // namespace v8
|