| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 } | 54 } |
| 55 | 55 |
| 56 | 56 |
| 57 class CodeStubGraphBuilderBase : public HGraphBuilder { | 57 class CodeStubGraphBuilderBase : public HGraphBuilder { |
| 58 public: | 58 public: |
| 59 CodeStubGraphBuilderBase(Isolate* isolate, HydrogenCodeStub* stub) | 59 CodeStubGraphBuilderBase(Isolate* isolate, HydrogenCodeStub* stub) |
| 60 : HGraphBuilder(&info_), | 60 : HGraphBuilder(&info_), |
| 61 arguments_length_(NULL), | 61 arguments_length_(NULL), |
| 62 info_(stub, isolate), | 62 info_(stub, isolate), |
| 63 context_(NULL) { | 63 context_(NULL) { |
| 64 int major_key = stub->MajorKey(); | 64 descriptor_ = stub->GetInterfaceDescriptor(isolate); |
| 65 descriptor_ = isolate->code_stub_interface_descriptor(major_key); | |
| 66 if (descriptor_->register_param_count_ < 0) { | |
| 67 stub->InitializeInterfaceDescriptor(isolate, descriptor_); | |
| 68 } | |
| 69 parameters_.Reset(new HParameter*[descriptor_->register_param_count_]); | 65 parameters_.Reset(new HParameter*[descriptor_->register_param_count_]); |
| 70 } | 66 } |
| 71 virtual bool BuildGraph(); | 67 virtual bool BuildGraph(); |
| 72 | 68 |
| 73 protected: | 69 protected: |
| 74 virtual HValue* BuildCodeStub() = 0; | 70 virtual HValue* BuildCodeStub() = 0; |
| 75 HParameter* GetParameter(int parameter) { | 71 HParameter* GetParameter(int parameter) { |
| 76 ASSERT(parameter < descriptor_->register_param_count_); | 72 ASSERT(parameter < descriptor_->register_param_count_); |
| 77 return parameters_[parameter]; | 73 return parameters_[parameter]; |
| 78 } | 74 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 89 private: | 85 private: |
| 90 SmartArrayPointer<HParameter*> parameters_; | 86 SmartArrayPointer<HParameter*> parameters_; |
| 91 HValue* arguments_length_; | 87 HValue* arguments_length_; |
| 92 CompilationInfoWithZone info_; | 88 CompilationInfoWithZone info_; |
| 93 CodeStubInterfaceDescriptor* descriptor_; | 89 CodeStubInterfaceDescriptor* descriptor_; |
| 94 HContext* context_; | 90 HContext* context_; |
| 95 }; | 91 }; |
| 96 | 92 |
| 97 | 93 |
| 98 bool CodeStubGraphBuilderBase::BuildGraph() { | 94 bool CodeStubGraphBuilderBase::BuildGraph() { |
| 95 // Update the static counter each time a new code stub is generated. |
| 96 isolate()->counters()->code_stubs()->Increment(); |
| 97 |
| 99 if (FLAG_trace_hydrogen) { | 98 if (FLAG_trace_hydrogen) { |
| 100 const char* name = CodeStub::MajorName(stub()->MajorKey(), false); | 99 const char* name = CodeStub::MajorName(stub()->MajorKey(), false); |
| 101 PrintF("-----------------------------------------------------------\n"); | 100 PrintF("-----------------------------------------------------------\n"); |
| 102 PrintF("Compiling stub %s using hydrogen\n", name); | 101 PrintF("Compiling stub %s using hydrogen\n", name); |
| 103 isolate()->GetHTracer()->TraceCompilation(&info_); | 102 isolate()->GetHTracer()->TraceCompilation(&info_); |
| 104 } | 103 } |
| 105 | 104 |
| 106 Zone* zone = this->zone(); | 105 Zone* zone = this->zone(); |
| 107 int param_count = descriptor_->register_param_count_; | 106 int param_count = descriptor_->register_param_count_; |
| 108 HEnvironment* start_environment = graph()->start_environment(); | 107 HEnvironment* start_environment = graph()->start_environment(); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 } | 168 } |
| 170 | 169 |
| 171 | 170 |
| 172 template <class Stub> | 171 template <class Stub> |
| 173 class CodeStubGraphBuilder: public CodeStubGraphBuilderBase { | 172 class CodeStubGraphBuilder: public CodeStubGraphBuilderBase { |
| 174 public: | 173 public: |
| 175 explicit CodeStubGraphBuilder(Stub* stub) | 174 explicit CodeStubGraphBuilder(Stub* stub) |
| 176 : CodeStubGraphBuilderBase(Isolate::Current(), stub) {} | 175 : CodeStubGraphBuilderBase(Isolate::Current(), stub) {} |
| 177 | 176 |
| 178 protected: | 177 protected: |
| 179 virtual HValue* BuildCodeStub(); | 178 virtual HValue* BuildCodeStub() { |
| 179 if (casted_stub()->IsMiss()) { |
| 180 return BuildCodeInitializedStub(); |
| 181 } else { |
| 182 return BuildCodeUninitializedStub(); |
| 183 } |
| 184 } |
| 185 |
| 186 virtual HValue* BuildCodeInitializedStub() { |
| 187 UNIMPLEMENTED(); |
| 188 return NULL; |
| 189 } |
| 190 |
| 191 virtual HValue* BuildCodeUninitializedStub() { |
| 192 // Force a deopt that falls back to the runtime. |
| 193 HValue* undefined = graph()->GetConstantUndefined(); |
| 194 CheckBuilder builder(this); |
| 195 builder.CheckNotUndefined(undefined); |
| 196 builder.End(); |
| 197 return undefined; |
| 198 } |
| 199 |
| 180 Stub* casted_stub() { return static_cast<Stub*>(stub()); } | 200 Stub* casted_stub() { return static_cast<Stub*>(stub()); } |
| 181 }; | 201 }; |
| 182 | 202 |
| 183 | 203 |
| 184 template <class Stub> | 204 Handle<Code> HydrogenCodeStub::GenerateLightweightMissCode(Isolate* isolate) { |
| 185 static Handle<Code> DoGenerateCode(Stub* stub) { | 205 Factory* factory = isolate->factory(); |
| 186 CodeStubGraphBuilder<Stub> builder(stub); | 206 |
| 187 LChunk* chunk = OptimizeGraph(builder.CreateGraph()); | 207 // Generate the new code. |
| 188 return chunk->Codegen(); | 208 MacroAssembler masm(isolate, NULL, 256); |
| 209 |
| 210 { |
| 211 // Update the static counter each time a new code stub is generated. |
| 212 isolate->counters()->code_stubs()->Increment(); |
| 213 |
| 214 // Nested stubs are not allowed for leaves. |
| 215 AllowStubCallsScope allow_scope(&masm, false); |
| 216 |
| 217 // Generate the code for the stub. |
| 218 masm.set_generating_stub(true); |
| 219 NoCurrentFrameScope scope(&masm); |
| 220 GenerateLightweightMiss(&masm); |
| 221 } |
| 222 |
| 223 // Create the code object. |
| 224 CodeDesc desc; |
| 225 masm.GetCode(&desc); |
| 226 |
| 227 // Copy the generated code into a heap object. |
| 228 Code::Flags flags = Code::ComputeFlags( |
| 229 GetCodeKind(), |
| 230 GetICState(), |
| 231 GetExtraICState(), |
| 232 GetStubType(), -1); |
| 233 Handle<Code> new_object = factory->NewCode( |
| 234 desc, flags, masm.CodeObject(), NeedsImmovableCode()); |
| 235 return new_object; |
| 189 } | 236 } |
| 190 | 237 |
| 191 | 238 |
| 239 template <class Stub> |
| 240 static Handle<Code> DoGenerateCode(Stub* stub) { |
| 241 Isolate* isolate = Isolate::Current(); |
| 242 CodeStub::Major major_key = |
| 243 static_cast<HydrogenCodeStub*>(stub)->MajorKey(); |
| 244 CodeStubInterfaceDescriptor* descriptor = |
| 245 isolate->code_stub_interface_descriptor(major_key); |
| 246 if (descriptor->register_param_count_ < 0) { |
| 247 stub->InitializeInterfaceDescriptor(isolate, descriptor); |
| 248 } |
| 249 // The miss case without stack parameters can use a light-weight stub to enter |
| 250 // the runtime that is significantly faster than using the standard |
| 251 // stub-failure deopt mechanism. |
| 252 if (stub->IsMiss() && descriptor->stack_parameter_count_ == NULL) { |
| 253 return stub->GenerateLightweightMissCode(isolate); |
| 254 } else { |
| 255 CodeStubGraphBuilder<Stub> builder(stub); |
| 256 LChunk* chunk = OptimizeGraph(builder.CreateGraph()); |
| 257 return chunk->Codegen(); |
| 258 } |
| 259 } |
| 260 |
| 261 |
| 192 template <> | 262 template <> |
| 193 HValue* CodeStubGraphBuilder<FastCloneShallowArrayStub>::BuildCodeStub() { | 263 HValue* CodeStubGraphBuilder<FastCloneShallowArrayStub>::BuildCodeStub() { |
| 194 Zone* zone = this->zone(); | 264 Zone* zone = this->zone(); |
| 195 Factory* factory = isolate()->factory(); | 265 Factory* factory = isolate()->factory(); |
| 196 AllocationSiteMode alloc_site_mode = casted_stub()->allocation_site_mode(); | 266 AllocationSiteMode alloc_site_mode = casted_stub()->allocation_site_mode(); |
| 197 FastCloneShallowArrayStub::Mode mode = casted_stub()->mode(); | 267 FastCloneShallowArrayStub::Mode mode = casted_stub()->mode(); |
| 198 int length = casted_stub()->length(); | 268 int length = casted_stub()->length(); |
| 199 | 269 |
| 200 HInstruction* boilerplate = | 270 HInstruction* boilerplate = |
| 201 AddInstruction(new(zone) HLoadKeyed(GetParameter(0), | 271 AddInstruction(new(zone) HLoadKeyed(GetParameter(0), |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 alloc_site_mode, | 311 alloc_site_mode, |
| 242 elements_kind, | 312 elements_kind, |
| 243 length)); | 313 length)); |
| 244 } | 314 } |
| 245 | 315 |
| 246 return environment()->Pop(); | 316 return environment()->Pop(); |
| 247 } | 317 } |
| 248 | 318 |
| 249 | 319 |
| 250 Handle<Code> FastCloneShallowArrayStub::GenerateCode() { | 320 Handle<Code> FastCloneShallowArrayStub::GenerateCode() { |
| 251 CodeStubGraphBuilder<FastCloneShallowArrayStub> builder(this); | 321 return DoGenerateCode(this); |
| 252 LChunk* chunk = OptimizeGraph(builder.CreateGraph()); | |
| 253 return chunk->Codegen(); | |
| 254 } | 322 } |
| 255 | 323 |
| 256 | 324 |
| 257 template <> | 325 template <> |
| 258 HValue* CodeStubGraphBuilder<FastCloneShallowObjectStub>::BuildCodeStub() { | 326 HValue* CodeStubGraphBuilder<FastCloneShallowObjectStub>::BuildCodeStub() { |
| 259 Zone* zone = this->zone(); | 327 Zone* zone = this->zone(); |
| 260 Factory* factory = isolate()->factory(); | 328 Factory* factory = isolate()->factory(); |
| 261 | 329 |
| 262 HInstruction* boilerplate = | 330 HInstruction* boilerplate = |
| 263 AddInstruction(new(zone) HLoadKeyed(GetParameter(0), | 331 AddInstruction(new(zone) HLoadKeyed(GetParameter(0), |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 current_block()->MarkAsDeoptimizing(); | 503 current_block()->MarkAsDeoptimizing(); |
| 436 return GetParameter(0); | 504 return GetParameter(0); |
| 437 } | 505 } |
| 438 | 506 |
| 439 | 507 |
| 440 Handle<Code> ArrayNArgumentsConstructorStub::GenerateCode() { | 508 Handle<Code> ArrayNArgumentsConstructorStub::GenerateCode() { |
| 441 return DoGenerateCode(this); | 509 return DoGenerateCode(this); |
| 442 } | 510 } |
| 443 | 511 |
| 444 } } // namespace v8::internal | 512 } } // namespace v8::internal |
| OLD | NEW |