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

The nightly build (jdk-9+181-20 on January 22 2018) has different behaviors from OpenJDK #999

Closed
tianxiaogu opened this Issue Jan 22, 2018 · 13 comments

Comments

5 participants
@tianxiaogu

tianxiaogu commented Jan 22, 2018

C0.class (via Google Drive) triggers different behaviors on OpenJDK and OpenJ9.

The nightly build (jdk-9+181-20 on January 22 2018) throws an exception in default mode,
where OpenJDK (head) exits normally.

This bug may relate to #997. I am not sure whether this is a bug of OpenJDK or OpenJ9.

OpenJ9-JDK9

$ ./jdk-9+181/bin/java C0
Exception in thread "main" java.lang.NegativeArraySizeException
	at C0.main(Unknown Source)
$ ./jdk-9+181/bin/java -Xcomp C0
Exception in thread "main" java.lang.NegativeArraySizeException
	at C0.main(Unknown Source)
$ ./jdk-9+181/bin/java -version
openjdk version "9-internal"
OpenJDK Runtime Environment (build 9-internal+0-adhoc.jenkins.openjdk)
Eclipse OpenJ9 VM (build 2.9, JRE 9 Linux amd64-64 Compressed References 20180122_95 (JIT enabled, AOT enabled)
OpenJ9   - d38352e
OMR      - cfd2f17
OpenJDK  - be5903d based on jdk-9+181)

OpenJDK

$ ./openjdk/jdk/build/linux-x86_64-normal-server-release/jdk/bin/java C0
$ echo $?
0
$ ./openjdk/jdk/build/linux-x86_64-normal-server-release/jdk/bin/java --version
openjdk 10-internal 2018-03-20
OpenJDK Runtime Environment (build 10-internal+0-adhoc.t.jdk)
OpenJDK 64-Bit Server VM (build 10-internal+0-adhoc.t.jdk, mixed mode)

Oracle JDK 9.0.4

$ ./jdk-9.0.4/bin/java C0
$ echo $?
0
$ ./jdk-9.0.4/bin/java -version
java version "9.0.4"
Java(TM) SE Runtime Environment (build 9.0.4+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.4+11, mixed mode)
@pshipton

This comment has been minimized.

Contributor

pshipton commented Jan 23, 2018

What happens when you run ./jdk-9+181/bin/java -Xint C0?

@tianxiaogu

This comment has been minimized.

tianxiaogu commented Jan 23, 2018

@pshipton The same exception is thrown with ./jdk-9+181/bin/java -Xint C0.

$ ../jdk-9+181/bin/java -Xint C0
Exception in thread "main" java.lang.NegativeArraySizeException
        at C0.main(Unknown Source)

@pshipton pshipton added the comp:vm label Jan 23, 2018

@mstoodle mstoodle added the userRaised label Jan 31, 2018

@DanHeidinga

This comment has been minimized.

Contributor

DanHeidinga commented Feb 14, 2018

@dnakamura Can you take a look at this?

@DanHeidinga DanHeidinga added this to User Raised issues in Issue tracking Feb 14, 2018

@dnakamura

This comment has been minimized.

Contributor

dnakamura commented Feb 14, 2018

The bytecodes causing the issue (truncated for clarity)

  public static void main(java.lang.String[]);
    descriptor: ([Ljava/lang/String;)V
    flags: (0x0009) ACC_PUBLIC, ACC_STATIC
    Code:
      stack=6, locals=2, args_size=1
.....
        35: invokestatic  #22                 // Method M1:()C
        38: anewarray     #24                 // class java/lang/Float
  public static char M1();
    descriptor: ()C
    flags: (0x0009) ACC_PUBLIC, ACC_STATIC
    Code:
      stack=1, locals=0, args_size=0
         0: sipush        5260
         3: ineg
         4: ireturn

Which would approximately correspond to the following java code

class C0 {
	public static main(string[] args){
		....
		new float[M1()];
		...
	}
	public static char M1(){
		return -5260;
	}
}

However I suspect that if you fed this to javac it would add an implicit i2c instruction to the end of M1

The issue here is that internally the JVM only operates on int types, and will sign extend or truncate as needed on loads and stores. My suspicion is that Oracle is implicitly truncating to a char as part of the iret, even though, on first glance, there doesn't appear to be any requirement to do so in the spec. @DanHeidinga is this something we want to do anyway in order to match Oracles behavior?

@pshipton

This comment has been minimized.

Contributor

pshipton commented Feb 14, 2018

A char is a 16-bit unsigned integer.

This simple test prints 60276.

		System.out.println((int)(char)-5260);
@DanHeidinga

This comment has been minimized.

Contributor

DanHeidinga commented Feb 15, 2018

I know @gacholio has looked into similar issues in the past. Let's take advantage of being colocated and discuss in person. @dnakamura Can you book a meeting today?

And we'll make sure to update this after the discussion.

@DanHeidinga

This comment has been minimized.

Contributor

DanHeidinga commented Feb 15, 2018

Looking at the Java 9 JVMS for ireturn, it states:

Prior to pushing value onto the operand stack of the frame of the invoker, it may have to be converted. If the return type of the invoked method was byte, char, or short, then value is converted from int to the return type as if by execution of i2b, i2c, or i2s, respectively. If the return type of the invoked method was boolean, then value is narrowed from int to boolean by taking the bitwise AND of value and 1.

https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-6.html#jvms-6.5.ireturn

We can do this by either:

  • Looking at the return type in the JBreturn1 bytecode (expensive)
  • Adding new internal bytecodes to return c, s, b, z and modifying JBgenericreturn. The verifier will also need to be updated. As will the JIT and potentially the jit return bytecodes, though we may get away with a single one if the compiled code can ensure the conversion has already occurred.
@dnakamura

This comment has been minimized.

Contributor

dnakamura commented Feb 28, 2018

I have a solution which does fix the test case (https://github.com/dnakamura/openj9/tree/ret_opcode). Although I'm not sure its the right solution, and of course it needs to add jit support

@pshipton

This comment has been minimized.

Contributor

pshipton commented Feb 28, 2018

It would be easier if a WIP Pull Request is created for the changes.

@DanHeidinga

This comment has been minimized.

Contributor

DanHeidinga commented May 3, 2018

@dnakamura Can you outline the next steps on this?

@dnakamura

This comment has been minimized.

Contributor

dnakamura commented May 3, 2018

Currently the code for executing the new bytecodes is in place. I have changes which will cause the new bytecodes to be emitted, and updates to the verifier. Currently waiting on support in the jit for the new bytecodes. Perhaps @andrewcraik or @fjeremic can provide more details for the jit part

@DanHeidinga

This comment has been minimized.

Contributor

DanHeidinga commented May 3, 2018

Can you open a WIP PR for the remaining VM changes so we can get them reviewed and ready to merge as soon as the jit support is ready?

dnakamura added a commit to dnakamura/openj9 that referenced this issue May 3, 2018

Implement truncated return bytecodes
Add code which emmits the new bytecodes for truncated return types.
See eclipse#999

Signed-off-by: Devin Nakamura <devinn@ca.ibm.com>

dnakamura added a commit to dnakamura/openj9 that referenced this issue May 3, 2018

Implement truncated return bytecodes
Add code which emmits the new bytecodes for truncated return types.
See eclipse#999

Signed-off-by: Devin Nakamura <devinn@ca.ibm.com>

dnakamura added a commit to dnakamura/openj9 that referenced this issue May 25, 2018

Implement truncated return bytecodes
Add code which emmits the new bytecodes for truncated return types.
See eclipse#999

Signed-off-by: Devin Nakamura <devinn@ca.ibm.com>

dnakamura added a commit to dnakamura/openj9 that referenced this issue May 30, 2018

Implement truncated return bytecodes
Add code which emmits the new bytecodes for truncated return types.
See eclipse#999

Signed-off-by: Devin Nakamura <devinn@ca.ibm.com>

dnakamura added a commit to dnakamura/openj9 that referenced this issue May 31, 2018

Implement truncated return bytecodes
Add code which emmits the new bytecodes for truncated return types.
See eclipse#999

Signed-off-by: Devin Nakamura <devinn@ca.ibm.com>

dnakamura added a commit to dnakamura/openj9 that referenced this issue Jun 4, 2018

Implement truncated return bytecodes
Add code which emmits the new bytecodes for truncated return types.
See eclipse#999

Signed-off-by: Devin Nakamura <devinn@ca.ibm.com>

dnakamura added a commit to dnakamura/openj9 that referenced this issue Jun 14, 2018

Implement truncated return bytecodes
Add code which emmits the new bytecodes for truncated return types.
See eclipse#999

Signed-off-by: Devin Nakamura <devinn@ca.ibm.com>

dnakamura added a commit to dnakamura/openj9 that referenced this issue Jun 18, 2018

Implement truncated return bytecodes
Add code which emmits the new bytecodes for truncated return types.
See eclipse#999

Signed-off-by: Devin Nakamura <devinn@ca.ibm.com>

dnakamura added a commit to dnakamura/openj9 that referenced this issue Jun 18, 2018

Implement truncated return bytecodes
Add code which emmits the new bytecodes for truncated return types.
See eclipse#999

Signed-off-by: Devin Nakamura <devinn@ca.ibm.com>

dnakamura added a commit to dnakamura/openj9 that referenced this issue Jun 19, 2018

Implement truncated return bytecodes
Add code which emmits the new bytecodes for truncated return types.
See eclipse#999

Signed-off-by: Devin Nakamura <devinn@ca.ibm.com>

dnakamura added a commit to dnakamura/openj9 that referenced this issue Jun 19, 2018

Implement truncated return bytecodes
Add code which emmits the new bytecodes for truncated return types.
See eclipse#999

Signed-off-by: Devin Nakamura <devinn@ca.ibm.com>

dnakamura added a commit to dnakamura/openj9 that referenced this issue Jun 19, 2018

Implement truncated return bytecodes
Add code which emmits the new bytecodes for truncated return types.
See eclipse#999

Signed-off-by: Devin Nakamura <devinn@ca.ibm.com>

dnakamura added a commit to dnakamura/openj9 that referenced this issue Jun 21, 2018

Implement truncated return bytecodes
Add code which emmits the new bytecodes for truncated return types.
See eclipse#999

Signed-off-by: Devin Nakamura <devinn@ca.ibm.com>

dnakamura added a commit to dnakamura/openj9 that referenced this issue Jun 25, 2018

Implement truncated return bytecodes
Add code which emmits the new bytecodes for truncated return types.
See eclipse#999

Signed-off-by: Devin Nakamura <devinn@ca.ibm.com>

dnakamura added a commit to dnakamura/openj9 that referenced this issue Jul 26, 2018

Implement truncated return bytecodes
Add code which emmits the new bytecodes for truncated return types.
See eclipse#999

Signed-off-by: Devin Nakamura <devinn@ca.ibm.com>

dnakamura added a commit to dnakamura/openj9 that referenced this issue Jul 26, 2018

Implement truncated return bytecodes
Add code which emmits the new bytecodes for truncated return types.
See eclipse#999

Signed-off-by: Devin Nakamura <devinn@ca.ibm.com>

@DanHeidinga DanHeidinga added this to the Release 0.11.0 milestone Oct 11, 2018

dnakamura added a commit to dnakamura/openj9 that referenced this issue Oct 11, 2018

Implement truncated return bytecodes
Add code which emmits the new bytecodes for truncated return types.
See eclipse#999

Signed-off-by: Devin Nakamura <devinn@ca.ibm.com>

dnakamura added a commit to dnakamura/openj9 that referenced this issue Oct 12, 2018

Implement truncated return bytecodes
Add code which emmits the new bytecodes for truncated return types.
See eclipse#999

Signed-off-by: Devin Nakamura <devinn@ca.ibm.com>

dnakamura added a commit to dnakamura/openj9 that referenced this issue Oct 15, 2018

Implement truncated return bytecodes
Add code which emmits the new bytecodes for truncated return types.
See eclipse#999

Signed-off-by: Devin Nakamura <devinn@ca.ibm.com>

dnakamura added a commit to dnakamura/openj9 that referenced this issue Oct 16, 2018

Implement truncated return bytecodes
Add code which emmits the new bytecodes for truncated return types.
See eclipse#999

Signed-off-by: Devin Nakamura <devinn@ca.ibm.com>

dnakamura added a commit to dnakamura/openj9 that referenced this issue Oct 16, 2018

Implement truncated return bytecodes
Add code which emmits the new bytecodes for truncated return types.
See eclipse#999

Signed-off-by: Devin Nakamura <devinn@ca.ibm.com>

dnakamura added a commit to dnakamura/openj9 that referenced this issue Oct 16, 2018

Implement truncated return bytecodes
Add code which emmits the new bytecodes for truncated return types.
See eclipse#999

Signed-off-by: Devin Nakamura <devinn@ca.ibm.com>
@DanHeidinga

This comment has been minimized.

Contributor

DanHeidinga commented Oct 17, 2018

#1831 resolves this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment