当前位置: 首页>>代码示例>>Java>>正文


Java ClassLayout类代码示例

本文整理汇总了Java中org.openjdk.jol.info.ClassLayout的典型用法代码示例。如果您正苦于以下问题:Java ClassLayout类的具体用法?Java ClassLayout怎么用?Java ClassLayout使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ClassLayout类属于org.openjdk.jol.info包,在下文中一共展示了ClassLayout类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import org.openjdk.jol.info.ClassLayout; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    out.println(VM.current().details());

    TimeUnit.SECONDS.sleep(6);

    final A a = new A();

    ClassLayout layout = ClassLayout.parseInstance(a);

    out.println("**** Fresh object");
    out.println(layout.toPrintable());

    synchronized (a) {
        out.println("**** With the lock");
        out.println(layout.toPrintable());
    }

    out.println("**** After the lock");
    out.println(layout.toPrintable());
}
 
开发者ID:tianshuang,项目名称:jol-samples,代码行数:21,代码来源:JOLSample_13_BiasedLocking.java

示例2: sample

import org.openjdk.jol.info.ClassLayout; //导入依赖的package包/类
private static ClassLayout sample() throws ClassNotFoundException {
//        return layout(42);
//        return layout(42L);
//        return layout(0.123);
//        return layout(0.123f);
//        return layout((byte) 0xFF);
//        return layout('x');
//        return layout("helloworld");
//        return layout(new char[]{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l'}); // 12 chars! try less?
//        return layout(this.dummy);
//        return layout(this);
        return layout(Class.forName("java.lang.String"));
//        return layout(Integer.parseInt("255"));
//        return layout(Long.parseLong("DEADBEEF", 0x10));
//        return layout(Class.class);
    }
 
开发者ID:vitaly-chibrikov,项目名称:otus_java_2017_10,代码行数:17,代码来源:ObjectLayer.java

示例3: main

import org.openjdk.jol.info.ClassLayout; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    out.println(VM.current().details());

    final A a = new A();

    ClassLayout layout = ClassLayout.parseInstance(a);

    out.println("**** Fresh object");
    out.println(layout.toPrintable());

    synchronized (a) {
        out.println("**** With the lock");
        out.println(layout.toPrintable());
    }

    out.println("**** After the lock");
    out.println(layout.toPrintable());
}
 
开发者ID:tianshuang,项目名称:jol-samples,代码行数:19,代码来源:JOLSample_12_ThinLocking.java

示例4: main

import org.openjdk.jol.info.ClassLayout; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    Layouter l;

    l = new CurrentLayouter();
    System.out.println("***** " + l);
    System.out.println(ClassLayout.parseClass(A.class, l).toPrintable());

    l = new HotSpotLayouter(new X86_32_DataModel());
    System.out.println("***** " + l);
    System.out.println(ClassLayout.parseClass(A.class, l).toPrintable());

    l = new HotSpotLayouter(new X86_64_DataModel());
    System.out.println("***** " + l);
    System.out.println(ClassLayout.parseClass(A.class, l).toPrintable());

    l = new HotSpotLayouter(new X86_64_COOPS_DataModel());
    System.out.println("***** " + l);
    System.out.println(ClassLayout.parseClass(A.class, l).toPrintable());
}
 
开发者ID:tianshuang,项目名称:jol-samples,代码行数:20,代码来源:JOLSample_10_DataModels.java

示例5: deepInstanceSize

import org.openjdk.jol.info.ClassLayout; //导入依赖的package包/类
/**
 * Computes the size of an instance of this class assuming that all reference fields are non-null
 */
private static int deepInstanceSize(Class<?> clazz)
{
    if (clazz.isArray()) {
        throw new IllegalArgumentException(String.format("Cannot determine size of %s because it contains an array", clazz.getSimpleName()));
    }
    if (clazz.isInterface()) {
        throw new IllegalArgumentException(String.format("%s is an interface", clazz.getSimpleName()));
    }
    if (Modifier.isAbstract(clazz.getModifiers())) {
        throw new IllegalArgumentException(String.format("%s is abstract", clazz.getSimpleName()));
    }
    if (!clazz.getSuperclass().equals(Object.class)) {
        throw new IllegalArgumentException(String.format("Cannot determine size of a subclass. %s extends from %s", clazz.getSimpleName(), clazz.getSuperclass().getSimpleName()));
    }

    int size = ClassLayout.parseClass(clazz).instanceSize();
    for (Field field : clazz.getDeclaredFields()) {
        if (!field.getType().isPrimitive()) {
            size += deepInstanceSize(field.getType());
        }
    }
    return size;
}
 
开发者ID:y-lan,项目名称:presto,代码行数:27,代码来源:BlockBuilderStatus.java

示例6: main

import org.openjdk.jol.info.ClassLayout; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    out.println(VM.current().details());

    PrintWriter pw = new PrintWriter(System.out, true);

    Object o = new Object();

    ClassLayout layout = ClassLayout.parseInstance(o);

    long lastAddr = VM.current().addressOf(o);
    pw.printf("Fresh object is at %x%n", lastAddr);

    int moves = 0;
    for (int i = 0; i < 100000; i++) {
        long cur = VM.current().addressOf(o);
        if (cur != lastAddr) {
            moves++;
            pw.printf("*** Move %2d, object is at %x%n", moves, cur);
            out.println(layout.toPrintable());
            lastAddr = cur;
        }

        // make garbage
        for (int c = 0; c < 10000; c++) {
            sink = new Object();
        }
    }

    pw.close();
}
 
开发者ID:tianshuang,项目名称:jol-samples,代码行数:31,代码来源:JOLSample_19_Promotion.java

示例7: main

import org.openjdk.jol.info.ClassLayout; //导入依赖的package包/类
public static void main(String[] args) {
  new Container().printMe();

  System.out.println(VMSupport.vmDetails());
  System.out.println(ClassLayout.parseClass(Container.class).toPrintable());
  System.out.println(GraphLayout.parseInstance(new Container()).toPrintable());

}
 
开发者ID:msteindorfer,项目名称:criterion,代码行数:9,代码来源:TestMemoryLayout.java

示例8: main

import org.openjdk.jol.info.ClassLayout; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    out.println(VM.current().details());
    out.println(ClassLayout.parseInstance(new long[0]).toPrintable());
    for (int size = 0; size <= 8; size++) {
        out.println(ClassLayout.parseInstance(new byte[size]).toPrintable());
    }
}
 
开发者ID:tianshuang,项目名称:jol-samples,代码行数:8,代码来源:JOLSample_25_ArrayAlignment.java

示例9: main

import org.openjdk.jol.info.ClassLayout; //导入依赖的package包/类
public static void main(String[] args) throws RunnerException {
  System.out.println(ClassInitializationBenchmark.class.getSimpleName());
  Options opt = new OptionsBuilder()
      .include(".*" + ClassInitializationBenchmark.class.getSimpleName() + ".*timeRangecopy_.*")
      .timeUnit(TimeUnit.NANOSECONDS).forks(1).mode(Mode.AverageTime).warmupIterations(5)
      .measurementIterations(5).build();

  System.out.println(VMSupport.vmDetails());
  System.out.println(ClassLayout.parseClass(Map2To0Node.class).toPrintable());

  new Runner(opt).run();
}
 
开发者ID:msteindorfer,项目名称:criterion,代码行数:13,代码来源:ClassInitializationBenchmark.java

示例10: main

import org.openjdk.jol.info.ClassLayout; //导入依赖的package包/类
public static void main(String[] args) throws RunnerException {
  System.out.println(BitmapIndexingBenchmark.class.getSimpleName());
  Options opt =
      new OptionsBuilder().include(".*" + BitmapIndexingBenchmark.class.getSimpleName() + ".*")
          .timeUnit(TimeUnit.NANOSECONDS).forks(0).mode(Mode.AverageTime).warmupIterations(5)
          .measurementIterations(10).build();

  System.out.println(VMSupport.vmDetails());
  System.out.println(ClassLayout.parseClass(Map2To0Node.class).toPrintable());

  new Runner(opt).run();
}
 
开发者ID:msteindorfer,项目名称:criterion,代码行数:13,代码来源:BitmapIndexingBenchmark.java

示例11: main

import org.openjdk.jol.info.ClassLayout; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
  Class<?> bslotClass = Class.forName("stormpot.BSlot");
  Constructor<?> slotConstructor = bslotClass.getConstructor(BlockingQueue.class, AtomicInteger.class);
  slotConstructor.setAccessible(true);
  Object bslot = slotConstructor.newInstance(null, null);
  System.out.println(VMSupport.vmDetails());
  System.out.println(ClassLayout.parseClass(bslotClass).toPrintable(bslot));
}
 
开发者ID:chrisvest,项目名称:object-pool-benchmarks,代码行数:9,代码来源:BSlotObjectLayout.java

示例12: main

import org.openjdk.jol.info.ClassLayout; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    log.info("various vm properties visible via the unsafe");
    log.info(VMSupport.vmDetails());

    log.info("memory layout based on class object at runtime");
    log.info(ClassLayout.parseClass(CodableFieldInfo.class).toPrintable());

    log.info("runtime footprint for the standard java string object for 'heylo friend'");
    String sample = "heylo friend";
    log.info(GraphLayout.parseInstance(sample).toFootprint());
}
 
开发者ID:addthis,项目名称:codec,代码行数:12,代码来源:JolExample.java

示例13: testRetainedSize

import org.openjdk.jol.info.ClassLayout; //导入依赖的package包/类
@Test
public void testRetainedSize()
        throws Exception
{
    int sliceOutputInstanceSize = ClassLayout.parseClass(DynamicSliceOutput.class).instanceSize();
    DynamicSliceOutput output = new DynamicSliceOutput(10);

    long originalRetainedSize = output.getRetainedSize();
    assertEquals(originalRetainedSize, sliceOutputInstanceSize + output.getUnderlyingSlice().getRetainedSize());
    assertEquals(output.size(), 0);
    output.appendLong(0);
    output.appendShort(0);
    assertEquals(output.getRetainedSize(), originalRetainedSize);
    assertEquals(output.size(), 10);
}
 
开发者ID:airlift,项目名称:slice,代码行数:16,代码来源:TestSliceOutput.java

示例14: testRetainedSize

import org.openjdk.jol.info.ClassLayout; //导入依赖的package包/类
@Test
public void testRetainedSize()
        throws Exception
{
    int sliceInstanceSize = ClassLayout.parseClass(Slice.class).instanceSize();
    Slice slice = Slices.allocate(10);
    assertEquals(slice.getRetainedSize(), sizeOfByteArray(10) + sliceInstanceSize);
    assertEquals(slice.length(), 10);
    Slice subSlice = slice.slice(0, 1);
    assertEquals(subSlice.getRetainedSize(), sizeOfByteArray(10) + sliceInstanceSize);
    assertEquals(subSlice.length(), 1);
}
 
开发者ID:airlift,项目名称:slice,代码行数:13,代码来源:TestSlice.java

示例15: testWrapHeapBufferRetainedSize

import org.openjdk.jol.info.ClassLayout; //导入依赖的package包/类
@Test
public void testWrapHeapBufferRetainedSize()
{
    ByteBuffer heapByteBuffer = ByteBuffer.allocate(50);
    Slice slice = Slices.wrappedBuffer(heapByteBuffer);
    assertEquals(slice.getRetainedSize(), ClassLayout.parseClass(Slice.class).instanceSize() + sizeOf(heapByteBuffer.array()));
}
 
开发者ID:airlift,项目名称:slice,代码行数:8,代码来源:TestSlices.java


注:本文中的org.openjdk.jol.info.ClassLayout类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。