Commit 1560bbb9 authored by Peter Marshall's avatar Peter Marshall Committed by Commit Bot

[cleanup] Refactor CodeEventListener to use handles

Just a cleanup, should not change behavior, although we will allocate
more handles in some cases.

Also re-orders some of the implementations of the interface to try
and keep things consistent.

Included cleanup: Change CodeEventDispatcher so that it now implements
CodeEventListener, given that it had that exact interface already.
Also remove the macro dispatch to try and make things a bit easier to
read.

Bug: chromium:1033407
Change-Id: Id943b10c49f102d9783d8f4cf3a8c43e04364c77
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1976390Reviewed-by: 's avatarRoss McIlroy <rmcilroy@chromium.org>
Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Commit-Queue: Peter Marshall <petermarshall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#65571}
parent 450736bf
......@@ -282,15 +282,16 @@ void Builtins::EmitCodeCreateEvents(Isolate* isolate) {
Address* builtins = isolate->builtins_table();
int i = 0;
HandleScope scope(isolate);
for (; i < kFirstBytecodeHandler; i++) {
auto code = AbstractCode::cast(Object(builtins[i]));
Handle<AbstractCode> code(AbstractCode::cast(Object(builtins[i])), isolate);
PROFILE(isolate, CodeCreateEvent(CodeEventListener::BUILTIN_TAG, code,
Builtins::name(i)));
}
STATIC_ASSERT(kLastBytecodeHandlerPlusOne == builtin_count);
for (; i < builtin_count; i++) {
auto code = AbstractCode::cast(Object(builtins[i]));
Handle<AbstractCode> code(AbstractCode::cast(Object(builtins[i])), isolate);
interpreter::Bytecode bytecode =
builtin_metadata[i].data.bytecode_and_scale.bytecode;
interpreter::OperandScale scale =
......
......@@ -95,13 +95,14 @@ void LogFunctionCompilation(CodeEventListener::LogEventsAndTags tag,
int line_num = Script::GetLineNumber(script, shared->StartPosition()) + 1;
int column_num = Script::GetColumnNumber(script, shared->StartPosition()) + 1;
String script_name = script->name().IsString()
? String::cast(script->name())
: ReadOnlyRoots(isolate).empty_string();
Handle<String> script_name(script->name().IsString()
? String::cast(script->name())
: ReadOnlyRoots(isolate).empty_string(),
isolate);
CodeEventListener::LogEventsAndTags log_tag =
Logger::ToNativeByScript(tag, *script);
PROFILE(isolate, CodeCreateEvent(log_tag, *abstract_code, *shared,
script_name, line_num, column_num));
PROFILE(isolate, CodeCreateEvent(log_tag, abstract_code, shared, script_name,
line_num, column_num));
if (!FLAG_log_function_events) return;
DisallowHeapAllocation no_gc;
......@@ -387,12 +388,13 @@ void InstallBytecodeArray(Handle<BytecodeArray> bytecode_array,
Script::GetLineNumber(script, shared_info->StartPosition()) + 1;
int column_num =
Script::GetColumnNumber(script, shared_info->StartPosition()) + 1;
String script_name = script->name().IsString()
? String::cast(script->name())
: ReadOnlyRoots(isolate).empty_string();
Handle<String> script_name =
handle(script->name().IsString() ? String::cast(script->name())
: ReadOnlyRoots(isolate).empty_string(),
isolate);
CodeEventListener::LogEventsAndTags log_tag = Logger::ToNativeByScript(
CodeEventListener::INTERPRETED_FUNCTION_TAG, *script);
PROFILE(isolate, CodeCreateEvent(log_tag, *abstract_code, *shared_info,
PROFILE(isolate, CodeCreateEvent(log_tag, abstract_code, shared_info,
script_name, line_num, column_num));
}
......
......@@ -519,8 +519,9 @@ Deoptimizer::Deoptimizer(Isolate* isolate, JSFunction function,
}
if (compiled_code_.kind() == Code::OPTIMIZED_FUNCTION) {
compiled_code_.set_deopt_already_counted(true);
PROFILE(isolate_,
CodeDeoptEvent(compiled_code_, kind, from_, fp_to_sp_delta_));
HandleScope scope(isolate_);
PROFILE(isolate_, CodeDeoptEvent(handle(compiled_code_, isolate_), kind,
from_, fp_to_sp_delta_));
}
unsigned size = ComputeInputFrameSize();
const int parameter_count =
......
......@@ -42,8 +42,8 @@ class PerfJitLogger : public CodeEventLogger {
~PerfJitLogger() override;
void CodeMoveEvent(AbstractCode from, AbstractCode to) override;
void CodeDisableOptEvent(AbstractCode code,
SharedFunctionInfo shared) override {}
void CodeDisableOptEvent(Handle<AbstractCode> code,
Handle<SharedFunctionInfo> shared) override {}
private:
void OpenJitDumpFile();
......@@ -131,8 +131,8 @@ class PerfJitLogger : public CodeEventLogger {
UNIMPLEMENTED();
}
void CodeDisableOptEvent(AbstractCode code,
SharedFunctionInfo shared) override {
void CodeDisableOptEvent(Handle<AbstractCode> code,
Handle<SharedFunctionInfo> shared) override {
UNIMPLEMENTED();
}
......
......@@ -72,34 +72,40 @@ class CodeEventListener {
virtual ~CodeEventListener() = default;
virtual void CodeCreateEvent(LogEventsAndTags tag, AbstractCode code,
const char* comment) = 0;
virtual void CodeCreateEvent(LogEventsAndTags tag, AbstractCode code,
Name name) = 0;
virtual void CodeCreateEvent(LogEventsAndTags tag, AbstractCode code,
SharedFunctionInfo shared, Name source) = 0;
virtual void CodeCreateEvent(LogEventsAndTags tag, AbstractCode code,
SharedFunctionInfo shared, Name source, int line,
virtual void CodeCreateEvent(LogEventsAndTags tag, Handle<AbstractCode> code,
const char* name) = 0;
virtual void CodeCreateEvent(LogEventsAndTags tag, Handle<AbstractCode> code,
Handle<Name> name) = 0;
virtual void CodeCreateEvent(LogEventsAndTags tag, Handle<AbstractCode> code,
Handle<SharedFunctionInfo> shared,
Handle<Name> script_name) = 0;
virtual void CodeCreateEvent(LogEventsAndTags tag, Handle<AbstractCode> code,
Handle<SharedFunctionInfo> shared,
Handle<Name> script_name, int line,
int column) = 0;
virtual void CodeCreateEvent(LogEventsAndTags tag, const wasm::WasmCode* code,
wasm::WasmName name) = 0;
virtual void CallbackEvent(Name name, Address entry_point) = 0;
virtual void GetterCallbackEvent(Name name, Address entry_point) = 0;
virtual void SetterCallbackEvent(Name name, Address entry_point) = 0;
virtual void RegExpCodeCreateEvent(AbstractCode code, String source) = 0;
virtual void CallbackEvent(Handle<Name> name, Address entry_point) = 0;
virtual void GetterCallbackEvent(Handle<Name> name, Address entry_point) = 0;
virtual void SetterCallbackEvent(Handle<Name> name, Address entry_point) = 0;
virtual void RegExpCodeCreateEvent(Handle<AbstractCode> code,
Handle<String> source) = 0;
// Not handlified as this happens during GC. No allocation allowed.
virtual void CodeMoveEvent(AbstractCode from, AbstractCode to) = 0;
virtual void SharedFunctionInfoMoveEvent(Address from, Address to) = 0;
virtual void NativeContextMoveEvent(Address from, Address to) = 0;
virtual void CodeMovingGCEvent() = 0;
virtual void CodeDisableOptEvent(AbstractCode code,
SharedFunctionInfo shared) = 0;
virtual void CodeDeoptEvent(Code code, DeoptimizeKind kind, Address pc,
int fp_to_sp_delta) = 0;
virtual void CodeDisableOptEvent(Handle<AbstractCode> code,
Handle<SharedFunctionInfo> shared) = 0;
virtual void CodeDeoptEvent(Handle<Code> code, DeoptimizeKind kind,
Address pc, int fp_to_sp_delta) = 0;
virtual bool is_listening_to_code_events() { return false; }
};
class CodeEventDispatcher {
// Dispatches code events to a set of registered listeners.
class CodeEventDispatcher : public CodeEventListener {
public:
using LogEventsAndTags = CodeEventListener::LogEventsAndTags;
......@@ -122,61 +128,98 @@ class CodeEventDispatcher {
return false;
}
#define CODE_EVENT_DISPATCH(code) \
base::MutexGuard guard(&mutex_); \
for (auto it = listeners_.begin(); it != listeners_.end(); ++it) (*it)->code
void CodeCreateEvent(LogEventsAndTags tag, AbstractCode code,
const char* comment) {
CODE_EVENT_DISPATCH(CodeCreateEvent(tag, code, comment));
}
void CodeCreateEvent(LogEventsAndTags tag, AbstractCode code, Name name) {
CODE_EVENT_DISPATCH(CodeCreateEvent(tag, code, name));
}
void CodeCreateEvent(LogEventsAndTags tag, AbstractCode code,
SharedFunctionInfo shared, Name name) {
CODE_EVENT_DISPATCH(CodeCreateEvent(tag, code, shared, name));
void DispatchEventToListeners(
std::function<void(CodeEventListener*)> callback) {
base::MutexGuard guard(&mutex_);
for (CodeEventListener* listener : listeners_) {
callback(listener);
}
}
void CodeCreateEvent(LogEventsAndTags tag, AbstractCode code,
SharedFunctionInfo shared, Name source, int line,
int column) {
CODE_EVENT_DISPATCH(
CodeCreateEvent(tag, code, shared, source, line, column));
void CodeCreateEvent(LogEventsAndTags tag, Handle<AbstractCode> code,
const char* comment) override {
DispatchEventToListeners([=](CodeEventListener* listener) {
listener->CodeCreateEvent(tag, code, comment);
});
}
void CodeCreateEvent(LogEventsAndTags tag, Handle<AbstractCode> code,
Handle<Name> name) override {
DispatchEventToListeners([=](CodeEventListener* listener) {
listener->CodeCreateEvent(tag, code, name);
});
}
void CodeCreateEvent(LogEventsAndTags tag, Handle<AbstractCode> code,
Handle<SharedFunctionInfo> shared,
Handle<Name> name) override {
DispatchEventToListeners([=](CodeEventListener* listener) {
listener->CodeCreateEvent(tag, code, shared, name);
});
}
void CodeCreateEvent(LogEventsAndTags tag, Handle<AbstractCode> code,
Handle<SharedFunctionInfo> shared, Handle<Name> source,
int line, int column) override {
DispatchEventToListeners([=](CodeEventListener* listener) {
listener->CodeCreateEvent(tag, code, shared, source, line, column);
});
}
void CodeCreateEvent(LogEventsAndTags tag, const wasm::WasmCode* code,
wasm::WasmName name) {
CODE_EVENT_DISPATCH(CodeCreateEvent(tag, code, name));
}
void CallbackEvent(Name name, Address entry_point) {
CODE_EVENT_DISPATCH(CallbackEvent(name, entry_point));
}
void GetterCallbackEvent(Name name, Address entry_point) {
CODE_EVENT_DISPATCH(GetterCallbackEvent(name, entry_point));
}
void SetterCallbackEvent(Name name, Address entry_point) {
CODE_EVENT_DISPATCH(SetterCallbackEvent(name, entry_point));
}
void RegExpCodeCreateEvent(AbstractCode code, String source) {
CODE_EVENT_DISPATCH(RegExpCodeCreateEvent(code, source));
}
void CodeMoveEvent(AbstractCode from, AbstractCode to) {
CODE_EVENT_DISPATCH(CodeMoveEvent(from, to));
}
void SharedFunctionInfoMoveEvent(Address from, Address to) {
CODE_EVENT_DISPATCH(SharedFunctionInfoMoveEvent(from, to));
}
void NativeContextMoveEvent(Address from, Address to) {
CODE_EVENT_DISPATCH(NativeContextMoveEvent(from, to));
}
void CodeMovingGCEvent() { CODE_EVENT_DISPATCH(CodeMovingGCEvent()); }
void CodeDisableOptEvent(AbstractCode code, SharedFunctionInfo shared) {
CODE_EVENT_DISPATCH(CodeDisableOptEvent(code, shared));
}
void CodeDeoptEvent(Code code, DeoptimizeKind kind, Address pc,
int fp_to_sp_delta) {
CODE_EVENT_DISPATCH(CodeDeoptEvent(code, kind, pc, fp_to_sp_delta));
wasm::WasmName name) override {
DispatchEventToListeners([=](CodeEventListener* listener) {
listener->CodeCreateEvent(tag, code, name);
});
}
void CallbackEvent(Handle<Name> name, Address entry_point) override {
DispatchEventToListeners([=](CodeEventListener* listener) {
listener->CallbackEvent(name, entry_point);
});
}
void GetterCallbackEvent(Handle<Name> name, Address entry_point) override {
DispatchEventToListeners([=](CodeEventListener* listener) {
listener->GetterCallbackEvent(name, entry_point);
});
}
void SetterCallbackEvent(Handle<Name> name, Address entry_point) override {
DispatchEventToListeners([=](CodeEventListener* listener) {
listener->SetterCallbackEvent(name, entry_point);
});
}
void RegExpCodeCreateEvent(Handle<AbstractCode> code,
Handle<String> source) override {
DispatchEventToListeners([=](CodeEventListener* listener) {
listener->RegExpCodeCreateEvent(code, source);
});
}
void CodeMoveEvent(AbstractCode from, AbstractCode to) override {
DispatchEventToListeners([=](CodeEventListener* listener) {
listener->CodeMoveEvent(from, to);
});
}
void SharedFunctionInfoMoveEvent(Address from, Address to) override {
DispatchEventToListeners([=](CodeEventListener* listener) {
listener->SharedFunctionInfoMoveEvent(from, to);
});
}
void NativeContextMoveEvent(Address from, Address to) override {
DispatchEventToListeners([=](CodeEventListener* listener) {
listener->NativeContextMoveEvent(from, to);
});
}
void CodeMovingGCEvent() override {
DispatchEventToListeners(
[](CodeEventListener* listener) { listener->CodeMovingGCEvent(); });
}
void CodeDisableOptEvent(Handle<AbstractCode> code,
Handle<SharedFunctionInfo> shared) override {
DispatchEventToListeners([=](CodeEventListener* listener) {
listener->CodeDisableOptEvent(code, shared);
});
}
void CodeDeoptEvent(Handle<Code> code, DeoptimizeKind kind, Address pc,
int fp_to_sp_delta) override {
DispatchEventToListeners([=](CodeEventListener* listener) {
listener->CodeDeoptEvent(code, kind, pc, fp_to_sp_delta);
});
}
#undef CODE_EVENT_DISPATCH
private:
std::unordered_set<CodeEventListener*> listeners_;
......
This diff is collapsed.
......@@ -186,46 +186,42 @@ class Logger : public CodeEventListener {
V8_EXPORT_PRIVATE void AddCodeEventListener(CodeEventListener* listener);
V8_EXPORT_PRIVATE void RemoveCodeEventListener(CodeEventListener* listener);
// Emits a code event for a callback function.
void CallbackEvent(Name name, Address entry_point) override;
void GetterCallbackEvent(Name name, Address entry_point) override;
void SetterCallbackEvent(Name name, Address entry_point) override;
// Emits a code create event.
void CodeCreateEvent(CodeEventListener::LogEventsAndTags tag,
AbstractCode code, const char* source) override;
void CodeCreateEvent(CodeEventListener::LogEventsAndTags tag,
AbstractCode code, Name name) override;
void CodeCreateEvent(CodeEventListener::LogEventsAndTags tag,
AbstractCode code, SharedFunctionInfo shared,
Name name) override;
void CodeCreateEvent(CodeEventListener::LogEventsAndTags tag,
AbstractCode code, SharedFunctionInfo shared,
Name source, int line, int column) override;
void CodeCreateEvent(CodeEventListener::LogEventsAndTags tag,
const wasm::WasmCode* code,
// CodeEventListener implementation.
void CodeCreateEvent(LogEventsAndTags tag, Handle<AbstractCode> code,
const char* name) override;
void CodeCreateEvent(LogEventsAndTags tag, Handle<AbstractCode> code,
Handle<Name> name) override;
void CodeCreateEvent(LogEventsAndTags tag, Handle<AbstractCode> code,
Handle<SharedFunctionInfo> shared,
Handle<Name> script_name) override;
void CodeCreateEvent(LogEventsAndTags tag, Handle<AbstractCode> code,
Handle<SharedFunctionInfo> shared,
Handle<Name> script_name, int line, int column) override;
void CodeCreateEvent(LogEventsAndTags tag, const wasm::WasmCode* code,
wasm::WasmName name) override;
// Emits a code deoptimization event.
void CodeDisableOptEvent(AbstractCode code,
SharedFunctionInfo shared) override;
void CodeMovingGCEvent() override;
// Emits a code create event for a RegExp.
void RegExpCodeCreateEvent(AbstractCode code, String source) override;
// Emits a code move event.
void CallbackEvent(Handle<Name> name, Address entry_point) override;
void GetterCallbackEvent(Handle<Name> name, Address entry_point) override;
void SetterCallbackEvent(Handle<Name> name, Address entry_point) override;
void RegExpCodeCreateEvent(Handle<AbstractCode> code,
Handle<String> source) override;
void CodeMoveEvent(AbstractCode from, AbstractCode to) override;
void SharedFunctionInfoMoveEvent(Address from, Address to) override;
void NativeContextMoveEvent(Address from, Address to) override {}
void CodeMovingGCEvent() override;
void CodeDisableOptEvent(Handle<AbstractCode> code,
Handle<SharedFunctionInfo> shared) override;
void CodeDeoptEvent(Handle<Code> code, DeoptimizeKind kind, Address pc,
int fp_to_sp_delta) override;
// Emits a code line info record event.
void CodeLinePosInfoRecordEvent(Address code_start,
ByteArray source_position_table);
void CodeLinePosInfoRecordEvent(Address code_start,
Vector<const byte> source_position_table);
void SharedFunctionInfoMoveEvent(Address from, Address to) override;
void NativeContextMoveEvent(Address from, Address to) override {}
void CodeNameEvent(Address addr, int pos, const char* code_name);
void CodeDeoptEvent(Code code, DeoptimizeKind kind, Address pc,
int fp_to_sp_delta) override;
void ICEvent(const char* type, bool keyed, Map map, Object key,
char old_state, char new_state, const char* modifier,
......@@ -281,7 +277,7 @@ class Logger : public CodeEventListener {
void ProfilerBeginEvent();
// Emits callback event messages.
void CallbackEventInternal(const char* prefix, Name name,
void CallbackEventInternal(const char* prefix, Handle<Name> name,
Address entry_point);
// Internal configurable move event.
......@@ -372,31 +368,34 @@ class TimerEventScope {
Isolate* isolate_;
};
// Abstract
class V8_EXPORT_PRIVATE CodeEventLogger : public CodeEventListener {
public:
explicit CodeEventLogger(Isolate* isolate);
~CodeEventLogger() override;
void CodeCreateEvent(LogEventsAndTags tag, AbstractCode code,
const char* comment) override;
void CodeCreateEvent(LogEventsAndTags tag, AbstractCode code,
Name name) override;
void CodeCreateEvent(LogEventsAndTags tag, AbstractCode code,
SharedFunctionInfo shared, Name name) override;
void CodeCreateEvent(LogEventsAndTags tag, AbstractCode code,
SharedFunctionInfo shared, Name source, int line,
int column) override;
void CodeCreateEvent(LogEventsAndTags tag, Handle<AbstractCode> code,
const char* name) override;
void CodeCreateEvent(LogEventsAndTags tag, Handle<AbstractCode> code,
Handle<Name> name) override;
void CodeCreateEvent(LogEventsAndTags tag, Handle<AbstractCode> code,
Handle<SharedFunctionInfo> shared,
Handle<Name> script_name) override;
void CodeCreateEvent(LogEventsAndTags tag, Handle<AbstractCode> code,
Handle<SharedFunctionInfo> shared,
Handle<Name> script_name, int line, int column) override;
void CodeCreateEvent(LogEventsAndTags tag, const wasm::WasmCode* code,
wasm::WasmName name) override;
void RegExpCodeCreateEvent(AbstractCode code, String source) override;
void CallbackEvent(Name name, Address entry_point) override {}
void GetterCallbackEvent(Name name, Address entry_point) override {}
void SetterCallbackEvent(Name name, Address entry_point) override {}
void RegExpCodeCreateEvent(Handle<AbstractCode> code,
Handle<String> source) override;
void CallbackEvent(Handle<Name> name, Address entry_point) override {}
void GetterCallbackEvent(Handle<Name> name, Address entry_point) override {}
void SetterCallbackEvent(Handle<Name> name, Address entry_point) override {}
void SharedFunctionInfoMoveEvent(Address from, Address to) override {}
void NativeContextMoveEvent(Address from, Address to) override {}
void CodeMovingGCEvent() override {}
void CodeDeoptEvent(Code code, DeoptimizeKind kind, Address pc,
void CodeDeoptEvent(Handle<Code> code, DeoptimizeKind kind, Address pc,
int fp_to_sp_delta) override {}
protected:
......@@ -431,29 +430,31 @@ class ExternalCodeEventListener : public CodeEventListener {
explicit ExternalCodeEventListener(Isolate* isolate);
~ExternalCodeEventListener() override;
void CodeCreateEvent(LogEventsAndTags tag, AbstractCode code,
void CodeCreateEvent(LogEventsAndTags tag, Handle<AbstractCode> code,
const char* comment) override;
void CodeCreateEvent(LogEventsAndTags tag, AbstractCode code,
Name name) override;
void CodeCreateEvent(LogEventsAndTags tag, AbstractCode code,
SharedFunctionInfo shared, Name name) override;
void CodeCreateEvent(LogEventsAndTags tag, AbstractCode code,
SharedFunctionInfo shared, Name source, int line,
int column) override;
void CodeCreateEvent(LogEventsAndTags tag, Handle<AbstractCode> code,
Handle<Name> name) override;
void CodeCreateEvent(LogEventsAndTags tag, Handle<AbstractCode> code,
Handle<SharedFunctionInfo> shared,
Handle<Name> name) override;
void CodeCreateEvent(LogEventsAndTags tag, Handle<AbstractCode> code,
Handle<SharedFunctionInfo> shared, Handle<Name> source,
int line, int column) override;
void CodeCreateEvent(LogEventsAndTags tag, const wasm::WasmCode* code,
wasm::WasmName name) override;
void RegExpCodeCreateEvent(AbstractCode code, String source) override;
void CallbackEvent(Name name, Address entry_point) override {}
void GetterCallbackEvent(Name name, Address entry_point) override {}
void SetterCallbackEvent(Name name, Address entry_point) override {}
void RegExpCodeCreateEvent(Handle<AbstractCode> code,
Handle<String> source) override;
void CallbackEvent(Handle<Name> name, Address entry_point) override {}
void GetterCallbackEvent(Handle<Name> name, Address entry_point) override {}
void SetterCallbackEvent(Handle<Name> name, Address entry_point) override {}
void SharedFunctionInfoMoveEvent(Address from, Address to) override {}
void NativeContextMoveEvent(Address from, Address to) override {}
void CodeMoveEvent(AbstractCode from, AbstractCode to) override;
void CodeDisableOptEvent(AbstractCode code,
SharedFunctionInfo shared) override {}
void CodeDisableOptEvent(Handle<AbstractCode> code,
Handle<SharedFunctionInfo> shared) override {}
void CodeMovingGCEvent() override {}
void CodeDeoptEvent(Code code, DeoptimizeKind kind, Address pc,
void CodeDeoptEvent(Handle<Code> code, DeoptimizeKind kind, Address pc,
int fp_to_sp_delta) override {}
void StartListening(v8::CodeEventHandler* code_event_handler);
......
......@@ -5246,7 +5246,9 @@ void SharedFunctionInfo::DisableOptimization(BailoutReason reason) {
// Code should be the lazy compilation stub or else interpreted.
DCHECK(abstract_code().kind() == AbstractCode::INTERPRETED_FUNCTION ||
abstract_code().kind() == AbstractCode::BUILTIN);
PROFILE(GetIsolate(), CodeDisableOptEvent(abstract_code(), *this));
PROFILE(GetIsolate(),
CodeDisableOptEvent(handle(abstract_code(), GetIsolate()),
handle(*this, GetIsolate())));
if (FLAG_trace_opt) {
PrintF("[disabled optimization for ");
ShortPrint();
......
This diff is collapsed.
......@@ -30,32 +30,32 @@ class V8_EXPORT_PRIVATE ProfilerListener : public CodeEventListener {
CpuProfilingNamingMode mode = kDebugNaming);
~ProfilerListener() override;
void CallbackEvent(Name name, Address entry_point) override;
void CodeCreateEvent(CodeEventListener::LogEventsAndTags tag,
AbstractCode code, const char* comment) override;
void CodeCreateEvent(CodeEventListener::LogEventsAndTags tag,
AbstractCode code, Name name) override;
void CodeCreateEvent(CodeEventListener::LogEventsAndTags tag,
AbstractCode code, SharedFunctionInfo shared,
Name script_name) override;
void CodeCreateEvent(CodeEventListener::LogEventsAndTags tag,
AbstractCode code, SharedFunctionInfo shared,
Name script_name, int line, int column) override;
void CodeCreateEvent(CodeEventListener::LogEventsAndTags tag,
const wasm::WasmCode* code,
void CodeCreateEvent(LogEventsAndTags tag, Handle<AbstractCode> code,
const char* name) override;
void CodeCreateEvent(LogEventsAndTags tag, Handle<AbstractCode> code,
Handle<Name> name) override;
void CodeCreateEvent(LogEventsAndTags tag, Handle<AbstractCode> code,
Handle<SharedFunctionInfo> shared,
Handle<Name> script_name) override;
void CodeCreateEvent(LogEventsAndTags tag, Handle<AbstractCode> code,
Handle<SharedFunctionInfo> shared,
Handle<Name> script_name, int line, int column) override;
void CodeCreateEvent(LogEventsAndTags tag, const wasm::WasmCode* code,
wasm::WasmName name) override;
void CodeMovingGCEvent() override {}
void CallbackEvent(Handle<Name> name, Address entry_point) override;
void GetterCallbackEvent(Handle<Name> name, Address entry_point) override;
void SetterCallbackEvent(Handle<Name> name, Address entry_point) override;
void RegExpCodeCreateEvent(Handle<AbstractCode> code,
Handle<String> source) override;
void CodeMoveEvent(AbstractCode from, AbstractCode to) override;
void CodeDisableOptEvent(AbstractCode code,
SharedFunctionInfo shared) override;
void CodeDeoptEvent(Code code, DeoptimizeKind kind, Address pc,
int fp_to_sp_delta) override;
void GetterCallbackEvent(Name name, Address entry_point) override;
void RegExpCodeCreateEvent(AbstractCode code, String source) override;
void SetterCallbackEvent(Name name, Address entry_point) override;
void SharedFunctionInfoMoveEvent(Address from, Address to) override {}
void NativeContextMoveEvent(Address from, Address to) override;
void CodeMovingGCEvent() override {}
void CodeDisableOptEvent(Handle<AbstractCode> code,
Handle<SharedFunctionInfo> shared) override;
void CodeDeoptEvent(Handle<Code> code, DeoptimizeKind kind, Address pc,
int fp_to_sp_delta) override;
const char* GetName(Name name) {
return function_and_resource_names_.GetName(name);
......@@ -76,7 +76,7 @@ class V8_EXPORT_PRIVATE ProfilerListener : public CodeEventListener {
private:
const char* GetFunctionName(SharedFunctionInfo);
void AttachDeoptInlinedFrames(Code code, CodeDeoptEventRecord* rec);
void AttachDeoptInlinedFrames(Handle<Code> code, CodeDeoptEventRecord* rec);
Name InferScriptName(Name name, SharedFunctionInfo info);
V8_INLINE void DispatchCodeEvent(const CodeEventsContainer& evt_rec) {
observer_->CodeEventHandler(evt_rec);
......
......@@ -911,7 +911,7 @@ Handle<HeapObject> RegExpMacroAssemblerARM::GetCode(Handle<String> source) {
.set_self_reference(masm_->CodeObject())
.Build();
PROFILE(masm_->isolate(),
RegExpCodeCreateEvent(AbstractCode::cast(*code), *source));
RegExpCodeCreateEvent(Handle<AbstractCode>::cast(code), source));
return Handle<HeapObject>::cast(code);
}
......
......@@ -1097,7 +1097,7 @@ Handle<HeapObject> RegExpMacroAssemblerARM64::GetCode(Handle<String> source) {
.set_self_reference(masm_->CodeObject())
.Build();
PROFILE(masm_->isolate(),
RegExpCodeCreateEvent(AbstractCode::cast(*code), *source));
RegExpCodeCreateEvent(Handle<AbstractCode>::cast(code), source));
return Handle<HeapObject>::cast(code);
}
......
......@@ -952,7 +952,7 @@ Handle<HeapObject> RegExpMacroAssemblerIA32::GetCode(Handle<String> source) {
.set_self_reference(masm_->CodeObject())
.Build();
PROFILE(masm_->isolate(),
RegExpCodeCreateEvent(AbstractCode::cast(*code), *source));
RegExpCodeCreateEvent(Handle<AbstractCode>::cast(code), source));
return Handle<HeapObject>::cast(code);
}
......
......@@ -922,7 +922,7 @@ Handle<HeapObject> RegExpMacroAssemblerMIPS::GetCode(Handle<String> source) {
.set_self_reference(masm_->CodeObject())
.Build();
LOG(masm_->isolate(),
RegExpCodeCreateEvent(AbstractCode::cast(*code), *source));
RegExpCodeCreateEvent(Handle<AbstractCode>::cast(code), source));
return Handle<HeapObject>::cast(code);
}
......
......@@ -958,7 +958,7 @@ Handle<HeapObject> RegExpMacroAssemblerMIPS::GetCode(Handle<String> source) {
.set_self_reference(masm_->CodeObject())
.Build();
LOG(masm_->isolate(),
RegExpCodeCreateEvent(AbstractCode::cast(*code), *source));
RegExpCodeCreateEvent(Handle<AbstractCode>::cast(code), source));
return Handle<HeapObject>::cast(code);
}
......
......@@ -963,7 +963,7 @@ Handle<HeapObject> RegExpMacroAssemblerPPC::GetCode(Handle<String> source) {
.set_self_reference(masm_->CodeObject())
.Build();
PROFILE(masm_->isolate(),
RegExpCodeCreateEvent(AbstractCode::cast(*code), *source));
RegExpCodeCreateEvent(Handle<AbstractCode>::cast(code), source));
return Handle<HeapObject>::cast(code);
}
......
......@@ -957,7 +957,7 @@ Handle<HeapObject> RegExpMacroAssemblerS390::GetCode(Handle<String> source) {
.set_self_reference(masm_->CodeObject())
.Build();
PROFILE(masm_->isolate(),
RegExpCodeCreateEvent(AbstractCode::cast(*code), *source));
RegExpCodeCreateEvent(Handle<AbstractCode>::cast(code), source));
return Handle<HeapObject>::cast(code);
}
......
......@@ -1014,7 +1014,8 @@ Handle<HeapObject> RegExpMacroAssemblerX64::GetCode(Handle<String> source) {
Handle<Code> code = Factory::CodeBuilder(isolate, code_desc, Code::REGEXP)
.set_self_reference(masm_.CodeObject())
.Build();
PROFILE(isolate, RegExpCodeCreateEvent(AbstractCode::cast(*code), *source));
PROFILE(isolate,
RegExpCodeCreateEvent(Handle<AbstractCode>::cast(code), source));
return Handle<HeapObject>::cast(code);
}
......
......@@ -1449,28 +1449,32 @@ RUNTIME_FUNCTION(Runtime_EnableCodeLoggingForTesting) {
// {true} on {is_listening_to_code_events()}. Feel free to add assertions to
// any method to further test the code logging callbacks.
class NoopListener final : public CodeEventListener {
void CodeCreateEvent(LogEventsAndTags tag, AbstractCode code,
const char* comment) final {}
void CodeCreateEvent(LogEventsAndTags tag, AbstractCode code,
Name name) final {}
void CodeCreateEvent(LogEventsAndTags tag, AbstractCode code,
SharedFunctionInfo shared, Name source) final {}
void CodeCreateEvent(LogEventsAndTags tag, AbstractCode code,
SharedFunctionInfo shared, Name source, int line,
int column) final {}
void CodeCreateEvent(LogEventsAndTags tag, Handle<AbstractCode> code,
const char* name) final {}
void CodeCreateEvent(LogEventsAndTags tag, Handle<AbstractCode> code,
Handle<Name> name) final {}
void CodeCreateEvent(LogEventsAndTags tag, Handle<AbstractCode> code,
Handle<SharedFunctionInfo> shared,
Handle<Name> script_name) final {}
void CodeCreateEvent(LogEventsAndTags tag, Handle<AbstractCode> code,
Handle<SharedFunctionInfo> shared,
Handle<Name> script_name, int line, int column) final {
}
void CodeCreateEvent(LogEventsAndTags tag, const wasm::WasmCode* code,
wasm::WasmName name) final {}
void CallbackEvent(Name name, Address entry_point) final {}
void GetterCallbackEvent(Name name, Address entry_point) final {}
void SetterCallbackEvent(Name name, Address entry_point) final {}
void RegExpCodeCreateEvent(AbstractCode code, String source) final {}
void CallbackEvent(Handle<Name> name, Address entry_point) final {}
void GetterCallbackEvent(Handle<Name> name, Address entry_point) final {}
void SetterCallbackEvent(Handle<Name> name, Address entry_point) final {}
void RegExpCodeCreateEvent(Handle<AbstractCode> code,
Handle<String> source) final {}
void CodeMoveEvent(AbstractCode from, AbstractCode to) final {}
void SharedFunctionInfoMoveEvent(Address from, Address to) final {}
void NativeContextMoveEvent(Address from, Address to) final {}
void CodeMovingGCEvent() final {}
void CodeDisableOptEvent(AbstractCode code,
SharedFunctionInfo shared) final {}
void CodeDeoptEvent(Code code, DeoptimizeKind kind, Address pc,
void CodeDisableOptEvent(Handle<AbstractCode> code,
Handle<SharedFunctionInfo> shared) final {}
void CodeDeoptEvent(Handle<Code> code, DeoptimizeKind kind, Address pc,
int fp_to_sp_delta) final {}
bool is_listening_to_code_events() final { return true; }
......
......@@ -251,7 +251,7 @@ void CreateInterpreterDataForDeserializedCode(Isolate* isolate,
int column_num = script->GetColumnNumber(info->StartPosition()) + 1;
PROFILE(isolate,
CodeCreateEvent(CodeEventListener::INTERPRETED_FUNCTION_TAG,
*abstract_code, *info, *name_handle, line_num,
abstract_code, info, name_handle, line_num,
column_num));
}
}
......@@ -339,9 +339,10 @@ MaybeHandle<SharedFunctionInfo> CodeSerializer::Deserialize(
script->GetLineNumber(shared_info->StartPosition()) + 1;
int column_num =
script->GetColumnNumber(shared_info->StartPosition()) + 1;
PROFILE(isolate, CodeCreateEvent(CodeEventListener::SCRIPT_TAG,
info.abstract_code(), *shared_info,
*name, line_num, column_num));
PROFILE(isolate,
CodeCreateEvent(CodeEventListener::SCRIPT_TAG,
handle(info.abstract_code(), isolate),
shared_info, name, line_num, column_num));
}
}
}
......
......@@ -32,8 +32,8 @@ class CodeAddressMap : public CodeEventLogger {
address_to_name_map_.Move(from.address(), to.address());
}
void CodeDisableOptEvent(AbstractCode code,
SharedFunctionInfo shared) override {}
void CodeDisableOptEvent(Handle<AbstractCode> code,
Handle<SharedFunctionInfo> shared) override {}
const char* Lookup(Address address) {
return address_to_name_map_.Lookup(address);
......
......@@ -233,7 +233,7 @@ void RecordWasmHeapStubCompilation(Isolate* isolate, Handle<Code> code,
Handle<String> name_str =
isolate->factory()->NewStringFromAsciiChecked(buffer.begin());
PROFILE(isolate, CodeCreateEvent(CodeEventListener::STUB_TAG,
AbstractCode::cast(*code), *name_str));
Handle<AbstractCode>::cast(code), name_str));
}
} // namespace
......
......@@ -166,10 +166,10 @@ TEST(CodeEvents) {
i::HandleScope scope(isolate);
i::AbstractCode aaa_code = CreateCode(&env);
i::AbstractCode comment_code = CreateCode(&env);
i::AbstractCode comment2_code = CreateCode(&env);
i::AbstractCode moved_code = CreateCode(&env);
i::Handle<i::AbstractCode> aaa_code(CreateCode(&env), isolate);
i::Handle<i::AbstractCode> comment_code(CreateCode(&env), isolate);
i::Handle<i::AbstractCode> comment2_code(CreateCode(&env), isolate);
i::Handle<i::AbstractCode> moved_code(CreateCode(&env), isolate);
CpuProfilesCollection* profiles = new CpuProfilesCollection(isolate);
ProfilerCodeObserver code_observer(isolate);
......@@ -186,34 +186,34 @@ TEST(CodeEvents) {
const char* aaa_str = "aaa";
i::Handle<i::String> aaa_name = factory->NewStringFromAsciiChecked(aaa_str);
profiler_listener.CodeCreateEvent(i::Logger::FUNCTION_TAG, aaa_code,
*aaa_name);
aaa_name);
profiler_listener.CodeCreateEvent(i::Logger::BUILTIN_TAG, comment_code,
"comment");
profiler_listener.CodeCreateEvent(i::Logger::BUILTIN_TAG, comment2_code,
"comment2");
profiler_listener.CodeMoveEvent(comment2_code, moved_code);
profiler_listener.CodeMoveEvent(*comment2_code, *moved_code);
// Enqueue a tick event to enable code events processing.
EnqueueTickSampleEvent(processor, aaa_code.InstructionStart());
EnqueueTickSampleEvent(processor, aaa_code->InstructionStart());
isolate->logger()->RemoveCodeEventListener(&profiler_listener);
processor->StopSynchronously();
// Check the state of profile generator.
CodeEntry* aaa =
generator->code_map()->FindEntry(aaa_code.InstructionStart());
generator->code_map()->FindEntry(aaa_code->InstructionStart());
CHECK(aaa);
CHECK_EQ(0, strcmp(aaa_str, aaa->name()));
CodeEntry* comment =
generator->code_map()->FindEntry(comment_code.InstructionStart());
generator->code_map()->FindEntry(comment_code->InstructionStart());
CHECK(comment);
CHECK_EQ(0, strcmp("comment", comment->name()));
CHECK(!generator->code_map()->FindEntry(comment2_code.InstructionStart()));
CHECK(!generator->code_map()->FindEntry(comment2_code->InstructionStart()));
CodeEntry* comment2 =
generator->code_map()->FindEntry(moved_code.InstructionStart());
generator->code_map()->FindEntry(moved_code->InstructionStart());
CHECK(comment2);
CHECK_EQ(0, strcmp("comment2", comment2->name()));
}
......@@ -229,9 +229,9 @@ TEST(TickEvents) {
i::Isolate* isolate = CcTest::i_isolate();
i::HandleScope scope(isolate);
i::AbstractCode frame1_code = CreateCode(&env);
i::AbstractCode frame2_code = CreateCode(&env);
i::AbstractCode frame3_code = CreateCode(&env);
i::Handle<i::AbstractCode> frame1_code(CreateCode(&env), isolate);
i::Handle<i::AbstractCode> frame2_code(CreateCode(&env), isolate);
i::Handle<i::AbstractCode> frame3_code(CreateCode(&env), isolate);
CpuProfilesCollection* profiles = new CpuProfilesCollection(isolate);
ProfilerCodeObserver code_observer(isolate);
......@@ -251,14 +251,14 @@ TEST(TickEvents) {
profiler_listener.CodeCreateEvent(i::Logger::STUB_TAG, frame2_code, "ccc");
profiler_listener.CodeCreateEvent(i::Logger::BUILTIN_TAG, frame3_code, "ddd");
EnqueueTickSampleEvent(processor, frame1_code.raw_instruction_start());
EnqueueTickSampleEvent(processor, frame1_code->raw_instruction_start());
EnqueueTickSampleEvent(
processor,
frame2_code.raw_instruction_start() + frame2_code.ExecutableSize() / 2,
frame1_code.raw_instruction_start() + frame1_code.ExecutableSize() / 2);
EnqueueTickSampleEvent(processor, frame3_code.raw_instruction_end() - 1,
frame2_code.raw_instruction_end() - 1,
frame1_code.raw_instruction_end() - 1);
frame2_code->raw_instruction_start() + frame2_code->ExecutableSize() / 2,
frame1_code->raw_instruction_start() + frame1_code->ExecutableSize() / 2);
EnqueueTickSampleEvent(processor, frame3_code->raw_instruction_end() - 1,
frame2_code->raw_instruction_end() - 1,
frame1_code->raw_instruction_end() - 1);
isolate->logger()->RemoveCodeEventListener(&profiler_listener);
processor->StopSynchronously();
......@@ -303,7 +303,7 @@ TEST(Issue1398) {
i::Isolate* isolate = CcTest::i_isolate();
i::HandleScope scope(isolate);
i::AbstractCode code = CreateCode(&env);
i::Handle<i::AbstractCode> code(CreateCode(&env), isolate);
CpuProfilesCollection* profiles = new CpuProfilesCollection(isolate);
ProfilerCodeObserver code_observer(isolate);
......@@ -321,11 +321,11 @@ TEST(Issue1398) {
profiler_listener.CodeCreateEvent(i::Logger::BUILTIN_TAG, code, "bbb");
v8::internal::TickSample sample;
sample.pc = reinterpret_cast<void*>(code.InstructionStart());
sample.pc = reinterpret_cast<void*>(code->InstructionStart());
sample.tos = nullptr;
sample.frames_count = TickSample::kMaxFramesCount;
for (unsigned i = 0; i < sample.frames_count; ++i) {
sample.stack[i] = reinterpret_cast<void*>(code.InstructionStart());
sample.stack[i] = reinterpret_cast<void*>(code->InstructionStart());
}
sample.timestamp = base::TimeTicks::HighResolutionNow();
processor->AddSample(sample);
......@@ -1169,9 +1169,9 @@ static void TickLines(bool optimize) {
CHECK(!func->shared().abstract_code().is_null());
CHECK(!optimize || func->IsOptimized() ||
!CcTest::i_isolate()->use_optimizer());
i::AbstractCode code = func->abstract_code();
CHECK(!code.is_null());
i::Address code_address = code.raw_instruction_start();
i::Handle<i::AbstractCode> code(func->abstract_code(), isolate);
CHECK(!code->is_null());
i::Address code_address = code->raw_instruction_start();
CHECK_NE(code_address, kNullAddress);
CpuProfilesCollection* profiles = new CpuProfilesCollection(isolate);
......@@ -1197,7 +1197,8 @@ static void TickLines(bool optimize) {
int line = 1;
int column = 1;
profiler_listener.CodeCreateEvent(i::Logger::FUNCTION_TAG, code,
func->shared(), *str, line, column);
handle(func->shared(), isolate), str, line,
column);
// Enqueue a tick event to enable code events processing.
EnqueueTickSampleEvent(processor, code_address);
......
......@@ -460,8 +460,9 @@ UNINITIALIZED_TEST(Issue539892) {
: CodeEventLogger(isolate) {}
void CodeMoveEvent(i::AbstractCode from, i::AbstractCode to) override {}
void CodeDisableOptEvent(i::AbstractCode code,
i::SharedFunctionInfo shared) override {}
void CodeDisableOptEvent(i::Handle<i::AbstractCode> code,
i::Handle<i::SharedFunctionInfo> shared) override {
}
private:
void LogRecordedBuffer(i::AbstractCode code, i::SharedFunctionInfo shared,
......
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