Chromium Code Reviews| 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 21 matching lines...) Expand all Loading... | |
| 32 #include "ast.h" | 32 #include "ast.h" |
| 33 #include "zone.h" | 33 #include "zone.h" |
| 34 | 34 |
| 35 namespace v8 { | 35 namespace v8 { |
| 36 namespace internal { | 36 namespace internal { |
| 37 | 37 |
| 38 class ScriptDataImpl; | 38 class ScriptDataImpl; |
| 39 | 39 |
| 40 // CompilationInfo encapsulates some information known at compile time. It | 40 // CompilationInfo encapsulates some information known at compile time. It |
| 41 // is constructed based on the resources available at compile-time. | 41 // is constructed based on the resources available at compile-time. |
| 42 class CompilationInfo BASE_EMBEDDED { | 42 class CompilationInfo { |
| 43 public: | 43 public: |
| 44 CompilationInfo(Handle<Script> script, Zone* zone); | 44 CompilationInfo(Handle<Script> script, Zone* zone); |
| 45 CompilationInfo(Handle<SharedFunctionInfo> shared_info, Zone* zone); | 45 CompilationInfo(Handle<SharedFunctionInfo> shared_info, Zone* zone); |
| 46 CompilationInfo(Handle<JSFunction> closure, Zone* zone); | 46 CompilationInfo(Handle<JSFunction> closure, Zone* zone); |
| 47 | 47 |
| 48 virtual ~CompilationInfo(); | 48 virtual ~CompilationInfo(); |
| 49 | 49 |
| 50 Isolate* isolate() { | 50 Isolate* isolate() { |
| 51 ASSERT(Isolate::Current() == isolate_); | 51 ASSERT(Isolate::Current() == isolate_); |
| 52 return isolate_; | 52 return isolate_; |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 173 | 173 |
| 174 // Disable all optimization attempts of this info for the rest of the | 174 // Disable all optimization attempts of this info for the rest of the |
| 175 // current compilation pipeline. | 175 // current compilation pipeline. |
| 176 void AbortOptimization(); | 176 void AbortOptimization(); |
| 177 | 177 |
| 178 void set_deferred_handles(DeferredHandles* deferred_handles) { | 178 void set_deferred_handles(DeferredHandles* deferred_handles) { |
| 179 ASSERT(deferred_handles_ == NULL); | 179 ASSERT(deferred_handles_ == NULL); |
| 180 deferred_handles_ = deferred_handles; | 180 deferred_handles_ = deferred_handles; |
| 181 } | 181 } |
| 182 | 182 |
| 183 void SaveHandles() { | |
| 184 SaveHandle(&closure_); | |
| 185 SaveHandle(&shared_info_); | |
| 186 SaveHandle(&calling_context_); | |
| 187 SaveHandle(&script_); | |
| 188 } | |
| 189 | |
| 183 private: | 190 private: |
| 184 Isolate* isolate_; | 191 Isolate* isolate_; |
| 185 | 192 |
| 186 // Compilation mode. | 193 // Compilation mode. |
| 187 // BASE is generated by the full codegen, optionally prepared for bailouts. | 194 // BASE is generated by the full codegen, optionally prepared for bailouts. |
| 188 // OPTIMIZE is optimized code generated by the Hydrogen-based backend. | 195 // OPTIMIZE is optimized code generated by the Hydrogen-based backend. |
| 189 // NONOPT is generated by the full codegen and is not prepared for | 196 // NONOPT is generated by the full codegen and is not prepared for |
| 190 // recompilation/bailouts. These functions are never recompiled. | 197 // recompilation/bailouts. These functions are never recompiled. |
| 191 enum Mode { | 198 enum Mode { |
| 192 BASE, | 199 BASE, |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 261 // Compilation mode flag and whether deoptimization is allowed. | 268 // Compilation mode flag and whether deoptimization is allowed. |
| 262 Mode mode_; | 269 Mode mode_; |
| 263 int osr_ast_id_; | 270 int osr_ast_id_; |
| 264 | 271 |
| 265 // The zone from which the compilation pipeline working on this | 272 // The zone from which the compilation pipeline working on this |
| 266 // CompilationInfo allocates. | 273 // CompilationInfo allocates. |
| 267 Zone* zone_; | 274 Zone* zone_; |
| 268 | 275 |
| 269 DeferredHandles* deferred_handles_; | 276 DeferredHandles* deferred_handles_; |
| 270 | 277 |
| 278 template<typename T> | |
| 279 void SaveHandle(Handle<T> *object) { | |
| 280 if (!object->is_null()) { | |
| 281 Handle<T> handle(*(*object)); | |
| 282 *object = handle; | |
| 283 } | |
| 284 } | |
| 285 | |
| 271 DISALLOW_COPY_AND_ASSIGN(CompilationInfo); | 286 DISALLOW_COPY_AND_ASSIGN(CompilationInfo); |
| 272 }; | 287 }; |
| 273 | 288 |
| 274 | 289 |
| 275 // Exactly like a CompilationInfo, except also creates and enters a | 290 // Exactly like a CompilationInfo, except also creates and enters a |
| 276 // Zone on construction and deallocates it on exit. | 291 // Zone on construction and deallocates it on exit. |
| 277 class CompilationInfoWithZone: public CompilationInfo { | 292 class CompilationInfoWithZone: public CompilationInfo { |
| 278 public: | 293 public: |
| 279 explicit CompilationInfoWithZone(Handle<Script> script) | 294 explicit CompilationInfoWithZone(Handle<Script> script) |
| 280 : CompilationInfo(script, &zone_), | 295 : CompilationInfo(script, &zone_), |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 326 public: | 341 public: |
| 327 explicit OptimizingCompiler(CompilationInfo* info) | 342 explicit OptimizingCompiler(CompilationInfo* info) |
| 328 : info_(info), | 343 : info_(info), |
| 329 oracle_(NULL), | 344 oracle_(NULL), |
| 330 graph_builder_(NULL), | 345 graph_builder_(NULL), |
| 331 graph_(NULL), | 346 graph_(NULL), |
| 332 chunk_(NULL), | 347 chunk_(NULL), |
| 333 time_taken_to_create_graph_(0), | 348 time_taken_to_create_graph_(0), |
| 334 time_taken_to_optimize_(0), | 349 time_taken_to_optimize_(0), |
| 335 time_taken_to_codegen_(0), | 350 time_taken_to_codegen_(0), |
| 336 last_status_(FAILED) { } | 351 last_status_(FAILED), |
| 352 abort_optimization_(false) { } | |
| 337 | 353 |
| 338 enum Status { | 354 enum Status { |
| 339 FAILED, BAILED_OUT, SUCCEEDED | 355 FAILED, BAILED_OUT, SUCCEEDED |
| 340 }; | 356 }; |
| 341 | 357 |
| 342 MUST_USE_RESULT Status CreateGraph(); | 358 MUST_USE_RESULT Status CreateGraph(); |
| 343 MUST_USE_RESULT Status OptimizeGraph(); | 359 MUST_USE_RESULT Status OptimizeGraph(); |
| 344 MUST_USE_RESULT Status GenerateAndInstallCode(); | 360 MUST_USE_RESULT Status GenerateAndInstallCode(); |
| 345 | 361 |
| 346 Status last_status() const { return last_status_; } | 362 Status last_status() const { return last_status_; } |
| 347 CompilationInfo* info() const { return info_; } | 363 CompilationInfo* info() const { return info_; } |
| 348 | 364 |
| 365 void DoPendingAbort() { | |
| 366 if (abort_optimization_) { | |
| 367 info_->AbortOptimization(); | |
| 368 info_->shared_info()->DisableOptimization(); | |
| 369 } | |
| 370 } | |
| 371 | |
| 349 private: | 372 private: |
| 350 CompilationInfo* info_; | 373 CompilationInfo* info_; |
| 351 TypeFeedbackOracle* oracle_; | 374 TypeFeedbackOracle* oracle_; |
| 352 HGraphBuilder* graph_builder_; | 375 HGraphBuilder* graph_builder_; |
| 353 HGraph* graph_; | 376 HGraph* graph_; |
| 354 LChunk* chunk_; | 377 LChunk* chunk_; |
| 355 int64_t time_taken_to_create_graph_; | 378 int64_t time_taken_to_create_graph_; |
| 356 int64_t time_taken_to_optimize_; | 379 int64_t time_taken_to_optimize_; |
| 357 int64_t time_taken_to_codegen_; | 380 int64_t time_taken_to_codegen_; |
| 358 Status last_status_; | 381 Status last_status_; |
| 382 bool abort_optimization_; | |
|
Yang
2012/07/19 15:56:01
imo checking for BAILED_OUT status after the paral
sanjoy
2012/07/19 16:25:36
Done.
| |
| 359 | 383 |
| 360 MUST_USE_RESULT Status SetLastStatus(Status status) { | 384 MUST_USE_RESULT Status SetLastStatus(Status status) { |
| 361 last_status_ = status; | 385 last_status_ = status; |
| 362 return last_status_; | 386 return last_status_; |
| 363 } | 387 } |
| 364 void RecordOptimizationStats(); | 388 void RecordOptimizationStats(); |
| 365 MUST_USE_RESULT Status AbortOptimization() { | 389 MUST_USE_RESULT Status AbortOptimization() { |
| 366 info_->AbortOptimization(); | 390 info_->AbortOptimization(); |
| 367 info_->shared_info()->DisableOptimization(); | 391 info_->shared_info()->DisableOptimization(); |
| 368 return SetLastStatus(BAILED_OUT); | 392 return SetLastStatus(BAILED_OUT); |
| 369 } | 393 } |
| 394 MUST_USE_RESULT Status DeferAbortOptimization() { | |
| 395 abort_optimization_ = true; | |
| 396 return SetLastStatus(BAILED_OUT); | |
| 397 } | |
| 370 | 398 |
| 371 struct Timer { | 399 struct Timer { |
| 372 Timer(OptimizingCompiler* compiler, int64_t* location) | 400 Timer(OptimizingCompiler* compiler, int64_t* location) |
| 373 : compiler_(compiler), | 401 : compiler_(compiler), |
| 374 start_(OS::Ticks()), | 402 start_(OS::Ticks()), |
| 375 location_(location) { } | 403 location_(location) { } |
| 376 | 404 |
| 377 ~Timer() { | 405 ~Timer() { |
| 378 *location_ += (OS::Ticks() - start_); | 406 *location_ += (OS::Ticks() - start_); |
| 379 } | 407 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 425 static Handle<SharedFunctionInfo> CompileEval(Handle<String> source, | 453 static Handle<SharedFunctionInfo> CompileEval(Handle<String> source, |
| 426 Handle<Context> context, | 454 Handle<Context> context, |
| 427 bool is_global, | 455 bool is_global, |
| 428 LanguageMode language_mode, | 456 LanguageMode language_mode, |
| 429 int scope_position); | 457 int scope_position); |
| 430 | 458 |
| 431 // Compile from function info (used for lazy compilation). Returns true on | 459 // Compile from function info (used for lazy compilation). Returns true on |
| 432 // success and false if the compilation resulted in a stack overflow. | 460 // success and false if the compilation resulted in a stack overflow. |
| 433 static bool CompileLazy(CompilationInfo* info); | 461 static bool CompileLazy(CompilationInfo* info); |
| 434 | 462 |
| 463 static void RecompileParallel(Handle<JSFunction> function); | |
| 464 | |
| 435 // Compile a shared function info object (the function is possibly lazily | 465 // Compile a shared function info object (the function is possibly lazily |
| 436 // compiled). | 466 // compiled). |
| 437 static Handle<SharedFunctionInfo> BuildFunctionInfo(FunctionLiteral* node, | 467 static Handle<SharedFunctionInfo> BuildFunctionInfo(FunctionLiteral* node, |
| 438 Handle<Script> script); | 468 Handle<Script> script); |
| 439 | 469 |
| 440 // Set the function info for a newly compiled function. | 470 // Set the function info for a newly compiled function. |
| 441 static void SetFunctionInfo(Handle<SharedFunctionInfo> function_info, | 471 static void SetFunctionInfo(Handle<SharedFunctionInfo> function_info, |
| 442 FunctionLiteral* lit, | 472 FunctionLiteral* lit, |
| 443 bool is_toplevel, | 473 bool is_toplevel, |
| 444 Handle<Script> script); | 474 Handle<Script> script); |
| 445 | 475 |
| 476 static void InstallOptimizedCode(OptimizingCompiler* info); | |
| 477 | |
| 446 #ifdef ENABLE_DEBUGGER_SUPPORT | 478 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 447 static bool MakeCodeForLiveEdit(CompilationInfo* info); | 479 static bool MakeCodeForLiveEdit(CompilationInfo* info); |
| 448 #endif | 480 #endif |
| 449 | 481 |
| 450 static void RecordFunctionCompilation(Logger::LogEventsAndTags tag, | 482 static void RecordFunctionCompilation(Logger::LogEventsAndTags tag, |
| 451 CompilationInfo* info, | 483 CompilationInfo* info, |
| 452 Handle<SharedFunctionInfo> shared); | 484 Handle<SharedFunctionInfo> shared); |
| 453 }; | 485 }; |
| 454 | 486 |
| 455 | 487 |
| 456 } } // namespace v8::internal | 488 } } // namespace v8::internal |
| 457 | 489 |
| 458 #endif // V8_COMPILER_H_ | 490 #endif // V8_COMPILER_H_ |
| OLD | NEW |