Object Storage Model: has anybody real-world experience?

Stefan Marr java at stefan-marr.de
Wed Mar 16 14:07:25 UTC 2016

Hi Raffaello:

> On 16 Mar 2016, at 14:21, Raffaello Giulietti <raffaello.giulietti at supsi.ch> wrote:
> More generally, to implement large contiguous heterogeneous collections in dynamically typed languages the OSM does not seem to be of great help: for the elements, one either has to resort to boxed primitives here and there or has to maintain two equally sized (large) Java arrays, one for potential primitives and one for potential objects. Or implement more complex and slower “strategies" to maintain mixed-mode cases.

What you describe sounds very similar to the Storage Strategy work of the PyPy guys [1,2].
This optimization is not provided by the Truffle object model since it is orthogonal to objects.

However, TruffleSOM, SOMns, JRuby+Truffle and other Truffle-based languages use it as well.
So, it might be useful to push that as something reusable into the framework. Don’t think anyone looked into making that happening specifically though.

In TruffleSOM, you can have a look at SArray [3] and the #at: primitive [4] to get a basic impression of how it works.

I haven’t actually seen an implementation that would use two arrays. I think PyPy implements a strategy for mixed int+float lists but beside that, it seems to be rather uncommon that collections are mixed in a way that a specific strategy promises huge gains.

>> In SOMns, i.e., Newspeak, I did not implement the Truffle object model yet, because I got a very similar custom object model (still from my SOM Smalltalk), and in Newspeak, I actually need another version of it for not objects, but classes, because of the inner class semantics.
> As far as I remember, classes in Newspeak are very light-weight objects of predictable shape: not sure if they need the flexibility of the OSM. (Many years ago, long before Graal/Truffle, I tried to implement Newspeak on the JVM with the then upcoming invokedynamic instruction on early-access JDK7 platforms but had to gave up to preserve my nerves.)

The problem with classes in Newspeak is that you essentially need to decouple their identity and their structure, otherwise you won’t get good results with optimization.
If you see many different class objects, which is typically the case with inner classes in Newspeak, you would normally abort optimizing/go to a megamorphic case.
If you decouple the identity and the structure, you can still optimize nicely for the same structure.
SOMns does just that and thereby Newspeak is among the fastest Truffle languages.

Bye the way, are you working on a Truffle language?

Best regards

[1] http://tratt.net/laurie/research/pubs/html/bolz_diekmann_tratt__storage_strategies_for_collections_in_dynamically_typed_languages/
[2] http://soft-dev.org/pubs/pdf/pape_et_al__language_independent_storage_strategies.pdf

[3] https://github.com/smarr/TruffleSOM/blob/master/src/som/vmobjects/SArray.java
[4] https://github.com/smarr/TruffleSOM/blob/master/src/som/primitives/arrays/AtPrim.java

More information about the graal-dev mailing list