From 21e1dcce69fc6f6fe65aa3059deabdb71a2e90b9 Mon Sep 17 00:00:00 2001 From: Christian Haeubl Date: Mon, 20 Jan 2025 16:59:51 +0100 Subject: [PATCH] Add RuntimeCodeInfoMemory.contains(...). --- .../svm/core/code/RuntimeCodeInfoMemory.java | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/code/RuntimeCodeInfoMemory.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/code/RuntimeCodeInfoMemory.java index d6227faa5780..8e49517605a0 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/code/RuntimeCodeInfoMemory.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/code/RuntimeCodeInfoMemory.java @@ -26,7 +26,6 @@ import java.util.concurrent.locks.ReentrantLock; -import jdk.graal.compiler.word.Word; import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.Platforms; @@ -47,6 +46,7 @@ import com.oracle.svm.core.util.VMError; import jdk.graal.compiler.api.replacements.Fold; +import jdk.graal.compiler.word.Word; /** * Keeps track of {@link CodeInfo} structures of runtime-compiled methods (including invalidated and @@ -226,6 +226,17 @@ public boolean remove(CodeInfo info) { } } + public boolean contains(CodeInfo info) { + assert !VMOperation.isGCInProgress(); + assert info.isNonNull() : "null"; + lock.lock(); + try { + return contains0(info); + } finally { + lock.unlock(); + } + } + public boolean removeDuringGC(CodeInfo info) { assert VMOperation.isGCInProgress() : "Otherwise, we would need to protect the CodeInfo from the GC."; assert info.isNonNull(); @@ -308,6 +319,21 @@ private boolean remove0(CodeInfo info) { return false; } + @Uninterruptible(reason = "Access hashtable atomically with regard to GC.") + private boolean contains0(CodeInfo info) { + int length = NonmovableArrays.lengthOf(table); + int index = hashIndex(info, length); + UntetheredCodeInfo entry = NonmovableArrays.getWord(table, index); + while (entry.isNonNull()) { + if (entry.equal(info)) { + return true; + } + index = nextIndex(index, length); + entry = NonmovableArrays.getWord(table, index); + } + return false; + } + /** Rehashes possibly-colliding entries after deletion to preserve collision properties. */ @Uninterruptible(reason = "Manipulate hashtable atomically with regard to GC.") private void rehashAfterUnregisterAt(int index) { // from IdentityHashMap: Knuth 6.4 Algorithm R