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 */
013 package org.jikesrvm.jni;
014
015 import org.jikesrvm.VM;
016 import org.jikesrvm.objectmodel.RuntimeTable;
017 import org.vmmagic.Intrinsic;
018 import org.vmmagic.pragma.*;
019 import org.vmmagic.unboxed.AddressArray;
020
021 /**
022 * This class holds a triplet for each entry of the JNI function table.
023 */
024 @NonMoving
025 public 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 */
035 private LinkageTripletTable(int size) {
036 this.data = new AddressArray[size];
037 }
038
039 /**
040 * Create a new LinkageTripletTable of the specified size.
041 *
042 * @param size The size of the LinkageTripletTable
043 * @return The created LinkageTripletTable instance.
044 */
045 public static LinkageTripletTable allocate(int size) {
046 if (VM.VerifyAssertions && VM.runningVM) VM._assert(VM.NOT_REACHED);
047 return new LinkageTripletTable(size);
048 }
049
050 /**
051 * Return the backing array (for boot image writing)
052 */
053 public AddressArray[] getBacking() {
054 if (VM.VerifyAssertions) VM._assert(!VM.runningVM);
055 return data;
056 }
057
058 /**
059 * Get a LinkageTripletTable entry.
060 *
061 * @param index The index of the entry to get
062 * @return The value of that entry
063 */
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 @Intrinsic
078 @UninterruptibleNoWarn("Interruptible code not reachable at runtime")
079 public void set(int index, AddressArray value) {
080 if (VM.VerifyAssertions && VM.runningVM) VM._assert(VM.NOT_REACHED);
081 data[index] = value;
082 }
083
084 /**
085 * Return the length of the LinkageTripletTable
086 */
087 @Intrinsic
088 @Uninterruptible
089 public int length() {
090 if (VM.VerifyAssertions && VM.runningVM) VM._assert(VM.NOT_REACHED);
091 return data.length;
092 }
093 }