# HG changeset patch # User Roland Schatz # Date 1395054469 -3600 # Node ID 45812e05cdb3ad1456c3df69374b18992bdf15a9 # Parent e14198669e5c506756dbfae740ebee7f2aa553f3 Move narrow oop handling in reference maps to hotspot specific code. diff -r e14198669e5c -r 45812e05cdb3 graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CodeUtil.java --- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CodeUtil.java Mon Mar 17 11:53:51 2014 +0100 +++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CodeUtil.java Mon Mar 17 12:07:49 2014 +0100 @@ -281,6 +281,17 @@ } } + public static class NumberedRefMapFormatter implements RefMapFormatter { + + public String formatStackSlot(int frameRefMapIndex) { + return "s" + frameRefMapIndex; + } + + public String formatRegister(int regRefMapIndex) { + return "r" + regRefMapIndex; + } + } + /** * Appends a formatted debug info to a {@link StringBuilder}. * @@ -288,7 +299,11 @@ * @param info the debug info to format and append to {@code sb} * @return the value of {@code sb} */ - public static StringBuilder append(StringBuilder sb, DebugInfo info, RefMapFormatter formatter) { + public static StringBuilder append(StringBuilder sb, DebugInfo info, RefMapFormatter formatterArg) { + RefMapFormatter formatter = formatterArg; + if (formatter == null) { + formatter = new NumberedRefMapFormatter(); + } String nl = NEW_LINE; ReferenceMap refMap = info.getReferenceMap(); if (refMap != null && refMap.hasRegisterRefMap()) { diff -r e14198669e5c -r 45812e05cdb3 graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CompilationResult.java --- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CompilationResult.java Mon Mar 17 11:53:51 2014 +0100 +++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CompilationResult.java Mon Mar 17 12:07:49 2014 +0100 @@ -28,6 +28,7 @@ import java.nio.*; import java.util.*; +import com.oracle.graal.api.code.CodeUtil.*; import com.oracle.graal.api.meta.*; /** @@ -695,14 +696,15 @@ if (info != null) { ReferenceMap refMap = info.getReferenceMap(); if (refMap != null) { + RefMapFormatter formatter = new CodeUtil.NumberedRefMapFormatter(); if (refMap.hasFrameRefMap()) { sb.append(" stackMap["); - refMap.appendFrameMap(sb, null); + refMap.appendFrameMap(sb, formatter); sb.append(']'); } if (refMap.hasRegisterRefMap()) { sb.append(" registerMap["); - refMap.appendRegisterMap(sb, null); + refMap.appendRegisterMap(sb, formatter); sb.append(']'); } } diff -r e14198669e5c -r 45812e05cdb3 graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/ReferenceMap.java --- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/ReferenceMap.java Mon Mar 17 11:53:51 2014 +0100 +++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/ReferenceMap.java Mon Mar 17 12:07:49 2014 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2014, 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 @@ -22,123 +22,20 @@ */ 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; - - /** - * Contains 2 bits per register. - * - */ - private final BitSet registerRefMap; - - /** - * Contains 3 bits per stack slot. - * - */ - private final BitSet frameRefMap; +import com.oracle.graal.api.meta.*; - public ReferenceMap(int registerCount, int frameSlotCount) { - if (registerCount > 0) { - this.registerRefMap = new BitSet(registerCount * 2); - } else { - this.registerRefMap = null; - } - this.frameRefMap = new BitSet(frameSlotCount * 3); - } +public interface ReferenceMap { - public void setRegister(int idx, boolean narrow) { - registerRefMap.set(2 * idx); - if (narrow) { - registerRefMap.set(2 * idx + 1); - } - } + void setRegister(int idx, PlatformKind kind); - public void setStackSlot(int idx, boolean narrow1, boolean narrow2) { - frameRefMap.set(3 * idx); - if (narrow1) { - frameRefMap.set(3 * idx + 1); - } - if (narrow2) { - frameRefMap.set(3 * idx + 2); - } - } - - public boolean hasRegisterRefMap() { - return registerRefMap != null && registerRefMap.size() > 0; - } + void setStackSlot(int offset, PlatformKind kind); - public boolean hasFrameRefMap() { - return frameRefMap != null && frameRefMap.size() > 0; - } - - public interface Iterator { - void register(int idx, boolean narrow); - - void stackSlot(int idx, boolean narrow1, boolean narrow2); - } + boolean hasRegisterRefMap(); - public void iterate(Iterator iterator) { - if (hasRegisterRefMap()) { - for (int i = 0; i < registerRefMap.size() / 2; i++) { - if (registerRefMap.get(2 * i)) { - iterator.register(i, registerRefMap.get(2 * i + 1)); - } - } - } - if (hasFrameRefMap()) { - for (int i = 0; i < frameRefMap.size() / 3; i++) { - if (frameRefMap.get(3 * i)) { - iterator.stackSlot(i, frameRefMap.get(3 * i + 1), frameRefMap.get(3 * i + 2)); - } - } - } - } - - private static class NumberedRefMapFormatter implements RefMapFormatter { + boolean hasFrameRefMap(); - 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(); - } + void appendRegisterMap(StringBuilder sb, RefMapFormatter formatterArg); - for (int reg = registerRefMap.nextSetBit(0); reg >= 0; reg = registerRefMap.nextSetBit(reg + 2)) { - sb.append(' ').append(formatter.formatRegister(reg / 2)); - } - } - - 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 + 3)) { - sb.append(' ').append(formatter.formatStackSlot(slot / 3)); - } - } + void appendFrameMap(StringBuilder sb, RefMapFormatter formatterArg); } diff -r e14198669e5c -r 45812e05cdb3 graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/TargetDescription.java --- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/TargetDescription.java Mon Mar 17 11:53:51 2014 +0100 +++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/TargetDescription.java Mon Mar 17 12:07:49 2014 +0100 @@ -28,7 +28,7 @@ * Represents the target machine for a compiler, including the CPU architecture, the size of * pointers and references, alignment of stacks, caches, etc. */ -public class TargetDescription { +public abstract class TargetDescription { public final Architecture arch; @@ -85,4 +85,6 @@ public int getSizeInBytes(PlatformKind kind) { return arch.getSizeInBytes(kind); } + + public abstract ReferenceMap createReferenceMap(boolean hasRegisters, int stackSlotCount); } diff -r e14198669e5c -r 45812e05cdb3 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotReferenceMap.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotReferenceMap.java Mon Mar 17 12:07:49 2014 +0100 @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2009, 2014, 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.hotspot; + +import java.io.*; +import java.util.*; + +import com.oracle.graal.api.code.CodeUtil.RefMapFormatter; +import com.oracle.graal.api.code.*; +import com.oracle.graal.api.meta.*; +import com.oracle.graal.hotspot.nodes.type.*; + +public class HotSpotReferenceMap implements ReferenceMap, Serializable { + + private static final long serialVersionUID = -1052183095979496819L; + + /** + * Contains 2 bits per register. + * + */ + private final BitSet registerRefMap; + + /** + * Contains 3 bits per stack slot. + * + */ + private final BitSet frameRefMap; + + private final int frameSlotSize; + + public HotSpotReferenceMap(int registerCount, int frameSlotCount, int frameSlotSize) { + if (registerCount > 0) { + this.registerRefMap = new BitSet(registerCount * 2); + } else { + this.registerRefMap = null; + } + this.frameRefMap = new BitSet(frameSlotCount * 3); + this.frameSlotSize = frameSlotSize; + } + + public void setRegister(int idx, PlatformKind kind) { + if (kind == Kind.Object) { + registerRefMap.set(2 * idx); + } else if (kind == NarrowOopStamp.NarrowOop) { + registerRefMap.set(2 * idx); + registerRefMap.set(2 * idx + 1); + } + } + + public void setStackSlot(int offset, PlatformKind kind) { + int idx = offset / frameSlotSize; + if (kind == Kind.Object) { + assert offset % frameSlotSize == 0; + frameRefMap.set(3 * idx); + } else if (kind == NarrowOopStamp.NarrowOop) { + frameRefMap.set(3 * idx); + if (offset % frameSlotSize == 0) { + frameRefMap.set(3 * idx + 1); + } else { + assert offset % frameSlotSize == frameSlotSize / 2; + frameRefMap.set(3 * idx + 2); + } + } + } + + public boolean hasRegisterRefMap() { + return registerRefMap != null && registerRefMap.size() > 0; + } + + public boolean hasFrameRefMap() { + return frameRefMap != null && frameRefMap.size() > 0; + } + + 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)); + } + } + + 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)); + } + } +} diff -r e14198669e5c -r 45812e05cdb3 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 Mar 17 11:53:51 2014 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotTargetDescription.java Mon Mar 17 12:07:49 2014 +0100 @@ -43,4 +43,9 @@ return super.getSizeInBytes(kind); } } + + @Override + public ReferenceMap createReferenceMap(boolean hasRegisters, int stackSlotCount) { + return new HotSpotReferenceMap(hasRegisters ? arch.getRegisterReferenceMapBitCount() : 0, stackSlotCount, wordSize); + } } diff -r e14198669e5c -r 45812e05cdb3 graal/com.oracle.graal.lir/src/com/oracle/graal/lir/FrameMap.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/FrameMap.java Mon Mar 17 11:53:51 2014 +0100 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/FrameMap.java Mon Mar 17 12:07:49 2014 +0100 @@ -347,8 +347,8 @@ } } - public ReferenceMap initReferenceMap(boolean canHaveRegisters) { - ReferenceMap refMap = new ReferenceMap(canHaveRegisters ? target.arch.getRegisterReferenceMapBitCount() : 0, frameSize() / target.wordSize); + public ReferenceMap initReferenceMap(boolean hasRegisters) { + ReferenceMap refMap = target.createReferenceMap(hasRegisters, frameSize() / target.wordSize); for (StackSlot slot : objectStackSlots) { setReference(slot, refMap); } @@ -364,22 +364,14 @@ * @param refMap A reference map, as created by {@link #initReferenceMap(boolean)}. */ public void setReference(Value location, ReferenceMap refMap) { - Kind kind = location.getKind(); - if (kind == Kind.Object || kind == Kind.NarrowOop) { - if (isRegister(location)) { - refMap.setRegister(asRegister(location).number, kind == Kind.NarrowOop); - } else if (isStackSlot(location)) { - if (kind == Kind.NarrowOop) { - int offset = offsetForStackSlot(asStackSlot(location)); - assert offset % target.wordSize == 0 || offset % target.wordSize == target.wordSize / 2; - refMap.setStackSlot(offset / target.wordSize, offset % target.wordSize == 0, offset % target.wordSize != 0); - } else { - int index = indexForStackSlot(asStackSlot(location)); - refMap.setStackSlot(index, false, false); - } - } else { - assert isConstant(location); - } + PlatformKind kind = location.getPlatformKind(); + if (isRegister(location)) { + refMap.setRegister(asRegister(location).number, kind); + } else if (isStackSlot(location)) { + int offset = offsetForStackSlot(asStackSlot(location)); + refMap.setStackSlot(offset, kind); + } else { + assert isConstant(location); } } } diff -r e14198669e5c -r 45812e05cdb3 graal/com.oracle.graal.printer/src/com/oracle/graal/printer/CompilationPrinter.java --- a/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/CompilationPrinter.java Mon Mar 17 11:53:51 2014 +0100 +++ b/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/CompilationPrinter.java Mon Mar 17 12:07:49 2014 +0100 @@ -134,16 +134,17 @@ */ protected String debugInfoToString(BytecodePosition codePos, ReferenceMap refMap, RegisterSaveLayout calleeSaveInfo, Architecture arch) { StringBuilder sb = new StringBuilder(); + RefMapFormatter formatter = new CodeUtil.NumberedRefMapFormatter(); if (refMap != null && refMap.hasRegisterRefMap()) { sb.append("reg-ref-map:"); - refMap.appendRegisterMap(sb, arch != null ? new ArchitectureRegFormatter(arch) : null); + refMap.appendRegisterMap(sb, arch != null ? new ArchitectureRegFormatter(arch) : formatter); sb.append("\n"); } if (refMap != null && refMap.hasFrameRefMap()) { sb.append("frame-ref-map:"); - refMap.appendFrameMap(sb, null); + refMap.appendFrameMap(sb, formatter); sb.append("\n"); } diff -r e14198669e5c -r 45812e05cdb3 src/share/vm/classfile/systemDictionary.hpp --- a/src/share/vm/classfile/systemDictionary.hpp Mon Mar 17 11:53:51 2014 +0100 +++ b/src/share/vm/classfile/systemDictionary.hpp Mon Mar 17 12:07:49 2014 +0100 @@ -191,6 +191,7 @@ do_klass(HotSpotCompiledNmethod_klass, com_oracle_graal_hotspot_HotSpotCompiledNmethod, Opt) \ do_klass(HotSpotCompiledRuntimeStub_klass, com_oracle_graal_hotspot_HotSpotCompiledRuntimeStub, Opt) \ do_klass(HotSpotForeignCallLinkage_klass, com_oracle_graal_hotspot_HotSpotForeignCallLinkage, Opt) \ + do_klass(HotSpotReferenceMap_klass, com_oracle_graal_hotspot_HotSpotReferenceMap, Opt) \ do_klass(DataSection_klass, com_oracle_graal_hotspot_data_DataSection, Opt) \ do_klass(DataSectionReference_klass, com_oracle_graal_hotspot_data_DataSectionReference, Opt) \ do_klass(MetaspaceData_klass, com_oracle_graal_hotspot_data_MetaspaceData, Opt) \ @@ -212,7 +213,6 @@ 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) \ diff -r e14198669e5c -r 45812e05cdb3 src/share/vm/classfile/vmSymbols.hpp --- a/src/share/vm/classfile/vmSymbols.hpp Mon Mar 17 11:53:51 2014 +0100 +++ b/src/share/vm/classfile/vmSymbols.hpp Mon Mar 17 12:07:49 2014 +0100 @@ -300,6 +300,7 @@ template(com_oracle_graal_hotspot_HotSpotCompiledNmethod, "com/oracle/graal/hotspot/HotSpotCompiledNmethod") \ template(com_oracle_graal_hotspot_HotSpotCompiledRuntimeStub, "com/oracle/graal/hotspot/HotSpotCompiledRuntimeStub") \ template(com_oracle_graal_hotspot_HotSpotForeignCallLinkage, "com/oracle/graal/hotspot/HotSpotForeignCallLinkage") \ + template(com_oracle_graal_hotspot_HotSpotReferenceMap, "com/oracle/graal/hotspot/HotSpotReferenceMap") \ template(com_oracle_graal_hotspot_bridge_VMToCompiler, "com/oracle/graal/hotspot/bridge/VMToCompiler") \ template(com_oracle_graal_hotspot_bridge_CompilerToVMImpl, "com/oracle/graal/hotspot/bridge/CompilerToVMImpl") \ template(com_oracle_graal_hotspot_data_DataSection, "com/oracle/graal/hotspot/data/DataSection") \ @@ -342,7 +343,6 @@ 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") \ diff -r e14198669e5c -r 45812e05cdb3 src/share/vm/graal/graalCodeInstaller.cpp --- a/src/share/vm/graal/graalCodeInstaller.cpp Mon Mar 17 11:53:51 2014 +0100 +++ b/src/share/vm/graal/graalCodeInstaller.cpp Mon Mar 17 12:07:49 2014 +0100 @@ -91,8 +91,8 @@ 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 reference_map = DebugInfo::referenceMap(debug_info); - oop register_map = ReferenceMap::registerRefMap(reference_map); - oop frame_map = ReferenceMap::frameRefMap(reference_map); + oop register_map = HotSpotReferenceMap::registerRefMap(reference_map); + oop frame_map = HotSpotReferenceMap::frameRefMap(reference_map); oop callee_save_info = (oop) DebugInfo::calleeSaveInfo(debug_info); if (register_map != NULL) { diff -r e14198669e5c -r 45812e05cdb3 src/share/vm/graal/graalJavaAccess.hpp --- a/src/share/vm/graal/graalJavaAccess.hpp Mon Mar 17 11:53:51 2014 +0100 +++ b/src/share/vm/graal/graalJavaAccess.hpp Mon Mar 17 12:07:49 2014 +0100 @@ -179,9 +179,9 @@ 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;") \ + start_class(HotSpotReferenceMap) \ + oop_field(HotSpotReferenceMap, registerRefMap, "Ljava/util/BitSet;") \ + oop_field(HotSpotReferenceMap, frameRefMap, "Ljava/util/BitSet;") \ end_class \ start_class(RegisterSaveLayout) \ oop_field(RegisterSaveLayout, registers, "[Lcom/oracle/graal/api/code/Register;") \