MemoryLayout api

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Tue Jan 21 15:28:30 UTC 2020


On 21/01/2020 15:17, Remi Forax wrote:
> Hi all,
> i've played a little bit with the current version used by the jdk 15 and the one in the branch foreign-memaccess (for the benchmarks).
>
> I really like the API, the MemoryLayout part in particular.
>
> I will do a presentation in two weeks about the foreign API (and everythings else introduced in jdk 14)
>    https://github.com/forax/do-synthetic-methods-dream-of-electric-switch-expressions
> All my tests are available as a python notebook (see the README).
Thanks for the comments Remi
>
> There is something i don't understand.
> The memory layout API let you create layouts that are invalid, i.e. that you can not create any VarHandle on it,
> by example a group (struct or union) that contains a sequence without a size, or a layout that starts with two sequences with no size.
>
> I get why you can have one sequence free, but you can not have more than one, otherwise you can not compute the size of the inner layout.
>
> So why the layout API let users create such badly shaped layout ?
> May i have overlooked something ?

Well, in principle, a sequence without a size is just a layout with a 
size 'hole' in it. If you find a way to 'plug' the hole (let's say that 
all the unsized sequence layouts are preceeded by a ValueLayout which 
specifies the sequence size), then there's a way for you to obtain a new 
layout, derived from the first, which is actually usable for 
allocation/VarHandle computation.

So, in a way, this is to make the layout API partially usable with 
variable-sized structures. Think about classfile attributes e.g.

RuntimeInvisibleParameterAnnotations_attribute {
     u2 attribute_name_index;
     u4 attribute_length;
     u1 num_parameters;
     {   u2         num_annotations;
         annotation annotations[num_annotations];
     } parameter_annotations[num_parameters];
}

These can have multiple sequences whose size is bound dynamically - and 
not statically, right?

Maurizio

>
> regards,
> Rémi
>
>


More information about the panama-dev mailing list