1 salcianu 1.1 // PreallocData.java, created Sat Feb 22 12:12:38 2003 by salcianu 2 salcianu 1.1 // Copyright (C) 2000 Alexandru Salcianu <salcianu@MIT.EDU> 3 salcianu 1.1 // Licensed under the terms of the GNU GPL; see COPYING for details. 4 salcianu 1.1 package harpoon.Analysis.MemOpt; 5 salcianu 1.1 6 salcianu 1.1 import harpoon.Backend.Generic.Frame; 7 salcianu 1.1 import harpoon.ClassFile.HClass; 8 salcianu 1.1 import harpoon.ClassFile.HDataElement; 9 salcianu 1.1 10 salcianu 1.1 import harpoon.IR.Tree.CONST; 11 salcianu 1.1 import harpoon.IR.Tree.DATUM; 12 salcianu 1.1 import harpoon.IR.Tree.LABEL; 13 salcianu 1.1 import harpoon.IR.Tree.SEGMENT; 14 salcianu 1.1 import harpoon.IR.Tree.ALIGN; 15 salcianu 1.1 import harpoon.IR.Tree.Stm; 16 salcianu 1.1 import harpoon.Temp.Label; 17 salcianu 1.1 18 salcianu 1.1 import java.util.List; 19 salcianu 1.1 import java.util.ArrayList; 20 salcianu 1.1 import java.util.Set; 21 salcianu 1.1 import java.util.Iterator; 22 salcianu 1.1 23 salcianu 1.1 24 salcianu 1.1 /** 25 salcianu 1.1 * <code>PreallocData</code> 26 salcianu 1.1 * 27 salcianu 1.1 * @author Alexandru Salcianu <salcianu@MIT.EDU> 28 cananian 1.2 * @version $Id: PreallocData.java,v 1.2 2004/02/08 03:19:53 cananian Exp $ 29 salcianu 1.1 */ 30 salcianu 1.1 public class PreallocData extends harpoon.Backend.Runtime1.Data { 31 salcianu 1.1 32 salcianu 1.1 /** Creates a <code>PreallocData</code>. */ 33 salcianu 1.1 public PreallocData(HClass hc, Frame f, Set/*<Label>*/ labels, 34 salcianu 1.1 Label beginLabel, Label endLabel) { 35 salcianu 1.1 super("prealloc-data", hc, f); 36 salcianu 1.1 // only emit this once 37 salcianu 1.1 assert hc == f.getLinker().forName("java.lang.Object") : 38 salcianu 1.1 "Pointers to preallocated memory should be stored only " + 39 salcianu 1.1 "in the data segment for java.lang.Object"; 40 salcianu 1.1 this.root = build(labels, beginLabel, endLabel); 41 salcianu 1.1 } 42 salcianu 1.1 43 salcianu 1.1 44 salcianu 1.1 private HDataElement build(Set/*<Label>*/ labels, 45 salcianu 1.1 Label beginLabel, Label endLabel) { 46 salcianu 1.1 boolean first = true; 47 salcianu 1.1 48 salcianu 1.1 List stmList = new ArrayList(); 49 salcianu 1.1 stmList.add(new SEGMENT(tf, null, SEGMENT.INIT_DATA)); 50 salcianu 1.1 51 cananian 1.2 for(Object labelO : labels) { 52 cananian 1.2 Label label = (Label) labelO; 53 salcianu 1.1 stmList.add(new ALIGN(tf, null, 4)); // word align 54 salcianu 1.1 // mark the beginning of the prealloc data segment 55 salcianu 1.1 if(first) 56 salcianu 1.1 stmList.add(new LABEL(tf, null, beginLabel, true)); 57 salcianu 1.1 // reserve space for one pointer; referred by "label" 58 salcianu 1.1 stmList.add(new LABEL(tf, null, label, true)); 59 salcianu 1.1 stmList.add(new DATUM(tf, null, new CONST(tf, null))); 60 salcianu 1.1 first = false; 61 salcianu 1.1 } 62 salcianu 1.1 63 salcianu 1.1 // mark the end of the prealloc data segment 64 salcianu 1.1 stmList.add(new LABEL(tf, null, endLabel, true)); 65 salcianu 1.1 66 salcianu 1.1 return (HDataElement) Stm.toStm(stmList); 67 salcianu 1.1 } 68 salcianu 1.1 }