// Log the event and add the code to the builtins array.
LOG(CodeCreateEvent("Builtin", Code::cast(code), functions[i].s_name));
builtins_[i] = code;
-#ifdef DEBUG
+#ifdef ENABLE_DISASSEMBLER
if (FLAG_print_builtin_code) {
PrintF("Builtin: %s\n", functions[i].s_name);
- code->Print();
+ Code::cast(code)->Disassemble(functions[i].s_name);
PrintF("\n");
}
#endif
LOG(CodeCreateEvent("Stub", *code, GetName()));
Counters::total_stubs_code_size.Increment(code->instruction_size());
-#ifdef DEBUG
+#ifdef ENABLE_DISASSEMBLER
if (FLAG_print_code_stubs) {
+#ifdef DEBUG
Print();
- code->Print();
+#endif
+ code->Disassemble(GetName());
PrintF("\n");
}
#endif
PrintF("\n\n");
}
PrintF("--- Code ---\n");
- code->Disassemble();
+ code->Disassemble(*flit->name()->ToCString());
}
#endif // ENABLE_DISASSEMBLER
DEFINE_bool(enable_slow_asserts, false,
"enable asserts that are slow to execute")
-// code-stubs.cc
-DEFINE_bool(print_code_stubs, false, "print code stubs")
-
// codegen-ia32.cc / codegen-arm.cc
DEFINE_bool(trace_codegen, false,
"print name of functions for which code is generated")
#define FLAG FLAG_READONLY
#endif
+// code-stubs.cc
+DEFINE_bool(print_code_stubs, false, "print code stubs")
+
// codegen-ia32.cc / codegen-arm.cc
DEFINE_bool(print_code, false, "print generated code")
DEFINE_bool(print_builtin_code, false, "print generated code for builtins")
void Code::CodePrint() {
HeapObject::PrintHeader("Code");
#ifdef ENABLE_DISASSEMBLER
- Disassemble();
+ Disassemble(NULL);
#endif
}
}
-void Code::Disassemble() {
- PrintF("kind = %s", Kind2String(kind()));
+void Code::Disassemble(const char* name) {
+ PrintF("kind = %s\n", Kind2String(kind()));
+ if ((name != NULL) && (name[0] != '\0')) {
+ PrintF("name = %s\n", name);
+ }
- PrintF("\nInstructions (size = %d)\n", instruction_size());
+ PrintF("Instructions (size = %d)\n", instruction_size());
Disassembler::Decode(NULL, this);
PrintF("\n");
// Printing
static const char* Kind2String(Kind kind);
static const char* ICState2String(InlineCacheState state);
- void Disassemble();
+ void Disassemble(const char* name);
#endif // ENABLE_DISASSEMBLER
// [instruction_size]: Size of the native instructions
// Do a tail-call of the compiled function.
__ Jump(r2);
- return GetCodeWithFlags(flags);
+ return GetCodeWithFlags(flags, "LazyCompileStub");
}
Object* CallStubCompiler::CompileCallField(Object* object,
JSObject* holder,
- int index) {
+ int index,
+ String* name) {
// ----------- S t a t e -------------
// -- lr: return address
// -----------------------------------
__ Jump(ic, RelocInfo::CODE_TARGET);
// Return the generated code.
- return GetCode(FIELD);
+ return GetCode(FIELD, name);
}
__ Jump(ic, RelocInfo::CODE_TARGET);
// Return the generated code.
- return GetCode(CONSTANT_FUNCTION);
+ String* function_name = NULL;
+ if (function->shared()->name()->IsString()) {
+ function_name = String::cast(function->shared()->name());
+ }
+ return GetCode(CONSTANT_FUNCTION, function_name);
}
__ Jump(ic, RelocInfo::CODE_TARGET);
// Return the generated code.
- return GetCode(INTERCEPTOR);
+ return GetCode(INTERCEPTOR, name);
}
__ Jump(ic, RelocInfo::CODE_TARGET);
// Return the generated code.
- return GetCode(transition == NULL ? FIELD : MAP_TRANSITION);
+ return GetCode(transition == NULL ? FIELD : MAP_TRANSITION, name);
}
__ Jump(ic, RelocInfo::CODE_TARGET);
// Return the generated code.
- return GetCode(CALLBACKS);
+ return GetCode(CALLBACKS, name);
}
__ Jump(ic, RelocInfo::CODE_TARGET);
// Return the generated code.
- return GetCode(INTERCEPTOR);
+ return GetCode(INTERCEPTOR, name);
}
Object* LoadStubCompiler::CompileLoadField(JSObject* object,
JSObject* holder,
- int index) {
+ int index,
+ String* name) {
// ----------- S t a t e -------------
// -- r2 : name
// -- lr : return address
GenerateLoadMiss(masm(), Code::LOAD_IC);
// Return the generated code.
- return GetCode(FIELD);
+ return GetCode(FIELD, name);
}
Object* LoadStubCompiler::CompileLoadCallback(JSObject* object,
JSObject* holder,
- AccessorInfo* callback) {
+ AccessorInfo* callback,
+ String* name) {
// ----------- S t a t e -------------
// -- r2 : name
// -- lr : return address
GenerateLoadMiss(masm(), Code::LOAD_IC);
// Return the generated code.
- return GetCode(CALLBACKS);
+ return GetCode(CALLBACKS, name);
}
Object* LoadStubCompiler::CompileLoadConstant(JSObject* object,
JSObject* holder,
- Object* value) {
+ Object* value,
+ String* name) {
// ----------- S t a t e -------------
// -- r2 : name
// -- lr : return address
GenerateLoadMiss(masm(), Code::LOAD_IC);
// Return the generated code.
- return GetCode(CONSTANT_FUNCTION);
+ return GetCode(CONSTANT_FUNCTION, name);
}
GenerateLoadMiss(masm(), Code::LOAD_IC);
// Return the generated code.
- return GetCode(INTERCEPTOR);
+ return GetCode(INTERCEPTOR, name);
}
__ bind(&miss);
GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC);
- return GetCode(FIELD);
+ return GetCode(FIELD, name);
}
__ bind(&miss);
GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC);
- return GetCode(CALLBACKS);
+ return GetCode(CALLBACKS, name);
}
GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC);
// Return the generated code.
- return GetCode(CONSTANT_FUNCTION);
+ return GetCode(CONSTANT_FUNCTION, name);
}
__ bind(&miss);
GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC);
- return GetCode(INTERCEPTOR);
+ return GetCode(INTERCEPTOR, name);
}
__ bind(&miss);
GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC);
- return GetCode(CALLBACKS);
+ return GetCode(CALLBACKS, name);
}
GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC);
- return GetCode(CALLBACKS);
+ return GetCode(CALLBACKS, name);
}
// -----------------------------------
GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC);
- return GetCode(CALLBACKS);
+ return GetCode(CALLBACKS, name);
}
__ Jump(ic, RelocInfo::CODE_TARGET);
// Return the generated code.
- return GetCode(transition == NULL ? FIELD : MAP_TRANSITION);
+ return GetCode(transition == NULL ? FIELD : MAP_TRANSITION, name);
}
__ lea(ecx, FieldOperand(eax, Code::kHeaderSize));
__ jmp(Operand(ecx));
- return GetCodeWithFlags(flags);
+ return GetCodeWithFlags(flags, "LazyCompileStub");
}
Object* CallStubCompiler::CompileCallField(Object* object,
JSObject* holder,
- int index) {
+ int index,
+ String* name) {
// ----------- S t a t e -------------
// -----------------------------------
Label miss;
__ jmp(ic, RelocInfo::CODE_TARGET);
// Return the generated code.
- return GetCode(FIELD);
+ return GetCode(FIELD, name);
}
__ jmp(ic, RelocInfo::CODE_TARGET);
// Return the generated code.
- return GetCode(CONSTANT_FUNCTION);
+ String* function_name = NULL;
+ if (function->shared()->name()->IsString()) {
+ function_name = String::cast(function->shared()->name());
+ }
+ return GetCode(CONSTANT_FUNCTION, function_name);
}
__ jmp(ic, RelocInfo::CODE_TARGET);
// Return the generated code.
- return GetCode(INTERCEPTOR);
+ return GetCode(INTERCEPTOR, name);
}
__ jmp(ic, RelocInfo::CODE_TARGET);
// Return the generated code.
- return GetCode(transition == NULL ? FIELD : MAP_TRANSITION);
+ return GetCode(transition == NULL ? FIELD : MAP_TRANSITION, name);
}
__ jmp(ic, RelocInfo::CODE_TARGET);
// Return the generated code.
- return GetCode(CALLBACKS);
+ return GetCode(CALLBACKS, name);
}
__ jmp(ic, RelocInfo::CODE_TARGET);
// Return the generated code.
- return GetCode(INTERCEPTOR);
+ return GetCode(INTERCEPTOR, name);
}
__ jmp(ic, RelocInfo::CODE_TARGET);
// Return the generated code.
- return GetCode(transition == NULL ? FIELD : MAP_TRANSITION);
+ return GetCode(transition == NULL ? FIELD : MAP_TRANSITION, name);
}
Object* LoadStubCompiler::CompileLoadField(JSObject* object,
JSObject* holder,
- int index) {
+ int index,
+ String* name) {
// ----------- S t a t e -------------
// -- ecx : name
// -- esp[0] : return address
GenerateLoadMiss(masm(), Code::LOAD_IC);
// Return the generated code.
- return GetCode(FIELD);
+ return GetCode(FIELD, name);
}
Object* LoadStubCompiler::CompileLoadCallback(JSObject* object,
JSObject* holder,
- AccessorInfo* callback) {
+ AccessorInfo* callback,
+ String* name) {
// ----------- S t a t e -------------
// -- ecx : name
// -- esp[0] : return address
GenerateLoadMiss(masm(), Code::LOAD_IC);
// Return the generated code.
- return GetCode(CALLBACKS);
+ return GetCode(CALLBACKS, name);
}
Object* LoadStubCompiler::CompileLoadConstant(JSObject* object,
JSObject* holder,
- Object* value) {
+ Object* value,
+ String* name) {
// ----------- S t a t e -------------
// -- ecx : name
// -- esp[0] : return address
GenerateLoadMiss(masm(), Code::LOAD_IC);
// Return the generated code.
- return GetCode(CONSTANT_FUNCTION);
+ return GetCode(CONSTANT_FUNCTION, name);
}
GenerateLoadMiss(masm(), Code::LOAD_IC);
// Return the generated code.
- return GetCode(INTERCEPTOR);
+ return GetCode(INTERCEPTOR, name);
}
GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC);
// Return the generated code.
- return GetCode(FIELD);
+ return GetCode(FIELD, name);
}
GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC);
// Return the generated code.
- return GetCode(CALLBACKS);
+ return GetCode(CALLBACKS, name);
}
GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC);
// Return the generated code.
- return GetCode(CONSTANT_FUNCTION);
+ return GetCode(CONSTANT_FUNCTION, name);
}
GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC);
// Return the generated code.
- return GetCode(INTERCEPTOR);
+ return GetCode(INTERCEPTOR, name);
}
GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC);
// Return the generated code.
- return GetCode(CALLBACKS);
+ return GetCode(CALLBACKS, name);
}
GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC);
// Return the generated code.
- return GetCode(CALLBACKS);
+ return GetCode(CALLBACKS, name);
}
GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC);
// Return the generated code.
- return GetCode(CALLBACKS);
+ return GetCode(CALLBACKS, name);
}
Object* code = receiver->map()->FindInCodeCache(name, flags);
if (code->IsUndefined()) {
LoadStubCompiler compiler;
- code = compiler.CompileLoadField(receiver, holder, field_index);
+ code = compiler.CompileLoadField(receiver, holder, field_index, name);
if (code->IsFailure()) return code;
LOG(CodeCreateEvent("LoadIC", Code::cast(code), name));
Object* result = receiver->map()->UpdateCodeCache(name, Code::cast(code));
Object* code = receiver->map()->FindInCodeCache(name, flags);
if (code->IsUndefined()) {
LoadStubCompiler compiler;
- code = compiler.CompileLoadCallback(receiver, holder, callback);
+ code = compiler.CompileLoadCallback(receiver, holder, callback, name);
if (code->IsFailure()) return code;
LOG(CodeCreateEvent("LoadIC", Code::cast(code), name));
Object* result = receiver->map()->UpdateCodeCache(name, Code::cast(code));
Object* code = receiver->map()->FindInCodeCache(name, flags);
if (code->IsUndefined()) {
LoadStubCompiler compiler;
- code = compiler.CompileLoadConstant(receiver, holder, value);
+ code = compiler.CompileLoadConstant(receiver, holder, value, name);
if (code->IsFailure()) return code;
LOG(CodeCreateEvent("LoadIC", Code::cast(code), name));
Object* result = receiver->map()->UpdateCodeCache(name, Code::cast(code));
Object* code = map->FindInCodeCache(name, flags);
if (code->IsUndefined()) {
CallStubCompiler compiler(argc);
- code = compiler.CompileCallField(object, holder, index);
+ code = compiler.CompileCallField(object, holder, index, name);
if (code->IsFailure()) return code;
LOG(CodeCreateEvent("CallIC", Code::cast(code), name));
Object* result = map->UpdateCodeCache(name, Code::cast(code));
HandleScope scope;
int argc = Code::ExtractArgumentsCountFromFlags(flags);
CallIC::GenerateInitialize(masm(), argc);
- Object* result = GetCodeWithFlags(flags);
+ Object* result = GetCodeWithFlags(flags, "CompileCallInitialize");
if (!result->IsFailure()) {
Counters::call_initialize_stubs.Increment();
Code* code = Code::cast(result);
HandleScope scope;
int argc = Code::ExtractArgumentsCountFromFlags(flags);
CallIC::GenerateInitialize(masm(), argc);
- Object* result = GetCodeWithFlags(flags);
+ Object* result = GetCodeWithFlags(flags, "CompileCallPreMonomorphic");
if (!result->IsFailure()) {
Counters::call_premonomorphic_stubs.Increment();
Code* code = Code::cast(result);
HandleScope scope;
int argc = Code::ExtractArgumentsCountFromFlags(flags);
CallIC::GenerateNormal(masm(), argc);
- Object* result = GetCodeWithFlags(flags);
+ Object* result = GetCodeWithFlags(flags, "CompileCallNormal");
if (!result->IsFailure()) {
Counters::call_normal_stubs.Increment();
Code* code = Code::cast(result);
HandleScope scope;
int argc = Code::ExtractArgumentsCountFromFlags(flags);
CallIC::GenerateMegamorphic(masm(), argc);
- Object* result = GetCodeWithFlags(flags);
+ Object* result = GetCodeWithFlags(flags, "CompileCallMegamorphic");
if (!result->IsFailure()) {
Counters::call_megamorphic_stubs.Increment();
Code* code = Code::cast(result);
HandleScope scope;
int argc = Code::ExtractArgumentsCountFromFlags(flags);
CallIC::GenerateMiss(masm(), argc);
- Object* result = GetCodeWithFlags(flags);
+ Object* result = GetCodeWithFlags(flags, "CompileCallMiss");
if (!result->IsFailure()) {
Counters::call_megamorphic_stubs.Increment();
Code* code = Code::cast(result);
Object* StubCompiler::CompileCallDebugBreak(Code::Flags flags) {
HandleScope scope;
Debug::GenerateCallICDebugBreak(masm());
- Object* result = GetCodeWithFlags(flags);
+ Object* result = GetCodeWithFlags(flags, "CompileCallDebugBreak");
if (!result->IsFailure()) {
Code* code = Code::cast(result);
USE(code);
// the miss case.
int argc = Code::ExtractArgumentsCountFromFlags(flags);
CallIC::GenerateMiss(masm(), argc);
- Object* result = GetCodeWithFlags(flags);
+ Object* result = GetCodeWithFlags(flags, "CompileCallDebugPrepareStepIn");
if (!result->IsFailure()) {
Code* code = Code::cast(result);
USE(code);
}
-Object* StubCompiler::GetCodeWithFlags(Code::Flags flags) {
+Object* StubCompiler::GetCodeWithFlags(Code::Flags flags, char* name) {
CodeDesc desc;
masm_.GetCode(&desc);
Object* result = Heap::CreateCode(desc, NULL, flags, masm_.CodeObject());
-#ifdef DEBUG
+#ifdef ENABLE_DISASSEMBLER
if (FLAG_print_code_stubs && !result->IsFailure()) {
- Code::cast(result)->Print();
+ Code::cast(result)->Disassemble(name);
}
#endif
return result;
}
-Object* LoadStubCompiler::GetCode(PropertyType type) {
- return GetCodeWithFlags(Code::ComputeMonomorphicFlags(Code::LOAD_IC, type));
+Object* StubCompiler::GetCodeWithFlags(Code::Flags flags, String* name) {
+ if (FLAG_print_code_stubs && (name != NULL)) {
+ return GetCodeWithFlags(flags, *name->ToCString());
+ }
+ return GetCodeWithFlags(flags, reinterpret_cast<char*>(NULL));
+}
+
+
+Object* LoadStubCompiler::GetCode(PropertyType type, String* name) {
+ Code::Flags flags = Code::ComputeMonomorphicFlags(Code::LOAD_IC, type);
+ return GetCodeWithFlags(flags, name);
}
-Object* KeyedLoadStubCompiler::GetCode(PropertyType type) {
- return GetCodeWithFlags(Code::ComputeMonomorphicFlags(Code::KEYED_LOAD_IC,
- type));
+Object* KeyedLoadStubCompiler::GetCode(PropertyType type, String* name) {
+ Code::Flags flags = Code::ComputeMonomorphicFlags(Code::KEYED_LOAD_IC, type);
+ return GetCodeWithFlags(flags, name);
}
-Object* StoreStubCompiler::GetCode(PropertyType type) {
- return GetCodeWithFlags(Code::ComputeMonomorphicFlags(Code::STORE_IC, type));
+Object* StoreStubCompiler::GetCode(PropertyType type, String* name) {
+ Code::Flags flags = Code::ComputeMonomorphicFlags(Code::STORE_IC, type);
+ return GetCodeWithFlags(flags, name);
}
-Object* KeyedStoreStubCompiler::GetCode(PropertyType type) {
- return GetCodeWithFlags(Code::ComputeMonomorphicFlags(Code::KEYED_STORE_IC,
- type));
+Object* KeyedStoreStubCompiler::GetCode(PropertyType type, String* name) {
+ Code::Flags flags = Code::ComputeMonomorphicFlags(Code::KEYED_STORE_IC, type);
+ return GetCodeWithFlags(flags, name);
}
-Object* CallStubCompiler::GetCode(PropertyType type) {
+Object* CallStubCompiler::GetCode(PropertyType type, String* name) {
int argc = arguments_.immediate();
Code::Flags flags = Code::ComputeMonomorphicFlags(Code::CALL_IC, type, argc);
- return GetCodeWithFlags(flags);
+ return GetCodeWithFlags(flags, name);
}
static void GenerateLoadMiss(MacroAssembler* masm, Code::Kind kind);
protected:
- Object* GetCodeWithFlags(Code::Flags flags);
+ Object* GetCodeWithFlags(Code::Flags flags, char* name);
+ Object* GetCodeWithFlags(Code::Flags flags, String* name);
MacroAssembler* masm() { return &masm_; }
class LoadStubCompiler: public StubCompiler {
public:
- Object* CompileLoadField(JSObject* object, JSObject* holder, int index);
+ Object* CompileLoadField(JSObject* object,
+ JSObject* holder,
+ int index,
+ String* name);
Object* CompileLoadCallback(JSObject* object,
JSObject* holder,
- AccessorInfo* callback);
+ AccessorInfo* callback,
+ String* name);
Object* CompileLoadConstant(JSObject* object,
JSObject* holder,
- Object* value);
+ Object* value,
+ String* name);
Object* CompileLoadInterceptor(JSObject* object,
JSObject* holder,
String* name);
private:
- Object* GetCode(PropertyType);
+ Object* GetCode(PropertyType type, String* name);
};
Object* CompileLoadFunctionPrototype(String* name);
private:
- Object* GetCode(PropertyType);
+ Object* GetCode(PropertyType type, String* name);
};
Object* CompileStoreInterceptor(JSObject* object, String* name);
private:
- Object* GetCode(PropertyType type);
+ Object* GetCode(PropertyType type, String* name);
};
String* name);
private:
- Object* GetCode(PropertyType type);
+ Object* GetCode(PropertyType type, String* name);
};
public:
explicit CallStubCompiler(int argc) : arguments_(argc) { }
- Object* CompileCallField(Object* object, JSObject* holder, int index);
+ Object* CompileCallField(Object* object,
+ JSObject* holder,
+ int index,
+ String* name);
Object* CompileCallConstant(Object* object,
JSObject* holder,
JSFunction* function,
const ParameterCount& arguments() { return arguments_; }
- Object* GetCode(PropertyType type);
+ Object* GetCode(PropertyType type, String* name);
};