Lwjgl3: Replace Unsafe-based object scanning with a spec-compliat mechanism.

Created on 14 Mar 2021  路  1Comment  路  Source: LWJGL/lwjgl3

Environment

  • LWJGL version: 3.3.0 SNAPSHOT
  • LWJGL build #: X
  • Java version: ALL
  • Platform: Linux|macOS|Windows
  • Module: core

Description

To find private field offsets of DirectByteBuffer, objects are scanned using Unsafe e.g. see MemoryUtil#getFieldOffset

Scanning objects like that is very fragile, field offsets are just a token/cookie, the physical location remains an implementation detail. The JVM may decide the shuffle fields (packing), or even remove fields that are always constant or unused and provide a "fake" offset instead.
The issue was originally reported/found here. Espresso is an alternative, spec-compliant JVM; it uses the OpenJDK class library but an different object model/layout that is not compatible with this pattern.

A spec-compliant improvement would be to scan all fields (instead of all offsets) while searching for a magic constant. This should be more resilient to object layout changes and alignment issues.

Bug

Most helpful comment

Thanks @mukel!

>All comments

Thanks @mukel!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Marcono1234 picture Marcono1234  路  3Comments

SpinyOwl picture SpinyOwl  路  3Comments

Hugobros3 picture Hugobros3  路  7Comments

shathor picture shathor  路  3Comments

Zamundaaa picture Zamundaaa  路  4Comments