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

Read Barrier for CompareAndSwapObject #1965

Merged
merged 2 commits into from
May 24, 2018

Conversation

fjeremic
Copy link
Contributor

Compare-And-Swap on object reference, while primarily is a store
operation, it is also an implicit read (it reads the existing value to
be compared with a provided compare value, before the store itself),
hence needs a read barrier.

This change is an extension of #1573 with JIT support.

Signed-off-by: Filip Jeremic fjeremic@ca.ibm.com

Compare-And-Swap on object reference, while primarily is a store
operation, it is also an implicit read (it reads the existing value to
be compared with a provided compare value, before the store itself),
hence needs a read barrier.

This change is an extension of eclipse-openj9#1573 with JIT support.

Signed-off-by: Filip Jeremic <fjeremic@ca.ibm.com>
@fjeremic
Copy link
Contributor Author

fjeremic commented May 23, 2018

@amicic, @dsouzai, @joransiu could I please get a review? And also one of you assigned as a committer for this PR?

Note there are also compare and swap instructions generated in inlineAtomicOps and inlineDoubleWordCAS. The former only deals with primitives so it does not need a read barrier. The latter does have a path for objects but the code is completely dead (the associated Java recognized methods are deprecated and do not exist) and I will remove it in a subsequent PR I'm working on right now.

@amicic
Copy link
Contributor

amicic commented May 23, 2018

Looks good.

Btw, I bet, in real life, very often just a few instructions before this one you'll have a similar one, loading the value to oldVReg (and again very likely, no async check in-between), which would make this one redundant. But I guess, it's hard to prove it. On the other side, the extra cost of this guarded read should not be that high (data would be in L1 already), anyway.

Still, I wonder if it would be safe to load the value into the same oldVReg (so that you save on a reg), but I guess it's not - there is possibility that in some cases it would change the semantics of the program.

@fjeremic
Copy link
Contributor Author

Btw, I bet, in real life, very often just a few instructions before this one you'll have a similar one, loading the value to oldVReg (and again very likely, no async check in-between), which would make this one redundant. But I guess, it's hard to prove it.

I suppose we can write a peephole pass in the future to validate this and remove the redundant read barrier. This is a correctness issue though while a peephole pass would be a performance issue. I'll leave things as is for now.

On the other side, the extra cost of this guarded read should not be that high (data would be in L1 already), anyway.

And the guarded load would not trigger in that case either so yes the load will be as fast as it can be.

Thanks for the review!

@joransiu
Copy link
Member

We should consider adding an NIAI in front of the guarded load, to ensure that the cache line is loaded in the write exclusive state for CAS.

@fjeremic
Copy link
Contributor Author

fjeremic commented May 23, 2018

The latter does have a path for objects but the code is completely dead (the associated Java recognized methods are deprecated and do not exist) and I will remove it in a subsequent PR I'm working on right now.

This work has been completed in #1966.

Signed-off-by: Filip Jeremic <fjeremic@ca.ibm.com>
@fjeremic
Copy link
Contributor Author

We should consider adding an NIAI in front of the guarded load, to ensure that the cache line is loaded in the write exclusive state for CAS.

This is a good suggestion. Added in c451080. @joransiu could you also be a committer for this PR please?

@joransiu
Copy link
Member

Jenkins test sanity

Copy link
Member

@joransiu joransiu left a comment

Choose a reason for hiding this comment

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

LGTM

@joransiu joransiu self-assigned this May 23, 2018
@fjeremic
Copy link
Contributor Author

Just a heads up that the Jenkins builds will almost certanly fail because we are waiting for a new level of OMR to be promoted. We may have to re-launch these once this has happened. I can luanch the new builds on your behalf as I'm tracking https://github.com/eclipse/openj9-omr/tree/openj9 like a hawk!

@fjeremic
Copy link
Contributor Author

Jenkins test sanity

@fjeremic
Copy link
Contributor Author

Windows failures are unrelated infrastructure issues. @joransiu I think we should be good to go here.

@joransiu joransiu merged commit 44e5ec1 into eclipse-openj9:master May 24, 2018
@fjeremic fjeremic deleted the cas-read-barrier branch August 30, 2018 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants