a Sample for Sparc backend

Christian Thalinger christian.thalinger at oracle.com
Mon Apr 25 18:31:31 UTC 2016


> On Apr 25, 2016, at 8:27 AM, Christian Thalinger <christian.thalinger at oracle.com> wrote:
> 
>> 
>> On Apr 23, 2016, at 8:34 PM, Bahram Yarahmadi <bahram.yarahmadi at gmail.com> wrote:
>> 
>> Hello guys,
>> I want to generate code for different ISAs ( for example SPARC which is
>> currently in graal code base) before migrating to old revisions ( my main
>> target is PTX)

One more thing… GPU architectures are (or can be) treated a little differently.  See:

https://github.com/graalvm/graal-core/blob/master/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java#L106

and

https://github.com/graalvm/graal-core/blob/master/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java#L120

Actually I’m surprised this code was never removed.  Plain oversight, I guess.

>> I have written a very simple program ,that is :
>>  RuntimeProvider runtimeProvider =
>> Graal.getRequiredCapability(RuntimeProvider.class);
>>  Backend backend = runtimeProvider.getBackend(SPARC.class);
>>  Providers providers=backend.getProviders();
>>  MetaAccess   metaAccess = providers.getMetaAccess();
>>  CodeCache  codeCache = providers.getCodeCache();
>>   ResolvedJavaMethod method = findMethod(ScrachTest.class,
>> "AddTwoNumbers"); //ScrachTest.class is a simple class with a method in it
>>   StructuredGraph graph = new StructuredGraph(method,
>> AllowAssumptions.YES);
>>   PhaseSuite<HighTierContext> graphBuilderSuite =
>> backend.getSuites().getDefaultGraphBuilderSuite();
>>       Suites suites = backend.getSuites().getDefaultSuites();
>>       LIRSuites lirSuites = backend.getSuites().getDefaultLIRSuites();
>> 
>>       OptimisticOptimizations optimisticOpts =
>> OptimisticOptimizations.ALL;
>>       ProfilingInfo profilingInfo = graph.getProfilingInfo(method);
>>       CompilationResult compilationResult = new CompilationResult();
>>       CompilationResultBuilderFactory factory =
>> CompilationResultBuilderFactory.Default;
>>        GraalCompiler.compileGraph(graph, method, providers, backend,
>> graphBuilderSuite,
>>        optimisticOpts, profilingInfo, suites, lirSuites,
>> compilationResult, factory);
>>        CompiledCode compiledCode = backend.createCompiledCode(method,
>> compilationResult);
>>       InstalledCode installedCode = codeCache.addCode(method,
>> compiledCode, null, null);
>> When I want to test my program I get these Errors
>> (com.oracle.graal.compiler.test.tutorial.GraalTutorial)
>> java.lang.NullPointerException
>> at
>> com.oracle.graal.compiler.test.tutorial.InvokeGraal.<init>(InvokeGraal.java:76)
>> at
>> com.oracle.graal.compiler.test.tutorial.GraalTutorial.<init>(GraalTutorial.java:65)
>> at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
>> at
>> sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
>> at
>> sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
>> at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
>> at
>> org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:195)
>> at
>> org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:244)
>> 
>> Could you please tell me how can I generate code for different ISAs ?
> 
> The simplest way, which I used when working on the AArch64 port, is to define the os.arch system property:
> 
> -Dos.arch=sparcv9
> 
> That way you can JIT compile methods for a different architecture on, let’s say, x86.  Obviously this will bail out when the JVM wants to install the compiled code in the code cache but it gets you a long way.
> 
>> 
>> Thanks
>> 
>> Regards



More information about the graal-dev mailing list