1 cananian 1.1.2.1 // DefaultAllocationInformation.java, created Mon Apr 3 18:46:15 2000 by cananian 2 cananian 1.1.2.1 // Copyright (C) 2000 C. Scott Ananian <cananian@alumni.princeton.edu> 3 cananian 1.1.2.1 // Licensed under the terms of the GNU GPL; see COPYING for details. 4 cananian 1.1.2.1 package harpoon.Analysis; 5 cananian 1.1.2.1 6 cananian 1.1.2.1 import harpoon.Analysis.Maps.AllocationInformation; 7 pnkfelix 1.1.2.6 import harpoon.Analysis.Maps.AllocationInformation.AllocationProperties; 8 cananian 1.1.2.1 import harpoon.ClassFile.HClass; 9 salcianu 1.8 import harpoon.ClassFile.HField; 10 cananian 1.1.2.1 import harpoon.ClassFile.HCodeElement; 11 cananian 1.9 import harpoon.IR.Quads.Quad; 12 salcianu 1.8 import harpoon.Temp.Label; 13 cananian 1.1.2.1 import harpoon.Temp.Temp; 14 cananian 1.1.2.1 import harpoon.Util.Util; 15 cananian 1.1.2.1 /** 16 cananian 1.1.2.1 * <code>DefaultAllocationInformation</code> returns a simple 17 cananian 1.1.2.1 * no-analysis <code>AllocationInformation</code> structure which 18 cananian 1.1.2.1 * works for allocation sites in quad form. The 19 cananian 1.1.2.1 * <code>DefaultAllocationInformation</code> will conservatively say 20 cananian 1.1.2.1 * that nothing can be stack or thread-locally allocated. 21 cananian 1.1.2.1 * 22 cananian 1.1.2.1 * @author C. Scott Ananian <cananian@alumni.princeton.edu> 23 cananian 1.9 * @version $Id: DefaultAllocationInformation.java,v 1.9 2003/03/11 17:49:51 cananian Exp $ 24 cananian 1.1.2.1 */ 25 cananian 1.1.2.3 public class DefaultAllocationInformation 26 cananian 1.9 implements AllocationInformation<Quad>, java.io.Serializable { 27 cananian 1.1.2.1 28 cananian 1.1.2.3 /** A static instance of the singleton 29 cananian 1.1.2.3 * <code>DefaultAllocationInformation</code> object. */ 30 cananian 1.9 public static final AllocationInformation<Quad> SINGLETON = 31 cananian 1.1.2.3 new DefaultAllocationInformation(); 32 cananian 1.1.2.3 33 cananian 1.1.2.1 /** Creates a <code>DefaultAllocationInformation</code>. */ 34 cananian 1.1.2.3 private DefaultAllocationInformation() { } 35 cananian 1.1.2.1 36 cananian 1.1.2.1 /** Return an <code>AllocationProperties</code> object for the given 37 cananian 1.1.2.1 * allocation site. The allocation site must be either a 38 cananian 1.1.2.1 * <code>harpoon.IR.Quads.NEW</code> or a 39 cananian 1.1.2.1 * <code>harpoon.IR.Quads.ANEW</code>. */ 40 cananian 1.9 public AllocationProperties query(Quad allocationSite) { 41 cananian 1.1.2.1 if (allocationSite instanceof harpoon.IR.Quads.NEW) 42 cananian 1.1.2.2 return _hasInteriorPointers 43 cananian 1.1.2.1 (((harpoon.IR.Quads.NEW)allocationSite).hclass()); 44 cananian 1.1.2.1 if (allocationSite instanceof harpoon.IR.Quads.ANEW) 45 cananian 1.1.2.2 return _hasInteriorPointers 46 cananian 1.1.2.1 (((harpoon.IR.Quads.ANEW)allocationSite).hclass()); 47 cananian 1.3.2.1 assert false : "not a NEW or ANEW quad."; 48 cananian 1.1.2.1 return null; 49 cananian 1.1.2.1 } 50 cananian 1.1.2.1 /** Return an AllocationProperties object matching the allocated object 51 cananian 1.1.2.1 * type specified by the parameter. */ 52 cananian 1.1.2.2 private static AllocationProperties _hasInteriorPointers(HClass cls) { 53 cananian 1.1.2.2 return hasInteriorPointers(cls) ? 54 kkz 1.1.2.5 (AllocationProperties) new MyAP(cls) { 55 kkz 1.1.2.5 public boolean hasInteriorPointers() { return true; } 56 kkz 1.1.2.5 } : 57 kkz 1.1.2.5 (AllocationProperties) new MyAP(cls) { 58 kkz 1.1.2.5 public boolean hasInteriorPointers() { return false; } 59 kkz 1.1.2.5 }; 60 cananian 1.1.2.1 } 61 cananian 1.1.2.1 /** Return true iff the specified object type has no interior pointers; 62 cananian 1.1.2.1 * that is, iff all its fields are primitive. */ 63 cananian 1.1.2.2 public static boolean hasInteriorPointers(HClass cls) { 64 cananian 1.3.2.1 assert !cls.isInterface() && !cls.isPrimitive(); 65 cananian 1.1.2.1 if (cls.isArray()) return !cls.getComponentType().isPrimitive(); 66 cananian 1.1.2.1 // okay, it's an object. see if it has any non-primitive fields. 67 cananian 1.1.2.1 for (HClass sc=cls; sc!=null; sc=sc.getSuperclass()) { 68 cananian 1.1.2.1 HField[] hf = sc.getDeclaredFields(); 69 cananian 1.1.2.1 for (int i=0; i<hf.length; i++) 70 cananian 1.1.2.1 if (!hf[i].getType().isPrimitive()) return true; 71 cananian 1.1.2.1 } 72 cananian 1.1.2.1 return false; // no interior pointers. 73 cananian 1.1.2.1 } 74 cananian 1.1.2.1 75 cananian 1.1.2.3 // serialization support. 76 cananian 1.1.2.3 private Object readResolve() throws java.io.ObjectStreamException { 77 cananian 1.1.2.3 return SINGLETON; // maintain singleton. 78 cananian 1.1.2.3 } 79 cananian 1.1.2.3 80 cananian 1.1.2.1 /* convenience class for code reuse. */ 81 cananian 1.1.2.3 private static abstract class MyAP 82 cananian 1.1.2.3 implements AllocationProperties, java.io.Serializable { 83 kkz 1.1.2.5 private HClass actualClass; 84 kkz 1.1.2.5 public MyAP(HClass actualClass) { this.actualClass = actualClass; } 85 cananian 1.1.2.1 public abstract boolean hasInteriorPointers(); 86 cananian 1.1.2.1 public boolean canBeStackAllocated() { return false; } 87 cananian 1.1.2.1 public boolean canBeThreadAllocated() { return false; } 88 cananian 1.1.2.4 public boolean makeHeap() { return false; } 89 salcianu 1.1.2.7 public boolean noSync() { return false; } 90 cananian 1.1.2.1 public Temp allocationHeap() { return null; } 91 kkz 1.1.2.5 public HClass actualClass() { return actualClass; } 92 kkz 1.5 public boolean setDynamicWBFlag() { return false; } 93 salcianu 1.8 public Label getLabelOfPtrToMemoryChunk() { return null; } 94 salcianu 1.7 public int getUniqueID() { return -1; } 95 cananian 1.1.2.1 } 96 cananian 1.1.2.1 } 97 kkz 1.1.2.5 98 kkz 1.1.2.5 99 kkz 1.1.2.5 100 cananian 1.2