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.ArchitectureSpecific.CodeArray;
017 import org.jikesrvm.objectmodel.RuntimeTable;
018 import org.vmmagic.Intrinsic;
019 import org.vmmagic.pragma.NonMoving;
020 import org.vmmagic.pragma.Uninterruptible;
021 import 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
028 public 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 */
038 private FunctionTable(int size) {
039 this.data = new CodeArray[size];
040 }
041
042 /**
043 * Create a new ITable of the specified size.
044 *
045 * @param size The size of the ITable
046 * @return The created ITable instance.
047 */
048 public static FunctionTable allocate(int size) {
049 if (VM.VerifyAssertions && VM.runningVM) VM._assert(VM.NOT_REACHED);
050 return new FunctionTable(size);
051 }
052
053 /**
054 * Return the backing array (for boot image writing)
055 */
056 public CodeArray[] getBacking() {
057 if (VM.VerifyAssertions) VM._assert(!VM.runningVM);
058 return data;
059 }
060
061 /**
062 * Get an ITable entry.
063 *
064 * @param index The index of the entry to get
065 * @return The value of that entry
066 */
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 @Intrinsic
081 @UninterruptibleNoWarn("Interruptible code not reachable at runtime")
082 public void set(int index, CodeArray value) {
083 if (VM.VerifyAssertions && VM.runningVM) VM._assert(VM.NOT_REACHED);
084 data[index] = value;
085 }
086
087 /**
088 * Return the length of the ITable
089 */
090 @Intrinsic
091 @Uninterruptible
092 public int length() {
093 if (VM.VerifyAssertions && VM.runningVM) VM._assert(VM.NOT_REACHED);
094 return data.length;
095 }
096 }