Optimize defaults format: avoid reduntant stack normalization operations

This commit is contained in:
Mikhael Bogdanov
2017-01-25 11:26:15 +01:00
parent fc4be17623
commit 4c7a07bed6
3 changed files with 19 additions and 2 deletions
@@ -938,8 +938,6 @@ public class FunctionCodegen {
InstructionAdapter iv = new InstructionAdapter(mv);
genDefaultSuperCallCheckIfNeeded(iv, functionDescriptor, defaultMethod);
loadExplicitArgumentsOnStack(OBJECT_TYPE, isStatic, signature, generator);
List<JvmMethodParameterSignature> mappedParameters = signature.getValueParameters();
int capturedArgumentsCount = 0;
while (capturedArgumentsCount < mappedParameters.size() &&
@@ -968,7 +966,15 @@ public class FunctionCodegen {
iv.mark(loadArg);
}
}
// load arguments after defaults generation to avoid redundant stack normalization operations
loadExplicitArgumentsOnStack(OBJECT_TYPE, isStatic, signature, generator);
for (int index = 0; index < valueParameters.size(); index++) {
ValueParameterDescriptor parameterDescriptor = valueParameters.get(index);
Type type = mappedParameters.get(capturedArgumentsCount + index).getAsmType();
int parameterIndex = frameMap.getIndex(parameterDescriptor);
generator.putValueIfNeeded(type, StackValue.local(parameterIndex, type));
}
@@ -0,0 +1,5 @@
fun test(a: Int, z: String = try{"1"} catch (e: Exception) {"2"}) {
"Default body"
}
//1 ILOAD 0\s*ALOAD 1\s*INVOKESTATIC DefaultMethodBodyKt\.test \(ILjava/lang/String;\)V
@@ -120,6 +120,12 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest {
doTest(fileName);
}
@TestMetadata("defaultMethodBody.kt")
public void testDefaultMethodBody() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/defaultMethodBody.kt");
doTest(fileName);
}
@TestMetadata("falseSmartCast.kt")
public void testFalseSmartCast() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/falseSmartCast.kt");