Set<Entry> ldcRefSet = ldcRefMap.get(curClass);
if (ldcRefSet == null)
ldcRefMap.put(curClass, ldcRefSet = new HashSet<>());
ClassEntry thisClass = curClass.thisClass;
ClassEntry superClass = curClass.superClass;
ClassEntry newClass = null; // class of last _new opcode
int pc = 0; // fill pointer in buf; actual bytecode PC
int numInsns = 0;
int numLabels = 0;
boolean hasEscs = false;
fixupBuf.clear();
for (int i = 0; i < codeOps.length; i++) {
int bc = Instruction.getByte(codeOps, i);
int curPC = pc;
insnMap[numInsns++] = curPC;
if (pc + 10 > buf.length) buf = realloc(buf);
if (numInsns+10 > insnMap.length) insnMap = realloc(insnMap);
if (numLabels+10 > labels.length) labels = realloc(labels);
boolean isWide = false;
if (bc == _wide) {
buf[pc++] = (byte) bc;
bc = Instruction.getByte(codeOps, ++i);
isWide = true;
}
switch (bc) {
case _tableswitch: // apc: (df, lo, hi, (hi-lo+1)*(label))
case _lookupswitch: // apc: (df, nc, nc*(case, label))
{
int caseCount = bc_case_count.getInt();
while ((pc + 30 + caseCount*8) > buf.length)
buf = realloc(buf);
buf[pc++] = (byte) bc;
//initialize apc, df, lo, hi bytes to reasonable bits:
Arrays.fill(buf, pc, pc+30, (byte)0);
Instruction.Switch isw = (Instruction.Switch)
Instruction.at(buf, curPC);
//isw.setDefaultLabel(getLabel(bc_label, code, curPC));
isw.setCaseCount(caseCount);
if (bc == _tableswitch) {
isw.setCaseValue(0, bc_case_value.getInt());
} else {
for (int j = 0; j < caseCount; j++) {
isw.setCaseValue(j, bc_case_value.getInt());
}
}
// Make our getLabel calls later.
labels[numLabels++] = curPC;
pc = isw.getNextPC();
continue;
}
case _iinc:
{
buf[pc++] = (byte) bc;
int local = bc_local.getInt();
int delta;
if (isWide) {
delta = bc_short.getInt();
Instruction.setShort(buf, pc, local); pc += 2;
Instruction.setShort(buf, pc, delta); pc += 2;
} else {
delta = (byte) bc_byte.getByte();
buf[pc++] = (byte)local;
buf[pc++] = (byte)delta;
}
continue;
}
case _sipush:
{
int val = bc_short.getInt();
buf[pc++] = (byte) bc;
Instruction.setShort(buf, pc, val); pc += 2;
continue;
}
case _bipush:
case _newarray:
{
int val = bc_byte.getByte();
buf[pc++] = (byte) bc;
buf[pc++] = (byte) val;
continue;
}
case _ref_escape:
{
// Note that insnMap has one entry for this.
hasEscs = true;
int size = bc_escrefsize.getInt();
Entry ref = bc_escref.getRef();
if (size == 1) ldcRefSet.add(ref);
int fmt;
switch (size) {
case 1: fmt = Fixups.U1_FORMAT; break;
case 2: fmt = Fixups.U2_FORMAT; break;
default: assert(false); fmt = 0;
}
fixupBuf.add(pc, fmt, ref);
buf[pc+0] = buf[pc+1] = 0;
pc += size;
}
continue;
case _byte_escape:
{
// Note that insnMap has one entry for all these bytes.
hasEscs = true;
int size = bc_escsize.getInt();
while ((pc + size) > buf.length)
buf = realloc(buf);
while (size-- > 0) {
buf[pc++] = (byte) bc_escbyte.getByte();
}
}
continue;
default:
if (Instruction.isInvokeInitOp(bc)) {
int idx = (bc - _invokeinit_op);
int origBC = _invokespecial;
ClassEntry classRef;
switch (idx) {
case _invokeinit_self_option:
classRef = thisClass; break;
case _invokeinit_super_option:
classRef = superClass; break;
default:
assert(idx == _invokeinit_new_option);
classRef = newClass; break;
}
buf[pc++] = (byte) origBC;
int coding = bc_initref.getInt();
// Find the nth overloading of <init> in classRef.
MemberEntry ref = pkg.cp.getOverloadingForIndex(CONSTANT_Methodref, classRef, "<init>", coding);
fixupBuf.add(pc, Fixups.U2_FORMAT, ref);
buf[pc+0] = buf[pc+1] = 0;
pc += 2;
assert(Instruction.opLength(origBC) == (pc - curPC));
continue;
}
if (Instruction.isSelfLinkerOp(bc)) {
int idx = (bc - _self_linker_op);
boolean isSuper = (idx >= _self_linker_super_flag);
if (isSuper) idx -= _self_linker_super_flag;
boolean isAload = (idx >= _self_linker_aload_flag);
if (isAload) idx -= _self_linker_aload_flag;
int origBC = _first_linker_op + idx;
boolean isField = Instruction.isFieldOp(origBC);
CPRefBand bc_which;
ClassEntry which_cls = isSuper ? superClass : thisClass;
Index which_ix;
if (isField) {
bc_which = isSuper ? bc_superfield : bc_thisfield;
which_ix = pkg.cp.getMemberIndex(CONSTANT_Fieldref, which_cls);
} else {