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

Side by Side Diff: src/compiler.cc

Issue 12986: Checking and reporting for stack overflow in the right places. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 12 years 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 67
68 // Optimize the AST. 68 // Optimize the AST.
69 if (!Rewriter::Optimize(literal)) { 69 if (!Rewriter::Optimize(literal)) {
70 // Signal a stack overflow by returning a null handle. The stack 70 // Signal a stack overflow by returning a null handle. The stack
71 // overflow exception will be thrown by the caller. 71 // overflow exception will be thrown by the caller.
72 return Handle<Code>::null(); 72 return Handle<Code>::null();
73 } 73 }
74 74
75 // Generate code and return it. 75 // Generate code and return it.
76 Handle<Code> result = CodeGenerator::MakeCode(literal, script, is_eval); 76 Handle<Code> result = CodeGenerator::MakeCode(literal, script, is_eval);
77 // Check for stack-overflow exception.
78 if (result.is_null()) {
79 Top::StackOverflow();
80 Top::ReportPendingMessages();
81 }
82 return result; 77 return result;
83 } 78 }
84 79
85 80
86 static Handle<JSFunction> MakeFunction(bool is_global, 81 static Handle<JSFunction> MakeFunction(bool is_global,
87 bool is_eval, 82 bool is_eval,
88 Handle<Script> script, 83 Handle<Script> script,
89 v8::Extension* extension, 84 v8::Extension* extension,
90 ScriptDataImpl* pre_data) { 85 ScriptDataImpl* pre_data) {
91 ZoneScope zone_scope(DELETE_ON_EXIT); 86 ZoneScope zone_scope(DELETE_ON_EXIT);
(...skipping 24 matching lines...) Expand all
116 StatsRate* rate = is_eval 111 StatsRate* rate = is_eval
117 ? &Counters::compile_eval 112 ? &Counters::compile_eval
118 : &Counters::compile; 113 : &Counters::compile;
119 StatsRateScope timer(rate); 114 StatsRateScope timer(rate);
120 115
121 // Compile the code. 116 // Compile the code.
122 Handle<Code> code = MakeCode(lit, script, is_eval); 117 Handle<Code> code = MakeCode(lit, script, is_eval);
123 118
124 // Check for stack-overflow exceptions. 119 // Check for stack-overflow exceptions.
125 if (code.is_null()) { 120 if (code.is_null()) {
121 Top::StackOverflow();
122 Top::ReportPendingMessages();
126 return Handle<JSFunction>::null(); 123 return Handle<JSFunction>::null();
127 } 124 }
128 125
129 if (script->name()->IsString()) { 126 if (script->name()->IsString()) {
130 SmartPointer<char> data = 127 SmartPointer<char> data =
131 String::cast(script->name())->ToCString(DISALLOW_NULLS); 128 String::cast(script->name())->ToCString(DISALLOW_NULLS);
132 LOG(CodeCreateEvent(is_eval ? "Eval" : "Script", *code, *data)); 129 LOG(CodeCreateEvent(is_eval ? "Eval" : "Script", *code, *data));
133 } else { 130 } else {
134 LOG(CodeCreateEvent(is_eval ? "Eval" : "Script", *code, "")); 131 LOG(CodeCreateEvent(is_eval ? "Eval" : "Script", *code, ""));
135 } 132 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 if (extension == NULL && !result.is_null()) { 201 if (extension == NULL && !result.is_null()) {
205 CompilationCache::PutFunction(source, CompilationCache::SCRIPT, result); 202 CompilationCache::PutFunction(source, CompilationCache::SCRIPT, result);
206 } 203 }
207 204
208 // Get rid of the pre-parsing data (if necessary). 205 // Get rid of the pre-parsing data (if necessary).
209 if (input_pre_data == NULL && pre_data != NULL) { 206 if (input_pre_data == NULL && pre_data != NULL) {
210 delete pre_data; 207 delete pre_data;
211 } 208 }
212 } 209 }
213 210
214 if (result.is_null()) Top::ReportPendingMessages();
215
216 return result; 211 return result;
217 } 212 }
218 213
219 214
220 Handle<JSFunction> Compiler::CompileEval(Handle<String> source, 215 Handle<JSFunction> Compiler::CompileEval(Handle<String> source,
221 int line_offset, 216 int line_offset,
222 bool is_global) { 217 bool is_global) {
223 int source_length = source->length(); 218 int source_length = source->length();
224 Counters::total_eval_size.Increment(source_length); 219 Counters::total_eval_size.Increment(source_length);
225 Counters::total_compile_size.Increment(source_length); 220 Counters::total_compile_size.Increment(source_length);
(...skipping 10 matching lines...) Expand all
236 if (result.is_null()) { 231 if (result.is_null()) {
237 // Create a script object describing the script to be compiled. 232 // Create a script object describing the script to be compiled.
238 Handle<Script> script = Factory::NewScript(source); 233 Handle<Script> script = Factory::NewScript(source);
239 script->set_line_offset(Smi::FromInt(line_offset)); 234 script->set_line_offset(Smi::FromInt(line_offset));
240 result = MakeFunction(is_global, true, script, NULL, NULL); 235 result = MakeFunction(is_global, true, script, NULL, NULL);
241 if (!result.is_null()) { 236 if (!result.is_null()) {
242 CompilationCache::PutFunction(source, entry, result); 237 CompilationCache::PutFunction(source, entry, result);
243 } 238 }
244 } 239 }
245 240
246 if (result.is_null()) Top::ReportPendingMessages();
247
248 return result; 241 return result;
249 } 242 }
250 243
251 244
252 bool Compiler::CompileLazy(Handle<SharedFunctionInfo> shared, 245 bool Compiler::CompileLazy(Handle<SharedFunctionInfo> shared,
253 int loop_nesting) { 246 int loop_nesting) {
254 ZoneScope zone_scope(DELETE_ON_EXIT); 247 ZoneScope zone_scope(DELETE_ON_EXIT);
255 248
256 // The VM is in the COMPILER state until exiting this function. 249 // The VM is in the COMPILER state until exiting this function.
257 VMState state(COMPILER); 250 VMState state(COMPILER);
(...skipping 29 matching lines...) Expand all
287 lit->set_loop_nesting(loop_nesting); 280 lit->set_loop_nesting(loop_nesting);
288 281
289 // Measure how long it takes to do the lazy compilation; only take 282 // Measure how long it takes to do the lazy compilation; only take
290 // the rest of the function into account to avoid overlap with the 283 // the rest of the function into account to avoid overlap with the
291 // lazy parsing statistics. 284 // lazy parsing statistics.
292 StatsRateScope timer(&Counters::compile_lazy); 285 StatsRateScope timer(&Counters::compile_lazy);
293 286
294 // Compile the code. 287 // Compile the code.
295 Handle<Code> code = MakeCode(lit, script, false); 288 Handle<Code> code = MakeCode(lit, script, false);
296 289
290 // Check for stack-overflow exception.
297 if (code.is_null()) { 291 if (code.is_null()) {
292 Top::StackOverflow();
293 Top::ReportPendingMessages();
298 return false; 294 return false;
299 } 295 }
300 296
301 // Generate the code, update the function info, and return the code. 297 // Generate the code, update the function info, and return the code.
302 LOG(CodeCreateEvent("LazyCompile", *code, *lit->name())); 298 LOG(CodeCreateEvent("LazyCompile", *code, *lit->name()));
303 299
304 // Update the shared function info with the compiled code. 300 // Update the shared function info with the compiled code.
305 shared->set_code(*code); 301 shared->set_code(*code);
306 302
307 // Set the expected number of properties for instances. 303 // Set the expected number of properties for instances.
308 SetExpectedNofPropertiesFromEstimate(shared, lit->expected_property_count()); 304 SetExpectedNofPropertiesFromEstimate(shared, lit->expected_property_count());
309 305
310 // Check the function has compiled code. 306 // Check the function has compiled code.
311 ASSERT(shared->is_compiled()); 307 ASSERT(shared->is_compiled());
312 return true; 308 return true;
313 } 309 }
314 310
315 311
316 } } // namespace v8::internal 312 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698