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

Print this page
7001933: Deadlock in java.lang.classloader.getPackage()
   1 /*
   2  * Copyright (c) 1994, 2010, 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


1611                               implTitle, implVersion, implVendor,
1612                               sealBase, this);
1613             packages.put(name, pkg);
1614             return pkg;
1615         }
1616     }
1617 
1618     /**
1619      * Returns a <tt>Package</tt> that has been defined by this class loader
1620      * or any of its ancestors.  </p>
1621      *
1622      * @param  name
1623      *         The package name
1624      *
1625      * @return  The <tt>Package</tt> corresponding to the given name, or
1626      *          <tt>null</tt> if not found
1627      *
1628      * @since  1.2
1629      */
1630     protected Package getPackage(String name) {

1631         synchronized (packages) {
1632             Package pkg = packages.get(name);

1633             if (pkg == null) {
1634                 if (parent != null) {
1635                     pkg = parent.getPackage(name);
1636                 } else {
1637                     pkg = Package.getSystemPackage(name);
1638                 }
1639                 if (pkg != null) {



1640                     packages.put(name, pkg);


1641                 }
1642             }
1643             return pkg;
1644         }
1645     }


1646 
1647     /**
1648      * Returns all of the <tt>Packages</tt> defined by this class loader and
1649      * its ancestors.  </p>
1650      *
1651      * @return  The array of <tt>Package</tt> objects defined by this
1652      *          <tt>ClassLoader</tt>
1653      *
1654      * @since  1.2
1655      */
1656     protected Package[] getPackages() {
1657         Map<String, Package> map;
1658         synchronized (packages) {
1659             map = new HashMap<>(packages);
1660         }
1661         Package[] pkgs;
1662         if (parent != null) {
1663             pkgs = parent.getPackages();
1664         } else {
1665             pkgs = Package.getSystemPackages();


   1 /*
   2  * Copyright (c) 1994, 2011, 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


1611                               implTitle, implVersion, implVendor,
1612                               sealBase, this);
1613             packages.put(name, pkg);
1614             return pkg;
1615         }
1616     }
1617 
1618     /**
1619      * Returns a <tt>Package</tt> that has been defined by this class loader
1620      * or any of its ancestors.  </p>
1621      *
1622      * @param  name
1623      *         The package name
1624      *
1625      * @return  The <tt>Package</tt> corresponding to the given name, or
1626      *          <tt>null</tt> if not found
1627      *
1628      * @since  1.2
1629      */
1630     protected Package getPackage(String name) {
1631         Package pkg;
1632         synchronized (packages) {
1633             pkg = packages.get(name);
1634         }
1635         if (pkg == null) {
1636             if (parent != null) {
1637                 pkg = parent.getPackage(name);
1638             } else {
1639                 pkg = Package.getSystemPackage(name);
1640             }
1641             if (pkg != null) {
1642                 synchronized (packages) {
1643                     Package pkg2 = packages.get(name);
1644                     if (pkg2 == null) {
1645                         packages.put(name, pkg);
1646                     } else {
1647                         pkg = pkg2;
1648                     }
1649                 }

1650             }
1651         }
1652         return pkg;
1653     }
1654 
1655     /**
1656      * Returns all of the <tt>Packages</tt> defined by this class loader and
1657      * its ancestors.  </p>
1658      *
1659      * @return  The array of <tt>Package</tt> objects defined by this
1660      *          <tt>ClassLoader</tt>
1661      *
1662      * @since  1.2
1663      */
1664     protected Package[] getPackages() {
1665         Map<String, Package> map;
1666         synchronized (packages) {
1667             map = new HashMap<>(packages);
1668         }
1669         Package[] pkgs;
1670         if (parent != null) {
1671             pkgs = parent.getPackages();
1672         } else {
1673             pkgs = Package.getSystemPackages();