本文整理汇总了Java中org.openjdk.jol.info.GraphLayout类的典型用法代码示例。如果您正苦于以下问题:Java GraphLayout类的具体用法?Java GraphLayout怎么用?Java GraphLayout使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GraphLayout类属于org.openjdk.jol.info包,在下文中一共展示了GraphLayout类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.openjdk.jol.info.GraphLayout; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
out.println(VM.current().details());
ArrayList<Integer> al = new ArrayList<Integer>();
LinkedList<Integer> ll = new LinkedList<Integer>();
for (int i = 0; i < 1000; i++) {
Integer io = i; // box once
al.add(io);
ll.add(io);
}
al.trimToSize();
PrintWriter pw = new PrintWriter(out);
pw.println(GraphLayout.parseInstance(al).toFootprint());
pw.println(GraphLayout.parseInstance(ll).toFootprint());
pw.println(GraphLayout.parseInstance(al, ll).toFootprint());
pw.close();
}
示例2: main
import org.openjdk.jol.info.GraphLayout; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
out.println(VM.current().details());
// allocate some objects to beef up generations
for (int c = 0; c < 1000000; c++) {
sink = new Object();
}
System.gc();
List<String> list = new ArrayList<String>();
for (int c = 0; c < 1000; c++) {
list.add("Key" + c);
}
for (int c = 1; c <= 10; c++) {
GraphLayout.parseInstance(list).toImage("list-" + c + ".png");
System.gc();
}
}
示例3: main
import org.openjdk.jol.info.GraphLayout; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
out.println(VM.current().details());
// allocate some objects to beef up generations
for (int c = 0; c < 1000000; c++) {
sink = new Object();
}
System.gc();
final int COUNT = 10000;
Object[] array = new Object[COUNT];
for (int c = 0; c < COUNT; c++) {
array[c] = new Object();
}
Object obj = array;
GraphLayout.parseInstance(obj).toImage("array-1-new.png");
for (int c = 2; c <= 5; c++) {
System.gc();
GraphLayout.parseInstance(obj).toImage("array-" + c + "-before.png");
}
for (int c = 0; c < COUNT; c++) {
if (Math.random() < 0.5) {
array[c] = null;
}
}
GraphLayout.parseInstance(obj).toImage("array-6-after.png");
for (int c = 7; c <= 10; c++) {
System.gc();
GraphLayout.parseInstance(obj).toImage("array-" + c + "-after-gc.png");
}
}
示例4: main
import org.openjdk.jol.info.GraphLayout; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
out.println(VM.current().details());
// allocate some objects to beef up generations
for (int c = 0; c < 1000000; c++) {
sink = new Object();
}
System.gc();
final int COUNT = 1000;
ConcurrentHashMap<Object, Object> chm = new ConcurrentHashMap<Object, Object>();
addElements(COUNT, chm);
GraphLayout.parseInstance(chm).toImage("chm-1-new.png");
for (int c = 2; c <= 5; c++) {
GraphLayout.parseInstance(chm).toImage("chm-" + c + "-gc.png");
System.gc();
}
addElements(COUNT, chm);
for (int c = 6; c <= 10; c++) {
GraphLayout.parseInstance(chm).toImage("chm-" + c + "-more-gc.png");
System.gc();
}
}
示例5: main
import org.openjdk.jol.info.GraphLayout; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
out.println(VM.current().details());
PrintWriter pw = new PrintWriter(System.out, true);
Map<Dummy, Void> map = new HashMap<Dummy, Void>();
map.put(new Dummy(1), null);
map.put(new Dummy(2), null);
System.gc();
pw.println(GraphLayout.parseInstance(map).toPrintable());
map.put(new Dummy(2), null);
map.put(new Dummy(2), null);
map.put(new Dummy(2), null);
map.put(new Dummy(2), null);
System.gc();
pw.println(GraphLayout.parseInstance(map).toPrintable());
for (int c = 0; c < 12; c++) {
map.put(new Dummy(2), null);
}
System.gc();
pw.println(GraphLayout.parseInstance(map).toPrintable());
pw.close();
}
示例6: printSize
import org.openjdk.jol.info.GraphLayout; //导入依赖的package包/类
public static void printSize(final @NotNull Object object) {
System.out.println(String.format("%-30s(%-25s)\t %-10s\t%-10s\t%-10s\n",
object.toString(),
object.getClass(),
SimpleAgent.getObjectSize(object),
ObjectLayer.layout(object).instanceSize(),
GraphLayout.parseInstance(object).totalSize()
));
}
示例7: main
import org.openjdk.jol.info.GraphLayout; //导入依赖的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.GraphLayout; //导入依赖的package包/类
/** Run a test and output the memory footprint of the registry. */
@SuppressWarnings("PMD")
public static void main(String[] args) {
if (args.length < 2) {
System.out.println("Usage: perf <registry> <test>");
System.exit(1);
}
Registry registry = run(args[0], args[1]);
GraphLayout igraph = GraphLayout.parseInstance(registry);
System.out.println(igraph.toFootprint());
}
示例9: checkMemoryUsage
import org.openjdk.jol.info.GraphLayout; //导入依赖的package包/类
private void checkMemoryUsage(Registry registry, long limit) {
GraphLayout graph = GraphLayout.parseInstance(registry);
long size = graph.totalSize();
String details = "memory use exceeds limit: " + size + " > " + limit + "\n\n" + graph.toFootprint();
//System.out.println(details);
Assert.assertTrue(details, size <= limit);
}
示例10: main
import org.openjdk.jol.info.GraphLayout; //导入依赖的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());
}
示例11: main
import org.openjdk.jol.info.GraphLayout; //导入依赖的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());
}
示例12: main
import org.openjdk.jol.info.GraphLayout; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
out.println(VM.current().details());
Map<String, String> chm = new ConcurrentHashMap<String, String>();
GraphLayout gl1 = GraphLayout.parseInstance(chm);
chm.put("Foo", "Bar");
GraphLayout gl2 = GraphLayout.parseInstance(chm);
chm.put("Foo2", "Bar2");
GraphLayout gl3 = GraphLayout.parseInstance(chm);
System.out.println(gl2.subtract(gl1).toPrintable());
System.out.println(gl3.subtract(gl2).toPrintable());
}
示例13: main
import org.openjdk.jol.info.GraphLayout; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
out.println(VM.current().details());
PrintWriter pw = new PrintWriter(System.out, true);
// create links
L l1 = new L1();
L l2 = new L2();
L l3 = new L3();
L l4 = new L4();
L l5 = new L5();
L l6 = new L6();
// bind the ring
l1.bind(l2);
l2.bind(l3);
l3.bind(l4);
l4.bind(l5);
l5.bind(l6);
l6.bind(l1);
// current root
L r = l1;
// break all other roots
l1 = l2 = l3 = l4 = l5 = l6 = null;
long lastAddr = VM.current().addressOf(r);
pw.printf("Fresh object is at %x%n", lastAddr);
int moves = 0;
for (int i = 0; i < 100000; i++) {
// scan for L1 and determine it's address
L s = r;
while (!((s = s.link()) instanceof L1)) ;
long cur = VM.current().addressOf(s);
s = null;
// if L1 had moved, then probably the entire ring had also moved
if (cur != lastAddr) {
moves++;
pw.printf("*** Move %2d, L1 is at %x%n", moves, cur);
pw.println("*** Root is " + r.getClass());
pw.println(GraphLayout.parseInstance(r).toPrintable());
// select another link
Random random = new Random();
for (int c = 0; c < random.nextInt(100); c++) {
r = r.link();
}
lastAddr = cur;
}
// make garbage
for (int c = 0; c < 10000; c++) {
sink = new Object();
}
}
pw.close();
}
示例14: printUsage
import org.openjdk.jol.info.GraphLayout; //导入依赖的package包/类
static void printUsage(Object obj) {
long total = GraphLayout.parseInstance(obj).totalSize();
long perItem = Math.round((double) (total) / SIZE);
System.out.println(String.format("%-30s: %-6d bytes\t(%-3d b/item)", obj.getClass(), total, perItem));
}
示例15: testPercolationSize
import org.openjdk.jol.info.GraphLayout; //导入依赖的package包/类
@Test
public void testPercolationSize()
throws Exception {
long percolationSize = GraphLayout.parseInstance(p).totalSize();
assertThat(percolationSize, lessThanOrEqualTo(11 * size * size + 128 * size + 1024));
}