-
Notifications
You must be signed in to change notification settings - Fork 6.1k
8353487: JShell LocalExecutionControl should allow decorating the execution task #24398
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
base: master
Are you sure you want to change the base?
Conversation
/csr |
👋 Welcome back acobbs! A progress list of the required criteria for merging this PR into |
❗ This change is not yet ready to be integrated. |
@archiecobbs an approved CSR request is already required for this pull request. |
@archiecobbs The following label will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command. |
Webrevs
|
I wonder how generic are the snippets used - for some types of snippets, it might be possible to put some code around the original snippet directly in the snippet. That would alleviate the need to add a new API. But presumably it would only work for some types of snippets. For the API itself - just an idea, would having a method
? |
Yes, sort of - it's already possible to modify the snippet bytecode itself of course because the
Yes that would work just as well. A third option would be to define a pair like I think your idea of a Thanks for taking a look. |
@archiecobbs This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration! |
import jdk.jshell.execution.LocalExecutionControl;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class LocalExecutionControlTest {
public static void main(String[] args) throws Throwable {
var control = new LocalExecutionControl((ClassLoader) null) {
Object result;
@Override
protected Object doInvoke(Method method) throws IllegalAccessException, InvocationTargetException {
return result = super.doInvoke(method);
}
};
control.doInvoke(MethodHandles.class.getDeclaredMethod("lookup"));
var lookup = (MethodHandles.Lookup) control.result;
var unsafeClass = Class.forName("jdk.internal.misc.Unsafe");
var unsafe = lookup.findStatic(unsafeClass, "getUnsafe", MethodType.methodType(unsafeClass)).invoke();
var field = MethodHandles.Lookup.class.getDeclaredField("IMPL_LOOKUP");
lookup = (MethodHandles.Lookup) lookup.findVirtual(unsafeClass, "getReference", MethodType.methodType(Object.class, Object.class, long.class))
.invoke(
unsafe,
lookup.findVirtual(unsafeClass, "staticFieldBase", MethodType.methodType(Object.class, Field.class)).invoke(unsafe, field),
(long) lookup.findVirtual(unsafeClass, "staticFieldOffset", MethodType.methodType(long.class, Field.class)).invoke(unsafe, field)
);
System.out.println(lookup);
}
} jdk/src/java.base/share/classes/module-info.java Lines 204 to 222 in 3acfa9e
Please reconsider use of reflection (or method handles) I was looking into jshell before to achieve something like this using jdk/src/jdk.jshell/share/classes/jdk/jshell/execution/DirectExecutionControl.java Line 125 in 3acfa9e
java.lang.reflect.Method to user code, but it was not possible to get back the invocation result. With this PR, it is now possible.
|
Good point. I believe my original patch which adds a Or there is the other approach (previously mentioned) which adds @lahodaj what's your opinion here? Thanks. |
@archiecobbs This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply issue a |
/touch |
@archiecobbs The pull request is being re-evaluated and the inactivity timeout has been reset. |
This PR adds the ability for subclasses of JShell's
LocalExecutionControl
to configure thread-local context in the execution thread that snippets execute in. Please see JDK-8353487 for more details & rationale.Progress
Issues
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/24398/head:pull/24398
$ git checkout pull/24398
Update a local copy of the PR:
$ git checkout pull/24398
$ git pull https://git.openjdk.org/jdk.git pull/24398/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 24398
View PR using the GUI difftool:
$ git pr show -t 24398
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/24398.diff
Using Webrev
Link to Webrev Comment