Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(731)

Side by Side Diff: src/compiler.h

Issue 6529032: Merge 6168:6800 from bleeding_edge to experimental/gc branch. (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/gc/
Patch Set: Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/compilation-cache.cc ('k') | src/compiler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 // is constructed based on the resources available at compile-time. 42 // is constructed based on the resources available at compile-time.
43 class CompilationInfo BASE_EMBEDDED { 43 class CompilationInfo BASE_EMBEDDED {
44 public: 44 public:
45 explicit CompilationInfo(Handle<Script> script); 45 explicit CompilationInfo(Handle<Script> script);
46 explicit CompilationInfo(Handle<SharedFunctionInfo> shared_info); 46 explicit CompilationInfo(Handle<SharedFunctionInfo> shared_info);
47 explicit CompilationInfo(Handle<JSFunction> closure); 47 explicit CompilationInfo(Handle<JSFunction> closure);
48 48
49 bool is_lazy() const { return (flags_ & IsLazy::mask()) != 0; } 49 bool is_lazy() const { return (flags_ & IsLazy::mask()) != 0; }
50 bool is_eval() const { return (flags_ & IsEval::mask()) != 0; } 50 bool is_eval() const { return (flags_ & IsEval::mask()) != 0; }
51 bool is_global() const { return (flags_ & IsGlobal::mask()) != 0; } 51 bool is_global() const { return (flags_ & IsGlobal::mask()) != 0; }
52 bool is_strict() const { return (flags_ & IsStrict::mask()) != 0; }
52 bool is_in_loop() const { return (flags_ & IsInLoop::mask()) != 0; } 53 bool is_in_loop() const { return (flags_ & IsInLoop::mask()) != 0; }
53 FunctionLiteral* function() const { return function_; } 54 FunctionLiteral* function() const { return function_; }
54 Scope* scope() const { return scope_; } 55 Scope* scope() const { return scope_; }
55 Handle<Code> code() const { return code_; } 56 Handle<Code> code() const { return code_; }
56 Handle<JSFunction> closure() const { return closure_; } 57 Handle<JSFunction> closure() const { return closure_; }
57 Handle<SharedFunctionInfo> shared_info() const { return shared_info_; } 58 Handle<SharedFunctionInfo> shared_info() const { return shared_info_; }
58 Handle<Script> script() const { return script_; } 59 Handle<Script> script() const { return script_; }
59 v8::Extension* extension() const { return extension_; } 60 v8::Extension* extension() const { return extension_; }
60 ScriptDataImpl* pre_parse_data() const { return pre_parse_data_; } 61 ScriptDataImpl* pre_parse_data() const { return pre_parse_data_; }
61 Handle<Context> calling_context() const { return calling_context_; } 62 Handle<Context> calling_context() const { return calling_context_; }
62 int osr_ast_id() const { return osr_ast_id_; } 63 int osr_ast_id() const { return osr_ast_id_; }
63 64
64 void MarkAsEval() { 65 void MarkAsEval() {
65 ASSERT(!is_lazy()); 66 ASSERT(!is_lazy());
66 flags_ |= IsEval::encode(true); 67 flags_ |= IsEval::encode(true);
67 } 68 }
68 void MarkAsGlobal() { 69 void MarkAsGlobal() {
69 ASSERT(!is_lazy()); 70 ASSERT(!is_lazy());
70 flags_ |= IsGlobal::encode(true); 71 flags_ |= IsGlobal::encode(true);
71 } 72 }
73 void MarkAsStrict() {
74 flags_ |= IsStrict::encode(true);
75 }
76 StrictModeFlag StrictMode() {
77 return is_strict() ? kStrictMode : kNonStrictMode;
78 }
72 void MarkAsInLoop() { 79 void MarkAsInLoop() {
73 ASSERT(is_lazy()); 80 ASSERT(is_lazy());
74 flags_ |= IsInLoop::encode(true); 81 flags_ |= IsInLoop::encode(true);
75 } 82 }
76 void SetFunction(FunctionLiteral* literal) { 83 void SetFunction(FunctionLiteral* literal) {
77 ASSERT(function_ == NULL); 84 ASSERT(function_ == NULL);
78 function_ = literal; 85 function_ = literal;
79 } 86 }
80 void SetScope(Scope* scope) { 87 void SetScope(Scope* scope) {
81 ASSERT(scope_ == NULL); 88 ASSERT(scope_ == NULL);
(...skipping 25 matching lines...) Expand all
107 return has_global_object() ? closure()->context()->global() : NULL; 114 return has_global_object() ? closure()->context()->global() : NULL;
108 } 115 }
109 116
110 // Accessors for the different compilation modes. 117 // Accessors for the different compilation modes.
111 bool IsOptimizing() const { return mode_ == OPTIMIZE; } 118 bool IsOptimizing() const { return mode_ == OPTIMIZE; }
112 bool IsOptimizable() const { return mode_ == BASE; } 119 bool IsOptimizable() const { return mode_ == BASE; }
113 void SetOptimizing(int osr_ast_id) { 120 void SetOptimizing(int osr_ast_id) {
114 SetMode(OPTIMIZE); 121 SetMode(OPTIMIZE);
115 osr_ast_id_ = osr_ast_id; 122 osr_ast_id_ = osr_ast_id;
116 } 123 }
117 void DisableOptimization() { SetMode(NONOPT); } 124 void DisableOptimization();
118 125
119 // Deoptimization support. 126 // Deoptimization support.
120 bool HasDeoptimizationSupport() const { return supports_deoptimization_; } 127 bool HasDeoptimizationSupport() const { return supports_deoptimization_; }
121 void EnableDeoptimizationSupport() { 128 void EnableDeoptimizationSupport() {
122 ASSERT(IsOptimizable()); 129 ASSERT(IsOptimizable());
123 supports_deoptimization_ = true; 130 supports_deoptimization_ = true;
124 } 131 }
125 132
126 // Determine whether or not we can adaptively optimize. 133 // Determine whether or not we can adaptively optimize.
127 bool AllowOptimize() { 134 bool AllowOptimize() {
128 return V8::UseCrankshaft() && 135 return V8::UseCrankshaft() && !closure_.is_null();
129 !closure_.is_null() &&
130 function_->AllowOptimize();
131 } 136 }
132 137
133 private: 138 private:
134 // Compilation mode. 139 // Compilation mode.
135 // BASE is generated by the full codegen, optionally prepared for bailouts. 140 // BASE is generated by the full codegen, optionally prepared for bailouts.
136 // OPTIMIZE is optimized code generated by the Hydrogen-based backend. 141 // OPTIMIZE is optimized code generated by the Hydrogen-based backend.
137 // NONOPT is generated by the full codegen or the classic backend 142 // NONOPT is generated by the full codegen or the classic backend
138 // and is not prepared for recompilation/bailouts. These functions 143 // and is not prepared for recompilation/bailouts. These functions
139 // are never recompiled. 144 // are never recompiled.
140 enum Mode { 145 enum Mode {
141 BASE, 146 BASE,
142 OPTIMIZE, 147 OPTIMIZE,
143 NONOPT 148 NONOPT
144 }; 149 };
145 150
146 CompilationInfo() : function_(NULL) {} 151 CompilationInfo() : function_(NULL) {}
147 152
148 void Initialize(Mode mode) { 153 void Initialize(Mode mode) {
149 mode_ = V8::UseCrankshaft() ? mode : NONOPT; 154 mode_ = V8::UseCrankshaft() ? mode : NONOPT;
155 if (!shared_info_.is_null() && shared_info_->strict_mode()) {
156 MarkAsStrict();
157 }
150 } 158 }
151 159
152 void SetMode(Mode mode) { 160 void SetMode(Mode mode) {
153 ASSERT(V8::UseCrankshaft()); 161 ASSERT(V8::UseCrankshaft());
154 mode_ = mode; 162 mode_ = mode;
155 } 163 }
156 164
157 // Flags using template class BitField<type, start, length>. All are 165 // Flags using template class BitField<type, start, length>. All are
158 // false by default. 166 // false by default.
159 // 167 //
160 // Compilation is either eager or lazy. 168 // Compilation is either eager or lazy.
161 class IsLazy: public BitField<bool, 0, 1> {}; 169 class IsLazy: public BitField<bool, 0, 1> {};
162 // Flags that can be set for eager compilation. 170 // Flags that can be set for eager compilation.
163 class IsEval: public BitField<bool, 1, 1> {}; 171 class IsEval: public BitField<bool, 1, 1> {};
164 class IsGlobal: public BitField<bool, 2, 1> {}; 172 class IsGlobal: public BitField<bool, 2, 1> {};
165 // Flags that can be set for lazy compilation. 173 // Flags that can be set for lazy compilation.
166 class IsInLoop: public BitField<bool, 3, 1> {}; 174 class IsInLoop: public BitField<bool, 3, 1> {};
175 // Strict mode - used in eager compilation.
176 class IsStrict: public BitField<bool, 4, 1> {};
167 177
168 unsigned flags_; 178 unsigned flags_;
169 179
170 // Fields filled in by the compilation pipeline. 180 // Fields filled in by the compilation pipeline.
171 // AST filled in by the parser. 181 // AST filled in by the parser.
172 FunctionLiteral* function_; 182 FunctionLiteral* function_;
173 // The scope of the function literal as a convenience. Set to indicate 183 // The scope of the function literal as a convenience. Set to indicate
174 // that scopes have been analyzed. 184 // that scopes have been analyzed.
175 Scope* scope_; 185 Scope* scope_;
176 // The compiled code. 186 // The compiled code.
(...skipping 27 matching lines...) Expand all
204 // parameters which then can be executed. If the source code contains other 214 // parameters which then can be executed. If the source code contains other
205 // functions, they will be compiled and allocated as part of the compilation 215 // functions, they will be compiled and allocated as part of the compilation
206 // of the source code. 216 // of the source code.
207 217
208 // Please note this interface returns shared function infos. This means you 218 // Please note this interface returns shared function infos. This means you
209 // need to call Factory::NewFunctionFromSharedFunctionInfo before you have a 219 // need to call Factory::NewFunctionFromSharedFunctionInfo before you have a
210 // real function with a context. 220 // real function with a context.
211 221
212 class Compiler : public AllStatic { 222 class Compiler : public AllStatic {
213 public: 223 public:
214 // All routines return a JSFunction. 224 // Default maximum number of function optimization attempts before we
215 // If an error occurs an exception is raised and 225 // give up.
216 // the return handle contains NULL. 226 static const int kDefaultMaxOptCount = 10;
227
228 // All routines return a SharedFunctionInfo.
229 // If an error occurs an exception is raised and the return handle
230 // contains NULL.
217 231
218 // Compile a String source within a context. 232 // Compile a String source within a context.
219 static Handle<SharedFunctionInfo> Compile(Handle<String> source, 233 static Handle<SharedFunctionInfo> Compile(Handle<String> source,
220 Handle<Object> script_name, 234 Handle<Object> script_name,
221 int line_offset, 235 int line_offset,
222 int column_offset, 236 int column_offset,
223 v8::Extension* extension, 237 v8::Extension* extension,
224 ScriptDataImpl* pre_data, 238 ScriptDataImpl* pre_data,
225 Handle<Object> script_data, 239 Handle<Object> script_data,
226 NativesFlag is_natives_code); 240 NativesFlag is_natives_code);
227 241
228 // Compile a String source within a context for Eval. 242 // Compile a String source within a context for Eval.
229 static Handle<SharedFunctionInfo> CompileEval(Handle<String> source, 243 static Handle<SharedFunctionInfo> CompileEval(Handle<String> source,
230 Handle<Context> context, 244 Handle<Context> context,
231 bool is_global); 245 bool is_global,
246 StrictModeFlag strict_mode);
232 247
233 // Compile from function info (used for lazy compilation). Returns true on 248 // Compile from function info (used for lazy compilation). Returns true on
234 // success and false if the compilation resulted in a stack overflow. 249 // success and false if the compilation resulted in a stack overflow.
235 static bool CompileLazy(CompilationInfo* info); 250 static bool CompileLazy(CompilationInfo* info);
236 251
237 // Compile a shared function info object (the function is possibly lazily 252 // Compile a shared function info object (the function is possibly lazily
238 // compiled). 253 // compiled).
239 static Handle<SharedFunctionInfo> BuildFunctionInfo(FunctionLiteral* node, 254 static Handle<SharedFunctionInfo> BuildFunctionInfo(FunctionLiteral* node,
240 Handle<Script> script); 255 Handle<Script> script);
241 256
(...skipping 25 matching lines...) Expand all
267 FrameElement::ClearConstantList(); 282 FrameElement::ClearConstantList();
268 Result::ClearConstantList(); 283 Result::ClearConstantList();
269 } 284 }
270 } 285 }
271 }; 286 };
272 287
273 288
274 } } // namespace v8::internal 289 } } // namespace v8::internal
275 290
276 #endif // V8_COMPILER_H_ 291 #endif // V8_COMPILER_H_
OLDNEW
« no previous file with comments | « src/compilation-cache.cc ('k') | src/compiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698