Fix <clinit> elimination in case of native methods

This commit is contained in:
Alexey Andreev 2020-02-10 16:37:32 +03:00
parent 862b5e79a1
commit 3b1dae4412
4 changed files with 27 additions and 19 deletions

View File

@ -180,7 +180,7 @@ public class RuntimeRenderer {
return false;
}
MethodReader method = cls.getMethod(STRING_INTERN_METHOD);
return method != null && method.getProgram() != null;
return method != null && method.hasModifier(ElementModifier.NATIVE);
}
private void renderRuntimeObjcls() throws IOException {

View File

@ -49,8 +49,10 @@ public class PreOptimizingClassHolderSource implements ClassHolderSource {
return cls;
}
for (MethodHolder method : cls.getMethods()) {
new GlobalValueNumbering(true).optimize(method.getProgram());
new UnusedVariableElimination().optimize(method, method.getProgram());
if (method.getProgram() != null) {
new GlobalValueNumbering(true).optimize(method.getProgram());
new UnusedVariableElimination().optimize(method, method.getProgram());
}
}
return cls;
}

View File

@ -129,7 +129,9 @@ public class ClassRefsRenamer extends AbstractInstructionVisitor {
renamedMethod.setLevel(method.getLevel());
renamedMethod.setProgram(method.getProgram());
rename(method.getAnnotations(), renamedMethod.getAnnotations());
rename(renamedMethod.getProgram());
if (renamedMethod.getProgram() != null) {
rename(renamedMethod.getProgram());
}
renamedMethod.setTypeParameters(rename(method.getTypeParameters()));
GenericValueType genericResultType = method.getGenericResultType();

View File

@ -79,23 +79,27 @@ public class Parser {
ValueType[] signature = MethodDescriptor.parseSignature(node.desc);
MethodHolder method = new MethodHolder(referenceCache.getCached(new MethodDescriptor(node.name, signature)));
parseModifiers(node.access, method, DECL_METHOD);
ProgramParser programParser = new ProgramParser(referenceCache);
programParser.setFileName(fileName);
Program program = programParser.parse(node);
new UnreachableBasicBlockEliminator().optimize(program);
PhiUpdater phiUpdater = new PhiUpdater();
Variable[] argumentMapping = applySignature(program, method.getParameterTypes());
phiUpdater.updatePhis(program, argumentMapping);
method.setProgram(program);
applyDebugNames(program, phiUpdater, programParser, argumentMapping);
parseAnnotations(method.getAnnotations(), node.visibleAnnotations, node.invisibleAnnotations);
applyDebugNames(program, phiUpdater, programParser,
applySignature(program, method.getDescriptor().getParameterTypes()));
while (program.variableCount() <= method.parameterCount()) {
program.createVariable();
if (node.instructions.size() > 0) {
ProgramParser programParser = new ProgramParser(referenceCache);
programParser.setFileName(fileName);
Program program = programParser.parse(node);
new UnreachableBasicBlockEliminator().optimize(program);
PhiUpdater phiUpdater = new PhiUpdater();
Variable[] argumentMapping = applySignature(program, method.getParameterTypes());
phiUpdater.updatePhis(program, argumentMapping);
method.setProgram(program);
applyDebugNames(program, phiUpdater, programParser, argumentMapping);
applyDebugNames(program, phiUpdater, programParser,
applySignature(program, method.getDescriptor().getParameterTypes()));
while (program.variableCount() <= method.parameterCount()) {
program.createVariable();
}
}
if (node.annotationDefault != null) {
method.setAnnotationDefault(parseAnnotationValue(node.annotationDefault));
}