|
| 1 | +/* |
| 2 | + * Copyright (c) 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 jdk.graal.compiler.hotspot.aarch64.shenandoah; |
| 26 | + |
| 27 | +import jdk.graal.compiler.asm.aarch64.AArch64Address; |
| 28 | +import jdk.graal.compiler.core.aarch64.AArch64LIRGenerator; |
| 29 | +import jdk.graal.compiler.core.common.LIRKind; |
| 30 | +import jdk.graal.compiler.core.common.spi.ForeignCallLinkage; |
| 31 | +import jdk.graal.compiler.hotspot.GraalHotSpotVMConfig; |
| 32 | +import jdk.graal.compiler.hotspot.meta.HotSpotHostForeignCallsProvider; |
| 33 | +import jdk.graal.compiler.hotspot.meta.HotSpotProviders; |
| 34 | +import jdk.graal.compiler.lir.aarch64.AArch64AddressValue; |
| 35 | +import jdk.graal.compiler.lir.gen.LIRGeneratorTool; |
| 36 | +import jdk.graal.compiler.lir.gen.ShenandoahBarrierSetLIRGeneratorTool; |
| 37 | +import jdk.graal.compiler.nodes.gc.shenandoah.ShenandoahLoadRefBarrierNode; |
| 38 | +import jdk.vm.ci.aarch64.AArch64Kind; |
| 39 | +import jdk.vm.ci.meta.AllocatableValue; |
| 40 | +import jdk.vm.ci.meta.PlatformKind; |
| 41 | +import jdk.vm.ci.meta.Value; |
| 42 | + |
| 43 | +/** |
| 44 | + * Lowers Shenandoah barriers to AArch64 LIR. |
| 45 | + */ |
| 46 | +public class AArch64HotSpotShenandoahBarrierSetLIRGenerator implements ShenandoahBarrierSetLIRGeneratorTool { |
| 47 | + public AArch64HotSpotShenandoahBarrierSetLIRGenerator(GraalHotSpotVMConfig config, HotSpotProviders providers) { |
| 48 | + this.config = config; |
| 49 | + this.providers = providers; |
| 50 | + } |
| 51 | + |
| 52 | + private final GraalHotSpotVMConfig config; |
| 53 | + private final HotSpotProviders providers; |
| 54 | + |
| 55 | + private static ForeignCallLinkage getReadBarrierStub(LIRGeneratorTool tool, ShenandoahLoadRefBarrierNode.ReferenceStrength strength, boolean narrow) { |
| 56 | + return switch (strength) { |
| 57 | + case STRONG -> narrow ? tool.getForeignCalls().lookupForeignCall(HotSpotHostForeignCallsProvider.SHENANDOAH_LOAD_BARRIER_NARROW) |
| 58 | + : tool.getForeignCalls().lookupForeignCall(HotSpotHostForeignCallsProvider.SHENANDOAH_LOAD_BARRIER); |
| 59 | + case WEAK -> narrow ? tool.getForeignCalls().lookupForeignCall(HotSpotHostForeignCallsProvider.SHENANDOAH_LOAD_BARRIER_WEAK_NARROW) |
| 60 | + : tool.getForeignCalls().lookupForeignCall(HotSpotHostForeignCallsProvider.SHENANDOAH_LOAD_BARRIER_WEAK); |
| 61 | + case PHANTOM -> narrow ? tool.getForeignCalls().lookupForeignCall(HotSpotHostForeignCallsProvider.SHENANDOAH_LOAD_BARRIER_PHANTOM_NARROW) |
| 62 | + : tool.getForeignCalls().lookupForeignCall(HotSpotHostForeignCallsProvider.SHENANDOAH_LOAD_BARRIER_PHANTOM); |
| 63 | + }; |
| 64 | + } |
| 65 | + |
| 66 | + @Override |
| 67 | + public Value emitLoadReferenceBarrier(LIRGeneratorTool tool, Value obj, Value address, ShenandoahLoadRefBarrierNode.ReferenceStrength strength, boolean narrow, boolean notNull) { |
| 68 | + PlatformKind platformKind = obj.getPlatformKind(); |
| 69 | + LIRKind kind = LIRKind.reference(platformKind); |
| 70 | + Value result = tool.newVariable(tool.toRegisterKind(kind)); |
| 71 | + ForeignCallLinkage callTarget = getReadBarrierStub(tool, strength, narrow); |
| 72 | + AllocatableValue object = tool.asAllocatable(obj); |
| 73 | + AArch64AddressValue loadAddress = ((AArch64LIRGenerator) tool).asAddressValue(address, AArch64Address.ANY_SIZE); |
| 74 | + tool.getResult().getFrameMapBuilder().callsMethod(callTarget.getOutgoingCallingConvention()); |
| 75 | + tool.append(new AArch64HotSpotShenandoahLoadRefBarrierOp(config, providers, tool.asAllocatable(result), object, loadAddress, callTarget, strength, notNull)); |
| 76 | + return result; |
| 77 | + } |
| 78 | + |
| 79 | + @Override |
| 80 | + public void emitPreWriteBarrier(LIRGeneratorTool lirTool, Value address, AllocatableValue expectedObject, boolean nonNull) { |
| 81 | + AllocatableValue temp = lirTool.newVariable(LIRKind.value(AArch64Kind.QWORD)); |
| 82 | + // If the assembly must load the value then it's needs a temporary to store it |
| 83 | + AllocatableValue temp2 = expectedObject.equals(Value.ILLEGAL) ? lirTool.newVariable(LIRKind.value(AArch64Kind.QWORD)) : Value.ILLEGAL; |
| 84 | + |
| 85 | + // Load the address into a register |
| 86 | + AllocatableValue addressValue = lirTool.newVariable(address.getValueKind()); |
| 87 | + lirTool.emitMove(addressValue, address); |
| 88 | + |
| 89 | + ForeignCallLinkage callTarget = lirTool.getForeignCalls().lookupForeignCall(HotSpotHostForeignCallsProvider.SHENANDOAH_WRITE_BARRIER_PRE); |
| 90 | + lirTool.getResult().getFrameMapBuilder().callsMethod(callTarget.getOutgoingCallingConvention()); |
| 91 | + lirTool.append(new AArch64HotSpotShenandoahSATBBarrierOp(config, providers, addressValue, expectedObject, temp, temp2, callTarget, nonNull)); |
| 92 | + } |
| 93 | + |
| 94 | + @Override |
| 95 | + public void emitCardBarrier(LIRGeneratorTool lirTool, Value address) { |
| 96 | + AArch64AddressValue addr = ((AArch64LIRGenerator) lirTool).asAddressValue(address, AArch64Address.ANY_SIZE); |
| 97 | + AllocatableValue tmp = lirTool.newVariable(LIRKind.value(AArch64Kind.QWORD)); |
| 98 | + lirTool.append(new AArch64HotSpotShenandoahCardBarrierOp(config, providers, addr, tmp)); |
| 99 | + } |
| 100 | +} |
0 commit comments