# HG changeset patch # User Roland Schatz # Date 1402940285 -7200 # Node ID a0d1dfc113b8b189bbc65296159747f1a161d417 # Parent a3a9d703c078e400085a044c9362ac44d5e0c5f9 Better documentation for HotSpotReferenceMap. diff -r a3a9d703c078 -r a0d1dfc113b8 graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/Architecture.java --- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/Architecture.java Mon Jun 16 23:07:45 2014 +0200 +++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/Architecture.java Mon Jun 16 19:38:05 2014 +0200 @@ -34,11 +34,11 @@ public abstract class Architecture { /** - * The number of bits required in a bit map covering all the registers that may store - * references. The bit position of a register in the map is the register's - * {@linkplain Register#number number}. + * The number of entries required in a {@link ReferenceMap} covering all the registers that may + * store references. The index of a register in the reference map is given by + * {@link Register#getReferenceMapIndex()}. */ - private final int registerReferenceMapBitCount; + private final int registerReferenceMapSize; /** * Represents the natural size of words (typically registers and pointers) of this architecture, @@ -85,7 +85,7 @@ private final int returnAddressSize; protected Architecture(String name, int wordSize, ByteOrder byteOrder, boolean unalignedMemoryAccess, Register[] registers, int implicitMemoryBarriers, int nativeCallDisplacementOffset, - int registerReferenceMapBitCount, int returnAddressSize) { + int registerReferenceMapSize, int returnAddressSize) { this.name = name; this.registers = registers; this.wordSize = wordSize; @@ -93,13 +93,13 @@ this.unalignedMemoryAccess = unalignedMemoryAccess; this.implicitMemoryBarriers = implicitMemoryBarriers; this.machineCodeCallDisplacementOffset = nativeCallDisplacementOffset; - this.registerReferenceMapBitCount = registerReferenceMapBitCount; + this.registerReferenceMapSize = registerReferenceMapSize; this.returnAddressSize = returnAddressSize; } /** * Converts this architecture to a string. - * + * * @return the string representation of this architecture */ @Override @@ -107,8 +107,8 @@ return getName().toLowerCase(); } - public int getRegisterReferenceMapBitCount() { - return registerReferenceMapBitCount; + public int getRegisterReferenceMapSize() { + return registerReferenceMapSize; } /** @@ -163,7 +163,7 @@ /** * Determines the barriers in a given barrier mask that are explicitly required on this * architecture. - * + * * @param barriers a mask of the barrier constants * @return the value of {@code barriers} minus the barriers unnecessary on this architecture */ @@ -173,9 +173,9 @@ /** * Gets the size in bytes of the specified kind for this target. - * + * * @param kind the kind for which to get the size - * + * * @return the size in bytes of {@code kind} */ public int getSizeInBytes(PlatformKind kind) { @@ -205,7 +205,7 @@ /** * Determine whether a kind can be stored in a register of a given category. - * + * * @param category the category of the register * @param kind the kind that should be stored in the register */ @@ -213,7 +213,7 @@ /** * Return the largest kind that can be stored in a register of a given category. - * + * * @param category the category of the register * @return the largest kind that can be stored in a register {@code category} */ diff -r a3a9d703c078 -r a0d1dfc113b8 graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/Register.java --- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/Register.java Mon Jun 16 23:07:45 2014 +0200 +++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/Register.java Mon Jun 16 19:38:05 2014 +0200 @@ -137,6 +137,9 @@ return registerCategory; } + /** + * Get the start index of this register in the {@link ReferenceMap}. + */ public int getReferenceMapIndex() { return (encoding << registerCategory.referenceMapShift) + registerCategory.referenceMapOffset; } diff -r a3a9d703c078 -r a0d1dfc113b8 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotReferenceMap.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotReferenceMap.java Mon Jun 16 23:07:45 2014 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotReferenceMap.java Mon Jun 16 19:38:05 2014 +0200 @@ -34,25 +34,36 @@ private static final long serialVersionUID = -1052183095979496819L; + private static final int BITS_PER_WORD = 3; + /** - * Contains 3 bits per 64 bit register, and n*3 bits per n*64 bit vector register. - * + * Contains 3 bits per scalar register, and n*3 bits per n-word vector register (e.g., on a + * 64-bit system, a 256-bit vector register requires 12 reference map bits). + *

+ * These bits can have the following values (LSB first): + * + *

+     * 000 - contains no references
+     * 100 - contains a wide oop
+     * 110 - contains a narrow oop in the lower half
+     * 101 - contains a narrow oop in the upper half
+     * 111 - contains two narrow oops
+     * 
*/ private final BitSet registerRefMap; /** - * Contains 3 bits per stack slot. - * + * Contains 3 bits per stack word. + *

+ * These bits can have the following values (LSB first): + * + *

+     * 000 - contains no references
+     * 100 - contains a wide oop
+     * 110 - contains a narrow oop in the lower half
+     * 101 - contains a narrow oop in the upper half
+     * 111 - contains two narrow oops
+     * 
*/ private final BitSet frameRefMap; @@ -60,18 +71,18 @@ public HotSpotReferenceMap(int registerCount, int frameSlotCount, TargetDescription target) { if (registerCount > 0) { - this.registerRefMap = new BitSet(registerCount * 3); + this.registerRefMap = new BitSet(registerCount * BITS_PER_WORD); } else { this.registerRefMap = null; } - this.frameRefMap = new BitSet(frameSlotCount * 3); + this.frameRefMap = new BitSet(frameSlotCount * BITS_PER_WORD); this.target = target; } private static void setOop(BitSet map, int startIdx, LIRKind kind) { int length = kind.getPlatformKind().getVectorLength(); - map.clear(3 * startIdx, 3 * (startIdx + length) - 1); - for (int i = 0, idx = 3 * startIdx; i < length; i++, idx += 3) { + map.clear(BITS_PER_WORD * startIdx, BITS_PER_WORD * (startIdx + length) - 1); + for (int i = 0, idx = BITS_PER_WORD * startIdx; i < length; i++, idx += BITS_PER_WORD) { if (kind.isReference(i)) { map.set(idx); } @@ -81,8 +92,8 @@ private static void setNarrowOop(BitSet map, int idx, LIRKind kind) { int length = kind.getPlatformKind().getVectorLength(); int nextIdx = idx + (length + 1) / 2; - map.clear(3 * idx, 3 * nextIdx - 1); - for (int i = 0, regIdx = 3 * idx; i < length; i += 2, regIdx += 3) { + map.clear(BITS_PER_WORD * idx, BITS_PER_WORD * nextIdx - 1); + for (int i = 0, regIdx = BITS_PER_WORD * idx; i < length; i += 2, regIdx += BITS_PER_WORD) { if (kind.isReference(i)) { map.set(regIdx); map.set(regIdx + 1); @@ -130,11 +141,11 @@ // so setNarrowOop won't work correctly int idx = offset / target.wordSize; if (kind.isReference(0)) { - frameRefMap.set(3 * idx); + frameRefMap.set(BITS_PER_WORD * idx); if (offset % target.wordSize == 0) { - frameRefMap.set(3 * idx + 1); + frameRefMap.set(BITS_PER_WORD * idx + 1); } else { - frameRefMap.set(3 * idx + 2); + frameRefMap.set(BITS_PER_WORD * idx + 2); } } } @@ -152,14 +163,14 @@ } public void appendRegisterMap(StringBuilder sb, RefMapFormatter formatter) { - for (int reg = registerRefMap.nextSetBit(0); reg >= 0; reg = registerRefMap.nextSetBit(reg + 2)) { - sb.append(' ').append(formatter.formatRegister(reg / 2)); + for (int reg = registerRefMap.nextSetBit(0); reg >= 0; reg = registerRefMap.nextSetBit(reg + BITS_PER_WORD)) { + sb.append(' ').append(formatter.formatRegister(reg / BITS_PER_WORD)); } } public void appendFrameMap(StringBuilder sb, RefMapFormatter formatter) { - for (int slot = frameRefMap.nextSetBit(0); slot >= 0; slot = frameRefMap.nextSetBit(slot + 3)) { - sb.append(' ').append(formatter.formatStackSlot(slot / 3)); + for (int slot = frameRefMap.nextSetBit(0); slot >= 0; slot = frameRefMap.nextSetBit(slot + BITS_PER_WORD)) { + sb.append(' ').append(formatter.formatStackSlot(slot / BITS_PER_WORD)); } } } diff -r a3a9d703c078 -r a0d1dfc113b8 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotTargetDescription.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotTargetDescription.java Mon Jun 16 23:07:45 2014 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotTargetDescription.java Mon Jun 16 19:38:05 2014 +0200 @@ -46,6 +46,6 @@ @Override public ReferenceMap createReferenceMap(boolean hasRegisters, int stackSlotCount) { - return new HotSpotReferenceMap(hasRegisters ? arch.getRegisterReferenceMapBitCount() : 0, stackSlotCount, this); + return new HotSpotReferenceMap(hasRegisters ? arch.getRegisterReferenceMapSize() : 0, stackSlotCount, this); } }