RFR(S) 8182473: Optimize value type layout to max alignment of fields

Frederic Parain frederic.parain at oracle.com
Thu Jun 29 16:45:36 UTC 2017


Mr Simms,

I’ve run the ValueTypeCreation test with -XX:+PrintValueLayout to see the
layout of the different value types.
Here’s the output:

java.lang.__Value: field layout
  @ 16 --- instance fields start ---
  @ 16 --- instance fields end ---
  @ 16 --- instance ends ---
  @112 --- static fields start ---
  @112 --- static fields end ---

  OopMapBlocks:   0  /  0

runtime.valhalla.valuetypes.Point: field layout
  @ 16 --- instance fields start ---
  @ 16 "x" I
  @ 20 "y" I
  @ 24 --- instance fields end ---
  @ 24 --- instance ends ---
  @112 --- static fields start ---
  @112 --- static fields end ---

  OopMapBlocks:   0  /  0

runtime.valhalla.valuetypes.Long8Value: field layout
  @ 16 --- instance fields start ---
  @ 16 "longField1" J
  @ 24 "longField2" J
  @ 32 "longField3" J
  @ 40 "longField4" J
  @ 48 "longField5" J
  @ 56 "longField6" J
  @ 64 "longField7" J
  @ 72 "longField8" J
  @ 80 --- instance fields end ---
  @ 80 --- instance ends ---
  @112 --- static fields start ---
  @112 --- static fields end ---

  OopMapBlocks:   0  /  0

runtime.valhalla.valuetypes.Person: field layout
  @ 16 --- instance fields start ---
  @ 16 "id" I
  @ 20 "firstName" Ljava.lang.String;
  @ 24 "lastName" Ljava.lang.String;
  @ 32 --- instance fields end ---
  @ 32 --- instance ends ---
  @112 --- static fields start ---
  @112 --- static fields end ---

  OopMapBlocks:   1  /  2
    Offset:  20  - 24 Count:   2

runtime.valhalla.valuetypes.ValueTypeCreation$SmallEmbed: field layout
  @ 16 --- instance fields start ---
  @ 16 "a" B
  @ 17 "b" B
  @ 20 --- instance fields end ---
  @ 24 --- instance ends ---
  @112 --- static fields start ---
  @112 --- static fields end ---

  OopMapBlocks:   0  /  0

runtime.valhalla.valuetypes.ValueTypeCreation$Composition: field layout
  @ 16 --- instance fields start ---
  @ 16 "a" S
  @ 18 "se" Qruntime.valhalla.valuetypes.ValueTypeCreation$SmallEmbed;
  @ 24 "long8Value" Qruntime.valhalla.valuetypes.Long8Value;
  @ 88 "person" Qruntime.valhalla.valuetypes.Person;
  @104 --- instance fields end ---
  @104 --- instance ends ---
  @112 --- static fields start ---
  @112 --- static fields end ---

  OopMapBlocks:   1  /  1
    Offset:  92  - 96 Count:   2

runtime.valhalla.valuetypes.ValueTypeCreation$ValueHolder: field layout
  @ 12 --- instance fields start ---
  @ 16 "a" S
  @ 12 "b" I
  @ 18 "small" Qruntime.valhalla.valuetypes.ValueTypeCreation$SmallEmbed;
  @ 24 "comp" Qruntime.valhalla.valuetypes.ValueTypeCreation$Composition;
  @112 --- instance fields end ---
  @112 --- instance ends ---
  @112 --- static fields start ---
  @112 --- static fields end ---

  OopMapBlocks:   1  /  1
    Offset: 100  -104 Count:   2


The layout of value type runtime.valhalla.valuetypes.Person doesn’t look
optimal: it looks like there’s a gap between the end of the last field, lastName,
which has a size of 4 bytes, and the end of the instance field area.

I don’t know of this issue comes from your changes or if it was already
there before, but as you’re working on the layout_fields() method, could
you look at this issue?

Thank you,

Fred


> On Jun 29, 2017, at 04:58, David Simms <david.simms at oracle.com> wrote:
> 
> Hi all,
> 
> Request for review:
> 
>    RFE: https://bugs.openjdk.java.net/browse/JDK-8182473
> 
>    Webrev: http://cr.openjdk.java.net/~dsimms/valhalla/8182473/webrev0/
> 
> Here is a patch to remove the fixed "jlong" alignment from laying out values within object and values.
> 
> The value type oop base offset remains aligned to "jlong", since "value type oops" are temporary holders, there is no real memory savings to be made otherwise. That is to say published values types in object fields are now no longer padded if no padding is required.
> 
> Otherwise field layout will now try to coerce "small" value types (allocation type sized under NONSTATIC_DOUBLE) into one of other allocation types (NONSTATIC_BYTE, NONSTATIC_SHORT, NONSTATIC_WORD or NONSTATIC_OOP). The rest are laid out at the end of the instance jlong aligned as before (but these are variable jlong aligned size).
> 
> Added basic sanity tests for layout involving value types. Generated layout combination testing needed when/if MVT users are enabled to declare value type fields in classes.
> 
> JPRT, hotspot_tier1, and jdk_valhalla_mvt tests pass.
> 
> /David Simms
> 



More information about the valhalla-dev mailing list