OLD | NEW |
1 // Copyright 2017 the V8 project authors. All rights reserved. | 1 // Copyright 2017 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/wasm/wasm-code-specialization.h" | 5 #include "src/wasm/wasm-code-specialization.h" |
6 | 6 |
7 #include "src/assembler-inl.h" | 7 #include "src/assembler-inl.h" |
8 #include "src/objects-inl.h" | 8 #include "src/objects-inl.h" |
9 #include "src/source-position-table.h" | 9 #include "src/source-position-table.h" |
10 #include "src/wasm/decoder.h" | 10 #include "src/wasm/decoder.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 SourcePositionTableIterator source_pos_it; | 54 SourcePositionTableIterator source_pos_it; |
55 Decoder decoder; | 55 Decoder decoder; |
56 const byte* func_bytes; | 56 const byte* func_bytes; |
57 }; | 57 }; |
58 | 58 |
59 bool IsAtWasmDirectCallTarget(RelocIterator& it) { | 59 bool IsAtWasmDirectCallTarget(RelocIterator& it) { |
60 DCHECK(RelocInfo::IsCodeTarget(it.rinfo()->rmode())); | 60 DCHECK(RelocInfo::IsCodeTarget(it.rinfo()->rmode())); |
61 Code* code = Code::GetCodeFromTargetAddress(it.rinfo()->target_address()); | 61 Code* code = Code::GetCodeFromTargetAddress(it.rinfo()->target_address()); |
62 return code->kind() == Code::WASM_FUNCTION || | 62 return code->kind() == Code::WASM_FUNCTION || |
63 code->kind() == Code::WASM_TO_JS_FUNCTION || | 63 code->kind() == Code::WASM_TO_JS_FUNCTION || |
64 code->builtin_index() == Builtins::kIllegal; | 64 code->builtin_index() == Builtins::kIllegal || |
| 65 code->builtin_index() == Builtins::kWasmCompileLazy; |
65 } | 66 } |
66 | 67 |
67 } // namespace | 68 } // namespace |
68 | 69 |
69 CodeSpecialization::CodeSpecialization(Isolate* isolate, Zone* zone) | 70 CodeSpecialization::CodeSpecialization(Isolate* isolate, Zone* zone) |
70 : objects_to_relocate(isolate->heap(), ZoneAllocationPolicy(zone)) {} | 71 : objects_to_relocate(isolate->heap(), ZoneAllocationPolicy(zone)) {} |
71 | 72 |
72 CodeSpecialization::~CodeSpecialization() {} | 73 CodeSpecialization::~CodeSpecialization() {} |
73 | 74 |
74 void CodeSpecialization::RelocateMemoryReferences(Address old_start, | 75 void CodeSpecialization::RelocateMemoryReferences(Address old_start, |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 compiled_module->module()->num_exported_functions, | 125 compiled_module->module()->num_exported_functions, |
125 code_table->length()); | 126 code_table->length()); |
126 | 127 |
127 bool changed = false; | 128 bool changed = false; |
128 int func_index = module->num_imported_functions; | 129 int func_index = module->num_imported_functions; |
129 | 130 |
130 // Patch all wasm functions. | 131 // Patch all wasm functions. |
131 for (int num_wasm_functions = static_cast<int>(wasm_functions->size()); | 132 for (int num_wasm_functions = static_cast<int>(wasm_functions->size()); |
132 func_index < num_wasm_functions; ++func_index) { | 133 func_index < num_wasm_functions; ++func_index) { |
133 Code* wasm_function = Code::cast(code_table->get(func_index)); | 134 Code* wasm_function = Code::cast(code_table->get(func_index)); |
| 135 if (wasm_function->builtin_index() == Builtins::kWasmCompileLazy) continue; |
134 changed |= ApplyToWasmCode(wasm_function, icache_flush_mode); | 136 changed |= ApplyToWasmCode(wasm_function, icache_flush_mode); |
135 } | 137 } |
136 | 138 |
137 // Patch all exported functions. | 139 // Patch all exported functions. |
138 for (auto exp : module->export_table) { | 140 for (auto exp : module->export_table) { |
139 if (exp.kind != kExternalFunction) continue; | 141 if (exp.kind != kExternalFunction) continue; |
140 Code* export_wrapper = Code::cast(code_table->get(func_index)); | 142 Code* export_wrapper = Code::cast(code_table->get(func_index)); |
141 DCHECK_EQ(Code::JS_TO_WASM_FUNCTION, export_wrapper->kind()); | 143 DCHECK_EQ(Code::JS_TO_WASM_FUNCTION, export_wrapper->kind()); |
142 // There must be exactly one call to WASM_FUNCTION or WASM_TO_JS_FUNCTION. | 144 // There must be exactly one call to WASM_FUNCTION or WASM_TO_JS_FUNCTION. |
143 for (RelocIterator it(export_wrapper, | 145 for (RelocIterator it(export_wrapper, |
144 RelocInfo::ModeMask(RelocInfo::CODE_TARGET)); | 146 RelocInfo::ModeMask(RelocInfo::CODE_TARGET)); |
145 ; it.next()) { | 147 ; it.next()) { |
146 DCHECK(!it.done()); | 148 DCHECK(!it.done()); |
147 // Ignore calls to other builtins like ToNumber. | 149 // Ignore calls to other builtins like ToNumber. |
148 if (!IsAtWasmDirectCallTarget(it)) continue; | 150 if (!IsAtWasmDirectCallTarget(it)) continue; |
149 Code* new_code = Code::cast(code_table->get(exp.index)); | 151 Code* new_code = Code::cast(code_table->get(exp.index)); |
150 DCHECK(new_code->kind() == Code::WASM_FUNCTION || | |
151 new_code->kind() == Code::WASM_TO_JS_FUNCTION); | |
152 it.rinfo()->set_target_address(new_code->instruction_start(), | 152 it.rinfo()->set_target_address(new_code->instruction_start(), |
153 UPDATE_WRITE_BARRIER, SKIP_ICACHE_FLUSH); | 153 UPDATE_WRITE_BARRIER, SKIP_ICACHE_FLUSH); |
154 break; | 154 break; |
155 } | 155 } |
156 changed = true; | 156 changed = true; |
157 func_index++; | 157 func_index++; |
158 } | 158 } |
159 DCHECK_EQ(code_table->length(), func_index); | 159 DCHECK_EQ(code_table->length(), func_index); |
160 return changed; | 160 return changed; |
161 } | 161 } |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 icache_flush_mode); | 251 icache_flush_mode); |
252 changed = true; | 252 changed = true; |
253 break; | 253 break; |
254 default: | 254 default: |
255 UNREACHABLE(); | 255 UNREACHABLE(); |
256 } | 256 } |
257 } | 257 } |
258 | 258 |
259 return changed; | 259 return changed; |
260 } | 260 } |
OLD | NEW |