java jaf html类_Java ClassLayout類代碼示例

本文整理匯總了Java中org.openjdk.jol.info.ClassLayout類的典型用法代碼示例。如果您正苦於以下問題:Java ClassLayout類的具體用法?Java ClassLayout怎麽用?Java ClassLayout使用的例子?那麽恭喜您, 這裏精選的類代碼示例或許可以為您提供幫助。

ClassLayout類屬於org.openjdk.jol.info包,在下文中一共展示了ClassLayout類的28個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於我們的係統推薦出更棒的Java代碼示例。

示例1: main

​點讚 5

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,

示例2: sample

​點讚 4

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,

示例3: main

​點讚 3

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,

示例4: main

​點讚 3

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,

示例5: deepInstanceSize

​點讚 3

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,

示例6: main

​點讚 3

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,

示例7: main

​點讚 3

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,

示例8: main

​點讚 2

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,

示例9: main

​點讚 2

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,

示例10: main

​點讚 2

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,

示例11: main

​點讚 2

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,

示例12: main

​點讚 2

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,

示例13: testRetainedSize

​點讚 2

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,

示例14: testRetainedSize

​點讚 2

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,

示例15: testWrapHeapBufferRetainedSize

​點讚 2

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,

示例16: main

​點讚 2

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; should see 4 'free bytes' to spend");

log.info(ClassLayout.parseClass(ByteArrayReadOnlyAsciiBuf.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());

log.info("runtime footprint for a ByteArrayReadOnlyUtfBuf object for 'heylo friend'");

ByteArrayReadOnlyUtfBuf utfBuf = new ByteArrayReadOnlyUtfBuf(sample);

log.info(GraphLayout.parseInstance(utfBuf).toFootprint());

}

開發者ID:addthis,項目名稱:basis,代碼行數:16,

示例17: main

​點讚 2

import org.openjdk.jol.info.ClassLayout; //導入依賴的package包/類

public static void main(String[] args) throws Exception {

out.println(VM.current().details());

out.println(ClassLayout.parseClass(Throwable.class).toPrintable());

}

開發者ID:tianshuang,項目名稱:jol-samples,代碼行數:5,

示例18: main

​點讚 2

import org.openjdk.jol.info.ClassLayout; //導入依賴的package包/類

public static void main(String[] args) throws Exception {

out.println(VM.current().details());

out.println(ClassLayout.parseClass(A.class).toPrintable());

}

開發者ID:tianshuang,項目名稱:jol-samples,代碼行數:5,

示例19: main

​點讚 2

import org.openjdk.jol.info.ClassLayout; //導入依賴的package包/類

public static void main(String[] args) throws Exception {

out.println(VM.current().details());

out.println(ClassLayout.parseClass(C.class).toPrintable());

}

開發者ID:tianshuang,項目名稱:jol-samples,代碼行數:5,

示例20: main

​點讚 2

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());

Thread t = new Thread(new Runnable() {

@Override

public void run() {

synchronized (a) {

try {

TimeUnit.SECONDS.sleep(10);

} catch (InterruptedException e) {

return;

}

}

}

});

t.start();

TimeUnit.SECONDS.sleep(1);

out.println("**** Before the lock");

out.println(layout.toPrintable());

synchronized (a) {

out.println("**** With the lock");

out.println(layout.toPrintable());

}

out.println("**** After the lock");

out.println(layout.toPrintable());

System.gc();

out.println("**** After System.gc()");

out.println(layout.toPrintable());

}

開發者ID:tianshuang,項目名稱:jol-samples,代碼行數:44,

示例21: main

​點讚 2

import org.openjdk.jol.info.ClassLayout; //導入依賴的package包/類

public static void main(String[] args) throws Exception {

out.println(VM.current().details());

out.println(ClassLayout.parseClass(Class.class).toPrintable());

}

開發者ID:tianshuang,項目名稱:jol-samples,代碼行數:5,

示例22: main

​點讚 2

import org.openjdk.jol.info.ClassLayout; //導入依賴的package包/類

public static void main(String[] args) throws Exception {

out.println(VM.current().details());

out.println(ClassLayout.parseClass(B.class).toPrintable());

}

開發者ID:tianshuang,項目名稱:jol-samples,代碼行數:5,

示例23: main

​點讚 2

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 A()).toPrintable());

out.println(ClassLayout.parseInstance(new B()).toPrintable());

}

開發者ID:tianshuang,項目名稱:jol-samples,代碼行數:6,

示例24: main

​點讚 2

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());

out.println("hashCode: " + Integer.toHexString(a.hashCode()));

out.println();

out.println("**** After identityHashCode()");

out.println(layout.toPrintable());

}

開發者ID:tianshuang,項目名稱:jol-samples,代碼行數:17,

示例25: layout

​點讚 2

import org.openjdk.jol.info.ClassLayout; //導入依賴的package包/類

public static ClassLayout layout(Class klass) {

return ClassLayout.parseClass(klass);

}

開發者ID:vitaly-chibrikov,項目名稱:otus_java_2017_10,代碼行數:4,

示例26: main

​點讚 2

import org.openjdk.jol.info.ClassLayout; //導入依賴的package包/類

public static void main(String[] args) {

System.out.println(VMSupport.vmDetails());

System.out.println(ClassLayout.parseClass(Integer.class).toPrintable());

}

開發者ID:walle-liao,項目名稱:jaf-examples,代碼行數:5,

示例27: objectPadding

​點讚 2

import org.openjdk.jol.info.ClassLayout; //導入依賴的package包/類

@Test

public void objectPadding() {

ClassLayout layout = ClassLayout.parseClass(QueueDrainSubscriber.class);

AtomicReference wip = new AtomicReference<>();

AtomicReference 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);

}

開發者ID:reactor,項目名稱:reactor-core,代碼行數:48,

示例28: generateSingleStateClass

​點讚 2

import org.openjdk.jol.info.ClassLayout; //導入依賴的package包/類

private static Class extends T> generateSingleStateClass(Class clazz, DynamicClassLoader classLoader)

{

ClassDefinition definition = new ClassDefinition(

a(PUBLIC, FINAL),

makeClassName("Single" + clazz.getSimpleName()),

type(Object.class),

type(clazz));

// Store class size in static field

FieldDefinition classSize = definition.declareField(a(PRIVATE, STATIC, FINAL), "CLASS_SIZE", long.class);

definition.getClassInitializer()

.getBody()

.comment("CLASS_SIZE = ClassLayout.parseClass(%s.class).instanceSize()", definition.getName())

.push(definition.getType())

.invokeStatic(ClassLayout.class, "parseClass", ClassLayout.class, Class.class)

.invokeVirtual(ClassLayout.class, "instanceSize", int.class)

.intToLong()

.putStaticField(classSize);

// Add getter for class size

definition.declareMethod(a(PUBLIC), "getEstimatedSize", type(long.class))

.getBody()

.getStaticField(classSize)

.retLong();

// Generate constructor

MethodDefinition constructor = definition.declareConstructor(a(PUBLIC));

constructor.getBody()

.append(constructor.getThis())

.invokeConstructor(Object.class);

// Generate fields

List fields = enumerateFields(clazz);

for (StateField field : fields) {

generateField(definition, constructor, field);

}

constructor.getBody()

.ret();

return defineClass(definition, clazz, classLoader);

}

開發者ID:y-lan,項目名稱:presto,代碼行數:44,

注:本文中的org.openjdk.jol.info.ClassLayout類示例整理自Github/MSDocs等源碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值