Closed janehmueller closed 3 years ago
This is expected behavior as TruffleSqueak implements storage strategies to optimize guest language arrays. You are directly accessing the actual Java object representing the Smalltalk object without considering the optimization. The correct way to access ArrayObjects is to use the ArrayObjectNodes but that can be a bit tricky via interop.
If you want to directly access the object, you can only use getObjectStorage() if the object returns true for isObjectType(). Otherwise it can be isEmptyType(), isLongType(), and so on.
TruffleSqueak's VM introspection capabilities are quite powerful, but you know what comes with great power. 😉
If I have an empty ArrayObject and call
getObjectStorage
on it, I get the following exception:This seems to be caused by the storage object being an integer instead of an array. One has to use
size
first to check if theArrayObject
contains any elements.getObjectLength
can not be used, since it also usesgetObjectStorage