< prev index next > src/java.base/share/classes/jdk/internal/loader/NativeLibraries.java
Print this page
/*
- * Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2025, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
if (cached != null) {
return cached;
}
// cannot be loaded by other class loaders
- if (loadedLibraryNames.contains(name)) {
+ if (Holder.loadedLibraryNames.contains(name)) {
throw new UnsatisfiedLinkError("Native Library " + name +
" already loaded in another classloader");
}
/*
}
} finally {
NativeLibraryContext.pop();
}
// register the loaded native library
- loadedLibraryNames.add(name);
+ Holder.loadedLibraryNames.add(name);
libraries.put(name, lib);
return lib;
} finally {
releaseNativeLibraryLock(name);
}
lib = findFromPaths(LibraryPaths.USER_PATHS, fromClass, name);
}
return lib;
}
+ // Called at the end of AOTCache assembly phase.
+ public void clear() {
+ libraries.clear();
+ }
+
private NativeLibrary findFromPaths(String[] paths, Class<?> fromClass, String name) {
for (String path : paths) {
File libfile = new File(path, System.mapLibraryName(name));
NativeLibrary nl = loadLibrary(fromClass, libfile);
if (nl != null) {
@Override
public void run() {
acquireNativeLibraryLock(name);
try {
/* remove the native library name */
- if (!loadedLibraryNames.remove(name)) {
+ if (!Holder.loadedLibraryNames.remove(name)) {
throw new IllegalStateException(name + " has already been unloaded");
}
NativeLibraryContext.push(UNLOADER);
try {
unload(name, isBuiltin, handle);
// The paths searched for libraries
static final String[] SYS_PATHS = ClassLoaderHelper.parsePath(StaticProperty.sunBootLibraryPath());
static final String[] USER_PATHS = ClassLoaderHelper.parsePath(StaticProperty.javaLibraryPath());
}
- // All native libraries we've loaded.
- private static final Set<String> loadedLibraryNames =
+ // Holder has the fields that need to be initialized during JVM bootstrap even if
+ // the outer is aot-initialized.
+ static class Holder {
+ // All native libraries we've loaded.
+ private static final Set<String> loadedLibraryNames =
ConcurrentHashMap.newKeySet();
+ }
// reentrant lock class that allows exact counting (with external synchronization)
@SuppressWarnings("serial")
private static final class CountedLock extends ReentrantLock {
< prev index next >