in core/src/main/java/org/adoptopenjdk/jitwatch/loader/BytecodeLoader.java [741:854]
public static List<BytecodeInstruction> parseInstructions(final String bytecode)
{
List<BytecodeInstruction> bytecodeInstructions = new ArrayList<>();
if (DEBUG_LOGGING_BYTECODE)
{
logger.debug("Raw bytecode: '{}'", bytecode);
}
String[] lines = bytecode.split(S_NEWLINE);
boolean inSwitch = false;
BCParamSwitch table = new BCParamSwitch();
BytecodeInstruction instruction = null;
for (String line : lines)
{
line = line.trim();
if (DEBUG_LOGGING_BYTECODE)
{
logger.debug("parsing bytecode line: '{}' inSwitch: {}", line, inSwitch);
}
if (inSwitch)
{
if (S_CLOSE_BRACE.equals(line))
{
instruction.addParameter(table);
bytecodeInstructions.add(instruction);
inSwitch = false;
if (DEBUG_LOGGING_BYTECODE)
{
logger.debug("finished switch");
}
}
else
{
String[] parts = line.split(S_COLON);
if (parts.length == 2)
{
table.put(parts[0].trim(), parts[1].trim());
}
else
{
logger.error("Unexpected tableswitch entry: " + line);
}
}
}
else
{
try
{
Matcher matcher = PATTERN_BYTECODE_INSTRUCTION.matcher(line);
if (matcher.find())
{
instruction = new BytecodeInstruction();
String offset = matcher.group(1);
String mnemonic = matcher.group(2);
String paramString = matcher.group(3);
String comment = matcher.group(4);
if (mnemonic.endsWith("_w") && !Opcode.GOTO_W.equals(mnemonic) && !Opcode.JSR_W.equals(mnemonic)
&& !Opcode.LDC_W.equals(mnemonic) && !Opcode.LDC2_W.equals(mnemonic))
{
mnemonic = mnemonic.substring(0, mnemonic.length() - "_w".length());
}
instruction.setOffset(Integer.parseInt(offset));
instruction.setOpcode(Opcode.getByMnemonic(mnemonic));
if (comment != null && comment.trim().length() > 0)
{
instruction.setComment(comment.trim());
}
if (instruction.getOpcode() == Opcode.TABLESWITCH || instruction.getOpcode() == Opcode.LOOKUPSWITCH)
{
if (DEBUG_LOGGING_BYTECODE)
{
logger.debug("Found a table or lookup switch");
}
inSwitch = true;
}
else
{
if (paramString != null && paramString.trim().length() > 0)
{
processParameters(paramString.trim(), instruction);
}
bytecodeInstructions.add(instruction);
}
}
else
{
logger.error("could not parse bytecode: '" + line + "'");
}
}
catch (Exception e)
{
logger.error("Error parsing bytecode line: '" + line + "'", e);
}
}
}
return bytecodeInstructions;
}