OLD | NEW |
---|---|
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/objects-inl.h" | 8 #include "src/objects-inl.h" |
9 #include "src/snapshot/code-serializer.h" | 9 #include "src/snapshot/code-serializer.h" |
10 #include "src/version.h" | 10 #include "src/version.h" |
(...skipping 1094 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1105 | 1105 |
1106 // TODO(eholk): Skipping calls to externalize when guard pages are enabled | 1106 // TODO(eholk): Skipping calls to externalize when guard pages are enabled |
1107 // for now. This will have to be dealt with when turning on guard pages as | 1107 // for now. This will have to be dealt with when turning on guard pages as |
1108 // currently gin assumes that it can take ownership of the ArrayBuffer. | 1108 // currently gin assumes that it can take ownership of the ArrayBuffer. |
1109 // Potential for crashes as this might lead to externalizing an already | 1109 // Potential for crashes as this might lead to externalizing an already |
1110 // externalized buffer. | 1110 // externalized buffer. |
1111 if (!memory->has_guard_region()) v8::Utils::ToLocal(memory)->Externalize(); | 1111 if (!memory->has_guard_region()) v8::Utils::ToLocal(memory)->Externalize(); |
1112 void* backing_store = memory->backing_store(); | 1112 void* backing_store = memory->backing_store(); |
1113 uint64_t byte_length = NumberToSize(memory->byte_length()); | 1113 uint64_t byte_length = NumberToSize(memory->byte_length()); |
1114 uint32_t result = WasmMemoryObject::Grow(isolate, mem_obj, 4); | 1114 uint32_t result = WasmMemoryObject::Grow(isolate, mem_obj, 4); |
1115 wasm::DetachWebAssemblyMemoryBuffer(isolate, memory, 4); | |
1115 CHECK_EQ(16, result); | 1116 CHECK_EQ(16, result); |
1116 if (!memory->has_guard_region()) { | 1117 if (!memory->has_guard_region()) { |
1117 isolate->array_buffer_allocator()->Free(backing_store, byte_length); | 1118 isolate->array_buffer_allocator()->Free(backing_store, byte_length); |
1118 } | 1119 } |
1119 memory = handle(mem_obj->buffer()); | 1120 memory = handle(mem_obj->buffer()); |
1120 byte_length = NumberToSize(memory->byte_length()); | 1121 byte_length = NumberToSize(memory->byte_length()); |
1121 instance->set_memory_buffer(*memory); | 1122 instance->set_memory_buffer(*memory); |
1122 // Externalize should make no difference without the JS API as in this case | 1123 // Externalize should make no difference without the JS API as in this case |
1123 // the buffer is not detached. | 1124 // the buffer is not detached. |
1124 if (!memory->has_guard_region()) v8::Utils::ToLocal(memory)->Externalize(); | 1125 if (!memory->has_guard_region()) v8::Utils::ToLocal(memory)->Externalize(); |
1125 result = testing::RunWasmModuleForTesting(isolate, instance, 0, nullptr, | 1126 result = testing::RunWasmModuleForTesting(isolate, instance, 0, nullptr, |
1126 ModuleOrigin::kWasmOrigin); | 1127 ModuleOrigin::kWasmOrigin); |
1127 CHECK_EQ(kExpectedValue, result); | 1128 CHECK_EQ(kExpectedValue, result); |
1128 // Free the buffer as the tracker does not know about it. | 1129 // Free the buffer as the tracker does not know about it. |
1129 if (!memory->has_guard_region()) { | 1130 if (!memory->has_guard_region()) { |
1130 isolate->array_buffer_allocator()->Free( | 1131 isolate->array_buffer_allocator()->Free( |
1131 memory->backing_store(), NumberToSize(memory->byte_length())); | 1132 memory->backing_store(), NumberToSize(memory->byte_length())); |
1132 } | 1133 } |
1133 } | 1134 } |
1134 Cleanup(); | 1135 Cleanup(); |
1135 } | 1136 } |
1137 | |
1138 TEST(Run_WasmModule_Buffer_Externalized_GrowMemMemSize) { | |
1139 { | |
1140 static const int kPageSize = 0x10000; | |
ahaas
2017/05/10 08:33:48
use WasmModule::kPageSize instead.
gdeepti
2017/05/10 15:50:35
Done.
| |
1141 Isolate* isolate = CcTest::InitIsolateOnce(); | |
1142 | |
1143 HandleScope scope(isolate); | |
1144 void* backing_store = | |
1145 isolate->array_buffer_allocator()->Allocate(16 * kPageSize); | |
1146 Handle<JSArrayBuffer> buffer = wasm::SetupArrayBuffer( | |
1147 isolate, backing_store, 16 * kPageSize, false, false); | |
1148 Handle<WasmMemoryObject> mem_obj = | |
1149 WasmMemoryObject::New(isolate, buffer, 100); | |
1150 v8::Utils::ToLocal(buffer)->Externalize(); | |
1151 int32_t result = WasmMemoryObject::Grow(isolate, mem_obj, 0); | |
1152 wasm::DetachWebAssemblyMemoryBuffer(isolate, buffer, 0); | |
1153 CHECK_EQ(16, result); | |
1154 | |
1155 isolate->array_buffer_allocator()->Free(backing_store, 16 * kPageSize); | |
1156 } | |
1157 Cleanup(); | |
1158 } | |
OLD | NEW |