in core/src/main/java/org/adoptopenjdk/jitwatch/loader/BytecodeLoader.java [203:421]
public static ClassBC parse(ClassBC parentClassBC, String fqClassName, String[] bytecodeLines, boolean cacheBytecode)
{
ClassBC classBytecode = new ClassBC(parentClassBC, fqClassName);
int pos = 0;
StringBuilder builder = new StringBuilder();
BytecodeSection section = BytecodeSection.NONE;
MemberSignatureParts msp = null;
MemberBytecode memberBytecode = null;
boolean lookClassSignature = false;
while (pos < bytecodeLines.length)
{
String line = bytecodeLines[pos].trim();
pos ++;
if (line.equals("}"))
{
lookClassSignature = true;
continue;
}
if (lookClassSignature && line.startsWith(S_BYTECODE_SIGNATURE))
{
buildClassGenerics(line, classBytecode);
break;
}
}
pos = 0;
while (pos < bytecodeLines.length)
{
String line = bytecodeLines[pos].trim();
if (DEBUG_LOGGING_BYTECODE)
{
logger.debug("Line: '{}'", line);
}
BytecodeSection nextSection = getNextSection(section, line);
if (nextSection != null)
{
sectionFinished(fqClassName, section, msp, builder, memberBytecode, classBytecode);
section = changeSection(nextSection);
pos++;
if (pos < bytecodeLines.length)
{
line = bytecodeLines[pos].trim();
}
}
if (DEBUG_LOGGING_BYTECODE)
{
logger.debug("{} Line: {}", section, line);
}
switch (section)
{
case NONE:
if (couldBeMemberSignature(line))
{
msp = MemberSignatureParts.fromBytecodeSignature(fqClassName, line, classBytecode);
if (DEBUG_LOGGING_BYTECODE)
{
logger.debug("New signature: {}", msp);
}
memberBytecode = new MemberBytecode(classBytecode, msp);
if (DEBUG_LOGGING_BYTECODE)
{
logger.debug("Initialised new MemberBytecode");
}
}
else if (line.startsWith(S_BYTECODE_SIGNATURE))
{
buildClassGenerics(line, classBytecode);
}
else if (line.startsWith(S_BYTECODE_MINOR_VERSION))
{
int minorVersion = getVersionPart(line);
if (minorVersion != -1)
{
classBytecode.setMinorVersion(minorVersion);
}
}
else if (line.startsWith(S_BYTECODE_MAJOR_VERSION))
{
int majorVersion = getVersionPart(line);
if (majorVersion != -1)
{
classBytecode.setMajorVersion(majorVersion);
}
}
else if (line.startsWith(S_BYTECODE_CLASSFILE))
{
String modules = "/modules/";
int startIndex = line.indexOf(modules);
if (startIndex != -1)
{
startIndex += modules.length();
int endIndex = line.indexOf('/', startIndex);
if (endIndex != -1)
{
String moduleName = line.substring(startIndex, endIndex);
classBytecode.setModuleName(moduleName);
}
}
else
{
String jrt = "jrt:/";
startIndex = line.indexOf(jrt);
if (startIndex != -1)
{
startIndex += jrt.length();
int endIndex = line.indexOf('/', startIndex);
if (endIndex != -1)
{
String moduleName = line.substring(startIndex, endIndex);
classBytecode.setModuleName(moduleName);
}
}
}
}
else if (line.startsWith(S_BYTECODE_SOURCE_FILE))
{
String sourceFilename = getSourceFile(line);
if (sourceFilename != null)
{
classBytecode.setSourceFile(sourceFilename);
if (cacheBytecode)
{
SourceMapper.addSourceClassMapping(classBytecode);
}
}
else
{
logger.warn("Couldn't parse source file from line {}", line);
}
}
break;
case INNERCLASSES:
InnerClassRelationship icr = InnerClassRelationship.parse(line);
if (icr != null)
{
if (fqClassName.equals(icr.getParentClass()))
{
classBytecode.addInnerClassName(icr.getChildClass());
}
}
else
{
section = changeSection(BytecodeSection.NONE);
pos--;
}
break;
case CODE:
section = performCODE(fqClassName, classBytecode, builder, section, msp, memberBytecode, line);
break;
case CONSTANT_POOL:
section = performConstantPool(fqClassName, classBytecode, builder, section, msp, memberBytecode, line);
break;
case LINETABLE:
section = performLINETABLE(fqClassName, classBytecode, builder, section, msp, memberBytecode, line);
break;
case RUNTIMEVISIBLEANNOTATIONS:
if (!isRunTimeVisibleAnnotation(line))
{
section = changeSection(BytecodeSection.NONE);
pos--;
}
break;
case LOCALVARIABLETABLE:
if (!isLocalVariableLine(line))
{
section = changeSection(BytecodeSection.NONE);
pos--;
}
break;
case STACKMAPTABLE:
if (!isStackMapTable(line))
{
section = changeSection(BytecodeSection.NONE);
pos--;
}
break;
case EXCEPTIONTABLE:
section = performEXCEPTIONTABLE(fqClassName, classBytecode, builder, section, msp, memberBytecode, line);
break;
}
pos++;
}
return classBytecode;
}