8339285: Test fails with assert(depth < max_critical_stack_depth) failed: can't have more than 10 critical frames

Reviewed-by: alanb
This commit is contained in:
Maurizio Cimadamore 2024-09-05 18:11:18 +00:00
parent 48d79431c9
commit 9e1af8cc7c
9 changed files with 241 additions and 41 deletions

View file

@ -2450,7 +2450,8 @@ public abstract class ClassLoader {
* @param javaName the native method's declared name
*/
static long findNative(ClassLoader loader, Class<?> clazz, String entryName, String javaName) {
long addr = findNativeInternal(loader, entryName);
NativeLibraries nativeLibraries = nativeLibrariesFor(loader);
long addr = nativeLibraries.find(entryName);
if (addr != 0 && loader != null) {
Reflection.ensureNativeAccess(clazz, clazz, javaName, true);
}
@ -2462,11 +2463,11 @@ public abstract class ClassLoader {
* to avoid a restricted check, as that check has already been performed when
* obtaining the lookup.
*/
static long findNativeInternal(ClassLoader loader, String entryName) {
static NativeLibraries nativeLibrariesFor(ClassLoader loader) {
if (loader == null) {
return BootLoader.getNativeLibraries().find(entryName);
return BootLoader.getNativeLibraries();
} else {
return loader.libraries.find(entryName);
return loader.libraries;
}
}

View file

@ -70,6 +70,7 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Stream;
import jdk.internal.javac.Restricted;
import jdk.internal.loader.NativeLibraries;
import jdk.internal.logger.LoggerFinderLoader.TemporaryLoggerFinder;
import jdk.internal.misc.Blocker;
import jdk.internal.misc.CarrierThreadLocal;
@ -2662,8 +2663,8 @@ public final class System {
}
@Override
public long findNative(ClassLoader loader, String entry) {
return ClassLoader.findNativeInternal(loader, entry);
public NativeLibraries nativeLibrariesFor(ClassLoader loader) {
return ClassLoader.nativeLibrariesFor(loader);
}
@Override

View file

@ -31,6 +31,7 @@ import jdk.internal.foreign.MemorySessionImpl;
import jdk.internal.foreign.Utils;
import jdk.internal.javac.Restricted;
import jdk.internal.loader.BuiltinClassLoader;
import jdk.internal.loader.NativeLibraries;
import jdk.internal.loader.NativeLibrary;
import jdk.internal.loader.RawNativeLibraries;
import jdk.internal.reflect.CallerSensitive;
@ -256,7 +257,8 @@ public interface SymbolLookup {
if (Utils.containsNullChars(name)) return Optional.empty();
JavaLangAccess javaLangAccess = SharedSecrets.getJavaLangAccess();
// note: ClassLoader::findNative supports a null loader
long addr = javaLangAccess.findNative(loader, name);
NativeLibraries nativeLibraries = javaLangAccess.nativeLibrariesFor(loader);
long addr = nativeLibraries.find(name);
return addr == 0L ?
Optional.empty() :
Optional.of(MemorySegment.ofAddress(addr)

View file

@ -116,6 +116,18 @@ import jdk.internal.misc.Unsafe;
private static native void unload0(long address, long length);
private static native void force0(FileDescriptor fd, long address, long length) throws IOException;
/* Register the natives via the static initializer.
*
* This is required, as these native methods are "scoped methods" (see ScopedMemoryAccess).
* As such, it's better not to end up doing a full JNI lookup while in a scoped method context,
* as that will make the stack trace too deep.
*/
private static native void registerNatives();
static {
registerNatives();
isLoaded0(0, 0, 0);
}
// utility methods
// Returns the distance (in bytes) of the buffer start from the