mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +02:00
8231584: Deadlock with ClassLoader.findLibrary and System.loadLibrary call
Reviewed-by: mchung
This commit is contained in:
parent
725da985e1
commit
4b7bbaf5b0
6 changed files with 243 additions and 9 deletions
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2019, Azul Systems, Inc. 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
|
||||
|
@ -2004,6 +2005,17 @@ public abstract class ClassLoader {
|
|||
return scl;
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize default paths for native libraries search.
|
||||
* Must be done early as JDK may load libraries during bootstrap.
|
||||
*
|
||||
* @see java.lang.System#initPhase1
|
||||
*/
|
||||
static void initLibraryPaths() {
|
||||
usr_paths = initializePath("java.library.path");
|
||||
sys_paths = initializePath("sun.boot.library.path");
|
||||
}
|
||||
|
||||
// Returns true if the specified class loader can be found in this class
|
||||
// loader's delegation chain.
|
||||
boolean isAncestor(ClassLoader cl) {
|
||||
|
@ -2473,8 +2485,7 @@ public abstract class ClassLoader {
|
|||
*
|
||||
* We use a static stack to hold the list of libraries we are
|
||||
* loading because this can happen only when called by the
|
||||
* same thread because Runtime.load and Runtime.loadLibrary
|
||||
* are synchronous.
|
||||
* same thread because this block is synchronous.
|
||||
*
|
||||
* If there is a pending load operation for the library, we
|
||||
* immediately return success; otherwise, we raise
|
||||
|
@ -2619,10 +2630,9 @@ public abstract class ClassLoader {
|
|||
boolean isAbsolute) {
|
||||
ClassLoader loader =
|
||||
(fromClass == null) ? null : fromClass.getClassLoader();
|
||||
if (sys_paths == null) {
|
||||
usr_paths = initializePath("java.library.path");
|
||||
sys_paths = initializePath("sun.boot.library.path");
|
||||
}
|
||||
assert sys_paths != null : "should be initialized at this point";
|
||||
assert usr_paths != null : "should be initialized at this point";
|
||||
|
||||
if (isAbsolute) {
|
||||
if (loadLibrary0(fromClass, new File(name))) {
|
||||
return;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 1995, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2019, Azul Systems, Inc. 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
|
||||
|
@ -732,7 +733,7 @@ public class Runtime {
|
|||
load0(Reflection.getCallerClass(), filename);
|
||||
}
|
||||
|
||||
synchronized void load0(Class<?> fromClass, String filename) {
|
||||
void load0(Class<?> fromClass, String filename) {
|
||||
SecurityManager security = System.getSecurityManager();
|
||||
if (security != null) {
|
||||
security.checkLink(filename);
|
||||
|
@ -794,14 +795,14 @@ public class Runtime {
|
|||
loadLibrary0(Reflection.getCallerClass(), libname);
|
||||
}
|
||||
|
||||
synchronized void loadLibrary0(Class<?> fromClass, String libname) {
|
||||
void loadLibrary0(Class<?> fromClass, String libname) {
|
||||
SecurityManager security = System.getSecurityManager();
|
||||
if (security != null) {
|
||||
security.checkLink(libname);
|
||||
}
|
||||
if (libname.indexOf((int)File.separatorChar) != -1) {
|
||||
throw new UnsatisfiedLinkError(
|
||||
"Directory separator should not appear in library name: " + libname);
|
||||
"Directory separator should not appear in library name: " + libname);
|
||||
}
|
||||
ClassLoader.loadLibrary(fromClass, libname, false);
|
||||
}
|
||||
|
|
|
@ -2045,6 +2045,8 @@ public final class System {
|
|||
// register shared secrets
|
||||
setJavaLangAccess();
|
||||
|
||||
ClassLoader.initLibraryPaths();
|
||||
|
||||
// Subsystems that are invoked during initialization can invoke
|
||||
// VM.isBooted() in order to avoid doing things that should
|
||||
// wait until the VM is fully initialized. The initialization level
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue