Commit af526117 authored by Igor Sheludko's avatar Igor Sheludko Committed by Commit Bot

Introduce --print-builtin-code-filter for filtering of --print-builtin-code output.

Bug: v8:7754
Change-Id: I11845f84c5e837d3d7323c4a932c36af08b61a8e
Reviewed-on: https://chromium-review.googlesource.com/1096940Reviewed-by: 's avatarJaroslav Sevcik <jarin@chromium.org>
Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53670}
parent 9dd58b05
......@@ -30,11 +30,7 @@ void PostBuildProfileAndTracing(Isolate* isolate, Code* code,
AbstractCode::cast(code), name));
#ifdef ENABLE_DISASSEMBLER
if (FLAG_print_builtin_code) {
CodeTracer::Scope trace_scope(isolate->GetCodeTracer());
OFStream os(trace_scope.file());
os << "Builtin: " << name << "\n";
code->Disassemble(name, os);
os << "\n";
code->PrintBuiltinCode(isolate, name);
}
#endif
}
......
......@@ -177,7 +177,7 @@ Handle<Code> CodeStub::GetCode() {
return Handle<Code>(code, isolate());
}
CodeStub::Major CodeStub::GetMajorKey(Code* code_stub) {
CodeStub::Major CodeStub::GetMajorKey(const Code* code_stub) {
return MajorKeyFromKey(code_stub->stub_key());
}
......
......@@ -107,7 +107,7 @@ class CodeStub : public ZoneObject {
}
// Gets the major key from a code object that is a code stub or binary op IC.
static Major GetMajorKey(Code* code_stub);
static Major GetMajorKey(const Code* code_stub);
static uint32_t NoCacheKey() { return MajorKeyBits::encode(NoCache); }
......
......@@ -578,7 +578,8 @@ void PrintCode(Handle<Code> code, OptimizedCompilationInfo* info) {
AllowDeferredHandleDereference allow_deference_for_print_code;
bool print_code =
isolate->bootstrapper()->IsActive()
? FLAG_print_builtin_code
? 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)));
......
......@@ -1298,6 +1298,8 @@ DEFINE_BOOL(print_opt_code, false, "print optimized code")
DEFINE_STRING(print_opt_code_filter, "*", "filter for printing optimized code")
DEFINE_BOOL(print_code_verbose, false, "print more information for code")
DEFINE_BOOL(print_builtin_code, false, "print generated code for builtins")
DEFINE_STRING(print_builtin_code_filter, "*",
"filter for printing builtin code")
DEFINE_BOOL(print_builtin_size, false, "print code size for builtins")
#ifdef ENABLE_DISASSEMBLER
......
......@@ -233,7 +233,7 @@ bool Interpreter::IsDispatchTableInitialized() const {
return dispatch_table_[0] != kNullAddress;
}
const char* Interpreter::LookupNameOfBytecodeHandler(Code* code) {
const char* Interpreter::LookupNameOfBytecodeHandler(const Code* code) {
#ifdef ENABLE_DISASSEMBLER
#define RETURN_NAME(Name, ...) \
if (dispatch_table_[Bytecodes::ToByte(Bytecode::k##Name)] == \
......
......@@ -65,7 +65,7 @@ class Interpreter {
void IterateDispatchTable(RootVisitor* v);
// Disassembler support (only useful with ENABLE_DISASSEMBLER defined).
const char* LookupNameOfBytecodeHandler(Code* code);
const char* LookupNameOfBytecodeHandler(const Code* code);
V8_EXPORT_PRIVATE Local<v8::Object> GetDispatchCountersObject();
......
......@@ -84,6 +84,13 @@ void SetupInterpreter::InstallBytecodeHandler(Isolate* isolate,
dispatch_table[index] = code->entry();
if (FLAG_print_builtin_size) PrintBuiltinSize(bytecode, operand_scale, code);
#ifdef ENABLE_DISASSEMBLER
if (FLAG_print_builtin_code) {
std::string name = Bytecodes::ToString(bytecode, operand_scale);
code->PrintBuiltinCode(isolate, name.c_str());
}
#endif // ENABLE_DISASSEMBLER
}
} // namespace interpreter
......
......@@ -14609,27 +14609,46 @@ void DeoptimizationData::DeoptimizationDataPrint(std::ostream& os) { // NOLINT
}
}
const char* Code::GetName(Isolate* isolate) const {
if (is_stub()) {
return CodeStub::MajorName(CodeStub::GetMajorKey(this));
} else if (kind() == BYTECODE_HANDLER) {
return isolate->interpreter()->LookupNameOfBytecodeHandler(this);
} else {
// There are some handlers and ICs that we can also find names for with
// Builtins::Lookup.
return isolate->builtins()->Lookup(raw_instruction_start());
}
}
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";
}
}
void Code::Disassemble(const char* name, std::ostream& os, Address current_pc) {
Isolate* isolate = GetIsolate();
os << "kind = " << Kind2String(kind()) << "\n";
if (is_stub()) {
const char* n = CodeStub::MajorName(CodeStub::GetMajorKey(this));
os << "major_key = " << (n == nullptr ? "null" : n) << "\n";
os << "minor_key = " << CodeStub::MinorKeyFromKey(this->stub_key()) << "\n";
}
if (name == nullptr) {
name = GetName(isolate);
}
if ((name != nullptr) && (name[0] != '\0')) {
os << "name = " << name << "\n";
} else if (kind() == BYTECODE_HANDLER) {
name = GetIsolate()->interpreter()->LookupNameOfBytecodeHandler(this);
if (name != nullptr) {
os << "name = " << name << "\n";
}
} else {
// There are some handlers and ICs that we can also find names for with
// Builtins::Lookup.
name = GetIsolate()->builtins()->Lookup(raw_instruction_start());
if (name != nullptr) {
os << "name = " << name << "\n";
}
}
if (kind() == OPTIMIZED_FUNCTION) {
os << "stack_slots = " << stack_slots() << "\n";
......@@ -14639,7 +14658,6 @@ void Code::Disassemble(const char* name, std::ostream& os, Address current_pc) {
os << "Body (size = " << InstructionSize() << ")\n";
{
Isolate* isolate = GetIsolate();
int size = InstructionSize();
int safepoint_offset =
has_safepoint_info() ? safepoint_table_offset() : size;
......
......@@ -52,6 +52,8 @@ class Code : public HeapObject {
static const char* Kind2String(Kind kind);
#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
......
......@@ -73,6 +73,20 @@ void BuiltinDeserializer::DeserializeEagerBuiltinsAndHandlers() {
}
#endif
#ifdef ENABLE_DISASSEMBLER
if (FLAG_print_builtin_code) {
// We can't print builtins during deserialization because they may refer
// to not yet deserialized builtins.
for (int i = 0; i < BSU::kNumberOfBuiltins; i++) {
if (!IsLazyDeserializationEnabled() || !Builtins::IsLazy(i)) {
Code* code = builtins->builtin(i);
const char* name = Builtins::name(i);
code->PrintBuiltinCode(isolate(), name);
}
}
}
#endif
// Deserialize bytecode handlers.
Interpreter* interpreter = isolate()->interpreter();
......@@ -113,12 +127,8 @@ Code* BuiltinDeserializer::DeserializeBuiltin(int builtin_id) {
#ifdef ENABLE_DISASSEMBLER
if (FLAG_print_builtin_code) {
CodeTracer::Scope tracing_scope(isolate()->GetCodeTracer());
OFStream os(tracing_scope.file());
DCHECK(isolate()->builtins()->is_initialized());
code->Disassemble(Builtins::name(builtin_id), os);
os << std::flush;
const char* name = Builtins::name(builtin_id);
code->PrintBuiltinCode(isolate(), name);
}
#endif // ENABLE_DISASSEMBLER
......@@ -129,19 +139,7 @@ Code* BuiltinDeserializer::DeserializeHandler(Bytecode bytecode,
OperandScale operand_scale) {
allocator()->ReserveForHandler(bytecode, operand_scale);
DisallowHeapAllocation no_gc;
Code* code = DeserializeHandlerRaw(bytecode, operand_scale);
#ifdef ENABLE_DISASSEMBLER
if (FLAG_print_builtin_code) {
CodeTracer::Scope tracing_scope(isolate()->GetCodeTracer());
OFStream os(tracing_scope.file());
code->Disassemble(Bytecodes::ToString(bytecode), os);
os << std::flush;
}
#endif // ENABLE_DISASSEMBLER
return code;
return DeserializeHandlerRaw(bytecode, operand_scale);
}
Code* BuiltinDeserializer::DeserializeBuiltinRaw(int builtin_id) {
......@@ -196,13 +194,15 @@ Code* BuiltinDeserializer::DeserializeHandlerRaw(Bytecode bytecode,
Assembler::FlushICache(code->raw_instruction_start(),
code->raw_instruction_size());
const char* handler_name =
isolate()->interpreter()->LookupNameOfBytecodeHandler(code);
if (handler_name == nullptr) {
handler_name = "UnknownBytecodeHadler";
}
std::string name = Bytecodes::ToString(bytecode, operand_scale);
PROFILE(isolate(), CodeCreateEvent(CodeEventListener::HANDLER_TAG,
AbstractCode::cast(code), handler_name));
AbstractCode::cast(code), name.c_str()));
#ifdef ENABLE_DISASSEMBLER
if (FLAG_print_builtin_code) {
code->PrintBuiltinCode(isolate(), name.c_str());
}
#endif // ENABLE_DISASSEMBLER
return code;
}
......
......@@ -6,6 +6,7 @@
#include "src/api.h"
#include "src/assembler-inl.h"
#include "src/code-stubs.h"
#include "src/heap/heap-inl.h"
#include "src/snapshot/builtin-deserializer.h"
#include "src/snapshot/snapshot.h"
......@@ -95,7 +96,13 @@ void StartupDeserializer::PrintDisassembledCodeObjects() {
for (HeapObject* obj = iterator.next(); obj != nullptr;
obj = iterator.next()) {
if (obj->IsCode()) {
Code::cast(obj)->Disassemble(nullptr, os);
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);
}
}
}
}
......
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