/* * This file is part of the Jikes RVM project (http://jikesrvm.org). * * This file is licensed to You under the Common Public License (CPL); * You may not use this file except in compliance with the License. You * may obtain a copy of the License at * * http://www.opensource.org/licenses/cpl1.0.php * * See the COPYRIGHT.txt file distributed with this work for information * regarding copyright ownership. */ package org.jikesrvm.cellspu; import org.jikesrvm.SubordinateArchitecture; import org.jikesrvm.VM; import org.jikesrvm.memorymanagers.mminterface.MM_Interface; import org.vmmagic.pragma.Uninterruptible; /** * VM_CodeArray represents a code object (contiguous memory region containing code). * The types of the access methods are platform-dependent. */ @Uninterruptible public abstract class VM_CodeArray extends org.jikesrvm.VM_CodeArray { //TODO - make private public int[] data; public VM_CodeArray(int size) { if (VM.runningVM) VM._assert(false); // should be unreachable data = new int[size]; } public int get(int index) { if (VM.runningVM) VM._assert(false); // should be hijacked return data[index]; } public void set(int index, int v) { if (VM.runningVM) VM._assert(false); // should be hijacked data[index] = v; } public int length() { if (VM.runningVM) VM._assert(false); // should be hijacked return data.length; } public Object getBacking() { if (!(VM.writingImage || VM.writingBootImage)) VM.sysFail("VM_CodeArray.getBacking called when not writing boot image"); return data; } /** * A helper class to contain the 'real' methods of VM_CodeArray. * Because Jikes RVM believes that VM_CodeArray is really a Code[] * (ie, an array of primitives), we cannot define non-hijacked methods * on the 'class' VM_CodeArray. */ public static class Factory { /** * Allocate a code array big enough to contain numInstrs instructions. * @param numInstrs the number of instructions to copy from instrs * @param isHot is this an allocation of code for a hot method? * @return a VM_CodeArray containing the instructions */ public static SubordinateArchitecture.VM_CodeArray create(int numInstrs, boolean isHot) { if (VM.runningVM) { return MM_Interface.allocateCodeSubArch(numInstrs, isHot); } else { return SubordinateArchitecture.VM_CodeArray.create(numInstrs); } } } }