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      @Override
054      public CodeArray[] getBacking() {
055        if (VM.VerifyAssertions) VM._assert(!VM.runningVM);
056        return data;
057      }
058    
059      /**
060       * Get an ITable entry.
061       *
062       * @param index The index of the entry to get
063       * @return The value of that entry
064       */
065      @Override
066      @Intrinsic
067      @Uninterruptible
068      public CodeArray get(int index) {
069        if (VM.VerifyAssertions && VM.runningVM) VM._assert(VM.NOT_REACHED);
070        return data[index];
071      }
072    
073      /**
074       * Set an ITable entry.
075       *
076       * @param index The index of the entry to set
077       * @param value The value to set the entry to.
078       */
079      @Override
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      @Override
091      @Intrinsic
092      @Uninterruptible
093      public int length() {
094        if (VM.VerifyAssertions && VM.runningVM) VM._assert(VM.NOT_REACHED);
095        return data.length;
096      }
097    }