Skip to content

Commit

Permalink
Cleanups, simplifications, and small bugfixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
christianhaeubl committed Jan 25, 2024
1 parent 51201ad commit c3ea022
Show file tree
Hide file tree
Showing 40 changed files with 1,169 additions and 1,612 deletions.
1 change: 1 addition & 0 deletions substratevm/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ This changelog summarizes major changes to GraalVM Native Image.
## GraalVM for JDK 23 (Internal Version 24.1.0)
* (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.
* (GR-49996) Ensure explicitly set image name (e.g., via `-o imagename`) is not accidentally overwritten by `-jar jarfile` option.
* (GR-48683) Red Hat added partial support for the JFR event OldObjectSample.

## GraalVM for JDK 22 (Internal Version 24.0.0)
* (GR-48304) Red Hat added support for the JFR event ThreadAllocationStatistics.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

import java.lang.ref.Reference;

import com.oracle.svm.core.heap.Heap;
import org.graalvm.nativeimage.CurrentIsolate;
import org.graalvm.nativeimage.IsolateThread;
import org.graalvm.nativeimage.Platform;
Expand Down Expand Up @@ -228,7 +227,6 @@ assert getCollectionEpoch().equal(data.getRequestingEpoch()) ||
GenScavengeMemoryPoolMXBeans.singleton().notifyAfterCollection();

printGCAfter(cause);
Heap.getHeap().updateUsedAtGC();
JfrGCHeapSummaryEvent.emit(JfrGCWhen.AFTER_GC);

collectionEpoch = collectionEpoch.add(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,6 @@ public UnsignedWord getEdenUsedBytes() {
return edenUsedBytes.get();
}

UnsignedWord getUncheckedYoungUsedBytes() {
return youngUsedBytes.get();
}

@Uninterruptible(reason = "Necessary to return a reasonably consistent value (a GC can change the queried values).")
@SuppressWarnings("static-method")
public UnsignedWord getSurvivorUsedBytes() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ public final class HeapImpl extends Heap {

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

@Platforms(Platform.HOSTED_ONLY.class)
public HeapImpl() {
Expand Down Expand Up @@ -703,17 +702,8 @@ public long getIdentityHashSalt(Object obj) {

@Override
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
public long getUsedAtLastGC() {
return usedAtLastGC;
}

@Override
public void updateUsedAtGC() {
usedAtLastGC = getUncheckedUsedBytes().rawValue();
}

private UnsignedWord getUncheckedUsedBytes() {
return getOldGeneration().getUncheckedChunkBytes().add(getAccounting().getUncheckedYoungUsedBytes()).add(getAccounting().getSurvivorUsedBytes());
public UnsignedWord getUsedMemoryAfterLastGC() {
return accounting.getUsedBytes();
}

private boolean printLocationInfo(Log log, Pointer ptr, boolean allowJavaHeapAccess, boolean allowUnsafeOperations) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,4 @@ AlignedHeapChunk.AlignedHeader requestAlignedChunk() {
RememberedSet.get().enableRememberedSetForChunk(chunk);
return chunk;
}

UnsignedWord getUncheckedChunkBytes() {
UnsignedWord fromBytes = getFromSpace().getUncheckedChunkBytes();
UnsignedWord toBytes = getToSpace().getUncheckedChunkBytes();
return fromBytes.add(toBytes);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -542,11 +542,6 @@ UnsignedWord getAlignedChunkBytes() {
return accounting.getAlignedChunkBytes();
}

@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
UnsignedWord getUncheckedChunkBytes() {
return getAlignedChunkBytes().add(accounting.getUnalignedChunkBytes());
}

UnsignedWord computeObjectBytes() {
assert !isEdenSpace() || areEdenBytesCorrect() : "eden bytes are only accurate during a GC, or at a safepoint after a TLAB flush";
return computeAlignedObjectBytes().add(computeUnalignedObjectBytes());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@
import static com.oracle.svm.core.graal.snippets.SubstrateAllocationSnippets.TLAB_END_IDENTITY;
import static com.oracle.svm.core.graal.snippets.SubstrateAllocationSnippets.TLAB_TOP_IDENTITY;

import jdk.graal.compiler.api.replacements.Fold;
import jdk.graal.compiler.replacements.AllocationSnippets.FillContent;
import jdk.graal.compiler.word.Word;
import com.oracle.svm.core.jfr.HasJfrSupport;
import com.oracle.svm.core.jfr.JfrEvent;
import com.oracle.svm.core.jfr.SubstrateJVM;
import org.graalvm.nativeimage.CurrentIsolate;
import org.graalvm.nativeimage.IsolateThread;
import org.graalvm.nativeimage.Platform;
Expand Down Expand Up @@ -64,7 +58,9 @@
import com.oracle.svm.core.heap.StoredContinuation;
import com.oracle.svm.core.hub.DynamicHub;
import com.oracle.svm.core.hub.LayoutEncoding;
import com.oracle.svm.core.jfr.HasJfrSupport;
import com.oracle.svm.core.jfr.JfrTicks;
import com.oracle.svm.core.jfr.SubstrateJVM;
import com.oracle.svm.core.jfr.events.ObjectAllocationInNewTLABEvent;
import com.oracle.svm.core.log.Log;
import com.oracle.svm.core.snippets.KnownIntrinsics;
Expand All @@ -79,7 +75,9 @@
import com.oracle.svm.core.threadlocal.FastThreadLocalWord;
import com.oracle.svm.core.util.VMError;

import java.lang.ref.WeakReference;
import jdk.graal.compiler.api.replacements.Fold;
import jdk.graal.compiler.replacements.AllocationSnippets.FillContent;
import jdk.graal.compiler.word.Word;

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

UnsignedWord size = LayoutEncoding.getPureInstanceAllocationSize(hub.getLayoutEncoding());
Object result = slowPathNewInstanceWithoutAllocating(hub, size);

runSlowPathHooks();
sampleSlowPathAllocation(result, size, Integer.MIN_VALUE);

sampleSlowPathAllocation(result, size.rawValue(), Integer.MIN_VALUE);
return result;
} finally {
StackOverflowCheck.singleton().protectYellowZone();
Expand Down Expand Up @@ -290,9 +289,10 @@ private static Object slowPathNewArrayLikeObject(Word objectHeader, int length,
}

Object result = slowPathNewArrayLikeObject0(hub, length, size, podReferenceMap);

runSlowPathHooks();
sampleSlowPathAllocation(result, size, length);

sampleSlowPathAllocation(result, size.rawValue(), length);
return result;
} finally {
StackOverflowCheck.singleton().protectYellowZone();
Expand Down Expand Up @@ -538,16 +538,9 @@ private static Descriptor retireCurrentAllocationChunk(IsolateThread thread) {
return tlab;
}

private static boolean sampleSlowPathAllocation(Object obj, long allocatedSize, int arrayLength) {
if (HasJfrSupport.get() && shouldEmitOldObjectSample()) {
// Instantiate weak reference before allocations are forbidden
return SubstrateJVM.getJfrOldObjectProfiler().sample(new WeakReference<>(obj), allocatedSize, arrayLength);
private static void sampleSlowPathAllocation(Object obj, UnsignedWord allocatedSize, int arrayLength) {
if (HasJfrSupport.get()) {
SubstrateJVM.getJfrOldObjectProfiler().sample(obj, allocatedSize, arrayLength);
}
return false;
}

@Uninterruptible(reason = "Prevent races with VM operations that start/stop recording.")
private static boolean shouldEmitOldObjectSample() {
return JfrEvent.OldObjectSample.shouldEmit();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2024, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.oracle.svm.core.collections;

import static com.oracle.svm.core.Uninterruptible.CALLED_FROM_UNINTERRUPTIBLE_CODE;

import com.oracle.svm.core.Uninterruptible;

public interface UninterruptibleComparable {
@Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true)
int compareTo(UninterruptibleComparable other);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* Copyright (c) 2024, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

package com.oracle.svm.core.collections;

import static com.oracle.svm.core.Uninterruptible.CALLED_FROM_UNINTERRUPTIBLE_CODE;

import com.oracle.svm.core.Uninterruptible;
import com.oracle.svm.core.util.VMError;

/** An uninterruptible singly linked list. */
public final class UninterruptibleLinkedList {
private Element head;
private Element tail;

@Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true)
public Element getHead() {
return head;
}

@Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true)
public void append(Element sample) {
assert sample != null;
assert sample.getNext() == null;

if (tail == null || head == null) {
assert tail == head;
tail = sample;
head = sample;
} else {
tail.setNext(sample);
tail = sample;
}
}

@Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true)
public void remove(Element sample) {
assert sample != null;

Element prev = findPrevious(sample);
if (prev == null) {
head = sample.getNext();
} else {
prev.setNext(sample.getNext());
}

if (tail == sample) {
tail = prev;
}
sample.setNext(null);
}

@Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true)
private Element findPrevious(Element sample) {
Element prev = null;
Element cur = head;
while (cur != null) {
if (cur == sample) {
break;
}
prev = cur;
cur = cur.getNext();
}
VMError.guarantee(cur != null, "obj must be in the list");
return prev;
}

@Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true)
public Element pop() {
Element result = head;
if (result != null) {
remove(result);
}
return result;
}

public interface Element {
@Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true)
Element getNext();

@Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true)
void setNext(Element element);
}
}
Loading

0 comments on commit c3ea022

Please sign in to comment.