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.osr.ia32;
014
015import static org.jikesrvm.ia32.StackframeLayoutConstants.STACKFRAME_RETURN_ADDRESS_OFFSET;
016
017import org.jikesrvm.VM;
018import org.jikesrvm.compilers.common.CodeArray;
019import org.jikesrvm.runtime.Magic;
020import org.jikesrvm.scheduler.RVMThread;
021import org.vmmagic.pragma.NoInline;
022import org.vmmagic.pragma.Uninterruptible;
023import org.vmmagic.unboxed.Address;
024import org.vmmagic.unboxed.Offset;
025
026/**
027 * A class helps schedule OSRed method, it is called right after thread switch
028 * and highly depends on the calling convention. It should not be interrupted
029 * because it deals with row instruction address.
030 */
031@Uninterruptible
032public final class PostThreadSwitch {
033
034  /**
035   * This method must not be inlined to keep the correctness
036   * This method is called at the end of threadSwitch, the caller
037   * is threadSwitchFrom<...>
038   *
039   * @param myThread the currently running thread
040   */
041  @NoInline
042  public static void postProcess(RVMThread myThread) {
043
044    /* We need to generate thread specific code and install new code.
045    * We have to make sure that no GC happens from here and before
046    * the new code get executed.
047    */
048    // add branch instruction from CTR.
049    CodeArray bridge = myThread.bridgeInstructions;
050
051    Address bridgeaddr = Magic.objectAsAddress(bridge);
052
053    if (VM.TraceOnStackReplacement) {
054      VM.sysWrite("osr post processing\n");
055    }
056
057    Offset offset = myThread.tsFPOffset.plus(STACKFRAME_RETURN_ADDRESS_OFFSET);
058    Magic.objectAsAddress(myThread.getStack()).store(bridgeaddr, offset);
059
060    myThread.tsFPOffset = Offset.zero();
061
062    myThread.isWaitingForOsr = false;
063    myThread.bridgeInstructions = null;
064
065    // no GC should happen until the glue code gets executed.
066  }
067}