9 #if V8_TARGET_ARCH_IA32
12 #elif V8_TARGET_ARCH_X64
15 #elif V8_TARGET_ARCH_ARM
18 #elif V8_TARGET_ARCH_ARM64
21 #elif V8_TARGET_ARCH_MIPS
24 #elif V8_TARGET_ARCH_MIPS64
27 #elif V8_TARGET_ARCH_X87
31 #error Unsupported target architecture.
38 HGraph* LCodeGenBase::graph()
const {
39 return chunk()->graph();
43 LCodeGenBase::LCodeGenBase(LChunk* chunk,
44 MacroAssembler* assembler,
45 CompilationInfo* info)
46 : chunk_(static_cast<LPlatformChunk*>(chunk)),
52 current_instruction_(-1),
53 instructions_(chunk->instructions()),
54 last_lazy_deopt_pc_(0) {
58 bool LCodeGenBase::GenerateBody() {
60 bool emit_instructions =
true;
61 LCodeGen* codegen =
static_cast<LCodeGen*
>(
this);
62 for (current_instruction_ = 0;
63 !is_aborted() && current_instruction_ < instructions_->length();
64 current_instruction_++) {
65 LInstruction* instr = instructions_->at(current_instruction_);
68 if (instr->IsLabel()) {
69 emit_instructions = !LLabel::cast(instr)->HasReplacement() &&
70 (!FLAG_unreachable_code_elimination ||
71 instr->hydrogen_value()->block()->IsReachable());
72 if (FLAG_code_comments && !emit_instructions) {
74 ";;; <@%d,#%d> -------------------- B%d (unreachable/replaced) "
75 "--------------------",
77 instr->hydrogen_value()->id(),
78 instr->hydrogen_value()->block()->block_id());
81 if (!emit_instructions)
continue;
83 if (FLAG_code_comments && instr->HasInterestingComment(codegen)) {
84 Comment(
";;; <@%d,#%d> %s",
86 instr->hydrogen_value()->id(),
90 GenerateBodyInstructionPre(instr);
92 HValue* value = instr->hydrogen_value();
93 if (!value->position().IsUnknown()) {
94 RecordAndWritePosition(
95 chunk()->graph()->SourcePositionToScriptPosition(value->position()));
98 instr->CompileToNative(codegen);
100 GenerateBodyInstructionPost(instr);
102 EnsureSpaceForLazyDeopt(Deoptimizer::patch_size());
103 last_lazy_deopt_pc_ = masm()->pc_offset();
104 return !is_aborted();
108 void LCodeGenBase::CheckEnvironmentUsage() {
110 bool dead_block =
false;
111 for (
int i = 0;
i < instructions_->length();
i++) {
112 LInstruction* instr = instructions_->at(
i);
113 HValue* hval = instr->hydrogen_value();
114 if (instr->IsLabel()) dead_block = LLabel::cast(instr)->HasReplacement();
115 if (dead_block || !hval->block()->IsReachable())
continue;
117 HInstruction* hinstr = HInstruction::cast(hval);
118 if (!hinstr->CanDeoptimize() && instr->HasEnvironment()) {
119 V8_Fatal(__FILE__, __LINE__,
"CanDeoptimize is wrong for %s (%s)",
120 hinstr->Mnemonic(), instr->Mnemonic());
123 if (instr->HasEnvironment() && !instr->environment()->has_been_used()) {
124 V8_Fatal(__FILE__, __LINE__,
"unused environment for %s (%s)",
125 hinstr->Mnemonic(), instr->Mnemonic());
132 void LCodeGenBase::Comment(
const char* format, ...) {
133 if (!FLAG_code_comments)
return;
135 StringBuilder builder(buffer,
arraysize(buffer));
137 va_start(arguments, format);
138 builder.AddFormattedList(format, arguments);
143 size_t length = builder.position();
145 MemCopy(copy.start(), builder.Finalize(), copy.length());
146 masm()->RecordComment(copy.start());
150 void LCodeGenBase::DeoptComment(
const Deoptimizer::Reason& reason) {
152 os <<
";;; deoptimize at " << HSourcePosition(reason.raw_position) <<
" "
154 if (reason.detail !=
NULL) os <<
": " << reason.detail;
155 Comment(
"%s", os.c_str());
159 int LCodeGenBase::GetNextEmittedBlock()
const {
160 for (
int i = current_block_ + 1;
i < graph()->blocks()->length(); ++
i) {
161 if (!graph()->blocks()->at(
i)->IsReachable())
continue;
162 if (!chunk_->GetLabel(
i)->HasReplacement())
return i;
174 dep = DependentCode::Insert(dep, DependentCode::kWeakCodeGroup, code);
179 void LCodeGenBase::RegisterWeakObjectsInOptimizedCode(
Handle<Code> code) {
180 DCHECK(code->is_optimized_code());
181 ZoneList<Handle<Map> > maps(1, zone());
182 ZoneList<Handle<JSObject> > objects(1, zone());
183 ZoneList<Handle<Cell> > cells(1, zone());
184 int mode_mask = RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT) |
185 RelocInfo::ModeMask(RelocInfo::CELL);
186 for (RelocIterator it(*code, mode_mask); !it.done(); it.next()) {
187 RelocInfo::Mode
mode = it.rinfo()->rmode();
188 if (
mode == RelocInfo::CELL &&
189 code->IsWeakObjectInOptimizedCode(it.rinfo()->target_cell())) {
191 cells.Add(cell, zone());
192 }
else if (
mode == RelocInfo::EMBEDDED_OBJECT &&
193 code->IsWeakObjectInOptimizedCode(it.rinfo()->target_object())) {
194 if (it.rinfo()->target_object()->IsMap()) {
195 Handle<Map>
map(Map::cast(it.rinfo()->target_object()));
196 maps.Add(
map, zone());
197 }
else if (it.rinfo()->target_object()->IsJSObject()) {
198 Handle<JSObject> object(JSObject::cast(it.rinfo()->target_object()));
199 objects.Add(
object, zone());
200 }
else if (it.rinfo()->target_object()->IsCell()) {
201 Handle<Cell> cell(Cell::cast(it.rinfo()->target_object()));
202 cells.Add(cell, zone());
206 if (FLAG_enable_ool_constant_pool) {
207 code->constant_pool()->set_weak_object_state(
208 ConstantPoolArray::WEAK_OBJECTS_IN_OPTIMIZED_CODE);
214 NoWeakObjectVerificationScope disable_verification_of_embedded_objects;
216 for (
int i = 0;
i < maps.length();
i++) {
217 Map::AddDependentCode(maps.at(
i), DependentCode::kWeakCodeGroup, code);
219 for (
int i = 0;
i < objects.length();
i++) {
222 for (
int i = 0;
i < cells.length();
i++) {
229 info()->AbortOptimization(reason);
235 info()->RetryOptimization(reason);
240 void LCodeGenBase::AddDeprecationDependency(Handle<Map>
map) {
241 if (
map->is_deprecated())
return Retry(kMapBecameDeprecated);
242 chunk_->AddDeprecationDependency(
map);
246 void LCodeGenBase::AddStabilityDependency(Handle<Map>
map) {
247 if (!
map->is_stable())
return Retry(kMapBecameUnstable);
248 chunk_->AddStabilityDependency(
map);
An object reference managed by the v8 garbage collector.
void AddWeakObjectToCodeDependency(Handle< Object > obj, Handle< DependentCode > dep)
void EnsureWeakObjectToCodeTable()
DependentCode * LookupWeakObjectToCodeDependency(Handle< Object > obj)
static Vector< char > New(int length)
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf map
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS 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_BOOL(enable_always_align_csp
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS 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 enable alignment of csp to bytes on platforms which prefer the register to always be NULL
void V8_Fatal(const char *file, int line, const char *format,...)
#define DCHECK(condition)
static void AddWeakObjectToCodeDependency(Isolate *isolate, Handle< Object > object, Handle< Code > code)
void MemCopy(void *dest, const void *src, size_t size)
Debugger support for the V8 JavaScript engine.