# HG changeset patch # User Doug Simon # Date 1365492907 -7200 # Node ID b9fb1ecaad92f99d17a9e7c9793a589548f38a32 # Parent 91c39d0927fb3f9d689017a8045f9b61665db3fd convert non-int boxed primitives whose stack kind is int to Constants of the right kind diff -r 91c39d0927fb -r b9fb1ecaad92 graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/SnippetTemplate.java --- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/SnippetTemplate.java Mon Apr 08 21:33:22 2013 +0200 +++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/SnippetTemplate.java Tue Apr 09 09:35:07 2013 +0200 @@ -497,7 +497,7 @@ } else { Kind kind = ((LocalNode) parameter).kind(); assert argument != null || kind == Kind.Object : this + " cannot accept null for non-object parameter named " + name; - Constant constant = Constant.forBoxed(kind, argument); + Constant constant = forBoxed(argument, kind); replacements.put((LocalNode) parameter, ConstantNode.forConstant(constant, runtime, replaceeGraph)); } } else if (parameter instanceof LocalNode[]) { @@ -521,7 +521,7 @@ if (value instanceof ValueNode) { replacements.put(local, (ValueNode) value); } else { - Constant constant = Constant.forBoxed(local.kind(), value); + Constant constant = forBoxed(value, local.kind()); ConstantNode element = ConstantNode.forConstant(constant, runtime, replaceeGraph); replacements.put(local, element); } @@ -534,6 +534,32 @@ } /** + * Converts a Java boxed value to a {@link Constant} of the right kind. This adjusts for the + * limitation that a {@link Local}'s kind is a {@linkplain Kind#getStackKind() stack kind} and + * so cannot be used for re-boxing primitives smaller than an int. + * + * @param argument a Java boxed value + * @param localKind the kind of the {@link Local} to which {@code argument} will be bound + */ + protected Constant forBoxed(Object argument, Kind localKind) { + assert localKind == localKind.getStackKind(); + if (localKind == Kind.Int && !(argument instanceof Integer)) { + if (argument instanceof Boolean) { + return Constant.forBoxed(Kind.Boolean, argument); + } + if (argument instanceof Byte) { + return Constant.forBoxed(Kind.Byte, argument); + } + if (argument instanceof Short) { + return Constant.forBoxed(Kind.Short, argument); + } + assert argument instanceof Character; + return Constant.forBoxed(Kind.Char, argument); + } + return Constant.forBoxed(localKind, argument); + } + + /** * Logic for replacing a snippet-lowered node at its usages with the return value of the * snippet. An alternative to the {@linkplain SnippetTemplate#DEFAULT_REPLACER default} * replacement logic can be used to handle mismatches between the stamp of the node being