001/*
002 *  This file is part of the Jikes RVM project (http://jikesrvm.org).
003 *
004 *  This file is licensed to You under the Eclipse Public License (EPL);
005 *  You may not use this file except in compliance with the License. You
006 *  may obtain a copy of the License at
007 *
008 *      http://www.opensource.org/licenses/eclipse-1.0.php
009 *
010 *  See the COPYRIGHT.txt file distributed with this work for information
011 *  regarding copyright ownership.
012 */
013package org.jikesrvm.compilers.opt.inlining;
014
015import org.jikesrvm.classloader.RVMMethod;
016import org.jikesrvm.classloader.NormalMethod;
017import org.jikesrvm.compilers.common.CompiledMethod;
018import org.jikesrvm.compilers.opt.OptOptions;
019import org.jikesrvm.compilers.opt.ir.Call;
020import org.jikesrvm.compilers.opt.ir.Instruction;
021
022/**
023 * This class holds miscellaneous information regarding the state of
024 * a compilation
025 */
026public final class CompilationState {
027
028  /*
029   * Implementation
030   */
031  private final Instruction call;
032  private final boolean isExtant;
033  private final OptOptions options;
034  private final CompiledMethod cm;
035  private final int realBCI;
036
037  /*
038   * Interface
039   */
040
041  /**
042   * @param call the call instruction being considered for inlining.
043   * @param isExtant is the receiver of a virtual call an extant object?
044   * @param options controlling compiler options
045   * @param cm compiled method of the IR object being compiled
046   * @param realBCI the real bytecode index of the call instruction, not adjusted because of OSR
047   */
048  public CompilationState(Instruction call, boolean isExtant, OptOptions options, CompiledMethod cm, int realBCI) {
049    this.call = call;
050    this.isExtant = isExtant;
051    this.options = options;
052    this.cm = cm;
053    this.realBCI = realBCI;
054  }
055
056  /**
057   * Does this state represent an invokeinterface call?
058   *
059   * @return <code>true</code> if it is an interface call
060   *         or <code>false</code> if it is not.
061   */
062  public boolean isInvokeInterface() {
063    return Call.getMethod(call).isInterface();
064  }
065
066  /**
067   * @return the depth of inlining so far.
068   */
069  public int getInlineDepth() {
070    return call.position.getInlineDepth();
071  }
072
073  /**
074   * @return the call instruction being considered for inlining
075   */
076  public Instruction getCallInstruction() {
077    return call;
078  }
079
080  /**
081   * Obtains the target method from the compilation state.
082   * If a computed target is present, use it.
083   *
084   * @return the obtained target
085   */
086  public RVMMethod obtainTarget() {
087    return Call.getMethod(call).getTarget();
088  }
089
090  /**
091   * @return the controlling compiler options
092   */
093  public OptOptions getOptions() {
094    return options;
095  }
096
097  /**
098   * @return whether or not the receiving object is extant
099   */
100  public boolean getIsExtant() {
101    return isExtant;
102  }
103
104  /**
105   * @return whether or not the target is precise (ie needs no guard)
106   */
107  public boolean getHasPreciseTarget() {
108    return Call.getMethod(call).hasPreciseTarget();
109  }
110
111  /**
112   * @return the root method of the compilation
113   */
114  public NormalMethod getRootMethod() {
115    return call.position.getRootMethod();
116  }
117
118  /**
119   * @return the method being compiled
120   */
121  public NormalMethod getMethod() {
122    return call.position.getMethod();
123  }
124
125  /**
126   * @return the real bytecode index associated with this call
127   */
128  public int getRealBytecodeIndex() {
129    return realBCI;
130  }
131
132  /**
133   * @return the inlining sequence
134   */
135  public InlineSequence getSequence() {
136    return call.position;
137  }
138
139  /**
140   * @return the compiled method
141   */
142  public CompiledMethod getCompiledMethod() {
143    return cm;
144  }
145}