Skip to content

Commit 1181773

Browse files
author
Thomas Schrott
committed
Add util class for filler objects
1 parent e742187 commit 1181773

File tree

3 files changed

+82
-38
lines changed

3 files changed

+82
-38
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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.genscavenge;
26+
27+
import static com.oracle.svm.core.Uninterruptible.CALLED_FROM_UNINTERRUPTIBLE_CODE;
28+
import static jdk.graal.compiler.replacements.AllocationSnippets.FillContent.WITH_GARBAGE_IF_ASSERTIONS_ENABLED;
29+
30+
import org.graalvm.word.Pointer;
31+
import org.graalvm.word.UnsignedWord;
32+
33+
import com.oracle.svm.core.Uninterruptible;
34+
import com.oracle.svm.core.config.ConfigurationValues;
35+
import com.oracle.svm.core.genscavenge.graal.nodes.FormatArrayNode;
36+
import com.oracle.svm.core.genscavenge.graal.nodes.FormatObjectNode;
37+
import com.oracle.svm.core.heap.FillerArray;
38+
import com.oracle.svm.core.heap.FillerObject;
39+
import com.oracle.svm.core.hub.LayoutEncoding;
40+
import com.oracle.svm.core.util.UnsignedUtils;
41+
42+
import jdk.graal.compiler.api.replacements.Fold;
43+
import jdk.graal.compiler.core.common.NumUtil;
44+
import jdk.graal.compiler.word.Word;
45+
import jdk.vm.ci.meta.JavaKind;
46+
47+
public class FillerObjectUtil {
48+
private static final Class<?> ARRAY_CLASS = FillerArray.class;
49+
private static final JavaKind ARRAY_ELEMENT_KIND = JavaKind.Int;
50+
private static final int ARRAY_ELEMENT_SIZE = ARRAY_ELEMENT_KIND.getByteCount();
51+
52+
@Fold
53+
public static UnsignedWord objectMinSize() {
54+
return Word.unsigned(ConfigurationValues.getObjectLayout().getMinImageHeapObjectSize());
55+
}
56+
57+
@Fold
58+
static int arrayMinSize() {
59+
return NumUtil.safeToInt(ConfigurationValues.getObjectLayout().getArraySize(ARRAY_ELEMENT_KIND, 0, false));
60+
}
61+
62+
@Fold
63+
static int arrayBaseOffset() {
64+
return ConfigurationValues.getObjectLayout().getArrayBaseOffset(ARRAY_ELEMENT_KIND);
65+
}
66+
67+
@Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true)
68+
public static void writeFillerObjectAt(Pointer p, UnsignedWord size) {
69+
assert size.aboveThan(0);
70+
if (size.aboveOrEqual(arrayMinSize())) {
71+
int length = UnsignedUtils.safeToInt(size.subtract(arrayBaseOffset()).unsignedDivide(ARRAY_ELEMENT_SIZE));
72+
FormatArrayNode.formatArray(p, ARRAY_CLASS, length, true, false, WITH_GARBAGE_IF_ASSERTIONS_ENABLED, false);
73+
} else {
74+
FormatObjectNode.formatObject(p, FillerObject.class, true, WITH_GARBAGE_IF_ASSERTIONS_ENABLED, false);
75+
}
76+
assert LayoutEncoding.getSizeFromObjectInGC(p.toObject()).equal(size);
77+
}
78+
}

substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/compacting/SweepingVisitor.java

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -24,67 +24,31 @@
2424
*/
2525
package com.oracle.svm.core.genscavenge.compacting;
2626

27-
import static jdk.graal.compiler.replacements.AllocationSnippets.FillContent.WITH_GARBAGE_IF_ASSERTIONS_ENABLED;
28-
2927
import org.graalvm.word.Pointer;
3028
import org.graalvm.word.UnsignedWord;
3129

32-
import com.oracle.svm.core.config.ConfigurationValues;
3330
import com.oracle.svm.core.genscavenge.AlignedHeapChunk;
31+
import com.oracle.svm.core.genscavenge.FillerObjectUtil;
3432
import com.oracle.svm.core.genscavenge.HeapChunk;
35-
import com.oracle.svm.core.genscavenge.graal.nodes.FormatArrayNode;
36-
import com.oracle.svm.core.genscavenge.graal.nodes.FormatObjectNode;
37-
import com.oracle.svm.core.heap.FillerArray;
38-
import com.oracle.svm.core.heap.FillerObject;
39-
import com.oracle.svm.core.hub.LayoutEncoding;
40-
import com.oracle.svm.core.util.UnsignedUtils;
41-
42-
import jdk.graal.compiler.api.replacements.Fold;
43-
import jdk.graal.compiler.core.common.NumUtil;
44-
import jdk.vm.ci.meta.JavaKind;
4533

4634
/**
4735
* Overwrites dead objects with filler objects so that heap walks or scans that use card tables
4836
* cannot encounter them (and their broken references).
4937
*/
5038
public final class SweepingVisitor implements ObjectMoveInfo.Visitor {
51-
private static final Class<?> ARRAY_CLASS = FillerArray.class;
52-
private static final JavaKind ARRAY_ELEMENT_KIND = JavaKind.Int;
53-
private static final int ARRAY_ELEMENT_SIZE = ARRAY_ELEMENT_KIND.getByteCount();
54-
55-
@Fold
56-
static int arrayMinSize() {
57-
return NumUtil.safeToInt(ConfigurationValues.getObjectLayout().getArraySize(ARRAY_ELEMENT_KIND, 0, false));
58-
}
59-
60-
@Fold
61-
static int arrayBaseOffset() {
62-
return ConfigurationValues.getObjectLayout().getArrayBaseOffset(ARRAY_ELEMENT_KIND);
63-
}
6439

6540
@Override
6641
public boolean visit(Pointer objSeq, UnsignedWord size, Pointer newAddress, Pointer nextObjSeq) {
6742
assert objSeq.equal(newAddress);
6843
if (nextObjSeq.isNonNull()) {
6944
Pointer gapStart = objSeq.add(size);
7045
assert gapStart.belowThan(nextObjSeq);
71-
writeFillerObjectAt(gapStart, nextObjSeq.subtract(gapStart));
46+
FillerObjectUtil.writeFillerObjectAt(gapStart, nextObjSeq.subtract(gapStart));
7247
// Note that we have already added first object table entries for fillers during fixup.
7348
} else {
7449
AlignedHeapChunk.AlignedHeader chunk = AlignedHeapChunk.getEnclosingChunkFromObjectPointer(objSeq);
7550
assert objSeq.add(size).equal(HeapChunk.getTopPointer(chunk));
7651
}
7752
return true;
7853
}
79-
80-
private static void writeFillerObjectAt(Pointer p, UnsignedWord size) {
81-
assert size.aboveThan(0);
82-
if (size.aboveOrEqual(arrayMinSize())) {
83-
int length = UnsignedUtils.safeToInt(size.subtract(arrayBaseOffset()).unsignedDivide(ARRAY_ELEMENT_SIZE));
84-
FormatArrayNode.formatArray(p, ARRAY_CLASS, length, true, false, WITH_GARBAGE_IF_ASSERTIONS_ENABLED, false);
85-
} else {
86-
FormatObjectNode.formatObject(p, FillerObject.class, true, WITH_GARBAGE_IF_ASSERTIONS_ENABLED, false);
87-
}
88-
assert LayoutEncoding.getSizeFromObjectInGC(p.toObject()).equal(size);
89-
}
9054
}

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/config/ObjectLayout.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import com.oracle.svm.core.util.VMError;
4545

4646
import jdk.graal.compiler.api.directives.GraalDirectives;
47+
import jdk.graal.compiler.api.replacements.Fold;
4748
import jdk.graal.compiler.core.common.NumUtil;
4849
import jdk.graal.compiler.replacements.ReplacementsUtil;
4950
import jdk.vm.ci.code.CodeUtil;
@@ -305,6 +306,7 @@ public int getMinImageHeapArraySize() {
305306
return NumUtil.safeToInt(getArraySize(JavaKind.Byte, 0, true));
306307
}
307308

309+
@Fold
308310
public int getMinImageHeapObjectSize() {
309311
return Math.min(getMinImageHeapArraySize(), getMinImageHeapInstanceSize());
310312
}

0 commit comments

Comments
 (0)