Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4663d1c

Browse files
Matheus Marchinitargos
Matheus Marchini
authored andcommittedJun 24, 2018
deps: backport aa6ce3e from upstream V8
Original commit message: [log][api] introduce public CodeEventListener API Introduce a new public API called CodeEventListener to allow embedders to better support external profilers and other diagnostic tools without relying on unsupported methods like --perf-basic-prof. Bug: v8:7694 Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng Change-Id: I063cc965394d59401358757634c9ea84c11517e9 Co-authored-by: Daniel Beckert <[email protected]> Reviewed-on: https://chromium-review.googlesource.com/1028770 Commit-Queue: Yang Guo <[email protected]> Reviewed-by: Hannes Payer <[email protected]> Reviewed-by: Yang Guo <[email protected]> Reviewed-by: Andreas Haas <[email protected]> Cr-Commit-Position: refs/heads/master@{#53382} Refs: v8/v8@aa6ce3e PR-URL: #21126 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 6b40ba1 commit 4663d1c

16 files changed

+695
-201
lines changed
 

‎common.gypi

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
# Reset this number to 0 on major V8 upgrades.
2929
# Increment by one for each non-official patch applied to deps/v8.
30-
'v8_embedder_string': '-node.9',
30+
'v8_embedder_string': '-node.10',
3131

3232
# Enable disassembler for `--print-code` v8 options
3333
'v8_enable_disassembler': 1,

‎deps/v8/include/v8-profiler.h

+70
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,76 @@ struct HeapStatsUpdate {
988988
uint32_t size; // New value of size field for the interval with this index.
989989
};
990990

991+
#define CODE_EVENTS_LIST(V) \
992+
V(Builtin) \
993+
V(Callback) \
994+
V(Eval) \
995+
V(Function) \
996+
V(InterpretedFunction) \
997+
V(Handler) \
998+
V(BytecodeHandler) \
999+
V(LazyCompile) \
1000+
V(RegExp) \
1001+
V(Script) \
1002+
V(Stub)
1003+
1004+
/**
1005+
* Note that this enum may be extended in the future. Please include a default
1006+
* case if this enum is used in a switch statement.
1007+
*/
1008+
enum CodeEventType {
1009+
kUnknownType = 0
1010+
#define V(Name) , k##Name##Type
1011+
CODE_EVENTS_LIST(V)
1012+
#undef V
1013+
};
1014+
1015+
/**
1016+
* Representation of a code creation event
1017+
*/
1018+
class V8_EXPORT CodeEvent {
1019+
public:
1020+
uintptr_t GetCodeStartAddress();
1021+
size_t GetCodeSize();
1022+
Local<String> GetFunctionName();
1023+
Local<String> GetScriptName();
1024+
int GetScriptLine();
1025+
int GetScriptColumn();
1026+
/**
1027+
* NOTE (mmarchini): We can't allocate objects in the heap when we collect
1028+
* existing code, and both the code type and the comment are not stored in the
1029+
* heap, so we return those as const char*.
1030+
*/
1031+
CodeEventType GetCodeType();
1032+
const char* GetComment();
1033+
1034+
static const char* GetCodeEventTypeName(CodeEventType code_event_type);
1035+
};
1036+
1037+
/**
1038+
* Interface to listen to code creation events.
1039+
*/
1040+
class V8_EXPORT CodeEventHandler {
1041+
public:
1042+
/**
1043+
* Creates a new listener for the |isolate|. The isolate must be initialized.
1044+
* The listener object must be disposed after use by calling |Dispose| method.
1045+
* Multiple listeners can be created for the same isolate.
1046+
*/
1047+
explicit CodeEventHandler(Isolate* isolate);
1048+
virtual ~CodeEventHandler();
1049+
1050+
virtual void Handle(CodeEvent* code_event) = 0;
1051+
1052+
void Enable();
1053+
void Disable();
1054+
1055+
private:
1056+
CodeEventHandler();
1057+
CodeEventHandler(const CodeEventHandler&);
1058+
CodeEventHandler& operator=(const CodeEventHandler&);
1059+
void* internal_listener_;
1060+
};
9911061

9921062
} // namespace v8
9931063

‎deps/v8/src/api.cc

+64
Original file line numberDiff line numberDiff line change
@@ -10211,6 +10211,70 @@ void CpuProfiler::SetIdle(bool is_idle) {
1021110211
isolate->SetIdle(is_idle);
1021210212
}
1021310213

10214+
uintptr_t CodeEvent::GetCodeStartAddress() {
10215+
return reinterpret_cast<i::CodeEvent*>(this)->code_start_address;
10216+
}
10217+
10218+
size_t CodeEvent::GetCodeSize() {
10219+
return reinterpret_cast<i::CodeEvent*>(this)->code_size;
10220+
}
10221+
10222+
Local<String> CodeEvent::GetFunctionName() {
10223+
return ToApiHandle<String>(
10224+
reinterpret_cast<i::CodeEvent*>(this)->function_name);
10225+
}
10226+
10227+
Local<String> CodeEvent::GetScriptName() {
10228+
return ToApiHandle<String>(
10229+
reinterpret_cast<i::CodeEvent*>(this)->script_name);
10230+
}
10231+
10232+
int CodeEvent::GetScriptLine() {
10233+
return reinterpret_cast<i::CodeEvent*>(this)->script_line;
10234+
}
10235+
10236+
int CodeEvent::GetScriptColumn() {
10237+
return reinterpret_cast<i::CodeEvent*>(this)->script_column;
10238+
}
10239+
10240+
CodeEventType CodeEvent::GetCodeType() {
10241+
return reinterpret_cast<i::CodeEvent*>(this)->code_type;
10242+
}
10243+
10244+
const char* CodeEvent::GetComment() {
10245+
return reinterpret_cast<i::CodeEvent*>(this)->comment;
10246+
}
10247+
10248+
const char* CodeEvent::GetCodeEventTypeName(CodeEventType code_event_type) {
10249+
switch (code_event_type) {
10250+
case kUnknownType:
10251+
return "Unknown";
10252+
#define V(Name) \
10253+
case k##Name##Type: \
10254+
return #Name;
10255+
CODE_EVENTS_LIST(V)
10256+
#undef V
10257+
}
10258+
}
10259+
10260+
CodeEventHandler::CodeEventHandler(Isolate* isolate) {
10261+
internal_listener_ =
10262+
new i::ExternalCodeEventListener(reinterpret_cast<i::Isolate*>(isolate));
10263+
}
10264+
10265+
CodeEventHandler::~CodeEventHandler() {
10266+
delete reinterpret_cast<i::ExternalCodeEventListener*>(internal_listener_);
10267+
}
10268+
10269+
void CodeEventHandler::Enable() {
10270+
reinterpret_cast<i::ExternalCodeEventListener*>(internal_listener_)
10271+
->StartListening(this);
10272+
}
10273+
10274+
void CodeEventHandler::Disable() {
10275+
reinterpret_cast<i::ExternalCodeEventListener*>(internal_listener_)
10276+
->StopListening();
10277+
}
1021410278

1021510279
static i::HeapGraphEdge* ToInternal(const HeapGraphEdge* edge) {
1021610280
return const_cast<i::HeapGraphEdge*>(

‎deps/v8/src/code-events.h

+39-23
Original file line numberDiff line numberDiff line change
@@ -24,32 +24,38 @@ class WasmCode;
2424
using WasmName = Vector<const char>;
2525
} // namespace wasm
2626

27-
#define LOG_EVENTS_AND_TAGS_LIST(V) \
28-
V(CODE_CREATION_EVENT, "code-creation") \
29-
V(CODE_DISABLE_OPT_EVENT, "code-disable-optimization") \
30-
V(CODE_MOVE_EVENT, "code-move") \
31-
V(CODE_DELETE_EVENT, "code-delete") \
32-
V(CODE_MOVING_GC, "code-moving-gc") \
33-
V(SHARED_FUNC_MOVE_EVENT, "sfi-move") \
34-
V(SNAPSHOT_CODE_NAME_EVENT, "snapshot-code-name") \
35-
V(TICK_EVENT, "tick") \
36-
V(BUILTIN_TAG, "Builtin") \
37-
V(CALLBACK_TAG, "Callback") \
38-
V(EVAL_TAG, "Eval") \
39-
V(FUNCTION_TAG, "Function") \
40-
V(INTERPRETED_FUNCTION_TAG, "InterpretedFunction") \
41-
V(HANDLER_TAG, "Handler") \
42-
V(BYTECODE_HANDLER_TAG, "BytecodeHandler") \
43-
V(LAZY_COMPILE_TAG, "LazyCompile") \
44-
V(REG_EXP_TAG, "RegExp") \
45-
V(SCRIPT_TAG, "Script") \
46-
V(STUB_TAG, "Stub") \
47-
V(NATIVE_FUNCTION_TAG, "Function") \
48-
V(NATIVE_LAZY_COMPILE_TAG, "LazyCompile") \
49-
V(NATIVE_SCRIPT_TAG, "Script")
27+
#define LOG_EVENTS_LIST(V) \
28+
V(CODE_CREATION_EVENT, code-creation) \
29+
V(CODE_DISABLE_OPT_EVENT, code-disable-optimization) \
30+
V(CODE_MOVE_EVENT, code-move) \
31+
V(CODE_DELETE_EVENT, code-delete) \
32+
V(CODE_MOVING_GC, code-moving-gc) \
33+
V(SHARED_FUNC_MOVE_EVENT, sfi-move) \
34+
V(SNAPSHOT_CODE_NAME_EVENT, snapshot-code-name) \
35+
V(TICK_EVENT, tick)
36+
37+
#define TAGS_LIST(V) \
38+
V(BUILTIN_TAG, Builtin) \
39+
V(CALLBACK_TAG, Callback) \
40+
V(EVAL_TAG, Eval) \
41+
V(FUNCTION_TAG, Function) \
42+
V(INTERPRETED_FUNCTION_TAG, InterpretedFunction) \
43+
V(HANDLER_TAG, Handler) \
44+
V(BYTECODE_HANDLER_TAG, BytecodeHandler) \
45+
V(LAZY_COMPILE_TAG, LazyCompile) \
46+
V(REG_EXP_TAG, RegExp) \
47+
V(SCRIPT_TAG, Script) \
48+
V(STUB_TAG, Stub) \
49+
V(NATIVE_FUNCTION_TAG, Function) \
50+
V(NATIVE_LAZY_COMPILE_TAG, LazyCompile) \
51+
V(NATIVE_SCRIPT_TAG, Script)
5052
// Note that 'NATIVE_' cases for functions and scripts are mapped onto
5153
// original tags when writing to the log.
5254

55+
#define LOG_EVENTS_AND_TAGS_LIST(V) \
56+
LOG_EVENTS_LIST(V) \
57+
TAGS_LIST(V)
58+
5359
#define PROFILE(the_isolate, Call) (the_isolate)->code_event_dispatcher()->Call;
5460

5561
class CodeEventListener {
@@ -85,6 +91,8 @@ class CodeEventListener {
8591
enum DeoptKind { kSoft, kLazy, kEager };
8692
virtual void CodeDeoptEvent(Code* code, DeoptKind kind, Address pc,
8793
int fp_to_sp_delta) = 0;
94+
95+
virtual bool is_listening_to_code_events() { return false; }
8896
};
8997

9098
class CodeEventDispatcher {
@@ -101,6 +109,14 @@ class CodeEventDispatcher {
101109
base::LockGuard<base::Mutex> guard(&mutex_);
102110
listeners_.erase(listener);
103111
}
112+
bool IsListeningToCodeEvents() {
113+
for (auto it : listeners_) {
114+
if (it->is_listening_to_code_events()) {
115+
return true;
116+
}
117+
}
118+
return false;
119+
}
104120

105121
#define CODE_EVENT_DISPATCH(code) \
106122
base::LockGuard<base::Mutex> guard(&mutex_); \

‎deps/v8/src/compiler.cc

+3-2
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,9 @@ void LogFunctionCompilation(CodeEventListener::LogEventsAndTags tag,
8484
// Log the code generation. If source information is available include
8585
// script name and line number. Check explicitly whether logging is
8686
// enabled as finding the line number is not free.
87-
if (!isolate->logger()->is_logging_code_events() &&
88-
!isolate->is_profiling() && !FLAG_log_function_events) {
87+
if (!isolate->logger()->is_listening_to_code_events() &&
88+
!isolate->is_profiling() && !FLAG_log_function_events &&
89+
!isolate->code_event_dispatcher()->IsListeningToCodeEvents()) {
8990
return;
9091
}
9192

‎deps/v8/src/compiler/wasm-compiler.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -4625,7 +4625,8 @@ Node* WasmGraphBuilder::AtomicOp(wasm::WasmOpcode opcode, Node* const* inputs,
46254625

46264626
namespace {
46274627
bool must_record_function_compilation(Isolate* isolate) {
4628-
return isolate->logger()->is_logging_code_events() || isolate->is_profiling();
4628+
return isolate->logger()->is_listening_to_code_events() ||
4629+
isolate->is_profiling();
46294630
}
46304631

46314632
PRINTF_FORMAT(4, 5)

‎deps/v8/src/heap/mark-compact.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -2458,7 +2458,7 @@ void MarkCompactCollectorBase::CreateAndExecuteEvacuationTasks(
24582458

24592459
const bool profiling =
24602460
heap()->isolate()->is_profiling() ||
2461-
heap()->isolate()->logger()->is_logging_code_events() ||
2461+
heap()->isolate()->logger()->is_listening_to_code_events() ||
24622462
heap()->isolate()->heap_profiler()->is_tracking_object_moves() ||
24632463
heap()->has_heap_object_allocation_tracker();
24642464
ProfilingMigrationObserver profiling_observer(heap());

‎deps/v8/src/isolate.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -2883,7 +2883,7 @@ void CreateOffHeapTrampolines(Isolate* isolate) {
28832883
// thus collected by the GC.
28842884
builtins->set_builtin(i, *trampoline);
28852885

2886-
if (isolate->logger()->is_logging_code_events() ||
2886+
if (isolate->logger()->is_listening_to_code_events() ||
28872887
isolate->is_profiling()) {
28882888
isolate->logger()->LogCodeObject(*trampoline);
28892889
}

‎deps/v8/src/isolate.h

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class BuiltinsConstantsTableBuilder;
5656
class CallInterfaceDescriptorData;
5757
class CancelableTaskManager;
5858
class CodeEventDispatcher;
59+
class ExternalCodeEventListener;
5960
class CodeGenerator;
6061
class CodeRange;
6162
class CodeStubDescriptor;

‎deps/v8/src/log.cc

+348-162
Large diffs are not rendered by default.

‎deps/v8/src/log.h

+81-5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <set>
99
#include <string>
1010

11+
#include "include/v8-profiler.h"
1112
#include "src/allocation.h"
1213
#include "src/base/compiler-specific.h"
1314
#include "src/base/platform/elapsed-timer.h"
@@ -87,12 +88,33 @@ class WasmCode;
8788
if (logger->is_logging()) logger->Call; \
8889
} while (false)
8990

90-
#define LOG_CODE_EVENT(isolate, Call) \
91-
do { \
92-
v8::internal::Logger* logger = (isolate)->logger(); \
93-
if (logger->is_logging_code_events()) logger->Call; \
91+
#define LOG_CODE_EVENT(isolate, Call) \
92+
do { \
93+
v8::internal::Logger* logger = (isolate)->logger(); \
94+
if (logger->is_listening_to_code_events()) logger->Call; \
9495
} while (false)
9596

97+
class ExistingCodeLogger {
98+
public:
99+
explicit ExistingCodeLogger(Isolate* isolate,
100+
CodeEventListener* listener = nullptr)
101+
: isolate_(isolate), listener_(listener) {}
102+
103+
void LogCodeObjects();
104+
void LogBytecodeHandlers();
105+
106+
void LogCompiledFunctions();
107+
void LogExistingFunction(Handle<SharedFunctionInfo> shared,
108+
Handle<AbstractCode> code);
109+
void LogCodeObject(Object* object);
110+
void LogBytecodeHandler(interpreter::Bytecode bytecode,
111+
interpreter::OperandScale operand_scale, Code* code);
112+
113+
private:
114+
Isolate* isolate_;
115+
CodeEventListener* listener_;
116+
};
117+
96118
class Logger : public CodeEventListener {
97119
public:
98120
enum StartEnd { START = 0, END = 1, STAMP = 2 };
@@ -233,7 +255,7 @@ class Logger : public CodeEventListener {
233255
return is_logging_;
234256
}
235257

236-
bool is_logging_code_events() {
258+
bool is_listening_to_code_events() {
237259
return is_logging() || jit_logger_ != nullptr;
238260
}
239261

@@ -332,6 +354,8 @@ class Logger : public CodeEventListener {
332354
// 'true' between SetUp() and TearDown().
333355
bool is_initialized_;
334356

357+
ExistingCodeLogger existing_code_logger_;
358+
335359
base::ElapsedTimer timer_;
336360

337361
friend class CpuProfiler;
@@ -412,6 +436,58 @@ class CodeEventLogger : public CodeEventListener {
412436
NameBuffer* name_buffer_;
413437
};
414438

439+
struct CodeEvent {
440+
uintptr_t code_start_address;
441+
size_t code_size;
442+
Handle<String> function_name;
443+
Handle<String> script_name;
444+
int script_line;
445+
int script_column;
446+
CodeEventType code_type;
447+
const char* comment;
448+
};
449+
450+
class ExternalCodeEventListener : public CodeEventListener {
451+
public:
452+
explicit ExternalCodeEventListener(Isolate* isolate);
453+
~ExternalCodeEventListener() override;
454+
455+
void CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code,
456+
const char* comment) override;
457+
void CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code,
458+
Name* name) override;
459+
void CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code,
460+
SharedFunctionInfo* shared, Name* name) override;
461+
void CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code,
462+
SharedFunctionInfo* shared, Name* source, int line,
463+
int column) override;
464+
void CodeCreateEvent(LogEventsAndTags tag, const wasm::WasmCode* code,
465+
wasm::WasmName name) override;
466+
467+
void RegExpCodeCreateEvent(AbstractCode* code, String* source) override;
468+
void CallbackEvent(Name* name, Address entry_point) override {}
469+
void GetterCallbackEvent(Name* name, Address entry_point) override {}
470+
void SetterCallbackEvent(Name* name, Address entry_point) override {}
471+
void SharedFunctionInfoMoveEvent(Address from, Address to) override {}
472+
void CodeMoveEvent(AbstractCode* from, Address to) override {}
473+
void CodeDisableOptEvent(AbstractCode* code,
474+
SharedFunctionInfo* shared) override {}
475+
void CodeMovingGCEvent() override {}
476+
void CodeDeoptEvent(Code* code, DeoptKind kind, Address pc,
477+
int fp_to_sp_delta) override {}
478+
479+
void StartListening(CodeEventHandler* code_event_handler);
480+
void StopListening();
481+
482+
bool is_listening_to_code_events() override { return true; }
483+
484+
private:
485+
void LogExistingCode();
486+
487+
bool is_listening_;
488+
Isolate* isolate_;
489+
v8::CodeEventHandler* code_event_handler_;
490+
};
415491

416492
} // namespace internal
417493
} // namespace v8

‎deps/v8/src/runtime/runtime-function.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ RUNTIME_FUNCTION(Runtime_SetCode) {
147147
// the target_shared optimized code map.
148148
JSFunction::EnsureFeedbackVector(target);
149149

150-
if (isolate->logger()->is_logging_code_events() || isolate->is_profiling()) {
150+
if (isolate->logger()->is_listening_to_code_events() ||
151+
isolate->is_profiling()) {
151152
isolate->logger()->LogExistingFunction(
152153
source_shared, Handle<AbstractCode>(source_shared->abstract_code()));
153154
}

‎deps/v8/src/snapshot/code-serializer.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,8 @@ MaybeHandle<SharedFunctionInfo> CodeSerializer::Deserialize(
284284
PrintF("[Deserializing from %d bytes took %0.3f ms]\n", length, ms);
285285
}
286286

287-
if (isolate->logger()->is_logging_code_events() || isolate->is_profiling()) {
287+
if (isolate->logger()->is_listening_to_code_events() ||
288+
isolate->is_profiling()) {
288289
String* name = isolate->heap()->empty_string();
289290
if (result->script()->IsScript()) {
290291
Script* script = Script::cast(result->script());

‎deps/v8/src/snapshot/snapshot-common.cc

+4-2
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ Code* Snapshot::DeserializeBuiltin(Isolate* isolate, int builtin_id) {
114114
Builtins::name(builtin_id), bytes, ms);
115115
}
116116

117-
if (isolate->logger()->is_logging_code_events() || isolate->is_profiling()) {
117+
if (isolate->logger()->is_listening_to_code_events() ||
118+
isolate->is_profiling()) {
118119
isolate->logger()->LogCodeObject(code);
119120
}
120121

@@ -195,7 +196,8 @@ Code* Snapshot::DeserializeHandler(Isolate* isolate,
195196
bytes, ms);
196197
}
197198

198-
if (isolate->logger()->is_logging_code_events() || isolate->is_profiling()) {
199+
if (isolate->logger()->is_listening_to_code_events() ||
200+
isolate->is_profiling()) {
199201
isolate->logger()->LogBytecodeHandler(bytecode, operand_scale, code);
200202
}
201203

‎deps/v8/src/wasm/wasm-code-manager.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ bool WasmCode::HasTrapHandlerIndex() const { return trap_handler_index_ >= 0; }
190190
void WasmCode::ResetTrapHandlerIndex() { trap_handler_index_ = -1; }
191191

192192
bool WasmCode::ShouldBeLogged(Isolate* isolate) {
193-
return isolate->logger()->is_logging_code_events() ||
193+
return isolate->logger()->is_listening_to_code_events() ||
194194
isolate->is_profiling() || FLAG_print_wasm_code || FLAG_print_code;
195195
}
196196

‎deps/v8/test/cctest/test-log.cc

+75
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#endif // __linux__
3636

3737
#include <unordered_set>
38+
#include <vector>
3839
#include "src/api.h"
3940
#include "src/log-utils.h"
4041
#include "src/log.h"
@@ -251,6 +252,38 @@ class ScopedLoggerInitializer {
251252
DISALLOW_COPY_AND_ASSIGN(ScopedLoggerInitializer);
252253
};
253254

255+
class TestCodeEventHandler : public v8::CodeEventHandler {
256+
public:
257+
explicit TestCodeEventHandler(v8::Isolate* isolate)
258+
: v8::CodeEventHandler(isolate) {}
259+
260+
const char* FindLine(const char* prefix, const char* suffix = nullptr,
261+
const char* start = nullptr) {
262+
if (!log_.length()) return NULL;
263+
const char* c_log = log_.c_str();
264+
if (start == nullptr) start = c_log;
265+
const char* end = c_log + log_.length();
266+
return FindLogLine(start, end, prefix, suffix);
267+
}
268+
269+
void Handle(v8::CodeEvent* code_event) override {
270+
const char* code_type =
271+
v8::CodeEvent::GetCodeEventTypeName(code_event->GetCodeType());
272+
char function_name[1000];
273+
strncpy(function_name, code_type, 1000);
274+
function_name[strlen(code_type)] = ' ';
275+
code_event->GetFunctionName()->WriteUtf8(
276+
function_name + strlen(code_type) + 1, 1000);
277+
function_name[strlen(function_name) + 1] = '\0';
278+
function_name[strlen(function_name)] = '\n';
279+
280+
log_ += std::string(function_name);
281+
}
282+
283+
private:
284+
std::string log_;
285+
};
286+
254287
} // namespace
255288

256289
TEST(FindLogLine) {
@@ -801,6 +834,48 @@ TEST(LogInterpretedFramesNativeStack) {
801834
isolate->Dispose();
802835
}
803836

837+
TEST(ExternalCodeEventListener) {
838+
i::FLAG_log = false;
839+
i::FLAG_prof = false;
840+
841+
v8::Isolate::CreateParams create_params;
842+
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
843+
v8::Isolate* isolate = v8::Isolate::New(create_params);
844+
845+
{
846+
v8::HandleScope scope(isolate);
847+
v8::Isolate::Scope isolate_scope(isolate);
848+
v8::Local<v8::Context> context = v8::Context::New(isolate);
849+
context->Enter();
850+
851+
TestCodeEventHandler code_event_handler(isolate);
852+
853+
const char* source_text_before_start =
854+
"function testCodeEventListenerBeforeStart(a,b) { return a + b };"
855+
"testCodeEventListenerBeforeStart('1', 1);";
856+
CompileRun(source_text_before_start);
857+
858+
CHECK_NULL(code_event_handler.FindLine("LazyCompile",
859+
"testCodeEventListenerBeforeStart"));
860+
861+
code_event_handler.Enable();
862+
863+
CHECK_NOT_NULL(code_event_handler.FindLine(
864+
"LazyCompile", "testCodeEventListenerBeforeStart"));
865+
866+
const char* source_text_after_start =
867+
"function testCodeEventListenerAfterStart(a,b) { return a + b };"
868+
"testCodeEventListenerAfterStart('1', 1);";
869+
CompileRun(source_text_after_start);
870+
871+
CHECK_NOT_NULL(code_event_handler.FindLine(
872+
"LazyCompile", "testCodeEventListenerAfterStart"));
873+
874+
context->Exit();
875+
}
876+
isolate->Dispose();
877+
}
878+
804879
TEST(TraceMaps) {
805880
SETUP_FLAGS();
806881
i::FLAG_trace_maps = true;

0 commit comments

Comments
 (0)
Please sign in to comment.