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