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.classloader.NormalMethod;
016import org.jikesrvm.compilers.common.CompiledMethod;
017
018/**
019 * This is the top-level class to support specialized versions of Java methods
020 */
021public final class SpecializedMethod {
022  /**
023   * The method that was specialized
024   */
025  final NormalMethod method;
026
027  /**
028   * Corresponding compiled method
029   */
030  CompiledMethod compiledMethod;
031
032  /**
033   * Specialized Method index into the SpecializedMethods table
034   */
035  final int smid;
036
037  /**
038   * Encodes the rules for generating the specialized code.
039   */
040  final SpecializationContext context;
041
042  SpecializedMethod(NormalMethod source, SpecializationContext context) {
043    this.method = source;
044    this.context = context;
045    this.smid = SpecializedMethodPool.createSpecializedMethodID();
046  }
047
048  /**
049   * Generates the specialized code for this method.
050   */
051  void compile() {
052    compiledMethod = context.specialCompile(method);
053  }
054
055  public NormalMethod getMethod() {
056    return method;
057  }
058
059  public SpecializationContext getSpecializationContext() {
060    return context;
061  }
062
063  public CompiledMethod getCompiledMethod() {
064    return compiledMethod;
065  }
066
067  public void setCompiledMethod(CompiledMethod cm) {
068    compiledMethod = cm;
069  }
070
071  public int getSpecializedMethodIndex() {
072    return smid;
073  }
074
075  @Override
076  public String toString() {
077    return "Specialized " + method + "  (Context: " + context + ")";
078  }
079}