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