本文整理汇总了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());
}
示例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);
}
示例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());
}
示例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());
}
示例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;
}
示例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();
}
示例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());
}
示例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());
}
}
示例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();
}
示例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();
}
示例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));
}
示例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());
}
示例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);
}
示例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);
}
示例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()));
}