Skip to content

Commit 8420407

Browse files
Cleanups, simplifications, and small bugfixes.
1 parent 51201ad commit 8420407

40 files changed

+1150
-1659
lines changed

substratevm/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ This changelog summarizes major changes to GraalVM Native Image.
55
## GraalVM for JDK 23 (Internal Version 24.1.0)
66
* (GR-51106) Fields that are accessed via a `VarHandle` or `MethodHandle` are no longer marked as "unsafe accessed" when the `VarHandle`/`MethodHandle` can be fully intrinsified.
77
* (GR-49996) Ensure explicitly set image name (e.g., via `-o imagename`) is not accidentally overwritten by `-jar jarfile` option.
8+
* (GR-48683) Red Hat added partial support for the JFR event OldObjectSample.
89

910
## GraalVM for JDK 22 (Internal Version 24.0.0)
1011
* (GR-48304) Red Hat added support for the JFR event ThreadAllocationStatistics.

substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/GCImpl.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929

3030
import java.lang.ref.Reference;
3131

32-
import com.oracle.svm.core.heap.Heap;
3332
import org.graalvm.nativeimage.CurrentIsolate;
3433
import org.graalvm.nativeimage.IsolateThread;
3534
import org.graalvm.nativeimage.Platform;
@@ -228,7 +227,6 @@ assert getCollectionEpoch().equal(data.getRequestingEpoch()) ||
228227
GenScavengeMemoryPoolMXBeans.singleton().notifyAfterCollection();
229228

230229
printGCAfter(cause);
231-
Heap.getHeap().updateUsedAtGC();
232230
JfrGCHeapSummaryEvent.emit(JfrGCWhen.AFTER_GC);
233231

234232
collectionEpoch = collectionEpoch.add(1);

substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/HeapAccounting.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,6 @@ public UnsignedWord getEdenUsedBytes() {
9595
return edenUsedBytes.get();
9696
}
9797

98-
UnsignedWord getUncheckedYoungUsedBytes() {
99-
return youngUsedBytes.get();
100-
}
101-
10298
@Uninterruptible(reason = "Necessary to return a reasonably consistent value (a GC can change the queried values).")
10399
@SuppressWarnings("static-method")
104100
public UnsignedWord getSurvivorUsedBytes() {

substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/HeapImpl.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ public final class HeapImpl extends Heap {
120120

121121
/** A cached list of all the classes, if someone asks for it. */
122122
private List<Class<?>> classList;
123-
private long usedAtLastGC;
124123

125124
@Platforms(Platform.HOSTED_ONLY.class)
126125
public HeapImpl() {
@@ -703,17 +702,8 @@ public long getIdentityHashSalt(Object obj) {
703702

704703
@Override
705704
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
706-
public long getUsedAtLastGC() {
707-
return usedAtLastGC;
708-
}
709-
710-
@Override
711-
public void updateUsedAtGC() {
712-
usedAtLastGC = getUncheckedUsedBytes().rawValue();
713-
}
714-
715-
private UnsignedWord getUncheckedUsedBytes() {
716-
return getOldGeneration().getUncheckedChunkBytes().add(getAccounting().getUncheckedYoungUsedBytes()).add(getAccounting().getSurvivorUsedBytes());
705+
public UnsignedWord getUsedMemoryAfterLastGC() {
706+
return accounting.getUsedBytes();
717707
}
718708

719709
private boolean printLocationInfo(Log log, Pointer ptr, boolean allowJavaHeapAccess, boolean allowUnsafeOperations) {

substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/OldGeneration.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,4 @@ AlignedHeapChunk.AlignedHeader requestAlignedChunk() {
175175
RememberedSet.get().enableRememberedSetForChunk(chunk);
176176
return chunk;
177177
}
178-
179-
UnsignedWord getUncheckedChunkBytes() {
180-
UnsignedWord fromBytes = getFromSpace().getUncheckedChunkBytes();
181-
UnsignedWord toBytes = getToSpace().getUncheckedChunkBytes();
182-
return fromBytes.add(toBytes);
183-
}
184178
}

substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/Space.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -542,11 +542,6 @@ UnsignedWord getAlignedChunkBytes() {
542542
return accounting.getAlignedChunkBytes();
543543
}
544544

545-
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
546-
UnsignedWord getUncheckedChunkBytes() {
547-
return getAlignedChunkBytes().add(accounting.getUnalignedChunkBytes());
548-
}
549-
550545
UnsignedWord computeObjectBytes() {
551546
assert !isEdenSpace() || areEdenBytesCorrect() : "eden bytes are only accurate during a GC, or at a safepoint after a TLAB flush";
552547
return computeAlignedObjectBytes().add(computeUnalignedObjectBytes());

substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/ThreadLocalAllocation.java

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@
2727
import static com.oracle.svm.core.graal.snippets.SubstrateAllocationSnippets.TLAB_END_IDENTITY;
2828
import static com.oracle.svm.core.graal.snippets.SubstrateAllocationSnippets.TLAB_TOP_IDENTITY;
2929

30-
import jdk.graal.compiler.api.replacements.Fold;
31-
import jdk.graal.compiler.replacements.AllocationSnippets.FillContent;
32-
import jdk.graal.compiler.word.Word;
33-
import com.oracle.svm.core.jfr.HasJfrSupport;
34-
import com.oracle.svm.core.jfr.JfrEvent;
35-
import com.oracle.svm.core.jfr.SubstrateJVM;
3630
import org.graalvm.nativeimage.CurrentIsolate;
3731
import org.graalvm.nativeimage.IsolateThread;
3832
import org.graalvm.nativeimage.Platform;
@@ -64,7 +58,9 @@
6458
import com.oracle.svm.core.heap.StoredContinuation;
6559
import com.oracle.svm.core.hub.DynamicHub;
6660
import com.oracle.svm.core.hub.LayoutEncoding;
61+
import com.oracle.svm.core.jfr.HasJfrSupport;
6762
import com.oracle.svm.core.jfr.JfrTicks;
63+
import com.oracle.svm.core.jfr.SubstrateJVM;
6864
import com.oracle.svm.core.jfr.events.ObjectAllocationInNewTLABEvent;
6965
import com.oracle.svm.core.log.Log;
7066
import com.oracle.svm.core.snippets.KnownIntrinsics;
@@ -79,7 +75,9 @@
7975
import com.oracle.svm.core.threadlocal.FastThreadLocalWord;
8076
import com.oracle.svm.core.util.VMError;
8177

82-
import java.lang.ref.WeakReference;
78+
import jdk.graal.compiler.api.replacements.Fold;
79+
import jdk.graal.compiler.replacements.AllocationSnippets.FillContent;
80+
import jdk.graal.compiler.word.Word;
8381

8482
/**
8583
* Bump-pointer allocation from thread-local top and end Pointers. Many of these methods are called
@@ -225,9 +223,10 @@ private static Object slowPathNewInstance(Word objectHeader) {
225223

226224
UnsignedWord size = LayoutEncoding.getPureInstanceAllocationSize(hub.getLayoutEncoding());
227225
Object result = slowPathNewInstanceWithoutAllocating(hub, size);
226+
228227
runSlowPathHooks();
228+
sampleSlowPathAllocation(result, size, Integer.MIN_VALUE);
229229

230-
sampleSlowPathAllocation(result, size.rawValue(), Integer.MIN_VALUE);
231230
return result;
232231
} finally {
233232
StackOverflowCheck.singleton().protectYellowZone();
@@ -290,9 +289,10 @@ private static Object slowPathNewArrayLikeObject(Word objectHeader, int length,
290289
}
291290

292291
Object result = slowPathNewArrayLikeObject0(hub, length, size, podReferenceMap);
292+
293293
runSlowPathHooks();
294+
sampleSlowPathAllocation(result, size, length);
294295

295-
sampleSlowPathAllocation(result, size.rawValue(), length);
296296
return result;
297297
} finally {
298298
StackOverflowCheck.singleton().protectYellowZone();
@@ -538,16 +538,9 @@ private static Descriptor retireCurrentAllocationChunk(IsolateThread thread) {
538538
return tlab;
539539
}
540540

541-
private static boolean sampleSlowPathAllocation(Object obj, long allocatedSize, int arrayLength) {
542-
if (HasJfrSupport.get() && shouldEmitOldObjectSample()) {
543-
// Instantiate weak reference before allocations are forbidden
544-
return SubstrateJVM.getJfrOldObjectProfiler().sample(new WeakReference<>(obj), allocatedSize, arrayLength);
541+
private static void sampleSlowPathAllocation(Object obj, UnsignedWord allocatedSize, int arrayLength) {
542+
if (HasJfrSupport.get()) {
543+
SubstrateJVM.getJfrOldObjectProfiler().sample(obj, allocatedSize, arrayLength);
545544
}
546-
return false;
547-
}
548-
549-
@Uninterruptible(reason = "Prevent races with VM operations that start/stop recording.")
550-
private static boolean shouldEmitOldObjectSample() {
551-
return JfrEvent.OldObjectSample.shouldEmit();
552545
}
553546
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright (c) 2024, 2024, 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.collections;
26+
27+
import static com.oracle.svm.core.Uninterruptible.CALLED_FROM_UNINTERRUPTIBLE_CODE;
28+
29+
import com.oracle.svm.core.Uninterruptible;
30+
31+
public interface UninterruptibleComparable {
32+
@Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true)
33+
int compareTo(UninterruptibleComparable other);
34+
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*
2+
* Copyright (c) 2024, 2024, 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+
26+
package com.oracle.svm.core.collections;
27+
28+
import static com.oracle.svm.core.Uninterruptible.CALLED_FROM_UNINTERRUPTIBLE_CODE;
29+
30+
import com.oracle.svm.core.Uninterruptible;
31+
import com.oracle.svm.core.util.VMError;
32+
33+
/** An uninterruptible singly linked list. */
34+
public final class UninterruptibleLinkedList {
35+
private Element head;
36+
private Element tail;
37+
38+
@Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true)
39+
public Element getHead() {
40+
return head;
41+
}
42+
43+
@Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true)
44+
public void append(Element sample) {
45+
assert sample != null;
46+
assert sample.getNext() == null;
47+
48+
if (tail == null || head == null) {
49+
assert tail == head;
50+
tail = sample;
51+
head = sample;
52+
} else {
53+
tail.setNext(sample);
54+
tail = sample;
55+
}
56+
}
57+
58+
@Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true)
59+
public void remove(Element sample) {
60+
assert sample != null;
61+
62+
Element prev = findPrevious(sample);
63+
if (prev == null) {
64+
head = sample.getNext();
65+
} else {
66+
prev.setNext(sample.getNext());
67+
}
68+
69+
if (tail == sample) {
70+
tail = prev;
71+
}
72+
sample.setNext(null);
73+
}
74+
75+
@Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true)
76+
private Element findPrevious(Element sample) {
77+
Element prev = null;
78+
Element cur = head;
79+
while (cur != null) {
80+
if (cur == sample) {
81+
break;
82+
}
83+
prev = cur;
84+
cur = cur.getNext();
85+
}
86+
VMError.guarantee(cur != null, "obj must be in the list");
87+
return prev;
88+
}
89+
90+
@Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true)
91+
public Element pop() {
92+
Element result = head;
93+
if (result != null) {
94+
remove(result);
95+
}
96+
return result;
97+
}
98+
99+
public interface Element {
100+
@Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true)
101+
Element getNext();
102+
103+
@Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true)
104+
void setNext(Element element);
105+
}
106+
}

0 commit comments

Comments
 (0)