Index: rvm/src/org/jikesrvm/compilers/opt/runtimesupport/VM_OptCompiledMethod.java =================================================================== --- rvm/src/org/jikesrvm/compilers/opt/runtimesupport/VM_OptCompiledMethod.java (revision 13976) +++ rvm/src/org/jikesrvm/compilers/opt/runtimesupport/VM_OptCompiledMethod.java (working copy) @@ -253,7 +253,7 @@ @Interruptible public void createFinalOSRMap(IR ir) { - this._osrMap = new OSR_EncodedOSRMap(ir.MIRInfo.osrVarMap); + this._osrMap = OSR_EncodedOSRMap.makeMap(ir.MIRInfo.osrVarMap); } public OSR_EncodedOSRMap getOSRMap() { Index: rvm/src/org/jikesrvm/osr/OSR_EncodedOSRMap.java =================================================================== --- rvm/src/org/jikesrvm/osr/OSR_EncodedOSRMap.java (revision 13976) +++ rvm/src/org/jikesrvm/osr/OSR_EncodedOSRMap.java (working copy) @@ -17,6 +17,7 @@ import org.jikesrvm.VM; import org.jikesrvm.compilers.opt.inlining.CallSiteTree; import org.jikesrvm.compilers.opt.ir.Instruction; +import org.jikesrvm.util.VM_HashMap; import org.vmmagic.pragma.Inline; import org.vmmagic.unboxed.Offset; @@ -28,15 +29,15 @@ * all OSR map info for that method. */ -public class OSR_EncodedOSRMap implements VM_OptGCMapIteratorConstants, OSR_Constants { +public final class OSR_EncodedOSRMap implements VM_OptGCMapIteratorConstants, OSR_Constants { - /* osr info entries */ - private long[] mapEntries; + /** osr info entries */ + private final long[] mapEntries; - /* the last entry index. */ - private int lastEntry; + /** the last entry index. */ + private final int lastEntry; - /* the OSR map */ + /** the OSR map */ private int[] osrMaps; private int mapSize = 16; private int lastIndex = 0; @@ -68,9 +69,8 @@ return regnum - FIRST_GCMAP_REG + 1; } - /* - */ - public OSR_EncodedOSRMap(OSR_VariableMap varMap) { + /** Constructor */ + private OSR_EncodedOSRMap(OSR_VariableMap varMap) { int entries = varMap.getNumberOfElements(); this.lastEntry = entries - 1; @@ -80,15 +80,65 @@ this.osrMaps = new int[mapSize]; translateMap(varMap.list); resizeOsrMaps(); + } else { + this.mapEntries = null; } - /* -if (VM.TraceOnStackReplacement) { - printMap(); -} - */ + //if (VM.TraceOnStackReplacement) { + // printMap(); + //} } + public int hashCode() { + if (osrMaps == null) return -1; + int val=0; + for (int i=0; i < osrMaps.length; i++) { + val ^= osrMaps[i]; + } + return val; + } + + public boolean equals(Object obj) { + if (!(obj instanceof OSR_EncodedOSRMap)) { + return false; + } + OSR_EncodedOSRMap that = (OSR_EncodedOSRMap)obj; + if (lastEntry == that.lastEntry) { + if (mapEntries != null && that.mapEntries != null) { + if (mapEntries.length != that.mapEntries.length) return false; + for (int i=0; i < mapEntries.length; i++) { + if (mapEntries[i] != that.mapEntries[i]) return false; + } + } else { + if (mapEntries != null || that.mapEntries != null) return false; + } + if (osrMaps != null && that.osrMaps != null) { + if (osrMaps.length != that.osrMaps.length) return false; + for (int i=0; i < osrMaps.length; i++) { + if (osrMaps[i] != that.osrMaps[i]) return false; + } + } else { + if (osrMaps != null || that.osrMaps != null) return false; + } + return true; + } + return false; + } + + private static final VM_HashMap + uniqueMap = new VM_HashMap(); + + public static OSR_EncodedOSRMap makeMap(OSR_VariableMap varMap) { + OSR_EncodedOSRMap encodedMap = new OSR_EncodedOSRMap(varMap); + OSR_EncodedOSRMap result = uniqueMap.get(encodedMap); + if (result != null) { + return result; + } else { + uniqueMap.put(encodedMap, encodedMap); + return encodedMap; + } + } + /* * translates a list of OSR_MapElement to encoding, * we can not trust the osrlist is in the increasing order of