Compute default method signature lazily in CallableMethod

To prevent calling mapDefaultMethod for methods which are guaranteed
not to have default parameters (e.g. signature-polymorphic methods)
This commit is contained in:
Alexander Udalov
2018-11-20 19:28:02 +01:00
parent 0331f84ccd
commit b940418604
2 changed files with 9 additions and 9 deletions
@@ -21,7 +21,7 @@ import org.jetbrains.org.objectweb.asm.util.Printer
class CallableMethod(
override val owner: Type,
private val defaultImplOwner: Type?,
private val defaultMethodDesc: String,
computeDefaultMethodDesc: () -> String,
private val signature: JvmMethodSignature,
private val invokeOpcode: Int,
override val dispatchReceiverType: Type?,
@@ -33,6 +33,8 @@ class CallableMethod(
private val isInterfaceMethod: Boolean = Opcodes.INVOKEINTERFACE == invokeOpcode,
private val isDefaultMethodInInterface: Boolean = false
) : Callable {
private val defaultMethodDesc: String by lazy(LazyThreadSafetyMode.PUBLICATION, computeDefaultMethodDesc)
fun getValueParameters(): List<JvmMethodParameterSignature> =
signature.valueParameters
@@ -45,7 +47,6 @@ class CallableMethod(
override val parameterTypes: Array<Type>
get() = getAsmMethod().argumentTypes
override fun genInvokeInstruction(v: InstructionAdapter) {
v.visitMethodInsn(
invokeOpcode,
@@ -797,10 +797,9 @@ public class KotlinTypeMapper {
JvmMethodSignature method = mapSignatureSkipGeneric(descriptor.getOriginal());
Type owner = mapOwner(descriptor);
FunctionDescriptor originalDescriptor = descriptor.getOriginal();
String defaultImplDesc = mapDefaultMethod(originalDescriptor, OwnerKind.IMPLEMENTATION).getDescriptor();
return new CallableMethod(
owner, owner, defaultImplDesc, method, INVOKESPECIAL,
null, null, null, null, null, originalDescriptor.getReturnType(), false, false
owner, owner, () -> mapDefaultMethod(originalDescriptor, OwnerKind.IMPLEMENTATION).getDescriptor(), method,
INVOKESPECIAL, null, null, null, null, null, originalDescriptor.getReturnType(), false, false
);
}
@@ -956,11 +955,11 @@ public class KotlinTypeMapper {
receiverParameterType = null;
}
String defaultImplDesc = mapDefaultMethod(baseMethodDescriptor, getKindForDefaultImplCall(baseMethodDescriptor)).getDescriptor();
return new CallableMethod(
owner, ownerForDefaultImpl, defaultImplDesc, signature, invokeOpcode,
thisClass, dispatchReceiverKotlinType, receiverParameterType, extensionReceiverKotlinType, calleeType, returnKotlinType,
owner, ownerForDefaultImpl,
() -> mapDefaultMethod(baseMethodDescriptor, getKindForDefaultImplCall(baseMethodDescriptor)).getDescriptor(),
signature, invokeOpcode, thisClass, dispatchReceiverKotlinType, receiverParameterType, extensionReceiverKotlinType,
calleeType, returnKotlinType,
jvmTarget.compareTo(JvmTarget.JVM_1_8) >= 0 ? isInterfaceMember : invokeOpcode == INVOKEINTERFACE,
isDefaultMethodInInterface
);