8275703: System.loadLibrary fails on Big Sur for libraries hidden from filesystem

Reviewed-by: dholmes, alanb, mcimadamore
This commit is contained in:
Mandy Chung 2021-10-28 15:27:26 +00:00
parent abe52aea23
commit 309acbf0e8
10 changed files with 199 additions and 32 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2021, 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
@ -27,11 +27,37 @@ package jdk.internal.loader;
import java.io.File;
import java.util.ArrayList;
import sun.security.action.GetPropertyAction;
class ClassLoaderHelper {
private static final boolean hasDynamicLoaderCache;
static {
String osVersion = GetPropertyAction.privilegedGetProperty("os.version");
// dynamic linker cache support on os.version >= 11.x
int major = 11;
int i = osVersion.indexOf('.');
try {
major = Integer.parseInt(i < 0 ? osVersion : osVersion.substring(0, i));
} catch (NumberFormatException e) {}
hasDynamicLoaderCache = major >= 11;
}
private ClassLoaderHelper() {}
/**
* Returns true if loading a native library only if
* it's present on the file system.
*
* @implNote
* On macOS 11.x or later which supports dynamic linker cache,
* the dynamic library is not present on the filesystem. The
* library cannot determine if a dynamic library exists on a
* given path or not and so this method returns false.
*/
static boolean loadLibraryOnlyIfPresent() {
return !hasDynamicLoaderCache;
}
/**
* Returns an alternate path name for the given file
* such that if the original pathname did not exist, then the