| OLD | NEW | 
|    1 // Copyright 2011 the V8 project authors. All rights reserved. |    1 // Copyright 2011 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   45   explicit CompilationInfo(Handle<SharedFunctionInfo> shared_info); |   45   explicit CompilationInfo(Handle<SharedFunctionInfo> shared_info); | 
|   46   explicit CompilationInfo(Handle<JSFunction> closure); |   46   explicit CompilationInfo(Handle<JSFunction> closure); | 
|   47  |   47  | 
|   48   Isolate* isolate() { |   48   Isolate* isolate() { | 
|   49     ASSERT(Isolate::Current() == isolate_); |   49     ASSERT(Isolate::Current() == isolate_); | 
|   50     return isolate_; |   50     return isolate_; | 
|   51   } |   51   } | 
|   52   bool is_lazy() const { return IsLazy::decode(flags_); } |   52   bool is_lazy() const { return IsLazy::decode(flags_); } | 
|   53   bool is_eval() const { return IsEval::decode(flags_); } |   53   bool is_eval() const { return IsEval::decode(flags_); } | 
|   54   bool is_global() const { return IsGlobal::decode(flags_); } |   54   bool is_global() const { return IsGlobal::decode(flags_); } | 
|   55   bool is_strict_mode() const { return IsStrictMode::decode(flags_); } |   55   bool is_strict_mode() const { return strict_mode_flag() == kStrictMode; } | 
 |   56   StrictModeFlag strict_mode_flag() const { | 
 |   57     return StrictModeFlagField::decode(flags_); | 
 |   58   } | 
|   56   bool is_in_loop() const { return IsInLoop::decode(flags_); } |   59   bool is_in_loop() const { return IsInLoop::decode(flags_); } | 
|   57   FunctionLiteral* function() const { return function_; } |   60   FunctionLiteral* function() const { return function_; } | 
|   58   Scope* scope() const { return scope_; } |   61   Scope* scope() const { return scope_; } | 
|   59   Handle<Code> code() const { return code_; } |   62   Handle<Code> code() const { return code_; } | 
|   60   Handle<JSFunction> closure() const { return closure_; } |   63   Handle<JSFunction> closure() const { return closure_; } | 
|   61   Handle<SharedFunctionInfo> shared_info() const { return shared_info_; } |   64   Handle<SharedFunctionInfo> shared_info() const { return shared_info_; } | 
|   62   Handle<Script> script() const { return script_; } |   65   Handle<Script> script() const { return script_; } | 
|   63   v8::Extension* extension() const { return extension_; } |   66   v8::Extension* extension() const { return extension_; } | 
|   64   ScriptDataImpl* pre_parse_data() const { return pre_parse_data_; } |   67   ScriptDataImpl* pre_parse_data() const { return pre_parse_data_; } | 
|   65   Handle<Context> calling_context() const { return calling_context_; } |   68   Handle<Context> calling_context() const { return calling_context_; } | 
|   66   int osr_ast_id() const { return osr_ast_id_; } |   69   int osr_ast_id() const { return osr_ast_id_; } | 
|   67  |   70  | 
|   68   void MarkAsEval() { |   71   void MarkAsEval() { | 
|   69     ASSERT(!is_lazy()); |   72     ASSERT(!is_lazy()); | 
|   70     flags_ |= IsEval::encode(true); |   73     flags_ |= IsEval::encode(true); | 
|   71   } |   74   } | 
|   72   void MarkAsGlobal() { |   75   void MarkAsGlobal() { | 
|   73     ASSERT(!is_lazy()); |   76     ASSERT(!is_lazy()); | 
|   74     flags_ |= IsGlobal::encode(true); |   77     flags_ |= IsGlobal::encode(true); | 
|   75   } |   78   } | 
|   76   void MarkAsStrictMode() { |   79   void SetStrictModeFlag(StrictModeFlag strict_mode_flag) { | 
|   77     flags_ |= IsStrictMode::encode(true); |   80     ASSERT(StrictModeFlagField::decode(flags_) == kNonStrictMode || | 
|   78   } |   81            StrictModeFlagField::decode(flags_) == strict_mode_flag); | 
|   79   StrictModeFlag StrictMode() { |   82     flags_ = StrictModeFlagField::update(flags_, strict_mode_flag); | 
|   80     return is_strict_mode() ? kStrictMode : kNonStrictMode; |  | 
|   81   } |   83   } | 
|   82   void MarkAsInLoop() { |   84   void MarkAsInLoop() { | 
|   83     ASSERT(is_lazy()); |   85     ASSERT(is_lazy()); | 
|   84     flags_ |= IsInLoop::encode(true); |   86     flags_ |= IsInLoop::encode(true); | 
|   85   } |   87   } | 
|   86   void MarkAsNative() { |   88   void MarkAsNative() { | 
|   87     flags_ |= IsNative::encode(true); |   89     flags_ |= IsNative::encode(true); | 
|   88   } |   90   } | 
|   89   bool is_native() const { |   91   bool is_native() const { | 
|   90     return IsNative::decode(flags_); |   92     return IsNative::decode(flags_); | 
| (...skipping 16 matching lines...) Expand all  Loading... | 
|  107     pre_parse_data_ = pre_parse_data; |  109     pre_parse_data_ = pre_parse_data; | 
|  108   } |  110   } | 
|  109   void SetCallingContext(Handle<Context> context) { |  111   void SetCallingContext(Handle<Context> context) { | 
|  110     ASSERT(is_eval()); |  112     ASSERT(is_eval()); | 
|  111     calling_context_ = context; |  113     calling_context_ = context; | 
|  112   } |  114   } | 
|  113   void SetOsrAstId(int osr_ast_id) { |  115   void SetOsrAstId(int osr_ast_id) { | 
|  114     ASSERT(IsOptimizing()); |  116     ASSERT(IsOptimizing()); | 
|  115     osr_ast_id_ = osr_ast_id; |  117     osr_ast_id_ = osr_ast_id; | 
|  116   } |  118   } | 
 |  119   void MarkCompilingForDebugging(Handle<Code> current_code) { | 
 |  120     ASSERT(mode_ != OPTIMIZE); | 
 |  121     ASSERT(current_code->kind() == Code::FUNCTION); | 
 |  122     flags_ |= IsCompilingForDebugging::encode(true); | 
 |  123     if (current_code->is_compiled_optimizable()) { | 
 |  124       EnableDeoptimizationSupport(); | 
 |  125     } else { | 
 |  126       mode_ = CompilationInfo::NONOPT; | 
 |  127     } | 
 |  128   } | 
 |  129   bool IsCompilingForDebugging() { | 
 |  130     return IsCompilingForDebugging::decode(flags_); | 
 |  131   } | 
|  117  |  132  | 
|  118   bool has_global_object() const { |  133   bool has_global_object() const { | 
|  119     return !closure().is_null() && (closure()->context()->global() != NULL); |  134     return !closure().is_null() && (closure()->context()->global() != NULL); | 
|  120   } |  135   } | 
|  121  |  136  | 
|  122   GlobalObject* global_object() const { |  137   GlobalObject* global_object() const { | 
|  123     return has_global_object() ? closure()->context()->global() : NULL; |  138     return has_global_object() ? closure()->context()->global() : NULL; | 
|  124   } |  139   } | 
|  125  |  140  | 
|  126   // Accessors for the different compilation modes. |  141   // Accessors for the different compilation modes. | 
|  127   bool IsOptimizing() const { return mode_ == OPTIMIZE; } |  142   bool IsOptimizing() const { return mode_ == OPTIMIZE; } | 
|  128   bool IsOptimizable() const { return mode_ == BASE; } |  143   bool IsOptimizable() const { return mode_ == BASE; } | 
|  129   void SetOptimizing(int osr_ast_id) { |  144   void SetOptimizing(int osr_ast_id) { | 
|  130     SetMode(OPTIMIZE); |  145     SetMode(OPTIMIZE); | 
|  131     osr_ast_id_ = osr_ast_id; |  146     osr_ast_id_ = osr_ast_id; | 
|  132   } |  147   } | 
|  133   void DisableOptimization(); |  148   void DisableOptimization(); | 
|  134  |  149  | 
|  135   // Deoptimization support. |  150   // Deoptimization support. | 
|  136   bool HasDeoptimizationSupport() const { return supports_deoptimization_; } |  151   bool HasDeoptimizationSupport() const { | 
 |  152     return SupportsDeoptimization::decode(flags_); | 
 |  153   } | 
|  137   void EnableDeoptimizationSupport() { |  154   void EnableDeoptimizationSupport() { | 
|  138     ASSERT(IsOptimizable()); |  155     ASSERT(IsOptimizable()); | 
|  139     supports_deoptimization_ = true; |  156     flags_ |= SupportsDeoptimization::encode(true); | 
|  140   } |  157   } | 
|  141  |  158  | 
|  142   // Determine whether or not we can adaptively optimize. |  159   // Determine whether or not we can adaptively optimize. | 
|  143   bool AllowOptimize() { |  160   bool AllowOptimize() { | 
|  144     return V8::UseCrankshaft() && !closure_.is_null(); |  161     return V8::UseCrankshaft() && !closure_.is_null(); | 
|  145   } |  162   } | 
|  146  |  163  | 
|  147   // Disable all optimization attempts of this info for the rest of the |  164   // Disable all optimization attempts of this info for the rest of the | 
|  148   // current compilation pipeline. |  165   // current compilation pipeline. | 
|  149   void AbortOptimization(); |  166   void AbortOptimization(); | 
| (...skipping 14 matching lines...) Expand all  Loading... | 
|  164   }; |  181   }; | 
|  165  |  182  | 
|  166   CompilationInfo() : function_(NULL) {} |  183   CompilationInfo() : function_(NULL) {} | 
|  167  |  184  | 
|  168   void Initialize(Mode mode) { |  185   void Initialize(Mode mode) { | 
|  169     mode_ = V8::UseCrankshaft() ? mode : NONOPT; |  186     mode_ = V8::UseCrankshaft() ? mode : NONOPT; | 
|  170     ASSERT(!script_.is_null()); |  187     ASSERT(!script_.is_null()); | 
|  171     if (script_->type()->value() == Script::TYPE_NATIVE) { |  188     if (script_->type()->value() == Script::TYPE_NATIVE) { | 
|  172       MarkAsNative(); |  189       MarkAsNative(); | 
|  173     } |  190     } | 
|  174     if (!shared_info_.is_null() && shared_info_->strict_mode()) { |  191     if (!shared_info_.is_null()) { | 
|  175       MarkAsStrictMode(); |  192       ASSERT(strict_mode_flag() == kNonStrictMode); | 
 |  193       SetStrictModeFlag(shared_info_->strict_mode_flag()); | 
|  176     } |  194     } | 
|  177   } |  195   } | 
|  178  |  196  | 
|  179   void SetMode(Mode mode) { |  197   void SetMode(Mode mode) { | 
|  180     ASSERT(V8::UseCrankshaft()); |  198     ASSERT(V8::UseCrankshaft()); | 
|  181     mode_ = mode; |  199     mode_ = mode; | 
|  182   } |  200   } | 
|  183  |  201  | 
|  184   // Flags using template class BitField<type, start, length>.  All are |  202   // Flags using template class BitField<type, start, length>.  All are | 
|  185   // false by default. |  203   // false by default. | 
|  186   // |  204   // | 
|  187   // Compilation is either eager or lazy. |  205   // Compilation is either eager or lazy. | 
|  188   class IsLazy:   public BitField<bool, 0, 1> {}; |  206   class IsLazy:   public BitField<bool, 0, 1> {}; | 
|  189   // Flags that can be set for eager compilation. |  207   // Flags that can be set for eager compilation. | 
|  190   class IsEval:   public BitField<bool, 1, 1> {}; |  208   class IsEval:   public BitField<bool, 1, 1> {}; | 
|  191   class IsGlobal: public BitField<bool, 2, 1> {}; |  209   class IsGlobal: public BitField<bool, 2, 1> {}; | 
|  192   // Flags that can be set for lazy compilation. |  210   // Flags that can be set for lazy compilation. | 
|  193   class IsInLoop: public BitField<bool, 3, 1> {}; |  211   class IsInLoop: public BitField<bool, 3, 1> {}; | 
|  194   // Strict mode - used in eager compilation. |  212   // Strict mode - used in eager compilation. | 
|  195   class IsStrictMode: public BitField<bool, 4, 1> {}; |  213   class StrictModeFlagField: public BitField<StrictModeFlag, 4, 1> {}; | 
|  196   // Is this a function from our natives. |  214   // Is this a function from our natives. | 
|  197   class IsNative: public BitField<bool, 6, 1> {}; |  215   class IsNative: public BitField<bool, 6, 1> {}; | 
 |  216   // Is this code being compiled with support for deoptimization.. | 
 |  217   class SupportsDeoptimization: public BitField<bool, 7, 1> {}; | 
 |  218   // If compiling for debugging produce just full code matching the | 
 |  219   // initial mode setting. | 
 |  220   class IsCompilingForDebugging: public BitField<bool, 8, 1> {}; | 
|  198  |  221  | 
|  199  |  222  | 
|  200   unsigned flags_; |  223   unsigned flags_; | 
|  201  |  224  | 
|  202   // Fields filled in by the compilation pipeline. |  225   // Fields filled in by the compilation pipeline. | 
|  203   // AST filled in by the parser. |  226   // AST filled in by the parser. | 
|  204   FunctionLiteral* function_; |  227   FunctionLiteral* function_; | 
|  205   // The scope of the function literal as a convenience.  Set to indicate |  228   // The scope of the function literal as a convenience.  Set to indicate | 
|  206   // that scopes have been analyzed. |  229   // that scopes have been analyzed. | 
|  207   Scope* scope_; |  230   Scope* scope_; | 
|  208   // The compiled code. |  231   // The compiled code. | 
|  209   Handle<Code> code_; |  232   Handle<Code> code_; | 
|  210  |  233  | 
|  211   // Possible initial inputs to the compilation process. |  234   // Possible initial inputs to the compilation process. | 
|  212   Handle<JSFunction> closure_; |  235   Handle<JSFunction> closure_; | 
|  213   Handle<SharedFunctionInfo> shared_info_; |  236   Handle<SharedFunctionInfo> shared_info_; | 
|  214   Handle<Script> script_; |  237   Handle<Script> script_; | 
|  215  |  238  | 
|  216   // Fields possibly needed for eager compilation, NULL by default. |  239   // Fields possibly needed for eager compilation, NULL by default. | 
|  217   v8::Extension* extension_; |  240   v8::Extension* extension_; | 
|  218   ScriptDataImpl* pre_parse_data_; |  241   ScriptDataImpl* pre_parse_data_; | 
|  219  |  242  | 
|  220   // The context of the caller is needed for eval code, and will be a null |  243   // The context of the caller is needed for eval code, and will be a null | 
|  221   // handle otherwise. |  244   // handle otherwise. | 
|  222   Handle<Context> calling_context_; |  245   Handle<Context> calling_context_; | 
|  223  |  246  | 
|  224   // Compilation mode flag and whether deoptimization is allowed. |  247   // Compilation mode flag and whether deoptimization is allowed. | 
|  225   Mode mode_; |  248   Mode mode_; | 
|  226   bool supports_deoptimization_; |  | 
|  227   int osr_ast_id_; |  249   int osr_ast_id_; | 
|  228  |  250  | 
|  229   DISALLOW_COPY_AND_ASSIGN(CompilationInfo); |  251   DISALLOW_COPY_AND_ASSIGN(CompilationInfo); | 
|  230 }; |  252 }; | 
|  231  |  253  | 
|  232  |  254  | 
|  233 // The V8 compiler |  255 // The V8 compiler | 
|  234 // |  256 // | 
|  235 // General strategy: Source code is translated into an anonymous function w/o |  257 // General strategy: Source code is translated into an anonymous function w/o | 
|  236 // parameters which then can be executed. If the source code contains other |  258 // parameters which then can be executed. If the source code contains other | 
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  290  |  312  | 
|  291   static void RecordFunctionCompilation(Logger::LogEventsAndTags tag, |  313   static void RecordFunctionCompilation(Logger::LogEventsAndTags tag, | 
|  292                                         CompilationInfo* info, |  314                                         CompilationInfo* info, | 
|  293                                         Handle<SharedFunctionInfo> shared); |  315                                         Handle<SharedFunctionInfo> shared); | 
|  294 }; |  316 }; | 
|  295  |  317  | 
|  296  |  318  | 
|  297 } }  // namespace v8::internal |  319 } }  // namespace v8::internal | 
|  298  |  320  | 
|  299 #endif  // V8_COMPILER_H_ |  321 #endif  // V8_COMPILER_H_ | 
| OLD | NEW |