Skip to content

Unexpected offset for Unsafe.arrayIndexScale #618

@AliveDevil

Description

@AliveDevil

A third-party component we are consuming uses Unsafe.arrayIndexScale(Object[].class), which returns unexpected values (I think 1, instead of 4 or 8).

Should this be amended to return IntPtr.Size for Object[]-arrays as well?

class Main {
    public static void main(String[] args)
    {
        System.out.println(sun.misc.Unsafe.ARRAY_OBJECT_BASE_OFFSET);
        System.out.println(sun.misc.Unsafe.ARRAY_OBJECT_INDEX_SCALE);
    }
}
Program stdout
16
4

Godbolt Sample

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions