Request: give meaningful error message when attempting to use on heap buffers when creating data buffers · Issue #10214 · deeplearning4j/deeplearning4j · GitHub
Skip to content

Request: give meaningful error message when attempting to use on heap buffers when creating data buffers #10214

Open

Description

@sdyura
    @Test
    public void test1() {
        ByteBuffer buffer1 = ByteBuffer.allocateDirect(8 * 6);
        buffer1.asDoubleBuffer().put(new double[]{1, 2, 3, 4, 5, 6});

        ByteBuffer buffer2 = ByteBuffer.wrap(new byte[]{63, -16, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 64, 8, 0, 0, 0, 0, 0, 0, 64, 16, 0, 0, 0, 0, 0, 0, 64, 20, 0, 0, 0, 0, 0, 0, 64, 24, 0, 0, 0, 0, 0, 0});

        assertThat(buffer1).isEqualTo(buffer2);

        DataBuffer dataBuffer1 = Nd4j.createBuffer(buffer1, DataType.DOUBLE, 6, 0);
        DataBuffer dataBuffer2 = Nd4j.createBuffer(buffer2, DataType.DOUBLE, 6, 0); // <~~ crashes the JVM on this line

        assertThat(dataBuffer1.asDouble()).isEqualTo(dataBuffer2.asDouble());
    }

crashes the JVM:

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x000000018b2503f4, pid=83713, tid=3843
#
# JRE version: Java(TM) SE Runtime Environment Oracle GraalVM 21.0.2+13.1 (21.0.2+13) (build 21.0.2+13-LTS-jvmci-23.1-b30)
# Java VM: Java HotSpot(TM) 64-Bit Server VM Oracle GraalVM 21.0.2+13.1 (21.0.2+13-LTS-jvmci-23.1-b30, mixed mode, sharing, tiered, jvmci, jvmci compiler, compressed oops, compressed class ptrs, g1 gc, bsd-aarch64)
# Problematic frame:
# C  [libsystem_platform.dylib+0x33f4]  _platform_memmove+0x1a4
#
# No core dump will be written. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /Users/xxx/hs_err_pid83713.log
#
# If you would like to submit a bug report, please visit:
#   https://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

Process finished with exit code 134 (interrupted by signal 6:SIGABRT)

Activity

  1. agibsonccc commented on Jun 24, 2025

    @agibsonccc
    Contributor

    @sdyura I'm not fixing this. Use Bytebuffer.allocateDirect(..) it works that way for a reason. All nd4j data is off heap.

  2. sdyura commented on Jun 24, 2025

    @sdyura
    ContributorAuthor

    i am not saying non-direct ByteBuffer needs to be supported, but it would have saved me a lot of time if it just gave a useful error message instead of crashing the JVM

  3. agibsonccc commented on Jun 24, 2025

    @agibsonccc
    Contributor

    @sdyura Sorry about that. Let me reword the issue and I'll ensure that's in there.

  4. changed the title [-]using a non-direct ByteBuffer crashes the JVM[/-] [+]Request: give meaningful error message when attempting to use on heap buffers when creating data buffers[/+] on Jun 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    EnhancementNew features and other enhancements

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions