v8  3.25.30(node0.11.13)
V8 is Google's open source JavaScript engine
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
lithium-codegen.cc
Go to the documentation of this file.
1 // Copyright 2013 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 #include "v8.h"
29 
30 #include "lithium-codegen.h"
31 
32 #if V8_TARGET_ARCH_IA32
33 #include "ia32/lithium-ia32.h"
35 #elif V8_TARGET_ARCH_X64
36 #include "x64/lithium-x64.h"
38 #elif V8_TARGET_ARCH_ARM
39 #include "arm/lithium-arm.h"
41 #elif V8_TARGET_ARCH_ARM64
42 #include "arm64/lithium-arm64.h"
44 #elif V8_TARGET_ARCH_MIPS
45 #include "mips/lithium-mips.h"
47 #else
48 #error Unsupported target architecture.
49 #endif
50 
51 namespace v8 {
52 namespace internal {
53 
54 
55 HGraph* LCodeGenBase::graph() const {
56  return chunk()->graph();
57 }
58 
59 
60 LCodeGenBase::LCodeGenBase(LChunk* chunk,
61  MacroAssembler* assembler,
62  CompilationInfo* info)
63  : chunk_(static_cast<LPlatformChunk*>(chunk)),
64  masm_(assembler),
65  info_(info),
66  zone_(info->zone()),
67  status_(UNUSED),
68  current_block_(-1),
69  current_instruction_(-1),
70  instructions_(chunk->instructions()),
71  last_lazy_deopt_pc_(0) {
72 }
73 
74 
75 bool LCodeGenBase::GenerateBody() {
76  ASSERT(is_generating());
77  bool emit_instructions = true;
78  LCodeGen* codegen = static_cast<LCodeGen*>(this);
79  for (current_instruction_ = 0;
80  !is_aborted() && current_instruction_ < instructions_->length();
81  current_instruction_++) {
82  LInstruction* instr = instructions_->at(current_instruction_);
83 
84  // Don't emit code for basic blocks with a replacement.
85  if (instr->IsLabel()) {
86  emit_instructions = !LLabel::cast(instr)->HasReplacement() &&
87  (!FLAG_unreachable_code_elimination ||
88  instr->hydrogen_value()->block()->IsReachable());
89  if (FLAG_code_comments && !emit_instructions) {
90  Comment(
91  ";;; <@%d,#%d> -------------------- B%d (unreachable/replaced) "
92  "--------------------",
93  current_instruction_,
94  instr->hydrogen_value()->id(),
95  instr->hydrogen_value()->block()->block_id());
96  }
97  }
98  if (!emit_instructions) continue;
99 
100  if (FLAG_code_comments && instr->HasInterestingComment(codegen)) {
101  Comment(";;; <@%d,#%d> %s",
102  current_instruction_,
103  instr->hydrogen_value()->id(),
104  instr->Mnemonic());
105  }
106 
107  GenerateBodyInstructionPre(instr);
108 
109  HValue* value = instr->hydrogen_value();
110  if (!value->position().IsUnknown()) {
111  RecordAndWritePosition(
112  chunk()->graph()->SourcePositionToScriptPosition(value->position()));
113  }
114 
115  instr->CompileToNative(codegen);
116 
117  GenerateBodyInstructionPost(instr);
118  }
119  EnsureSpaceForLazyDeopt(Deoptimizer::patch_size());
120  last_lazy_deopt_pc_ = masm()->pc_offset();
121  return !is_aborted();
122 }
123 
124 
125 void LCodeGenBase::Comment(const char* format, ...) {
126  if (!FLAG_code_comments) return;
127  char buffer[4 * KB];
128  StringBuilder builder(buffer, ARRAY_SIZE(buffer));
129  va_list arguments;
130  va_start(arguments, format);
131  builder.AddFormattedList(format, arguments);
132  va_end(arguments);
133 
134  // Copy the string before recording it in the assembler to avoid
135  // issues when the stack allocated buffer goes out of scope.
136  size_t length = builder.position();
137  Vector<char> copy = Vector<char>::New(static_cast<int>(length) + 1);
138  OS::MemCopy(copy.start(), builder.Finalize(), copy.length());
139  masm()->RecordComment(copy.start());
140 }
141 
142 
143 int LCodeGenBase::GetNextEmittedBlock() const {
144  for (int i = current_block_ + 1; i < graph()->blocks()->length(); ++i) {
145  if (!graph()->blocks()->at(i)->IsReachable()) continue;
146  if (!chunk_->GetLabel(i)->HasReplacement()) return i;
147  }
148  return -1;
149 }
150 
151 
152 void LCodeGenBase::RegisterWeakObjectsInOptimizedCode(Handle<Code> code) {
153  ASSERT(code->is_optimized_code());
154  ZoneList<Handle<Map> > maps(1, zone());
155  ZoneList<Handle<JSObject> > objects(1, zone());
156  ZoneList<Handle<Cell> > cells(1, zone());
157  int mode_mask = RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT) |
158  RelocInfo::ModeMask(RelocInfo::CELL);
159  for (RelocIterator it(*code, mode_mask); !it.done(); it.next()) {
160  RelocInfo::Mode mode = it.rinfo()->rmode();
161  if (mode == RelocInfo::CELL &&
162  code->IsWeakObjectInOptimizedCode(it.rinfo()->target_cell())) {
163  Handle<Cell> cell(it.rinfo()->target_cell());
164  cells.Add(cell, zone());
165  } else if (mode == RelocInfo::EMBEDDED_OBJECT &&
166  code->IsWeakObjectInOptimizedCode(it.rinfo()->target_object())) {
167  if (it.rinfo()->target_object()->IsMap()) {
168  Handle<Map> map(Map::cast(it.rinfo()->target_object()));
169  maps.Add(map, zone());
170  } else if (it.rinfo()->target_object()->IsJSObject()) {
171  Handle<JSObject> object(JSObject::cast(it.rinfo()->target_object()));
172  objects.Add(object, zone());
173  } else if (it.rinfo()->target_object()->IsCell()) {
174  Handle<Cell> cell(Cell::cast(it.rinfo()->target_object()));
175  cells.Add(cell, zone());
176  }
177  }
178  }
179 #ifdef VERIFY_HEAP
180  // This disables verification of weak embedded objects after full GC.
181  // AddDependentCode can cause a GC, which would observe the state where
182  // this code is not yet in the depended code lists of the embedded maps.
183  NoWeakObjectVerificationScope disable_verification_of_embedded_objects;
184 #endif
185  for (int i = 0; i < maps.length(); i++) {
186  maps.at(i)->AddDependentCode(DependentCode::kWeaklyEmbeddedGroup, code);
187  }
188  for (int i = 0; i < objects.length(); i++) {
189  AddWeakObjectToCodeDependency(isolate()->heap(), objects.at(i), code);
190  }
191  for (int i = 0; i < cells.length(); i++) {
192  AddWeakObjectToCodeDependency(isolate()->heap(), cells.at(i), code);
193  }
194 }
195 
196 
197 } } // namespace v8::internal
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter trace hydrogen to given file name trace inlining decisions trace store elimination trace all use positions trace global value numbering trace hydrogen escape analysis trace the tracking of allocation sites trace map generalization environment for every instruction deoptimize every n garbage collections put a break point before deoptimizing deoptimize uncommon cases use on stack replacement trace array bounds check elimination perform array index dehoisting use load elimination use store elimination use constant folding eliminate unreachable code number of stress runs when picking a function to watch for shared function not JSFunction itself flushes the cache of optimized code for closures on every GC functions with arguments object maximum number of escape analysis fix point iterations allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms concurrent on stack replacement do not emit check maps for constant values that have a leaf map
Definition: flags.cc:350
const int KB
Definition: globals.h:245
static Map * cast(Object *obj)
#define ASSERT(condition)
Definition: checks.h:329
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter trace hydrogen to given file name trace inlining decisions trace store elimination trace all use positions trace global value numbering trace hydrogen escape analysis trace the tracking of allocation sites trace map generalization environment for every instruction deoptimize every n garbage collections put a break point before deoptimizing deoptimize uncommon cases use on stack replacement trace array bounds check elimination perform array index dehoisting use load elimination use store elimination use constant folding eliminate unreachable code number of stress runs when picking a function to watch for shared function not JSFunction itself flushes the cache of optimized code for closures on every GC functions with arguments object maximum number of escape analysis fix point iterations allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms concurrent on stack replacement do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes number of stack frames inspected by the profiler percentage of ICs that must have type info to allow optimization extra verbose compilation tracing generate extra emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long mode(MIPS only)") DEFINE_string(expose_natives_as
static Cell * cast(Object *obj)
static void MemCopy(void *dest, const void *src, size_t size)
Definition: platform.h:399
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter trace hydrogen to given file name trace inlining decisions trace store elimination trace all use positions trace global value numbering trace hydrogen escape analysis trace the tracking of allocation sites trace map generalization environment for every instruction deoptimize every n garbage collections put a break point before deoptimizing deoptimize uncommon cases use on stack replacement trace array bounds check elimination perform array index dehoisting use load elimination use store elimination use constant folding eliminate unreachable code number of stress runs when picking a function to watch for shared function not JSFunction itself flushes the cache of optimized code for closures on every GC functions with arguments object maximum number of escape analysis fix point iterations allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms concurrent on stack replacement do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes number of stack frames inspected by the profiler percentage of ICs that must have type info to allow optimization extra verbose compilation tracing generate extra code(assertions) for debugging") DEFINE_bool(code_comments
static Vector< T > New(int length)
Definition: utils.h:406
void AddWeakObjectToCodeDependency(Heap *heap, Handle< Object > object, Handle< Code > code)
Definition: handles.cc:765
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter trace hydrogen to given file name trace inlining decisions trace store elimination trace all use positions trace global value numbering trace hydrogen escape analysis trace the tracking of allocation sites trace map generalization environment for every instruction deoptimize every n garbage collections put a break point before deoptimizing deoptimize uncommon cases use on stack replacement trace array bounds check elimination perform array index dehoisting use load elimination use store elimination use constant folding eliminate unreachable code number of stress runs when picking a function to watch for shared function info
Definition: flags.cc:317
#define ARRAY_SIZE(a)
Definition: globals.h:333
static JSObject * cast(Object *obj)