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.jni.ia32;
014
015import org.jikesrvm.VM;
016import org.jikesrvm.architecture.AbstractRegisters;
017import org.jikesrvm.compilers.common.CompiledMethod;
018import org.jikesrvm.ia32.RegisterConstants.GPR;
019import org.jikesrvm.runtime.ExceptionDeliverer;
020import org.vmmagic.unboxed.Address;
021import org.vmmagic.pragma.Uninterruptible;
022
023/**
024 * Exception delivery mechanisms for JNI on IA32
025 */
026public class JNIExceptionDeliverer extends ExceptionDeliverer {
027
028  /**
029   * Deliver exception, not possible for JNI methods
030   * @see org.jikesrvm.runtime.ExceptionDeliverer#deliverException(CompiledMethod, Address, Throwable, AbstractRegisters)
031   */
032  @Uninterruptible
033  @Override
034  public void deliverException(CompiledMethod compiledMethod,
035      Address catchBlockInstructionAddress, Throwable exceptionObject,
036      AbstractRegisters registers) {
037    // this method should never get called as native methods don't have catch blocks
038    if (VM.VerifyAssertions) VM._assert(VM.NOT_REACHED);
039  }
040
041  /**
042   * Unwind registers/stack through JNI method
043   * @see org.jikesrvm.runtime.ExceptionDeliverer#unwindStackFrame(CompiledMethod, AbstractRegisters)
044   */
045  @Uninterruptible
046  @Override
047  public void unwindStackFrame(CompiledMethod compiledMethod,
048      AbstractRegisters registers) {
049    Address fp = registers.getInnermostFramePointer();
050    // Restore nonvolatile registers used by the JNI compiler
051    registers.getGPRs().set(GPR.EDI.value(), fp.plus(JNICompiler.EDI_SAVE_OFFSET).loadWord());
052    registers.getGPRs().set(GPR.EBX.value(), fp.plus(JNICompiler.EBX_SAVE_OFFSET).loadWord());
053    registers.getGPRs().set(GPR.EBP.value(), fp.plus(JNICompiler.EBP_SAVE_OFFSET).loadWord());
054    registers.unwindStackFrame();
055  }
056
057}