Commit d2ef40dd authored by Camillo Bruni's avatar Camillo Bruni Committed by Commit Bot

Fixes for --trace-maps

- Make sure scripts have line end data
- Make sure initial class maps are logged
- Log map creation independently from details
- Properly escape commas in the v8 logger

Cq-Include-Trybots: master.tryserver.chromium.linux:linux_chromium_rel_ng
Change-Id: I583c784cf75e884673e46bfb263da3bc20e6ac41
Reviewed-on: https://chromium-review.googlesource.com/822333Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#50236}
parent 1ed3bd53
......@@ -2581,6 +2581,9 @@ MaybeLocal<Script> ScriptCompiler::Compile(Local<Context> context,
i::StreamedSource* source = v8_source->impl();
i::Handle<i::String> str = Utils::OpenHandle(*(full_source_string));
i::Handle<i::Script> script = isolate->factory()->NewScript(str);
if (isolate->NeedsSourcePositionsForProfiling()) {
i::Script::InitLineEnds(script);
}
if (!origin.ResourceName().IsEmpty()) {
script->set_name(*Utils::OpenHandle(*(origin.ResourceName())));
}
......
......@@ -1536,6 +1536,9 @@ MaybeHandle<SharedFunctionInfo> Compiler::GetSharedFunctionInfoForScript(
inner_result, vector);
Handle<Script> script(Script::cast(inner_result->script()), isolate);
isolate->debug()->OnAfterCompile(script);
if (isolate->NeedsSourcePositionsForProfiling()) {
Script::InitLineEnds(script);
}
return inner_result;
}
// Deserializer failed. Fall through to compile.
......
......@@ -895,6 +895,7 @@ DEFINE_BOOL(trace_prototype_users, false,
DEFINE_BOOL(use_verbose_printer, true, "allows verbose printing")
DEFINE_BOOL(trace_for_in_enumerate, false, "Trace for-in enumerate slow-paths")
DEFINE_BOOL(trace_maps, false, "trace map creation")
DEFINE_BOOL(trace_maps_details, true, "also log map details")
DEFINE_IMPLICATION(trace_maps, log_code)
// parser.cc
......
......@@ -2461,7 +2461,7 @@ AllocationResult Heap::AllocateMap(InstanceType instance_type,
map->set_bit_field3(bit_field3);
map->set_elements_kind(elements_kind);
map->set_new_target_is_base(true);
if (FLAG_trace_maps) LOG(isolate(), MapCreate(map));
return map;
}
......
......@@ -670,6 +670,11 @@ Handle<FixedArray> Isolate::GetDetailedStackTrace(
Address Isolate::GetAbstractPC(int* line, int* column) {
JavaScriptFrameIterator it(this);
if (it.done()) {
*line = -1;
*column = -1;
return nullptr;
}
JavaScriptFrame* frame = it.frame();
DCHECK(!frame->is_builtin());
int position = frame->position();
......@@ -3169,7 +3174,7 @@ bool Isolate::use_optimizer() {
bool Isolate::NeedsSourcePositionsForProfiling() const {
return FLAG_trace_deopt || FLAG_trace_turbo || FLAG_trace_turbo_graph ||
FLAG_turbo_profiling || FLAG_perf_prof || is_profiling() ||
debug_->is_active() || logger_->is_logging();
debug_->is_active() || logger_->is_logging() || FLAG_trace_maps;
}
void Isolate::SetFeedbackVectorsForProfilingTools(Object* value) {
......
......@@ -196,6 +196,9 @@ MaybeHandle<Object> JsonParser<seq_one_byte>::ParseJson() {
}
Handle<Script> script(factory->NewScript(source_));
if (isolate()->NeedsSourcePositionsForProfiling()) {
Script::InitLineEnds(script);
}
// We should sent compile error event because we compile JSON object in
// separated source file.
isolate()->debug()->OnCompileError(script);
......
......@@ -173,7 +173,7 @@ void Log::MessageBuilder::AppendCharacter(char c) {
if (c >= 32 && c <= 126) {
if (c == ',') {
// Escape commas (log field separator) directly.
os << "\x2C";
os << "\\x2C";
} else {
// Directly append any printable ascii character.
os << c;
......
......@@ -1359,6 +1359,7 @@ void Logger::MapEvent(const char* type, Map* from, Map* to, const char* reason,
int line = -1;
int column = -1;
Address pc = 0;
if (!isolate_->bootstrapper()->IsActive()) {
pc = isolate_->GetAbstractPC(&line, &column);
}
......@@ -1382,6 +1383,15 @@ void Logger::MapEvent(const char* type, Map* from, Map* to, const char* reason,
msg.WriteToLogFile();
}
void Logger::MapCreate(Map* map) {
if (!log_->IsEnabled() || !FLAG_trace_maps) return;
DisallowHeapAllocation no_gc;
Log::MessageBuilder msg(log_);
msg << "map-create" << kNext << timer_.Elapsed().InMicroseconds() << kNext
<< reinterpret_cast<void*>(map);
msg.WriteToLogFile();
}
void Logger::MapDetails(Map* map) {
if (!log_->IsEnabled() || !FLAG_trace_maps) return;
// Disable logging Map details during bootstrapping since we use LogMaps() to
......@@ -1391,9 +1401,11 @@ void Logger::MapDetails(Map* map) {
Log::MessageBuilder msg(log_);
msg << "map-details" << kNext << timer_.Elapsed().InMicroseconds() << kNext
<< reinterpret_cast<void*>(map) << kNext;
std::ostringstream buffer;
map->PrintMapDetails(buffer);
msg << buffer.str().c_str();
if (FLAG_trace_maps_details) {
std::ostringstream buffer;
map->PrintMapDetails(buffer);
msg << buffer.str().c_str();
}
msg.WriteToLogFile();
}
......
......@@ -201,6 +201,7 @@ class Logger : public CodeEventListener {
void MapEvent(const char* type, Map* from, Map* to,
const char* reason = nullptr,
HeapObject* name_or_sfi = nullptr);
void MapCreate(Map* map);
void MapDetails(Map* map);
......
......@@ -339,7 +339,6 @@ bool AddDescriptorsByTemplate(
map->InitializeDescriptors(*descriptors,
LayoutDescriptor::FastPointerLayout());
if (elements_dictionary->NumberOfElements() > 0) {
if (!SubstituteValues<NumberDictionary>(isolate, elements_dictionary,
receiver, args)) {
......@@ -454,7 +453,6 @@ bool InitClassPrototype(Isolate* isolate,
Map::SetPrototype(map, prototype_parent);
constructor->set_prototype_or_initial_map(*prototype);
map->SetConstructor(*constructor);
Handle<FixedArray> computed_properties(
class_boilerplate->instance_computed_properties(), isolate);
Handle<NumberDictionary> elements_dictionary_template(
......@@ -595,6 +593,14 @@ MaybeHandle<Object> DefineClass(Isolate* isolate,
DCHECK(isolate->has_pending_exception());
return MaybeHandle<Object>();
}
if (FLAG_trace_maps) {
LOG(isolate,
MapEvent("InitialMap", nullptr, constructor->map(),
"init class constructor", constructor->shared()->DebugName()));
LOG(isolate, MapEvent("InitialMap", nullptr, prototype->map(),
"init class prototype"));
}
return prototype;
}
......
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