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