Commit 7a9f2a46 authored by Jakob Gruber's avatar Jakob Gruber Committed by Commit Bot

[snapshot] Dedicated code start symbol for sampling profiler

The UMA sampling profiler prefers unique symbol addresses, otherwise
disambiguation is fairly arbitrary (lexicographic).

To this end, introduce a dedicated symbol v8_code_start_for_profiler_
at a unique address (i.e. no other symbol is located at this address).

Bug: v8:6666
Change-Id: Iec13ccac64efc7ac3f63e29632ee8f6300bcb76b
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2464926
Auto-Submit: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#70556}
parent ecbbbc28
...@@ -14,6 +14,38 @@ ...@@ -14,6 +14,38 @@
namespace v8 { namespace v8 {
namespace internal { namespace internal {
namespace {
int WriteDirectiveOrSeparator(PlatformEmbeddedFileWriterBase* w,
int current_line_length,
DataDirective directive) {
int printed_chars;
if (current_line_length == 0) {
printed_chars = w->IndentedDataDirective(directive);
DCHECK_LT(0, printed_chars);
} else {
printed_chars = fprintf(w->fp(), ",");
DCHECK_EQ(1, printed_chars);
}
return current_line_length + printed_chars;
}
int WriteLineEndIfNeeded(PlatformEmbeddedFileWriterBase* w,
int current_line_length, int write_size) {
static const int kTextWidth = 100;
// Check if adding ',0xFF...FF\n"' would force a line wrap. This doesn't use
// the actual size of the string to be written to determine this so it's
// more conservative than strictly needed.
if (current_line_length + strlen(",0x") + write_size * 2 > kTextWidth) {
fprintf(w->fp(), "\n");
return 0;
} else {
return current_line_length;
}
}
} // namespace
void EmbeddedFileWriter::WriteBuiltin(PlatformEmbeddedFileWriterBase* w, void EmbeddedFileWriter::WriteBuiltin(PlatformEmbeddedFileWriterBase* w,
const i::EmbeddedData* blob, const i::EmbeddedData* blob,
const int builtin_id) const { const int builtin_id) const {
...@@ -98,6 +130,39 @@ void EmbeddedFileWriter::WriteBuiltinLabels(PlatformEmbeddedFileWriterBase* w, ...@@ -98,6 +130,39 @@ void EmbeddedFileWriter::WriteBuiltinLabels(PlatformEmbeddedFileWriterBase* w,
w->DeclareLabel(name.c_str()); w->DeclareLabel(name.c_str());
} }
void EmbeddedFileWriter::WriteInstructionStreams(
PlatformEmbeddedFileWriterBase* w, const i::EmbeddedData* blob) const {
w->Comment("The embedded blob data starts here. It contains the builtin");
w->Comment("instruction streams.");
w->SectionText();
#if V8_TARGET_ARCH_IA32 || V8_TARGET_ARCH_X64
// UMA needs an exposed function-type label at the start of the embedded
// code section.
static const char* kCodeStartForProfilerSymbolName =
"v8_code_start_for_profiler_";
static constexpr int kDummyFunctionLength = 1;
static constexpr int kDummyFunctionData = 0xcc;
w->DeclareFunctionBegin(kCodeStartForProfilerSymbolName,
kDummyFunctionLength);
// The label must not be at the same address as the first builtin, insert
// padding bytes.
WriteDirectiveOrSeparator(w, 0, kByte);
w->HexLiteral(kDummyFunctionData);
w->Newline();
w->DeclareFunctionEnd(kCodeStartForProfilerSymbolName);
#endif
w->AlignToCodeAlignment();
w->DeclareLabel(EmbeddedBlobCodeDataSymbol().c_str());
for (int i = 0; i < i::Builtins::builtin_count; i++) {
if (!blob->ContainsBuiltin(i)) continue;
WriteBuiltin(w, blob, i);
}
w->Newline();
}
void EmbeddedFileWriter::WriteFileEpilogue(PlatformEmbeddedFileWriterBase* w, void EmbeddedFileWriter::WriteFileEpilogue(PlatformEmbeddedFileWriterBase* w,
const i::EmbeddedData* blob) const { const i::EmbeddedData* blob) const {
{ {
...@@ -162,38 +227,6 @@ void EmbeddedFileWriter::WriteFileEpilogue(PlatformEmbeddedFileWriterBase* w, ...@@ -162,38 +227,6 @@ void EmbeddedFileWriter::WriteFileEpilogue(PlatformEmbeddedFileWriterBase* w,
w->FileEpilogue(); w->FileEpilogue();
} }
namespace {
int WriteDirectiveOrSeparator(PlatformEmbeddedFileWriterBase* w,
int current_line_length,
DataDirective directive) {
int printed_chars;
if (current_line_length == 0) {
printed_chars = w->IndentedDataDirective(directive);
DCHECK_LT(0, printed_chars);
} else {
printed_chars = fprintf(w->fp(), ",");
DCHECK_EQ(1, printed_chars);
}
return current_line_length + printed_chars;
}
int WriteLineEndIfNeeded(PlatformEmbeddedFileWriterBase* w,
int current_line_length, int write_size) {
static const int kTextWidth = 100;
// Check if adding ',0xFF...FF\n"' would force a line wrap. This doesn't use
// the actual size of the string to be written to determine this so it's
// more conservative than strictly needed.
if (current_line_length + strlen(",0x") + write_size * 2 > kTextWidth) {
fprintf(w->fp(), "\n");
return 0;
} else {
return current_line_length;
}
}
} // namespace
// static // static
void EmbeddedFileWriter::WriteBinaryContentsAsInlineAssembly( void EmbeddedFileWriter::WriteBinaryContentsAsInlineAssembly(
PlatformEmbeddedFileWriterBase* w, const uint8_t* data, uint32_t size) { PlatformEmbeddedFileWriterBase* w, const uint8_t* data, uint32_t size) {
......
...@@ -187,31 +187,7 @@ class EmbeddedFileWriter : public EmbeddedFileWriterInterface { ...@@ -187,31 +187,7 @@ class EmbeddedFileWriter : public EmbeddedFileWriterInterface {
std::string name) const; std::string name) const;
void WriteInstructionStreams(PlatformEmbeddedFileWriterBase* w, void WriteInstructionStreams(PlatformEmbeddedFileWriterBase* w,
const i::EmbeddedData* blob) const { const i::EmbeddedData* blob) const;
w->Comment("The embedded blob data starts here. It contains the builtin");
w->Comment("instruction streams.");
w->SectionText();
w->AlignToCodeAlignment();
#if V8_TARGET_ARCH_IA32 || V8_TARGET_ARCH_X64
// UMA needs an exposed function-type label at the start of the embedded
// code section, thus this label is declared as a function (otherwise we
// could use DeclareLabel).
static constexpr int kDummyFunctionLength = 0;
w->DeclareFunctionBegin(EmbeddedBlobCodeDataSymbol().c_str(),
kDummyFunctionLength);
w->DeclareFunctionEnd(EmbeddedBlobCodeDataSymbol().c_str());
#else
w->DeclareLabel(EmbeddedBlobCodeDataSymbol().c_str());
#endif
for (int i = 0; i < i::Builtins::builtin_count; i++) {
if (!blob->ContainsBuiltin(i)) continue;
WriteBuiltin(w, blob, i);
}
w->Newline();
}
void WriteFileEpilogue(PlatformEmbeddedFileWriterBase* w, void WriteFileEpilogue(PlatformEmbeddedFileWriterBase* w,
const i::EmbeddedData* blob) const; const i::EmbeddedData* blob) const;
......
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