0N/A/*
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 *
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 *
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 *
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 *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#include "precompiled.hpp"
1879N/A#include "classfile/classFileParser.hpp"
1879N/A#include "classfile/classFileStream.hpp"
1879N/A#include "classfile/classLoader.hpp"
1879N/A#include "classfile/javaClasses.hpp"
1879N/A#include "classfile/systemDictionary.hpp"
1879N/A#include "classfile/vmSymbols.hpp"
1879N/A#include "compiler/compileBroker.hpp"
1879N/A#include "gc_interface/collectedHeap.inline.hpp"
1879N/A#include "interpreter/bytecodeStream.hpp"
1879N/A#include "interpreter/oopMapCache.hpp"
1879N/A#include "memory/allocation.inline.hpp"
1879N/A#include "memory/generation.hpp"
1879N/A#include "memory/oopFactory.hpp"
1879N/A#include "memory/universe.inline.hpp"
1879N/A#include "oops/constantPoolKlass.hpp"
1879N/A#include "oops/instanceKlass.hpp"
1879N/A#include "oops/instanceRefKlass.hpp"
1879N/A#include "oops/oop.inline.hpp"
2062N/A#include "oops/symbol.hpp"
1879N/A#include "prims/jvm_misc.hpp"
1879N/A#include "runtime/arguments.hpp"
1879N/A#include "runtime/compilationPolicy.hpp"
1879N/A#include "runtime/fprofiler.hpp"
1879N/A#include "runtime/handles.hpp"
1879N/A#include "runtime/handles.inline.hpp"
1879N/A#include "runtime/init.hpp"
1879N/A#include "runtime/interfaceSupport.hpp"
1879N/A#include "runtime/java.hpp"
1879N/A#include "runtime/javaCalls.hpp"
1879N/A#include "runtime/threadCritical.hpp"
1879N/A#include "runtime/timer.hpp"
1879N/A#include "services/management.hpp"
1879N/A#include "services/threadService.hpp"
1879N/A#include "utilities/events.hpp"
1879N/A#include "utilities/hashtable.hpp"
1879N/A#include "utilities/hashtable.inline.hpp"
1879N/A#ifdef TARGET_OS_FAMILY_linux
1879N/A# include "os_linux.inline.hpp"
1879N/A#endif
1879N/A#ifdef TARGET_OS_FAMILY_solaris
1879N/A# include "os_solaris.inline.hpp"
1879N/A#endif
1879N/A#ifdef TARGET_OS_FAMILY_windows
1879N/A# include "os_windows.inline.hpp"
1879N/A#endif
2796N/A#ifdef TARGET_OS_FAMILY_bsd
2796N/A# include "os_bsd.inline.hpp"
2796N/A#endif
0N/A
0N/A
0N/A// Entry points in zip.dll for loading zip/jar file entries
0N/A
0N/Atypedef void * * (JNICALL *ZipOpen_t)(const char *name, char **pmsg);
0N/Atypedef void (JNICALL *ZipClose_t)(jzfile *zip);
0N/Atypedef jzentry* (JNICALL *FindEntry_t)(jzfile *zip, const char *name, jint *sizeP, jint *nameLen);
0N/Atypedef jboolean (JNICALL *ReadEntry_t)(jzfile *zip, jzentry *entry, unsigned char *buf, char *namebuf);
0N/Atypedef jboolean (JNICALL *ReadMappedEntry_t)(jzfile *zip, jzentry *entry, unsigned char **buf, char *namebuf);
0N/Atypedef jzentry* (JNICALL *GetNextEntry_t)(jzfile *zip, jint n);
0N/A
0N/Astatic ZipOpen_t ZipOpen = NULL;
0N/Astatic ZipClose_t ZipClose = NULL;
0N/Astatic FindEntry_t FindEntry = NULL;
0N/Astatic ReadEntry_t ReadEntry = NULL;
0N/Astatic ReadMappedEntry_t ReadMappedEntry = NULL;
0N/Astatic GetNextEntry_t GetNextEntry = NULL;
0N/Astatic canonicalize_fn_t CanonicalizeEntry = NULL;
0N/A
0N/A// Globals
0N/A
0N/APerfCounter* ClassLoader::_perf_accumulated_time = NULL;
0N/APerfCounter* ClassLoader::_perf_classes_inited = NULL;
0N/APerfCounter* ClassLoader::_perf_class_init_time = NULL;
875N/APerfCounter* ClassLoader::_perf_class_init_selftime = NULL;
875N/APerfCounter* ClassLoader::_perf_classes_verified = NULL;
0N/APerfCounter* ClassLoader::_perf_class_verify_time = NULL;
875N/APerfCounter* ClassLoader::_perf_class_verify_selftime = NULL;
0N/APerfCounter* ClassLoader::_perf_classes_linked = NULL;
0N/APerfCounter* ClassLoader::_perf_class_link_time = NULL;
875N/APerfCounter* ClassLoader::_perf_class_link_selftime = NULL;
875N/APerfCounter* ClassLoader::_perf_class_parse_time = NULL;
875N/APerfCounter* ClassLoader::_perf_class_parse_selftime = NULL;
875N/APerfCounter* ClassLoader::_perf_sys_class_lookup_time = NULL;
875N/APerfCounter* ClassLoader::_perf_shared_classload_time = NULL;
875N/APerfCounter* ClassLoader::_perf_sys_classload_time = NULL;
875N/APerfCounter* ClassLoader::_perf_app_classload_time = NULL;
875N/APerfCounter* ClassLoader::_perf_app_classload_selftime = NULL;
875N/APerfCounter* ClassLoader::_perf_app_classload_count = NULL;
875N/APerfCounter* ClassLoader::_perf_define_appclasses = NULL;
875N/APerfCounter* ClassLoader::_perf_define_appclass_time = NULL;
875N/APerfCounter* ClassLoader::_perf_define_appclass_selftime = NULL;
875N/APerfCounter* ClassLoader::_perf_app_classfile_bytes_read = NULL;
875N/APerfCounter* ClassLoader::_perf_sys_classfile_bytes_read = NULL;
0N/APerfCounter* ClassLoader::_sync_systemLoaderLockContentionRate = NULL;
0N/APerfCounter* ClassLoader::_sync_nonSystemLoaderLockContentionRate = NULL;
0N/APerfCounter* ClassLoader::_sync_JVMFindLoadedClassLockFreeCounter = NULL;
0N/APerfCounter* ClassLoader::_sync_JVMDefineClassLockFreeCounter = NULL;
0N/APerfCounter* ClassLoader::_sync_JNIDefineClassLockFreeCounter = NULL;
0N/APerfCounter* ClassLoader::_unsafe_defineClassCallCounter = NULL;
0N/APerfCounter* ClassLoader::_isUnsyncloadClass = NULL;
0N/APerfCounter* ClassLoader::_load_instance_class_failCounter = NULL;
0N/A
0N/AClassPathEntry* ClassLoader::_first_entry = NULL;
0N/AClassPathEntry* ClassLoader::_last_entry = NULL;
0N/APackageHashtable* ClassLoader::_package_hash_table = NULL;
0N/A
0N/A// helper routines
0N/Abool string_starts_with(const char* str, const char* str_to_find) {
0N/A size_t str_len = strlen(str);
0N/A size_t str_to_find_len = strlen(str_to_find);
0N/A if (str_to_find_len > str_len) {
0N/A return false;
0N/A }
0N/A return (strncmp(str, str_to_find, str_to_find_len) == 0);
0N/A}
0N/A
0N/Abool string_ends_with(const char* str, const char* str_to_find) {
0N/A size_t str_len = strlen(str);
0N/A size_t str_to_find_len = strlen(str_to_find);
0N/A if (str_to_find_len > str_len) {
0N/A return false;
0N/A }
0N/A return (strncmp(str + (str_len - str_to_find_len), str_to_find, str_to_find_len) == 0);
0N/A}
0N/A
0N/A
0N/AMetaIndex::MetaIndex(char** meta_package_names, int num_meta_package_names) {
0N/A if (num_meta_package_names == 0) {
0N/A _meta_package_names = NULL;
0N/A _num_meta_package_names = 0;
0N/A } else {
3863N/A _meta_package_names = NEW_C_HEAP_ARRAY(char*, num_meta_package_names, mtClass);
0N/A _num_meta_package_names = num_meta_package_names;
0N/A memcpy(_meta_package_names, meta_package_names, num_meta_package_names * sizeof(char*));
0N/A }
0N/A}
0N/A
0N/A
0N/AMetaIndex::~MetaIndex() {
3863N/A FREE_C_HEAP_ARRAY(char*, _meta_package_names, mtClass);
0N/A}
0N/A
0N/A
0N/Abool MetaIndex::may_contain(const char* class_name) {
0N/A if ( _num_meta_package_names == 0) {
0N/A return false;
0N/A }
0N/A size_t class_name_len = strlen(class_name);
0N/A for (int i = 0; i < _num_meta_package_names; i++) {
0N/A char* pkg = _meta_package_names[i];
0N/A size_t pkg_len = strlen(pkg);
0N/A size_t min_len = MIN2(class_name_len, pkg_len);
0N/A if (!strncmp(class_name, pkg, min_len)) {
0N/A return true;
0N/A }
0N/A }
0N/A return false;
0N/A}
0N/A
0N/A
0N/AClassPathEntry::ClassPathEntry() {
0N/A set_next(NULL);
0N/A}
0N/A
0N/A
0N/Abool ClassPathEntry::is_lazy() {
0N/A return false;
0N/A}
0N/A
0N/AClassPathDirEntry::ClassPathDirEntry(char* dir) : ClassPathEntry() {
3863N/A _dir = NEW_C_HEAP_ARRAY(char, strlen(dir)+1, mtClass);
0N/A strcpy(_dir, dir);
0N/A}
0N/A
0N/A
0N/AClassFileStream* ClassPathDirEntry::open_stream(const char* name) {
0N/A // construct full path name
0N/A char path[JVM_MAXPATHLEN];
0N/A if (jio_snprintf(path, sizeof(path), "%s%s%s", _dir, os::file_separator(), name) == -1) {
0N/A return NULL;
0N/A }
0N/A // check if file exists
0N/A struct stat st;
0N/A if (os::stat(path, &st) == 0) {
0N/A // found file, open it
1887N/A int file_handle = os::open(path, 0, 0);
0N/A if (file_handle != -1) {
0N/A // read contents into resource array
0N/A u1* buffer = NEW_RESOURCE_ARRAY(u1, st.st_size);
0N/A size_t num_read = os::read(file_handle, (char*) buffer, st.st_size);
0N/A // close file
1887N/A os::close(file_handle);
0N/A // construct ClassFileStream
0N/A if (num_read == (size_t)st.st_size) {
875N/A if (UsePerfData) {
875N/A ClassLoader::perf_sys_classfile_bytes_read()->inc(num_read);
875N/A }
0N/A return new ClassFileStream(buffer, st.st_size, _dir); // Resource allocated
0N/A }
0N/A }
0N/A }
0N/A return NULL;
0N/A}
0N/A
0N/A
0N/AClassPathZipEntry::ClassPathZipEntry(jzfile* zip, const char* zip_name) : ClassPathEntry() {
0N/A _zip = zip;
3863N/A _zip_name = NEW_C_HEAP_ARRAY(char, strlen(zip_name)+1, mtClass);
0N/A strcpy(_zip_name, zip_name);
0N/A}
0N/A
0N/AClassPathZipEntry::~ClassPathZipEntry() {
0N/A if (ZipClose != NULL) {
0N/A (*ZipClose)(_zip);
0N/A }
3863N/A FREE_C_HEAP_ARRAY(char, _zip_name, mtClass);
0N/A}
0N/A
0N/AClassFileStream* ClassPathZipEntry::open_stream(const char* name) {
0N/A // enable call to C land
0N/A JavaThread* thread = JavaThread::current();
0N/A ThreadToNativeFromVM ttn(thread);
0N/A // check whether zip archive contains name
0N/A jint filesize, name_len;
0N/A jzentry* entry = (*FindEntry)(_zip, name, &filesize, &name_len);
0N/A if (entry == NULL) return NULL;
0N/A u1* buffer;
0N/A char name_buf[128];
0N/A char* filename;
0N/A if (name_len < 128) {
0N/A filename = name_buf;
0N/A } else {
0N/A filename = NEW_RESOURCE_ARRAY(char, name_len + 1);
0N/A }
0N/A
0N/A // file found, get pointer to class in mmaped jar file.
0N/A if (ReadMappedEntry == NULL ||
0N/A !(*ReadMappedEntry)(_zip, entry, &buffer, filename)) {
0N/A // mmaped access not available, perhaps due to compression,
0N/A // read contents into resource array
0N/A buffer = NEW_RESOURCE_ARRAY(u1, filesize);
0N/A if (!(*ReadEntry)(_zip, entry, buffer, filename)) return NULL;
0N/A }
875N/A if (UsePerfData) {
875N/A ClassLoader::perf_sys_classfile_bytes_read()->inc(filesize);
875N/A }
0N/A // return result
0N/A return new ClassFileStream(buffer, filesize, _zip_name); // Resource allocated
0N/A}
0N/A
0N/A// invoke function for each entry in the zip file
0N/Avoid ClassPathZipEntry::contents_do(void f(const char* name, void* context), void* context) {
0N/A JavaThread* thread = JavaThread::current();
0N/A HandleMark handle_mark(thread);
0N/A ThreadToNativeFromVM ttn(thread);
0N/A for (int n = 0; ; n++) {
0N/A jzentry * ze = ((*GetNextEntry)(_zip, n));
0N/A if (ze == NULL) break;
0N/A (*f)(ze->name, context);
0N/A }
0N/A}
0N/A
0N/ALazyClassPathEntry::LazyClassPathEntry(char* path, struct stat st) : ClassPathEntry() {
0N/A _path = strdup(path);
0N/A _st = st;
0N/A _meta_index = NULL;
0N/A _resolved_entry = NULL;
0N/A}
0N/A
0N/Abool LazyClassPathEntry::is_jar_file() {
0N/A return ((_st.st_mode & S_IFREG) == S_IFREG);
0N/A}
0N/A
0N/AClassPathEntry* LazyClassPathEntry::resolve_entry() {
0N/A if (_resolved_entry != NULL) {
0N/A return (ClassPathEntry*) _resolved_entry;
0N/A }
0N/A ClassPathEntry* new_entry = NULL;
0N/A ClassLoader::create_class_path_entry(_path, _st, &new_entry, false);
0N/A assert(new_entry != NULL, "earlier code should have caught this");
0N/A {
0N/A ThreadCritical tc;
0N/A if (_resolved_entry == NULL) {
0N/A _resolved_entry = new_entry;
0N/A return new_entry;
0N/A }
0N/A }
0N/A assert(_resolved_entry != NULL, "bug in MT-safe resolution logic");
0N/A delete new_entry;
0N/A return (ClassPathEntry*) _resolved_entry;
0N/A}
0N/A
0N/AClassFileStream* LazyClassPathEntry::open_stream(const char* name) {
0N/A if (_meta_index != NULL &&
0N/A !_meta_index->may_contain(name)) {
0N/A return NULL;
0N/A }
0N/A return resolve_entry()->open_stream(name);
0N/A}
0N/A
0N/Abool LazyClassPathEntry::is_lazy() {
0N/A return true;
0N/A}
0N/A
0N/Astatic void print_meta_index(LazyClassPathEntry* entry,
0N/A GrowableArray<char*>& meta_packages) {
0N/A tty->print("[Meta index for %s=", entry->name());
0N/A for (int i = 0; i < meta_packages.length(); i++) {
0N/A if (i > 0) tty->print(" ");
0N/A tty->print(meta_packages.at(i));
0N/A }
0N/A tty->print_cr("]");
0N/A}
0N/A
0N/A
0N/Avoid ClassLoader::setup_meta_index() {
0N/A // Set up meta index which allows us to open boot jars lazily if
0N/A // class data sharing is enabled
0N/A const char* known_version = "% VERSION 2";
0N/A char* meta_index_path = Arguments::get_meta_index_path();
0N/A char* meta_index_dir = Arguments::get_meta_index_dir();
0N/A FILE* file = fopen(meta_index_path, "r");
0N/A int line_no = 0;
0N/A if (file != NULL) {
0N/A ResourceMark rm;
0N/A LazyClassPathEntry* cur_entry = NULL;
0N/A GrowableArray<char*> boot_class_path_packages(10);
0N/A char package_name[256];
0N/A bool skipCurrentJar = false;
0N/A while (fgets(package_name, sizeof(package_name), file) != NULL) {
0N/A ++line_no;
0N/A // Remove trailing newline
0N/A package_name[strlen(package_name) - 1] = '\0';
0N/A switch(package_name[0]) {
0N/A case '%':
0N/A {
0N/A if ((line_no == 1) && (strcmp(package_name, known_version) != 0)) {
0N/A if (TraceClassLoading && Verbose) {
0N/A tty->print("[Unsupported meta index version]");
0N/A }
0N/A fclose(file);
0N/A return;
0N/A }
0N/A }
0N/A
0N/A // These directives indicate jar files which contain only
0N/A // classes, only non-classfile resources, or a combination of
0N/A // the two. See src/share/classes/sun/misc/MetaIndex.java and
0N/A // make/tools/MetaIndex/BuildMetaIndex.java in the J2SE
0N/A // workspace.
0N/A case '#':
0N/A case '!':
0N/A case '@':
0N/A {
0N/A // Hand off current packages to current lazy entry (if any)
0N/A if ((cur_entry != NULL) &&
0N/A (boot_class_path_packages.length() > 0)) {
0N/A if (TraceClassLoading && Verbose) {
0N/A print_meta_index(cur_entry, boot_class_path_packages);
0N/A }
0N/A MetaIndex* index = new MetaIndex(boot_class_path_packages.adr_at(0),
0N/A boot_class_path_packages.length());
0N/A cur_entry->set_meta_index(index);
0N/A }
0N/A cur_entry = NULL;
0N/A boot_class_path_packages.clear();
0N/A
0N/A // Find lazy entry corresponding to this jar file
0N/A for (ClassPathEntry* entry = _first_entry; entry != NULL; entry = entry->next()) {
0N/A if (entry->is_lazy() &&
0N/A string_starts_with(entry->name(), meta_index_dir) &&
0N/A string_ends_with(entry->name(), &package_name[2])) {
0N/A cur_entry = (LazyClassPathEntry*) entry;
0N/A break;
0N/A }
0N/A }
0N/A
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 if (package_name[0] == '@') {
0N/A if (cur_entry != NULL) {
0N/A cur_entry->set_meta_index(new MetaIndex(NULL, 0));
0N/A }
0N/A cur_entry = NULL;
0N/A skipCurrentJar = true;
0N/A } else {
0N/A skipCurrentJar = false;
0N/A }
0N/A
0N/A break;
0N/A }
0N/A
0N/A default:
0N/A {
0N/A if (!skipCurrentJar && cur_entry != NULL) {
0N/A char* new_name = strdup(package_name);
0N/A boot_class_path_packages.append(new_name);
0N/A }
0N/A }
0N/A }
0N/A }
0N/A // Hand off current packages to current lazy entry (if any)
0N/A if ((cur_entry != NULL) &&
0N/A (boot_class_path_packages.length() > 0)) {
0N/A if (TraceClassLoading && Verbose) {
0N/A print_meta_index(cur_entry, boot_class_path_packages);
0N/A }
0N/A MetaIndex* index = new MetaIndex(boot_class_path_packages.adr_at(0),
0N/A boot_class_path_packages.length());
0N/A cur_entry->set_meta_index(index);
0N/A }
0N/A fclose(file);
0N/A }
0N/A}
0N/A
0N/Avoid ClassLoader::setup_bootstrap_search_path() {
0N/A assert(_first_entry == NULL, "should not setup bootstrap class search path twice");
0N/A char* sys_class_path = os::strdup(Arguments::get_sysclasspath());
0N/A if (TraceClassLoading && Verbose) {
0N/A tty->print_cr("[Bootstrap loader class path=%s]", sys_class_path);
0N/A }
0N/A
0N/A int len = (int)strlen(sys_class_path);
0N/A int end = 0;
0N/A
0N/A // Iterate over class path entries
0N/A for (int start = 0; start < len; start = end) {
0N/A while (sys_class_path[end] && sys_class_path[end] != os::path_separator()[0]) {
0N/A end++;
0N/A }
3863N/A char* path = NEW_C_HEAP_ARRAY(char, end-start+1, mtClass);
0N/A strncpy(path, &sys_class_path[start], end-start);
0N/A path[end-start] = '\0';
0N/A update_class_path_entry_list(path, false);
3863N/A FREE_C_HEAP_ARRAY(char, path, mtClass);
0N/A while (sys_class_path[end] == os::path_separator()[0]) {
0N/A end++;
0N/A }
0N/A }
0N/A}
0N/A
0N/Avoid ClassLoader::create_class_path_entry(char *path, struct stat st, ClassPathEntry **new_entry, bool lazy) {
0N/A JavaThread* thread = JavaThread::current();
0N/A if (lazy) {
0N/A *new_entry = new LazyClassPathEntry(path, st);
0N/A return;
0N/A }
0N/A if ((st.st_mode & S_IFREG) == S_IFREG) {
0N/A // Regular file, should be a zip file
0N/A // Canonicalized filename
0N/A char canonical_path[JVM_MAXPATHLEN];
0N/A if (!get_canonical_path(path, canonical_path, JVM_MAXPATHLEN)) {
0N/A // This matches the classic VM
0N/A EXCEPTION_MARK;
0N/A THROW_MSG(vmSymbols::java_io_IOException(), "Bad pathname");
0N/A }
0N/A char* error_msg = NULL;
0N/A jzfile* zip;
0N/A {
0N/A // enable call to C land
0N/A ThreadToNativeFromVM ttn(thread);
0N/A HandleMark hm(thread);
0N/A zip = (*ZipOpen)(canonical_path, &error_msg);
0N/A }
0N/A if (zip != NULL && error_msg == NULL) {
0N/A *new_entry = new ClassPathZipEntry(zip, path);
0N/A if (TraceClassLoading) {
0N/A tty->print_cr("[Opened %s]", path);
0N/A }
0N/A } else {
0N/A ResourceMark rm(thread);
0N/A char *msg;
0N/A if (error_msg == NULL) {
0N/A msg = NEW_RESOURCE_ARRAY(char, strlen(path) + 128); ;
0N/A jio_snprintf(msg, strlen(path) + 127, "error in opening JAR file %s", path);
0N/A } else {
0N/A int len = (int)(strlen(path) + strlen(error_msg) + 128);
0N/A msg = NEW_RESOURCE_ARRAY(char, len); ;
0N/A jio_snprintf(msg, len - 1, "error in opening JAR file <%s> %s", error_msg, path);
0N/A }
0N/A EXCEPTION_MARK;
0N/A THROW_MSG(vmSymbols::java_lang_ClassNotFoundException(), msg);
0N/A }
0N/A } else {
0N/A // Directory
0N/A *new_entry = new ClassPathDirEntry(path);
0N/A if (TraceClassLoading) {
0N/A tty->print_cr("[Path %s]", path);
0N/A }
0N/A }
0N/A}
0N/A
0N/A
0N/A// Create a class path zip entry for a given path (return NULL if not found
0N/A// or zip/JAR file cannot be opened)
0N/AClassPathZipEntry* ClassLoader::create_class_path_zip_entry(const char *path) {
0N/A // check for a regular file
0N/A struct stat st;
0N/A if (os::stat(path, &st) == 0) {
0N/A if ((st.st_mode & S_IFREG) == S_IFREG) {
0N/A char orig_path[JVM_MAXPATHLEN];
0N/A char canonical_path[JVM_MAXPATHLEN];
0N/A
0N/A strcpy(orig_path, path);
0N/A if (get_canonical_path(orig_path, canonical_path, JVM_MAXPATHLEN)) {
0N/A char* error_msg = NULL;
0N/A jzfile* zip;
0N/A {
0N/A // enable call to C land
0N/A JavaThread* thread = JavaThread::current();
0N/A ThreadToNativeFromVM ttn(thread);
0N/A HandleMark hm(thread);
0N/A zip = (*ZipOpen)(canonical_path, &error_msg);
0N/A }
0N/A if (zip != NULL && error_msg == NULL) {
0N/A // create using canonical path
0N/A return new ClassPathZipEntry(zip, canonical_path);
0N/A }
0N/A }
0N/A }
0N/A }
0N/A return NULL;
0N/A}
0N/A
0N/A// returns true if entry already on class path
0N/Abool ClassLoader::contains_entry(ClassPathEntry *entry) {
0N/A ClassPathEntry* e = _first_entry;
0N/A while (e != NULL) {
0N/A // assume zip entries have been canonicalized
0N/A if (strcmp(entry->name(), e->name()) == 0) {
0N/A return true;
0N/A }
0N/A e = e->next();
0N/A }
0N/A return false;
0N/A}
0N/A
0N/Avoid ClassLoader::add_to_list(ClassPathEntry *new_entry) {
0N/A if (new_entry != NULL) {
0N/A if (_last_entry == NULL) {
0N/A _first_entry = _last_entry = new_entry;
0N/A } else {
0N/A _last_entry->set_next(new_entry);
0N/A _last_entry = new_entry;
0N/A }
0N/A }
0N/A}
0N/A
0N/Avoid ClassLoader::update_class_path_entry_list(const char *path,
0N/A bool check_for_duplicates) {
0N/A struct stat st;
0N/A if (os::stat((char *)path, &st) == 0) {
0N/A // File or directory found
0N/A ClassPathEntry* new_entry = NULL;
0N/A create_class_path_entry((char *)path, st, &new_entry, LazyBootClassLoader);
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 if (!check_for_duplicates || !contains_entry(new_entry)) {
0N/A add_to_list(new_entry);
0N/A }
0N/A }
0N/A}
0N/A
0N/Avoid ClassLoader::print_bootclasspath() {
0N/A ClassPathEntry* e = _first_entry;
0N/A tty->print("[bootclasspath= ");
0N/A while (e != NULL) {
0N/A tty->print("%s ;", e->name());
0N/A e = e->next();
0N/A }
0N/A tty->print_cr("]");
0N/A}
0N/A
0N/Avoid ClassLoader::load_zip_library() {
0N/A assert(ZipOpen == NULL, "should not load zip library twice");
0N/A // First make sure native library is loaded
0N/A os::native_java_library();
0N/A // Load zip library
0N/A char path[JVM_MAXPATHLEN];
0N/A char ebuf[1024];
1887N/A os::dll_build_name(path, sizeof(path), Arguments::get_dll_dir(), "zip");
1887N/A void* handle = os::dll_load(path, ebuf, sizeof ebuf);
0N/A if (handle == NULL) {
0N/A vm_exit_during_initialization("Unable to load ZIP library", path);
0N/A }
0N/A // Lookup zip entry points
1887N/A ZipOpen = CAST_TO_FN_PTR(ZipOpen_t, os::dll_lookup(handle, "ZIP_Open"));
1887N/A ZipClose = CAST_TO_FN_PTR(ZipClose_t, os::dll_lookup(handle, "ZIP_Close"));
1887N/A FindEntry = CAST_TO_FN_PTR(FindEntry_t, os::dll_lookup(handle, "ZIP_FindEntry"));
1887N/A ReadEntry = CAST_TO_FN_PTR(ReadEntry_t, os::dll_lookup(handle, "ZIP_ReadEntry"));
1887N/A ReadMappedEntry = CAST_TO_FN_PTR(ReadMappedEntry_t, os::dll_lookup(handle, "ZIP_ReadMappedEntry"));
1887N/A GetNextEntry = CAST_TO_FN_PTR(GetNextEntry_t, os::dll_lookup(handle, "ZIP_GetNextEntry"));
0N/A
0N/A // ZIP_Close is not exported on Windows in JDK5.0 so don't abort if ZIP_Close is NULL
0N/A if (ZipOpen == NULL || FindEntry == NULL || ReadEntry == NULL || GetNextEntry == NULL) {
0N/A vm_exit_during_initialization("Corrupted ZIP library", path);
0N/A }
0N/A
0N/A // Lookup canonicalize entry in libjava.dll
0N/A void *javalib_handle = os::native_java_library();
1887N/A CanonicalizeEntry = CAST_TO_FN_PTR(canonicalize_fn_t, os::dll_lookup(javalib_handle, "Canonicalize"));
0N/A // This lookup only works on 1.3. Do not check for non-null here
0N/A}
0N/A
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
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
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
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
3863N/Aclass PackageInfo: public BasicHashtableEntry<mtClass> {
0N/Apublic:
0N/A const char* _pkgname; // Package name
0N/A int _classpath_index; // Index of directory or JAR file loaded from
0N/A
0N/A PackageInfo* next() {
3863N/A return (PackageInfo*)BasicHashtableEntry<mtClass>::next();
0N/A }
0N/A
0N/A const char* pkgname() { return _pkgname; }
0N/A void set_pkgname(char* pkgname) { _pkgname = pkgname; }
0N/A
0N/A const char* filename() {
0N/A return ClassLoader::classpath_entry(_classpath_index)->name();
0N/A }
0N/A
0N/A void set_index(int index) {
0N/A _classpath_index = index;
0N/A }
0N/A};
0N/A
0N/A
3863N/Aclass PackageHashtable : public BasicHashtable<mtClass> {
0N/Aprivate:
0N/A inline unsigned int compute_hash(const char *s, int n) {
0N/A unsigned int val = 0;
0N/A while (--n >= 0) {
0N/A val = *s++ + 31 * val;
0N/A }
0N/A return val;
0N/A }
0N/A
0N/A PackageInfo* bucket(int index) {
3863N/A return (PackageInfo*)BasicHashtable<mtClass>::bucket(index);
0N/A }
0N/A
0N/A PackageInfo* get_entry(int index, unsigned int hash,
0N/A const char* pkgname, size_t n) {
0N/A for (PackageInfo* pp = bucket(index); pp != NULL; pp = pp->next()) {
0N/A if (pp->hash() == hash &&
0N/A strncmp(pkgname, pp->pkgname(), n) == 0 &&
0N/A pp->pkgname()[n] == '\0') {
0N/A return pp;
0N/A }
0N/A }
0N/A return NULL;
0N/A }
0N/A
0N/Apublic:
0N/A PackageHashtable(int table_size)
3863N/A : BasicHashtable<mtClass>(table_size, sizeof(PackageInfo)) {}
0N/A
3863N/A PackageHashtable(int table_size, HashtableBucket<mtClass>* t, int number_of_entries)
3863N/A : BasicHashtable<mtClass>(table_size, sizeof(PackageInfo), t, number_of_entries) {}
0N/A
0N/A PackageInfo* get_entry(const char* pkgname, int n) {
0N/A unsigned int hash = compute_hash(pkgname, n);
0N/A return get_entry(hash_to_index(hash), hash, pkgname, n);
0N/A }
0N/A
0N/A PackageInfo* new_entry(char* pkgname, int n) {
0N/A unsigned int hash = compute_hash(pkgname, n);
0N/A PackageInfo* pp;
3863N/A pp = (PackageInfo*)BasicHashtable<mtClass>::new_entry(hash);
0N/A pp->set_pkgname(pkgname);
0N/A return pp;
0N/A }
0N/A
0N/A void add_entry(PackageInfo* pp) {
0N/A int index = hash_to_index(pp->hash());
3863N/A BasicHashtable<mtClass>::add_entry(index, pp);
0N/A }
0N/A
0N/A void copy_pkgnames(const char** packages) {
0N/A int n = 0;
0N/A for (int i = 0; i < table_size(); ++i) {
0N/A for (PackageInfo* pp = bucket(i); pp != NULL; pp = pp->next()) {
0N/A packages[n++] = pp->pkgname();
0N/A }
0N/A }
0N/A assert(n == number_of_entries(), "just checking");
0N/A }
0N/A
0N/A void copy_table(char** top, char* end, PackageHashtable* table);
0N/A};
0N/A
0N/A
0N/Avoid PackageHashtable::copy_table(char** top, char* end,
0N/A PackageHashtable* table) {
0N/A // Copy (relocate) the table to the shared space.
3863N/A BasicHashtable<mtClass>::copy_table(top, end);
0N/A
0N/A // Calculate the space needed for the package name strings.
0N/A int i;
0N/A int n = 0;
0N/A for (i = 0; i < table_size(); ++i) {
0N/A for (PackageInfo* pp = table->bucket(i);
0N/A pp != NULL;
0N/A pp = pp->next()) {
0N/A n += (int)(strlen(pp->pkgname()) + 1);
0N/A }
0N/A }
0N/A if (*top + n + sizeof(intptr_t) >= end) {
2062N/A report_out_of_shared_space(SharedMiscData);
0N/A }
0N/A
0N/A // Copy the table data (the strings) to the shared space.
0N/A n = align_size_up(n, sizeof(HeapWord));
0N/A *(intptr_t*)(*top) = n;
0N/A *top += sizeof(intptr_t);
0N/A
0N/A for (i = 0; i < table_size(); ++i) {
0N/A for (PackageInfo* pp = table->bucket(i);
0N/A pp != NULL;
0N/A pp = pp->next()) {
0N/A int n1 = (int)(strlen(pp->pkgname()) + 1);
0N/A pp->set_pkgname((char*)memcpy(*top, pp->pkgname(), n1));
0N/A *top += n1;
0N/A }
0N/A }
0N/A *top = (char*)align_size_up((intptr_t)*top, sizeof(HeapWord));
0N/A}
0N/A
0N/A
0N/Avoid ClassLoader::copy_package_info_buckets(char** top, char* end) {
0N/A _package_hash_table->copy_buckets(top, end);
0N/A}
0N/A
0N/Avoid ClassLoader::copy_package_info_table(char** top, char* end) {
0N/A _package_hash_table->copy_table(top, end, _package_hash_table);
0N/A}
0N/A
0N/A
0N/APackageInfo* ClassLoader::lookup_package(const char *pkgname) {
0N/A const char *cp = strrchr(pkgname, '/');
0N/A if (cp != NULL) {
0N/A // Package prefix found
0N/A int n = cp - pkgname + 1;
0N/A return _package_hash_table->get_entry(pkgname, n);
0N/A }
0N/A return NULL;
0N/A}
0N/A
0N/A
0N/Abool ClassLoader::add_package(const char *pkgname, int classpath_index, TRAPS) {
0N/A assert(pkgname != NULL, "just checking");
0N/A // Bootstrap loader no longer holds system loader lock obj serializing
0N/A // load_instance_class and thereby add_package
0N/A {
0N/A MutexLocker ml(PackageTable_lock, THREAD);
0N/A // First check for previously loaded entry
0N/A PackageInfo* pp = lookup_package(pkgname);
0N/A if (pp != NULL) {
0N/A // Existing entry found, check source of package
0N/A pp->set_index(classpath_index);
0N/A return true;
0N/A }
0N/A
0N/A const char *cp = strrchr(pkgname, '/');
0N/A if (cp != NULL) {
0N/A // Package prefix found
0N/A int n = cp - pkgname + 1;
0N/A
3863N/A char* new_pkgname = NEW_C_HEAP_ARRAY(char, n + 1, mtClass);
0N/A if (new_pkgname == NULL) {
0N/A return false;
0N/A }
0N/A
0N/A memcpy(new_pkgname, pkgname, n);
0N/A new_pkgname[n] = '\0';
0N/A pp = _package_hash_table->new_entry(new_pkgname, n);
0N/A pp->set_index(classpath_index);
0N/A
0N/A // Insert into hash table
0N/A _package_hash_table->add_entry(pp);
0N/A }
0N/A return true;
0N/A }
0N/A}
0N/A
0N/A
0N/Aoop ClassLoader::get_system_package(const char* name, TRAPS) {
0N/A PackageInfo* pp;
0N/A {
0N/A MutexLocker ml(PackageTable_lock, THREAD);
0N/A pp = lookup_package(name);
0N/A }
0N/A if (pp == NULL) {
0N/A return NULL;
0N/A } else {
0N/A Handle p = java_lang_String::create_from_str(pp->filename(), THREAD);
0N/A return p();
0N/A }
0N/A}
0N/A
0N/A
0N/AobjArrayOop ClassLoader::get_system_packages(TRAPS) {
0N/A ResourceMark rm(THREAD);
0N/A int nof_entries;
0N/A const char** packages;
0N/A {
0N/A MutexLocker ml(PackageTable_lock, THREAD);
0N/A // Allocate resource char* array containing package names
0N/A nof_entries = _package_hash_table->number_of_entries();
0N/A if ((packages = NEW_RESOURCE_ARRAY(const char*, nof_entries)) == NULL) {
0N/A return NULL;
0N/A }
0N/A _package_hash_table->copy_pkgnames(packages);
0N/A }
0N/A // Allocate objArray and fill with java.lang.String
1142N/A objArrayOop r = oopFactory::new_objArray(SystemDictionary::String_klass(),
0N/A nof_entries, CHECK_0);
0N/A objArrayHandle result(THREAD, r);
0N/A for (int i = 0; i < nof_entries; i++) {
0N/A Handle str = java_lang_String::create_from_str(packages[i], CHECK_0);
0N/A result->obj_at_put(i, str());
0N/A }
0N/A
0N/A return result();
0N/A}
0N/A
0N/A
2062N/AinstanceKlassHandle ClassLoader::load_classfile(Symbol* h_name, TRAPS) {
0N/A ResourceMark rm(THREAD);
2062N/A EventMark m("loading class " INTPTR_FORMAT, (address)h_name);
0N/A ThreadProfilerMark tpm(ThreadProfilerMark::classLoaderRegion);
0N/A
0N/A stringStream st;
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 st.print_raw(h_name->as_utf8());
0N/A st.print_raw(".class");
0N/A char* name = st.as_string();
0N/A
0N/A // Lookup stream for parsing .class file
0N/A ClassFileStream* stream = NULL;
0N/A int classpath_index = 0;
0N/A {
875N/A PerfClassTraceTime vmtimer(perf_sys_class_lookup_time(),
875N/A ((JavaThread*) THREAD)->get_thread_stat()->perf_timers_addr(),
875N/A PerfClassTraceTime::CLASS_LOAD);
0N/A ClassPathEntry* e = _first_entry;
0N/A while (e != NULL) {
0N/A stream = e->open_stream(name);
0N/A if (stream != NULL) {
0N/A break;
0N/A }
0N/A e = e->next();
0N/A ++classpath_index;
0N/A }
0N/A }
0N/A
0N/A instanceKlassHandle h(THREAD, klassOop(NULL));
0N/A if (stream != NULL) {
0N/A
0N/A // class file found, parse it
0N/A ClassFileParser parser(stream);
0N/A Handle class_loader;
0N/A Handle protection_domain;
2062N/A TempNewSymbol parsed_name = NULL;
0N/A instanceKlassHandle result = parser.parseClassFile(h_name,
0N/A class_loader,
0N/A protection_domain,
0N/A parsed_name,
973N/A false,
0N/A CHECK_(h));
0N/A
0N/A // add to package table
0N/A if (add_package(name, classpath_index, THREAD)) {
0N/A h = result;
0N/A }
0N/A }
0N/A
0N/A return h;
0N/A}
0N/A
0N/A
3863N/Avoid ClassLoader::create_package_info_table(HashtableBucket<mtClass> *t, int length,
0N/A int number_of_entries) {
0N/A assert(_package_hash_table == NULL, "One package info table allowed.");
3863N/A assert(length == package_hash_table_size * sizeof(HashtableBucket<mtClass>),
0N/A "bad shared package info size.");
0N/A _package_hash_table = new PackageHashtable(package_hash_table_size, t,
0N/A number_of_entries);
0N/A}
0N/A
0N/A
0N/Avoid ClassLoader::create_package_info_table() {
0N/A assert(_package_hash_table == NULL, "shouldn't have one yet");
0N/A _package_hash_table = new PackageHashtable(package_hash_table_size);
0N/A}
0N/A
0N/A
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
0N/Avoid ClassLoader::initialize() {
0N/A assert(_package_hash_table == NULL, "should have been initialized by now.");
0N/A EXCEPTION_MARK;
0N/A
0N/A if (UsePerfData) {
0N/A // jvmstat performance counters
0N/A NEWPERFTICKCOUNTER(_perf_accumulated_time, SUN_CLS, "time");
0N/A NEWPERFTICKCOUNTER(_perf_class_init_time, SUN_CLS, "classInitTime");
875N/A NEWPERFTICKCOUNTER(_perf_class_init_selftime, SUN_CLS, "classInitTime.self");
0N/A NEWPERFTICKCOUNTER(_perf_class_verify_time, SUN_CLS, "classVerifyTime");
875N/A NEWPERFTICKCOUNTER(_perf_class_verify_selftime, SUN_CLS, "classVerifyTime.self");
0N/A NEWPERFTICKCOUNTER(_perf_class_link_time, SUN_CLS, "classLinkedTime");
875N/A NEWPERFTICKCOUNTER(_perf_class_link_selftime, SUN_CLS, "classLinkedTime.self");
0N/A NEWPERFEVENTCOUNTER(_perf_classes_inited, SUN_CLS, "initializedClasses");
0N/A NEWPERFEVENTCOUNTER(_perf_classes_linked, SUN_CLS, "linkedClasses");
875N/A NEWPERFEVENTCOUNTER(_perf_classes_verified, SUN_CLS, "verifiedClasses");
875N/A
875N/A NEWPERFTICKCOUNTER(_perf_class_parse_time, SUN_CLS, "parseClassTime");
875N/A NEWPERFTICKCOUNTER(_perf_class_parse_selftime, SUN_CLS, "parseClassTime.self");
875N/A NEWPERFTICKCOUNTER(_perf_sys_class_lookup_time, SUN_CLS, "lookupSysClassTime");
875N/A NEWPERFTICKCOUNTER(_perf_shared_classload_time, SUN_CLS, "sharedClassLoadTime");
875N/A NEWPERFTICKCOUNTER(_perf_sys_classload_time, SUN_CLS, "sysClassLoadTime");
875N/A NEWPERFTICKCOUNTER(_perf_app_classload_time, SUN_CLS, "appClassLoadTime");
875N/A NEWPERFTICKCOUNTER(_perf_app_classload_selftime, SUN_CLS, "appClassLoadTime.self");
875N/A NEWPERFEVENTCOUNTER(_perf_app_classload_count, SUN_CLS, "appClassLoadCount");
875N/A NEWPERFTICKCOUNTER(_perf_define_appclasses, SUN_CLS, "defineAppClasses");
875N/A NEWPERFTICKCOUNTER(_perf_define_appclass_time, SUN_CLS, "defineAppClassTime");
875N/A NEWPERFTICKCOUNTER(_perf_define_appclass_selftime, SUN_CLS, "defineAppClassTime.self");
875N/A NEWPERFBYTECOUNTER(_perf_app_classfile_bytes_read, SUN_CLS, "appClassBytes");
875N/A NEWPERFBYTECOUNTER(_perf_sys_classfile_bytes_read, SUN_CLS, "sysClassBytes");
875N/A
0N/A
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 // ClassLoader.loadClass/findClass is being called synchronized or not.
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 NEWPERFEVENTCOUNTER(_sync_systemLoaderLockContentionRate, SUN_CLS,
0N/A "systemLoaderLockContentionRate");
0N/A NEWPERFEVENTCOUNTER(_sync_nonSystemLoaderLockContentionRate, SUN_CLS,
0N/A "nonSystemLoaderLockContentionRate");
0N/A NEWPERFEVENTCOUNTER(_sync_JVMFindLoadedClassLockFreeCounter, SUN_CLS,
0N/A "jvmFindLoadedClassNoLockCalls");
0N/A NEWPERFEVENTCOUNTER(_sync_JVMDefineClassLockFreeCounter, SUN_CLS,
0N/A "jvmDefineClassNoLockCalls");
0N/A
0N/A NEWPERFEVENTCOUNTER(_sync_JNIDefineClassLockFreeCounter, SUN_CLS,
0N/A "jniDefineClassNoLockCalls");
0N/A
0N/A NEWPERFEVENTCOUNTER(_unsafe_defineClassCallCounter, SUN_CLS,
0N/A "unsafeDefineClassCalls");
0N/A
0N/A NEWPERFEVENTCOUNTER(_isUnsyncloadClass, SUN_CLS, "isUnsyncloadClassSet");
0N/A NEWPERFEVENTCOUNTER(_load_instance_class_failCounter, SUN_CLS,
0N/A "loadInstanceClassFailRate");
0N/A
0N/A // increment the isUnsyncloadClass counter if UnsyncloadClass is set.
0N/A if (UnsyncloadClass) {
0N/A _isUnsyncloadClass->inc();
0N/A }
0N/A }
0N/A
0N/A // lookup zip library entry points
0N/A load_zip_library();
0N/A // initialize search path
0N/A setup_bootstrap_search_path();
0N/A if (LazyBootClassLoader) {
0N/A // set up meta index which makes boot classpath initialization lazier
0N/A setup_meta_index();
0N/A }
0N/A}
0N/A
0N/A
0N/Ajlong ClassLoader::classloader_time_ms() {
0N/A return UsePerfData ?
0N/A Management::ticks_to_ms(_perf_accumulated_time->get_value()) : -1;
0N/A}
0N/A
0N/Ajlong ClassLoader::class_init_count() {
0N/A return UsePerfData ? _perf_classes_inited->get_value() : -1;
0N/A}
0N/A
0N/Ajlong ClassLoader::class_init_time_ms() {
0N/A return UsePerfData ?
0N/A Management::ticks_to_ms(_perf_class_init_time->get_value()) : -1;
0N/A}
0N/A
0N/Ajlong ClassLoader::class_verify_time_ms() {
0N/A return UsePerfData ?
0N/A Management::ticks_to_ms(_perf_class_verify_time->get_value()) : -1;
0N/A}
0N/A
0N/Ajlong ClassLoader::class_link_count() {
0N/A return UsePerfData ? _perf_classes_linked->get_value() : -1;
0N/A}
0N/A
0N/Ajlong ClassLoader::class_link_time_ms() {
0N/A return UsePerfData ?
0N/A Management::ticks_to_ms(_perf_class_link_time->get_value()) : -1;
0N/A}
0N/A
0N/Aint ClassLoader::compute_Object_vtable() {
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 int JDK_1_2_Object_vtable_size = 5;
0N/A return JDK_1_2_Object_vtable_size * vtableEntry::size();
0N/A}
0N/A
0N/A
0N/Avoid classLoader_init() {
0N/A ClassLoader::initialize();
0N/A}
0N/A
0N/A
0N/Abool ClassLoader::get_canonical_path(char* orig, char* out, int len) {
0N/A assert(orig != NULL && out != NULL && len > 0, "bad arguments");
0N/A if (CanonicalizeEntry != NULL) {
0N/A JNIEnv* env = JavaThread::current()->jni_environment();
1887N/A if ((CanonicalizeEntry)(env, os::native_path(orig), out, len) < 0) {
0N/A return false;
0N/A }
0N/A } else {
0N/A // On JDK 1.2.2 the Canonicalize does not exist, so just do nothing
0N/A strncpy(out, orig, len);
0N/A out[len - 1] = '\0';
0N/A }
0N/A return true;
0N/A}
0N/A
0N/A#ifndef PRODUCT
0N/A
0N/Avoid ClassLoader::verify() {
0N/A _package_hash_table->verify();
0N/A}
0N/A
0N/A
0N/A// CompileTheWorld
0N/A//
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//
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
0N/A
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//
0N/A// Note that this is only used in debug mode.
0N/A//
0N/A// HotSpot integration note:
0N/A// Matches zip_util.h 1.14 99/06/01 from jdk1.3 beta H build
0N/A
0N/A
0N/A// JDK 1.3 version
0N/Atypedef struct real_jzentry13 { /* Zip file entry */
0N/A char *name; /* entry name */
0N/A jint time; /* modification time */
0N/A jint size; /* size of uncompressed data */
0N/A jint csize; /* size of compressed data (zero if uncompressed) */
0N/A jint crc; /* crc of uncompressed data */
0N/A char *comment; /* optional zip file comment */
0N/A jbyte *extra; /* optional extra data */
0N/A jint pos; /* position of LOC header (if negative) or data */
0N/A} real_jzentry13;
0N/A
0N/Atypedef struct real_jzfile13 { /* Zip file */
0N/A char *name; /* zip file name */
0N/A jint refs; /* number of active references */
0N/A jint fd; /* open file descriptor */
0N/A void *lock; /* read lock */
0N/A char *comment; /* zip file comment */
0N/A char *msg; /* zip error message */
0N/A void *entries; /* array of hash cells */
0N/A jint total; /* total number of entries */
0N/A unsigned short *table; /* Hash chain heads: indexes into entries */
0N/A jint tablelen; /* number of hash eads */
0N/A real_jzfile13 *next; /* next zip file in search list */
0N/A jzentry *cache; /* we cache the most recently freed jzentry */
0N/A /* Information on metadata names in META-INF directory */
0N/A char **metanames; /* array of meta names (may have null names) */
0N/A jint metacount; /* number of slots in metanames array */
0N/A /* If there are any per-entry comments, they are in the comments array */
0N/A char **comments;
0N/A} real_jzfile13;
0N/A
0N/A// JDK 1.2 version
0N/Atypedef struct real_jzentry12 { /* Zip file entry */
0N/A char *name; /* entry name */
0N/A jint time; /* modification time */
0N/A jint size; /* size of uncompressed data */
0N/A jint csize; /* size of compressed data (zero if uncompressed) */
0N/A jint crc; /* crc of uncompressed data */
0N/A char *comment; /* optional zip file comment */
0N/A jbyte *extra; /* optional extra data */
0N/A jint pos; /* position of LOC header (if negative) or data */
0N/A struct real_jzentry12 *next; /* next entry in hash table */
0N/A} real_jzentry12;
0N/A
0N/Atypedef struct real_jzfile12 { /* Zip file */
0N/A char *name; /* zip file name */
0N/A jint refs; /* number of active references */
0N/A jint fd; /* open file descriptor */
0N/A void *lock; /* read lock */
0N/A char *comment; /* zip file comment */
0N/A char *msg; /* zip error message */
0N/A real_jzentry12 *entries; /* array of zip entries */
0N/A jint total; /* total number of entries */
0N/A real_jzentry12 **table; /* hash table of entries */
0N/A jint tablelen; /* number of buckets */
0N/A jzfile *next; /* next zip file in search list */
0N/A} real_jzfile12;
0N/A
0N/A
0N/Avoid ClassPathDirEntry::compile_the_world(Handle loader, TRAPS) {
0N/A // For now we only compile all methods in all classes in zip/jar files
0N/A tty->print_cr("CompileTheWorld : Skipped classes in %s", _dir);
0N/A tty->cr();
0N/A}
0N/A
0N/A
0N/Abool ClassPathDirEntry::is_rt_jar() {
0N/A return false;
0N/A}
0N/A
0N/Avoid ClassPathZipEntry::compile_the_world(Handle loader, TRAPS) {
0N/A if (JDK_Version::is_jdk12x_version()) {
0N/A compile_the_world12(loader, THREAD);
0N/A } else {
0N/A compile_the_world13(loader, THREAD);
0N/A }
0N/A if (HAS_PENDING_EXCEPTION) {
0N/A if (PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())) {
0N/A CLEAR_PENDING_EXCEPTION;
0N/A tty->print_cr("\nCompileTheWorld : Ran out of memory\n");
0N/A size_t used = Universe::heap()->permanent_used();
0N/A size_t capacity = Universe::heap()->permanent_capacity();
0N/A tty->print_cr("Permanent generation used %dK of %dK", used/K, capacity/K);
0N/A tty->print_cr("Increase size by setting e.g. -XX:MaxPermSize=%dK\n", capacity*2/K);
0N/A } else {
0N/A tty->print_cr("\nCompileTheWorld : Unexpected exception occurred\n");
0N/A }
0N/A }
0N/A}
0N/A
0N/A// Version that works for JDK 1.3.x
0N/Avoid ClassPathZipEntry::compile_the_world13(Handle loader, TRAPS) {
0N/A real_jzfile13* zip = (real_jzfile13*) _zip;
0N/A tty->print_cr("CompileTheWorld : Compiling all classes in %s", zip->name);
0N/A tty->cr();
0N/A // Iterate over all entries in zip file
0N/A for (int n = 0; ; n++) {
0N/A real_jzentry13 * ze = (real_jzentry13 *)((*GetNextEntry)(_zip, n));
0N/A if (ze == NULL) break;
0N/A ClassLoader::compile_the_world_in(ze->name, loader, CHECK);
0N/A }
0N/A}
0N/A
0N/A
0N/A// Version that works for JDK 1.2.x
0N/Avoid ClassPathZipEntry::compile_the_world12(Handle loader, TRAPS) {
0N/A real_jzfile12* zip = (real_jzfile12*) _zip;
0N/A tty->print_cr("CompileTheWorld : Compiling all classes in %s", zip->name);
0N/A tty->cr();
0N/A // Iterate over all entries in zip file
0N/A for (int n = 0; ; n++) {
0N/A real_jzentry12 * ze = (real_jzentry12 *)((*GetNextEntry)(_zip, n));
0N/A if (ze == NULL) break;
0N/A ClassLoader::compile_the_world_in(ze->name, loader, CHECK);
0N/A }
0N/A}
0N/A
0N/Abool ClassPathZipEntry::is_rt_jar() {
0N/A if (JDK_Version::is_jdk12x_version()) {
0N/A return is_rt_jar12();
0N/A } else {
0N/A return is_rt_jar13();
0N/A }
0N/A}
0N/A
0N/A// JDK 1.3 version
0N/Abool ClassPathZipEntry::is_rt_jar13() {
0N/A real_jzfile13* zip = (real_jzfile13*) _zip;
0N/A int len = (int)strlen(zip->name);
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 return (len >= 6) && (strcasecmp(zip->name + len - 6, "rt.jar") == 0);
0N/A}
0N/A
0N/A// JDK 1.2 version
0N/Abool ClassPathZipEntry::is_rt_jar12() {
0N/A real_jzfile12* zip = (real_jzfile12*) _zip;
0N/A int len = (int)strlen(zip->name);
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 return (len >= 6) && (strcasecmp(zip->name + len - 6, "rt.jar") == 0);
0N/A}
0N/A
0N/Avoid LazyClassPathEntry::compile_the_world(Handle loader, TRAPS) {
0N/A resolve_entry()->compile_the_world(loader, CHECK);
0N/A}
0N/A
0N/Abool LazyClassPathEntry::is_rt_jar() {
0N/A return resolve_entry()->is_rt_jar();
0N/A}
0N/A
0N/Avoid ClassLoader::compile_the_world() {
0N/A EXCEPTION_MARK;
0N/A HandleMark hm(THREAD);
0N/A ResourceMark rm(THREAD);
0N/A // Make sure we don't run with background compilation
0N/A BackgroundCompilation = false;
0N/A // Find bootstrap loader
0N/A Handle system_class_loader (THREAD, SystemDictionary::java_system_loader());
0N/A // Iterate over all bootstrap class path entries
0N/A ClassPathEntry* e = _first_entry;
0N/A while (e != NULL) {
0N/A // We stop at rt.jar, unless it is the first bootstrap path entry
0N/A if (e->is_rt_jar() && e != _first_entry) break;
0N/A e->compile_the_world(system_class_loader, CATCH);
0N/A e = e->next();
0N/A }
0N/A tty->print_cr("CompileTheWorld : Done");
0N/A {
0N/A // Print statistics as if before normal exit:
0N/A extern void print_statistics();
0N/A print_statistics();
0N/A }
0N/A vm_exit(0);
0N/A}
0N/A
0N/Aint ClassLoader::_compile_the_world_counter = 0;
1188N/Astatic int _codecache_sweep_counter = 0;
0N/A
2129N/A// Filter out all exceptions except OOMs
2129N/Astatic void clear_pending_exception_if_not_oom(TRAPS) {
2129N/A if (HAS_PENDING_EXCEPTION &&
2129N/A !PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())) {
2129N/A CLEAR_PENDING_EXCEPTION;
2129N/A }
2129N/A // The CHECK at the caller will propagate the exception out
2129N/A}
2129N/A
0N/Avoid ClassLoader::compile_the_world_in(char* name, Handle loader, TRAPS) {
0N/A int len = (int)strlen(name);
0N/A if (len > 6 && strcmp(".class", name + len - 6) == 0) {
0N/A // We have a .class file
0N/A char buffer[2048];
0N/A strncpy(buffer, name, len - 6);
0N/A buffer[len-6] = 0;
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 if (strchr(buffer, '.') == NULL) {
0N/A _compile_the_world_counter++;
723N/A if (_compile_the_world_counter > CompileTheWorldStopAt) return;
723N/A
723N/A // Construct name without extension
2062N/A TempNewSymbol sym = SymbolTable::new_symbol(buffer, CHECK);
723N/A // Use loader to load and initialize class
723N/A klassOop ik = SystemDictionary::resolve_or_null(sym, loader, Handle(), THREAD);
723N/A instanceKlassHandle k (THREAD, ik);
723N/A if (k.not_null() && !HAS_PENDING_EXCEPTION) {
723N/A k->initialize(THREAD);
723N/A }
723N/A bool exception_occurred = HAS_PENDING_EXCEPTION;
2129N/A clear_pending_exception_if_not_oom(CHECK);
723N/A if (CompileTheWorldPreloadClasses && k.not_null()) {
723N/A constantPoolKlass::preload_and_initialize_all_classes(k->constants(), THREAD);
723N/A if (HAS_PENDING_EXCEPTION) {
723N/A // If something went wrong in preloading we just ignore it
2129N/A clear_pending_exception_if_not_oom(CHECK);
723N/A tty->print_cr("Preloading failed for (%d) %s", _compile_the_world_counter, buffer);
0N/A }
723N/A }
723N/A
723N/A if (_compile_the_world_counter >= CompileTheWorldStartAt) {
2170N/A if (k.is_null() || exception_occurred) {
0N/A // If something went wrong (e.g. ExceptionInInitializerError) we skip this class
0N/A tty->print_cr("CompileTheWorld (%d) : Skipping %s", _compile_the_world_counter, buffer);
0N/A } else {
0N/A tty->print_cr("CompileTheWorld (%d) : %s", _compile_the_world_counter, buffer);
0N/A // Preload all classes to get around uncommon traps
0N/A // Iterate over all methods in class
0N/A for (int n = 0; n < k->methods()->length(); n++) {
0N/A methodHandle m (THREAD, methodOop(k->methods()->obj_at(n)));
1703N/A if (CompilationPolicy::can_be_compiled(m)) {
1188N/A
1188N/A if (++_codecache_sweep_counter == CompileTheWorldSafepointInterval) {
1188N/A // Give sweeper a chance to keep up with CTW
1188N/A VM_ForceSafepoint op;
1188N/A VMThread::execute(&op);
1188N/A _codecache_sweep_counter = 0;
1188N/A }
0N/A // Force compilation
2662N/A CompileBroker::compile_method(m, InvocationEntryBci, CompilationPolicy::policy()->initial_compile_level(),
0N/A methodHandle(), 0, "CTW", THREAD);
0N/A if (HAS_PENDING_EXCEPTION) {
2129N/A clear_pending_exception_if_not_oom(CHECK);
0N/A tty->print_cr("CompileTheWorld (%d) : Skipping method: %s", _compile_the_world_counter, m->name()->as_C_string());
0N/A }
2662N/A if (TieredCompilation && TieredStopAtLevel >= CompLevel_full_optimization) {
723N/A // Clobber the first compile and force second tier compilation
723N/A nmethod* nm = m->code();
723N/A if (nm != NULL) {
723N/A // Throw out the code so that the code cache doesn't fill up
723N/A nm->make_not_entrant();
723N/A m->clear_code();
723N/A }
1703N/A CompileBroker::compile_method(m, InvocationEntryBci, CompLevel_full_optimization,
723N/A methodHandle(), 0, "CTW", THREAD);
723N/A if (HAS_PENDING_EXCEPTION) {
2129N/A clear_pending_exception_if_not_oom(CHECK);
723N/A tty->print_cr("CompileTheWorld (%d) : Skipping method: %s", _compile_the_world_counter, m->name()->as_C_string());
723N/A }
0N/A }
0N/A }
723N/A
723N/A nmethod* nm = m->code();
723N/A if (nm != NULL) {
723N/A // Throw out the code so that the code cache doesn't fill up
723N/A nm->make_not_entrant();
723N/A m->clear_code();
0N/A }
0N/A }
0N/A }
0N/A }
0N/A }
0N/A }
0N/A}
0N/A
0N/A#endif //PRODUCT
2024N/A
2024N/A// Please keep following two functions at end of this file. With them placed at top or in middle of the file,
2024N/A// they could get inlined by agressive compiler, an unknown trick, see bug 6966589.
2024N/Avoid PerfClassTraceTime::initialize() {
2024N/A if (!UsePerfData) return;
2024N/A
2024N/A if (_eventp != NULL) {
2024N/A // increment the event counter
2024N/A _eventp->inc();
2024N/A }
2024N/A
2024N/A // stop the current active thread-local timer to measure inclusive time
2024N/A _prev_active_event = -1;
2024N/A for (int i=0; i < EVENT_TYPE_COUNT; i++) {
2024N/A if (_timers[i].is_active()) {
2024N/A assert(_prev_active_event == -1, "should have only one active timer");
2024N/A _prev_active_event = i;
2024N/A _timers[i].stop();
2024N/A }
2024N/A }
2024N/A
2024N/A if (_recursion_counters == NULL || (_recursion_counters[_event_type])++ == 0) {
2024N/A // start the inclusive timer if not recursively called
2024N/A _t.start();
2024N/A }
2024N/A
2024N/A // start thread-local timer of the given event type
2024N/A if (!_timers[_event_type].is_active()) {
2024N/A _timers[_event_type].start();
2024N/A }
2024N/A}
2024N/A
2024N/APerfClassTraceTime::~PerfClassTraceTime() {
2024N/A if (!UsePerfData) return;
2024N/A
2024N/A // stop the thread-local timer as the event completes
2024N/A // and resume the thread-local timer of the event next on the stack
2024N/A _timers[_event_type].stop();
2024N/A jlong selftime = _timers[_event_type].ticks();
2024N/A
2024N/A if (_prev_active_event >= 0) {
2024N/A _timers[_prev_active_event].start();
2024N/A }
2024N/A
2024N/A if (_recursion_counters != NULL && --(_recursion_counters[_event_type]) > 0) return;
2024N/A
2024N/A // increment the counters only on the leaf call
2024N/A _t.stop();
2024N/A _timep->inc(_t.ticks());
2024N/A if (_selftimep != NULL) {
2024N/A _selftimep->inc(selftime);
2024N/A }
2024N/A // add all class loading related event selftime to the accumulated time counter
2024N/A ClassLoader::perf_accumulated_time()->inc(selftime);
2024N/A
2024N/A // reset the timer
2024N/A _timers[_event_type].reset();
2024N/A}