| OLD | NEW |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 | 129 |
| 130 if (Isolate::Current()->bootstrapper()->IsActive()) { | 130 if (Isolate::Current()->bootstrapper()->IsActive()) { |
| 131 print_source = FLAG_print_builtin_source; | 131 print_source = FLAG_print_builtin_source; |
| 132 print_ast = FLAG_print_builtin_ast; | 132 print_ast = FLAG_print_builtin_ast; |
| 133 print_json_ast = FLAG_print_builtin_json_ast; | 133 print_json_ast = FLAG_print_builtin_json_ast; |
| 134 ftype = "builtin"; | 134 ftype = "builtin"; |
| 135 } else { | 135 } else { |
| 136 print_source = FLAG_print_source; | 136 print_source = FLAG_print_source; |
| 137 print_ast = FLAG_print_ast; | 137 print_ast = FLAG_print_ast; |
| 138 print_json_ast = FLAG_print_json_ast; | 138 print_json_ast = FLAG_print_json_ast; |
| 139 Vector<const char> filter = CStrVector(FLAG_hydrogen_filter); |
| 140 if (print_source && !filter.is_empty()) { |
| 141 print_source = info->function()->name()->IsEqualTo(filter); |
| 142 } |
| 143 if (print_ast && !filter.is_empty()) { |
| 144 print_ast = info->function()->name()->IsEqualTo(filter); |
| 145 } |
| 146 if (print_json_ast && !filter.is_empty()) { |
| 147 print_json_ast = info->function()->name()->IsEqualTo(filter); |
| 148 } |
| 139 ftype = "user-defined"; | 149 ftype = "user-defined"; |
| 140 } | 150 } |
| 141 | 151 |
| 142 if (FLAG_trace_codegen || print_source || print_ast) { | 152 if (FLAG_trace_codegen || print_source || print_ast) { |
| 143 PrintF("*** Generate code for %s function: ", ftype); | 153 PrintF("*** Generate code for %s function: ", ftype); |
| 144 info->function()->name()->ShortPrint(); | 154 info->function()->name()->ShortPrint(); |
| 145 PrintF(" ***\n"); | 155 PrintF(" ***\n"); |
| 146 } | 156 } |
| 147 | 157 |
| 148 if (print_source) { | 158 if (print_source) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 164 | 174 |
| 165 | 175 |
| 166 Handle<Code> CodeGenerator::MakeCodeEpilogue(MacroAssembler* masm, | 176 Handle<Code> CodeGenerator::MakeCodeEpilogue(MacroAssembler* masm, |
| 167 Code::Flags flags, | 177 Code::Flags flags, |
| 168 CompilationInfo* info) { | 178 CompilationInfo* info) { |
| 169 // Allocate and install the code. | 179 // Allocate and install the code. |
| 170 CodeDesc desc; | 180 CodeDesc desc; |
| 171 masm->GetCode(&desc); | 181 masm->GetCode(&desc); |
| 172 Handle<Code> code = FACTORY->NewCode(desc, flags, masm->CodeObject()); | 182 Handle<Code> code = FACTORY->NewCode(desc, flags, masm->CodeObject()); |
| 173 | 183 |
| 184 if (!code.is_null()) { |
| 185 COUNTERS->total_compiled_code_size()->Increment(code->instruction_size()); |
| 186 } |
| 187 return code; |
| 188 } |
| 189 |
| 190 |
| 191 void CodeGenerator::PrintCode(Handle<Code> code, CompilationInfo* info) { |
| 174 #ifdef ENABLE_DISASSEMBLER | 192 #ifdef ENABLE_DISASSEMBLER |
| 175 bool print_code = Isolate::Current()->bootstrapper()->IsActive() | 193 bool print_code = Isolate::Current()->bootstrapper()->IsActive() |
| 176 ? FLAG_print_builtin_code | 194 ? FLAG_print_builtin_code |
| 177 : FLAG_print_code; | 195 : (FLAG_print_code || (info->IsOptimizing() && FLAG_print_opt_code)); |
| 178 if (print_code) { | 196 Vector<const char> filter = CStrVector(FLAG_hydrogen_filter); |
| 197 FunctionLiteral* function = info->function(); |
| 198 bool match = filter.is_empty() || function->debug_name()->IsEqualTo(filter); |
| 199 if (print_code && match) { |
| 179 // Print the source code if available. | 200 // Print the source code if available. |
| 180 Handle<Script> script = info->script(); | 201 Handle<Script> script = info->script(); |
| 181 FunctionLiteral* function = info->function(); | |
| 182 if (!script->IsUndefined() && !script->source()->IsUndefined()) { | 202 if (!script->IsUndefined() && !script->source()->IsUndefined()) { |
| 183 PrintF("--- Raw source ---\n"); | 203 PrintF("--- Raw source ---\n"); |
| 184 StringInputBuffer stream(String::cast(script->source())); | 204 StringInputBuffer stream(String::cast(script->source())); |
| 185 stream.Seek(function->start_position()); | 205 stream.Seek(function->start_position()); |
| 186 // fun->end_position() points to the last character in the stream. We | 206 // fun->end_position() points to the last character in the stream. We |
| 187 // need to compensate by adding one to calculate the length. | 207 // need to compensate by adding one to calculate the length. |
| 188 int source_len = | 208 int source_len = |
| 189 function->end_position() - function->start_position() + 1; | 209 function->end_position() - function->start_position() + 1; |
| 190 for (int i = 0; i < source_len; i++) { | 210 for (int i = 0; i < source_len; i++) { |
| 191 if (stream.has_more()) PrintF("%c", stream.GetNext()); | 211 if (stream.has_more()) PrintF("%c", stream.GetNext()); |
| 192 } | 212 } |
| 193 PrintF("\n\n"); | 213 PrintF("\n\n"); |
| 194 } | 214 } |
| 195 PrintF("--- Code ---\n"); | 215 PrintF("--- Code ---\n"); |
| 196 code->Disassemble(*function->name()->ToCString()); | 216 code->Disassemble(*function->name()->ToCString()); |
| 197 } | 217 } |
| 198 #endif // ENABLE_DISASSEMBLER | 218 #endif // ENABLE_DISASSEMBLER |
| 199 | |
| 200 if (!code.is_null()) { | |
| 201 COUNTERS->total_compiled_code_size()->Increment(code->instruction_size()); | |
| 202 } | |
| 203 return code; | |
| 204 } | 219 } |
| 205 | 220 |
| 206 | 221 |
| 207 // Generate the code. Compile the AST and assemble all the pieces into a | 222 // Generate the code. Compile the AST and assemble all the pieces into a |
| 208 // Code object. | 223 // Code object. |
| 209 bool CodeGenerator::MakeCode(CompilationInfo* info) { | 224 bool CodeGenerator::MakeCode(CompilationInfo* info) { |
| 225 // When using Crankshaft the classic backend should never be used. |
| 226 ASSERT(!V8::UseCrankshaft()); |
| 210 Handle<Script> script = info->script(); | 227 Handle<Script> script = info->script(); |
| 211 if (!script->IsUndefined() && !script->source()->IsUndefined()) { | 228 if (!script->IsUndefined() && !script->source()->IsUndefined()) { |
| 212 int len = String::cast(script->source())->length(); | 229 int len = String::cast(script->source())->length(); |
| 213 COUNTERS->total_old_codegen_source_size()->Increment(len); | 230 COUNTERS->total_old_codegen_source_size()->Increment(len); |
| 214 } | 231 } |
| 232 if (FLAG_trace_codegen) { |
| 233 PrintF("Classic Compiler - "); |
| 234 } |
| 215 MakeCodePrologue(info); | 235 MakeCodePrologue(info); |
| 216 // Generate code. | 236 // Generate code. |
| 217 const int kInitialBufferSize = 4 * KB; | 237 const int kInitialBufferSize = 4 * KB; |
| 218 MacroAssembler masm(NULL, kInitialBufferSize); | 238 MacroAssembler masm(NULL, kInitialBufferSize); |
| 219 CodeGenerator cgen(&masm); | 239 CodeGenerator cgen(&masm); |
| 220 CodeGeneratorScope scope(Isolate::Current(), &cgen); | 240 CodeGeneratorScope scope(Isolate::Current(), &cgen); |
| 221 cgen.Generate(info); | 241 cgen.Generate(info); |
| 222 if (cgen.HasStackOverflow()) { | 242 if (cgen.HasStackOverflow()) { |
| 223 ASSERT(!Isolate::Current()->has_pending_exception()); | 243 ASSERT(!Isolate::Current()->has_pending_exception()); |
| 224 return false; | 244 return false; |
| 225 } | 245 } |
| 226 | 246 |
| 227 InLoopFlag in_loop = info->is_in_loop() ? IN_LOOP : NOT_IN_LOOP; | 247 InLoopFlag in_loop = info->is_in_loop() ? IN_LOOP : NOT_IN_LOOP; |
| 228 Code::Flags flags = Code::ComputeFlags(Code::FUNCTION, in_loop); | 248 Code::Flags flags = Code::ComputeFlags(Code::FUNCTION, in_loop); |
| 229 Handle<Code> code = MakeCodeEpilogue(cgen.masm(), flags, info); | 249 Handle<Code> code = MakeCodeEpilogue(cgen.masm(), flags, info); |
| 250 // There is no stack check table in code generated by the classic backend. |
| 251 code->SetNoStackCheckTable(); |
| 252 CodeGenerator::PrintCode(code, info); |
| 230 info->SetCode(code); // May be an empty handle. | 253 info->SetCode(code); // May be an empty handle. |
| 231 return !code.is_null(); | 254 return !code.is_null(); |
| 232 } | 255 } |
| 233 | 256 |
| 234 | 257 |
| 235 #ifdef ENABLE_LOGGING_AND_PROFILING | 258 #ifdef ENABLE_LOGGING_AND_PROFILING |
| 236 | 259 |
| 237 | 260 |
| 238 static Vector<const char> kRegexp = CStrVector("regexp"); | 261 static Vector<const char> kRegexp = CStrVector("regexp"); |
| 239 | 262 |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 void ArgumentsAccessStub::Generate(MacroAssembler* masm) { | 457 void ArgumentsAccessStub::Generate(MacroAssembler* masm) { |
| 435 switch (type_) { | 458 switch (type_) { |
| 436 case READ_ELEMENT: GenerateReadElement(masm); break; | 459 case READ_ELEMENT: GenerateReadElement(masm); break; |
| 437 case NEW_OBJECT: GenerateNewObject(masm); break; | 460 case NEW_OBJECT: GenerateNewObject(masm); break; |
| 438 } | 461 } |
| 439 } | 462 } |
| 440 | 463 |
| 441 | 464 |
| 442 int CEntryStub::MinorKey() { | 465 int CEntryStub::MinorKey() { |
| 443 ASSERT(result_size_ == 1 || result_size_ == 2); | 466 ASSERT(result_size_ == 1 || result_size_ == 2); |
| 467 int result = save_doubles_ ? 1 : 0; |
| 444 #ifdef _WIN64 | 468 #ifdef _WIN64 |
| 445 return result_size_ == 1 ? 0 : 1; | 469 return result | ((result_size_ == 1) ? 0 : 2); |
| 446 #else | 470 #else |
| 447 return 0; | 471 return result; |
| 448 #endif | 472 #endif |
| 449 } | 473 } |
| 450 | 474 |
| 451 | 475 |
| 452 } } // namespace v8::internal | 476 } } // namespace v8::internal |
| OLD | NEW |