MetaIndex.java revision 0
0N/A * Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 0N/A * published by the Free Software Foundation. Sun designates this 0N/A * particular file as subject to the "Classpath" exception as provided 0N/A * by Sun in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 0N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 0N/A * CA 95054 USA or visit www.sun.com if you need additional information or 0N/A * have any questions. 0N/A * MetaIndex is intended to decrease startup time (in particular cold 0N/A * start, when files are not yet in the disk cache) by providing a 0N/A * quick reject mechanism for probes into jar files. The on-disk 0N/A * representation of the meta-index is a flat text file with per-jar 0N/A * entries indicating (generally speaking) prefixes of package names 0N/A * contained in the jar. As an example, here is an edited excerpt of 0N/A * the meta-index generated for jre/lib in the current build: 0N/A * <p> A few notes about the design of the meta-index: 0N/A * <LI> It contains entries for multiple jar files. This is 0N/A * intentional, to reduce the number of disk accesses that need to be 0N/A * performed during startup. 0N/A * <LI> It is only intended to act as a fast reject mechanism to 0N/A * prevent application and other classes from forcing all jar files on 0N/A * the boot and extension class paths to be opened. It is not intended 0N/A * as a precise index of the contents of the jar. 0N/A * <LI> It should be as small as possible to reduce the amount of time 0N/A * required to parse it during startup. For example, adding on the 0N/A * secondary package element to java/ and javax/ packages 0N/A * significantly. This is why substrings of the packages have been 0N/A * chosen as the principal contents. 0N/A * <LI> It is versioned, and optional, to prevent strong dependencies 0N/A * between the JVM and JDK. It is also potentially applicable to more 0N/A * than just the boot and extension class paths. 0N/A * <LI> Precisely speaking, it plays different role in JVM and J2SE 0N/A * side. On the JVM side, meta-index file is used to speed up locating the 0N/A * class files only while on the J2SE side, meta-index file is used to speed 0N/A * up the resources file & class file. 0N/A * To help the JVM and J2SE code to better utilize the information in meta-index 0N/A * file, we mark the jar file differently. Here is the current rule we use. 0N/A * For jar file containing only class file, we put '!' before the jar file name; 0N/A * for jar file containing only resources file, we put '@' before the jar file name; 0N/A * for jar file containing both resources and class file, we put '#' before the 0N/A * Notice the fact that every jar file contains at least the manifest file, so when 0N/A * we say "jar file containing only class file", we don't include that file. 0N/A * <p> To avoid changing the behavior of the current application 0N/A * loader and other loaders, the current MetaIndex implementation in 0N/A * the JDK requires that the directory containing the meta-index be 0N/A * registered with the MetaIndex class before construction of the 0N/A * associated URLClassPath. This prevents the need for automatic 0N/A * searching for the meta-index in the URLClassPath code and potential 0N/A * changes in behavior for non-core ClassLoaders. 0N/A * is used principally by sun.misc.URLClassPath. 0N/A // Maps jar file names in registered directories to meta-indices 0N/A // List of contents of this meta-index 0N/A // Indicate whether the coresponding jar file is a pure class jar file or not 0N/A //---------------------------------------------------------------------- 0N/A // Registration of directories (which can cause parsing of the 0N/A // meta-index file if it is present), and fetching of parsed 0N/A // jarMap is not strictly thread-safe when the meta index mechanism 0N/A // is extended for user-provided jar files in future. 0N/A // 'synchronized' is added to protect the jarMap from being modified 0N/A // by multiple threads. 0N/A // Note that this does not currently check to see whether the 0N/A // directory has previously been registered, since the meta-index 0N/A // in a particular directory creates multiple entries in the 0N/A // jarMap. If this mechanism is extended beyond the boot and 0N/A // extension class paths (for example, automatically searching for 0N/A // meta-index files in directories containing jars which have been 0N/A // explicitly opened) then this code should be generalized. 0N/A // This method must be called from a privileged context. 0N/A /* Convert dir into canonical form. */ 0N/A /* Note: The first line should contain the version of 0N/A * the meta-index file. We have to match the right version 0N/A * before trying to parse this file. */ 0N/A // Store away current contents, if any 0N/A // Fetch new current jar file name 0N/A // Store away current contents, if any 0N/A // Silently fail for now (similar behavior to elsewhere in 0N/A // extension and core loaders) 0N/A //---------------------------------------------------------------------- 0N/A // Ask non-class file from class only jar returns false 0N/A // This check is important to avoid some class only jar 0N/A // files such as rt.jar are opened for resource request. 0N/A //---------------------------------------------------------------------- 0N/A // Implementation only below this point 0N/A // @IllegalArgumentException if entries is null.