Methods Summary |
---|
protected java.lang.String | argString(){@inheritDoc}
StringBuffer sb = new StringBuffer(100);
int sz = targets.length;
for (int i = 0; i < sz; i++) {
sb.append("\n ");
sb.append(cases.get(i));
sb.append(": ");
sb.append(targets[i]);
}
return sb.toString();
|
public int | codeSize(){@inheritDoc}
return packed ? (int) packedCodeSize(cases) :
(int) sparseCodeSize(cases);
|
public boolean | isPacked()Returns whether or not this instance's data will be output as packed.
return packed;
|
protected java.lang.String | listingString0(boolean noteIndices){@inheritDoc}
int baseAddress = user.getAddress();
StringBuffer sb = new StringBuffer(100);
int sz = targets.length;
sb.append(packed ? "packed" : "sparse");
sb.append("-switch-payload // for switch @ ");
sb.append(Hex.u2(baseAddress));
for (int i = 0; i < sz; i++) {
int absTarget = targets[i].getAddress();
int relTarget = absTarget - baseAddress;
sb.append("\n ");
sb.append(cases.get(i));
sb.append(": ");
sb.append(Hex.u4(absTarget));
sb.append(" // ");
sb.append(Hex.s4(relTarget));
}
return sb.toString();
|
private static long | packedCodeSize(com.android.dx.util.IntList cases)Gets the size of a packed table for the given cases, in 16-bit code
units.
int sz = cases.size();
long low = cases.get(0);
long high = cases.get(sz - 1);
long result = ((high - low + 1)) * 2 + 4;
return (result <= 0x7fffffff) ? result : -1;
|
private static boolean | shouldPack(com.android.dx.util.IntList cases)Determines whether the given list of cases warrant being packed.
int sz = cases.size();
if (sz < 2) {
return true;
}
long packedSize = packedCodeSize(cases);
long sparseSize = sparseCodeSize(cases);
/*
* We pick the packed representation if it is possible and
* would be as small or smaller than 5/4 of the sparse
* representation. That is, we accept some size overhead on
* the packed representation, since that format is faster to
* execute at runtime.
*/
return (packedSize >= 0) && (packedSize <= ((sparseSize * 5) / 4));
|
private static long | sparseCodeSize(com.android.dx.util.IntList cases)Gets the size of a sparse table for the given cases, in 16-bit code
units.
int sz = cases.size();
return (sz * 4L) + 2;
|
public DalvInsn | withRegisters(com.android.dx.rop.code.RegisterSpecList registers){@inheritDoc}
return new SwitchData(getPosition(), user, cases, targets);
|
public void | writeTo(com.android.dx.util.AnnotatedOutput out){@inheritDoc}
int baseAddress = user.getAddress();
int defaultTarget = Dops.PACKED_SWITCH.getFormat().codeSize();
int sz = targets.length;
if (packed) {
int firstCase = (sz == 0) ? 0 : cases.get(0);
int lastCase = (sz == 0) ? 0 : cases.get(sz - 1);
int outSz = lastCase - firstCase + 1;
out.writeShort(Opcodes.PACKED_SWITCH_PAYLOAD);
out.writeShort(outSz);
out.writeInt(firstCase);
int caseAt = 0;
for (int i = 0; i < outSz; i++) {
int outCase = firstCase + i;
int oneCase = cases.get(caseAt);
int relTarget;
if (oneCase > outCase) {
relTarget = defaultTarget;
} else {
relTarget = targets[caseAt].getAddress() - baseAddress;
caseAt++;
}
out.writeInt(relTarget);
}
} else {
out.writeShort(Opcodes.SPARSE_SWITCH_PAYLOAD);
out.writeShort(sz);
for (int i = 0; i < sz; i++) {
out.writeInt(cases.get(i));
}
for (int i = 0; i < sz; i++) {
int relTarget = targets[i].getAddress() - baseAddress;
out.writeInt(relTarget);
}
}
|