// Log the event and add the code to the builtins array.
PROFILE(isolate,
CodeCreateEvent(Logger::BUILTIN_TAG, *code, functions[i].s_name));
- GDBJIT(AddCode(GDBJITInterface::BUILTIN, functions[i].s_name, *code));
builtins_[i] = *code;
#ifdef ENABLE_DISASSEMBLER
if (FLAG_print_builtin_code) {
OStringStream os;
os << *this;
PROFILE(isolate(), CodeCreateEvent(Logger::STUB_TAG, *code, os.c_str()));
- GDBJIT(AddCode(GDBJITInterface::STUB, os.c_str(), *code));
Counters* counters = isolate()->counters();
counters->total_stubs_code_size()->Increment(code->instruction_size());
}
GDBJITInterface::CodeTag tag,
Script* script,
CompilationInfo* info) {
- if (!FLAG_gdbjit) return;
-
base::LockGuard<base::Mutex> lock_guard(mutex.Pointer());
DisallowHeapAllocation no_gc;
}
-void GDBJITInterface::AddCode(GDBJITInterface::CodeTag tag,
- const char* name,
- Code* code) {
- if (!FLAG_gdbjit) return;
-
- EmbeddedVector<char, 256> buffer;
- StringBuilder builder(buffer.start(), buffer.length());
-
- builder.AddString(Tag2String(tag));
- if ((name != NULL) && (*name != '\0')) {
- builder.AddString(": ");
- builder.AddString(name);
- } else {
- builder.AddFormatted(": code object %p", static_cast<void*>(code));
- }
-
- AddCode(builder.Finalize(), code, tag, NULL, NULL);
-}
-
-
-void GDBJITInterface::AddCode(GDBJITInterface::CodeTag tag,
- Name* name,
- Code* code) {
- if (!FLAG_gdbjit) return;
- if (name != NULL && name->IsString()) {
- AddCode(tag, String::cast(name)->ToCString(DISALLOW_NULLS).get(), code);
- } else {
- AddCode(tag, "", code);
- }
-}
-
-
-void GDBJITInterface::AddCode(GDBJITInterface::CodeTag tag, Code* code) {
- if (!FLAG_gdbjit) return;
-
- AddCode(tag, "", code);
-}
-
-
void GDBJITInterface::RemoveCode(Code* code) {
if (!FLAG_gdbjit) return;
void GDBJITInterface::EventHandler(const v8::JitCodeEvent* event) {
if (!FLAG_gdbjit) return;
switch (event->type) {
- case v8::JitCodeEvent::CODE_ADDED:
+ case v8::JitCodeEvent::CODE_ADDED: {
+ Code* code = Code::GetCodeFromTargetAddress(
+ reinterpret_cast<Address>(event->code_start));
+ if (code->kind() == Code::OPTIMIZED_FUNCTION ||
+ code->kind() == Code::FUNCTION) {
+ break;
+ }
+ EmbeddedVector<char, 256> buffer;
+ StringBuilder builder(buffer.start(), buffer.length());
+ builder.AddSubstring(event->name.str, static_cast<int>(event->name.len));
+ AddCode(builder.Finalize(), code, NON_FUNCTION, NULL, NULL);
+ break;
+ }
case v8::JitCodeEvent::CODE_MOVED:
- case v8::JitCodeEvent::CODE_REMOVED:
break;
+ case v8::JitCodeEvent::CODE_REMOVED: {
+ Code* code = Code::GetCodeFromTargetAddress(
+ reinterpret_cast<Address>(event->code_start));
+ RemoveCode(code);
+ break;
+ }
case v8::JitCodeEvent::CODE_ADD_LINE_POS_INFO: {
LineInfo* line_info = reinterpret_cast<LineInfo*>(event->user_data);
line_info->SetPosition(static_cast<intptr_t>(event->line_info.offset),
class CompilationInfo;
-#define CODE_TAGS_LIST(V) \
- V(LOAD_IC) \
- V(KEYED_LOAD_IC) \
- V(STORE_IC) \
- V(KEYED_STORE_IC) \
- V(STUB) \
- V(BUILTIN) \
- V(SCRIPT) \
- V(EVAL) \
- V(FUNCTION)
-
class GDBJITInterface: public AllStatic {
public:
- enum CodeTag {
-#define V(x) x,
- CODE_TAGS_LIST(V)
-#undef V
- TAG_COUNT
- };
-
- static const char* Tag2String(CodeTag tag) {
- switch (tag) {
-#define V(x) case x: return #x;
- CODE_TAGS_LIST(V)
-#undef V
- default:
- return NULL;
- }
- }
+ enum CodeTag { NON_FUNCTION, FUNCTION };
// Main entry point into GDB JIT realized as a JitCodeEventHandler.
static void EventHandler(const v8::JitCodeEvent* event);
- static void AddCode(const char* name,
- Code* code,
- CodeTag tag,
- Script* script,
- CompilationInfo* info);
-
static void AddCode(Handle<Name> name,
Handle<Script> script,
Handle<Code> code,
CompilationInfo* info);
- static void AddCode(CodeTag tag, Name* name, Code* code);
-
- static void AddCode(CodeTag tag, const char* name, Code* code);
+ static void RemoveCodeRange(Address start, Address end);
- static void AddCode(CodeTag tag, Code* code);
+ private:
+ static void AddCode(const char* name, Code* code, CodeTag tag, Script* script,
+ CompilationInfo* info);
static void RemoveCode(Code* code);
-
- static void RemoveCodeRange(Address start, Address end);
};
#define GDBJIT(action) GDBJITInterface::action
// code objects. We should either reenable it or change our tools.
void MarkCompactCollector::ReportDeleteIfNeeded(HeapObject* obj,
Isolate* isolate) {
-#ifdef ENABLE_GDB_JIT_INTERFACE
- if (obj->IsCode()) {
- GDBJITInterface::RemoveCode(reinterpret_cast<Code*>(obj));
- }
-#endif
if (obj->IsCode()) {
PROFILE(isolate, CodeDeleteEvent(obj->address()));
}
Handle<Code> code = GetCodeWithFlags(flags, "CompileLoadInitialize");
PROFILE(isolate(),
CodeCreateEvent(Logger::LOAD_INITIALIZE_TAG, *code, 0));
- GDBJIT(AddCode(GDBJITInterface::LOAD_IC, *code));
return code;
}
Handle<Code> code = GetCodeWithFlags(flags, "CompileLoadPreMonomorphic");
PROFILE(isolate(),
CodeCreateEvent(Logger::LOAD_PREMONOMORPHIC_TAG, *code, 0));
- GDBJIT(AddCode(GDBJITInterface::LOAD_IC, *code));
return code;
}
Handle<Code> code = GetCodeWithFlags(flags, "CompileLoadMegamorphic");
PROFILE(isolate(),
CodeCreateEvent(Logger::LOAD_MEGAMORPHIC_TAG, *code, 0));
- GDBJIT(AddCode(GDBJITInterface::LOAD_IC, *code));
return code;
}
Handle<Code> code = GetCodeWithFlags(flags, "CompileStoreInitialize");
PROFILE(isolate(),
CodeCreateEvent(Logger::STORE_INITIALIZE_TAG, *code, 0));
- GDBJIT(AddCode(GDBJITInterface::STORE_IC, *code));
return code;
}
Handle<Code> code = GetCodeWithFlags(flags, "CompileStorePreMonomorphic");
PROFILE(isolate(),
CodeCreateEvent(Logger::STORE_PREMONOMORPHIC_TAG, *code, 0));
- GDBJIT(AddCode(GDBJITInterface::STORE_IC, *code));
return code;
}
Handle<Code> code = GetCodeWithFlags(flags, "CompileStoreGeneric");
PROFILE(isolate(),
CodeCreateEvent(Logger::STORE_GENERIC_TAG, *code, 0));
- GDBJIT(AddCode(GDBJITInterface::STORE_IC, *code));
return code;
}
Handle<Code> code = GetCodeWithFlags(flags, "CompileStoreMegamorphic");
PROFILE(isolate(),
CodeCreateEvent(Logger::STORE_MEGAMORPHIC_TAG, *code, 0));
- GDBJIT(AddCode(GDBJITInterface::STORE_IC, *code));
return code;
}
}
-void BaseLoadStoreStubCompiler::JitEvent(Handle<Name> name, Handle<Code> code) {
-#ifdef ENABLE_GDB_JIT_INTERFACE
- GDBJITInterface::CodeTag tag;
- if (kind_ == Code::LOAD_IC) {
- tag = GDBJITInterface::LOAD_IC;
- } else if (kind_ == Code::KEYED_LOAD_IC) {
- tag = GDBJITInterface::KEYED_LOAD_IC;
- } else if (kind_ == Code::STORE_IC) {
- tag = GDBJITInterface::STORE_IC;
- } else {
- tag = GDBJITInterface::KEYED_STORE_IC;
- }
- GDBJIT(AddCode(tag, *name, *code));
-#endif
-}
-
-
void BaseLoadStoreStubCompiler::InitializeRegisters() {
if (kind_ == Code::LOAD_IC) {
registers_ = LoadStubCompiler::registers();
Handle<Code> code = GetCodeWithFlags(flags, name);
IC::RegisterWeakMapDependency(code);
PROFILE(isolate(), CodeCreateEvent(log_kind(code), *code, *name));
- JitEvent(name, code);
return code;
}
Code::Flags flags = Code::ComputeHandlerFlags(kind, type, cache_holder_);
Handle<Code> code = GetCodeWithFlags(flags, name);
PROFILE(isolate(), CodeCreateEvent(log_kind(code), *code, *name));
- JitEvent(name, code);
return code;
}
? Logger::KEYED_STORE_IC_TAG : Logger::KEYED_STORE_POLYMORPHIC_IC_TAG;
}
}
- void JitEvent(Handle<Name> name, Handle<Code> code);
Register receiver() { return registers_[0]; }
Register name() { return registers_[1]; }