# HG changeset patch # User Doug Simon # Date 1395777757 -3600 # Node ID c5ee41cf9823107438ed507344811c7078ceb529 # Parent 6ae9af961b7c32141688f7a9a01ecd274cefb5ac replaced RawDataValue with LIRGeneratorTool.emitData(); accept only ASCII strings in log and VM error messages diff -r 6ae9af961b7c -r c5ee41cf9823 graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/RawDataValue.java --- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/RawDataValue.java Tue Mar 25 18:53:34 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2011, 2012, 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.util.*; - -import com.oracle.graal.api.meta.*; - -/** - * Represents some raw data. - */ -public final class RawDataValue extends Value { - - private static final long serialVersionUID = 7947228462156566360L; - - private final byte[] data; - - public RawDataValue(PlatformKind kind, byte[] data) { - super(kind); - this.data = data; - } - - public byte[] getData() { - return data; - } - - @Override - public String toString() { - Formatter ret = new Formatter(); - ret.format("data["); - boolean first = true; - for (byte b : data) { - ret.format(first ? "%02X" : " %02X", b); - first = false; - } - return ret.format("]").toString(); - } - - @Override - public int hashCode() { - return Arrays.hashCode(data); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof RawDataValue) { - RawDataValue other = (RawDataValue) obj; - return Arrays.equals(data, other.data); - } else { - return false; - } - } -} diff -r 6ae9af961b7c -r c5ee41cf9823 graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/ValueUtil.java --- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/ValueUtil.java Tue Mar 25 18:53:34 2014 +0100 +++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/ValueUtil.java Tue Mar 25 21:02:37 2014 +0100 @@ -90,16 +90,6 @@ return ((RegisterValue) value).getRegister(); } - public static boolean isRawData(Value value) { - assert value != null; - return value instanceof RawDataValue; - } - - public static RawDataValue asRawData(Value value) { - assert value != null; - return (RawDataValue) value; - } - public static Register asIntReg(Value value) { if (value.getKind() != Kind.Int) { throw new InternalError("needed Int got: " + value.getKind()); diff -r 6ae9af961b7c -r c5ee41cf9823 graal/com.oracle.graal.compiler.amd64/src/com/oracle/graal/compiler/amd64/AMD64LIRGenerator.java --- a/graal/com.oracle.graal.compiler.amd64/src/com/oracle/graal/compiler/amd64/AMD64LIRGenerator.java Tue Mar 25 18:53:34 2014 +0100 +++ b/graal/com.oracle.graal.compiler.amd64/src/com/oracle/graal/compiler/amd64/AMD64LIRGenerator.java Tue Mar 25 21:02:37 2014 +0100 @@ -60,6 +60,7 @@ import com.oracle.graal.lir.amd64.AMD64ControlFlow.ReturnOp; import com.oracle.graal.lir.amd64.AMD64ControlFlow.StrategySwitchOp; import com.oracle.graal.lir.amd64.AMD64ControlFlow.TableSwitchOp; +import com.oracle.graal.lir.amd64.AMD64Move.LeaDataOp; import com.oracle.graal.lir.amd64.AMD64Move.LeaOp; import com.oracle.graal.lir.amd64.AMD64Move.LoadOp; import com.oracle.graal.lir.amd64.AMD64Move.MembarOp; @@ -158,6 +159,10 @@ append(createMove(dst, src)); } + public void emitData(AllocatableValue dst, byte[] data) { + append(new LeaDataOp(dst, data)); + } + @Override public AMD64AddressValue emitAddress(Value base, long displacement, Value index, int scale) { AllocatableValue baseRegister; diff -r 6ae9af961b7c -r c5ee41cf9823 graal/com.oracle.graal.compiler.hsail/src/com/oracle/graal/compiler/hsail/HSAILLIRGenerator.java --- a/graal/com.oracle.graal.compiler.hsail/src/com/oracle/graal/compiler/hsail/HSAILLIRGenerator.java Tue Mar 25 18:53:34 2014 +0100 +++ b/graal/com.oracle.graal.compiler.hsail/src/com/oracle/graal/compiler/hsail/HSAILLIRGenerator.java Tue Mar 25 21:02:37 2014 +0100 @@ -115,6 +115,10 @@ } } + public void emitData(AllocatableValue dst, byte[] data) { + throw GraalInternalError.unimplemented(); + } + protected HSAILAddressValue asAddressValue(Value address) { if (address instanceof HSAILAddressValue) { return (HSAILAddressValue) address; diff -r 6ae9af961b7c -r c5ee41cf9823 graal/com.oracle.graal.compiler.ptx/src/com/oracle/graal/compiler/ptx/PTXLIRGenerator.java --- a/graal/com.oracle.graal.compiler.ptx/src/com/oracle/graal/compiler/ptx/PTXLIRGenerator.java Tue Mar 25 18:53:34 2014 +0100 +++ b/graal/com.oracle.graal.compiler.ptx/src/com/oracle/graal/compiler/ptx/PTXLIRGenerator.java Tue Mar 25 21:02:37 2014 +0100 @@ -208,6 +208,11 @@ } @Override + public void emitData(AllocatableValue dst, byte[] data) { + throw GraalInternalError.unimplemented(); + } + + @Override public PTXAddressValue emitAddress(Value base, long displacement, Value index, int scale) { AllocatableValue baseRegister; long finalDisp = displacement; diff -r 6ae9af961b7c -r c5ee41cf9823 graal/com.oracle.graal.compiler.sparc/src/com/oracle/graal/compiler/sparc/SPARCLIRGenerator.java --- a/graal/com.oracle.graal.compiler.sparc/src/com/oracle/graal/compiler/sparc/SPARCLIRGenerator.java Tue Mar 25 18:53:34 2014 +0100 +++ b/graal/com.oracle.graal.compiler.sparc/src/com/oracle/graal/compiler/sparc/SPARCLIRGenerator.java Tue Mar 25 21:02:37 2014 +0100 @@ -132,6 +132,11 @@ } @Override + public void emitData(AllocatableValue dst, byte[] data) { + throw GraalInternalError.unimplemented(); + } + + @Override public SPARCAddressValue emitAddress(Value base, long displacement, Value index, int scale) { AllocatableValue baseRegister; long finalDisp = displacement; diff -r 6ae9af961b7c -r c5ee41cf9823 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/CStringNode.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/CStringNode.java Tue Mar 25 18:53:34 2014 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/CStringNode.java Tue Mar 25 21:02:37 2014 +0100 @@ -22,12 +22,11 @@ */ package com.oracle.graal.hotspot.nodes; -import java.util.*; - -import com.oracle.graal.api.code.*; +import com.oracle.graal.api.meta.*; import com.oracle.graal.compiler.gen.*; import com.oracle.graal.compiler.target.*; import com.oracle.graal.nodes.calc.*; +import com.oracle.graal.nodes.spi.*; import com.oracle.graal.word.*; /** @@ -43,17 +42,28 @@ } public void generate(LIRGenerator gen) { - gen.setResult(this, gen.emitMove(new RawDataValue(gen.target().wordKind, toCString(string)))); + gen.setResult(this, emitCString(gen, string)); + } + + public static AllocatableValue emitCString(LIRGeneratorTool gen, String value) { + AllocatableValue dst = gen.newVariable(gen.target().wordKind); + gen.emitData(dst, toCString(value)); + return dst; } /** - * Converts a String to a null terminated byte array suitable for use as a C string value. + * Converts a string to a null terminated byte array of ASCII characters. + * + * @param s a String that must only contain ASCII characters */ - public static byte[] toCString(String value) { - byte[] bytes = value.getBytes(); - byte[] nulTerminated = Arrays.copyOf(bytes, bytes.length + 1); - nulTerminated[bytes.length] = 0; - return nulTerminated; + public static byte[] toCString(String s) { + byte[] bytes = new byte[s.length() + 1]; + for (int i = 0; i < s.length(); i++) { + assert s.charAt(i) < 128 : "non-ascii string: " + s; + bytes[i] = (byte) s.charAt(i); + } + bytes[s.length()] = 0; + return bytes; } @NodeIntrinsic(setStampFromReturnType = true) diff -r 6ae9af961b7c -r c5ee41cf9823 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/VMErrorNode.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/VMErrorNode.java Tue Mar 25 18:53:34 2014 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/VMErrorNode.java Tue Mar 25 21:02:37 2014 +0100 @@ -65,8 +65,8 @@ ResolvedJavaMethod method = graph().method(); whereString = "in compiled code for " + (method == null ? graph().toString() : format("%H.%n(%p)", method)); } - Value whereArg = new RawDataValue(gen.target().wordKind, toCString(whereString)); - Value formatArg = new RawDataValue(gen.target().wordKind, toCString(format)); + Value whereArg = emitCString(gen, whereString); + Value formatArg = emitCString(gen, format); ForeignCallLinkage linkage = gen.getForeignCalls().lookupForeignCall(VMErrorNode.VM_ERROR); gen.emitForeignCall(linkage, null, whereArg, formatArg, gen.operand(value)); diff -r 6ae9af961b7c -r c5ee41cf9823 graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64Move.java --- a/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64Move.java Tue Mar 25 18:53:34 2014 +0100 +++ b/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64Move.java Tue Mar 25 21:02:37 2014 +0100 @@ -278,6 +278,23 @@ } } + public static class LeaDataOp extends AMD64LIRInstruction { + + @Def({REG}) protected AllocatableValue result; + private final byte[] data; + + public LeaDataOp(AllocatableValue result, byte[] data) { + this.result = result; + this.data = data; + } + + @Override + public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) { + RawData rawData = new RawData(data, 16); + masm.leaq(asRegister(result), (AMD64Address) crb.recordDataReferenceInCode(rawData)); + } + } + public static class StackLeaOp extends AMD64LIRInstruction { @Def({REG}) protected AllocatableValue result; @@ -377,13 +394,6 @@ } else { throw GraalInternalError.shouldNotReachHere(); } - } else if (isRawData(input)) { - if (isRegister(result)) { - RawData rawData = new RawData(asRawData(input).getData(), 16); - masm.leaq(asRegister(result), (AMD64Address) crb.recordDataReferenceInCode(rawData)); - } else { - throw GraalInternalError.shouldNotReachHere(); - } } else { throw GraalInternalError.shouldNotReachHere(); } diff -r 6ae9af961b7c -r c5ee41cf9823 graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCMove.java --- a/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCMove.java Tue Mar 25 18:53:34 2014 +0100 +++ b/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCMove.java Tue Mar 25 21:02:37 2014 +0100 @@ -26,7 +26,6 @@ import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; import static com.oracle.graal.sparc.SPARC.*; -import com.oracle.graal.api.code.CompilationResult.RawData; import com.oracle.graal.api.code.*; import com.oracle.graal.api.meta.*; import com.oracle.graal.asm.sparc.*; @@ -390,13 +389,6 @@ } else { throw GraalInternalError.shouldNotReachHere(); } - } else if (isRawData(input)) { - if (isRegister(result)) { - RawData rawData = new RawData(asRawData(input).getData(), 16); - throw GraalInternalError.unimplemented("Emitting raw data: " + rawData); - } else { - throw GraalInternalError.shouldNotReachHere(); - } } else { throw GraalInternalError.shouldNotReachHere(); } diff -r 6ae9af961b7c -r c5ee41cf9823 graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRVerifier.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRVerifier.java Tue Mar 25 18:53:34 2014 +0100 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRVerifier.java Tue Mar 25 21:02:37 2014 +0100 @@ -237,7 +237,6 @@ if ((isVariable(value) && flags.contains(OperandFlag.REG)) || (isRegister(value) && flags.contains(OperandFlag.REG)) || (isStackSlot(value) && flags.contains(OperandFlag.STACK)) || - (isRawData(value) && flags.contains(OperandFlag.CONST) && mode != OperandMode.DEF) || (isConstant(value) && flags.contains(OperandFlag.CONST) && mode != OperandMode.DEF) || (isIllegal(value) && flags.contains(OperandFlag.ILLEGAL))) { return value; diff -r 6ae9af961b7c -r c5ee41cf9823 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/spi/LIRGeneratorTool.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/spi/LIRGeneratorTool.java Tue Mar 25 18:53:34 2014 +0100 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/spi/LIRGeneratorTool.java Tue Mar 25 21:02:37 2014 +0100 @@ -59,6 +59,14 @@ void emitMove(AllocatableValue dst, Value src); + /** + * Emits an op that loads the address of some raw data. + * + * @param dst the variable into which the address is loaded + * @param data the data to be installed with the generated code + */ + void emitData(AllocatableValue dst, byte[] data); + Value emitAddress(Value base, long displacement, Value index, int scale); Value emitAddress(StackSlot slot);