Skip to content

Commit e105152

Browse files
committed
Pull assembler creation methods in SVM backends to common superclass.
1 parent 660a3b9 commit e105152

File tree

4 files changed

+56
-11
lines changed

4 files changed

+56
-11
lines changed

substratevm/src/com.oracle.svm.core.graal.aarch64/src/com/oracle/svm/core/graal/aarch64/SubstrateAArch64Backend.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
import com.oracle.svm.core.graal.code.AssignedLocation;
5656
import com.oracle.svm.core.graal.code.PatchConsumerFactory;
5757
import com.oracle.svm.core.graal.code.SharedCompilationResult;
58-
import com.oracle.svm.core.graal.code.SubstrateBackend;
58+
import com.oracle.svm.core.graal.code.SubstrateBackendWithAssembler;
5959
import com.oracle.svm.core.graal.code.SubstrateCallingConvention;
6060
import com.oracle.svm.core.graal.code.SubstrateCallingConventionKind;
6161
import com.oracle.svm.core.graal.code.SubstrateCallingConventionType;
@@ -194,7 +194,7 @@
194194
import jdk.vm.ci.meta.ResolvedJavaMethod;
195195
import jdk.vm.ci.meta.Value;
196196

197-
public class SubstrateAArch64Backend extends SubstrateBackend implements LIRGenerationProvider {
197+
public class SubstrateAArch64Backend extends SubstrateBackendWithAssembler<SubstrateAArch64MacroAssembler> implements LIRGenerationProvider {
198198

199199
protected static CompressEncoding getCompressEncoding() {
200200
return ImageSingletons.lookup(CompressEncoding.class);
@@ -1564,4 +1564,9 @@ public LIRGenerationResult newLIRGenerationResult(CompilationIdentifier compilat
15641564
public BasePhase<CoreProviders> newAddressLoweringPhase(CodeCacheProvider codeCache) {
15651565
return new AddressLoweringByUsePhase(new AArch64AddressLoweringByUse(createLirKindTool(), false));
15661566
}
1567+
1568+
@Override
1569+
public SubstrateAArch64MacroAssembler createAssembler(OptionValues options) {
1570+
return new SubstrateAArch64MacroAssembler(getTarget());
1571+
}
15671572
}

substratevm/src/com.oracle.svm.core.graal.amd64/src/com/oracle/svm/core/graal/amd64/SubstrateAMD64Backend.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
import java.util.List;
4848
import java.util.function.BiConsumer;
4949

50-
import org.graalvm.collections.EconomicMap;
5150
import org.graalvm.nativeimage.ImageSingletons;
5251

5352
import com.oracle.svm.core.CPUFeatureAccess;
@@ -67,7 +66,7 @@
6766
import com.oracle.svm.core.graal.code.PatchConsumerFactory;
6867
import com.oracle.svm.core.graal.code.SharedCompilationResult;
6968
import com.oracle.svm.core.graal.code.StubCallingConvention;
70-
import com.oracle.svm.core.graal.code.SubstrateBackend;
69+
import com.oracle.svm.core.graal.code.SubstrateBackendWithAssembler;
7170
import com.oracle.svm.core.graal.code.SubstrateCallingConvention;
7271
import com.oracle.svm.core.graal.code.SubstrateCallingConventionKind;
7372
import com.oracle.svm.core.graal.code.SubstrateCallingConventionType;
@@ -222,7 +221,7 @@
222221
import jdk.vm.ci.meta.ResolvedJavaMethod;
223222
import jdk.vm.ci.meta.Value;
224223

225-
public class SubstrateAMD64Backend extends SubstrateBackend implements LIRGenerationProvider {
224+
public class SubstrateAMD64Backend extends SubstrateBackendWithAssembler<AMD64MacroAssembler> implements LIRGenerationProvider {
226225

227226
protected static CompressEncoding getCompressEncoding() {
228227
return ImageSingletons.lookup(CompressEncoding.class);
@@ -1922,6 +1921,7 @@ public CompilationResultBuilder newCompilationResultBuilder(LIRGenerationResult
19221921
return crb;
19231922
}
19241923

1924+
@Override
19251925
protected AMD64MacroAssembler createAssembler(OptionValues options) {
19261926
return new AMD64MacroAssembler(getTarget(), options, true);
19271927
}
@@ -1961,11 +1961,6 @@ public void emitCode(CompilationResultBuilder crb, ResolvedJavaMethod installedC
19611961
}
19621962
}
19631963

1964-
public AMD64Assembler createAssemblerNoOptions() {
1965-
OptionValues o = new OptionValues(EconomicMap.create());
1966-
return createAssembler(o);
1967-
}
1968-
19691964
protected void resetForEmittingCode(CompilationResultBuilder crb) {
19701965
crb.resetForEmittingCode();
19711966
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright (c) 2025, 2025, 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. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
package com.oracle.svm.core.graal.code;
26+
27+
import org.graalvm.collections.EconomicMap;
28+
29+
import jdk.graal.compiler.asm.Assembler;
30+
import jdk.graal.compiler.options.OptionValues;
31+
import jdk.graal.compiler.phases.util.Providers;
32+
33+
public abstract class SubstrateBackendWithAssembler<A extends Assembler<?>> extends SubstrateBackend {
34+
35+
protected SubstrateBackendWithAssembler(Providers providers) {
36+
super(providers);
37+
}
38+
39+
protected abstract A createAssembler(OptionValues options);
40+
41+
public final A createAssemblerNoOptions() {
42+
OptionValues o = new OptionValues(EconomicMap.create());
43+
return createAssembler(o);
44+
}
45+
}

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/pltgot/amd64/AMD64PLTStubGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public byte[] generatePLT(SharedMethod[] got, SubstrateBackend substrateBackend)
114114
RegisterConfig registerConfig = amd64Backend.getCodeCache().getRegisterConfig();
115115
Register register = configuration.getGOTPassingRegister(registerConfig);
116116

117-
AMD64MacroAssembler asm = (AMD64MacroAssembler) amd64Backend.createAssemblerNoOptions();
117+
AMD64MacroAssembler asm = amd64Backend.createAssemblerNoOptions();
118118
PLTSectionSupport support = HostedPLTGOTConfiguration.singleton().getPLTSectionSupport();
119119

120120
asm.setCodePatchingAnnotationConsumer(this::recordResolverCallForPatching);

0 commit comments

Comments
 (0)