Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/src/java.base/macosx/classes/jdk/internal/loader/ClassLoaderHelper.java
67848 views
1
/*
2
* Copyright (c) 2012, 2022, 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 jdk.internal.loader;
27
28
import java.io.File;
29
import java.util.ArrayList;
30
import sun.security.action.GetPropertyAction;
31
32
class ClassLoaderHelper {
33
private static final boolean hasDynamicLoaderCache;
34
static {
35
String osVersion = GetPropertyAction.privilegedGetProperty("os.version");
36
// dynamic linker cache support on os.version >= 11.x
37
int major = 11;
38
int i = osVersion.indexOf('.');
39
try {
40
major = Integer.parseInt(i < 0 ? osVersion : osVersion.substring(0, i));
41
} catch (NumberFormatException e) {}
42
// SDK 10.15 and earlier always reports 10.16 instead of 11.x.x
43
hasDynamicLoaderCache = major >= 11 || osVersion.equals("10.16");
44
}
45
46
private ClassLoaderHelper() {}
47
48
/**
49
* Returns true if loading a native library only if
50
* it's present on the file system.
51
*
52
* @implNote
53
* On macOS 11.x or later which supports dynamic linker cache,
54
* the dynamic library is not present on the filesystem. The
55
* library cannot determine if a dynamic library exists on a
56
* given path or not and so this method returns false.
57
*/
58
static boolean loadLibraryOnlyIfPresent() {
59
return !hasDynamicLoaderCache;
60
}
61
62
/**
63
* Returns an alternate path name for the given file
64
* such that if the original pathname did not exist, then the
65
* file may be located at the alternate location.
66
* For mac, this replaces the final .dylib suffix with .jnilib
67
*/
68
static File mapAlternativeName(File lib) {
69
String name = lib.toString();
70
int index = name.lastIndexOf('.');
71
if (index < 0) {
72
return null;
73
}
74
return new File(name.substring(0, index) + ".jnilib");
75
}
76
77
/**
78
* Parse a PATH env variable.
79
*
80
* Empty elements will be replaced by dot.
81
*/
82
static String[] parsePath(String ldPath) {
83
char ps = File.pathSeparatorChar;
84
ArrayList<String> paths = new ArrayList<>();
85
int pathStart = 0;
86
int pathEnd;
87
while ((pathEnd = ldPath.indexOf(ps, pathStart)) >= 0) {
88
paths.add((pathStart < pathEnd) ?
89
ldPath.substring(pathStart, pathEnd) : ".");
90
pathStart = pathEnd + 1;
91
}
92
int ldLen = ldPath.length();
93
paths.add((pathStart < ldLen) ?
94
ldPath.substring(pathStart, ldLen) : ".");
95
return paths.toArray(new String[paths.size()]);
96
}
97
}
98
99