BasicAMD64Test

Doug Simon doug.simon at oracle.com
Wed May 22 15:12:09 PDT 2013


There is nothing particularly specific to AMD64 in your test as far as I can see. Also, you should never explicitly create AMD64HotSpotGraalRuntime objects. That is done by the C++ part of Graal during VM bootstrap.

I have reworked your test into what I think you ideally want. Place the attached file in graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test and run the following commands to see it in action:

mx build
mx unittest BasicTest

To run it in hosted mode:

mx --vm server build
mx --vm server unittest BasicTest

You should get output like this:

executing junit test now... (com.oracle.graal.compiler.test.BasicTest)
JUnit version 4.8
.Loaded disassembler from /Users/dsimon/linz/basic-graal/jdk1.7.0_17/product/jre/lib/hsdis-amd64.dylib
code generated for testArrayVarSnippet
----------------------------------------------------------------------
com/oracle/graal/compiler/test/BasicTest.testArrayVarSnippet  [0x00000001100cbde0, 0x00000001100cbe28]  576 bytes
[Disassembling for mach='i386:x86-64']
[Entry Point]
[Verified Entry Point]
[Constants]
  # {method}
 {0x000000010fd13060} 'testArrayVarSnippet' '([II)I' in 'com/oracle/graal/compiler/test/BasicTest'
  # parm0:    rsi:rsi   = '[I'
  # parm1:    rdx       = int
  #           [sp+0x20]  (sp of caller)
  0x00000001100cbde0: mov    %rax,-0x14000(%rsp)
  0x00000001100cbde8: sub    $0x18,%rsp
  0x00000001100cbdec: mov    %rbp,0x10(%rsp)    ; OopMap{rsi=Oop off=17}
                                                ;*aload_0
                                                ; - com.oracle.graal.compiler.test.BasicTest::testArrayVarSnippet at 0 (line 47)

  0x00000001100cbdf1: movslq 0x10(%rsi),%rax
  0x00000001100cbdf5: cmp    %edx,%eax
  0x00000001100cbdf7: jbe    0x00000001100cbe0c
  0x00000001100cbdfd: movslq 0x18(%rsi,%rdx,4),%rax
  0x00000001100cbe02: mov    0x10(%rsp),%rbp
  0x00000001100cbe07: add    $0x18,%rsp
  0x00000001100cbe0b: retq   
  0x00000001100cbe0c: movl   $0xffffffe5,0x8(%r15)
  0x00000001100cbe14: callq  0x000000010ffdddf3  ; OopMap{rsi=Oop off=57}
                                                ;*aload_0
                                                ; - com.oracle.graal.compiler.test.BasicTest::testArrayVarSnippet at 0 (line 47

Time: 0.565

OK (1 test)

-Doug

-------------- next part --------------

On May 22, 2013, at 11:20 PM, "Venkatachalam, Vasanth" <Vasanth.Venkatachalam at amd.com> wrote:

> Hi Doug,
> 
> Below is what I have in BasicAMD64Test.java.  The testArray2 example is failing with the error I described.
> 
> package com.oracle.graal.compiler.amd64.test;
> 
> import org.junit.*;
> 
> import static com.oracle.graal.api.code.CodeUtil.*;
> import static com.oracle.graal.hotspot.HotSpotGraalRuntime.*;
> 
> import com.oracle.graal.api.code.*;
> import com.oracle.graal.api.meta.*;
> import com.oracle.graal.api.runtime.*;
> import com.oracle.graal.compiler.*;
> import com.oracle.graal.compiler.amd64.*;
> import com.oracle.graal.compiler.test.*;
> import com.oracle.graal.debug.*;
> import com.oracle.graal.java.*;
> import com.oracle.graal.nodes.*;
> import com.oracle.graal.nodes.type.*;
> import com.oracle.graal.phases.*;
> import com.oracle.graal.phases.PhasePlan.*;
> import com.oracle.graal.amd64.*;
> import com.oracle.graal.hotspot.amd64.*;
> 
> import com.oracle.graal.api.code.CallingConvention.*;
> import com.oracle.graal.api.runtime.Graal;
> import com.oracle.graal.compiler.GraalCompiler;
> import com.oracle.graal.compiler.test.GraalCompilerTest;
> import com.oracle.graal.java.GraphBuilderConfiguration;
> import com.oracle.graal.java.GraphBuilderPhase;
> import com.oracle.graal.nodes.StructuredGraph;
> import com.oracle.graal.nodes.spi.*;
> import com.oracle.graal.phases.OptimisticOptimizations;
> import com.oracle.graal.phases.PhasePlan;
> import com.oracle.graal.phases.PhasePlan.PhasePosition;
> 
> /**
> * Test class for small Java methods compiled to AMD64 kernels.
> */
> public class BasicAMD64Test extends GraalCompilerTest {
> 
> 
> 
>    @Test
>    public void testArray2() {
>        test("testArrayVarSnippet");
>    }
> 
> 
>    public static int testArrayVarSnippet(int[] array, int n) {
>        return array[n];
>    }
> 
>    private CompilationResult test(String snippet) {
>        StructuredGraph graph = parse(snippet);
>        Debug.dump(graph, "Graph");
>        TargetDescription target = new TargetDescription(new AMD64(4, 1), true, 1, 0, true);
>        AMD64HotSpotBackend amd64Backend = new AMD64HotSpotBackend(new AMD64HotSpotGraalRuntime().getRuntime(), target);
>        PhasePlan phasePlan = new PhasePlan();
>        GraphBuilderPhase graphBuilderPhase = new GraphBuilderPhase(runtime, GraphBuilderConfiguration.getDefault(), OptimisticOptimizations.NONE);
>        phasePlan.addPhase(PhasePosition.AFTER_PARSING, graphBuilderPhase);
> 
>        phasePlan.addPhase(PhasePosition.AFTER_PARSING, new AMD64Phase());
>        new AMD64Phase().apply(graph);
>        CallingConvention cc = getCallingConvention(runtime, Type.JavaCallee, graph.method(), false);
>        CompilationResult result = GraalCompiler.compileGraph(graph, cc, graph.method(), runtime, graalRuntime().getReplacements(), amd64Backend, target, null, phasePlan,
>                        OptimisticOptimizations.NONE, new SpeculationLog());
> 
>        DisassemblerProvider dis = Graal.getRuntime().getCapability(DisassemblerProvider.class);
>        /******
>         * if (dis != null) { String disasm = dis.disassemble(result); }
>         **********/
>        if (true) {
>            String disasm = new AMD64HotSpotGraalRuntime().getRuntime().disassemble(result, null);
>            System.out.println("code for snippet " + snippet + " " + disasm);
>        }
>        return result;
>    }
> 
>    private static class AMD64Phase extends Phase {
> 
>        @Override
>        protected void run(StructuredGraph graph) {
>            for (LocalNode local : graph.getNodes(LocalNode.class)) {
>                if (local.kind() == Kind.Object) {
>                    local.setStamp(StampFactory.declaredNonNull(local.objectStamp().type()));
>                }
>            }
>        }
> 
>    }
> 
> }
> 
> -----Original Message-----
> From: Doug Simon [mailto:doug.simon at oracle.com] 
> Sent: Wednesday, May 22, 2013 4:13 PM
> To: Venkatachalam, Vasanth
> Cc: graal-dev at openjdk.java.net
> Subject: Re: BasicAMD64Test
> 
> Hi Vasanth,
> 
> I don't understand how this can be happening. The stack trace you provide implies that HotSpotRuntime.registerReplacements() is never called as otherwise the registration (on line 232) of the linkage for UNCOMMON_TRAP should have occurred.
> 
> How are you running these tests? It doesn't look like you are not using mx because I see that assertions are not enabled.
> 
> It may help if I could see the source code for BasicAMD64Test.java.
> 
> -Doug
> 
> On May 22, 2013, at 10:37 PM, "Venkatachalam, Vasanth" <Vasanth.Venkatachalam at amd.com> wrote:
> 
>> Hi Doug,
>> 
>> After pulling the most recent changes, I get a new error for the same test case. I did not see this error before.
>> 
>> com.oracle.graal.graph.GraalInternalError: java.lang.NullPointerException
>> 	at lir instruction: DEOPT action: InvalidateReprofile reason: BoundsCheckException info [bci:0]
>> 	at com.oracle.graal.lir.LIR.emitOp(LIR.java:172)
>> 	at com.oracle.graal.lir.LIR.emitBlock(LIR.java:161)
>> 	at com.oracle.graal.lir.LIR.emitCode(LIR.java:147)
>> 	at com.oracle.graal.hotspot.amd64.AMD64HotSpotBackend.emitCode(AMD64HotSpotBackend.java:248)
>> 	at com.oracle.graal.compiler.GraalCompiler.emitCode(GraalCompiler.java:228)
>> 	at com.oracle.graal.compiler.GraalCompiler$1$3.run(GraalCompiler.java:88)
>> 	at com.oracle.graal.debug.internal.DebugScope.executeScope(DebugScope.java:179)
>> 	at com.oracle.graal.debug.internal.DebugScope.scope(DebugScope.java:167)
>> 	at com.oracle.graal.debug.Debug.scope(Debug.java:118)
>> 	at com.oracle.graal.debug.Debug.scope(Debug.java:113)
>> 	at com.oracle.graal.compiler.GraalCompiler$1.run(GraalCompiler.java:85)
>> 	at com.oracle.graal.debug.internal.DebugScope.executeScope(DebugScope.java:179)
>> 	at com.oracle.graal.debug.internal.DebugScope.scope(DebugScope.java:167)
>> 	at com.oracle.graal.debug.Debug.scope(Debug.java:118)
>> 	at com.oracle.graal.compiler.GraalCompiler.compileGraph(GraalCompiler.java:69)
>> 	at com.oracle.graal.compiler.amd64.test.BasicAMD64Test.test(BasicAMD64Test.java:257)
>> 	at com.oracle.graal.compiler.amd64.test.BasicAMD64Test.testNBody(BasicAMD64Test.java:149)
>> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>> 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
>> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>> 	at java.lang.reflect.Method.invoke(Method.java:601)
>> 	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
>> 	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
>> 	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
>> 	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
>> 	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
>> 	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
>> 	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
>> 	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
>> 	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
>> 	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
>> 	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
>> 	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
>> 	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
>> 	at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
>> 	at org.junit.runners.Suite.runChild(Suite.java:128)
>> 	at org.junit.runners.Suite.runChild(Suite.java:24)
>> 	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
>> 	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
>> 	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
>> 	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
>> 	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
>> 	at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
>> 	at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
>> 	at org.junit.runner.JUnitCore.run(JUnitCore.java:136)
>> 	at org.junit.runner.JUnitCore.run(JUnitCore.java:117)
>> 	at org.junit.runner.JUnitCore.runMain(JUnitCore.java:98)
>> 	at org.junit.runner.JUnitCore.runMainAndExit(JUnitCore.java:53)
>> 	at org.junit.runner.JUnitCore.main(JUnitCore.java:45)
>> Caused by: java.lang.NullPointerException
>> 	at com.oracle.graal.hotspot.meta.HotSpotRuntime.lookupForeignCall(HotSpotRuntime.java:831)
>> 	at com.oracle.graal.hotspot.meta.HotSpotRuntime.lookupForeignCall(HotSpotRuntime.java:93)
>> 	at com.oracle.graal.hotspot.amd64.AMD64DeoptimizeOp.emitCode(AMD64DeoptimizeOp.java:55)
>> 	at com.oracle.graal.lir.amd64.AMD64LIRInstruction.emitCode(AMD64LIRInstruction.java:36)
>> 	at com.oracle.graal.lir.LIR.emitOp(LIR.java:168)
>> 	... 48 more
>> -----Original Message-----
>> From: Doug Simon [mailto:doug.simon at oracle.com] 
>> Sent: Tuesday, May 21, 2013 11:24 AM
>> To: Venkatachalam, Vasanth
>> Cc: graal-dev at openjdk.java.net
>> Subject: Re: BasicAMD64Test
>> 
>> Hi Vasanth,
>> 
>> On May 21, 2013, at 5:43 PM, "Venkatachalam, Vasanth" <Vasanth.Venkatachalam at amd.com> wrote:
>> 
>>> Hi,
>>> 
>>> The below test case for the AMD64 backend used to work, but after a recent merge it now fails with the error:
>>> 
>>> Java.lang.AssertionError: linkage without and address must be a stub - forgot to register a Stub associated with exceptionHandler(Object,Word) void.
>>> 
>>> Can someone explain what we need to do to get this working again?
>> 
>> Recent changes have removed this assertion. Please let me know if you still get this (or a similar) error after pulling the most recent changes.
>> 
>>> Also is there a way we can get the AMD64 backend to display the disassembled generated code?
>> 
>> What is not working with the (commented out) disassembler call in your attached code?
>> 
>>> Also it would be useful if we could write our test cases in one central location and run them in any backend (AMD64, PTX, HSAIL etc) instead of duplicating them into the test directories for each of the backends.
>> 
>> I assume you are talking about non-backend-specific tests. In that case, can't you just create a project similar to com.oracle.graal.compiler.test or com.oracle.graal.hotspot.test? 
>> 
>> -Doug
>> 
>>> BasicAMD64Test.java
>>> 
>>> public class BasicAMD64Test extends GraalCompilerTest {
>>> 
>>> @Test
>>>  public void testArray2() {
>>>      test("testArrayVarSnippet");
>>>  }
>>> 
>>> public static int testArrayVarSnippet(int[] array, int n) {
>>>      return array[n];
>>>  }
>>> 
>>> private CompilationResult test(String snippet) {
>>>      StructuredGraph graph = parse(snippet);
>>>      Debug.dump(graph, "Graph");
>>>      TargetDescription target = new TargetDescription(new AMD64(4, 1), true, 1, 0, true);
>>>      AMD64HotSpotBackend amd64Backend = new AMD64HotSpotBackend(new AMD64HotSpotGraalRuntime().getRuntime(), target);
>>>      PhasePlan phasePlan = new PhasePlan();
>>>      GraphBuilderPhase graphBuilderPhase = new GraphBuilderPhase(runtime, GraphBuilderConfiguration.getDefault(), OptimisticOptimizations.NONE);
>>>      phasePlan.addPhase(PhasePosition.AFTER_PARSING, graphBuilderPhase);
>>>      phasePlan.addPhase(PhasePosition.AFTER_PARSING, new AMD64Phase());
>>>      new AMD64Phase().apply(graph);
>>>      CallingConvention cc = getCallingConvention(runtime, Type.JavaCallee, graph.method(), false);
>>>      CompilationResult result = GraalCompiler.compileGraph(graph, cc, graph.method(), runtime, graalRuntime().getReplacements(), amd64Backend, target, null, phasePlan,
>>>                      OptimisticOptimizations.NONE, new SpeculationLog());
>>>      DisassemblerProvider dis = Graal.getRuntime().getCapability(DisassemblerProvider.class);
>>>      /******
>>>       * if (dis != null) { String disasm = dis.disassemble(result); }
>>>       **********/
>>>      if (true) {
>>>          String disasm = new AMD64HotSpotGraalRuntime().getRuntime().disassemble(result, null);
>>>          System.out.println("code for snippet " + snippet + " " + disasm);
>>>      }
>>>      return result;
>>>  }
>>> 
>>>  private static class AMD64Phase extends Phase {
>>> 
>>>      @Override
>>>      protected void run(StructuredGraph graph) {
>>>          for (LocalNode local : graph.getNodes(LocalNode.class)) {
>>>              if (local.kind() == Kind.Object) {
>>>                  local.setStamp(StampFactory.declaredNonNull(local.objectStamp().type()));
>>>              }
>>>          }
>>>      }
>>> 
>>>  }
>>> 
>> 
>> 
>> 
> 
> 
> 



More information about the graal-dev mailing list