1 /*
2 * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24
25 package org.graalvm.compiler.asm.test;
26
27 import static org.graalvm.compiler.core.common.CompilationRequestIdentifier.asCompilationRequest;
28
29 import java.lang.reflect.Method;
30
31 import org.graalvm.compiler.api.test.Graal;
32 import org.graalvm.compiler.code.CompilationResult;
33 import org.graalvm.compiler.code.DisassemblerProvider;
34 import org.graalvm.compiler.core.common.CompilationIdentifier;
35 import org.graalvm.compiler.core.gen.LIRGenerationProvider;
36 import org.graalvm.compiler.core.target.Backend;
37 import org.graalvm.compiler.debug.DebugContext;
38 import org.graalvm.compiler.nodes.StructuredGraph;
39 import org.graalvm.compiler.options.OptionValues;
40 import org.graalvm.compiler.runtime.RuntimeProvider;
41 import org.graalvm.compiler.serviceprovider.GraalServices;
42 import org.graalvm.compiler.test.GraalTest;
43 import org.junit.Assert;
44
45 import jdk.vm.ci.code.CallingConvention;
46 import jdk.vm.ci.code.CodeCacheProvider;
47 import jdk.vm.ci.code.InstalledCode;
48 import jdk.vm.ci.code.InvalidInstalledCodeException;
49 import jdk.vm.ci.code.RegisterConfig;
50 import jdk.vm.ci.code.TargetDescription;
51 import jdk.vm.ci.meta.MetaAccessProvider;
52 import jdk.vm.ci.meta.ResolvedJavaMethod;
53 import jdk.vm.ci.runtime.JVMCI;
54 import jdk.vm.ci.runtime.JVMCIBackend;
74 public AssemblerTest() {
75 JVMCIBackend providers = JVMCI.getRuntime().getHostJVMCIBackend();
76 this.metaAccess = providers.getMetaAccess();
77 this.codeCache = providers.getCodeCache();
78 this.backend = Graal.getRequiredCapability(RuntimeProvider.class).getHostBackend();
79 }
80
81 public MetaAccessProvider getMetaAccess() {
82 return metaAccess;
83 }
84
85 @SuppressWarnings("try")
86 protected InstalledCode assembleMethod(Method m, CodeGenTest test) {
87 ResolvedJavaMethod method = getMetaAccess().lookupJavaMethod(m);
88 OptionValues options = getInitialOptions();
89 DebugContext debug = getDebugContext(options);
90 try (DebugContext.Scope s = debug.scope("assembleMethod", method, codeCache)) {
91 RegisterConfig registerConfig = codeCache.getRegisterConfig();
92 CompilationIdentifier compilationId = backend.getCompilationIdentifier(method);
93 StructuredGraph graph = new StructuredGraph.Builder(options, debug).method(method).compilationId(compilationId).build();
94 CallingConvention cc = ((LIRGenerationProvider) backend).newLIRGenerationResult(compilationId, null, null, graph, null).getCallingConvention();
95
96 CompilationResult compResult = new CompilationResult(graph.compilationId());
97 byte[] targetCode = test.generateCode(compResult, codeCache.getTarget(), registerConfig, cc);
98 compResult.setTargetCode(targetCode, targetCode.length);
99 compResult.setTotalFrameSize(0);
100 compResult.close();
101
102 InstalledCode code = backend.addInstalledCode(debug, method, asCompilationRequest(compilationId), compResult);
103
104 for (DisassemblerProvider dis : GraalServices.load(DisassemblerProvider.class)) {
105 String disasm1 = dis.disassembleCompiledCode(codeCache, compResult);
106 Assert.assertTrue(compResult.toString(), disasm1 == null || disasm1.length() > 0);
107 String disasm2 = dis.disassembleInstalledCode(codeCache, compResult, code);
108 Assert.assertTrue(code.toString(), disasm2 == null || disasm2.length() > 0);
109 }
110 return code;
111 } catch (Throwable e) {
112 throw debug.handle(e);
113 }
114 }
|
1 /*
2 * Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24
25 package org.graalvm.compiler.asm.test;
26
27 import static org.graalvm.compiler.core.common.CompilationRequestIdentifier.asCompilationRequest;
28
29 import java.lang.reflect.Method;
30
31 import org.graalvm.compiler.api.test.Graal;
32 import org.graalvm.compiler.code.CompilationResult;
33 import org.graalvm.compiler.code.DisassemblerProvider;
34 import org.graalvm.compiler.core.common.CompilationIdentifier;
35 import org.graalvm.compiler.core.common.alloc.RegisterAllocationConfig;
36 import org.graalvm.compiler.core.gen.LIRGenerationProvider;
37 import org.graalvm.compiler.core.target.Backend;
38 import org.graalvm.compiler.debug.DebugContext;
39 import org.graalvm.compiler.nodes.StructuredGraph;
40 import org.graalvm.compiler.options.OptionValues;
41 import org.graalvm.compiler.runtime.RuntimeProvider;
42 import org.graalvm.compiler.serviceprovider.GraalServices;
43 import org.graalvm.compiler.test.GraalTest;
44 import org.junit.Assert;
45
46 import jdk.vm.ci.code.CallingConvention;
47 import jdk.vm.ci.code.CodeCacheProvider;
48 import jdk.vm.ci.code.InstalledCode;
49 import jdk.vm.ci.code.InvalidInstalledCodeException;
50 import jdk.vm.ci.code.RegisterConfig;
51 import jdk.vm.ci.code.TargetDescription;
52 import jdk.vm.ci.meta.MetaAccessProvider;
53 import jdk.vm.ci.meta.ResolvedJavaMethod;
54 import jdk.vm.ci.runtime.JVMCI;
55 import jdk.vm.ci.runtime.JVMCIBackend;
75 public AssemblerTest() {
76 JVMCIBackend providers = JVMCI.getRuntime().getHostJVMCIBackend();
77 this.metaAccess = providers.getMetaAccess();
78 this.codeCache = providers.getCodeCache();
79 this.backend = Graal.getRequiredCapability(RuntimeProvider.class).getHostBackend();
80 }
81
82 public MetaAccessProvider getMetaAccess() {
83 return metaAccess;
84 }
85
86 @SuppressWarnings("try")
87 protected InstalledCode assembleMethod(Method m, CodeGenTest test) {
88 ResolvedJavaMethod method = getMetaAccess().lookupJavaMethod(m);
89 OptionValues options = getInitialOptions();
90 DebugContext debug = getDebugContext(options);
91 try (DebugContext.Scope s = debug.scope("assembleMethod", method, codeCache)) {
92 RegisterConfig registerConfig = codeCache.getRegisterConfig();
93 CompilationIdentifier compilationId = backend.getCompilationIdentifier(method);
94 StructuredGraph graph = new StructuredGraph.Builder(options, debug).method(method).compilationId(compilationId).build();
95 RegisterAllocationConfig registerAllocationConfig = backend.newRegisterAllocationConfig(null, null);
96 CallingConvention cc = ((LIRGenerationProvider) backend).newLIRGenerationResult(compilationId, null, registerAllocationConfig, graph, null).getCallingConvention();
97
98 CompilationResult compResult = new CompilationResult(graph.compilationId());
99 byte[] targetCode = test.generateCode(compResult, codeCache.getTarget(), registerConfig, cc);
100 compResult.setTargetCode(targetCode, targetCode.length);
101 compResult.setTotalFrameSize(0);
102 compResult.close();
103
104 InstalledCode code = backend.addInstalledCode(debug, method, asCompilationRequest(compilationId), compResult);
105
106 for (DisassemblerProvider dis : GraalServices.load(DisassemblerProvider.class)) {
107 String disasm1 = dis.disassembleCompiledCode(codeCache, compResult);
108 Assert.assertTrue(compResult.toString(), disasm1 == null || disasm1.length() > 0);
109 String disasm2 = dis.disassembleInstalledCode(codeCache, compResult, code);
110 Assert.assertTrue(code.toString(), disasm2 == null || disasm2.length() > 0);
111 }
112 return code;
113 } catch (Throwable e) {
114 throw debug.handle(e);
115 }
116 }
|