Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefer to get & set exception from exec_env_tls #4007

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

paul-hoang
Copy link

@paul-hoang paul-hoang commented Jan 6, 2025

Exceptions are currently stored in module instance, but if most of them can be stored at the exec_env that would allow using a single module instance in parallel without locking and handle the exception separately.

Using a single module instance in parallel might not be usual, but it's possible from what I understand and tested WAMR, at least for specific use cases (e.g. no writing to globals or wasm memory, only reading from that and writing to wasm stack). Please correct me if I'm missing anything.

This PR proposes a change in how we store and retrieve exception from a given module instance:

  • If the exec_env_tls is present, get/set exception from that and not touching the module instance.
  • If not, keep getting/setting from the module instance. This is for exceptions that happens before an exec_env is created.

@@ -166,6 +168,9 @@ typedef struct WASMExecEnv {
/* The WASM stack. */
uint8 bottom[1];
} wasm_stack_u;

/* The exception buffer for current execution environment. */
char cur_exception[EXCEPTION_BUF_LEN];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we can safely add anything below wasm_stack_u.bottom as this is the region used for the WASM stack frames.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, I can move it to anywhere in WASMExecEnv struct. Is after module_inst OK?

@lum1n0us
Copy link
Collaborator

lum1n0us commented Jan 7, 2025

would allow using a single module instance in parallel ... Using a single module instance in parallel might not be usual,

I'm not entirely clear on the concept of "parallel" here. Does it mean using a single instance across multiple threads?

@paul-hoang
Copy link
Author

I'm not entirely clear on the concept of "parallel" here. Does it mean using a single instance across multiple threads?

Yes, it means use a single instance across multiple threads at the same time without locking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants