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.architecture;
014
015import org.jikesrvm.VM;
016import org.jikesrvm.classloader.TypeReference;
017import org.vmmagic.pragma.NoInline;
018import org.vmmagic.pragma.NoOptCompile;
019import org.vmmagic.unboxed.Address;
020
021/**
022 * Dispatches calls to JNIHelpers to the appropriate architecture-specific class.
023 * <p>
024 * This is necessary until the PowerPC JNI design is changed to match the design
025 * for IA32 JNI (i.e. until PowerPC uses C code to do var args passing on both sides).
026 * When PPC uses C var arg passing, the code can be refactored and moved from the JNI
027 * helpers into a single, architecture-independent class.
028 */
029public final class JNIHelpers {
030
031  public static Object invokeInitializer(Class<?> cls, int methodID, Address argAddress, boolean isJvalue,
032                                         boolean isDotDotStyle) throws Exception {
033    if (VM.BuildForIA32) {
034      return org.jikesrvm.jni.ia32.JNIHelpers.invokeInitializer(cls, methodID, argAddress, isJvalue, isDotDotStyle);
035    } else {
036      if (VM.VerifyAssertions) VM._assert(VM.BuildForPowerPC);
037      return org.jikesrvm.jni.ppc.JNIHelpers.invokeInitializer(cls, methodID, argAddress, isJvalue, isDotDotStyle);
038    }
039  }
040
041  // don't allow inlining because PPC JNI code expects a certain stack frame layout
042  @NoInline
043  @NoOptCompile
044  public static Object invokeWithDotDotVarArg(int methodID, TypeReference expectReturnType) throws Exception {
045    if (VM.BuildForIA32) {
046      // All architectures other than PPC should invoke the C functions
047      if (VM.VerifyAssertions) VM._assert(VM.NOT_REACHED);
048      return org.jikesrvm.jni.ia32.JNIHelpers.invokeWithDotDotVarArg(methodID, expectReturnType);
049    } else {
050      if (VM.VerifyAssertions) VM._assert(VM.BuildForPowerPC);
051      return org.jikesrvm.jni.ppc.JNIHelpers.invokeWithDotDotVarArg(methodID, expectReturnType);
052    }
053  }
054
055  // don't allow inlining because PPC JNI code expects a certain stack frame layout
056  @NoInline
057  @NoOptCompile
058  public static Object invokeWithDotDotVarArg(Object obj, int methodID, TypeReference expectReturnType,
059                                              boolean skip4Args) throws Exception {
060    if (VM.BuildForIA32) {
061      // All architectures other than PPC should invoke the C functions
062      if (VM.VerifyAssertions) VM._assert(VM.NOT_REACHED);
063      return org.jikesrvm.jni.ia32.JNIHelpers.invokeWithDotDotVarArg(obj, methodID, expectReturnType, skip4Args);
064    } else {
065      if (VM.VerifyAssertions) VM._assert(VM.BuildForPowerPC);
066      return org.jikesrvm.jni.ppc.JNIHelpers.invokeWithDotDotVarArg(obj, methodID, expectReturnType, skip4Args);
067    }
068  }
069
070  public static Object invokeWithVarArg(int methodID, Address argAddress, TypeReference expectReturnType)
071      throws Exception {
072    if (VM.BuildForIA32) {
073      return org.jikesrvm.jni.ia32.JNIHelpers.invokeWithVarArg(methodID, argAddress, expectReturnType);
074    } else {
075      if (VM.VerifyAssertions) VM._assert(VM.BuildForPowerPC);
076      return org.jikesrvm.jni.ppc.JNIHelpers.invokeWithVarArg(methodID, argAddress, expectReturnType);
077    }
078  }
079
080  public static Object invokeWithVarArg(Object obj, int methodID, Address argAddress, TypeReference expectReturnType,
081                                        boolean skip4Args) throws Exception {
082    if (VM.BuildForIA32) {
083      return org.jikesrvm.jni.ia32.JNIHelpers.invokeWithVarArg(obj, methodID, argAddress, expectReturnType, skip4Args);
084    } else {
085      if (VM.VerifyAssertions) VM._assert(VM.BuildForPowerPC);
086      return org.jikesrvm.jni.ppc.JNIHelpers.invokeWithVarArg(obj, methodID, argAddress, expectReturnType, skip4Args);
087    }
088  }
089
090}