1 kkz      1.1.2.1 // SPAllocationStrategy.java, created Fri Jun  2 13:51:38 2000 by kkz
 2 cananian 1.1.2.6 // Copyright (C) 2000 Karen K. Zee <kkz@alum.mit.edu>
 3 kkz      1.1.2.1 // Licensed under the terms of the GNU GPL; see COPYING for details.
 4 kkz      1.1.2.1 package harpoon.Backend.Runtime1;
 5 kkz      1.1.2.1 
 6 kkz      1.1.2.1 import harpoon.Analysis.Maps.AllocationInformation.AllocationProperties;
 7 kkz      1.1.2.1 import harpoon.Backend.Generic.Frame;
 8 kkz      1.1.2.1 import harpoon.Backend.Generic.Runtime;
 9 kkz      1.1.2.1 import harpoon.Backend.Generic.Runtime.TreeBuilder;
10 kkz      1.1.2.1 import harpoon.ClassFile.HClass;
11 kkz      1.1.2.1 import harpoon.ClassFile.HCodeElement;
12 kkz      1.1.2.1 import harpoon.ClassFile.Loader;
13 kkz      1.1.2.1 import harpoon.IR.Tree.DerivationGenerator;
14 kkz      1.1.2.1 import harpoon.IR.Tree.Exp;
15 kkz      1.1.2.1 import harpoon.IR.Tree.ExpList;
16 kkz      1.1.2.1 import harpoon.IR.Tree.TreeFactory;
17 kkz      1.1.2.1 import harpoon.IR.Tree.ESEQ;
18 kkz      1.1.2.1 import harpoon.IR.Tree.MEM;
19 kkz      1.1.2.1 import harpoon.IR.Tree.MOVE;
20 kkz      1.1.2.1 import harpoon.IR.Tree.NAME;
21 kkz      1.1.2.1 import harpoon.IR.Tree.SEQ;
22 kkz      1.1.2.1 import harpoon.IR.Tree.TEMP;
23 kkz      1.1.2.1 import harpoon.IR.Tree.Type;
24 kkz      1.1.2.1 import harpoon.Temp.Label;
25 kkz      1.1.2.1 import harpoon.Temp.Temp;
26 kkz      1.1.2.2 import harpoon.Util.Util;
27 kkz      1.1.2.1 /**
28 kkz      1.1.2.1  * <code>SPAllocationStrategy</code> implements a "semi-precise"
29 kkz      1.1.2.1  * allocation strategy by providing the BDW collector with more 
30 kkz      1.1.2.1  * precise information about pointer locations.
31 kkz      1.1.2.1  * 
32 cananian 1.1.2.6  * @author  Karen K. Zee <kkz@alum.mit.edu>
33 cananian 1.4      * @version $Id: SPAllocationStrategy.java,v 1.4 2002/04/10 03:03:20 cananian Exp $
34 kkz      1.1.2.1  */
35 cananian 1.1.2.3 public class SPAllocationStrategy extends MallocAllocationStrategy {
36 kkz      1.1.2.1     /** Creates a <code>SPAllocationStrategy</code>. */
37 kkz      1.1.2.1     public SPAllocationStrategy(Frame f) {
38 cananian 1.1.2.3         super(f, "__dont_use__");
39 kkz      1.1.2.1     }
40 kkz      1.1.2.1     public Exp memAlloc(TreeFactory tf, HCodeElement source,
41 kkz      1.1.2.1                         DerivationGenerator dg,
42 kkz      1.1.2.1                         AllocationProperties ap,
43 kkz      1.1.2.1                         Exp length) {
44 kkz      1.1.2.2         String func;
45 kkz      1.1.2.2         if (ap.hasInteriorPointers()) {
46 kkz      1.1.2.2             if (ap.actualClass().isArray()) { // array with interior pointers
47 cananian 1.3.2.1                 assert !ap.actualClass().getComponentType().
48 cananian 1.3.2.1                             isPrimitive();
49 kkz      1.1.2.2                 func = "SP_malloc_array";
50 kkz      1.1.2.2             } else { // non-array
51 kkz      1.1.2.2                 func = "SP_malloc";
52 kkz      1.1.2.2             }
53 kkz      1.1.2.2         } else {
54 kkz      1.1.2.2             if (ap.actualClass().isArray()) // array with no interior pointers
55 cananian 1.3.2.1                 assert ap.actualClass().getComponentType().
56 cananian 1.3.2.1                             isPrimitive();
57 kkz      1.1.2.2             func = "SP_malloc_atomic";
58 kkz      1.1.2.2         }
59 kkz      1.1.2.1         Runtime rt = frame.getRuntime();
60 cananian 1.1.2.3         return buildAllocCall(tf, source, dg, ap, func, length,
61 cananian 1.1.2.7                               new ExpList(new NAME(tf, source, rt.getNameMap().label
62 cananian 1.1.2.3                                                    (ap.actualClass(),
63 cananian 1.1.2.3                                                     "classinfo")), null));
64 kkz      1.1.2.1     }
65 cananian 1.2     }