Skip to content

Commit cb29f9c

Browse files
rmcilroyCommit bot
authored andcommitted
[Interpreter] Add support for cpu profiler logging.
Adds support for cpu profiler logging to the interpreter. Modifies the the API to be passed AbstractCode objects instead of Code objects, and adds extra functions to AbstractCode which is required by log.cc and cpu-profiler.cc. The main change in sampler.cc is to determine if a stack frame is an interpreter stack frame, and if so, use the bytecode address as the pc for that frame. This allows sampling of bytecode functions. This requires adding support to SafeStackIterator to determine if a frame is interpreted, which we do by checking the PC against pre-stored addresses for the start and end of interpreter entry builtins. Also removes CodeDeleteEvents which are dead code and haven't been reported for some time. Still to do is tracking source positions which will be done in a followup CL. BUG=v8:4766 LOG=N Review URL: https://codereview.chromium.org/1728593002 Cr-Commit-Position: refs/heads/master@{#34321}
1 parent 9f4c3e7 commit cb29f9c

38 files changed

Lines changed: 439 additions & 470 deletions

src/builtins.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4427,7 +4427,8 @@ void Builtins::SetUp(Isolate* isolate, bool create_heap_objects) {
44274427
isolate->factory()->NewCode(desc, flags, masm.CodeObject());
44284428
// Log the event and add the code to the builtins array.
44294429
PROFILE(isolate,
4430-
CodeCreateEvent(Logger::BUILTIN_TAG, *code, functions[i].s_name));
4430+
CodeCreateEvent(Logger::BUILTIN_TAG, AbstractCode::cast(*code),
4431+
functions[i].s_name));
44314432
builtins_[i] = *code;
44324433
code->set_builtin_index(i);
44334434
#ifdef ENABLE_DISASSEMBLER

src/code-stubs.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ void CodeStub::RecordCodeGeneration(Handle<Code> code) {
8282
std::ostringstream os;
8383
os << *this;
8484
PROFILE(isolate(),
85-
CodeCreateEvent(Logger::STUB_TAG, *code, os.str().c_str()));
85+
CodeCreateEvent(Logger::STUB_TAG, AbstractCode::cast(*code),
86+
os.str().c_str()));
8687
Counters* counters = isolate()->counters();
8788
counters->total_stubs_code_size()->Increment(code->instruction_size());
8889
#ifdef DEBUG

src/compiler.cc

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -717,8 +717,9 @@ static void RecordFunctionCompilation(Logger::LogEventsAndTags tag,
717717
if (info->isolate()->logger()->is_logging_code_events() ||
718718
info->isolate()->cpu_profiler()->is_profiling()) {
719719
Handle<Script> script = info->parse_info()->script();
720-
Handle<Code> code = info->code();
721-
if (code.is_identical_to(info->isolate()->builtins()->CompileLazy())) {
720+
Handle<AbstractCode> abstract_code = info->abstract_code();
721+
if (abstract_code.is_identical_to(
722+
info->isolate()->builtins()->CompileLazy())) {
722723
return;
723724
}
724725
int line_num = Script::GetLineNumber(script, shared->start_position()) + 1;
@@ -729,7 +730,7 @@ static void RecordFunctionCompilation(Logger::LogEventsAndTags tag,
729730
: info->isolate()->heap()->empty_string();
730731
Logger::LogEventsAndTags log_tag = Logger::ToNativeByScript(tag, *script);
731732
PROFILE(info->isolate(),
732-
CodeCreateEvent(log_tag, *code, *shared, info, script_name,
733+
CodeCreateEvent(log_tag, *abstract_code, *shared, info, script_name,
733734
line_num, column_num));
734735
}
735736
}
@@ -824,9 +825,7 @@ MUST_USE_RESULT static MaybeHandle<Code> GetUnoptimizedCodeCommon(
824825

825826
// Compile either unoptimized code or bytecode for the interpreter.
826827
if (!CompileBaselineCode(info)) return MaybeHandle<Code>();
827-
if (info->code()->kind() == Code::FUNCTION) { // Only for full code.
828-
RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info, shared);
829-
}
828+
RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info, shared);
830829

831830
// Update the shared function info with the scope info. Allocating the
832831
// ScopeInfo object may cause a GC.
@@ -1329,8 +1328,8 @@ static Handle<SharedFunctionInfo> CompileToplevel(CompilationInfo* info) {
13291328
? Logger::EVAL_TAG
13301329
: Logger::ToNativeByScript(Logger::SCRIPT_TAG, *script);
13311330

1332-
PROFILE(isolate, CodeCreateEvent(
1333-
log_tag, *info->code(), *result, info, *script_name));
1331+
PROFILE(isolate, CodeCreateEvent(log_tag, *info->abstract_code(), *result,
1332+
info, *script_name));
13341333

13351334
// Hint to the runtime system used when allocating space for initial
13361335
// property space by setting the expected number of properties for

src/compiler.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ class CompilationInfo {
116116
bool has_bytecode_array() const { return !bytecode_array_.is_null(); }
117117
Handle<BytecodeArray> bytecode_array() const { return bytecode_array_; }
118118

119+
Handle<AbstractCode> abstract_code() const {
120+
return has_bytecode_array() ? Handle<AbstractCode>::cast(bytecode_array())
121+
: Handle<AbstractCode>::cast(code());
122+
}
123+
119124
bool is_tracking_positions() const { return track_positions_; }
120125

121126
bool is_calling() const {

src/compiler/code-generator.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,8 @@ Handle<Code> CodeGenerator::GenerateCode() {
217217

218218
// Emit a code line info recording stop event.
219219
void* line_info = recorder->DetachJITHandlerData();
220-
LOG_CODE_EVENT(isolate(), CodeEndLinePosInfoRecordEvent(*result, line_info));
220+
LOG_CODE_EVENT(isolate(), CodeEndLinePosInfoRecordEvent(
221+
AbstractCode::cast(*result), line_info));
221222

222223
return result;
223224
}

src/compiler/wasm-compiler.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1982,8 +1982,8 @@ static void RecordFunctionCompilation(Logger::LogEventsAndTags tag,
19821982
Handle<Code> code = info->code();
19831983
Handle<SharedFunctionInfo> shared =
19841984
isolate->factory()->NewSharedFunctionInfo(name_str, code, false);
1985-
PROFILE(isolate,
1986-
CodeCreateEvent(tag, *code, *shared, info, *script_str, 0, 0));
1985+
PROFILE(isolate, CodeCreateEvent(tag, AbstractCode::cast(*code), *shared,
1986+
info, *script_str, 0, 0));
19871987
}
19881988
}
19891989

src/crankshaft/lithium.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,8 @@ Handle<Code> LChunk::Codegen() {
461461
void* jit_handler_data =
462462
assembler.positions_recorder()->DetachJITHandlerData();
463463
LOG_CODE_EVENT(info()->isolate(),
464-
CodeEndLinePosInfoRecordEvent(*code, jit_handler_data));
464+
CodeEndLinePosInfoRecordEvent(AbstractCode::cast(*code),
465+
jit_handler_data));
465466

466467
CodeGenerator::PrintCode(code, info());
467468
DCHECK(!(info()->isolate()->serializer_enabled() &&

src/frames.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,17 @@ void StackFrame::SetReturnAddressLocationResolver(
401401
return_address_location_resolver_ = resolver;
402402
}
403403

404+
static bool IsInterpreterFramePc(Isolate* isolate, Address pc) {
405+
Code* interpreter_entry_trampoline =
406+
isolate->builtins()->builtin(Builtins::kInterpreterEntryTrampoline);
407+
Code* interpreter_bytecode_dispatch =
408+
isolate->builtins()->builtin(Builtins::kInterpreterEnterBytecodeDispatch);
409+
410+
return (pc >= interpreter_entry_trampoline->instruction_start() &&
411+
pc < interpreter_entry_trampoline->instruction_end()) ||
412+
(pc >= interpreter_bytecode_dispatch->instruction_start() &&
413+
pc < interpreter_bytecode_dispatch->instruction_end());
414+
}
404415

405416
StackFrame::Type StackFrame::ComputeType(const StackFrameIteratorBase* iterator,
406417
State* state) {
@@ -427,6 +438,9 @@ StackFrame::Type StackFrame::ComputeType(const StackFrameIteratorBase* iterator,
427438
Memory::Object_at(state->fp + StandardFrameConstants::kMarkerOffset);
428439
if (marker->IsSmi()) {
429440
return static_cast<StackFrame::Type>(Smi::cast(marker)->value());
441+
} else if (FLAG_ignition && IsInterpreterFramePc(iterator->isolate(),
442+
*(state->pc_address))) {
443+
return INTERPRETED;
430444
} else {
431445
return JAVA_SCRIPT;
432446
}

src/full-codegen/full-codegen.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ bool FullCodeGenerator::MakeCode(CompilationInfo* info) {
6767
CodeGenerator::PrintCode(code, info);
6868
info->SetCode(code);
6969
void* line_info = masm.positions_recorder()->DetachJITHandlerData();
70-
LOG_CODE_EVENT(isolate, CodeEndLinePosInfoRecordEvent(*code, line_info));
70+
LOG_CODE_EVENT(isolate, CodeEndLinePosInfoRecordEvent(
71+
AbstractCode::cast(*code), line_info));
7172

7273
#ifdef DEBUG
7374
// Check that no context-specific object has been embedded.

src/heap/mark-compact.cc

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2630,11 +2630,14 @@ void MarkCompactCollector::MigrateObject(HeapObject* dst, HeapObject* src,
26302630
DCHECK(IsAligned(size, kPointerSize));
26312631

26322632
heap()->MoveBlock(dst->address(), src->address(), size);
2633+
if (FLAG_ignition && dst->IsBytecodeArray()) {
2634+
PROFILE(isolate(), CodeMoveEvent(AbstractCode::cast(src), dst_addr));
2635+
}
26332636
RecordMigratedSlotVisitor visitor(this, old_to_old_slots, old_to_new_slots);
26342637
dst->IterateBody(&visitor);
26352638
} else if (dest == CODE_SPACE) {
26362639
DCHECK_CODEOBJECT_SIZE(size, heap()->code_space());
2637-
PROFILE(isolate(), CodeMoveEvent(src_addr, dst_addr));
2640+
PROFILE(isolate(), CodeMoveEvent(AbstractCode::cast(src), dst_addr));
26382641
heap()->MoveBlock(dst_addr, src_addr, size);
26392642
old_to_old_slots->Record(RELOCATED_CODE_OBJECT, dst_addr);
26402643
Code::cast(dst)->Relocate(dst_addr - src_addr);
@@ -3876,18 +3879,6 @@ void MarkCompactCollector::ParallelSweepSpacesComplete() {
38763879
sweeping_list(heap()->map_space()).clear();
38773880
}
38783881

3879-
3880-
// TODO(1466) ReportDeleteIfNeeded is not called currently.
3881-
// Our profiling tools do not expect intersections between
3882-
// code objects. We should either reenable it or change our tools.
3883-
void MarkCompactCollector::ReportDeleteIfNeeded(HeapObject* obj,
3884-
Isolate* isolate) {
3885-
if (obj->IsCode()) {
3886-
PROFILE(isolate, CodeDeleteEvent(obj->address()));
3887-
}
3888-
}
3889-
3890-
38913882
Isolate* MarkCompactCollector::isolate() const { return heap_->isolate(); }
38923883

38933884

0 commit comments

Comments
 (0)