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

Check for boolean array when running bastore bytecode #2046

Merged
merged 1 commit into from
Oct 10, 2018

Conversation

tajila
Copy link
Contributor

@tajila tajila commented May 31, 2018

Check for boolean array when running bastore bytecode

The JVM spec states: "If the arrayref refers to an array whose
components are of type boolean, then the int value is narrowed by taking
the bitwise AND of value and 1; the result is stored as the component of
the array indexed by index"

Issue: #2049

Signed-off-by: tajila atobia@ca.ibm.com

The JVM spec states: "If the arrayref refers to an array whose
components are of type boolean, then the int value is narrowed by taking
the bitwise AND of value and 1; the result is stored as the component of
the array indexed by index"

Signed-off-by: tajila <atobia@ca.ibm.com>
@tajila
Copy link
Contributor Author

tajila commented May 31, 2018

@pshipton please review

@DanHeidinga
Copy link
Member

FYI @andrewcraik @fjeremic The JIT will need to modify the jit equivalent of bastore to do the & 1 before storing the value for boolean[] as well

@DanHeidinga
Copy link
Member

Jenkins test sanity plinux jdk8

@DanHeidinga DanHeidinga self-assigned this Jun 1, 2018
@DanHeidinga
Copy link
Member

Before merging this, I'd like to hear from the some of the JIT committers about how long it would take to update the JIT to match this behaviour. Having the interpreter and JIT have different results isn't optimal

fjeremic added a commit to fjeremic/openj9 that referenced this pull request Jun 1, 2018
The JVM spec states: "If the arrayref refers to an array whose
components are of type boolean, then the int value is narrowed by taking
the bitwise AND of value and 1; the result is stored as the component of
the array indexed by index"

This commit is the JIT portion of eclipse-openj9#2046.

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

fjeremic commented Jun 1, 2018

Before merging this, I'd like to hear from the some of the JIT committers about how long it would take to update the JIT to match this behaviour.

So we had a discussion on this and came to the conclusion that it will take us some single digit integer number of weeks to complete this on the JIT side.

The reason for this is because of the overloaded bytecode for both byte and boolean values we could do one of the two following solutions in the JIT:

  1. Check the arrayref at runtime for boolean[] and do the AND with 1
  2. Prove at compile time whether the arrayref is of type boolean[] and do the AND with 1

Doing 1. would involve introducing control flow at IL generation where it does not exist in the bytecode, which is something we don't do today so we would have to teach the IL generator about that. The alternative is to do the check at codegen time in the evaluators which would be simpler but will still involve additional path length and changes on all 4 code generators.

We would like to avoid doing 1. as it is expensive at runtime and would potentially hinder other optimizations by introducing such control flow.

Doing 2. is the proper way of solving this issue from the JIT perspective as the problem is decidable at compile time. Given Java semantics it is always possible to determine the type of the arrayref starting from the entry of a method. However doing so would involve doing a dataflow analysis which is quite expensive in terms of compile time. We cannot do a full dataflow for this problem given that it has to be done at IL generation time. We will need to come up with some simplified version of a dataflow to determine the type of the arrayref statically at compile time.

This solution must not increase compile time (by much) on the set of benchmarks we track. IL generation runs for every method we compile and every method we attempt to inline or consider inlining so it is important compile time is taken into consideration when implementing this IL pass during IL generation.

Because of these restrictions and other commitments we will need some time to come up with the right solution to this problem. Hope this clears things up for the JIT perspective.

@tajila
Copy link
Contributor Author

tajila commented Jun 1, 2018

FYI, we will have to do something similar for putstatic and putfield as well.
See #2057

@andrewcraik
Copy link
Contributor

From a performance perspective doing 1 is a non-starter - any runtime checks will greatly affect performance (especially in Java 9 and later due to strings using byte arrays as their backing storage). The proof is the way we need to go - especially since verified bytecode already passed the check of being able to statically decide the type. Would be nice if we could pickup the verification result rather than having to figure it out with a dataflow though the data flow Is likely required when the verifier is off.

Will need to consider putstatic and putfield as well.

Is this a change in the spec?

@DanHeidinga
Copy link
Member

Is this a change in the spec?

Yes

cathyzhyi pushed a commit to cathyzhyi/openj9 that referenced this pull request Sep 27, 2018
The JVM spec states: "If the arrayref refers to an array whose
components are of type boolean, then the int value is narrowed by taking
the bitwise AND of value and 1; the result is stored as the component of
the array indexed by index"

This is the JIT part of the change. The VM part is eclipse-openj9#2046

Issue: eclipse-openj9#2049

Signed-off-by: Yi Zhang <yizhang@ca.ibm.com>
@DanHeidinga
Copy link
Member

Jenkins test sanity plinux,aix,xlinux jdk8

@DanHeidinga
Copy link
Member

JIT side is merged - #2910

@DanHeidinga DanHeidinga merged commit f3607dd into eclipse-openj9:master Oct 10, 2018
@DanHeidinga DanHeidinga added this to the Release 0.11.0 milestone Oct 11, 2018
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