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.specialization;
014
015import org.jikesrvm.compilers.common.CodeArray;
016import org.jikesrvm.compilers.common.CompiledMethod;
017
018/**
019 * This class holds the static array of pointers to instructions
020 * of specialized methods
021 */
022public final class SpecializedMethodPool {
023  private static final int SPECIALIZED_METHOD_COUNT = 1024;
024  static int specializedMethodCount = 0;
025  static CodeArray[] specializedMethods = new CodeArray[SPECIALIZED_METHOD_COUNT];
026
027  public int getSpecializedMethodCount() {
028    return specializedMethodCount;
029  }
030
031  static void registerCompiledMethod(SpecializedMethod m) {
032    int smid = m.getSpecializedMethodIndex();
033    CompiledMethod cm = m.getCompiledMethod();
034    storeSpecializedMethod(cm, smid);
035  }
036
037  /**
038   * Associates a particular compiled method with a specialized method id.
039   *
040   * @param cm the compiled method
041   * @param smid the id of the specialized method
042   */
043  public static void storeSpecializedMethod(CompiledMethod cm, int smid) {
044    specializedMethods[smid] = cm.getEntryCodeArray();
045  }
046
047  /**
048   * @param smid the id of the specialized method
049   * @return whether thereis  a compiled version of a particular specialized method
050   */
051  public static boolean hasCompiledVersion(int smid) {
052    return specializedMethods[smid] != null;
053  }
054
055  /**
056   * @return a new unique integer identifier for a specialized method
057   */
058  public static int createSpecializedMethodID() {
059    specializedMethodCount++;
060    if (specializedMethodCount >= specializedMethods.length) {
061      growSpecializedMethods();
062    }
063    return specializedMethodCount;
064  }
065
066  /**
067   * Increase the capacity of the internal data structures to track
068   * specialized methods.
069   */
070  public static void growSpecializedMethods() {
071    int org_length = specializedMethods.length;
072    int new_length = 2 * org_length;
073    CodeArray[] temp = new CodeArray[new_length];
074    for (int i = 0; i < org_length; i++) {
075      temp[i] = specializedMethods[i];
076    }
077    specializedMethods = temp;
078  }
079}