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

[GR-52917] Correctness problem when System.arraycopy a byte array #8638

Closed
liyuheng55555 opened this issue Mar 26, 2024 · 2 comments
Closed
Assignees

Comments

@liyuheng55555
Copy link

Steps to reproduce the issue
Run the code below with GraalVm to reproceduce the problem.

import java.nio.ByteBuffer;
import java.util.Arrays;

public class GraalVM {
    public static void main(String[] args) {
        for (int j = 0; j < 10000000; j++) {
            byte[] array1 = ByteBuffer.allocate(8).putLong(0).array();
            byte[] array2 = new byte[6];
            System.arraycopy(array1, 2, array2, 0, array1.length - 2);
            if (!Arrays.toString(array2).equals("[0, 0, 0, 0, 0, 0]")) {
                System.out.println(j);
                System.out.println(Arrays.toString(array1));
                System.out.println(Arrays.toString(array2));
            }
        }
    }
}

If everything goes right, the program won't print anything. Actually it will print something like:

2283065
[0, 0, 0, 0, 0, 0, 0, 0]
[61, -38, -82, -31, 0, 0]
2283066
[0, 0, 0, 0, 0, 0, 0, 0]
[1, 0, 0, 0, 0, 0]
2283067
[0, 0, 0, 0, 0, 0, 0, 0]
[-67, -38, -82, -31, 0, 0]

Describe GraalVM and your environment:

  • java version "21.0.1" 2023-10-17
  • Java(TM) SE Runtime Environment Oracle GraalVM 21.0.1+12.1 (build 21.0.1+12-jvmci-23.1-b19)
  • Java HotSpot(TM) 64-Bit Server VM Oracle GraalVM 21.0.1+12.1 (build 21.0.1+12-jvmci-23.1-b19, mixed mode, sharing)

Also meet this problem in mac(arm verion) + GraalVM 17.0.10

@fniephaus fniephaus changed the title Correctness problem when System.arraycopy a byte array [GR-52917] Correctness problem when System.arraycopy a byte array Mar 26, 2024
@fniephaus
Copy link
Member

Thanks for raising this and the concise reproducer. We'll look into it!

@davleopo
Copy link
Member

davleopo commented Apr 2, 2024

@liyuheng55555 thanks for the nice reproducer. This was fixed by 2bb5ad0 - I also ensured the fix will be present in the upcoming April CPU releases of GraalVM.

@davleopo davleopo closed this as completed Apr 2, 2024
graalvmbot pushed a commit that referenced this issue Apr 15, 2024
….arraycopy a byte array.

PullRequest: graal/17391
graalvmbot pushed a commit that referenced this issue Apr 16, 2024
…m.arraycopy a byte array.

PullRequest: graal/17390
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants