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

Fixes #284 Add support for Thread.onSpinWait() while spinning #285

Open
wants to merge 79 commits into
base: master
Choose a base branch
from

Conversation

franz1981
Copy link
Collaborator

@franz1981 franz1981 commented Jan 4, 2020

I've opened this for discussion: I'll push different commits to propose places where onSpinWait could be welcome, if I'll solve first the compilation error:

InternalThreadHints.java:[52,41] method invoked with incorrect number of arguments; expected 0, found 1

franz1981 and others added 30 commits November 5, 2019 22:28
This is fixing MpqBurstCost and QueueBurstCost multi-consumer scenario
and will make both to look similar.
Fixes JCTools#272 BurstCost aren't handling multi-consumers correctly
@franz1981
Copy link
Collaborator Author

franz1981 commented Jan 4, 2020

Probably @PolymorphicSignature is creating issues while compiling with 1.6, but with 1.7 is fine and, of course, if I use MethodHandle::invokeWithArguments, that doesn't use @PolymorphicSignature, is fine too

@franz1981
Copy link
Collaborator Author

Here LMAX-Exchange/disruptor#183 (comment) some more information on how we could bring this in with 1.6, if it worths doing it

@richardstartin
Copy link

richardstartin commented Jan 9, 2020

If I understand correctly you want Thread.onSpinWait to be used in spin locks whenever it is available while maintaining bytecode compatibility with JDK6. You can achieve this with a shim class and a Multi-Release jar.

public class ThreadShim {

    public static void onSpinWait() {
        // do nothing
    }

}

In another directory e.g. src/main/java9 you add another implementation.

/** will load this one from META-INF/versions/9 in any JDK >= JDK9*/
public class ThreadShim {

    public static void onSpinWait() {
        Thread.onSpinWait();
    }

}

You now need to ensure that the JDK9+ implementation is in a special place in the jar (META-INF/versions/9, and the manifest has the property Multi-Release : true. JDK8 and less will never load the JDK+ shim.

There is an example of how to do this for a JDK9+ vectorised Arrays equality method in RoaringBitmap. An example implementation with Maven is here.

}

// prevent construction...
private ThreadHints()
Copy link
Contributor

Choose a reason for hiding this comment

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

I used to do this too, but my current thinking is that it is pointless. The class is final, it has no fields, no methods that are not static. If some idiot wants to instantiate it, so what?

@nitsanw
Copy link
Contributor

nitsanw commented Jan 28, 2020

In its current state this will not fly with building on 8 with JDK6 compatibility.

@franz1981
Copy link
Collaborator Author

franz1981 commented Jan 28, 2020

@nitsanw

In its current state this will not fly with building on 8 with JDK6 compatibility.

I know, I've yet to work on this to make it possible, but still not sure what to do: the idea of @richardstartin seems reasonable to me, but probably will need to support Multi-Release jar.

@franz1981
Copy link
Collaborator Author

franz1981 commented Jan 30, 2020

@nitsanw Nitsan, bud, I cannot add any label to this PR, can you do it for me? is "DON'T MERGE IT YET" in red; I will change it accordly when I've a bit of time and will proceed on this 👍

@richardstartin
Copy link

There's a demo of how to do this with Maven here.

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.

None yet

3 participants