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

Side by Side Diff: test/cctest/wasm/test-run-wasm-module.cc

Issue 2277443009: Populate relocation information correctly for RelocatableInt32Constants. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase + fix serializer test flakiness Created 4 years, 3 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/compiler/x64/code-generator-x64.cc ('k') | test/mjsunit/wasm/grow-memory.js » ('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 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 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 <stdlib.h> 5 #include <stdlib.h>
6 #include <string.h> 6 #include <string.h>
7 7
8 #include "src/wasm/encoder.h" 8 #include "src/wasm/encoder.h"
9 #include "src/wasm/module-decoder.h" 9 #include "src/wasm/module-decoder.h"
10 #include "src/wasm/wasm-js.h" 10 #include "src/wasm/wasm-js.h"
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 193
194 WasmFunctionBuilder* f = builder->FunctionAt(f_index); 194 WasmFunctionBuilder* f = builder->FunctionAt(f_index);
195 f->SetSignature(sigs.i_i()); 195 f->SetSignature(sigs.i_i());
196 byte code[] = {WASM_GET_LOCAL(0), kExprI32Const, 1, kExprI32Add}; 196 byte code[] = {WASM_GET_LOCAL(0), kExprI32Const, 1, kExprI32Add};
197 f->EmitCode(code, sizeof(code)); 197 f->EmitCode(code, sizeof(code));
198 ExportAs(f, kFunctionName); 198 ExportAs(f, kFunctionName);
199 199
200 ZoneBuffer buffer(&zone); 200 ZoneBuffer buffer(&zone);
201 builder->WriteTo(buffer); 201 builder->WriteTo(buffer);
202 202
203 Isolate* isolate = CcTest::InitIsolateOnce(); 203 v8::Isolate::CreateParams create_params;
204 create_params.array_buffer_allocator =
205 CcTest::InitIsolateOnce()->array_buffer_allocator();
206
207 v8::Isolate* v8_isolate = v8::Isolate::New(create_params);
208 Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate);
209 v8::HandleScope new_scope(v8_isolate);
210 v8::Local<v8::Context> new_ctx = v8::Context::New(v8_isolate);
211 new_ctx->Enter();
212
204 ErrorThrower thrower(isolate, ""); 213 ErrorThrower thrower(isolate, "");
205
206 v8::WasmCompiledModule::SerializedModule data; 214 v8::WasmCompiledModule::SerializedModule data;
207 { 215 {
208 HandleScope scope(isolate); 216 HandleScope scope(isolate);
209 217
210 ModuleResult decoding_result = DecodeWasmModule( 218 ModuleResult decoding_result = DecodeWasmModule(
211 isolate, &zone, buffer.begin(), buffer.end(), false, kWasmOrigin); 219 isolate, &zone, buffer.begin(), buffer.end(), false, kWasmOrigin);
212 std::unique_ptr<const WasmModule> module(decoding_result.val); 220 std::unique_ptr<const WasmModule> module(decoding_result.val);
213 CHECK(!decoding_result.failed()); 221 CHECK(!decoding_result.failed());
214 222
215 MaybeHandle<FixedArray> compiled_module = 223 MaybeHandle<FixedArray> compiled_module =
216 module->CompileFunctions(isolate, &thrower); 224 module->CompileFunctions(isolate, &thrower);
217 CHECK(!compiled_module.is_null()); 225 CHECK(!compiled_module.is_null());
218 Handle<JSObject> module_obj = CreateCompiledModuleObject( 226 Handle<JSObject> module_obj = CreateCompiledModuleObject(
219 isolate, compiled_module.ToHandleChecked(), ModuleOrigin::kWasmOrigin); 227 isolate, compiled_module.ToHandleChecked(), ModuleOrigin::kWasmOrigin);
220 v8::Local<v8::Object> v8_module_obj = v8::Utils::ToLocal(module_obj); 228 v8::Local<v8::Object> v8_module_obj = v8::Utils::ToLocal(module_obj);
221 CHECK(v8_module_obj->IsWebAssemblyCompiledModule()); 229 CHECK(v8_module_obj->IsWebAssemblyCompiledModule());
222 230
223 v8::Local<v8::WasmCompiledModule> v8_compiled_module = 231 v8::Local<v8::WasmCompiledModule> v8_compiled_module =
224 v8_module_obj.As<v8::WasmCompiledModule>(); 232 v8_module_obj.As<v8::WasmCompiledModule>();
225 data = v8_compiled_module->Serialize(); 233 data = v8_compiled_module->Serialize();
226 } 234 }
227 235
228 v8::Isolate::CreateParams create_params;
229 create_params.array_buffer_allocator = isolate->array_buffer_allocator(); 236 create_params.array_buffer_allocator = isolate->array_buffer_allocator();
230 237
231 v8::Isolate* v8_isolate = v8::Isolate::New(create_params);
232 isolate = reinterpret_cast<Isolate*>(v8_isolate); 238 isolate = reinterpret_cast<Isolate*>(v8_isolate);
233 { 239 {
234 v8::Isolate::Scope isolate_scope(v8_isolate); 240 v8::Isolate::Scope isolate_scope(v8_isolate);
235 v8::HandleScope new_scope(v8_isolate); 241 v8::HandleScope new_scope(v8_isolate);
236 v8::Local<v8::Context> new_ctx = v8::Context::New(v8_isolate); 242 v8::Local<v8::Context> new_ctx = v8::Context::New(v8_isolate);
237 new_ctx->Enter(); 243 new_ctx->Enter();
238 244
239 v8::MaybeLocal<v8::WasmCompiledModule> deserialized = 245 v8::MaybeLocal<v8::WasmCompiledModule> deserialized =
240 v8::WasmCompiledModule::Deserialize(v8_isolate, data); 246 v8::WasmCompiledModule::Deserialize(v8_isolate, data);
241 v8::Local<v8::WasmCompiledModule> compiled_module; 247 v8::Local<v8::WasmCompiledModule> compiled_module;
242 CHECK(deserialized.ToLocal(&compiled_module)); 248 CHECK(deserialized.ToLocal(&compiled_module));
243 Handle<JSObject> module_object = 249 Handle<JSObject> module_object =
244 Handle<JSObject>::cast(v8::Utils::OpenHandle(*compiled_module)); 250 Handle<JSObject>::cast(v8::Utils::OpenHandle(*compiled_module));
245 Handle<FixedArray> compiled_part = 251 Handle<FixedArray> compiled_part =
246 handle(FixedArray::cast(module_object->GetInternalField(0))); 252 handle(FixedArray::cast(module_object->GetInternalField(0)));
247 Handle<JSObject> instance = 253 Handle<JSObject> instance =
248 WasmModule::Instantiate(isolate, compiled_part, 254 WasmModule::Instantiate(isolate, compiled_part,
249 Handle<JSReceiver>::null(), 255 Handle<JSReceiver>::null(),
250 Handle<JSArrayBuffer>::null()) 256 Handle<JSArrayBuffer>::null())
251 .ToHandleChecked(); 257 .ToHandleChecked();
252 Handle<Object> params[1] = {Handle<Object>(Smi::FromInt(41), isolate)}; 258 Handle<Object> params[1] = {Handle<Object>(Smi::FromInt(41), isolate)};
253 int32_t result = testing::CallFunction(isolate, instance, &thrower, 259 int32_t result = testing::CallFunction(isolate, instance, &thrower,
254 kFunctionName, 1, params); 260 kFunctionName, 1, params);
255 CHECK(result == 42); 261 CHECK(result == 42);
256 new_ctx->Exit(); 262 new_ctx->Exit();
257 } 263 }
258 } 264 }
259 265
266 TEST(Run_WasmModule_MemSize_GrowMem) {
267 static const int kPageSize = 0x10000;
268 // Initial memory size = 16 + GrowMemory(10)
269 static const int kExpectedValue = kPageSize * 26;
270 TestSignatures sigs;
271 v8::base::AccountingAllocator allocator;
272 Zone zone(&allocator);
273
274 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone);
275 uint16_t f_index = builder->AddFunction();
276 WasmFunctionBuilder* f = builder->FunctionAt(f_index);
277 f->SetSignature(sigs.i_v());
278 ExportAsMain(f);
279 byte code[] = {WASM_GROW_MEMORY(WASM_I8(10)), WASM_MEMORY_SIZE};
280 f->EmitCode(code, sizeof(code));
281 TestModule(&zone, builder, kExpectedValue);
282 }
283
260 TEST(Run_WasmModule_GrowMemoryInIf) { 284 TEST(Run_WasmModule_GrowMemoryInIf) {
261 TestSignatures sigs; 285 TestSignatures sigs;
262 v8::base::AccountingAllocator allocator; 286 v8::base::AccountingAllocator allocator;
263 Zone zone(&allocator); 287 Zone zone(&allocator);
264 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); 288 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone);
265 uint16_t f_index = builder->AddFunction(); 289 uint16_t f_index = builder->AddFunction();
266 WasmFunctionBuilder* f = builder->FunctionAt(f_index); 290 WasmFunctionBuilder* f = builder->FunctionAt(f_index);
267 f->SetSignature(sigs.i_v()); 291 f->SetSignature(sigs.i_v());
268 ExportAsMain(f); 292 ExportAsMain(f);
269 byte code[] = {WASM_IF_ELSE(WASM_I32V(0), WASM_GROW_MEMORY(WASM_I32V(1)), 293 byte code[] = {WASM_IF_ELSE(WASM_I32V(0), WASM_GROW_MEMORY(WASM_I32V(1)),
270 WASM_I32V(12))}; 294 WASM_I32V(12))};
271 f->EmitCode(code, sizeof(code)); 295 f->EmitCode(code, sizeof(code));
272 TestModule(&zone, builder, 12); 296 TestModule(&zone, builder, 12);
273 } 297 }
OLDNEW
« no previous file with comments | « src/compiler/x64/code-generator-x64.cc ('k') | test/mjsunit/wasm/grow-memory.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698