Search in sources :

Example 1 with ClassLayout

use of org.openjdk.jol.info.ClassLayout 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)

Example 2 with ClassLayout

use of org.openjdk.jol.info.ClassLayout in project yyl_example by Relucent.

the class JolExample method main.

public static void main(String[] args) {
    A a = new A();
    ClassLayout aLayout = ClassLayout.parseInstance(a);
    System.out.println("**** Fresh object");
    System.out.println(aLayout.toPrintable());
    synchronized (a) {
        System.out.println("**** With the lock");
        System.out.println(aLayout.toPrintable());
    }
    B b = new B();
    System.out.println(ClassLayout.parseInstance(b).toPrintable());
    Object o = new Object();
    System.out.println(ClassLayout.parseInstance(o).toPrintable());
    int[] ints = new int[0];
    System.out.println(ClassLayout.parseInstance(ints).toPrintable());
    Object[] objects = { true, 0.0D, new Object(), null };
    System.out.println(ClassLayout.parseInstance(objects).toPrintable());
}
Also used : ClassLayout(org.openjdk.jol.info.ClassLayout)

Aggregations

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