Search in sources :

Example 1 with FieldLayout

use of org.openjdk.jol.info.FieldLayout in project reactor-core by reactor.

the class QueueDrainSubscriberTest method objectPadding.

@Test
public void objectPadding() {
    ClassLayout layout = ClassLayout.parseClass(QueueDrainSubscriber.class);
    AtomicReference<FieldLayout> wip = new AtomicReference<>();
    AtomicReference<FieldLayout> requested = new AtomicReference<>();
    layout.fields().forEach(f -> {
        if ("wip".equals(f.name()))
            wip.set(f);
        else if ("requested".equals(f.name()))
            requested.set(f);
    });
    final FieldLayout fieldAfterRequested = layout.fields().tailSet(requested.get()).stream().skip(1).filter(fl -> fl.name().length() >= 4).findFirst().get();
    assertThat(layout.fields().headSet(wip.get())).as("wip pre-padding").hasSize(15).allSatisfy(fl -> assertThat(fl.name()).startsWith("p"));
    assertThat(layout.fields().subSet(wip.get(), requested.get()).stream().skip(1)).as("wip-requested padding").hasSize(15).allSatisfy(fl -> assertThat(fl.name()).startsWith("p").endsWith("a"));
    assertThat(layout.fields().subSet(requested.get(), fieldAfterRequested).stream().skip(1)).as("requested post-padding").hasSize(15).allSatisfy(fl -> assertThat(fl.name()).startsWith("q").isNotEqualTo("queue"));
    assertThat(wip.get().offset()).as("wip offset").isEqualTo(136);
    assertThat(requested.get().offset()).as("requested offset").isEqualTo(wip.get().offset() + 128);
    System.out.println(wip.get());
    System.out.println(requested.get());
    System.out.println(fieldAfterRequested);
}
Also used : FieldLayout(org.openjdk.jol.info.FieldLayout) ClassLayout(org.openjdk.jol.info.ClassLayout) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.Test)

Aggregations

AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Test (org.junit.Test)1 ClassLayout (org.openjdk.jol.info.ClassLayout)1 FieldLayout (org.openjdk.jol.info.FieldLayout)1