load() — netty Function Reference
Architecture documentation for the load() function in NativeLibraryLoader.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD d92afe83_049b_d0b5_f35c_dd5834c38908["load()"] e940cc67_3be6_5ff3_e560_4d68972dc13b["NativeLibraryLoader"] d92afe83_049b_d0b5_f35c_dd5834c38908 -->|defined in| e940cc67_3be6_5ff3_e560_4d68972dc13b 8ea18f7b_b5e3_b0c6_4ce1_356784300e26["loadFirstAvailable()"] 8ea18f7b_b5e3_b0c6_4ce1_356784300e26 -->|calls| d92afe83_049b_d0b5_f35c_dd5834c38908 bafe3f15_b0bf_647a_3a35_cd885f9d3174["loadLibrary()"] d92afe83_049b_d0b5_f35c_dd5834c38908 -->|calls| bafe3f15_b0bf_647a_3a35_cd885f9d3174 de825732_fc04_e1dd_c5ab_9f862f5d6bca["shouldShadedLibraryIdBePatched()"] d92afe83_049b_d0b5_f35c_dd5834c38908 -->|calls| de825732_fc04_e1dd_c5ab_9f862f5d6bca 718b0b6c_05e8_e851_bc3f_0a119eac5245["tryPatchShadedLibraryIdAndSign()"] d92afe83_049b_d0b5_f35c_dd5834c38908 -->|calls| 718b0b6c_05e8_e851_bc3f_0a119eac5245 c99af081_4b91_92aa_6d30_6467f872c8bf["canExecuteExecutable()"] d92afe83_049b_d0b5_f35c_dd5834c38908 -->|calls| c99af081_4b91_92aa_6d30_6467f872c8bf style d92afe83_049b_d0b5_f35c_dd5834c38908 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
common/src/main/java/io/netty/util/internal/NativeLibraryLoader.java lines 160–256
public static void load(String originalName, ClassLoader loader) {
String mangledPackagePrefix = calculateMangledPackagePrefix();
String name = mangledPackagePrefix + originalName;
List<Throwable> suppressed = new ArrayList<>();
try {
// first try to load from java.library.path
loadLibrary(loader, name, false);
return;
} catch (Throwable ex) {
suppressed.add(ex);
}
String libname = System.mapLibraryName(name);
String path = NATIVE_RESOURCE_HOME + libname;
File tmpFile = null;
URL url = getResource(path, loader);
try {
if (url == null) {
if (PlatformDependent.isOsx()) {
String fileName = path.endsWith(".jnilib") ? NATIVE_RESOURCE_HOME + "lib" + name + ".dynlib" :
NATIVE_RESOURCE_HOME + "lib" + name + ".jnilib";
url = getResource(fileName, loader);
if (url == null) {
FileNotFoundException fnf = new FileNotFoundException(fileName);
ThrowableUtil.addSuppressedAndClear(fnf, suppressed);
throw fnf;
}
} else {
FileNotFoundException fnf = new FileNotFoundException(path);
ThrowableUtil.addSuppressedAndClear(fnf, suppressed);
throw fnf;
}
}
int index = libname.lastIndexOf('.');
String prefix = libname.substring(0, index);
String suffix = libname.substring(index);
tmpFile = PlatformDependent.createTempFile(prefix, suffix, WORKDIR);
try (InputStream in = url.openStream();
OutputStream out = new FileOutputStream(tmpFile)) {
byte[] buffer = new byte[8192];
int length;
while ((length = in.read(buffer)) > 0) {
out.write(buffer, 0, length);
}
out.flush();
if (shouldShadedLibraryIdBePatched(mangledPackagePrefix)) {
// Let's try to patch the id and re-sign it. This is a best-effort and might fail if a
// SecurityManager is setup or the right executables are not installed :/
tryPatchShadedLibraryIdAndSign(tmpFile, originalName);
}
}
// Close the output stream before loading the unpacked library,
// because otherwise Windows will refuse to load it when it's in use by other process.
loadLibrary(loader, tmpFile.getPath(), true);
} catch (UnsatisfiedLinkError e) {
try {
if (tmpFile != null && tmpFile.isFile() && tmpFile.canRead() &&
!NoexecVolumeDetector.canExecuteExecutable(tmpFile)) {
// Pass "io.netty.native.workdir" as an argument to allow shading tools to see
// the string. Since this is printed out to users to tell them what to do next,
// we want the value to be correct even when shading.
String message = String.format(
"%s exists but cannot be executed even when execute permissions set; " +
"check volume for \"noexec\" flag; use -D%s=[path] " +
"to set native working directory separately.",
tmpFile.getPath(), "io.netty.native.workdir");
logger.info(message);
suppressed.add(ThrowableUtil.unknownStackTrace(
new UnsatisfiedLinkError(message), NativeLibraryLoader.class, "load"));
}
} catch (Throwable t) {
suppressed.add(t);
logger.debug("Error checking if {} is on a file store mounted with noexec", tmpFile, t);
}
// Re-throw to fail the load
Domain
Subdomains
Calls
Called By
Source
Frequently Asked Questions
What does load() do?
load() is a function in the netty codebase, defined in common/src/main/java/io/netty/util/internal/NativeLibraryLoader.java.
Where is load() defined?
load() is defined in common/src/main/java/io/netty/util/internal/NativeLibraryLoader.java at line 160.
What does load() call?
load() calls 4 function(s): canExecuteExecutable, loadLibrary, shouldShadedLibraryIdBePatched, tryPatchShadedLibraryIdAndSign.
What calls load()?
load() is called by 1 function(s): loadFirstAvailable.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free