use of org.graalvm.wasm.memory.UnsafeWasmMemory in project graal by oracle.
the class WasmPolyglotTestSuite method unsafeMemoryFreed.
@Test
public void unsafeMemoryFreed() throws IOException {
Context.Builder contextBuilder = Context.newBuilder(WasmLanguage.ID);
Source.Builder sourceBuilder = Source.newBuilder(WasmLanguage.ID, ByteSequence.create(binaryReturnConst), "main");
Source source = sourceBuilder.build();
contextBuilder.allowExperimentalOptions(true);
contextBuilder.option("wasm.UseUnsafeMemory", "true");
Context context = contextBuilder.build();
context.enter();
context.eval(source);
final Value mainModule = context.getBindings(WasmLanguage.ID).getMember("main");
mainModule.getMember("main").execute();
final TruffleLanguage.Env env = WasmContext.get(null).environment();
final UnsafeWasmMemory memory = (UnsafeWasmMemory) env.asGuestValue(mainModule.getMember("memory"));
Assert.assertTrue("Memory should have been allocated.", !memory.freed());
context.close();
Assert.assertTrue("Memory should have been freed.", memory.freed());
}
use of org.graalvm.wasm.memory.UnsafeWasmMemory in project graal by oracle.
the class SymbolTable method allocateMemory.
public void allocateMemory(int declaredMinSize, int declaredMaxSize) {
checkNotParsed();
validateSingleMemory();
memory = new MemoryInfo(declaredMinSize, declaredMaxSize);
module().addLinkAction((context, instance) -> {
final int maxAllowedSize = minUnsigned(declaredMaxSize, module().limits().memoryInstanceSizeLimit());
module().limits().checkMemoryInstanceSize(declaredMinSize);
final WasmMemory wasmMemory;
if (context.environment().getOptions().get(WasmOptions.UseUnsafeMemory)) {
wasmMemory = new UnsafeWasmMemory(declaredMinSize, declaredMaxSize, maxAllowedSize);
} else {
wasmMemory = new ByteArrayWasmMemory(declaredMinSize, declaredMaxSize, maxAllowedSize);
}
final int memoryIndex = context.memories().register(wasmMemory);
final WasmMemory allocatedMemory = context.memories().memory(memoryIndex);
instance.setMemory(allocatedMemory);
});
}
Aggregations