Commit d034d088 authored by Jakob Gruber's avatar Jakob Gruber Committed by Commit Bot

[builtins] Unify builtin code and size printing mechanisms

There's no reason to scatter this all over when we have a single choke
point in Isolate::Init.

Drive-by: Remove unused DLH builtin kind.

Bug: v8:8238
Change-Id: I46373a1044e51d90d3a9c3e772f5930d57097937
Reviewed-on: https://chromium-review.googlesource.com/c/1347481Reviewed-by: 's avatarPeter Marshall <petermarshall@chromium.org>
Reviewed-by: 's avatarJaroslav Sevcik <jarin@chromium.org>
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57739}
parent 5952f12a
......@@ -8,6 +8,7 @@
#include "src/assembler-inl.h"
#include "src/builtins/builtins-descriptors.h"
#include "src/callable.h"
#include "src/code-tracer.h"
#include "src/isolate.h"
#include "src/macro-assembler.h"
#include "src/objects-inl.h"
......@@ -169,7 +170,7 @@ Callable Builtins::CallableFor(Isolate* isolate, Name name) {
#undef CASE_OTHER
default:
Builtins::Kind kind = Builtins::KindOf(name);
DCHECK(kind != BCH && kind != DLH);
DCHECK_NE(BCH, kind);
if (kind == TFJ || kind == CPP) {
return Callable(code, JSTrampolineDescriptor{});
}
......@@ -185,6 +186,34 @@ const char* Builtins::name(int index) {
return builtin_metadata[index].name;
}
void Builtins::PrintBuiltinCode() {
DCHECK(FLAG_print_builtin_code);
#ifdef ENABLE_DISASSEMBLER
for (int i = 0; i < builtin_count; i++) {
const char* builtin_name = name(i);
Handle<Code> code = builtin_handle(i);
if (PassesFilter(CStrVector(builtin_name),
CStrVector(FLAG_print_builtin_code_filter))) {
CodeTracer::Scope trace_scope(isolate_->GetCodeTracer());
OFStream os(trace_scope.file());
code->Disassemble(builtin_name, os);
os << "\n";
}
}
#endif
}
void Builtins::PrintBuiltinSize() {
DCHECK(FLAG_print_builtin_size);
for (int i = 0; i < builtin_count; i++) {
const char* builtin_name = name(i);
const char* kind = KindNameOf(i);
Code code = builtin(i);
PrintF(stdout, "%s Builtin, %s, %d\n", kind, builtin_name,
code->InstructionSize());
}
}
// static
Address Builtins::CppEntryOf(int index) {
DCHECK(Builtins::HasCppImplementation(index));
......@@ -315,7 +344,6 @@ const char* Builtins::KindNameOf(int index) {
case TFS: return "TFS";
case TFH: return "TFH";
case BCH: return "BCH";
case DLH: return "DLH";
case ASM: return "ASM";
}
// clang-format on
......
......@@ -65,7 +65,7 @@ class Builtins {
}
// The different builtin kinds are documented in builtins-definitions.h.
enum Kind { CPP, API, TFJ, TFC, TFS, TFH, BCH, DLH, ASM };
enum Kind { CPP, API, TFJ, TFC, TFS, TFH, BCH, ASM };
static BailoutId GetContinuationBailoutId(Name name);
static Name GetBuiltinFromBailoutId(BailoutId);
......@@ -94,6 +94,10 @@ class Builtins {
static const char* name(int index);
// Support for --print-builtin-size and --print-builtin-code.
void PrintBuiltinCode();
void PrintBuiltinSize();
// Returns the C++ entry point for builtins implemented in C++, and the null
// Address otherwise.
static Address CppEntryOf(int index);
......
......@@ -33,11 +33,6 @@ namespace {
void PostBuildProfileAndTracing(Isolate* isolate, Code code, const char* name) {
PROFILE(isolate, CodeCreateEvent(CodeEventListener::BUILTIN_TAG,
AbstractCode::cast(code), name));
#ifdef ENABLE_DISASSEMBLER
if (FLAG_print_builtin_code) {
code->PrintBuiltinCode(isolate, name);
}
#endif
}
AssemblerOptions BuiltinAssemblerOptions(Isolate* isolate,
......
......@@ -622,12 +622,9 @@ void PrintCode(Isolate* isolate, Handle<Code> code,
#ifdef ENABLE_DISASSEMBLER
AllowDeferredHandleDereference allow_deference_for_print_code;
bool print_code =
isolate->bootstrapper()->IsActive()
? FLAG_print_builtin_code && info->shared_info()->PassesFilter(
FLAG_print_builtin_code_filter)
: (FLAG_print_code || (info->IsStub() && FLAG_print_code_stubs) ||
(info->IsOptimizing() && FLAG_print_opt_code &&
info->shared_info()->PassesFilter(FLAG_print_opt_code_filter)));
FLAG_print_code || (info->IsStub() && FLAG_print_code_stubs) ||
(info->IsOptimizing() && FLAG_print_opt_code &&
info->shared_info()->PassesFilter(FLAG_print_opt_code_filter));
if (print_code) {
std::unique_ptr<char[]> debug_name = info->GetDebugName();
CodeTracer::Scope tracing_scope(isolate->GetCodeTracer());
......
......@@ -3072,15 +3072,6 @@ void Isolate::InitializeLoggingAndCounters() {
}
namespace {
void PrintBuiltinSizes(Isolate* isolate) {
Builtins* builtins = isolate->builtins();
for (int i = 0; i < Builtins::builtin_count; i++) {
const char* name = builtins->name(i);
const char* kind = Builtins::KindNameOf(i);
Code code = builtins->builtin(i);
PrintF(stdout, "%s Builtin, %s, %d\n", kind, name, code->InstructionSize());
}
}
void CreateOffHeapTrampolines(Isolate* isolate) {
DCHECK_NOT_NULL(isolate->embedded_blob());
......@@ -3112,6 +3103,7 @@ void CreateOffHeapTrampolines(Isolate* isolate) {
}
}
}
} // namespace
void Isolate::InitializeDefaultEmbeddedBlob() {
......@@ -3337,7 +3329,8 @@ bool Isolate::Init(StartupDeserializer* des) {
delete setup_delegate_;
setup_delegate_ = nullptr;
if (FLAG_print_builtin_size) PrintBuiltinSizes(this);
if (FLAG_print_builtin_code) builtins()->PrintBuiltinCode();
if (FLAG_print_builtin_size) builtins()->PrintBuiltinSize();
// Finish initialization of ThreadLocal after deserialization is done.
clear_pending_exception();
......
......@@ -15107,21 +15107,6 @@ const char* Code::GetName(Isolate* isolate) const {
}
}
void Code::PrintBuiltinCode(Isolate* isolate, const char* name) {
DCHECK(FLAG_print_builtin_code);
if (name == nullptr) {
name = GetName(isolate);
}
if (name != nullptr &&
PassesFilter(CStrVector(name),
CStrVector(FLAG_print_builtin_code_filter))) {
CodeTracer::Scope trace_scope(isolate->GetCodeTracer());
OFStream os(trace_scope.file());
Disassemble(name, os);
os << "\n";
}
}
namespace {
inline void DisassembleCodeRange(Isolate* isolate, std::ostream& os, Code code,
......
......@@ -56,7 +56,6 @@ class Code : public HeapObjectPtr {
#ifdef ENABLE_DISASSEMBLER
const char* GetName(Isolate* isolate) const;
void PrintBuiltinCode(Isolate* isolate, const char* name);
void Disassemble(const char* name, std::ostream& os,
Address current_pc = kNullAddress);
#endif
......
......@@ -102,7 +102,6 @@ bool BuiltinAliasesOffHeapTrampolineRegister(Isolate* isolate, Code code) {
// Bytecode handlers will only ever be used by the interpreter and so there
// will never be a need to use trampolines with them.
case Builtins::BCH:
case Builtins::DLH:
case Builtins::API:
case Builtins::ASM:
// TODO(jgruber): Extend checks to remaining kinds.
......
......@@ -7,7 +7,6 @@
#include "src/api.h"
#include "src/assembler-inl.h"
#include "src/code-stubs.h"
#include "src/code-tracer.h"
#include "src/heap/heap-inl.h"
#include "src/snapshot/read-only-deserializer.h"
#include "src/snapshot/snapshot.h"
......@@ -65,11 +64,6 @@ void StartupDeserializer::DeserializeInto(Isolate* isolate) {
isolate->builtins()->MarkInitialized();
// If needed, print the dissassembly of deserialized code objects.
// Needs to be called after the builtins are marked as initialized, in order
// to display the builtin names.
PrintDisassembledCodeObjects();
if (FLAG_rehash_snapshot && can_rehash()) {
isolate->heap()->InitializeHashSeed();
read_only_deserializer.RehashHeap();
......@@ -85,31 +79,5 @@ void StartupDeserializer::FlushICacheForNewIsolate() {
}
}
void StartupDeserializer::PrintDisassembledCodeObjects() {
#ifdef ENABLE_DISASSEMBLER
if (FLAG_print_builtin_code) {
Heap* heap = isolate()->heap();
HeapIterator iterator(heap);
DisallowHeapAllocation no_gc;
CodeTracer::Scope tracing_scope(isolate()->GetCodeTracer());
OFStream os(tracing_scope.file());
for (HeapObject* obj = iterator.next(); obj != nullptr;
obj = iterator.next()) {
if (obj->IsCode()) {
Code code = Code::cast(obj);
// Printing of builtins and bytecode handlers is handled during their
// deserialization.
if (code->kind() != Code::BUILTIN &&
code->kind() != Code::BYTECODE_HANDLER) {
code->PrintBuiltinCode(isolate(), nullptr);
}
}
}
}
#endif
}
} // namespace internal
} // namespace v8
......@@ -23,7 +23,6 @@ class StartupDeserializer final : public Deserializer {
private:
void FlushICacheForNewIsolate();
void PrintDisassembledCodeObjects();
const SnapshotData* read_only_data_;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment