AssumptionInlineInfo.java revision 12657:6ef01bd40ce2
1/*
2 * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23package org.graalvm.compiler.phases.common.inlining.info;
24
25import java.util.Collection;
26
27import org.graalvm.compiler.graph.Node;
28import org.graalvm.compiler.nodes.CallTargetNode.InvokeKind;
29import org.graalvm.compiler.nodes.Invoke;
30import org.graalvm.compiler.phases.common.inlining.InliningUtil;
31import org.graalvm.compiler.phases.util.Providers;
32
33import jdk.vm.ci.meta.Assumptions.AssumptionResult;
34import jdk.vm.ci.meta.ResolvedJavaMethod;
35
36/**
37 * Represents an inlining opportunity where the current class hierarchy leads to a monomorphic
38 * target method, but for which an assumption has to be registered because of non-final classes.
39 */
40public class AssumptionInlineInfo extends ExactInlineInfo {
41
42    private final AssumptionResult<?> takenAssumption;
43
44    public AssumptionInlineInfo(Invoke invoke, ResolvedJavaMethod concrete, AssumptionResult<?> takenAssumption) {
45        super(invoke, concrete);
46        this.takenAssumption = takenAssumption;
47    }
48
49    @Override
50    public Collection<Node> inline(Providers providers) {
51        takenAssumption.recordTo(invoke.asNode().graph().getAssumptions());
52        return super.inline(providers);
53    }
54
55    @Override
56    public void tryToDevirtualizeInvoke(Providers providers) {
57        takenAssumption.recordTo(invoke.asNode().graph().getAssumptions());
58        InliningUtil.replaceInvokeCallTarget(invoke, graph(), InvokeKind.Special, concrete);
59    }
60
61    @Override
62    public String toString() {
63        return "assumption " + concrete.format("%H.%n(%p):%r");
64    }
65}
66