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.classloader;
014
015import org.jikesrvm.VM;
016import org.jikesrvm.compilers.common.BootImageCompiler;
017import org.jikesrvm.compilers.common.CompiledMethod;
018import org.jikesrvm.compilers.common.CodeArray;
019
020/**
021 * A method that is specialized across all reference types.
022 * <p>
023 * In general as there may not be a 1-1 mapping between objects and the
024 * specialized methods this class is responsible for performing the
025 * mapping.
026 * <p>
027 * Specialized methods must have a static 'invoke' method that matches
028 * the given signature and return type.
029 */
030public abstract class SpecializedMethod {
031
032  /** This specialized method's id */
033  protected final int id;
034
035  protected SpecializedMethod(int id) {
036    this.id = id;
037  }
038
039  /**
040   * @param type the type whose specialzed method is to be returned
041   * @return the specialized method for the given type.
042   */
043  public abstract CodeArray specializeMethod(RVMType type);
044
045  /**
046   * @return the method signature of the specialized method's invoke.
047   */
048  public abstract TypeReference[] getSignature();
049
050  /**
051   * @return the return type of the specialized method's invoke
052   */
053  public abstract TypeReference getReturnType();
054
055  /**
056   * Compile a specialized version of a template method. The template must be a method
057   * that matches the signature of this specialized method class.
058   *
059   * The specialized types are the set of types to tell the compiler to use during specialized
060   * compilation. This array must match the length of the array returned from getSignature.
061   *
062   * @param template The method to use as a template
063   * @param specializedParams The known types of the parameters, possibly more refined than in the template
064   * @return The compiled code array.
065   */
066  protected CompiledMethod compileSpecializedMethod(RVMMethod template, TypeReference[] specializedParams) {
067    NormalMethod normalMethod = (NormalMethod)template;
068    /* Currently only support eagerly compiled methods */
069    if (VM.VerifyAssertions) VM._assert(VM.writingBootImage);
070
071    return BootImageCompiler.compile(normalMethod, specializedParams);
072  }
073}