classLoader.cpp revision 2273
2273N/A * Copyright (c) 1997, 2011, Oracle and/or its affiliates. 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. 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. 1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 0N/A// Entry points in zip.dll for loading zip/jar file entries 0N/A // construct full path name 0N/A // check if file exists 0N/A // found file, open it 0N/A // read contents into resource array 0N/A // construct ClassFileStream 0N/A // enable call to C land 0N/A // check whether zip archive contains name 0N/A // file found, get pointer to class in mmaped jar file. 0N/A // mmaped access not available, perhaps due to compression, 0N/A // read contents into resource array 0N/A// invoke function for each entry in the zip file 0N/A for (
int n = 0; ; n++) {
0N/A // Set up meta index which allows us to open boot jars lazily if 0N/A // class data sharing is enabled 0N/A // Remove trailing newline 0N/A // These directives indicate jar files which contain only 0N/A // classes, only non-classfile resources, or a combination of 0N/A // Hand off current packages to current lazy entry (if any) 0N/A // Find lazy entry corresponding to this jar file 0N/A // If the first character is '@', it indicates the following jar 0N/A // file is a resource only jar file in which case, we should skip 0N/A // reading the subsequent entries since the resource loading is 0N/A // totally handled by J2SE side. 0N/A // Hand off current packages to current lazy entry (if any) 0N/A // Iterate over class path entries 0N/A // Regular file, should be a zip file 0N/A // Canonicalized filename 0N/A // This matches the classic VM 0N/A // enable call to C land 0N/A// Create a class path zip entry for a given path (return NULL if not found 0N/A // check for a regular file 0N/A // enable call to C land 0N/A // create using canonical path 0N/A// returns true if entry already on class path 0N/A // assume zip entries have been canonicalized 0N/A // File or directory found 0N/A // The kernel VM adds dynamically to the end of the classloader path and 0N/A // doesn't reorder the bootclasspath which would break java.lang.Package 0N/A // (see PackageInfo). 0N/A // Add new entry to linked list 0N/A // First make sure native library is loaded 0N/A // Lookup zip entry points 0N/A // ZIP_Close is not exported on Windows in JDK5.0 so don't abort if ZIP_Close is NULL 0N/A // Lookup canonicalize entry in libjava.dll 0N/A // This lookup only works on 1.3. Do not check for non-null here 0N/A// PackageInfo data exists in order to support the java.lang.Package 0N/A// class. A Package object provides information about a java package 0N/A// (version, vendor, etc.) which originates in the manifest of the jar 0N/A// file supplying the package. For application classes, the ClassLoader 0N/A// object takes care of this. 0N/A// For system (boot) classes, the Java code in the Package class needs 0N/A// to be able to identify which source jar file contained the boot 0N/A// class, so that it can extract the manifest from it. This table 0N/A// identifies java packages with jar files in the boot classpath. 0N/A// Because the boot classpath cannot change, the classpath index is 0N/A// sufficient to identify the source jar file or directory. (Since 0N/A// directories have no manifests, the directory name is not required, 0N/A// but is available.) 0N/A// When using sharing -- the pathnames of entries in the boot classpath 0N/A// may not be the same at runtime as they were when the archive was 0N/A// created (NFS, Samba, etc.). The actual files and directories named 0N/A// in the classpath must be the same files, in the same order, even 0N/A// though the exact name is not the same. 0N/A // Copy (relocate) the table to the shared space. 0N/A // Calculate the space needed for the package name strings. 0N/A // Copy the table data (the strings) to the shared space. 0N/A // Package prefix found 0N/A // Bootstrap loader no longer holds system loader lock obj serializing 0N/A // load_instance_class and thereby add_package 0N/A // First check for previously loaded entry 0N/A // Existing entry found, check source of package 0N/A // Package prefix found 0N/A // Insert into hash table 0N/A // Allocate resource char* array containing package names 0N/A // Allocate objArray and fill with java.lang.String 0N/A // st.print() uses too much stack space while handling a StackOverflowError 0N/A // st.print("%s.class", h_name->as_utf8()); 0N/A // Lookup stream for parsing .class file 0N/A // class file found, parse it 0N/A // add to package table 0N/A "bad shared package info size.");
0N/A// Initialize the class loader's access to methods in libzip. Parse and 0N/A// process the boot classpath into a list ClassPathEntry objects. Once 0N/A// this list has been created, it must not change order (see class PackageInfo) 0N/A// it can be appended to and is by jvmti and the kernel vm. 0N/A // jvmstat performance counters 0N/A // The following performance counters are added for measuring the impact 0N/A // of the bug fix of 6365597. They are mainly focused on finding out 0N/A // the behavior of system & user-defined classloader lock, whether 0N/A // Also two additional counters are created to see whether 'UnsyncloadClass' 0N/A // flag is being set or not and how many times load_instance_class call 0N/A // fails with linkageError etc. 0N/A "systemLoaderLockContentionRate");
0N/A "nonSystemLoaderLockContentionRate");
0N/A "jvmFindLoadedClassNoLockCalls");
0N/A "jvmDefineClassNoLockCalls");
0N/A "jniDefineClassNoLockCalls");
0N/A "unsafeDefineClassCalls");
0N/A "loadInstanceClassFailRate");
0N/A // increment the isUnsyncloadClass counter if UnsyncloadClass is set. 0N/A // lookup zip library entry points 0N/A // initialize search path 0N/A // set up meta index which makes boot classpath initialization lazier 0N/A // hardwired for JDK1.2 -- would need to duplicate class file parsing 0N/A // code to determine actual value from file 0N/A // Would be value '11' if finals were in vtable 0N/A // On JDK 1.2.2 the Canonicalize does not exist, so just do nothing 0N/A// Iterates over all class path entries and forces compilation of all methods 0N/A// in all classes found. Currently, only zip/jar archives are searched. 0N/A// The classes are loaded by the Java level bootstrap class loader, and the 0N/A// initializer is called. If DelayCompilationDuringStartup is true (default), 0N/A// the interpreter will run the initialization code. Note that forcing 0N/A// initialization in this way could potentially lead to initialization order 0N/A// problems, in which case we could just force the initialization bit to be set. 0N/A// We need to iterate over the contents of a zip/jar file, so we replicate the 0N/A// jzcell and jzfile definitions from zip_util.h but rename jzfile to real_jzfile, 0N/A// since jzfile already has a void* definition. 0N/A// Note that this is only used in debug mode. 0N/A// HotSpot integration note: 0N/A jint csize;
/* size of compressed data (zero if uncompressed) */ 0N/A jint pos;
/* position of LOC header (if negative) or data */ 0N/A char *
msg;
/* zip error message */ 0N/A unsigned short *
table;
/* Hash chain heads: indexes into entries */ 0N/A /* Information on metadata names in META-INF directory */ 0N/A char **
metanames;
/* array of meta names (may have null names) */ 0N/A /* If there are any per-entry comments, they are in the comments array */ 0N/A jint csize;
/* size of compressed data (zero if uncompressed) */ 0N/A jint pos;
/* position of LOC header (if negative) or data */ 0N/A char *
msg;
/* zip error message */ 0N/A // For now we only compile all methods in all classes in zip/jar files 0N/A// Version that works for JDK 1.3.x 0N/A // Iterate over all entries in zip file 0N/A for (
int n = 0; ; n++) {
0N/A// Version that works for JDK 1.2.x 0N/A // Iterate over all entries in zip file 0N/A for (
int n = 0; ; n++) {
0N/A // Check whether zip name ends in "rt.jar" 0N/A // This will match other archives named rt.jar as well, but this is 0N/A // only used for debugging. 0N/A // Check whether zip name ends in "rt.jar" 0N/A // This will match other archives named rt.jar as well, but this is 0N/A // only used for debugging. 0N/A // Make sure we don't run with background compilation 0N/A // Find bootstrap loader 0N/A // Iterate over all bootstrap class path entries 0N/A // We stop at rt.jar, unless it is the first bootstrap path entry 0N/A // Print statistics as if before normal exit: 0N/A// Filter out all exceptions except OOMs 0N/A // The CHECK at the caller will propagate the exception out 0N/A // We have a .class file 0N/A // If the file has a period after removing .class, it's not really a 0N/A // valid class file. The class loader will check everything else. 0N/A // Construct name without extension 0N/A // Use loader to load and initialize class 0N/A // If something went wrong in preloading we just ignore it 0N/A // If something went wrong (e.g. ExceptionInInitializerError) we skip this class 0N/A // Preload all classes to get around uncommon traps 0N/A // Iterate over all methods in class 0N/A // Give sweeper a chance to keep up with CTW 0N/A // Force compilation 0N/A // Clobber the first compile and force second tier compilation 0N/A // Throw out the code so that the code cache doesn't fill up 0N/A // Throw out the code so that the code cache doesn't fill up 0N/A// Please keep following two functions at end of this file. With them placed at top or in middle of the file, 0N/A// they could get inlined by agressive compiler, an unknown trick, see bug 6966589. 0N/A // increment the event counter 0N/A // stop the current active thread-local timer to measure inclusive time 0N/A // start the inclusive timer if not recursively called 0N/A // start thread-local timer of the given event type 0N/A // stop the thread-local timer as the event completes 0N/A // and resume the thread-local timer of the event next on the stack 0N/A // increment the counters only on the leaf call 0N/A // add all class loading related event selftime to the accumulated time counter