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