Mercurial > hg > graal-compiler
changeset 22238:9c811a5e6a62
Split HotSpotReferenceMap into separate builder and result class, and move the builder class from jvmci to graal.
line wrap: on
line diff
--- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotBackend.java Thu Jul 16 14:17:48 2015 +0200 +++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotBackend.java Thu Jul 16 17:44:49 2015 +0200 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2015, 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 @@ -69,7 +69,7 @@ @Override public FrameMap newFrameMap(RegisterConfig registerConfig) { - return new AMD64FrameMap(getCodeCache(), registerConfig); + return new AMD64FrameMap(getCodeCache(), registerConfig, this); } @Override
--- a/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotBackend.java Thu Jul 16 14:17:48 2015 +0200 +++ b/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotBackend.java Thu Jul 16 17:44:49 2015 +0200 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2015, 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 @@ -96,7 +96,7 @@ @Override public FrameMap newFrameMap(RegisterConfig registerConfig) { - return new SPARCFrameMap(getCodeCache(), registerConfig); + return new SPARCFrameMap(getCodeCache(), registerConfig, this); } @Override
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotBackend.java Thu Jul 16 14:17:48 2015 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotBackend.java Thu Jul 16 17:44:49 2015 +0200 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2015, 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 @@ -52,7 +52,7 @@ /** * HotSpot specific backend. */ -public abstract class HotSpotBackend extends Backend { +public abstract class HotSpotBackend extends Backend implements FrameMap.ReferenceMapBuilderFactory { public static class Options { // @formatter:off @@ -242,4 +242,9 @@ HotSpotInstructionProfiling.countInstructions(lir, crb.asm); } } + + @Override + public ReferenceMapBuilder newReferenceMapBuilder(int totalFrameSize) { + return new HotSpotReferenceMapBuilder(getTarget(), totalFrameSize); + } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotReferenceMapBuilder.java Thu Jul 16 17:44:49 2015 +0200 @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2009, 2015, 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 static jdk.internal.jvmci.code.ValueUtil.*; + +import java.util.*; + +import com.oracle.graal.lir.*; +import com.oracle.graal.lir.framemap.*; + +import jdk.internal.jvmci.code.*; +import jdk.internal.jvmci.common.*; +import jdk.internal.jvmci.hotspot.*; +import jdk.internal.jvmci.meta.*; + +public final class HotSpotReferenceMapBuilder extends ReferenceMapBuilder { + + private int maxRegisterSize; + + private final ArrayList<Value> objectValues; + private int objectCount; + + private final TargetDescription target; + private final int totalFrameSize; + + public HotSpotReferenceMapBuilder(TargetDescription target, int totalFrameSize) { + this.objectValues = new ArrayList<>(); + this.objectCount = 0; + + this.target = target; + this.totalFrameSize = totalFrameSize; + } + + @Override + public void addLiveValue(Value v) { + if (isConstant(v)) { + return; + } + LIRKind lirKind = v.getLIRKind(); + if (!lirKind.isValue()) { + objectValues.add(v); + if (lirKind.isUnknownReference()) { + objectCount++; + } else { + objectCount += lirKind.getReferenceCount(); + } + } + if (isRegister(v)) { + int size = target.getSizeInBytes(lirKind.getPlatformKind()); + if (size > maxRegisterSize) { + maxRegisterSize = size; + } + } + } + + @Override + public ReferenceMap finish(LIRFrameState state) { + Location[] objects = new Location[objectCount]; + Location[] derivedBase = new Location[objectCount]; + int[] sizeInBytes = new int[objectCount]; + + int idx = 0; + for (Value obj : objectValues) { + LIRKind kind = obj.getLIRKind(); + int bytes = bytesPerElement(kind); + if (kind.isUnknownReference()) { + throw JVMCIError.unimplemented("derived references not yet implemented"); + } else { + for (int i = 0; i < kind.getPlatformKind().getVectorLength(); i++) { + if (kind.isReference(i)) { + objects[idx] = toLocation(obj, i * bytes); + derivedBase[idx] = null; + sizeInBytes[idx] = bytes; + idx++; + } + } + } + } + + return new HotSpotReferenceMap(objects, derivedBase, sizeInBytes, maxRegisterSize); + } + + private int bytesPerElement(LIRKind kind) { + PlatformKind platformKind = kind.getPlatformKind(); + return target.getSizeInBytes(platformKind) / platformKind.getVectorLength(); + } + + private Location toLocation(Value v, int offset) { + if (isRegister(v)) { + return Location.subregister(asRegister(v), offset); + } else { + StackSlot s = asStackSlot(v); + return Location.stack(s.getOffset(totalFrameSize) + offset); + } + } +}
--- a/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64FrameMap.java Thu Jul 16 14:17:48 2015 +0200 +++ b/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64FrameMap.java Thu Jul 16 17:44:49 2015 +0200 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2015, 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 @@ -36,7 +36,7 @@ * * <pre> * Base Contents - * + * * : : ----- * caller | incoming overflow argument n | ^ * frame : ... : | positive @@ -74,8 +74,8 @@ private StackSlot rbpSpillSlot; - public AMD64FrameMap(CodeCacheProvider codeCache, RegisterConfig registerConfig) { - super(codeCache, registerConfig); + public AMD64FrameMap(CodeCacheProvider codeCache, RegisterConfig registerConfig, ReferenceMapBuilderFactory referenceMapFactory) { + super(codeCache, registerConfig, referenceMapFactory); // (negative) offset relative to sp + total frame size initialSpillSize = returnAddressSize() + calleeSaveAreaSize(); spillSize = initialSpillSize;
--- a/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCFrameMap.java Thu Jul 16 14:17:48 2015 +0200 +++ b/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCFrameMap.java Thu Jul 16 17:44:49 2015 +0200 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2015, 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 @@ -75,8 +75,8 @@ */ public final class SPARCFrameMap extends FrameMap { - public SPARCFrameMap(CodeCacheProvider codeCache, RegisterConfig registerConfig) { - super(codeCache, registerConfig); + public SPARCFrameMap(CodeCacheProvider codeCache, RegisterConfig registerConfig, ReferenceMapBuilderFactory referenceMapFactory) { + super(codeCache, registerConfig, referenceMapFactory); // Initial spill size is set to register save area size (SPARC register window) initialSpillSize = 0; spillSize = initialSpillSize;
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRFrameState.java Thu Jul 16 14:17:48 2015 +0200 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRFrameState.java Thu Jul 16 17:44:49 2015 +0200 @@ -169,7 +169,7 @@ * @param canHaveRegisters True if there can be any register map entries. */ public void initDebugInfo(FrameMap frameMap, boolean canHaveRegisters) { - debugInfo = new DebugInfo(topFrame, frameMap.initReferenceMap(canHaveRegisters), virtualObjects); + debugInfo = new DebugInfo(topFrame, virtualObjects); } @Override
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/dfa/LocationMarkerPhase.java Thu Jul 16 14:17:48 2015 +0200 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/dfa/LocationMarkerPhase.java Thu Jul 16 17:44:49 2015 +0200 @@ -138,7 +138,7 @@ throw new UnsupportedOperationException(); } - public void addLiveValues(ReferenceMap refMap) { + public void addLiveValues(ReferenceMapBuilder refMap) { registers.addLiveValues(refMap); stack.addLiveValues(refMap); if (extraStack != null) { @@ -175,11 +175,11 @@ info.initDebugInfo(frameMap, !op.destroysCallerSavedRegisters() || !frameMap.getRegisterConfig().areAllAllocatableRegistersCallerSaved()); } - ReferenceMap refMap = info.debugInfo().getReferenceMap(); - refMap.reset(); + ReferenceMapBuilder refMap = frameMap.newReferenceMapBuilder(); frameMap.addLiveValues(refMap); values.addLiveValues(refMap); - refMap.finish(); + + info.debugInfo().setReferenceMap(refMap.finish(info)); } /**
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/dfa/ValueSet.java Thu Jul 16 14:17:48 2015 +0200 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/dfa/ValueSet.java Thu Jul 16 17:44:49 2015 +0200 @@ -24,9 +24,10 @@ import java.util.*; -import jdk.internal.jvmci.code.*; import jdk.internal.jvmci.meta.*; +import com.oracle.graal.lir.framemap.*; + final class ValueSet { private Value[] values; @@ -114,7 +115,7 @@ return false; } - public void addLiveValues(ReferenceMap refMap) { + public void addLiveValues(ReferenceMapBuilder refMap) { for (Value v : values) { if (v != null) { refMap.addLiveValue(v);
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/framemap/FrameMap.java Thu Jul 16 14:17:48 2015 +0200 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/framemap/FrameMap.java Thu Jul 16 17:44:49 2015 +0200 @@ -42,6 +42,13 @@ private final TargetDescription target; private final RegisterConfig registerConfig; + public interface ReferenceMapBuilderFactory { + + ReferenceMapBuilder newReferenceMapBuilder(int totalFrameSize); + } + + private final ReferenceMapBuilderFactory referenceMapFactory; + /** * The final frame size, not including the size of the * {@link Architecture#getReturnAddressSize() return address slot}. The value is only set after @@ -86,12 +93,13 @@ * Creates a new frame map for the specified method. The given registerConfig is optional, in * case null is passed the default RegisterConfig from the CodeCacheProvider will be used. */ - public FrameMap(CodeCacheProvider codeCache, RegisterConfig registerConfig) { + public FrameMap(CodeCacheProvider codeCache, RegisterConfig registerConfig, ReferenceMapBuilderFactory referenceMapFactory) { this.target = codeCache.getTarget(); this.registerConfig = registerConfig == null ? codeCache.getRegisterConfig() : registerConfig; this.frameSize = -1; this.outgoingSize = codeCache.getMinimumOutgoingSize(); this.objectStackSlots = new ArrayList<>(); + this.referenceMapFactory = referenceMapFactory; } public RegisterConfig getRegisterConfig() { @@ -102,7 +110,7 @@ return target; } - public void addLiveValues(ReferenceMap refMap) { + public void addLiveValues(ReferenceMapBuilder refMap) { for (Value value : objectStackSlots) { refMap.addLiveValue(value); } @@ -319,8 +327,7 @@ objectStackSlots.add(objectSlot); } - public ReferenceMap initReferenceMap(boolean hasRegisters) { - ReferenceMap refMap = getTarget().createReferenceMap(hasRegisters, frameSize() / getTarget().wordSize, totalFrameSize()); - return refMap; + public ReferenceMapBuilder newReferenceMapBuilder() { + return referenceMapFactory.newReferenceMapBuilder(totalFrameSize()); } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/framemap/ReferenceMapBuilder.java Thu Jul 16 17:44:49 2015 +0200 @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2015, 2015, 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.lir.framemap; + +import jdk.internal.jvmci.code.*; +import jdk.internal.jvmci.meta.*; + +import com.oracle.graal.lir.*; + +public abstract class ReferenceMapBuilder { + + public abstract void addLiveValue(Value value); + + public abstract ReferenceMap finish(LIRFrameState state); +}
--- a/jvmci/jdk.internal.jvmci.code/src/jdk/internal/jvmci/code/DebugInfo.java Thu Jul 16 14:17:48 2015 +0200 +++ b/jvmci/jdk.internal.jvmci.code/src/jdk/internal/jvmci/code/DebugInfo.java Thu Jul 16 17:44:49 2015 +0200 @@ -39,7 +39,7 @@ public final class DebugInfo { private final BytecodePosition bytecodePosition; - private final ReferenceMap referenceMap; + private ReferenceMap referenceMap; @SuppressWarnings("unused") private final VirtualObject[] virtualObjectMapping; private RegisterSaveLayout calleeSaveInfo; @@ -48,17 +48,19 @@ * * @param codePos the {@linkplain BytecodePosition code position} or {@linkplain BytecodeFrame * frame} info - * @param referenceMap the reference map * @param virtualObjectMapping the mapping of {@link VirtualObject}s to their real values */ - public DebugInfo(BytecodePosition codePos, ReferenceMap referenceMap, VirtualObject[] virtualObjectMapping) { + public DebugInfo(BytecodePosition codePos, VirtualObject[] virtualObjectMapping) { this.bytecodePosition = codePos; - this.referenceMap = referenceMap; this.virtualObjectMapping = virtualObjectMapping; } public DebugInfo(BytecodePosition codePos) { - this(codePos, null, null); + this(codePos, null); + } + + public void setReferenceMap(ReferenceMap referenceMap) { + this.referenceMap = referenceMap; } /**
--- a/jvmci/jdk.internal.jvmci.code/src/jdk/internal/jvmci/code/ReferenceMap.java Thu Jul 16 14:17:48 2015 +0200 +++ b/jvmci/jdk.internal.jvmci.code/src/jdk/internal/jvmci/code/ReferenceMap.java Thu Jul 16 17:44:49 2015 +0200 @@ -22,24 +22,5 @@ */ package jdk.internal.jvmci.code; -import jdk.internal.jvmci.meta.*; - public abstract class ReferenceMap { - - /** - * Empty out the reference map. - */ - public abstract void reset(); - - /** - * Add {@code value} to the current set of reference values. - * - * @param v - */ - public abstract void addLiveValue(Value v); - - /** - * Perform any final encoding needed before use. - */ - public abstract void finish(); }
--- a/jvmci/jdk.internal.jvmci.code/src/jdk/internal/jvmci/code/TargetDescription.java Thu Jul 16 14:17:48 2015 +0200 +++ b/jvmci/jdk.internal.jvmci.code/src/jdk/internal/jvmci/code/TargetDescription.java Thu Jul 16 17:44:49 2015 +0200 @@ -136,6 +136,4 @@ return LIRKind.Illegal; } } - - public abstract ReferenceMap createReferenceMap(boolean hasRegisters, int stackSlotCount, int totalFrameSize); }
--- a/jvmci/jdk.internal.jvmci.hotspot/src/jdk/internal/jvmci/hotspot/HotSpotReferenceMap.java Thu Jul 16 14:17:48 2015 +0200 +++ b/jvmci/jdk.internal.jvmci.hotspot/src/jdk/internal/jvmci/hotspot/HotSpotReferenceMap.java Thu Jul 16 17:44:49 2015 +0200 @@ -22,107 +22,22 @@ */ package jdk.internal.jvmci.hotspot; -import static jdk.internal.jvmci.code.ValueUtil.*; - import java.util.*; import jdk.internal.jvmci.code.*; -import jdk.internal.jvmci.common.*; -import jdk.internal.jvmci.meta.*; public final class HotSpotReferenceMap extends ReferenceMap { - private Location[] objects; - private Location[] derivedBase; - private int[] sizeInBytes; - private int maxRegisterSize; - - private ArrayList<Value> objectValues; - private int objectCount; - - private final TargetDescription target; - private final int totalFrameSize; - - public HotSpotReferenceMap(TargetDescription target, int totalFrameSize) { - this.target = target; - this.objectCount = 0; - this.totalFrameSize = totalFrameSize; - } - - @Override - public void reset() { - objects = null; - derivedBase = null; - sizeInBytes = null; - maxRegisterSize = 0; - - objectValues = new ArrayList<>(); - objectCount = 0; - } + final Location[] objects; + final Location[] derivedBase; + final int[] sizeInBytes; + final int maxRegisterSize; - @Override - public void addLiveValue(Value v) { - if (isConstant(v)) { - return; - } - LIRKind lirKind = v.getLIRKind(); - if (!lirKind.isValue()) { - objectValues.add(v); - if (lirKind.isUnknownReference()) { - objectCount++; - } else { - objectCount += lirKind.getReferenceCount(); - } - } - if (isRegister(v)) { - int size = target.getSizeInBytes(lirKind.getPlatformKind()); - if (size > maxRegisterSize) { - maxRegisterSize = size; - } - } - } - - @Override - public void finish() { - objects = new Location[objectCount]; - derivedBase = new Location[objectCount]; - sizeInBytes = new int[objectCount]; - - int idx = 0; - for (Value obj : objectValues) { - LIRKind kind = obj.getLIRKind(); - int bytes = bytesPerElement(kind); - if (kind.isUnknownReference()) { - throw JVMCIError.unimplemented("derived references not yet implemented"); - } else { - for (int i = 0; i < kind.getPlatformKind().getVectorLength(); i++) { - if (kind.isReference(i)) { - objects[idx] = toLocation(obj, i * bytes); - derivedBase[idx] = null; - sizeInBytes[idx] = bytes; - idx++; - } - } - } - } - - assert idx == objectCount; - objectValues = null; - objectCount = 0; - } - - private int bytesPerElement(LIRKind kind) { - PlatformKind platformKind = kind.getPlatformKind(); - return target.getSizeInBytes(platformKind) / platformKind.getVectorLength(); - } - - private Location toLocation(Value v, int offset) { - if (isRegister(v)) { - return Location.subregister(asRegister(v), offset); - } else { - StackSlot s = asStackSlot(v); - return Location.stack(s.getOffset(totalFrameSize) + offset); - } + public HotSpotReferenceMap(Location[] objects, Location[] derivedBase, int[] sizeInBytes, int maxRegisterSize) { + this.objects = objects; + this.derivedBase = derivedBase; + this.sizeInBytes = sizeInBytes; + this.maxRegisterSize = maxRegisterSize; } @Override @@ -137,7 +52,7 @@ } if (obj instanceof HotSpotReferenceMap) { HotSpotReferenceMap that = (HotSpotReferenceMap) obj; - if (Arrays.equals(objects, that.objects) && this.target.equals(that.target)) { + if (Arrays.equals(objects, that.objects)) { return true; } }
--- a/jvmci/jdk.internal.jvmci.hotspot/src/jdk/internal/jvmci/hotspot/HotSpotTargetDescription.java Thu Jul 16 14:17:48 2015 +0200 +++ b/jvmci/jdk.internal.jvmci.hotspot/src/jdk/internal/jvmci/hotspot/HotSpotTargetDescription.java Thu Jul 16 17:44:49 2015 +0200 @@ -29,9 +29,4 @@ public HotSpotTargetDescription(Architecture arch, boolean isMP, int stackAlignment, int implicitNullCheckLimit, boolean inlineObjects) { super(arch, isMP, stackAlignment, implicitNullCheckLimit, inlineObjects); } - - @Override - public ReferenceMap createReferenceMap(boolean hasRegisters, int stackSlotCount, int totalFrameSize) { - return new HotSpotReferenceMap(this, totalFrameSize); - } }