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;
014
015import org.jikesrvm.VM;
016import org.jikesrvm.compilers.common.CodeArray;
017import org.jikesrvm.objectmodel.RuntimeTable;
018import org.vmmagic.Intrinsic;
019import org.vmmagic.pragma.NonMoving;
020import org.vmmagic.pragma.Uninterruptible;
021import org.vmmagic.pragma.UninterruptibleNoWarn;
022
023/**
024 * This class holds a JNI function table, at runtime it is an array with
025 * CodeArray elements
026 */
027@NonMoving
028public final class FunctionTable implements RuntimeTable<CodeArray> {
029
030  /**
031   * The backing data used during boot image writing.
032   */
033  private final CodeArray[] data;
034
035  /**
036   * Private constructor. Can not create instances.
037   * @param size size of the function table
038   */
039  private FunctionTable(int size) {
040    this.data = new CodeArray[size];
041  }
042
043  /**
044   * Create a new ITable of the specified size.
045   *
046   * @param size The size of the ITable
047   * @return The created ITable instance.
048   */
049  public static FunctionTable allocate(int size) {
050    if (VM.VerifyAssertions && VM.runningVM) VM._assert(VM.NOT_REACHED);
051    return new FunctionTable(size);
052  }
053
054  @Override
055  public CodeArray[] getBacking() {
056    if (VM.VerifyAssertions) VM._assert(!VM.runningVM);
057    return data;
058  }
059
060  /**
061   * Get an ITable entry.
062   *
063   * @param index The index of the entry to get
064   * @return The value of that entry
065   */
066  @Override
067  @Intrinsic
068  @Uninterruptible
069  public CodeArray get(int index) {
070    if (VM.VerifyAssertions && VM.runningVM) VM._assert(VM.NOT_REACHED);
071    return data[index];
072  }
073
074  /**
075   * Set an ITable entry.
076   *
077   * @param index The index of the entry to set
078   * @param value The value to set the entry to.
079   */
080  @Override
081  @Intrinsic
082  @UninterruptibleNoWarn("Interruptible code not reachable at runtime")
083  public void set(int index, CodeArray value) {
084    if (VM.VerifyAssertions && VM.runningVM) VM._assert(VM.NOT_REACHED);
085    data[index] = value;
086  }
087
088  /**
089   * Return the length of the ITable
090   */
091  @Override
092  @Intrinsic
093  @Uninterruptible
094  public int length() {
095    if (VM.VerifyAssertions && VM.runningVM) VM._assert(VM.NOT_REACHED);
096    return data.length;
097  }
098}