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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 static Handle<SharedFunctionInfo> MakeFunctionInfo(CompilationInfo* info) { | 145 static Handle<SharedFunctionInfo> MakeFunctionInfo(CompilationInfo* info) { |
146 CompilationZoneScope zone_scope(DELETE_ON_EXIT); | 146 CompilationZoneScope zone_scope(DELETE_ON_EXIT); |
147 | 147 |
148 PostponeInterruptsScope postpone; | 148 PostponeInterruptsScope postpone; |
149 | 149 |
150 ASSERT(!i::Top::global_context().is_null()); | 150 ASSERT(!i::Top::global_context().is_null()); |
151 Handle<Script> script = info->script(); | 151 Handle<Script> script = info->script(); |
152 script->set_context_data((*i::Top::global_context())->data()); | 152 script->set_context_data((*i::Top::global_context())->data()); |
153 | 153 |
154 #ifdef ENABLE_DEBUGGER_SUPPORT | 154 #ifdef ENABLE_DEBUGGER_SUPPORT |
155 if (info->is_eval() || info->is_json()) { | 155 if (info->is_eval()) { |
156 Script::CompilationType compilation_type = info->is_json() | 156 Script::CompilationType compilation_type = Script::COMPILATION_TYPE_EVAL; |
157 ? Script::COMPILATION_TYPE_JSON | |
158 : Script::COMPILATION_TYPE_EVAL; | |
159 script->set_compilation_type(Smi::FromInt(compilation_type)); | 157 script->set_compilation_type(Smi::FromInt(compilation_type)); |
160 // For eval scripts add information on the function from which eval was | 158 // For eval scripts add information on the function from which eval was |
161 // called. | 159 // called. |
162 if (info->is_eval()) { | 160 if (info->is_eval()) { |
163 StackTraceFrameIterator it; | 161 StackTraceFrameIterator it; |
164 if (!it.done()) { | 162 if (!it.done()) { |
165 script->set_eval_from_shared( | 163 script->set_eval_from_shared( |
166 JSFunction::cast(it.frame()->function())->shared()); | 164 JSFunction::cast(it.frame()->function())->shared()); |
167 int offset = static_cast<int>( | 165 int offset = static_cast<int>( |
168 it.frame()->pc() - it.frame()->code()->instruction_start()); | 166 it.frame()->pc() - it.frame()->code()->instruction_start()); |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 } | 314 } |
317 } | 315 } |
318 | 316 |
319 if (result.is_null()) Top::ReportPendingMessages(); | 317 if (result.is_null()) Top::ReportPendingMessages(); |
320 return result; | 318 return result; |
321 } | 319 } |
322 | 320 |
323 | 321 |
324 Handle<SharedFunctionInfo> Compiler::CompileEval(Handle<String> source, | 322 Handle<SharedFunctionInfo> Compiler::CompileEval(Handle<String> source, |
325 Handle<Context> context, | 323 Handle<Context> context, |
326 bool is_global, | 324 bool is_global) { |
327 ValidationState validate) { | |
328 // Note that if validation is required then no path through this function | |
329 // is allowed to return a value without validating that the input is legal | |
330 // json. | |
331 bool is_json = (validate == VALIDATE_JSON); | |
332 | |
333 int source_length = source->length(); | 325 int source_length = source->length(); |
334 Counters::total_eval_size.Increment(source_length); | 326 Counters::total_eval_size.Increment(source_length); |
335 Counters::total_compile_size.Increment(source_length); | 327 Counters::total_compile_size.Increment(source_length); |
336 | 328 |
337 // The VM is in the COMPILER state until exiting this function. | 329 // The VM is in the COMPILER state until exiting this function. |
338 VMState state(COMPILER); | 330 VMState state(COMPILER); |
339 | 331 |
340 // Do a lookup in the compilation cache; if the entry is not there, invoke | 332 // Do a lookup in the compilation cache; if the entry is not there, invoke |
341 // the compiler and add the result to the cache. If we're evaluating json | 333 // the compiler and add the result to the cache. |
342 // we bypass the cache since we can't be sure a potential value in the | |
343 // cache has been validated. | |
344 Handle<SharedFunctionInfo> result; | 334 Handle<SharedFunctionInfo> result; |
345 if (!is_json) { | 335 result = CompilationCache::LookupEval(source, context, is_global); |
346 result = CompilationCache::LookupEval(source, context, is_global); | |
347 } | |
348 | 336 |
349 if (result.is_null()) { | 337 if (result.is_null()) { |
350 // Create a script object describing the script to be compiled. | 338 // Create a script object describing the script to be compiled. |
351 Handle<Script> script = Factory::NewScript(source); | 339 Handle<Script> script = Factory::NewScript(source); |
352 CompilationInfo info(script); | 340 CompilationInfo info(script); |
353 info.MarkAsEval(); | 341 info.MarkAsEval(); |
354 if (is_global) info.MarkAsGlobal(); | 342 if (is_global) info.MarkAsGlobal(); |
355 if (is_json) info.MarkAsJson(); | |
356 info.SetCallingContext(context); | 343 info.SetCallingContext(context); |
357 result = MakeFunctionInfo(&info); | 344 result = MakeFunctionInfo(&info); |
358 if (!result.is_null() && !is_json) { | 345 if (!result.is_null()) { |
359 // For json it's unlikely that we'll ever see exactly the same string | |
360 // again so we don't use the compilation cache. | |
361 CompilationCache::PutEval(source, context, is_global, result); | 346 CompilationCache::PutEval(source, context, is_global, result); |
362 } | 347 } |
363 } | 348 } |
364 | 349 |
365 return result; | 350 return result; |
366 } | 351 } |
367 | 352 |
368 | 353 |
369 bool Compiler::CompileLazy(CompilationInfo* info) { | 354 bool Compiler::CompileLazy(CompilationInfo* info) { |
370 CompilationZoneScope zone_scope(DELETE_ON_EXIT); | 355 CompilationZoneScope zone_scope(DELETE_ON_EXIT); |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 *code, | 550 *code, |
566 *name)); | 551 *name)); |
567 OPROFILE(CreateNativeCodeRegion(*name, | 552 OPROFILE(CreateNativeCodeRegion(*name, |
568 code->instruction_start(), | 553 code->instruction_start(), |
569 code->instruction_size())); | 554 code->instruction_size())); |
570 } | 555 } |
571 } | 556 } |
572 } | 557 } |
573 | 558 |
574 } } // namespace v8::internal | 559 } } // namespace v8::internal |
OLD | NEW |