The data contained in this repository can be downloaded to your computer using one of several clients.
Please see the documentation of your version control software client for more information.

Please select the desired protocol below to get the URL.

This URL has Read-Only access.

Statistics
| Branch: | Revision:

main_repo / deps / v8 / src / compiler.h @ f230a1cf

History | View | Annotate | Download (21.8 KB)

1
// Copyright 2012 the V8 project authors. All rights reserved.
2
// Redistribution and use in source and binary forms, with or without
3
// modification, are permitted provided that the following conditions are
4
// met:
5
//
6
//     * Redistributions of source code must retain the above copyright
7
//       notice, this list of conditions and the following disclaimer.
8
//     * Redistributions in binary form must reproduce the above
9
//       copyright notice, this list of conditions and the following
10
//       disclaimer in the documentation and/or other materials provided
11
//       with the distribution.
12
//     * Neither the name of Google Inc. nor the names of its
13
//       contributors may be used to endorse or promote products derived
14
//       from this software without specific prior written permission.
15
//
16
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27

    
28
#ifndef V8_COMPILER_H_
29
#define V8_COMPILER_H_
30

    
31
#include "allocation.h"
32
#include "ast.h"
33
#include "zone.h"
34

    
35
namespace v8 {
36
namespace internal {
37

    
38
class ScriptDataImpl;
39
class HydrogenCodeStub;
40

    
41
// ParseRestriction is used to restrict the set of valid statements in a
42
// unit of compilation.  Restriction violations cause a syntax error.
43
enum ParseRestriction {
44
  NO_PARSE_RESTRICTION,         // All expressions are allowed.
45
  ONLY_SINGLE_FUNCTION_LITERAL  // Only a single FunctionLiteral expression.
46
};
47

    
48
struct OffsetRange {
49
  OffsetRange(int from, int to) : from(from), to(to) {}
50
  int from;
51
  int to;
52
};
53

    
54
// CompilationInfo encapsulates some information known at compile time.  It
55
// is constructed based on the resources available at compile-time.
56
class CompilationInfo {
57
 public:
58
  CompilationInfo(Handle<JSFunction> closure, Zone* zone);
59
  virtual ~CompilationInfo();
60

    
61
  Isolate* isolate() const {
62
    return isolate_;
63
  }
64
  Zone* zone() { return zone_; }
65
  bool is_osr() const { return !osr_ast_id_.IsNone(); }
66
  bool is_lazy() const { return IsLazy::decode(flags_); }
67
  bool is_eval() const { return IsEval::decode(flags_); }
68
  bool is_global() const { return IsGlobal::decode(flags_); }
69
  bool is_classic_mode() const { return language_mode() == CLASSIC_MODE; }
70
  bool is_extended_mode() const { return language_mode() == EXTENDED_MODE; }
71
  LanguageMode language_mode() const {
72
    return LanguageModeField::decode(flags_);
73
  }
74
  bool is_in_loop() const { return IsInLoop::decode(flags_); }
75
  FunctionLiteral* function() const { return function_; }
76
  Scope* scope() const { return scope_; }
77
  Scope* global_scope() const { return global_scope_; }
78
  Handle<Code> code() const { return code_; }
79
  Handle<JSFunction> closure() const { return closure_; }
80
  Handle<SharedFunctionInfo> shared_info() const { return shared_info_; }
81
  Handle<Script> script() const { return script_; }
82
  HydrogenCodeStub* code_stub() const {return code_stub_; }
83
  v8::Extension* extension() const { return extension_; }
84
  ScriptDataImpl* pre_parse_data() const { return pre_parse_data_; }
85
  Handle<Context> context() const { return context_; }
86
  BailoutId osr_ast_id() const { return osr_ast_id_; }
87
  uint32_t osr_pc_offset() const { return osr_pc_offset_; }
88
  int opt_count() const { return opt_count_; }
89
  int num_parameters() const;
90
  int num_heap_slots() const;
91
  Code::Flags flags() const;
92

    
93
  void MarkAsEval() {
94
    ASSERT(!is_lazy());
95
    flags_ |= IsEval::encode(true);
96
  }
97
  void MarkAsGlobal() {
98
    ASSERT(!is_lazy());
99
    flags_ |= IsGlobal::encode(true);
100
  }
101
  void SetLanguageMode(LanguageMode language_mode) {
102
    ASSERT(this->language_mode() == CLASSIC_MODE ||
103
           this->language_mode() == language_mode ||
104
           language_mode == EXTENDED_MODE);
105
    flags_ = LanguageModeField::update(flags_, language_mode);
106
  }
107
  void MarkAsInLoop() {
108
    ASSERT(is_lazy());
109
    flags_ |= IsInLoop::encode(true);
110
  }
111
  void MarkAsNative() {
112
    flags_ |= IsNative::encode(true);
113
  }
114

    
115
  bool is_native() const {
116
    return IsNative::decode(flags_);
117
  }
118

    
119
  bool is_calling() const {
120
    return is_deferred_calling() || is_non_deferred_calling();
121
  }
122

    
123
  void MarkAsDeferredCalling() {
124
    flags_ |= IsDeferredCalling::encode(true);
125
  }
126

    
127
  bool is_deferred_calling() const {
128
    return IsDeferredCalling::decode(flags_);
129
  }
130

    
131
  void MarkAsNonDeferredCalling() {
132
    flags_ |= IsNonDeferredCalling::encode(true);
133
  }
134

    
135
  bool is_non_deferred_calling() const {
136
    return IsNonDeferredCalling::decode(flags_);
137
  }
138

    
139
  void MarkAsSavesCallerDoubles() {
140
    flags_ |= SavesCallerDoubles::encode(true);
141
  }
142

    
143
  bool saves_caller_doubles() const {
144
    return SavesCallerDoubles::decode(flags_);
145
  }
146

    
147
  void MarkAsRequiresFrame() {
148
    flags_ |= RequiresFrame::encode(true);
149
  }
150

    
151
  bool requires_frame() const {
152
    return RequiresFrame::decode(flags_);
153
  }
154

    
155
  void SetParseRestriction(ParseRestriction restriction) {
156
    flags_ = ParseRestricitonField::update(flags_, restriction);
157
  }
158

    
159
  ParseRestriction parse_restriction() const {
160
    return ParseRestricitonField::decode(flags_);
161
  }
162

    
163
  void SetFunction(FunctionLiteral* literal) {
164
    ASSERT(function_ == NULL);
165
    function_ = literal;
166
  }
167
  void SetScope(Scope* scope) {
168
    ASSERT(scope_ == NULL);
169
    scope_ = scope;
170
  }
171
  void SetGlobalScope(Scope* global_scope) {
172
    ASSERT(global_scope_ == NULL);
173
    global_scope_ = global_scope;
174
  }
175
  void SetCode(Handle<Code> code) { code_ = code; }
176
  void SetExtension(v8::Extension* extension) {
177
    ASSERT(!is_lazy());
178
    extension_ = extension;
179
  }
180
  void SetPreParseData(ScriptDataImpl* pre_parse_data) {
181
    ASSERT(!is_lazy());
182
    pre_parse_data_ = pre_parse_data;
183
  }
184
  void SetContext(Handle<Context> context) {
185
    context_ = context;
186
  }
187
  void MarkCompilingForDebugging(Handle<Code> current_code) {
188
    ASSERT(mode_ != OPTIMIZE);
189
    ASSERT(current_code->kind() == Code::FUNCTION);
190
    flags_ |= IsCompilingForDebugging::encode(true);
191
    if (current_code->is_compiled_optimizable()) {
192
      EnableDeoptimizationSupport();
193
    } else {
194
      mode_ = CompilationInfo::NONOPT;
195
    }
196
  }
197
  bool IsCompilingForDebugging() {
198
    return IsCompilingForDebugging::decode(flags_);
199
  }
200

    
201
  bool ShouldTrapOnDeopt() const {
202
    return (FLAG_trap_on_deopt && IsOptimizing()) ||
203
        (FLAG_trap_on_stub_deopt && IsStub());
204
  }
205

    
206
  bool has_global_object() const {
207
    return !closure().is_null() &&
208
        (closure()->context()->global_object() != NULL);
209
  }
210

    
211
  GlobalObject* global_object() const {
212
    return has_global_object() ? closure()->context()->global_object() : NULL;
213
  }
214

    
215
  // Accessors for the different compilation modes.
216
  bool IsOptimizing() const { return mode_ == OPTIMIZE; }
217
  bool IsOptimizable() const { return mode_ == BASE; }
218
  bool IsStub() const { return mode_ == STUB; }
219
  void SetOptimizing(BailoutId osr_ast_id) {
220
    SetMode(OPTIMIZE);
221
    osr_ast_id_ = osr_ast_id;
222
  }
223
  void DisableOptimization();
224

    
225
  // Deoptimization support.
226
  bool HasDeoptimizationSupport() const {
227
    return SupportsDeoptimization::decode(flags_);
228
  }
229
  void EnableDeoptimizationSupport() {
230
    ASSERT(IsOptimizable());
231
    flags_ |= SupportsDeoptimization::encode(true);
232
  }
233

    
234
  // Determines whether or not to insert a self-optimization header.
235
  bool ShouldSelfOptimize();
236

    
237
  // Reset code to the unoptimized version when optimization is aborted.
238
  void AbortOptimization() {
239
    SetCode(handle(shared_info()->code()));
240
  }
241

    
242
  void set_deferred_handles(DeferredHandles* deferred_handles) {
243
    ASSERT(deferred_handles_ == NULL);
244
    deferred_handles_ = deferred_handles;
245
  }
246

    
247
  ZoneList<Handle<HeapObject> >* dependencies(
248
      DependentCode::DependencyGroup group) {
249
    if (dependencies_[group] == NULL) {
250
      dependencies_[group] = new(zone_) ZoneList<Handle<HeapObject> >(2, zone_);
251
    }
252
    return dependencies_[group];
253
  }
254

    
255
  void CommitDependencies(Handle<Code> code);
256

    
257
  void RollbackDependencies();
258

    
259
  void SaveHandles() {
260
    SaveHandle(&closure_);
261
    SaveHandle(&shared_info_);
262
    SaveHandle(&context_);
263
    SaveHandle(&script_);
264
  }
265

    
266
  BailoutReason bailout_reason() const { return bailout_reason_; }
267
  void set_bailout_reason(BailoutReason reason) { bailout_reason_ = reason; }
268

    
269
  int prologue_offset() const {
270
    ASSERT_NE(Code::kPrologueOffsetNotSet, prologue_offset_);
271
    return prologue_offset_;
272
  }
273

    
274
  void set_prologue_offset(int prologue_offset) {
275
    ASSERT_EQ(Code::kPrologueOffsetNotSet, prologue_offset_);
276
    prologue_offset_ = prologue_offset;
277
  }
278

    
279
  // Adds offset range [from, to) where fp register does not point
280
  // to the current frame base. Used in CPU profiler to detect stack
281
  // samples where top frame is not set up.
282
  inline void AddNoFrameRange(int from, int to) {
283
    if (no_frame_ranges_) no_frame_ranges_->Add(OffsetRange(from, to));
284
  }
285

    
286
  List<OffsetRange>* ReleaseNoFrameRanges() {
287
    List<OffsetRange>* result = no_frame_ranges_;
288
    no_frame_ranges_ = NULL;
289
    return result;
290
  }
291

    
292
  Handle<Foreign> object_wrapper() {
293
    if (object_wrapper_.is_null()) {
294
      object_wrapper_ =
295
          isolate()->factory()->NewForeign(reinterpret_cast<Address>(this));
296
    }
297
    return object_wrapper_;
298
  }
299

    
300
  void AbortDueToDependencyChange() {
301
    ASSERT(!isolate()->optimizing_compiler_thread()->IsOptimizerThread());
302
    abort_due_to_dependency_ = true;
303
  }
304

    
305
  bool HasAbortedDueToDependencyChange() {
306
    ASSERT(!isolate()->optimizing_compiler_thread()->IsOptimizerThread());
307
    return abort_due_to_dependency_;
308
  }
309

    
310
  void set_osr_pc_offset(uint32_t pc_offset) {
311
    osr_pc_offset_ = pc_offset;
312
  }
313

    
314
  bool HasSameOsrEntry(Handle<JSFunction> function, uint32_t pc_offset) {
315
    return osr_pc_offset_ == pc_offset && function.is_identical_to(closure_);
316
  }
317

    
318
 protected:
319
  CompilationInfo(Handle<Script> script,
320
                  Zone* zone);
321
  CompilationInfo(Handle<SharedFunctionInfo> shared_info,
322
                  Zone* zone);
323
  CompilationInfo(HydrogenCodeStub* stub,
324
                  Isolate* isolate,
325
                  Zone* zone);
326

    
327
 private:
328
  Isolate* isolate_;
329

    
330
  // Compilation mode.
331
  // BASE is generated by the full codegen, optionally prepared for bailouts.
332
  // OPTIMIZE is optimized code generated by the Hydrogen-based backend.
333
  // NONOPT is generated by the full codegen and is not prepared for
334
  //   recompilation/bailouts.  These functions are never recompiled.
335
  enum Mode {
336
    BASE,
337
    OPTIMIZE,
338
    NONOPT,
339
    STUB
340
  };
341

    
342
  void Initialize(Isolate* isolate, Mode mode, Zone* zone);
343

    
344
  void SetMode(Mode mode) {
345
    ASSERT(isolate()->use_crankshaft());
346
    mode_ = mode;
347
  }
348

    
349
  // Flags using template class BitField<type, start, length>.  All are
350
  // false by default.
351
  //
352
  // Compilation is either eager or lazy.
353
  class IsLazy:   public BitField<bool, 0, 1> {};
354
  // Flags that can be set for eager compilation.
355
  class IsEval:   public BitField<bool, 1, 1> {};
356
  class IsGlobal: public BitField<bool, 2, 1> {};
357
  // Flags that can be set for lazy compilation.
358
  class IsInLoop: public BitField<bool, 3, 1> {};
359
  // Strict mode - used in eager compilation.
360
  class LanguageModeField: public BitField<LanguageMode, 4, 2> {};
361
  // Is this a function from our natives.
362
  class IsNative: public BitField<bool, 6, 1> {};
363
  // Is this code being compiled with support for deoptimization..
364
  class SupportsDeoptimization: public BitField<bool, 7, 1> {};
365
  // If compiling for debugging produce just full code matching the
366
  // initial mode setting.
367
  class IsCompilingForDebugging: public BitField<bool, 8, 1> {};
368
  // If the compiled code contains calls that require building a frame
369
  class IsCalling: public BitField<bool, 9, 1> {};
370
  // If the compiled code contains calls that require building a frame
371
  class IsDeferredCalling: public BitField<bool, 10, 1> {};
372
  // If the compiled code contains calls that require building a frame
373
  class IsNonDeferredCalling: public BitField<bool, 11, 1> {};
374
  // If the compiled code saves double caller registers that it clobbers.
375
  class SavesCallerDoubles: public BitField<bool, 12, 1> {};
376
  // If the set of valid statements is restricted.
377
  class ParseRestricitonField: public BitField<ParseRestriction, 13, 1> {};
378
  // If the function requires a frame (for unspecified reasons)
379
  class RequiresFrame: public BitField<bool, 14, 1> {};
380

    
381
  unsigned flags_;
382

    
383
  // Fields filled in by the compilation pipeline.
384
  // AST filled in by the parser.
385
  FunctionLiteral* function_;
386
  // The scope of the function literal as a convenience.  Set to indicate
387
  // that scopes have been analyzed.
388
  Scope* scope_;
389
  // The global scope provided as a convenience.
390
  Scope* global_scope_;
391
  // For compiled stubs, the stub object
392
  HydrogenCodeStub* code_stub_;
393
  // The compiled code.
394
  Handle<Code> code_;
395

    
396
  // Possible initial inputs to the compilation process.
397
  Handle<JSFunction> closure_;
398
  Handle<SharedFunctionInfo> shared_info_;
399
  Handle<Script> script_;
400

    
401
  // Fields possibly needed for eager compilation, NULL by default.
402
  v8::Extension* extension_;
403
  ScriptDataImpl* pre_parse_data_;
404

    
405
  // The context of the caller for eval code, and the global context for a
406
  // global script. Will be a null handle otherwise.
407
  Handle<Context> context_;
408

    
409
  // Compilation mode flag and whether deoptimization is allowed.
410
  Mode mode_;
411
  BailoutId osr_ast_id_;
412
  // The pc_offset corresponding to osr_ast_id_ in unoptimized code.
413
  // We can look this up in the back edge table, but cache it for quick access.
414
  uint32_t osr_pc_offset_;
415

    
416
  // Flag whether compilation needs to be aborted due to dependency change.
417
  bool abort_due_to_dependency_;
418

    
419
  // The zone from which the compilation pipeline working on this
420
  // CompilationInfo allocates.
421
  Zone* zone_;
422

    
423
  DeferredHandles* deferred_handles_;
424

    
425
  ZoneList<Handle<HeapObject> >* dependencies_[DependentCode::kGroupCount];
426

    
427
  template<typename T>
428
  void SaveHandle(Handle<T> *object) {
429
    if (!object->is_null()) {
430
      Handle<T> handle(*(*object));
431
      *object = handle;
432
    }
433
  }
434

    
435
  BailoutReason bailout_reason_;
436

    
437
  int prologue_offset_;
438

    
439
  List<OffsetRange>* no_frame_ranges_;
440

    
441
  // A copy of shared_info()->opt_count() to avoid handle deref
442
  // during graph optimization.
443
  int opt_count_;
444

    
445
  Handle<Foreign> object_wrapper_;
446

    
447
  DISALLOW_COPY_AND_ASSIGN(CompilationInfo);
448
};
449

    
450

    
451
// Exactly like a CompilationInfo, except also creates and enters a
452
// Zone on construction and deallocates it on exit.
453
class CompilationInfoWithZone: public CompilationInfo {
454
 public:
455
  explicit CompilationInfoWithZone(Handle<Script> script)
456
      : CompilationInfo(script, &zone_),
457
        zone_(script->GetIsolate()) {}
458
  explicit CompilationInfoWithZone(Handle<SharedFunctionInfo> shared_info)
459
      : CompilationInfo(shared_info, &zone_),
460
        zone_(shared_info->GetIsolate()) {}
461
  explicit CompilationInfoWithZone(Handle<JSFunction> closure)
462
      : CompilationInfo(closure, &zone_),
463
        zone_(closure->GetIsolate()) {}
464
  CompilationInfoWithZone(HydrogenCodeStub* stub, Isolate* isolate)
465
      : CompilationInfo(stub, isolate, &zone_),
466
        zone_(isolate) {}
467

    
468
  // Virtual destructor because a CompilationInfoWithZone has to exit the
469
  // zone scope and get rid of dependent maps even when the destructor is
470
  // called when cast as a CompilationInfo.
471
  virtual ~CompilationInfoWithZone() {
472
    RollbackDependencies();
473
  }
474

    
475
 private:
476
  Zone zone_;
477
};
478

    
479

    
480
// A wrapper around a CompilationInfo that detaches the Handles from
481
// the underlying DeferredHandleScope and stores them in info_ on
482
// destruction.
483
class CompilationHandleScope BASE_EMBEDDED {
484
 public:
485
  explicit CompilationHandleScope(CompilationInfo* info)
486
      : deferred_(info->isolate()), info_(info) {}
487
  ~CompilationHandleScope() {
488
    info_->set_deferred_handles(deferred_.Detach());
489
  }
490

    
491
 private:
492
  DeferredHandleScope deferred_;
493
  CompilationInfo* info_;
494
};
495

    
496

    
497
class HGraph;
498
class HOptimizedGraphBuilder;
499
class LChunk;
500

    
501
// A helper class that calls the three compilation phases in
502
// Crankshaft and keeps track of its state.  The three phases
503
// CreateGraph, OptimizeGraph and GenerateAndInstallCode can either
504
// fail, bail-out to the full code generator or succeed.  Apart from
505
// their return value, the status of the phase last run can be checked
506
// using last_status().
507
class RecompileJob: public ZoneObject {
508
 public:
509
  explicit RecompileJob(CompilationInfo* info)
510
      : info_(info),
511
        graph_builder_(NULL),
512
        graph_(NULL),
513
        chunk_(NULL),
514
        last_status_(FAILED),
515
        awaiting_install_(false) { }
516

    
517
  enum Status {
518
    FAILED, BAILED_OUT, SUCCEEDED
519
  };
520

    
521
  MUST_USE_RESULT Status CreateGraph();
522
  MUST_USE_RESULT Status OptimizeGraph();
523
  MUST_USE_RESULT Status GenerateAndInstallCode();
524

    
525
  Status last_status() const { return last_status_; }
526
  CompilationInfo* info() const { return info_; }
527
  Isolate* isolate() const { return info()->isolate(); }
528

    
529
  MUST_USE_RESULT Status AbortOptimization() {
530
    info_->AbortOptimization();
531
    info_->shared_info()->DisableOptimization(info_->bailout_reason());
532
    return SetLastStatus(BAILED_OUT);
533
  }
534

    
535
  void WaitForInstall() {
536
    ASSERT(info_->is_osr());
537
    awaiting_install_ = true;
538
  }
539

    
540
  bool IsWaitingForInstall() { return awaiting_install_; }
541

    
542
 private:
543
  CompilationInfo* info_;
544
  HOptimizedGraphBuilder* graph_builder_;
545
  HGraph* graph_;
546
  LChunk* chunk_;
547
  TimeDelta time_taken_to_create_graph_;
548
  TimeDelta time_taken_to_optimize_;
549
  TimeDelta time_taken_to_codegen_;
550
  Status last_status_;
551
  bool awaiting_install_;
552

    
553
  MUST_USE_RESULT Status SetLastStatus(Status status) {
554
    last_status_ = status;
555
    return last_status_;
556
  }
557
  void RecordOptimizationStats();
558

    
559
  struct Timer {
560
    Timer(RecompileJob* job, TimeDelta* location)
561
        : job_(job), location_(location) {
562
      ASSERT(location_ != NULL);
563
      timer_.Start();
564
    }
565

    
566
    ~Timer() {
567
      *location_ += timer_.Elapsed();
568
    }
569

    
570
    RecompileJob* job_;
571
    ElapsedTimer timer_;
572
    TimeDelta* location_;
573
  };
574
};
575

    
576

    
577
// The V8 compiler
578
//
579
// General strategy: Source code is translated into an anonymous function w/o
580
// parameters which then can be executed. If the source code contains other
581
// functions, they will be compiled and allocated as part of the compilation
582
// of the source code.
583

    
584
// Please note this interface returns shared function infos.  This means you
585
// need to call Factory::NewFunctionFromSharedFunctionInfo before you have a
586
// real function with a context.
587

    
588
class Compiler : public AllStatic {
589
 public:
590
  // Call count before primitive functions trigger their own optimization.
591
  static const int kCallsUntilPrimitiveOpt = 200;
592

    
593
  // All routines return a SharedFunctionInfo.
594
  // If an error occurs an exception is raised and the return handle
595
  // contains NULL.
596

    
597
  // Compile a String source within a context.
598
  static Handle<SharedFunctionInfo> Compile(Handle<String> source,
599
                                            Handle<Object> script_name,
600
                                            int line_offset,
601
                                            int column_offset,
602
                                            bool is_shared_cross_origin,
603
                                            Handle<Context> context,
604
                                            v8::Extension* extension,
605
                                            ScriptDataImpl* pre_data,
606
                                            Handle<Object> script_data,
607
                                            NativesFlag is_natives_code);
608

    
609
  // Compile a String source within a context for Eval.
610
  static Handle<SharedFunctionInfo> CompileEval(Handle<String> source,
611
                                                Handle<Context> context,
612
                                                bool is_global,
613
                                                LanguageMode language_mode,
614
                                                ParseRestriction restriction,
615
                                                int scope_position);
616

    
617
  // Compile from function info (used for lazy compilation). Returns true on
618
  // success and false if the compilation resulted in a stack overflow.
619
  static bool CompileLazy(CompilationInfo* info);
620

    
621
  static bool RecompileConcurrent(Handle<JSFunction> function,
622
                                  uint32_t osr_pc_offset = 0);
623

    
624
  // Compile a shared function info object (the function is possibly lazily
625
  // compiled).
626
  static Handle<SharedFunctionInfo> BuildFunctionInfo(FunctionLiteral* node,
627
                                                      Handle<Script> script);
628

    
629
  // Set the function info for a newly compiled function.
630
  static void SetFunctionInfo(Handle<SharedFunctionInfo> function_info,
631
                              FunctionLiteral* lit,
632
                              bool is_toplevel,
633
                              Handle<Script> script);
634

    
635
  static Handle<Code> InstallOptimizedCode(RecompileJob* job);
636

    
637
#ifdef ENABLE_DEBUGGER_SUPPORT
638
  static bool MakeCodeForLiveEdit(CompilationInfo* info);
639
#endif
640

    
641
  static void RecordFunctionCompilation(Logger::LogEventsAndTags tag,
642
                                        CompilationInfo* info,
643
                                        Handle<SharedFunctionInfo> shared);
644
};
645

    
646

    
647
class CompilationPhase BASE_EMBEDDED {
648
 public:
649
  CompilationPhase(const char* name, CompilationInfo* info);
650
  ~CompilationPhase();
651

    
652
 protected:
653
  bool ShouldProduceTraceOutput() const;
654

    
655
  const char* name() const { return name_; }
656
  CompilationInfo* info() const { return info_; }
657
  Isolate* isolate() const { return info()->isolate(); }
658
  Zone* zone() { return &zone_; }
659

    
660
 private:
661
  const char* name_;
662
  CompilationInfo* info_;
663
  Zone zone_;
664
  unsigned info_zone_start_allocation_size_;
665
  ElapsedTimer timer_;
666

    
667
  DISALLOW_COPY_AND_ASSIGN(CompilationPhase);
668
};
669

    
670

    
671
} }  // namespace v8::internal
672

    
673
#endif  // V8_COMPILER_H_