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

MutableCallSite does not work? #205

Open
xuwei-k opened this issue Jan 8, 2025 · 6 comments
Open

MutableCallSite does not work? #205

xuwei-k opened this issue Jan 8, 2025 · 6 comments

Comments

@xuwei-k
Copy link

xuwei-k commented Jan 8, 2025

No description provided.

@alexp-sssup
Copy link
Member

Hi, thanks for getting in touch. Can you provide an example demonstrating the problem?

MethodHandles are supported in general, so there must be a specific corner case that is not handled correctly.

With an example we will be able to identify and fix the problem.

@xuwei-k
Copy link
Author

xuwei-k commented Jan 8, 2025

Sorry, I misunderstood. Maybe not MethodHandle but java.lang.invoke.SwitchPoint does not work.

https://javafiddle.leaningtech.com/N4IgLglmA2CmIC4QgDQgK4AcAmBDMs2iIATAAwkCsAtGQIy0AcAKiSQpWQnWQHSN06ALVQgAZhDgBnRAG1QmfAAtiAWVwQAdrwBWuAG65RAYwD2mgheKLjAa1wBzWAAJYAD1wBbTHADcAHU1AiG9TACcwZz1DXmhcTQdeLX1TW1heVVgwJVNsAAl47D9g0Iiog1xY+MTk1PTM7NyCzSLYKQDNEMxwyOjKuISkzRS0jKyc7GYAT0xYDq6e8piBmuG63gBlAHcoYyUABVMtMA7AzHQAI2gIY2djOKkpZ3UtZ2BA50-nc6ub5ykwPg-ikINhnJ4NJoABQbMBhLQOWQAXWcuDCDikAEpnNkwqYtk9mEo8VtcFcXO9NF9qc9xk1CnBnnkAPoAsLGfDOAC8tMa+QZbViplSWChmN4EhaADUIBF0LhoDC4QjePdcI8UM5-CAzJoOWBtZqGhNprNeJ46ZMZrAlfDBmqNc5YXbEg6sZiOjSvttdgcjhZ-phIjzNLAtk6dmA9odjmLPV7UY9YBEoQBCKRB3hKdUAIVgsE0AElhgrQfhCGKPR8E8b6S1GVtwmkwnRuUzWXD9fGvbX+fWXI2ws2SG3e81WlJeLMwp50AQAILo9AWixSKGqFls-VGzed-C8MDWsWauiashVqk1y3jhtN5NtjNgXgOeVhbAAdSgSmYbTAUMHzans4AHJiQF4Jk6UwArAni8KYc5TnaMDQiBYTgV8AC+gRYZoIAYUiGFAA

https://github.com/openjdk/jdk/blob/jdk8-b120/jdk/src/share/classes/java/lang/invoke/SwitchPoint.java#L59-L66

https://docs.oracle.com/javase/8/docs/api/java/lang/invoke/SwitchPoint.html

package example;

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.invoke.SwitchPoint;

public class Main {
    public static void main(String[] args) throws Throwable {
        MethodHandle MH_strcat = MethodHandles.lookup().findVirtual(String.class, "concat", MethodType.methodType(String.class, String.class));
        SwitchPoint spt = new SwitchPoint();
        assert(!spt.hasBeenInvalidated());
        MethodHandle worker1 = MH_strcat;
        MethodHandle worker2 = MethodHandles.permuteArguments(MH_strcat, MH_strcat.type(), 1, 0);
        MethodHandle worker = spt.guardWithTest(worker1, worker2);
        System.out.println(worker);
    }
}

image

@xuwei-k xuwei-k changed the title MethodHandle#invokeExact does not work java.lang.invoke.SwitchPoint does not work Jan 8, 2025
@alexp-sssup
Copy link
Member

I can't reproduce this problem, can you please try again with a recent nightly build?

https://cjrtnc.leaningtech.com/3_20241216_574/cj3loader.js

@xuwei-k
Copy link
Author

xuwei-k commented Jan 9, 2025

please try again with a recent nightly build?

SwitchPoint works with nightly build. thanks!

I have another similar problem. (sorry for in succession)

MutableCallSite does not work 🤔

https://github.com/openjdk/jdk/blob/9a9add8825a040565051a09010b29b099c2e7d49/jdk/src/share/classes/java/lang/invoke/MutableCallSite.java#L42-L49

package example;

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.invoke.MutableCallSite;

public class Main {
    public static void main(String[] args) throws Throwable {
        MutableCallSite name = new MutableCallSite(MethodType.methodType(String.class));
        MethodHandle MH_name = name.dynamicInvoker();
        MethodType MT_str1 = MethodType.methodType(String.class);
        MethodHandle MH_upcase = MethodHandles.lookup().findVirtual(String.class, "toUpperCase", MT_str1);
        MethodHandle worker1 = MethodHandles.filterReturnValue(MH_name, MH_upcase);
        name.setTarget(MethodHandles.constant(String.class, "Rocky"));
        String x1 = (String) worker1.invokeExact(); // ClassCastException
        System.out.println(x1);
    }
}

@xuwei-k xuwei-k changed the title java.lang.invoke.SwitchPoint does not work MethodHandle does not work? Jan 9, 2025
@alexp-sssup alexp-sssup changed the title MethodHandle does not work? MutableCallSite does not work? Jan 9, 2025
@alexp-sssup
Copy link
Member

I can confirm this issue. I've added it to our internal bug tracking system and we'll take a look when we can. Is there any practical use case for this? It seems to be a technical corner case, since it never emerged from any of our customers or internal testing.

@xuwei-k
Copy link
Author

xuwei-k commented Jan 9, 2025

I have tried

I have tried run scala lang compiler in web browser. old version work but new version does not work due to MethodHandle, CallSite or something.

https://github.com/xuwei-k/cheerpj-scala/blob/574b8074449df0487a2b50b5750a95f9ff7e1da9/build.sbt#L4-L6

https://xuwei-k.github.io/cheerpj-scala/

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

No branches or pull requests

2 participants