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.adaptive.controller;
014
015import org.jikesrvm.adaptive.database.callgraph.PartialCallGraph;
016import org.jikesrvm.adaptive.measurements.RuntimeMeasurements;
017import org.jikesrvm.adaptive.measurements.listeners.CallDensityListener;
018import org.jikesrvm.adaptive.util.AOSOptions;
019
020/**
021 * Collection of static methods to assist with adaptive inlining.
022 */
023public class AdaptiveInlining {
024
025  /**
026   * A listener that tracks and can report the call density
027   * of the program (fraction of yieldpoints that are taken
028   * at prologue/epilogues).
029   */
030  private static final CallDensityListener callDensityListener = new CallDensityListener();
031
032  /**
033   * Creates the dynamic call graph. This method must be called after
034   * parsing the command-line.
035   *
036   * @param options the AOS options
037   */
038  static void boot(AOSOptions options) {
039    // create and register the dcg as a decayable object
040    // Give it an initial seed weight that approximates the old step
041    // function for edge hotness.  The intent is that early on
042    // (until decay decreases this initial weight), we are conservative in
043    // marking an edge as hot.
044    Controller.dcg = new PartialCallGraph(options.INLINE_AI_SEED_MULTIPLIER * (1 / options.INLINE_AI_HOT_CALLSITE_THRESHOLD));
045    RuntimeMeasurements.registerDecayableObject(Controller.dcg);
046
047    // Track call density: fraction of timer interrupts taken in prologue/epilogue
048    RuntimeMeasurements.installTimerNullListener(callDensityListener);
049    callDensityListener.activate();
050
051    if (options.GATHER_PROFILE_DATA) {
052      RuntimeMeasurements.registerReportableObject(Controller.dcg);
053    }
054  }
055
056  public static double adjustedWeight(double weight) {
057    return weight / (Controller.dcg.getTotalEdgeWeights()) * callDensityListener.callDensity();
058  }
059}