8339167: Remove AbstractPoolEntry.PrimitiveEntry to reduce boxing overheads
Reviewed-by: liach
This commit is contained in:
parent
a98ecad0a9
commit
eff6d9cd23
@ -1030,34 +1030,13 @@ public abstract sealed class AbstractPoolEntry {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract static sealed class PrimitiveEntry<T extends ConstantDesc>
|
public static final class IntegerEntryImpl extends AbstractPoolEntry implements IntegerEntry {
|
||||||
extends AbstractPoolEntry {
|
|
||||||
protected final T val;
|
|
||||||
|
|
||||||
public PrimitiveEntry(ConstantPool constantPool, int tag, int index, T val) {
|
private final int val;
|
||||||
super(constantPool, tag, index, hash1(tag, val.hashCode()));
|
|
||||||
this.val = val;
|
|
||||||
}
|
|
||||||
|
|
||||||
public T value() {
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConstantDesc constantValue() {
|
|
||||||
return value();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "" + tag() + value();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final class IntegerEntryImpl extends PrimitiveEntry<Integer>
|
|
||||||
implements IntegerEntry {
|
|
||||||
|
|
||||||
IntegerEntryImpl(ConstantPool cpm, int index, int i) {
|
IntegerEntryImpl(ConstantPool cpm, int index, int i) {
|
||||||
super(cpm, ClassFile.TAG_INTEGER, index, i);
|
super(cpm, ClassFile.TAG_INTEGER, index, hash1(ClassFile.TAG_INTEGER, Integer.hashCode(i)));
|
||||||
|
val = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -1073,7 +1052,12 @@ public abstract sealed class AbstractPoolEntry {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int intValue() {
|
public int intValue() {
|
||||||
return value();
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ConstantDesc constantValue() {
|
||||||
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -1086,11 +1070,14 @@ public abstract sealed class AbstractPoolEntry {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class FloatEntryImpl extends PrimitiveEntry<Float>
|
public static final class FloatEntryImpl extends AbstractPoolEntry
|
||||||
implements FloatEntry {
|
implements FloatEntry {
|
||||||
|
|
||||||
|
private final float val;
|
||||||
|
|
||||||
FloatEntryImpl(ConstantPool cpm, int index, float f) {
|
FloatEntryImpl(ConstantPool cpm, int index, float f) {
|
||||||
super(cpm, ClassFile.TAG_FLOAT, index, f);
|
super(cpm, ClassFile.TAG_FLOAT, index, hash1(ClassFile.TAG_FLOAT, Float.hashCode(f)));
|
||||||
|
val = f;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -1106,7 +1093,12 @@ public abstract sealed class AbstractPoolEntry {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float floatValue() {
|
public float floatValue() {
|
||||||
return value();
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ConstantDesc constantValue() {
|
||||||
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -1119,10 +1111,13 @@ public abstract sealed class AbstractPoolEntry {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class LongEntryImpl extends PrimitiveEntry<Long> implements LongEntry {
|
public static final class LongEntryImpl extends AbstractPoolEntry implements LongEntry {
|
||||||
|
|
||||||
|
private final long val;
|
||||||
|
|
||||||
LongEntryImpl(ConstantPool cpm, int index, long l) {
|
LongEntryImpl(ConstantPool cpm, int index, long l) {
|
||||||
super(cpm, ClassFile.TAG_LONG, index, l);
|
super(cpm, ClassFile.TAG_LONG, index, hash1(ClassFile.TAG_LONG, Long.hashCode(l)));
|
||||||
|
val = l;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -1138,7 +1133,12 @@ public abstract sealed class AbstractPoolEntry {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long longValue() {
|
public long longValue() {
|
||||||
return value();
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ConstantDesc constantValue() {
|
||||||
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -1151,10 +1151,13 @@ public abstract sealed class AbstractPoolEntry {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class DoubleEntryImpl extends PrimitiveEntry<Double> implements DoubleEntry {
|
public static final class DoubleEntryImpl extends AbstractPoolEntry implements DoubleEntry {
|
||||||
|
|
||||||
|
private final double val;
|
||||||
|
|
||||||
DoubleEntryImpl(ConstantPool cpm, int index, double d) {
|
DoubleEntryImpl(ConstantPool cpm, int index, double d) {
|
||||||
super(cpm, ClassFile.TAG_DOUBLE, index, d);
|
super(cpm, ClassFile.TAG_DOUBLE, index, hash1(ClassFile.TAG_DOUBLE, Double.hashCode(d)));
|
||||||
|
val = d;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -1170,7 +1173,12 @@ public abstract sealed class AbstractPoolEntry {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double doubleValue() {
|
public double doubleValue() {
|
||||||
return value();
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ConstantDesc constantValue() {
|
||||||
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -266,19 +266,70 @@ public final class SplitConstantPool implements ConstantPoolBuilder {
|
|||||||
return bsm;
|
return bsm;
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T extends ConstantDesc> PoolEntry findPrimitiveEntry(int tag, T val) {
|
private IntegerEntry findIntEntry(int val) {
|
||||||
int hash = AbstractPoolEntry.hash1(tag, val.hashCode());
|
int hash = AbstractPoolEntry.hash1(TAG_INTEGER, Integer.hashCode(val));
|
||||||
EntryMap<PoolEntry> map = map();
|
EntryMap<PoolEntry> map = map();
|
||||||
for (int token = map.firstToken(hash); token != -1; token = map.nextToken(hash, token)) {
|
for (int token = map.firstToken(hash); token != -1; token = map.nextToken(hash, token)) {
|
||||||
PoolEntry e = map.getElementByToken(token);
|
PoolEntry e = map.getElementByToken(token);
|
||||||
if (e.tag() == tag
|
if (e.tag() == TAG_INTEGER
|
||||||
&& e instanceof AbstractPoolEntry.PrimitiveEntry<?> ce
|
&& e instanceof AbstractPoolEntry.IntegerEntryImpl ce
|
||||||
&& ce.value().equals(val))
|
&& ce.intValue() == val)
|
||||||
return e;
|
return ce;
|
||||||
}
|
}
|
||||||
if (!doneFullScan) {
|
if (!doneFullScan) {
|
||||||
fullScan();
|
fullScan();
|
||||||
return findPrimitiveEntry(tag, val);
|
return findIntEntry(val);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private LongEntry findLongEntry(long val) {
|
||||||
|
int hash = AbstractPoolEntry.hash1(TAG_LONG, Long.hashCode(val));
|
||||||
|
EntryMap<PoolEntry> map = map();
|
||||||
|
for (int token = map.firstToken(hash); token != -1; token = map.nextToken(hash, token)) {
|
||||||
|
PoolEntry e = map.getElementByToken(token);
|
||||||
|
if (e.tag() == TAG_LONG
|
||||||
|
&& e instanceof AbstractPoolEntry.LongEntryImpl ce
|
||||||
|
&& ce.longValue() == val)
|
||||||
|
return ce;
|
||||||
|
}
|
||||||
|
if (!doneFullScan) {
|
||||||
|
fullScan();
|
||||||
|
return findLongEntry(val);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private FloatEntry findFloatEntry(float val) {
|
||||||
|
int hash = AbstractPoolEntry.hash1(TAG_FLOAT, Float.hashCode(val));
|
||||||
|
EntryMap<PoolEntry> map = map();
|
||||||
|
for (int token = map.firstToken(hash); token != -1; token = map.nextToken(hash, token)) {
|
||||||
|
PoolEntry e = map.getElementByToken(token);
|
||||||
|
if (e.tag() == TAG_FLOAT
|
||||||
|
&& e instanceof AbstractPoolEntry.FloatEntryImpl ce
|
||||||
|
&& ce.floatValue() == val)
|
||||||
|
return ce;
|
||||||
|
}
|
||||||
|
if (!doneFullScan) {
|
||||||
|
fullScan();
|
||||||
|
return findFloatEntry(val);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private DoubleEntry findDoubleEntry(double val) {
|
||||||
|
int hash = AbstractPoolEntry.hash1(TAG_DOUBLE, Double.hashCode(val));
|
||||||
|
EntryMap<PoolEntry> map = map();
|
||||||
|
for (int token = map.firstToken(hash); token != -1; token = map.nextToken(hash, token)) {
|
||||||
|
PoolEntry e = map.getElementByToken(token);
|
||||||
|
if (e.tag() == TAG_DOUBLE
|
||||||
|
&& e instanceof AbstractPoolEntry.DoubleEntryImpl ce
|
||||||
|
&& ce.doubleValue() == val)
|
||||||
|
return ce;
|
||||||
|
}
|
||||||
|
if (!doneFullScan) {
|
||||||
|
fullScan();
|
||||||
|
return findDoubleEntry(val);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -542,25 +593,25 @@ public final class SplitConstantPool implements ConstantPoolBuilder {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IntegerEntry intEntry(int value) {
|
public IntegerEntry intEntry(int value) {
|
||||||
var e = (IntegerEntry) findPrimitiveEntry(TAG_INTEGER, value);
|
var e = findIntEntry(value);
|
||||||
return e == null ? internalAdd(new AbstractPoolEntry.IntegerEntryImpl(this, size, value)) : e;
|
return e == null ? internalAdd(new AbstractPoolEntry.IntegerEntryImpl(this, size, value)) : e;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FloatEntry floatEntry(float value) {
|
public FloatEntry floatEntry(float value) {
|
||||||
var e = (FloatEntry) findPrimitiveEntry(TAG_FLOAT, value);
|
var e = findFloatEntry(value);
|
||||||
return e == null ? internalAdd(new AbstractPoolEntry.FloatEntryImpl(this, size, value)) : e;
|
return e == null ? internalAdd(new AbstractPoolEntry.FloatEntryImpl(this, size, value)) : e;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LongEntry longEntry(long value) {
|
public LongEntry longEntry(long value) {
|
||||||
var e = (LongEntry) findPrimitiveEntry(TAG_LONG, value);
|
var e = findLongEntry(value);
|
||||||
return e == null ? internalAdd(new AbstractPoolEntry.LongEntryImpl(this, size, value)) : e;
|
return e == null ? internalAdd(new AbstractPoolEntry.LongEntryImpl(this, size, value)) : e;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DoubleEntry doubleEntry(double value) {
|
public DoubleEntry doubleEntry(double value) {
|
||||||
var e = (DoubleEntry) findPrimitiveEntry(TAG_DOUBLE, value);
|
var e = findDoubleEntry(value);
|
||||||
return e == null ? internalAdd(new AbstractPoolEntry.DoubleEntryImpl(this, size, value)) : e;
|
return e == null ? internalAdd(new AbstractPoolEntry.DoubleEntryImpl(this, size, value)) : e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user