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.adaptive.util;
014
015import org.jikesrvm.classloader.MethodReference;
016
017/**
018 * A unresolved call site is a pair: {@code <MethodReference, bcIndex>}.
019 */
020public final class UnResolvedCallSite {
021
022  /**
023   * Caller method
024   */
025  private final MethodReference methodRef;
026
027  /**
028   * bytecode index of callsite in caller method
029   */
030  private final int bcIndex;
031
032  /**
033   * @param m the MethodReference containing the callsite
034   * @param bci the bytecode index of the callsite within m
035   */
036  public UnResolvedCallSite(MethodReference m, int bci) {
037    if (org.jikesrvm.VM.VerifyAssertions) org.jikesrvm.VM._assert(m != null);
038    methodRef = m;
039    bcIndex = bci;
040  }
041
042  /**
043   * @return method containing the callsite
044   */
045  public MethodReference getMethodRef() {
046    return methodRef;
047  }
048
049  /**
050   * @return call site's bytecode index in its method
051   */
052  public int getBytecodeIndex() {
053    return bcIndex;
054  }
055
056  /**
057   * @return string representation of call site
058   */
059  @Override
060  public String toString() {
061    return "<" + methodRef + ", " + bcIndex + ">";
062  }
063
064  /**
065   * Determine if two call sites are the same.  Exact match: no wild cards.
066   *
067   * @param obj call site to compare to
068   * @return {@code true} if call sites are the same; otherwise, return {@code fales}
069   */
070  @Override
071  public boolean equals(Object obj) {
072    if (obj instanceof UnResolvedCallSite) {
073      UnResolvedCallSite cs = (UnResolvedCallSite) obj;
074      return methodRef.equals(cs.methodRef) && bcIndex == cs.bcIndex;
075    } else {
076      return false;
077    }
078  }
079
080  /**
081   * @return hash code
082   */
083  @Override
084  public int hashCode() {
085    return bcIndex + methodRef.hashCode();
086  }
087}