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.compilers.opt.ssa;
014
015 import org.jikesrvm.compilers.opt.ir.BasicBlock;
016 import org.jikesrvm.compilers.opt.ir.IR;
017 import org.jikesrvm.util.BitVector;
018
019 /**
020 * An HeapVariable represents a heap variable for heap array SSA form
021 */
022 public class HeapVariable<T> {
023 /**
024 * a unique identifier for this heap variable among all heap variables
025 * with this type.
026 */
027 private final int number;
028 /**
029 * a bit vector representing the basic blocks that write to this
030 * variable
031 */
032 private final BitVector definedIn;
033 /**
034 * The type of this heap variable. Must be either a
035 * TypeReference, FieldReference, RVMField or a String
036 */
037 private final T type;
038
039 /**
040 * Create a new Heap variable of a given type, with a given number.
041 *
042 * @param type a FieldReference or TypeReference object, naming the type of this
043 * heap
044 * @param number second part of the name of this heap variable
045 * @param ir the governing IR
046 */
047 public HeapVariable(T type, int number, IR ir) {
048 this.type = type;
049 this.number = number;
050 definedIn = new BitVector(ir.getMaxBasicBlockNumber() + 1);
051 }
052
053 /**
054 * Return a number that uniquely identifies this heap variable, among
055 * all the heap variables with the same type.
056 * @return the number
057 */
058 public int getNumber() {
059 return number;
060 }
061
062 /**
063 * Return the type representing this heap object.
064 * @return either a TypeReference, FieldReference, RVMField or
065 * String object
066 */
067 public T getHeapType() {
068 return type;
069 }
070
071 /**
072 * Is the this the exception heap type?
073 * @return true if the heap represents exceptions
074 */
075 public boolean isExceptionHeapType() {
076 return type == SSADictionary.exceptionState;
077 }
078
079 /**
080 * Return a bit vector that represents the basic blocks that define
081 * this heap variable.
082 * @return a bit vector that represents the basic blocks that define
083 * this heap variable.
084 */
085 public BitVector getDefBlocks() {
086 return definedIn;
087 }
088
089 /**
090 * Note that this heap variable is defined in a given basic block.
091 * @param b a basic block that defines this heap variable
092 */
093 public void registerDef(BasicBlock b) {
094 definedIn.set(b.getNumber());
095 }
096
097 /**
098 * Return a String representation of this variable
099 * @return a String representation of this variable
100 */
101 public String toString() {
102 return "HEAP<" + type + ">" + number;
103 }
104
105 /**
106 * Is this heap variable exposed on procedure entry?
107 * <p> Equivalently: is the number = zero?
108 * @return true or false
109 */
110 public boolean isExposedOnEntry() {
111 return (number == 0);
112 }
113 }