| 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 FAILED, BAILED_OUT, SUCCEEDED | 354 FAILED, BAILED_OUT, SUCCEEDED |
| 340 }; | 355 }; |
| 341 | 356 |
| 342 MUST_USE_RESULT Status CreateGraph(); | 357 MUST_USE_RESULT Status CreateGraph(); |
| 343 MUST_USE_RESULT Status OptimizeGraph(); | 358 MUST_USE_RESULT Status OptimizeGraph(); |
| 344 MUST_USE_RESULT Status GenerateAndInstallCode(); | 359 MUST_USE_RESULT Status GenerateAndInstallCode(); |
| 345 | 360 |
| 346 Status last_status() const { return last_status_; } | 361 Status last_status() const { return last_status_; } |
| 347 CompilationInfo* info() const { return info_; } | 362 CompilationInfo* info() const { return info_; } |
| 348 | 363 |
| 364 MUST_USE_RESULT Status AbortOptimization() { |
| 365 info_->AbortOptimization(); |
| 366 info_->shared_info()->DisableOptimization(); |
| 367 return SetLastStatus(BAILED_OUT); |
| 368 } |
| 369 |
| 349 private: | 370 private: |
| 350 CompilationInfo* info_; | 371 CompilationInfo* info_; |
| 351 TypeFeedbackOracle* oracle_; | 372 TypeFeedbackOracle* oracle_; |
| 352 HGraphBuilder* graph_builder_; | 373 HGraphBuilder* graph_builder_; |
| 353 HGraph* graph_; | 374 HGraph* graph_; |
| 354 LChunk* chunk_; | 375 LChunk* chunk_; |
| 355 int64_t time_taken_to_create_graph_; | 376 int64_t time_taken_to_create_graph_; |
| 356 int64_t time_taken_to_optimize_; | 377 int64_t time_taken_to_optimize_; |
| 357 int64_t time_taken_to_codegen_; | 378 int64_t time_taken_to_codegen_; |
| 358 Status last_status_; | 379 Status last_status_; |
| 359 | 380 |
| 360 MUST_USE_RESULT Status SetLastStatus(Status status) { | 381 MUST_USE_RESULT Status SetLastStatus(Status status) { |
| 361 last_status_ = status; | 382 last_status_ = status; |
| 362 return last_status_; | 383 return last_status_; |
| 363 } | 384 } |
| 364 void RecordOptimizationStats(); | 385 void RecordOptimizationStats(); |
| 365 MUST_USE_RESULT Status AbortOptimization() { | |
| 366 info_->AbortOptimization(); | |
| 367 info_->shared_info()->DisableOptimization(); | |
| 368 return SetLastStatus(BAILED_OUT); | |
| 369 } | |
| 370 | 386 |
| 371 struct Timer { | 387 struct Timer { |
| 372 Timer(OptimizingCompiler* compiler, int64_t* location) | 388 Timer(OptimizingCompiler* compiler, int64_t* location) |
| 373 : compiler_(compiler), | 389 : compiler_(compiler), |
| 374 start_(OS::Ticks()), | 390 start_(OS::Ticks()), |
| 375 location_(location) { } | 391 location_(location) { } |
| 376 | 392 |
| 377 ~Timer() { | 393 ~Timer() { |
| 378 *location_ += (OS::Ticks() - start_); | 394 *location_ += (OS::Ticks() - start_); |
| 379 } | 395 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 static Handle<SharedFunctionInfo> CompileEval(Handle<String> source, | 441 static Handle<SharedFunctionInfo> CompileEval(Handle<String> source, |
| 426 Handle<Context> context, | 442 Handle<Context> context, |
| 427 bool is_global, | 443 bool is_global, |
| 428 LanguageMode language_mode, | 444 LanguageMode language_mode, |
| 429 int scope_position); | 445 int scope_position); |
| 430 | 446 |
| 431 // Compile from function info (used for lazy compilation). Returns true on | 447 // Compile from function info (used for lazy compilation). Returns true on |
| 432 // success and false if the compilation resulted in a stack overflow. | 448 // success and false if the compilation resulted in a stack overflow. |
| 433 static bool CompileLazy(CompilationInfo* info); | 449 static bool CompileLazy(CompilationInfo* info); |
| 434 | 450 |
| 451 static void RecompileParallel(Handle<JSFunction> function); |
| 452 |
| 435 // Compile a shared function info object (the function is possibly lazily | 453 // Compile a shared function info object (the function is possibly lazily |
| 436 // compiled). | 454 // compiled). |
| 437 static Handle<SharedFunctionInfo> BuildFunctionInfo(FunctionLiteral* node, | 455 static Handle<SharedFunctionInfo> BuildFunctionInfo(FunctionLiteral* node, |
| 438 Handle<Script> script); | 456 Handle<Script> script); |
| 439 | 457 |
| 440 // Set the function info for a newly compiled function. | 458 // Set the function info for a newly compiled function. |
| 441 static void SetFunctionInfo(Handle<SharedFunctionInfo> function_info, | 459 static void SetFunctionInfo(Handle<SharedFunctionInfo> function_info, |
| 442 FunctionLiteral* lit, | 460 FunctionLiteral* lit, |
| 443 bool is_toplevel, | 461 bool is_toplevel, |
| 444 Handle<Script> script); | 462 Handle<Script> script); |
| 445 | 463 |
| 464 static void InstallOptimizedCode(OptimizingCompiler* info); |
| 465 |
| 446 #ifdef ENABLE_DEBUGGER_SUPPORT | 466 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 447 static bool MakeCodeForLiveEdit(CompilationInfo* info); | 467 static bool MakeCodeForLiveEdit(CompilationInfo* info); |
| 448 #endif | 468 #endif |
| 449 | 469 |
| 450 static void RecordFunctionCompilation(Logger::LogEventsAndTags tag, | 470 static void RecordFunctionCompilation(Logger::LogEventsAndTags tag, |
| 451 CompilationInfo* info, | 471 CompilationInfo* info, |
| 452 Handle<SharedFunctionInfo> shared); | 472 Handle<SharedFunctionInfo> shared); |
| 453 }; | 473 }; |
| 454 | 474 |
| 455 | 475 |
| 456 } } // namespace v8::internal | 476 } } // namespace v8::internal |
| 457 | 477 |
| 458 #endif // V8_COMPILER_H_ | 478 #endif // V8_COMPILER_H_ |
| OLD | NEW |