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.objectmodel;
014    
015    import org.jikesrvm.VM;
016    import org.jikesrvm.ArchitectureSpecific.CodeArray;
017    import org.vmmagic.Intrinsic;
018    import org.vmmagic.pragma.NonMoving;
019    import org.vmmagic.pragma.Uninterruptible;
020    import org.vmmagic.pragma.UninterruptibleNoWarn;
021    
022    /**
023     * This class represents an instance of an interface method table, at runtime it
024     * is an array with CodeArray elements.
025     */
026    @NonMoving
027    public final class IMT implements RuntimeTable<CodeArray> {
028    
029      /**
030       * The backing data used during boot image writing.
031       */
032      private final CodeArray[] data;
033    
034      /**
035       * Private constructor. Can not create instances.
036       */
037      private IMT() {
038        this.data = new CodeArray[TIBLayoutConstants.IMT_METHOD_SLOTS];
039      }
040    
041      @Override
042      public CodeArray[] getBacking() {
043        if (VM.VerifyAssertions) VM._assert(!VM.runningVM);
044        return data;
045      }
046    
047      /**
048       * Creates an IMT.
049       *
050       * @return The created IMT instance.
051       */
052      public static IMT allocate() {
053        if (VM.VerifyAssertions && VM.runningVM) VM._assert(VM.NOT_REACHED);
054        return new IMT();
055      }
056    
057      /**
058       * Gets an entry in the IMT.
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 CodeArray get(int index) {
067        if (VM.VerifyAssertions && VM.runningVM) VM._assert(VM.NOT_REACHED);
068        return data[index];
069      }
070    
071      /**
072       * Sets an entry in the IMT.
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, CodeArray value) {
081        if (VM.VerifyAssertions && VM.runningVM) VM._assert(VM.NOT_REACHED);
082        data[index] = value;
083      }
084    
085      /**
086       * Returns the length of the IMT
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    }