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