Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
fwdptr heap overhead
package org.openjdk.jol.datamodel;
import org.openjdk.jol.util.MathUtil;
public class FwdptrDataModel implements DataModel {
private final int align;
private final boolean compressedOops;
private final FwdptrModel fwdptrModel;
public FwdptrDataModel(int align, boolean compressedOops, FwdptrModel fwdptrModel) {
this.align = align;
this.compressedOops = compressedOops;
this.fwdptrModel = fwdptrModel;
}
@Override
public int headerSize() {
return internalHeaderSize(true);
}
@Override
public int arrayHeaderSize() {
return internalHeaderSize(false) + 4;
}
private int internalHeaderSize(boolean alignToOop) {
// compressed: 8 byte mark + 4 byte class
// uncompressed: 8 byte mark + 8 byte class
int headerSize = compressedOops ? 12 : 16;
switch (fwdptrModel) {
case No: return headerSize;
case BeforeObject: return headerSize + align;
case Uncompressed: return MathUtil.align(headerSize, 8) + 8;
case Compressed:
if (alignToOop)
return MathUtil.align(headerSize + 4, oopSize());
else
return headerSize + 4;
default: throw new IllegalStateException();
}
}
@Override
public int sizeOf(String klass) {
if (klass.equals("byte")) return 1;
if (klass.equals("boolean")) return 1;
if (klass.equals("short")) return 2;
if (klass.equals("char")) return 2;
if (klass.equals("int")) return 4;
if (klass.equals("float")) return 4;
if (klass.equals("long")) return 8;
if (klass.equals("double")) return 8;
return oopSize();
}
public int oopSize() {
return compressedOops ? 4 : 8;
}
@Override
public int objectAlignment() {
return align;
}
@Override
public String toString() {
return "X64 model, " + align + "-byte aligned, with fwdptr";
}
}
Random JAR-files:
oop || compressed || uncompressed ||
fwdptr || no | bef | unco | comp || no | bef | unco | comp ||
===========||======|======|======|======||======|======|======|======||
align 8 || 1.00 | 1.24 | 1.33 | 1.09 || 1.46 | 1.71 | 1.71 | 1.71 ||
align 16 || 1.09 | 1.57 | 1.47 | 1.20 || 1.55 | 2.04 | 1.86 | 1.86 ||
align 32 || 1.36 | 2.34 | 1.62 | 1.43 || 1.83 | 2.80 | 2.04 | 2.04 ||
Eclipse:
oop || compressed || uncompressed ||
fwdptr || no | bef | unco | comp || no | bef | unco | comp ||
===========||======|======|======|======||======|======|======|======||
align 8 || 1.00 | 1.17 | 1.23 | 1.06 || 1.30 | 1.47 | 1.47 | 1.44 ||
align 16 || 1.09 | 1.43 | 1.31 | 1.16 || 1.36 | 1.71 | 1.58 | 1.54 ||
align 32 || 1.19 | 1.87 | 1.47 | 1.24 || 1.51 | 2.19 | 1.76 | 1.70 ||
IntelliJ:
oop || compressed || uncompressed ||
fwdptr || no | bef | unco | comp || no | bef | unco | comp ||
===========||======|======|======|======||======|======|======|======||
align 8 || 1.00 | 1.12 | 1.16 | 1.05 || 1.22 | 1.33 | 1.33 | 1.31 ||
align 16 || 1.06 | 1.29 | 1.21 | 1.12 || 1.27 | 1.50 | 1.40 | 1.38 ||
align 32 || 1.14 | 1.60 | 1.31 | 1.20 || 1.35 | 1.82 | 1.52 | 1.49 ||
NetBeans:
oop || compressed || uncompressed ||
fwdptr || no | bef | unco | comp || no | bef | unco | comp ||
===========||======|======|======|======||======|======|======|======||
align 8 || 1.00 | 1.14 | 1.19 | 1.04 || 1.26 | 1.40 | 1.40 | 1.37 ||
align 16 || 1.07 | 1.35 | 1.25 | 1.12 || 1.30 | 1.59 | 1.49 | 1.47 ||
align 32 || 1.16 | 1.73 | 1.39 | 1.18 || 1.43 | 2.00 | 1.63 | 1.60 ||
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment