Mercurial > hg > truffle
view graal/GraalCompiler/src/com/sun/c1x/ir/Invoke.java @ 2825:9ba6a8abe894
Fix Invoke bci problem
author | Gilles Duboscq <gilles.duboscq@oracle.com> |
---|---|
date | Mon, 30 May 2011 18:01:32 +0200 |
parents | 9bc0c2eb00d6 |
children | d6f3dbb4e3b5 |
line wrap: on
line source
/* * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package com.sun.c1x.ir; import com.oracle.graal.graph.*; import com.sun.c1x.debug.*; import com.sun.c1x.util.*; import com.sun.cri.bytecode.*; import com.sun.cri.ci.*; import com.sun.cri.ri.*; /** * The {@code Invoke} instruction represents all kinds of method calls. */ public final class Invoke extends StateSplit implements ExceptionEdgeInstruction { private final int argumentCount; private static final int SUCCESSOR_COUNT = 1; private static final int SUCCESSOR_EXCEPTION_EDGE = 0; @Override protected int inputCount() { return super.inputCount() + argumentCount; } @Override protected int successorCount() { return super.successorCount() + SUCCESSOR_COUNT; } /** * The list of instructions that produce input for this instruction. */ public Value argument(int index) { assert index >= 0 && index < argumentCount; return (Value) inputs().get(super.inputCount() + index); } public Value setArgument(int index, Value n) { assert index >= 0 && index < argumentCount; return (Value) inputs().set(super.inputCount() + index, n); } public int argumentCount() { return argumentCount; } /** * The entry to the exception dispatch chain for this invoke. */ @Override public Instruction exceptionEdge() { return (Instruction) successors().get(super.successorCount() + SUCCESSOR_EXCEPTION_EDGE); } public Instruction setExceptionEdge(Instruction n) { return (Instruction) successors().set(super.successorCount() + SUCCESSOR_EXCEPTION_EDGE, n); } public final int opcode; public final RiMethod target; public final RiType returnType; public final int bci; // XXX needed because we can not compute the bci from the sateBefore bci of this Invoke was optimized from INVOKEINTERFACE to INVOKESPECIAL /** * Constructs a new Invoke instruction. * * @param opcode the opcode of the invoke * @param result the result type * @param args the list of instructions producing arguments to the invocation, including the receiver object * @param isStatic {@code true} if this call is static (no receiver object) * @param target the target method being called * @param stateBefore the state before executing the invocation */ public Invoke(int opcode, CiKind result, Value[] args, RiMethod target, RiType returnType, Graph graph, int bci) { super(result, args.length, SUCCESSOR_COUNT, graph); this.opcode = opcode; this.target = target; this.returnType = returnType; this.bci = bci; this.argumentCount = args.length; for (int i = 0; i < args.length; i++) { setArgument(i, args[i]); } } /** * Gets the opcode of this invoke instruction. * @return the opcode */ public int opcode() { return opcode; } /** * Checks whether this is an invocation of a static method. * @return {@code true} if the invocation is a static invocation */ public boolean isStatic() { return opcode == Bytecodes.INVOKESTATIC; } @Override public RiType declaredType() { return returnType; } /** * Gets the instruction that produces the receiver object for this invocation, if any. * @return the instruction that produces the receiver object for this invocation if any, {@code null} if this * invocation does not take a receiver object */ public Value receiver() { assert !isStatic(); return argument(0); } /** * Gets the target method for this invocation instruction. * @return the target method */ public RiMethod target() { return target; } /** * Checks whether this invocation has a receiver object. * @return {@code true} if this invocation has a receiver object; {@code false} otherwise, if this is a * static call */ public boolean hasReceiver() { return !isStatic(); } @Override public void accept(ValueVisitor v) { v.visitInvoke(this); } public CiKind[] signature() { CiKind receiver = isStatic() ? null : target.holder().kind(); return Util.signatureToKinds(target.signature(), receiver); } @Override public void print(LogStream out) { int argStart = 0; if (hasReceiver()) { out.print(receiver()).print('.'); argStart = 1; } RiMethod target = target(); out.print(target.name()).print('('); for (int i = argStart; i < argumentCount; i++) { if (i > argStart) { out.print(", "); } out.print(argument(i)); } out.print(CiUtil.format(") [method: %H.%n(%p):%r]", target, false)); } }