Search in sources :

Example 6 with StackValue

use of org.jetbrains.kotlin.codegen.StackValue in project kotlin by JetBrains.

the class MethodInliner method doInline.

@NotNull
private InlineResult doInline(@NotNull MethodVisitor adapter, @NotNull LocalVarRemapper remapper, boolean remapReturn, @NotNull LabelOwner labelOwner, int finallyDeepShift) {
    //analyze body
    MethodNode transformedNode = markPlacesForInlineAndRemoveInlinable(node, labelOwner, finallyDeepShift);
    //substitute returns with "goto end" instruction to keep non local returns in lambdas
    Label end = new Label();
    transformedNode = doInline(transformedNode);
    removeClosureAssertions(transformedNode);
    transformedNode.instructions.resetLabels();
    MethodNode resultNode = new MethodNode(InlineCodegenUtil.API, transformedNode.access, transformedNode.name, transformedNode.desc, transformedNode.signature, ArrayUtil.toStringArray(transformedNode.exceptions));
    RemapVisitor visitor = new RemapVisitor(resultNode, remapper, nodeRemapper);
    try {
        transformedNode.accept(visitor);
    } catch (Throwable e) {
        throw wrapException(e, transformedNode, "couldn't inline method call");
    }
    resultNode.visitLabel(end);
    if (inliningContext.isRoot()) {
        StackValue remapValue = remapper.remap(parameters.getArgsSizeOnStack() + 1).value;
        InternalFinallyBlockInliner.processInlineFunFinallyBlocks(resultNode, lambdasFinallyBlocks, ((StackValue.Local) remapValue).index);
    }
    processReturns(resultNode, labelOwner, remapReturn, end);
    //flush transformed node to output
    resultNode.accept(new MethodBodyVisitor(adapter));
    sourceMapper.endMapping();
    return result;
}
Also used : StackValue(org.jetbrains.kotlin.codegen.StackValue) Label(org.jetbrains.org.objectweb.asm.Label) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with StackValue

use of org.jetbrains.kotlin.codegen.StackValue in project kotlin by JetBrains.

the class RegeneratedLambdaFieldRemapper method getFieldForInline.

@Nullable
@Override
public StackValue getFieldForInline(@NotNull FieldInsnNode node, @Nullable StackValue prefix) {
    assert node.name.startsWith("$$$") : "Captured field template should start with $$$ prefix";
    if (node.name.equals("$$$" + InlineCodegenUtil.THIS)) {
        assert oldOwnerType.equals(node.owner) : "Can't unfold '$$$THIS' parameter";
        return StackValue.LOCAL_0;
    }
    FieldInsnNode fin = new FieldInsnNode(node.getOpcode(), node.owner, node.name.substring(3), node.desc);
    CapturedParamInfo field = findFieldInMyCaptured(fin);
    boolean searchInParent = false;
    if (field == null) {
        field = findFieldInMyCaptured(new FieldInsnNode(Opcodes.GETSTATIC, oldOwnerType, InlineCodegenUtil.THIS$0, Type.getObjectType(parent.getLambdaInternalName()).getDescriptor()));
        searchInParent = true;
        if (field == null) {
            throw new IllegalStateException("Couldn't find captured this " + getLambdaInternalName() + " for " + node.name);
        }
    }
    StackValue result = StackValue.field(field.isSkipped ? Type.getObjectType(parent.parent.getNewLambdaInternalName()) : field.getType(), Type.getObjectType(getNewLambdaInternalName()), /*TODO owner type*/
    field.getNewFieldName(), false, prefix == null ? StackValue.LOCAL_0 : prefix);
    return searchInParent ? parent.getFieldForInline(node, result) : result;
}
Also used : StackValue(org.jetbrains.kotlin.codegen.StackValue) FieldInsnNode(org.jetbrains.org.objectweb.asm.tree.FieldInsnNode) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

StackValue (org.jetbrains.kotlin.codegen.StackValue)7 NotNull (org.jetbrains.annotations.NotNull)3 FieldInsnNode (org.jetbrains.org.objectweb.asm.tree.FieldInsnNode)2 Nullable (org.jetbrains.annotations.Nullable)1 FieldInfo (org.jetbrains.kotlin.codegen.FieldInfo)1 Label (org.jetbrains.org.objectweb.asm.Label)1 InstructionAdapter (org.jetbrains.org.objectweb.asm.commons.InstructionAdapter)1