-
Notifications
You must be signed in to change notification settings - Fork 429
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow method from interfaces to be inlined if it is private and is be…
…ing called from within the interface
- Loading branch information
1 parent
8bb7cc0
commit 7429219
Showing
4 changed files
with
97 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
base/src/test/kotlin/proguard/optimize/peephole/MethodInlinerJava9Test.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package proguard.optimize.peephole | ||
|
||
import io.kotest.core.spec.IsolationMode | ||
import io.kotest.core.spec.style.FreeSpec | ||
import io.kotest.matchers.ints.shouldBeGreaterThan | ||
import proguard.classfile.Clazz | ||
import proguard.classfile.Method | ||
import proguard.classfile.ProgramClass | ||
import proguard.classfile.ProgramMethod | ||
import proguard.classfile.attribute.CodeAttribute | ||
import proguard.classfile.attribute.visitor.AllAttributeVisitor | ||
import proguard.classfile.visitor.AllMethodVisitor | ||
import proguard.classfile.visitor.ClassVisitor | ||
import proguard.classfile.visitor.MultiClassVisitor | ||
import proguard.optimize.info.ProgramClassOptimizationInfoSetter | ||
import proguard.optimize.info.ProgramMemberOptimizationInfoSetter | ||
import proguard.testutils.ClassPoolBuilder | ||
import proguard.testutils.JavaSource | ||
import testutils.RequiresJavaVersion | ||
|
||
@RequiresJavaVersion(9) | ||
class MethodInlinerJava9Test : FreeSpec({ | ||
isolationMode = IsolationMode.InstancePerTest | ||
|
||
"Given a method calling a private method in the same interface" - { | ||
val (programClassPool, _) = ClassPoolBuilder.fromSource( | ||
JavaSource( | ||
"Foo.java", | ||
"""interface Foo { | ||
default void f1() { | ||
f2(); | ||
} | ||
|
||
private static void f2() { | ||
StringBuilder sb = new StringBuilder(); | ||
sb.append(System.currentTimeMillis()); | ||
System.out.println(sb.toString()); | ||
} | ||
}""", | ||
) | ||
) | ||
|
||
val clazz = programClassPool.getClass("Foo") as ProgramClass | ||
val method = clazz.findMethod("f1", "()V") as ProgramMethod | ||
val codeAttr = method.attributes.filterIsInstance<CodeAttribute>()[0] | ||
|
||
val lengthBefore = codeAttr.u4codeLength | ||
|
||
// Initialize optimization info (used when inlining). | ||
val optimizationInfoInitializer: ClassVisitor = MultiClassVisitor( | ||
ProgramClassOptimizationInfoSetter(), | ||
AllMethodVisitor( | ||
ProgramMemberOptimizationInfoSetter() | ||
) | ||
) | ||
|
||
programClassPool.classesAccept(optimizationInfoInitializer) | ||
|
||
// Create a mock method inliner which always returns true. | ||
val methodInliner = object : MethodInliner(false, true, true) { | ||
override fun shouldInline(clazz: Clazz?, method: Method?, codeAttribute: CodeAttribute?): Boolean = true | ||
} | ||
|
||
"Then the interface method is inlined" { | ||
programClassPool.classesAccept( | ||
AllMethodVisitor( | ||
AllAttributeVisitor( | ||
methodInliner | ||
) | ||
) | ||
) | ||
|
||
val lengthAfter = codeAttr.u4codeLength | ||
|
||
lengthAfter shouldBeGreaterThan lengthBefore | ||
} | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters