-
Notifications
You must be signed in to change notification settings - Fork 306
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
java: clean up the EvmcVm class a bit #549
Conversation
ff345f4
to
50610bb
Compare
|
||
/** | ||
* Function to execute a code by the VM instance. | ||
* | ||
* <p>This is a mandatory method and MUST NOT be set to NULL. | ||
*/ | ||
native void execute( | ||
private static native void execute( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this static?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because it only exists once, it is the native library which can only be loaded once.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, if it's purely functional, that may work.
// Licensed under the Apache License, Version 2.0. | ||
package org.ethereum.evmc; | ||
|
||
public class EvmcLoaderException extends Exception { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider making it extend RuntimeException - this way it's an unchecked exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd argue this must be actually checked because it is an error which should not be ignored or bubbled up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But perhaps I don't fully understand the distinction between Exception
and RuntimeException
-- could you explain please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure thing. In Java, you must catch checked exceptions, or the code doesn't compile. You can let unchecked exceptions "unchecked", meaning you don't need to catch them explicitly. They still happen and bubble up.
The net difference is that sometimes your Java code ends up looking like a bunch of try/catch statements or throws.
This is a subject of hot debate and frankly, I'm fine either way. I just prefer RuntimeException
s myself.
https://stackoverflow.com/questions/6115896/understanding-checked-vs-unchecked-exceptions-in-java
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! My argument for checked exception here is that this EVMC-specific loading error should be handled at the place this is integrated in, likely it would be translated into some local exception in the project?
Though I don't have a very strong opinion, fine either way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, let’s do it.
Please don't make the methods static - this would only allow one EVM in a JVM at a time. Having multiple EVMs is a good thing. |
The JNI binding (libevmc-java.so) should be loaded once. Multiple EVMC VMs can be loaded and that is distinguished by the |
50610bb
to
57cccf6
Compare
@atoulme okay to merge this? |
…haviour Also mark it private.
Introduce specific EvmcLoaderException exception.
57cccf6
to
4b24898
Compare
@atoulme merging this now to progress with the refactoring but we can revert certain changes if it turns out to be bad. |
All good. Sorry for the slow response. |
Some references: