From 61a49f13e18d0f5816a4ef10952507187a254983 Mon Sep 17 00:00:00 2001 From: Michael Bogdanov Date: Wed, 25 Mar 2015 14:35:29 +0300 Subject: [PATCH] ExtendedCallable and some optimazation in CallableMethod --- .../kotlin/codegen/CallableMethod.java | 22 ++++----- .../kotlin/codegen/ExtendedCallable.java | 46 +++++++++++++++++++ 2 files changed, 56 insertions(+), 12 deletions(-) create mode 100644 compiler/backend/src/org/jetbrains/kotlin/codegen/ExtendedCallable.java diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/CallableMethod.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/CallableMethod.java index 2e0b5e5dc15..aaa677ed353 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/CallableMethod.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/CallableMethod.java @@ -37,7 +37,7 @@ import java.util.List; import static org.jetbrains.org.objectweb.asm.Opcodes.INVOKESPECIAL; import static org.jetbrains.org.objectweb.asm.Opcodes.INVOKESTATIC; -public class CallableMethod implements Callable { +public class CallableMethod implements ExtendedCallable { private final Type owner; private final Type defaultImplOwner; private final Type defaultImplParam; @@ -67,6 +67,7 @@ public class CallableMethod implements Callable { this.generateCalleeType = generateCalleeType; } + @Override @NotNull public Type getOwner() { return owner; @@ -94,10 +95,6 @@ public class CallableMethod implements Callable { return signature.getAsmMethod(); } - public int getInvokeOpcode() { - return invokeOpcode; - } - @Nullable public Type getThisType() { return thisClass; @@ -109,9 +106,10 @@ public class CallableMethod implements Callable { } private void invoke(InstructionAdapter v) { - v.visitMethodInsn(getInvokeOpcode(), owner.getInternalName(), getAsmMethod().getName(), getAsmMethod().getDescriptor()); + v.visitMethodInsn(invokeOpcode, owner.getInternalName(), getAsmMethod().getName(), getAsmMethod().getDescriptor()); } + @Override public void invokeWithNotNullAssertion( @NotNull InstructionAdapter v, @NotNull GenerationState state, @@ -121,10 +119,12 @@ public class CallableMethod implements Callable { AsmUtil.genNotNullAssertionForMethod(v, state, resolvedCall); } + @Override public void invokeWithoutAssertions(@NotNull InstructionAdapter v) { invoke(v); } + @Override @Nullable public Type getGenerateCalleeType() { return generateCalleeType; @@ -137,7 +137,7 @@ public class CallableMethod implements Callable { Method method = getAsmMethod(); String desc = JetTypeMapper.getDefaultDescriptor(method, - getInvokeOpcode() == INVOKESTATIC ? null : defaultImplParam.getDescriptor(), + invokeOpcode == INVOKESTATIC ? null : defaultImplParam.getDescriptor(), receiverParameterType != null); if ("".equals(method.getName())) { v.aconst(null); @@ -158,10 +158,7 @@ public class CallableMethod implements Callable { AsmUtil.genNotNullAssertionForMethod(v, state, resolvedCall); } - public boolean isNeedsThis() { - return thisClass != null && generateCalleeType == null; - } - + @Override @NotNull public Type getReturnType() { return signature.getReturnType(); @@ -172,7 +169,8 @@ public class CallableMethod implements Callable { return Printer.OPCODES[invokeOpcode] + " " + owner.getInternalName() + "." + signature; } + @Override public boolean isStaticCall() { - return getInvokeOpcode() == Opcodes.INVOKESTATIC; + return invokeOpcode == Opcodes.INVOKESTATIC; } } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExtendedCallable.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExtendedCallable.java new file mode 100644 index 00000000000..fddce6037e1 --- /dev/null +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExtendedCallable.java @@ -0,0 +1,46 @@ +/* + * Copyright 2010-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.codegen; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.kotlin.codegen.state.GenerationState; +import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall; +import org.jetbrains.org.objectweb.asm.Type; +import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter; + +public interface ExtendedCallable extends Callable { + @NotNull + Type getOwner(); + + void invokeWithNotNullAssertion( + @NotNull InstructionAdapter v, + @NotNull GenerationState state, + @NotNull ResolvedCall resolvedCall + ); + + void invokeWithoutAssertions(@NotNull InstructionAdapter v); + + @Nullable + Type getGenerateCalleeType(); + + @NotNull + Type getReturnType(); + + boolean isStaticCall(); + +}