1 package Analysis.Prefetch;
6 public class PrefetchPair {
7 public TempDescriptor base;
8 public ArrayList<Descriptor> desc;
10 public PrefetchPair(){
11 base = new TempDescriptor("");
12 desc = new ArrayList<Descriptor>();
15 public PrefetchPair(TempDescriptor t, Descriptor f) {
17 desc = new ArrayList<Descriptor>();
21 public PrefetchPair(TempDescriptor t, ArrayList<Descriptor> descriptor) {
23 desc = new ArrayList<Descriptor>();
24 desc.addAll(descriptor);
27 public TempDescriptor getBase() {
31 public Descriptor getDescAt(int index) {
32 return desc.get(index);
35 public ArrayList<Descriptor> getDesc() {
39 public FieldDescriptor getFieldDesc(int index) {
40 return (FieldDescriptor) desc.get(index);
43 public IndexDescriptor getIndexDesc(int index) {
44 return (IndexDescriptor) desc.get(index);
47 public int hashCode() {
48 int hashcode = base.toString().hashCode();
50 hashcode^=desc.hashCode();
55 public String toString() {
56 String label= getBase().toString();
59 ListIterator it=getDesc().listIterator();
62 if(o instanceof FieldDescriptor) {
63 FieldDescriptor fd = (FieldDescriptor) o;
64 label+="."+ fd.toString();
66 IndexDescriptor id = (IndexDescriptor) o;
67 label+= id.toString();
73 public boolean equals(Object o) {
74 if(o instanceof PrefetchPair) {
75 PrefetchPair pp = (PrefetchPair) o;
76 return base == pp.base && desc.equals(pp.desc);
81 public Object clone() {
82 PrefetchPair newpp = new PrefetchPair();
83 newpp.base = this.base;
84 for(int i = 0; i < this.desc.size(); i++) {
85 Object o = desc.get(i);
86 if(o instanceof FieldDescriptor) {
87 newpp.desc.add((FieldDescriptor) o);
89 ArrayList<TempDescriptor> td = new ArrayList<TempDescriptor>();
90 for(int j = 0; j < ((IndexDescriptor)o).tddesc.size(); j++) {
91 td.add(((IndexDescriptor)o).getTempDescAt(j));
93 IndexDescriptor idesc = new IndexDescriptor();
95 idesc.offset = ((IndexDescriptor)o).offset;
96 newpp.desc.add(idesc);
102 /** This function returns true if a tempdescriptor object is found in the array of descriptors
103 * for a given prefetch pair else returns false*/
104 public boolean containsTemp(TempDescriptor td) {
105 ArrayList<Descriptor> desc = (ArrayList<Descriptor>) getDesc();
106 for(ListIterator it = desc.listIterator();it.hasNext();) {
107 Object o = it.next();
108 if(o instanceof IndexDescriptor) {
109 ArrayList<TempDescriptor> tdarray = (ArrayList<TempDescriptor>)((IndexDescriptor)o).tddesc;
110 if(tdarray.contains(td)) {
118 /** This function creates a new Arraylist of Descriptors by replacing old tempdescriptors with new
119 * tempdescriptors when there is a match */
120 public PrefetchPair replaceTemp(TempDescriptor td, TempDescriptor[] newtd) {
121 PrefetchPair npp=(PrefetchPair)clone();
122 ArrayList<Descriptor> desc = (ArrayList<Descriptor>) npp.getDesc();
123 for(ListIterator it = desc.listIterator();it.hasNext();) {
124 Object currdesc = it.next();
125 if(currdesc instanceof IndexDescriptor) {
126 ArrayList<TempDescriptor> tdarray = (ArrayList<TempDescriptor>)((IndexDescriptor)currdesc).tddesc;
127 if (tdarray.contains(td)) {
128 int index = tdarray.indexOf(td);
129 tdarray.set(index, newtd[0]);
130 for(int i=1;i<newtd.length;i++) {
131 tdarray.add(newtd[i]);