1 cananian 1.1.2.1 // ArrayCopyImplementer.java, created Tue Jan 23 16:26:48 2001 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.Transactions; 5 cananian 1.1.2.1 6 cananian 1.1.2.2 import harpoon.ClassFile.CachingCodeFactory; 7 cananian 1.1.2.2 import harpoon.ClassFile.HClass; 8 cananian 1.1.2.2 import harpoon.ClassFile.HCode; 9 cananian 1.1.2.2 import harpoon.ClassFile.HCodeAndMaps; 10 cananian 1.1.2.2 import harpoon.ClassFile.HCodeFactory; 11 cananian 1.1.2.2 import harpoon.ClassFile.HMethod; 12 cananian 1.1.2.2 import harpoon.ClassFile.HMethodMutator; 13 cananian 1.1.2.2 import harpoon.ClassFile.Linker; 14 cananian 1.1.2.2 import harpoon.Util.Util; 15 cananian 1.1.2.1 16 cananian 1.1.2.2 import java.lang.reflect.Modifier; 17 cananian 1.1.2.1 /** 18 cananian 1.1.2.1 * <code>ArrayCopyImplementer</code> adds a pure-java implementation of 19 cananian 1.1.2.1 * the <code>System.arraycopy()</code> method. Our implementation is 20 cananian 1.1.2.1 * defined in <code>harpoon.Runtime.ArrayCopy</code>. 21 cananian 1.1.2.1 * <p> 22 cananian 1.1.2.1 * Arguably, this class should belong in the 23 cananian 1.1.2.1 * <code>harpoon.Analysis.Quads</code> package, but we'll leave it 24 cananian 1.1.2.1 * here until someone other than the Transactions transformation 25 cananian 1.1.2.1 * needs it. 26 cananian 1.1.2.1 * <p> 27 cananian 1.1.2.1 * When we implement better array bounds check elimination in loops, 28 cananian 1.1.2.1 * the version implemented here should have performance equivalent 29 cananian 1.1.2.1 * (or better than) the native version. Better, we should be able 30 cananian 1.1.2.1 * to inline this version and eliminate lots of checks in most cases. 31 cananian 1.1.2.1 * 32 cananian 1.1.2.1 * @author C. Scott Ananian <cananian@alumni.princeton.edu> 33 cananian 1.5 * @version $Id: ArrayCopyImplementer.java,v 1.5 2003/10/03 19:46:33 cananian Exp $ 34 cananian 1.1.2.1 */ 35 cananian 1.1.2.1 public class ArrayCopyImplementer extends CachingCodeFactory { 36 cananian 1.1.2.1 /** Parent code factory. */ 37 cananian 1.5 final HMethod HMimpac; 38 cananian 1.1.2.1 39 cananian 1.1.2.1 /** Creates a <code>ArrayCopyImplementer</code>. */ 40 cananian 1.1.2.1 public ArrayCopyImplementer(HCodeFactory parent, Linker l) { 41 cananian 1.1.2.1 super(parent); 42 cananian 1.1.2.1 this.HMimpac = l.forName("harpoon.Runtime.ArrayCopy").getMethod 43 cananian 1.1.2.1 ("arraycopy", "(Ljava/lang/Object;ILjava/lang/Object;II)V"); 44 cananian 1.1.2.1 } 45 cananian 1.1.2.1 public HCode convert(HMethod m) { 46 cananian 1.5 if (m.getName().equals("arraycopy") && 47 cananian 1.5 m.getDescriptor().equals 48 cananian 1.5 ("(Ljava/lang/Object;ILjava/lang/Object;II)V") && 49 cananian 1.5 (m.getDeclaringClass().getName().equals("java.lang.System") || 50 cananian 1.5 m.getDeclaringClass().getName().equals("java.lang.VMSystem"))) 51 cananian 1.1.2.1 try { 52 cananian 1.5 // ensure method is non-native. 53 cananian 1.5 m.getMutator().removeModifiers(Modifier.NATIVE); 54 cananian 1.1.2.1 // copy implementation from harpoon.Runtime.ArrayCopy. 55 cananian 1.5 return super.convert(HMimpac).clone(m).hcode(); 56 cananian 1.1.2.1 } catch (CloneNotSupportedException e) { 57 cananian 1.3.2.1 assert false : e; // shouldn't happen. 58 cananian 1.1.2.1 } 59 cananian 1.1.2.1 return super.convert(m); 60 cananian 1.1.2.1 } 61 cananian 1.2 }