| OLD | NEW |
| 1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #include "v8.h" | 28 #include "v8.h" |
| 29 | 29 |
| 30 #include "bootstrapper.h" | 30 #include "bootstrapper.h" |
| 31 #include "codegen-inl.h" | 31 #include "codegen-inl.h" |
| 32 #include "compiler.h" | 32 #include "compiler.h" |
| 33 #include "debug.h" | 33 #include "debug.h" |
| 34 #include "liveedit.h" |
| 34 #include "oprofile-agent.h" | 35 #include "oprofile-agent.h" |
| 35 #include "prettyprinter.h" | 36 #include "prettyprinter.h" |
| 36 #include "register-allocator-inl.h" | 37 #include "register-allocator-inl.h" |
| 37 #include "rewriter.h" | 38 #include "rewriter.h" |
| 38 #include "runtime.h" | 39 #include "runtime.h" |
| 39 #include "scopeinfo.h" | 40 #include "scopeinfo.h" |
| 40 #include "stub-cache.h" | 41 #include "stub-cache.h" |
| 41 | 42 |
| 42 namespace v8 { | 43 namespace v8 { |
| 43 namespace internal { | 44 namespace internal { |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 Handle<Code> CodeGenerator::MakeCodeEpilogue(MacroAssembler* masm, | 191 Handle<Code> CodeGenerator::MakeCodeEpilogue(MacroAssembler* masm, |
| 191 Code::Flags flags, | 192 Code::Flags flags, |
| 192 CompilationInfo* info) { | 193 CompilationInfo* info) { |
| 193 // Allocate and install the code. | 194 // Allocate and install the code. |
| 194 CodeDesc desc; | 195 CodeDesc desc; |
| 195 masm->GetCode(&desc); | 196 masm->GetCode(&desc); |
| 196 ZoneScopeInfo sinfo(info->scope()); | 197 ZoneScopeInfo sinfo(info->scope()); |
| 197 Handle<Code> code = | 198 Handle<Code> code = |
| 198 Factory::NewCode(desc, &sinfo, flags, masm->CodeObject()); | 199 Factory::NewCode(desc, &sinfo, flags, masm->CodeObject()); |
| 199 | 200 |
| 200 // Add unresolved entries in the code to the fixup list. | |
| 201 Bootstrapper::AddFixup(*code, masm); | |
| 202 | |
| 203 #ifdef ENABLE_DISASSEMBLER | 201 #ifdef ENABLE_DISASSEMBLER |
| 204 bool print_code = Bootstrapper::IsActive() | 202 bool print_code = Bootstrapper::IsActive() |
| 205 ? FLAG_print_builtin_code | 203 ? FLAG_print_builtin_code |
| 206 : FLAG_print_code; | 204 : FLAG_print_code; |
| 207 if (print_code) { | 205 if (print_code) { |
| 208 // Print the source code if available. | 206 // Print the source code if available. |
| 209 Handle<Script> script = info->script(); | 207 Handle<Script> script = info->script(); |
| 210 FunctionLiteral* function = info->function(); | 208 FunctionLiteral* function = info->function(); |
| 211 if (!script->IsUndefined() && !script->source()->IsUndefined()) { | 209 if (!script->IsUndefined() && !script->source()->IsUndefined()) { |
| 212 PrintF("--- Raw source ---\n"); | 210 PrintF("--- Raw source ---\n"); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 230 Counters::total_compiled_code_size.Increment(code->instruction_size()); | 228 Counters::total_compiled_code_size.Increment(code->instruction_size()); |
| 231 } | 229 } |
| 232 return code; | 230 return code; |
| 233 } | 231 } |
| 234 | 232 |
| 235 | 233 |
| 236 // Generate the code. Takes a function literal, generates code for it, assemble | 234 // Generate the code. Takes a function literal, generates code for it, assemble |
| 237 // all the pieces into a Code object. This function is only to be called by | 235 // all the pieces into a Code object. This function is only to be called by |
| 238 // the compiler.cc code. | 236 // the compiler.cc code. |
| 239 Handle<Code> CodeGenerator::MakeCode(CompilationInfo* info) { | 237 Handle<Code> CodeGenerator::MakeCode(CompilationInfo* info) { |
| 238 LiveEditFunctionTracker live_edit_tracker(info->function()); |
| 240 Handle<Script> script = info->script(); | 239 Handle<Script> script = info->script(); |
| 241 if (!script->IsUndefined() && !script->source()->IsUndefined()) { | 240 if (!script->IsUndefined() && !script->source()->IsUndefined()) { |
| 242 int len = String::cast(script->source())->length(); | 241 int len = String::cast(script->source())->length(); |
| 243 Counters::total_old_codegen_source_size.Increment(len); | 242 Counters::total_old_codegen_source_size.Increment(len); |
| 244 } | 243 } |
| 245 MakeCodePrologue(info); | 244 MakeCodePrologue(info); |
| 246 // Generate code. | 245 // Generate code. |
| 247 const int kInitialBufferSize = 4 * KB; | 246 const int kInitialBufferSize = 4 * KB; |
| 248 MacroAssembler masm(NULL, kInitialBufferSize); | 247 MacroAssembler masm(NULL, kInitialBufferSize); |
| 249 CodeGenerator cgen(&masm); | 248 CodeGenerator cgen(&masm); |
| 250 CodeGeneratorScope scope(&cgen); | 249 CodeGeneratorScope scope(&cgen); |
| 251 cgen.Generate(info, PRIMARY); | 250 live_edit_tracker.RecordFunctionScope(info->function()->scope()); |
| 251 cgen.Generate(info); |
| 252 if (cgen.HasStackOverflow()) { | 252 if (cgen.HasStackOverflow()) { |
| 253 ASSERT(!Top::has_pending_exception()); | 253 ASSERT(!Top::has_pending_exception()); |
| 254 return Handle<Code>::null(); | 254 return Handle<Code>::null(); |
| 255 } | 255 } |
| 256 | 256 |
| 257 InLoopFlag in_loop = (cgen.loop_nesting() != 0) ? IN_LOOP : NOT_IN_LOOP; | 257 InLoopFlag in_loop = (cgen.loop_nesting() != 0) ? IN_LOOP : NOT_IN_LOOP; |
| 258 Code::Flags flags = Code::ComputeFlags(Code::FUNCTION, in_loop); | 258 Code::Flags flags = Code::ComputeFlags(Code::FUNCTION, in_loop); |
| 259 return MakeCodeEpilogue(cgen.masm(), flags, info); | 259 Handle<Code> result = MakeCodeEpilogue(cgen.masm(), flags, info); |
| 260 live_edit_tracker.RecordFunctionCode(result); |
| 261 return result; |
| 260 } | 262 } |
| 261 | 263 |
| 262 | 264 |
| 263 #ifdef ENABLE_LOGGING_AND_PROFILING | 265 #ifdef ENABLE_LOGGING_AND_PROFILING |
| 264 | 266 |
| 265 bool CodeGenerator::ShouldGenerateLog(Expression* type) { | 267 bool CodeGenerator::ShouldGenerateLog(Expression* type) { |
| 266 ASSERT(type != NULL); | 268 ASSERT(type != NULL); |
| 267 if (!Logger::is_logging()) return false; | 269 if (!Logger::is_logging()) return false; |
| 268 Handle<String> name = Handle<String>::cast(type->AsLiteral()->handle()); | 270 Handle<String> name = Handle<String>::cast(type->AsLiteral()->handle()); |
| 269 if (FLAG_log_regexp) { | 271 if (FLAG_log_regexp) { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 | 353 |
| 352 // Special cases: These 'runtime calls' manipulate the current | 354 // Special cases: These 'runtime calls' manipulate the current |
| 353 // frame and are only used 1 or two places, so we generate them | 355 // frame and are only used 1 or two places, so we generate them |
| 354 // inline instead of generating calls to them. They are used | 356 // inline instead of generating calls to them. They are used |
| 355 // for implementing Function.prototype.call() and | 357 // for implementing Function.prototype.call() and |
| 356 // Function.prototype.apply(). | 358 // Function.prototype.apply(). |
| 357 CodeGenerator::InlineRuntimeLUT CodeGenerator::kInlineRuntimeLUT[] = { | 359 CodeGenerator::InlineRuntimeLUT CodeGenerator::kInlineRuntimeLUT[] = { |
| 358 {&CodeGenerator::GenerateIsSmi, "_IsSmi"}, | 360 {&CodeGenerator::GenerateIsSmi, "_IsSmi"}, |
| 359 {&CodeGenerator::GenerateIsNonNegativeSmi, "_IsNonNegativeSmi"}, | 361 {&CodeGenerator::GenerateIsNonNegativeSmi, "_IsNonNegativeSmi"}, |
| 360 {&CodeGenerator::GenerateIsArray, "_IsArray"}, | 362 {&CodeGenerator::GenerateIsArray, "_IsArray"}, |
| 363 {&CodeGenerator::GenerateIsRegExp, "_IsRegExp"}, |
| 361 {&CodeGenerator::GenerateIsConstructCall, "_IsConstructCall"}, | 364 {&CodeGenerator::GenerateIsConstructCall, "_IsConstructCall"}, |
| 362 {&CodeGenerator::GenerateArgumentsLength, "_ArgumentsLength"}, | 365 {&CodeGenerator::GenerateArgumentsLength, "_ArgumentsLength"}, |
| 363 {&CodeGenerator::GenerateArgumentsAccess, "_Arguments"}, | 366 {&CodeGenerator::GenerateArgumentsAccess, "_Arguments"}, |
| 364 {&CodeGenerator::GenerateClassOf, "_ClassOf"}, | 367 {&CodeGenerator::GenerateClassOf, "_ClassOf"}, |
| 365 {&CodeGenerator::GenerateValueOf, "_ValueOf"}, | 368 {&CodeGenerator::GenerateValueOf, "_ValueOf"}, |
| 366 {&CodeGenerator::GenerateSetValueOf, "_SetValueOf"}, | 369 {&CodeGenerator::GenerateSetValueOf, "_SetValueOf"}, |
| 367 {&CodeGenerator::GenerateFastCharCodeAt, "_FastCharCodeAt"}, | 370 {&CodeGenerator::GenerateFastCharCodeAt, "_FastCharCodeAt"}, |
| 368 {&CodeGenerator::GenerateObjectEquals, "_ObjectEquals"}, | 371 {&CodeGenerator::GenerateObjectEquals, "_ObjectEquals"}, |
| 369 {&CodeGenerator::GenerateLog, "_Log"}, | 372 {&CodeGenerator::GenerateLog, "_Log"}, |
| 370 {&CodeGenerator::GenerateRandomPositiveSmi, "_RandomPositiveSmi"}, | 373 {&CodeGenerator::GenerateRandomPositiveSmi, "_RandomPositiveSmi"}, |
| 371 {&CodeGenerator::GenerateIsObject, "_IsObject"}, | 374 {&CodeGenerator::GenerateIsObject, "_IsObject"}, |
| 372 {&CodeGenerator::GenerateIsFunction, "_IsFunction"}, | 375 {&CodeGenerator::GenerateIsFunction, "_IsFunction"}, |
| 373 {&CodeGenerator::GenerateIsUndetectableObject, "_IsUndetectableObject"}, | 376 {&CodeGenerator::GenerateIsUndetectableObject, "_IsUndetectableObject"}, |
| 374 {&CodeGenerator::GenerateStringAdd, "_StringAdd"}, | 377 {&CodeGenerator::GenerateStringAdd, "_StringAdd"}, |
| 375 {&CodeGenerator::GenerateSubString, "_SubString"}, | 378 {&CodeGenerator::GenerateSubString, "_SubString"}, |
| 376 {&CodeGenerator::GenerateStringCompare, "_StringCompare"}, | 379 {&CodeGenerator::GenerateStringCompare, "_StringCompare"}, |
| 377 {&CodeGenerator::GenerateRegExpExec, "_RegExpExec"}, | 380 {&CodeGenerator::GenerateRegExpExec, "_RegExpExec"}, |
| 381 {&CodeGenerator::GenerateNumberToString, "_NumberToString"}, |
| 382 {&CodeGenerator::GenerateMathSin, "_Math_sin"}, |
| 383 {&CodeGenerator::GenerateMathCos, "_Math_cos"}, |
| 378 }; | 384 }; |
| 379 | 385 |
| 380 | 386 |
| 381 CodeGenerator::InlineRuntimeLUT* CodeGenerator::FindInlineRuntimeLUT( | 387 CodeGenerator::InlineRuntimeLUT* CodeGenerator::FindInlineRuntimeLUT( |
| 382 Handle<String> name) { | 388 Handle<String> name) { |
| 383 const int entries_count = | 389 const int entries_count = |
| 384 sizeof(kInlineRuntimeLUT) / sizeof(InlineRuntimeLUT); | 390 sizeof(kInlineRuntimeLUT) / sizeof(InlineRuntimeLUT); |
| 385 for (int i = 0; i < entries_count; i++) { | 391 for (int i = 0; i < entries_count; i++) { |
| 386 InlineRuntimeLUT* entry = &kInlineRuntimeLUT[i]; | 392 InlineRuntimeLUT* entry = &kInlineRuntimeLUT[i]; |
| 387 if (name->IsEqualTo(CStrVector(entry->name))) { | 393 if (name->IsEqualTo(CStrVector(entry->name))) { |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 *code_out = Code::cast(cache); | 524 *code_out = Code::cast(cache); |
| 519 return true; | 525 return true; |
| 520 } | 526 } |
| 521 } | 527 } |
| 522 | 528 |
| 523 | 529 |
| 524 void ApiGetterEntryStub::SetCustomCache(Code* value) { | 530 void ApiGetterEntryStub::SetCustomCache(Code* value) { |
| 525 info()->set_load_stub_cache(value); | 531 info()->set_load_stub_cache(value); |
| 526 } | 532 } |
| 527 | 533 |
| 528 #ifdef ENABLE_DEBUGGER_SUPPORT | |
| 529 void DebuggerStatementStub::Generate(MacroAssembler* masm) { | |
| 530 Runtime::Function* f = Runtime::FunctionForId(Runtime::kDebugBreak); | |
| 531 masm->TailCallRuntime(ExternalReference(f), 0, f->result_size); | |
| 532 } | |
| 533 #endif | |
| 534 | |
| 535 | 534 |
| 536 } } // namespace v8::internal | 535 } } // namespace v8::internal |
| OLD | NEW |