| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 bool is_in_loop() const { return (flags_ & IsInLoop::mask()) != 0; } | 56 bool is_in_loop() const { return (flags_ & IsInLoop::mask()) != 0; } |
| 57 FunctionLiteral* function() const { return function_; } | 57 FunctionLiteral* function() const { return function_; } |
| 58 Scope* scope() const { return scope_; } | 58 Scope* scope() const { return scope_; } |
| 59 Handle<Code> code() const { return code_; } | 59 Handle<Code> code() const { return code_; } |
| 60 Handle<JSFunction> closure() const { return closure_; } | 60 Handle<JSFunction> closure() const { return closure_; } |
| 61 Handle<SharedFunctionInfo> shared_info() const { return shared_info_; } | 61 Handle<SharedFunctionInfo> shared_info() const { return shared_info_; } |
| 62 Handle<Script> script() const { return script_; } | 62 Handle<Script> script() const { return script_; } |
| 63 v8::Extension* extension() const { return extension_; } | 63 v8::Extension* extension() const { return extension_; } |
| 64 ScriptDataImpl* pre_parse_data() const { return pre_parse_data_; } | 64 ScriptDataImpl* pre_parse_data() const { return pre_parse_data_; } |
| 65 Handle<Context> calling_context() const { return calling_context_; } | 65 Handle<Context> calling_context() const { return calling_context_; } |
| 66 int osr_ast_id() const { return osr_ast_id_; } |
| 66 | 67 |
| 67 void MarkAsEval() { | 68 void MarkAsEval() { |
| 68 ASSERT(!is_lazy()); | 69 ASSERT(!is_lazy()); |
| 69 flags_ |= IsEval::encode(true); | 70 flags_ |= IsEval::encode(true); |
| 70 } | 71 } |
| 71 void MarkAsGlobal() { | 72 void MarkAsGlobal() { |
| 72 ASSERT(!is_lazy()); | 73 ASSERT(!is_lazy()); |
| 73 flags_ |= IsGlobal::encode(true); | 74 flags_ |= IsGlobal::encode(true); |
| 74 } | 75 } |
| 75 void MarkAsInLoop() { | 76 void MarkAsInLoop() { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 90 extension_ = extension; | 91 extension_ = extension; |
| 91 } | 92 } |
| 92 void SetPreParseData(ScriptDataImpl* pre_parse_data) { | 93 void SetPreParseData(ScriptDataImpl* pre_parse_data) { |
| 93 ASSERT(!is_lazy()); | 94 ASSERT(!is_lazy()); |
| 94 pre_parse_data_ = pre_parse_data; | 95 pre_parse_data_ = pre_parse_data; |
| 95 } | 96 } |
| 96 void SetCallingContext(Handle<Context> context) { | 97 void SetCallingContext(Handle<Context> context) { |
| 97 ASSERT(is_eval()); | 98 ASSERT(is_eval()); |
| 98 calling_context_ = context; | 99 calling_context_ = context; |
| 99 } | 100 } |
| 101 void SetOsrAstId(int osr_ast_id) { |
| 102 ASSERT(IsOptimizing()); |
| 103 osr_ast_id_ = osr_ast_id; |
| 104 } |
| 105 |
| 106 bool has_global_object() const { |
| 107 return !closure().is_null() && (closure()->context()->global() != NULL); |
| 108 } |
| 109 |
| 110 GlobalObject* global_object() const { |
| 111 return has_global_object() ? closure()->context()->global() : NULL; |
| 112 } |
| 113 |
| 114 // Accessors for the different compilation modes. |
| 115 bool IsOptimizing() const { return mode_ == OPTIMIZE; } |
| 116 bool IsOptimizable() const { return mode_ == BASE; } |
| 117 void SetOptimizing(int osr_ast_id) { |
| 118 SetMode(OPTIMIZE); |
| 119 osr_ast_id_ = osr_ast_id; |
| 120 } |
| 121 void DisableOptimization() { SetMode(NONOPT); } |
| 122 |
| 123 // Deoptimization support. |
| 124 bool HasDeoptimizationSupport() const { return supports_deoptimization_; } |
| 125 void EnableDeoptimizationSupport() { |
| 126 ASSERT(IsOptimizable()); |
| 127 supports_deoptimization_ = true; |
| 128 } |
| 129 |
| 130 // Determine whether or not we can adaptively optimize. |
| 131 bool AllowOptimize() { |
| 132 return V8::UseCrankshaft() && |
| 133 !closure_.is_null() && |
| 134 function_->AllowOptimize(); |
| 135 } |
| 100 | 136 |
| 101 private: | 137 private: |
| 102 Isolate* isolate_; | 138 Isolate* isolate_; |
| 103 | 139 |
| 140 // Compilation mode. |
| 141 // BASE is generated by the full codegen, optionally prepared for bailouts. |
| 142 // OPTIMIZE is optimized code generated by the Hydrogen-based backend. |
| 143 // NONOPT is generated by the full codegen or the classic backend |
| 144 // and is not prepared for recompilation/bailouts. These functions |
| 145 // are never recompiled. |
| 146 enum Mode { |
| 147 BASE, |
| 148 OPTIMIZE, |
| 149 NONOPT |
| 150 }; |
| 151 |
| 152 CompilationInfo() : function_(NULL) {} |
| 153 |
| 154 void Initialize(Mode mode) { |
| 155 mode_ = V8::UseCrankshaft() ? mode : NONOPT; |
| 156 } |
| 157 |
| 158 void SetMode(Mode mode) { |
| 159 ASSERT(V8::UseCrankshaft()); |
| 160 mode_ = mode; |
| 161 } |
| 162 |
| 104 // Flags using template class BitField<type, start, length>. All are | 163 // Flags using template class BitField<type, start, length>. All are |
| 105 // false by default. | 164 // false by default. |
| 106 // | 165 // |
| 107 // Compilation is either eager or lazy. | 166 // Compilation is either eager or lazy. |
| 108 class IsLazy: public BitField<bool, 0, 1> {}; | 167 class IsLazy: public BitField<bool, 0, 1> {}; |
| 109 // Flags that can be set for eager compilation. | 168 // Flags that can be set for eager compilation. |
| 110 class IsEval: public BitField<bool, 1, 1> {}; | 169 class IsEval: public BitField<bool, 1, 1> {}; |
| 111 class IsGlobal: public BitField<bool, 2, 1> {}; | 170 class IsGlobal: public BitField<bool, 2, 1> {}; |
| 112 // Flags that can be set for lazy compilation. | 171 // Flags that can be set for lazy compilation. |
| 113 class IsInLoop: public BitField<bool, 3, 1> {}; | 172 class IsInLoop: public BitField<bool, 3, 1> {}; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 129 Handle<Script> script_; | 188 Handle<Script> script_; |
| 130 | 189 |
| 131 // Fields possibly needed for eager compilation, NULL by default. | 190 // Fields possibly needed for eager compilation, NULL by default. |
| 132 v8::Extension* extension_; | 191 v8::Extension* extension_; |
| 133 ScriptDataImpl* pre_parse_data_; | 192 ScriptDataImpl* pre_parse_data_; |
| 134 | 193 |
| 135 // The context of the caller is needed for eval code, and will be a null | 194 // The context of the caller is needed for eval code, and will be a null |
| 136 // handle otherwise. | 195 // handle otherwise. |
| 137 Handle<Context> calling_context_; | 196 Handle<Context> calling_context_; |
| 138 | 197 |
| 198 // Compilation mode flag and whether deoptimization is allowed. |
| 199 Mode mode_; |
| 200 bool supports_deoptimization_; |
| 201 int osr_ast_id_; |
| 202 |
| 139 DISALLOW_COPY_AND_ASSIGN(CompilationInfo); | 203 DISALLOW_COPY_AND_ASSIGN(CompilationInfo); |
| 140 }; | 204 }; |
| 141 | 205 |
| 142 | 206 |
| 143 // The V8 compiler | 207 // The V8 compiler |
| 144 // | 208 // |
| 145 // General strategy: Source code is translated into an anonymous function w/o | 209 // General strategy: Source code is translated into an anonymous function w/o |
| 146 // parameters which then can be executed. If the source code contains other | 210 // parameters which then can be executed. If the source code contains other |
| 147 // functions, they will be compiled and allocated as part of the compilation | 211 // functions, they will be compiled and allocated as part of the compilation |
| 148 // of the source code. | 212 // of the source code. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 // Set the function info for a newly compiled function. | 248 // Set the function info for a newly compiled function. |
| 185 static void SetFunctionInfo(Handle<SharedFunctionInfo> function_info, | 249 static void SetFunctionInfo(Handle<SharedFunctionInfo> function_info, |
| 186 FunctionLiteral* lit, | 250 FunctionLiteral* lit, |
| 187 bool is_toplevel, | 251 bool is_toplevel, |
| 188 Handle<Script> script); | 252 Handle<Script> script); |
| 189 | 253 |
| 190 #ifdef ENABLE_DEBUGGER_SUPPORT | 254 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 191 static bool MakeCodeForLiveEdit(CompilationInfo* info); | 255 static bool MakeCodeForLiveEdit(CompilationInfo* info); |
| 192 #endif | 256 #endif |
| 193 | 257 |
| 194 private: | |
| 195 static void RecordFunctionCompilation(Logger::LogEventsAndTags tag, | 258 static void RecordFunctionCompilation(Logger::LogEventsAndTags tag, |
| 196 Handle<String> name, | 259 Handle<String> name, |
| 197 int start_position, | 260 int start_position, |
| 198 CompilationInfo* info); | 261 CompilationInfo* info); |
| 199 }; | 262 }; |
| 200 | 263 |
| 201 | 264 |
| 202 // During compilation we need a global list of handles to constants | 265 // During compilation we need a global list of handles to constants |
| 203 // for frame elements. When the zone gets deleted, we make sure to | 266 // for frame elements. When the zone gets deleted, we make sure to |
| 204 // clear this list of handles as well. | 267 // clear this list of handles as well. |
| 205 class CompilationZoneScope : public ZoneScope { | 268 class CompilationZoneScope : public ZoneScope { |
| 206 public: | 269 public: |
| 207 explicit CompilationZoneScope(ZoneScopeMode mode) : ZoneScope(mode) { } | 270 explicit CompilationZoneScope(ZoneScopeMode mode) : ZoneScope(mode) { } |
| 208 virtual ~CompilationZoneScope() { | 271 virtual ~CompilationZoneScope() { |
| 209 if (ShouldDeleteOnExit()) { | 272 if (ShouldDeleteOnExit()) { |
| 210 Isolate* isolate = Isolate::Current(); | 273 Isolate* isolate = Isolate::Current(); |
| 211 isolate->frame_element_constant_list()->Clear(); | 274 isolate->frame_element_constant_list()->Clear(); |
| 212 isolate->result_constant_list()->Clear(); | 275 isolate->result_constant_list()->Clear(); |
| 213 } | 276 } |
| 214 } | 277 } |
| 215 }; | 278 }; |
| 216 | 279 |
| 217 | 280 |
| 218 } } // namespace v8::internal | 281 } } // namespace v8::internal |
| 219 | 282 |
| 220 #endif // V8_COMPILER_H_ | 283 #endif // V8_COMPILER_H_ |
| OLD | NEW |