Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(761)

Side by Side Diff: src/wasm/wasm-code-specialization.cc

Issue 2735103003: Merged: [wasm] Fix code specialization for empty memory buffer (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/assembler.cc ('k') | src/wasm/wasm-module.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 60
61 CodeSpecialization::CodeSpecialization(Isolate* isolate, Zone* zone) 61 CodeSpecialization::CodeSpecialization(Isolate* isolate, Zone* zone)
62 : objects_to_relocate(isolate->heap(), ZoneAllocationPolicy(zone)) {} 62 : objects_to_relocate(isolate->heap(), ZoneAllocationPolicy(zone)) {}
63 63
64 CodeSpecialization::~CodeSpecialization() {} 64 CodeSpecialization::~CodeSpecialization() {}
65 65
66 void CodeSpecialization::RelocateMemoryReferences(Address old_start, 66 void CodeSpecialization::RelocateMemoryReferences(Address old_start,
67 uint32_t old_size, 67 uint32_t old_size,
68 Address new_start, 68 Address new_start,
69 uint32_t new_size) { 69 uint32_t new_size) {
70 DCHECK(old_mem_start == 0 && new_mem_start == 0); 70 DCHECK(old_mem_start == nullptr && old_mem_size == 0 &&
71 DCHECK(old_start != 0 || new_start != 0); 71 new_mem_start == nullptr && new_mem_size == 0);
72 DCHECK(old_start != new_start || old_size != new_size);
72 old_mem_start = old_start; 73 old_mem_start = old_start;
73 old_mem_size = old_size; 74 old_mem_size = old_size;
74 new_mem_start = new_start; 75 new_mem_start = new_start;
75 new_mem_size = new_size; 76 new_mem_size = new_size;
76 } 77 }
77 78
78 void CodeSpecialization::RelocateGlobals(Address old_start, Address new_start) { 79 void CodeSpecialization::RelocateGlobals(Address old_start, Address new_start) {
79 DCHECK(old_globals_start == 0 && new_globals_start == 0); 80 DCHECK(old_globals_start == 0 && new_globals_start == 0);
80 DCHECK(old_start != 0 || new_start != 0); 81 DCHECK(old_start != 0 || new_start != 0);
81 old_globals_start = old_start; 82 old_globals_start = old_start;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 } 156 }
156 DCHECK_EQ(code_table->length(), func_index); 157 DCHECK_EQ(code_table->length(), func_index);
157 return changed; 158 return changed;
158 } 159 }
159 160
160 bool CodeSpecialization::ApplyToWasmCode(Code* code, 161 bool CodeSpecialization::ApplyToWasmCode(Code* code,
161 ICacheFlushMode icache_flush_mode) { 162 ICacheFlushMode icache_flush_mode) {
162 DisallowHeapAllocation no_gc; 163 DisallowHeapAllocation no_gc;
163 DCHECK_EQ(Code::WASM_FUNCTION, code->kind()); 164 DCHECK_EQ(Code::WASM_FUNCTION, code->kind());
164 165
165 bool reloc_mem = old_mem_start || new_mem_start; 166 bool reloc_mem_addr = old_mem_start != new_mem_start;
167 bool reloc_mem_size = old_mem_size != new_mem_size;
166 bool reloc_globals = old_globals_start || new_globals_start; 168 bool reloc_globals = old_globals_start || new_globals_start;
167 bool patch_table_size = old_function_table_size || new_function_table_size; 169 bool patch_table_size = old_function_table_size || new_function_table_size;
168 bool reloc_direct_calls = !relocate_direct_calls_instance.is_null(); 170 bool reloc_direct_calls = !relocate_direct_calls_instance.is_null();
169 bool reloc_objects = has_objects_to_relocate; 171 bool reloc_objects = has_objects_to_relocate;
170 172
171 int reloc_mode = 0; 173 int reloc_mode = 0;
172 auto add_mode = [&reloc_mode](bool cond, RelocInfo::Mode mode) { 174 auto add_mode = [&reloc_mode](bool cond, RelocInfo::Mode mode) {
173 if (cond) reloc_mode |= RelocInfo::ModeMask(mode); 175 if (cond) reloc_mode |= RelocInfo::ModeMask(mode);
174 }; 176 };
175 add_mode(reloc_mem, RelocInfo::WASM_MEMORY_REFERENCE); 177 add_mode(reloc_mem_addr, RelocInfo::WASM_MEMORY_REFERENCE);
176 add_mode(reloc_mem, RelocInfo::WASM_MEMORY_SIZE_REFERENCE); 178 add_mode(reloc_mem_size, RelocInfo::WASM_MEMORY_SIZE_REFERENCE);
177 add_mode(reloc_globals, RelocInfo::WASM_GLOBAL_REFERENCE); 179 add_mode(reloc_globals, RelocInfo::WASM_GLOBAL_REFERENCE);
178 add_mode(patch_table_size, RelocInfo::WASM_FUNCTION_TABLE_SIZE_REFERENCE); 180 add_mode(patch_table_size, RelocInfo::WASM_FUNCTION_TABLE_SIZE_REFERENCE);
179 add_mode(reloc_direct_calls, RelocInfo::CODE_TARGET); 181 add_mode(reloc_direct_calls, RelocInfo::CODE_TARGET);
180 add_mode(reloc_objects, RelocInfo::EMBEDDED_OBJECT); 182 add_mode(reloc_objects, RelocInfo::EMBEDDED_OBJECT);
181 183
182 std::unique_ptr<PatchDirectCallsHelper> patch_direct_calls_helper; 184 std::unique_ptr<PatchDirectCallsHelper> patch_direct_calls_helper;
183 bool changed = false; 185 bool changed = false;
184 186
185 for (RelocIterator it(code, reloc_mode); !it.done(); it.next()) { 187 for (RelocIterator it(code, reloc_mode); !it.done(); it.next()) {
186 RelocInfo::Mode mode = it.rinfo()->rmode(); 188 RelocInfo::Mode mode = it.rinfo()->rmode();
187 switch (mode) { 189 switch (mode) {
188 case RelocInfo::WASM_MEMORY_REFERENCE: 190 case RelocInfo::WASM_MEMORY_REFERENCE:
191 DCHECK(reloc_mem_addr);
192 it.rinfo()->update_wasm_memory_reference(old_mem_start, new_mem_start,
193 icache_flush_mode);
194 changed = true;
195 break;
189 case RelocInfo::WASM_MEMORY_SIZE_REFERENCE: 196 case RelocInfo::WASM_MEMORY_SIZE_REFERENCE:
190 DCHECK(reloc_mem); 197 DCHECK(reloc_mem_size);
191 it.rinfo()->update_wasm_memory_reference(old_mem_start, new_mem_start, 198 it.rinfo()->update_wasm_memory_size(old_mem_size, new_mem_size,
192 old_mem_size, new_mem_size, 199 icache_flush_mode);
193 icache_flush_mode);
194 changed = true; 200 changed = true;
195 break; 201 break;
196 case RelocInfo::WASM_GLOBAL_REFERENCE: 202 case RelocInfo::WASM_GLOBAL_REFERENCE:
197 DCHECK(reloc_globals); 203 DCHECK(reloc_globals);
198 it.rinfo()->update_wasm_global_reference( 204 it.rinfo()->update_wasm_global_reference(
199 old_globals_start, new_globals_start, icache_flush_mode); 205 old_globals_start, new_globals_start, icache_flush_mode);
200 changed = true; 206 changed = true;
201 break; 207 break;
202 case RelocInfo::CODE_TARGET: { 208 case RelocInfo::CODE_TARGET: {
203 DCHECK(reloc_direct_calls); 209 DCHECK(reloc_direct_calls);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 icache_flush_mode); 254 icache_flush_mode);
249 changed = true; 255 changed = true;
250 break; 256 break;
251 default: 257 default:
252 UNREACHABLE(); 258 UNREACHABLE();
253 } 259 }
254 } 260 }
255 261
256 return changed; 262 return changed;
257 } 263 }
OLDNEW
« no previous file with comments | « src/assembler.cc ('k') | src/wasm/wasm-module.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698