graal icon indicating copy to clipboard operation
graal copied to clipboard

A way to limit instructions per execution (mainly for wasm)

Open walksanatora opened this issue 1 year ago • 3 comments

Feature request

Please include the following information:

Is your feature request related to a problem? Please describe. I am frustrated that I cannot find any WASM runtime that would allow me to start a WASM programs main function. run 100k instructions. and then return to java to keep running at some later point

Describe the solution you'd like. I would like a way to limit wasm instructions per/call A way to do this would perhaps be a instr_limit to be set while building. and a .resume() function on the context

Describe who do you think will benefit the most. Probally people developing apps with GraalVM where you want to run a bit of WASM but not have it hog the thread.

Describe alternatives you've considered. limits based on exection time would also be a possibility.

Express whether you'd like to help contributing this feature sadly no. I have little expierence with how Graal works internally and would probally be breaking more then I fix

walksanatora avatar Feb 07 '24 18:02 walksanatora

I think you should be able to achieve something like this using a statementLimit, which is one of many supported resource limits. I'm not entirely sure how statements are counted in our WASM runtime, but maybe this already "just works". @chumer or @flohuemer would probably know more.

fniephaus avatar Feb 08 '24 08:02 fniephaus

I fear the statementLimit does not work with GraalWasm as it does not implement Truffle instrumentation.

chumer avatar Feb 08 '24 09:02 chumer

That's not entirely true. GraalWasm does support instrumentation when the wasm binary contains debug information. Only then are we able to define the meaning of a statement, which is needed by the statementLimit, if I understood it correctly.

However, using statementLimit prevents resuming the program. What could work is an instrument similar to a debugger, that allows to execute a certain number of statements and interrupts at a "breakpoint".

flohuemer avatar Feb 08 '24 10:02 flohuemer