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.osr;
014
015 import org.jikesrvm.compilers.opt.OptOptions;
016 import org.jikesrvm.compilers.opt.driver.CompilerPhase;
017 import org.jikesrvm.compilers.opt.driver.OptConstants;
018 import org.jikesrvm.compilers.opt.inlining.InlineSequence;
019 import org.jikesrvm.compilers.opt.ir.IR;
020 import org.jikesrvm.compilers.opt.ir.Instruction;
021 import org.jikesrvm.compilers.opt.ir.InstructionEnumeration;
022
023 /**
024 * OSR_AdjustBCIndex is an optimizing phase performed on HIR.
025 * It adjust the byte code index of instructions from specialized
026 * byte code to its original byte code.
027 */
028
029 public class AdjustBCIndexes extends CompilerPhase {
030
031 public final boolean shouldPerform(OptOptions options) {
032 return true;
033 }
034
035 /**
036 * Return this instance of this phase. This phase contains no
037 * per-compilation instance fields.
038 * @param ir not used
039 * @return this
040 */
041 public CompilerPhase newExecution(IR ir) {
042 return this;
043 }
044
045 public final String getName() { return "AdjustBytecodeIndexes"; }
046
047 public final void perform(IR ir) {
048 if (!ir.method.isForOsrSpecialization()) return;
049 int offset = ir.method.getOsrPrologueLength();
050
051 for (InstructionEnumeration ie = ir.forwardInstrEnumerator(); ie.hasMoreElements();) {
052 Instruction s = ie.next();
053
054 if ((s.position != null) && (s.position.method != ir.method)) {
055 // also adjust InlineSequence of the direct callee
056 InlineSequence caller = s.position.caller;
057 if ((caller != null) && (caller.method == ir.method)) {
058 // adjust the call site's bcIndex
059 s.position.bcIndex -= offset;
060 }
061 continue;
062 }
063
064 if (s.bcIndex >= offset) {
065 s.bcIndex -= offset;
066 } else if (s.bcIndex >= 0) {
067 s.bcIndex = OptConstants.OSR_PROLOGUE;
068 }
069 }
070 }
071 }