Skip to content

Commit dcaafee

Browse files
committed
Shenandoah support
1 parent fdf09e0 commit dcaafee

36 files changed

+2819
-12
lines changed

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/core/phases/EconomyLowTier.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import jdk.graal.compiler.debug.Assertions;
2828
import jdk.graal.compiler.graph.Graph;
29+
import jdk.graal.compiler.nodes.GraphState;
2930
import jdk.graal.compiler.options.OptionValues;
3031
import jdk.graal.compiler.phases.PlaceholderPhase;
3132
import jdk.graal.compiler.phases.common.AddressLoweringPhase;
@@ -36,6 +37,7 @@
3637
import jdk.graal.compiler.phases.common.LowTierLoweringPhase;
3738
import jdk.graal.compiler.phases.common.RemoveOpaqueValuePhase;
3839
import jdk.graal.compiler.phases.common.TransplantGraphsPhase;
40+
import jdk.graal.compiler.phases.common.WriteBarrierAdditionPhase;
3941
import jdk.graal.compiler.phases.schedule.SchedulePhase;
4042
import jdk.graal.compiler.phases.tiers.LowTierContext;
4143

@@ -50,6 +52,8 @@ public EconomyLowTier(OptionValues options) {
5052
appendPhase(new LowTierLoweringPhase(canonicalizer));
5153
appendPhase(new ExpandLogicPhase(canonicalizer));
5254

55+
appendPhase(new WriteBarrierAdditionPhase(GraphState.StageFlag.LOW_TIER_BARRIER_ADDITION));
56+
5357
if (Assertions.assertionsEnabled()) {
5458
appendPhase(new BarrierSetVerificationPhase());
5559
}

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/core/phases/LowTier.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import jdk.graal.compiler.core.common.GraalOptions;
3030
import jdk.graal.compiler.graph.Graph;
31+
import jdk.graal.compiler.nodes.GraphState;
3132
import jdk.graal.compiler.options.Option;
3233
import jdk.graal.compiler.options.OptionKey;
3334
import jdk.graal.compiler.options.OptionType;
@@ -47,6 +48,7 @@
4748
import jdk.graal.compiler.phases.common.PropagateDeoptimizeProbabilityPhase;
4849
import jdk.graal.compiler.phases.common.RemoveOpaqueValuePhase;
4950
import jdk.graal.compiler.phases.common.TransplantGraphsPhase;
51+
import jdk.graal.compiler.phases.common.WriteBarrierAdditionPhase;
5052
import jdk.graal.compiler.phases.schedule.SchedulePhase;
5153
import jdk.graal.compiler.phases.schedule.SchedulePhase.SchedulingStrategy;
5254
import jdk.graal.compiler.phases.tiers.LowTierContext;
@@ -87,6 +89,8 @@ public LowTier(OptionValues options) {
8789
appendPhase(new FixReadsPhase(true,
8890
new SchedulePhase(GraalOptions.StressTestEarlyReads.getValue(options) ? SchedulingStrategy.EARLIEST : SchedulingStrategy.LATEST_OUT_OF_LOOPS_IMPLICIT_NULL_CHECKS)));
8991

92+
appendPhase(new WriteBarrierAdditionPhase(GraphState.StageFlag.LOW_TIER_BARRIER_ADDITION));
93+
9094
appendPhase(canonicalizerWithoutGVN);
9195

9296
/*

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/GraalHotSpotVMConfig.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,44 @@ private long getZGCAddressField(String name) {
619619
public final long zBarrierSetRuntimeLoadBarrierOnOopArray = getZGCAddressField("ZBarrierSetRuntime::load_barrier_on_oop_array");
620620
public final int zPointerLoadShift = getConstant("ZPointerLoadShift", Integer.class, -1, osArch.equals("aarch64"));
621621

622+
/*
623+
* Shenandoah GC support.
624+
*/
625+
/**
626+
* Indicates whether or not the HotSpot VM has been built with Shenandoah support. If not, then
627+
* we don't expect the Shenandoah symbols to be present in JVMCI.
628+
*/
629+
public final boolean hasShenandoahGC = getStore().getConstants().containsKey("INCLUDE_SHENANDOAHGC") && getConstant("INCLUDE_SHENANDOAHGC", Boolean.class);
630+
631+
/*
632+
* Various Shenandoah GC constants.
633+
*/
634+
public final int shenandoahGCStateOffset = getConstant("ShenandoahThreadLocalData::gc_state_offset", Integer.class, -1, hasShenandoahGC);
635+
public final int shenandoahSATBIndexOffset = getConstant("ShenandoahThreadLocalData::satb_mark_queue_index_offset", Integer.class, -1, hasShenandoahGC);
636+
public final int shenandoahSATBBufferOffset = getConstant("ShenandoahThreadLocalData::satb_mark_queue_buffer_offset", Integer.class, -1, hasShenandoahGC);
637+
public final int shenandoahCardTableOffset = getConstant("ShenandoahThreadLocalData::card_table_offset", Integer.class, -1, hasShenandoahGC);
638+
public final int shenandoahGCRegionSizeBytesShift = getFieldValue("CompilerToVM::Data::shenandoah_region_size_bytes_shift", Integer.class, "int", -1, hasShenandoahGC);
639+
public final long shenandoahGCCSetFastTestAddress = getFieldValue("CompilerToVM::Data::shenandoah_in_cset_fast_test_addr", Long.class, "address", -1L, hasShenandoahGC);
640+
641+
public final int shenandoahGCStateHasForwarded = getConstant("ShenandoahHeap::HAS_FORWARDED", Integer.class, -1, hasShenandoahGC);
642+
public final int shenandoahGCStateMarking = getConstant("ShenandoahHeap::MARKING", Integer.class, -1, hasShenandoahGC);
643+
public final int shenandoahGCStateEvacuation = getConstant("ShenandoahHeap::EVACUATION", Integer.class, -1, hasShenandoahGC);
644+
public final int shenandoahGCStateUpdateRefs = getConstant("ShenandoahHeap::UPDATE_REFS", Integer.class, -1, hasShenandoahGC);
645+
public final int shenandoahGCStateWeakRoots = getConstant("ShenandoahHeap::WEAK_ROOTS", Integer.class, -1, hasShenandoahGC);
646+
public final int shenandoahGCStateYoungMarking = getConstant("ShenandoahHeap::YOUNG_MARKING", Integer.class, -1, hasShenandoahGC);
647+
public final int shenandoahGCStateOldMarking = getConstant("ShenandoahHeap::OLD_MARKING", Integer.class, -1, hasShenandoahGC);
648+
649+
/*
650+
* Shenandoah barrier slow-paths.
651+
*/
652+
public final long shenandoahLoadBarrierStrong = getAddress("ShenandoahRuntime::load_reference_barrier_strong", -1L, hasShenandoahGC);
653+
public final long shenandoahLoadBarrierStrongNarrow = getAddress("ShenandoahRuntime::load_reference_barrier_strong_narrow", -1L, hasShenandoahGC);
654+
public final long shenandoahLoadBarrierWeak = getAddress("ShenandoahRuntime::load_reference_barrier_weak", -1L, hasShenandoahGC);
655+
public final long shenandoahLoadBarrierWeakNarrow = getAddress("ShenandoahRuntime::load_reference_barrier_weak_narrow", -1L, hasShenandoahGC);
656+
public final long shenandoahLoadBarrierPhantom = getAddress("ShenandoahRuntime::load_reference_barrier_phantom", -1L, hasShenandoahGC);
657+
public final long shenandoahLoadBarrierPhantomNarrow = getAddress("ShenandoahRuntime::load_reference_barrier_phantom_narrow", -1L, hasShenandoahGC);
658+
public final long shenandoahWriteBarrierPre = getAddress("ShenandoahRuntime::write_barrier_pre", -1L, hasShenandoahGC);
659+
622660
// aarch64 specific nmethod entry barrier support
623661
// @formatter:off
624662
public final int BarrierSetAssembler_nmethod_patching_type = getFieldValue("CompilerToVM::Data::BarrierSetAssembler_nmethod_patching_type", Integer.class, "int", -1, osArch.equals("aarch64"));

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/HotSpotBackendFactory.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ private BarrierSet createBarrierSet(GraalHotSpotVMConfig config, MetaAccessProvi
259259
ResolvedJavaField referentField = HotSpotReplacementsUtil.referentField(metaAccess);
260260
if (config.gc == HotSpotGraalRuntime.HotSpotGC.Z) {
261261
return new HotSpotZBarrierSet(objectArrayType, referentField);
262+
} else if (config.gc == HotSpotGraalRuntime.HotSpotGC.Shenandoah) {
263+
return new HotSpotShenandoahBarrierSet(objectArrayType, referentField, config);
262264
} else if (config.gc == HotSpotGraalRuntime.HotSpotGC.Epsilon) {
263265
return new NoBarrierSet();
264266
} else if (config.useG1GC()) {

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/HotSpotGraalRuntime.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,7 @@ public enum HotSpotGC {
209209
G1("UseG1GC"),
210210
Z(true, true, flagIsSet("UseZGC")),
211211
Epsilon(true, true, flagIsSet("UseEpsilonGC")),
212-
213-
// Unsupported GCs
214-
Shenandoah(false, true, flagIsSet("UseShenandoahGC"));
212+
Shenandoah(true, true, flagIsSet("UseShenandoahGC"));
215213

216214
HotSpotGC(String flag) {
217215
this(true, true, flagIsSet(flag));
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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;
26+
27+
import jdk.graal.compiler.core.common.CompressEncoding;
28+
import jdk.graal.compiler.debug.GraalError;
29+
import jdk.graal.compiler.hotspot.nodes.HotSpotCompressionNode;
30+
import org.graalvm.word.LocationIdentity;
31+
32+
import jdk.graal.compiler.core.common.memory.BarrierType;
33+
import jdk.graal.compiler.core.common.type.AbstractObjectStamp;
34+
import jdk.graal.compiler.core.common.type.Stamp;
35+
import jdk.graal.compiler.hotspot.replacements.HotSpotReplacementsUtil;
36+
import jdk.graal.compiler.nodes.ValueNode;
37+
import jdk.graal.compiler.nodes.gc.shenandoah.ShenandoahBarrierSet;
38+
import jdk.vm.ci.meta.JavaKind;
39+
import jdk.vm.ci.meta.ResolvedJavaField;
40+
import jdk.vm.ci.meta.ResolvedJavaType;
41+
42+
/**
43+
* Specialization of {@link ShenandoahBarrierSet} that adds support for read barriers on handle
44+
* locations and compressed references.
45+
*/
46+
public class HotSpotShenandoahBarrierSet extends ShenandoahBarrierSet {
47+
private final CompressEncoding oopEncoding;
48+
49+
public HotSpotShenandoahBarrierSet(ResolvedJavaType objectArrayType, ResolvedJavaField referentField, GraalHotSpotVMConfig config) {
50+
super(objectArrayType, referentField);
51+
this.oopEncoding = config.getOopEncoding();
52+
this.useLoadRefBarrier = config.getFlag("ShenandoahLoadRefBarrier", Boolean.class);
53+
this.useSATBBarrier = config.getFlag("ShenandoahSATBBarrier", Boolean.class);
54+
this.useCASBarrier = config.getFlag("ShenandoahCASBarrier", Boolean.class);
55+
this.useCardBarrier = config.getFlag("ShenandoahCardBarrier", Boolean.class);
56+
}
57+
58+
@Override
59+
protected BarrierType barrierForLocation(BarrierType currentBarrier, LocationIdentity location, JavaKind storageKind) {
60+
if (location instanceof HotSpotReplacementsUtil.OopHandleLocationIdentity) {
61+
return BarrierType.READ;
62+
}
63+
return super.barrierForLocation(currentBarrier, location, storageKind);
64+
}
65+
66+
@Override
67+
public BarrierType readBarrierType(LocationIdentity location, ValueNode address, Stamp loadStamp) {
68+
if (location instanceof HotSpotReplacementsUtil.OopHandleLocationIdentity) {
69+
GraalError.guarantee(loadStamp instanceof AbstractObjectStamp, "expect object, got: %s", loadStamp);
70+
return BarrierType.READ;
71+
}
72+
return super.readBarrierType(location, address, loadStamp);
73+
}
74+
75+
@Override
76+
public BarrierType writeBarrierType(LocationIdentity location) {
77+
if (location instanceof HotSpotReplacementsUtil.OopHandleLocationIdentity) {
78+
return BarrierType.FIELD;
79+
}
80+
return BarrierType.NONE;
81+
}
82+
83+
@Override
84+
protected ValueNode maybeUncompressReference(ValueNode value, boolean narrow) {
85+
if (value != null && narrow) {
86+
return HotSpotCompressionNode.uncompressWithoutUnique(value.graph(), value, oopEncoding);
87+
}
88+
return value;
89+
}
90+
91+
@Override
92+
protected ValueNode maybeCompressReference(ValueNode value, boolean narrow) {
93+
if (value != null && narrow) {
94+
return HotSpotCompressionNode.compressWithoutUnique(value.graph(), value, oopEncoding);
95+
}
96+
return value;
97+
}
98+
}

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/aarch64/AArch64HotSpotLIRGenerator.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
import jdk.graal.compiler.hotspot.HotSpotLIRGenerator;
6363
import jdk.graal.compiler.hotspot.HotSpotLockStack;
6464
import jdk.graal.compiler.hotspot.aarch64.g1.AArch64HotSpotG1BarrierSetLIRTool;
65+
import jdk.graal.compiler.hotspot.aarch64.shenandoah.AArch64HotSpotShenandoahBarrierSetLIRGenerator;
6566
import jdk.graal.compiler.hotspot.aarch64.z.AArch64HotSpotZBarrierSetLIRGenerator;
6667
import jdk.graal.compiler.hotspot.debug.BenchmarkCounters;
6768
import jdk.graal.compiler.hotspot.meta.HotSpotProviders;
@@ -119,6 +120,9 @@ protected static BarrierSetLIRGeneratorTool getBarrierSet(GraalHotSpotVMConfig c
119120
if (config.gc == HotSpotGraalRuntime.HotSpotGC.Z) {
120121
return new AArch64HotSpotZBarrierSetLIRGenerator(config, providers);
121122
}
123+
if (config.gc == HotSpotGraalRuntime.HotSpotGC.Shenandoah) {
124+
return new AArch64HotSpotShenandoahBarrierSetLIRGenerator(config, providers);
125+
}
122126
return null;
123127
}
124128

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/aarch64/AArch64HotSpotMove.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ public void emitCode(CompilationResultBuilder crb, AArch64MacroAssembler masm) {
112112
Register resultRegister = asRegister(result);
113113
Register ptr = asRegister(input);
114114
Register base = (isRegister(baseRegister) ? asRegister(baseRegister) : zr);
115+
emitCompressCode(masm, ptr, resultRegister, base, encoding, nonNull);
116+
}
117+
118+
public static void emitCompressCode(AArch64MacroAssembler masm, Register ptr, Register resultRegister, Register base, CompressEncoding encoding, boolean nonNull) {
115119
// result = (ptr - base) >> shift
116120
if (!encoding.hasBase()) {
117121
if (encoding.hasShift()) {

0 commit comments

Comments
 (0)