Mercurial > hg > graal-compiler
changeset 13725:8d8732e14447
Refactor reference maps.
line wrap: on
line diff
--- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CodeUtil.java Wed Jan 22 10:51:32 2014 +0100 +++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CodeUtil.java Wed Jan 22 11:27:28 2014 +0100 @@ -227,10 +227,17 @@ return sb; } + public interface RefMapFormatter { + + String formatStackSlot(int frameRefMapIndex); + + String formatRegister(int regRefMapIndex); + } + /** * Formats a location present in a register or frame reference map. */ - public static class RefMapFormatter { + public static class DefaultRefMapFormatter implements RefMapFormatter { /** * The size of a stack slot. @@ -252,7 +259,7 @@ */ public final int refMapToFPOffset; - public RefMapFormatter(Architecture arch, int slotSize, Register fp, int refMapToFPOffset) { + public DefaultRefMapFormatter(Architecture arch, int slotSize, Register fp, int refMapToFPOffset) { this.arch = arch; this.slotSize = slotSize; this.fp = fp; @@ -283,25 +290,16 @@ */ public static StringBuilder append(StringBuilder sb, DebugInfo info, RefMapFormatter formatter) { String nl = NEW_LINE; - if (info.hasRegisterRefMap()) { + ReferenceMap refMap = info.getReferenceMap(); + if (refMap != null && refMap.hasRegisterRefMap()) { sb.append(" reg-ref-map:"); - BitSet bm = info.getRegisterRefMap(); - if (formatter != null) { - for (int reg = bm.nextSetBit(0); reg >= 0; reg = bm.nextSetBit(reg + 1)) { - sb.append(" " + formatter.formatRegister(reg)); - } - } - sb.append(' ').append(bm).append(nl); + refMap.appendRegisterMap(sb, formatter); + sb.append(nl); } - if (info.hasStackRefMap()) { + if (refMap != null && refMap.hasFrameRefMap()) { sb.append("frame-ref-map:"); - BitSet bm = info.getFrameRefMap(); - if (formatter != null) { - for (int i = bm.nextSetBit(0); i >= 0; i = bm.nextSetBit(i + 1)) { - sb.append(" " + formatter.formatStackSlot(i)); - } - } - sb.append(' ').append(bm).append(nl); + refMap.appendFrameMap(sb, formatter); + sb.append(nl); } RegisterSaveLayout calleeSaveInfo = info.getCalleeSaveInfo(); if (calleeSaveInfo != null) {
--- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CompilationResult.java Wed Jan 22 10:51:32 2014 +0100 +++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CompilationResult.java Wed Jan 22 11:27:28 2014 +0100 @@ -696,8 +696,19 @@ private static void appendDebugInfo(StringBuilder sb, DebugInfo info) { if (info != null) { - appendRefMap(sb, "stackMap", info.getFrameRefMap()); - appendRefMap(sb, "registerMap", info.getRegisterRefMap()); + ReferenceMap refMap = info.getReferenceMap(); + if (refMap != null) { + if (refMap.hasFrameRefMap()) { + sb.append(" stackMap["); + refMap.appendFrameMap(sb, null); + sb.append(']'); + } + if (refMap.hasRegisterRefMap()) { + sb.append(" registerMap["); + refMap.appendRegisterMap(sb, null); + sb.append(']'); + } + } RegisterSaveLayout calleeSaveInfo = info.getCalleeSaveInfo(); if (calleeSaveInfo != null) { sb.append(" callee-save-info["); @@ -721,12 +732,6 @@ } } - private static void appendRefMap(StringBuilder sb, String name, BitSet map) { - if (map != null) { - sb.append(' ').append(name).append('[').append(map.toString()).append(']'); - } - } - /** * @return the list of infopoints, sorted by {@link Site#pcOffset} */
--- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/DebugInfo.java Wed Jan 22 10:51:32 2014 +0100 +++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/DebugInfo.java Wed Jan 22 11:27:28 2014 +0100 @@ -23,15 +23,13 @@ package com.oracle.graal.api.code; import java.io.*; -import java.util.*; /** * Represents the debugging information for a particular point of execution. This information * includes: * <ul> * <li>a {@linkplain #getBytecodePosition() bytecode position}</li> - * <li>a reference map for {@linkplain #getRegisterRefMap() registers}</li> - * <li>a reference map for {@linkplain #getFrameRefMap() stack slots} in the current frame</li> + * <li>a reference map for registers and stack slots in the current frame</li> * <li>a map from bytecode locals and operand stack slots to their values or locations from which * their values can be read</li> * <li>a map from the registers (in the caller's frame) to the slots where they are saved in the @@ -42,8 +40,7 @@ private static final long serialVersionUID = -6047206624915812516L; private final BytecodePosition bytecodePosition; - private final BitSet registerRefMap; - private final BitSet frameRefMap; + private final ReferenceMap referenceMap; private RegisterSaveLayout calleeSaveInfo; /** @@ -51,13 +48,11 @@ * * @param codePos the {@linkplain BytecodePosition code position} or {@linkplain BytecodeFrame * frame} info - * @param registerRefMap the register map - * @param frameRefMap the reference map for {@code frame}, which may be {@code null} + * @param referenceMap the reference map */ - public DebugInfo(BytecodePosition codePos, BitSet registerRefMap, BitSet frameRefMap) { + public DebugInfo(BytecodePosition codePos, ReferenceMap referenceMap) { this.bytecodePosition = codePos; - this.registerRefMap = registerRefMap; - this.frameRefMap = frameRefMap; + this.referenceMap = referenceMap; } /** @@ -68,20 +63,6 @@ } /** - * @return {@code true} if this debug info has a reference map for the registers - */ - public boolean hasRegisterRefMap() { - return getRegisterRefMap() != null && getRegisterRefMap().size() > 0; - } - - /** - * @return {@code true} if this debug info has a reference map for the stack - */ - public boolean hasStackRefMap() { - return getFrameRefMap() != null && getFrameRefMap().size() > 0; - } - - /** * Gets the deoptimization information for each inlined frame (if available). * * @return {@code null} if no frame de-opt info is {@linkplain #hasFrame() available} @@ -107,21 +88,8 @@ return bytecodePosition; } - /** - * @return The reference map for the registers at this point. The reference map is <i>packed</i> - * in that for bit {@code k} in byte {@code n}, it refers to the register whose - * {@linkplain Register#number number} is {@code (k + n * 8)}. - */ - public BitSet getRegisterRefMap() { - return registerRefMap; - } - - /** - * @return The reference map for the stack frame at this point. A set bit at {@code k} in the - * map represents stack slot number {@code k}. - */ - public BitSet getFrameRefMap() { - return frameRefMap; + public ReferenceMap getReferenceMap() { + return referenceMap; } /**
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/ReferenceMap.java Wed Jan 22 11:27:28 2014 +0100 @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.api.code; + +import java.io.*; +import java.util.*; + +import com.oracle.graal.api.code.CodeUtil.RefMapFormatter; + +public class ReferenceMap implements Serializable { + + private static final long serialVersionUID = -1052183095979496819L; + + private final BitSet registerRefMap; + private final BitSet frameRefMap; + + public ReferenceMap(int registerCount, int frameSlotCount) { + if (registerCount > 0) { + this.registerRefMap = new BitSet(registerCount); + } else { + this.registerRefMap = null; + } + this.frameRefMap = new BitSet(frameSlotCount); + } + + public void setRegister(int idx) { + registerRefMap.set(idx); + } + + public void setStackSlot(int idx) { + frameRefMap.set(idx); + } + + public boolean hasRegisterRefMap() { + return registerRefMap != null && registerRefMap.size() > 0; + } + + public boolean hasFrameRefMap() { + return frameRefMap != null && frameRefMap.size() > 0; + } + + private static class NumberedRefMapFormatter implements RefMapFormatter { + + public String formatStackSlot(int frameRefMapIndex) { + return "s" + frameRefMapIndex; + } + + public String formatRegister(int regRefMapIndex) { + return "r" + regRefMapIndex; + } + } + + public void appendRegisterMap(StringBuilder sb, RefMapFormatter formatterArg) { + RefMapFormatter formatter = formatterArg; + if (formatter == null) { + formatter = new NumberedRefMapFormatter(); + } + + for (int reg = registerRefMap.nextSetBit(0); reg >= 0; reg = registerRefMap.nextSetBit(reg + 1)) { + sb.append(' ').append(formatter.formatRegister(reg)); + } + } + + public void appendFrameMap(StringBuilder sb, RefMapFormatter formatterArg) { + RefMapFormatter formatter = formatterArg; + if (formatter == null) { + formatter = new NumberedRefMapFormatter(); + } + + for (int slot = frameRefMap.nextSetBit(0); slot >= 0; slot = frameRefMap.nextSetBit(slot + 1)) { + sb.append(' ').append(formatter.formatStackSlot(slot)); + } + } +}
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotCodeCacheProvider.java Wed Jan 22 10:51:32 2014 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotCodeCacheProvider.java Wed Jan 22 11:27:28 2014 +0100 @@ -26,6 +26,7 @@ import java.util.*; import com.oracle.graal.api.code.*; +import com.oracle.graal.api.code.CodeUtil.DefaultRefMapFormatter; import com.oracle.graal.api.code.CodeUtil.RefMapFormatter; import com.oracle.graal.api.code.CompilationResult.Call; import com.oracle.graal.api.code.CompilationResult.DataPatch; @@ -65,7 +66,7 @@ HexCodeFile.addAnnotations(hcf, compResult.getAnnotations()); addExceptionHandlersComment(compResult, hcf); Register fp = regConfig.getFrameRegister(); - RefMapFormatter slotFormatter = new RefMapFormatter(target.arch, target.wordSize, fp, 0); + RefMapFormatter slotFormatter = new DefaultRefMapFormatter(target.arch, target.wordSize, fp, 0); for (Infopoint infopoint : compResult.getInfopoints()) { if (infopoint instanceof Call) { Call call = (Call) infopoint;
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/FrameMap.java Wed Jan 22 10:51:32 2014 +0100 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/FrameMap.java Wed Jan 22 11:27:28 2014 +0100 @@ -343,24 +343,12 @@ } } - /** - * Initializes a reference map that covers all registers of the target architecture. - */ - public BitSet initRegisterRefMap() { - return new BitSet(target.arch.getRegisterReferenceMapBitCount()); - } - - /** - * Initializes a reference map. Initially, the size is large enough to cover all the slots in - * the frame. If the method has incoming reference arguments on the stack, the reference map - * might grow later when such a reference is set. - */ - public BitSet initFrameRefMap() { - BitSet frameRefMap = new BitSet(frameSize() / target.wordSize); + public ReferenceMap initReferenceMap(boolean canHaveRegisters) { + ReferenceMap refMap = new ReferenceMap(canHaveRegisters ? target.arch.getRegisterReferenceMapBitCount() : 0, frameSize() / target.wordSize); for (StackSlot slot : objectStackSlots) { - setReference(slot, null, frameRefMap); + setReference(slot, refMap); } - return frameRefMap; + return refMap; } /** @@ -369,16 +357,15 @@ * {@link Constant} is automatically tracked. * * @param location The location to be added to the reference map. - * @param registerRefMap A register reference map, as created by {@link #initRegisterRefMap()}. - * @param frameRefMap A frame reference map, as created by {@link #initFrameRefMap()}. + * @param refMap A reference map, as created by {@link #initReferenceMap(boolean)}. */ - public void setReference(Value location, BitSet registerRefMap, BitSet frameRefMap) { + public void setReference(Value location, ReferenceMap refMap) { if (location.getKind() == Kind.Object) { if (isRegister(location)) { - registerRefMap.set(asRegister(location).number); + refMap.setRegister(asRegister(location).number); } else if (isStackSlot(location)) { int index = indexForStackSlot(asStackSlot(location)); - frameRefMap.set(index); + refMap.setStackSlot(index); } else { assert isConstant(location); }
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRFrameState.java Wed Jan 22 10:51:32 2014 +0100 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRFrameState.java Wed Jan 22 11:27:28 2014 +0100 @@ -116,8 +116,7 @@ * @param canHaveRegisters True if there can be any register map entries. */ public void initDebugInfo(FrameMap frameMap, boolean canHaveRegisters) { - BitSet registerRefMap = (canHaveRegisters ? frameMap.initRegisterRefMap() : null); - debugInfo = new DebugInfo(topFrame, registerRefMap, frameMap.initFrameRefMap()); + debugInfo = new DebugInfo(topFrame, frameMap.initReferenceMap(canHaveRegisters)); } /** @@ -129,16 +128,7 @@ * @param frameMap The frame map. */ public void markLocation(Value location, FrameMap frameMap) { - if (location.getKind() == Kind.Object) { - if (isRegister(location)) { - debugInfo.getRegisterRefMap().set(asRegister(location).number); - } else if (isStackSlot(location)) { - int index = frameMap.indexForStackSlot(asStackSlot(location)); - debugInfo.getFrameRefMap().set(index); - } else { - assert isConstant(location); - } - } + frameMap.setReference(location, debugInfo.getReferenceMap()); } /**
--- a/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/CFGPrinter.java Wed Jan 22 10:51:32 2014 +0100 +++ b/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/CFGPrinter.java Wed Jan 22 11:27:28 2014 +0100 @@ -443,9 +443,9 @@ protected void doState(LIRFrameState state) { if (state.hasDebugInfo()) { DebugInfo di = state.debugInfo(); - stateString.append(debugInfoToString(di.getBytecodePosition(), di.getRegisterRefMap(), di.getFrameRefMap(), di.getCalleeSaveInfo(), target.arch)); + stateString.append(debugInfoToString(di.getBytecodePosition(), di.getReferenceMap(), di.getCalleeSaveInfo(), target.arch)); } else { - stateString.append(debugInfoToString(state.topFrame, null, null, null, target.arch)); + stateString.append(debugInfoToString(state.topFrame, null, null, target.arch)); } } });
--- a/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/CompilationPrinter.java Wed Jan 22 10:51:32 2014 +0100 +++ b/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/CompilationPrinter.java Wed Jan 22 11:27:28 2014 +0100 @@ -28,6 +28,7 @@ import java.util.*; import com.oracle.graal.api.code.*; +import com.oracle.graal.api.code.CodeUtil.*; import com.oracle.graal.api.meta.*; import com.oracle.graal.debug.*; @@ -111,26 +112,38 @@ end("compilation"); } + private static class ArchitectureRegFormatter implements RefMapFormatter { + + private final Register[] registers; + + public ArchitectureRegFormatter(Architecture arch) { + registers = arch.getRegisters(); + } + + public String formatStackSlot(int frameRefMapIndex) { + return null; + } + + public String formatRegister(int regRefMapIndex) { + return registers[regRefMapIndex].toString(); + } + } + /** * Formats given debug info as a multi line string. */ - protected String debugInfoToString(BytecodePosition codePos, BitSet registerRefMap, BitSet frameRefMap, RegisterSaveLayout calleeSaveInfo, Architecture arch) { + protected String debugInfoToString(BytecodePosition codePos, ReferenceMap refMap, RegisterSaveLayout calleeSaveInfo, Architecture arch) { StringBuilder sb = new StringBuilder(); - if (registerRefMap != null) { + if (refMap != null && refMap.hasRegisterRefMap()) { sb.append("reg-ref-map:"); - Register[] registers = arch.getRegisters(); - for (int reg = registerRefMap.nextSetBit(0); reg >= 0; reg = registerRefMap.nextSetBit(reg + 1)) { - sb.append(' ').append(arch == null ? "r" + reg : registers[reg]); - } + refMap.appendRegisterMap(sb, arch != null ? new ArchitectureRegFormatter(arch) : null); sb.append("\n"); } - if (frameRefMap != null) { + if (refMap != null && refMap.hasFrameRefMap()) { sb.append("frame-ref-map:"); - for (int slot = frameRefMap.nextSetBit(0); slot >= 0; slot = frameRefMap.nextSetBit(slot + 1)) { - sb.append(' ').append("s").append(slot); - } + refMap.appendFrameMap(sb, null); sb.append("\n"); }
--- a/src/share/vm/classfile/systemDictionary.hpp Wed Jan 22 10:51:32 2014 +0100 +++ b/src/share/vm/classfile/systemDictionary.hpp Wed Jan 22 11:27:28 2014 +0100 @@ -212,6 +212,7 @@ do_klass(Assumptions_CallSiteTargetValue_klass, com_oracle_graal_api_code_Assumptions_CallSiteTargetValue, Opt) \ do_klass(BytecodePosition_klass, com_oracle_graal_api_code_BytecodePosition, Opt) \ do_klass(DebugInfo_klass, com_oracle_graal_api_code_DebugInfo, Opt) \ + do_klass(ReferenceMap_klass, com_oracle_graal_api_code_ReferenceMap, Opt) \ do_klass(RegisterSaveLayout_klass, com_oracle_graal_api_code_RegisterSaveLayout, Opt) \ do_klass(BytecodeFrame_klass, com_oracle_graal_api_code_BytecodeFrame, Opt) \ do_klass(CompilationResult_klass, com_oracle_graal_api_code_CompilationResult, Opt) \
--- a/src/share/vm/classfile/vmSymbols.hpp Wed Jan 22 10:51:32 2014 +0100 +++ b/src/share/vm/classfile/vmSymbols.hpp Wed Jan 22 11:27:28 2014 +0100 @@ -342,6 +342,7 @@ template(com_oracle_graal_api_code_BytecodeFrame, "com/oracle/graal/api/code/BytecodeFrame") \ template(com_oracle_graal_api_code_BytecodePosition, "com/oracle/graal/api/code/BytecodePosition") \ template(com_oracle_graal_api_code_DebugInfo, "com/oracle/graal/api/code/DebugInfo") \ + template(com_oracle_graal_api_code_ReferenceMap, "com/oracle/graal/api/code/ReferenceMap") \ template(com_oracle_graal_api_code_Register, "com/oracle/graal/api/code/Register") \ template(com_oracle_graal_api_code_RegisterValue, "com/oracle/graal/api/code/RegisterValue") \ template(com_oracle_graal_api_code_StackSlot, "com/oracle/graal/api/code/StackSlot") \
--- a/src/share/vm/graal/graalCodeInstaller.cpp Wed Jan 22 10:51:32 2014 +0100 +++ b/src/share/vm/graal/graalCodeInstaller.cpp Wed Jan 22 11:27:28 2014 +0100 @@ -84,8 +84,9 @@ // creates a HotSpot oop map out of the byte arrays provided by DebugInfo static OopMap* create_oop_map(jint total_frame_size, jint parameter_count, oop debug_info) { OopMap* map = new OopMap(total_frame_size, parameter_count); - oop register_map = (oop) DebugInfo::registerRefMap(debug_info); - oop frame_map = (oop) DebugInfo::frameRefMap(debug_info); + oop reference_map = DebugInfo::referenceMap(debug_info); + oop register_map = ReferenceMap::registerRefMap(reference_map); + oop frame_map = ReferenceMap::frameRefMap(reference_map); oop callee_save_info = (oop) DebugInfo::calleeSaveInfo(debug_info); if (register_map != NULL) {
--- a/src/share/vm/graal/graalJavaAccess.hpp Wed Jan 22 10:51:32 2014 +0100 +++ b/src/share/vm/graal/graalJavaAccess.hpp Wed Jan 22 11:27:28 2014 +0100 @@ -173,10 +173,13 @@ end_class \ start_class(DebugInfo) \ oop_field(DebugInfo, bytecodePosition, "Lcom/oracle/graal/api/code/BytecodePosition;") \ - oop_field(DebugInfo, registerRefMap, "Ljava/util/BitSet;") \ - oop_field(DebugInfo, frameRefMap, "Ljava/util/BitSet;") \ + oop_field(DebugInfo, referenceMap, "Lcom/oracle/graal/api/code/ReferenceMap;") \ oop_field(DebugInfo, calleeSaveInfo, "Lcom/oracle/graal/api/code/RegisterSaveLayout;") \ end_class \ + start_class(ReferenceMap) \ + oop_field(ReferenceMap, registerRefMap, "Ljava/util/BitSet;") \ + oop_field(ReferenceMap, frameRefMap, "Ljava/util/BitSet;") \ + end_class \ start_class(RegisterSaveLayout) \ oop_field(RegisterSaveLayout, registers, "[Lcom/oracle/graal/api/code/Register;") \ oop_field(RegisterSaveLayout, slots, "[I") \