OpenJDK / code-tools / jmh
changeset 1487:ee4b8b1f1523
7902620: JMH: Improve padding guidance
author | shade |
---|---|
date | Wed, 26 Feb 2020 11:09:00 +0100 |
parents | 1a48e97d9dea |
children | 455114b5c41d |
files | jmh-core/src/main/java/org/openjdk/jmh/generators/core/Paddings.java jmh-samples/src/main/java/org/openjdk/jmh/samples/JMHSample_22_FalseSharing.java |
diffstat | 2 files changed, 24 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/generators/core/Paddings.java Fri Feb 14 09:42:04 2020 +0100 +++ b/jmh-core/src/main/java/org/openjdk/jmh/generators/core/Paddings.java Wed Feb 26 11:09:00 2020 +0100 @@ -37,7 +37,7 @@ for (int p = 0; p < 16; p++) { StringBuilder sb = new StringBuilder(); sb.append(" "); - sb.append(String.format("boolean p%03d", p * 16 + 0)); + sb.append(String.format("byte p%03d", p * 16 + 0)); for (int q = 1; q < 16; q++) { sb.append(String.format(", p%03d", p * 16 + q)); }
--- a/jmh-samples/src/main/java/org/openjdk/jmh/samples/JMHSample_22_FalseSharing.java Fri Feb 14 09:42:04 2020 +0100 +++ b/jmh-samples/src/main/java/org/openjdk/jmh/samples/JMHSample_22_FalseSharing.java Wed Feb 26 11:09:00 2020 +0100 @@ -101,7 +101,7 @@ * * We can try to alleviate some of the effects with padding. * This is not versatile because JVMs can freely rearrange the - * field order. + * field order, even of the same type. */ @State(Scope.Group) @@ -133,6 +133,12 @@ * using the fact that superclass fields are usually laid out first. * In this construction, the protected field will be squashed between * paddings. + + * It is important to use the smallest data type, so that layouter would + * not generate any gaps that can be taken by later protected subclasses + * fields. Depending on the actual field layout of classes that bear the + * protected fields, we might need more padding to account for "lost" + * padding fields pulled into in their superclass gaps. */ public static class StateHierarchy_1 { @@ -140,8 +146,14 @@ } public static class StateHierarchy_2 extends StateHierarchy_1 { - int p01, p02, p03, p04, p05, p06, p07, p08; - int p11, p12, p13, p14, p15, p16, p17, p18; + byte p01, p02, p03, p04, p05, p06, p07, p08; + byte p11, p12, p13, p14, p15, p16, p17, p18; + byte p21, p22, p23, p24, p25, p26, p27, p28; + byte p31, p32, p33, p34, p35, p36, p37, p38; + byte p41, p42, p43, p44, p45, p46, p47, p48; + byte p51, p52, p53, p54, p55, p56, p57, p58; + byte p61, p62, p63, p64, p65, p66, p67, p68; + byte p71, p72, p73, p74, p75, p76, p77, p78; } public static class StateHierarchy_3 extends StateHierarchy_2 { @@ -149,8 +161,14 @@ } public static class StateHierarchy_4 extends StateHierarchy_3 { - int q01, q02, q03, q04, q05, q06, q07, q08; - int q11, q12, q13, q14, q15, q16, q17, q18; + byte q01, q02, q03, q04, q05, q06, q07, q08; + byte q11, q12, q13, q14, q15, q16, q17, q18; + byte q21, q22, q23, q24, q25, q26, q27, q28; + byte q31, q32, q33, q34, q35, q36, q37, q38; + byte q41, q42, q43, q44, q45, q46, q47, q48; + byte q51, q52, q53, q54, q55, q56, q57, q58; + byte q61, q62, q63, q64, q65, q66, q67, q68; + byte q71, q72, q73, q74, q75, q76, q77, q78; } @State(Scope.Group)