< prev index next >

src/share/classes/java/lang/ClassLoader.java

Print this page
rev 13708 : 8231584: Deadlock with ClassLoader.findLibrary and System.loadLibrary call
Reviewed-by: mchung

*** 1,7 **** --- 1,8 ---- /* * Copyright (c) 2013, 2015, 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 * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 1465,1474 **** --- 1466,1486 ---- } sclSet = true; } } + /* + * 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) { ClassLoader acl = this; do {
*** 1807,1820 **** // Invoked in the java.lang.Runtime class to implement load and loadLibrary. static void loadLibrary(Class<?> fromClass, String name, 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"); ! } if (isAbsolute) { if (loadLibrary0(fromClass, new File(name))) { return; } throw new UnsatisfiedLinkError("Can't load library: " + name); --- 1819,1831 ---- // Invoked in the java.lang.Runtime class to implement load and loadLibrary. static void loadLibrary(Class<?> fromClass, String name, boolean isAbsolute) { ClassLoader loader = (fromClass == null) ? null : fromClass.getClassLoader(); ! 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; } throw new UnsatisfiedLinkError("Can't load library: " + name);
*** 1900,1916 **** throw new UnsatisfiedLinkError ("Native Library " + name + " already loaded in another classloader"); } ! /* If the library is being loaded (must be by the same thread, ! * because Runtime.load and Runtime.loadLibrary are ! * synchronous). The reason is can occur is that the JNI_OnLoad ! * function can cause another loadLibrary invocation. * ! * Thus we can use a static stack to hold the list of libraries ! * we are loading. * * If there is a pending load operation for the library, we * immediately return success; otherwise, we raise * UnsatisfiedLinkError. */ --- 1911,1928 ---- throw new UnsatisfiedLinkError ("Native Library " + name + " already loaded in another classloader"); } ! /* ! * When a library is being loaded, JNI_OnLoad function can cause ! * another loadLibrary invocation that should succeed. * ! * 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. * * If there is a pending load operation for the library, we * immediately return success; otherwise, we raise * UnsatisfiedLinkError. */
< prev index next >