# HG changeset patch # User Lukas Stadler # Date 1407330076 -7200 # Node ID 56bcde831179b355a6202010de036df5bc742175 # Parent cd8284cfe935f726843e3e1ad54d20d01c419b61 support for compressed inputs to NullCheckNode diff -r cd8284cfe935 -r 56bcde831179 graal/com.oracle.graal.hotspot.amd64.test/src/com/oracle/graal/hotspot/amd64/test/CompressedNullCheckTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.hotspot.amd64.test/src/com/oracle/graal/hotspot/amd64/test/CompressedNullCheckTest.java Wed Aug 06 15:01:16 2014 +0200 @@ -0,0 +1,63 @@ +/* + * Copyright (c) 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.amd64.test; + +import org.junit.*; + +import com.oracle.graal.compiler.test.*; +import com.oracle.graal.hotspot.nodes.*; +import com.oracle.graal.nodes.*; +import com.oracle.graal.nodes.calc.*; + +/** + * Ensures that frame omission works in cases where it is expected to. + */ +public class CompressedNullCheckTest extends GraalCompilerTest { + + private static final class Container { + Integer i = new Integer(1); + } + + public static void testSnippet(Container c) { + c.i.intValue(); + } + + @Test + public void test() { + test("testSnippet", new Container()); + } + + @Override + protected boolean checkMidTierGraph(StructuredGraph graph) { + int count = 0; + for (IsNullNode isNull : graph.getNodes().filter(IsNullNode.class).snapshot()) { + ValueNode value = isNull.getValue(); + if (value instanceof CompressionNode) { + count++; + isNull.replaceFirstInput(value, ((CompressionNode) value).getValue()); + } + } + Assert.assertEquals("graph should contain exactly one IsNullNode", 1, count); + return super.checkMidTierGraph(graph); + } +} diff -r cd8284cfe935 -r 56bcde831179 graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotLIRGenerator.java --- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotLIRGenerator.java Tue Aug 05 10:06:08 2014 +0200 +++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotLIRGenerator.java Wed Aug 06 15:01:16 2014 +0200 @@ -559,8 +559,20 @@ } public void emitNullCheck(Value address, LIRFrameState state) { - assert address.getKind() == Kind.Object : address + " - " + address.getKind() + " not an object!"; - append(new AMD64Move.NullCheckOp(load(address), state)); + if (address.getLIRKind().getPlatformKind() == Kind.Int) { + CompressEncoding encoding = config.getOopEncoding(); + System.out.println("compressed null check: " + address + " - " + address.getKind()); + if (encoding.shift <= 3) { + AMD64AddressValue uncompressionAddress = emitAddress(getProviders().getRegisters().getHeapBaseRegister().asValue(), 0, load(address), 1 << encoding.shift); + append(new AMD64HotSpotMove.CompressedNullCheckOp(uncompressionAddress, state)); + } else { + Value uncompress = emitUncompress(address, encoding, false); + append(new AMD64Move.NullCheckOp(load(uncompress), state)); + } + } else { + assert address.getKind() == Kind.Object : address + " - " + address.getKind() + " not an object!"; + append(new AMD64Move.NullCheckOp(load(address), state)); + } } @Override diff -r cd8284cfe935 -r 56bcde831179 graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotMove.java --- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotMove.java Tue Aug 05 10:06:08 2014 +0200 +++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotMove.java Wed Aug 06 15:01:16 2014 +0200 @@ -25,6 +25,7 @@ import static com.oracle.graal.api.code.ValueUtil.*; import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; +import com.oracle.graal.amd64.*; import com.oracle.graal.api.code.*; import com.oracle.graal.api.meta.*; import com.oracle.graal.asm.*; @@ -254,4 +255,24 @@ } } + public static class CompressedNullCheckOp extends AMD64LIRInstruction { + + @Use({COMPOSITE}) protected AMD64AddressValue address; + @State protected LIRFrameState state; + + public CompressedNullCheckOp(AMD64AddressValue address, LIRFrameState state) { + this.address = address; + this.state = state; + } + + @Override + public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) { + crb.recordImplicitException(masm.position(), state); + masm.testl(AMD64.rax, address.toAddress()); + } + + public LIRFrameState getState() { + return state; + } + } } diff -r cd8284cfe935 -r 56bcde831179 mx/projects --- a/mx/projects Tue Aug 05 10:06:08 2014 +0200 +++ b/mx/projects Wed Aug 06 15:01:16 2014 +0200 @@ -321,7 +321,7 @@ # graal.hotspot.amd64.test project@com.oracle.graal.hotspot.amd64.test@subDir=graal project@com.oracle.graal.hotspot.amd64.test@sourceDirs=src -project@com.oracle.graal.hotspot.amd64.test@dependencies=com.oracle.graal.asm.amd64,com.oracle.graal.compiler.test +project@com.oracle.graal.hotspot.amd64.test@dependencies=com.oracle.graal.asm.amd64,com.oracle.graal.compiler.test,com.oracle.graal.hotspot project@com.oracle.graal.hotspot.amd64.test@checkstyle=com.oracle.graal.graph project@com.oracle.graal.hotspot.amd64.test@javaCompliance=1.8 project@com.oracle.graal.hotspot.amd64.test@workingSets=Graal,HotSpot,AMD64,Test