src/share/vm/memory/filemap.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File classload.03 Sdiff src/share/vm/memory

src/share/vm/memory/filemap.cpp

Print this page


   1 /*
   2  * Copyright (c) 2003, 2015, 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.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


 191   int bytes = 0;
 192   int count = 0;
 193   char* strptr = NULL;
 194   char* strptr_max = NULL;
 195   Thread* THREAD = Thread::current();
 196 
 197   ClassLoaderData* loader_data = ClassLoaderData::the_null_class_loader_data();
 198   size_t entry_size = SharedClassUtil::shared_class_path_entry_size();
 199 
 200   for (int pass=0; pass<2; pass++) {
 201     ClassPathEntry *cpe = ClassLoader::classpath_entry(0);
 202 
 203     for (int cur_entry = 0 ; cpe != NULL; cpe = cpe->next(), cur_entry++) {
 204       const char *name = cpe->name();
 205       int name_bytes = (int)(strlen(name) + 1);
 206 
 207       if (pass == 0) {
 208         count ++;
 209         bytes += (int)entry_size;
 210         bytes += name_bytes;
 211         if (TraceClassPaths || (TraceClassLoading && Verbose)) {
 212           tty->print_cr("[Add main shared path (%s) %s]", (cpe->is_jar_file() ? "jar" : "dir"), name);
 213         }
 214       } else {
 215         SharedClassPathEntry* ent = shared_classpath(cur_entry);
 216         if (cpe->is_jar_file()) {
 217           struct stat st;
 218           if (os::stat(name, &st) != 0) {
 219             // The file/dir must exist, or it would not have been added
 220             // into ClassLoader::classpath_entry().
 221             //
 222             // If we can't access a jar file in the boot path, then we can't
 223             // make assumptions about where classes get loaded from.
 224             FileMapInfo::fail_stop("Unable to open jar file %s.", name);
 225           }
 226 
 227           EXCEPTION_MARK; // The following call should never throw, but would exit VM on error.
 228           SharedClassUtil::update_shared_classpath(cpe, ent, st.st_mtime, st.st_size, THREAD);
 229         } else {
 230           struct stat st;
 231           if ((os::stat(name, &st) == 0) && ((st.st_mode & S_IFDIR) == S_IFDIR)) {


 258       _classpath_entry_table_size = count;
 259       _classpath_entry_table = table;
 260       _classpath_entry_size = entry_size;
 261     }
 262   }
 263 }
 264 
 265 bool FileMapInfo::validate_classpath_entry_table() {
 266   _validating_classpath_entry_table = true;
 267 
 268   int count = _header->_classpath_entry_table_size;
 269 
 270   _classpath_entry_table = _header->_classpath_entry_table;
 271   _classpath_entry_size = _header->_classpath_entry_size;
 272 
 273   for (int i=0; i<count; i++) {
 274     SharedClassPathEntry* ent = shared_classpath(i);
 275     struct stat st;
 276     const char* name = ent->_name;
 277     bool ok = true;
 278     if (TraceClassPaths || (TraceClassLoading && Verbose)) {
 279       tty->print_cr("[Checking shared classpath entry: %s]", name);
 280     }
 281     if (os::stat(name, &st) != 0) {
 282       fail_continue("Required classpath entry does not exist: %s", name);
 283       ok = false;
 284     } else if (ent->is_dir()) {
 285       if (!os::dir_is_empty(name)) {
 286         fail_continue("directory is not empty: %s", name);
 287         ok = false;
 288       }
 289     } else if (ent->is_jar()) {
 290       if (ent->_timestamp != st.st_mtime ||
 291           ent->_filesize != st.st_size) {
 292         ok = false;
 293         if (PrintSharedArchiveAndExit) {
 294           fail_continue(ent->_timestamp != st.st_mtime ?
 295                         "Timestamp mismatch" :
 296                         "File size mismatch");
 297         } else {
 298           fail_continue("A jar file is not the one used while building"
 299                         " the shared archive file: %s", name);
 300         }
 301       }
 302     }
 303     if (ok) {
 304       if (TraceClassPaths || (TraceClassLoading && Verbose)) {
 305         tty->print_cr("[ok]");
 306       }
 307     } else if (!PrintSharedArchiveAndExit) {
 308       _validating_classpath_entry_table = false;
 309       return false;
 310     }
 311   }
 312 
 313   _classpath_entry_table_size = _header->_classpath_entry_table_size;
 314   _validating_classpath_entry_table = false;
 315   return true;
 316 }
 317 
 318 
 319 // Read the FileMapInfo information from the file.
 320 
 321 bool FileMapInfo::init_from_file(int fd) {
 322   size_t sz = _header->data_size();
 323   char* addr = _header->data();
 324   size_t n = os::read(fd, addr, (unsigned int)sz);


   1 /*
   2  * Copyright (c) 2003, 2016, 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.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


 191   int bytes = 0;
 192   int count = 0;
 193   char* strptr = NULL;
 194   char* strptr_max = NULL;
 195   Thread* THREAD = Thread::current();
 196 
 197   ClassLoaderData* loader_data = ClassLoaderData::the_null_class_loader_data();
 198   size_t entry_size = SharedClassUtil::shared_class_path_entry_size();
 199 
 200   for (int pass=0; pass<2; pass++) {
 201     ClassPathEntry *cpe = ClassLoader::classpath_entry(0);
 202 
 203     for (int cur_entry = 0 ; cpe != NULL; cpe = cpe->next(), cur_entry++) {
 204       const char *name = cpe->name();
 205       int name_bytes = (int)(strlen(name) + 1);
 206 
 207       if (pass == 0) {
 208         count ++;
 209         bytes += (int)entry_size;
 210         bytes += name_bytes;
 211         if (TraceClassPaths) {
 212           tty->print_cr("[Add main shared path (%s) %s]", (cpe->is_jar_file() ? "jar" : "dir"), name);
 213         }
 214       } else {
 215         SharedClassPathEntry* ent = shared_classpath(cur_entry);
 216         if (cpe->is_jar_file()) {
 217           struct stat st;
 218           if (os::stat(name, &st) != 0) {
 219             // The file/dir must exist, or it would not have been added
 220             // into ClassLoader::classpath_entry().
 221             //
 222             // If we can't access a jar file in the boot path, then we can't
 223             // make assumptions about where classes get loaded from.
 224             FileMapInfo::fail_stop("Unable to open jar file %s.", name);
 225           }
 226 
 227           EXCEPTION_MARK; // The following call should never throw, but would exit VM on error.
 228           SharedClassUtil::update_shared_classpath(cpe, ent, st.st_mtime, st.st_size, THREAD);
 229         } else {
 230           struct stat st;
 231           if ((os::stat(name, &st) == 0) && ((st.st_mode & S_IFDIR) == S_IFDIR)) {


 258       _classpath_entry_table_size = count;
 259       _classpath_entry_table = table;
 260       _classpath_entry_size = entry_size;
 261     }
 262   }
 263 }
 264 
 265 bool FileMapInfo::validate_classpath_entry_table() {
 266   _validating_classpath_entry_table = true;
 267 
 268   int count = _header->_classpath_entry_table_size;
 269 
 270   _classpath_entry_table = _header->_classpath_entry_table;
 271   _classpath_entry_size = _header->_classpath_entry_size;
 272 
 273   for (int i=0; i<count; i++) {
 274     SharedClassPathEntry* ent = shared_classpath(i);
 275     struct stat st;
 276     const char* name = ent->_name;
 277     bool ok = true;
 278     if (TraceClassPaths) {
 279       tty->print_cr("[Checking shared classpath entry: %s]", name);
 280     }
 281     if (os::stat(name, &st) != 0) {
 282       fail_continue("Required classpath entry does not exist: %s", name);
 283       ok = false;
 284     } else if (ent->is_dir()) {
 285       if (!os::dir_is_empty(name)) {
 286         fail_continue("directory is not empty: %s", name);
 287         ok = false;
 288       }
 289     } else if (ent->is_jar()) {
 290       if (ent->_timestamp != st.st_mtime ||
 291           ent->_filesize != st.st_size) {
 292         ok = false;
 293         if (PrintSharedArchiveAndExit) {
 294           fail_continue(ent->_timestamp != st.st_mtime ?
 295                         "Timestamp mismatch" :
 296                         "File size mismatch");
 297         } else {
 298           fail_continue("A jar file is not the one used while building"
 299                         " the shared archive file: %s", name);
 300         }
 301       }
 302     }
 303     if (ok) {
 304       if (TraceClassPaths) {
 305         tty->print_cr("[ok]");
 306       }
 307     } else if (!PrintSharedArchiveAndExit) {
 308       _validating_classpath_entry_table = false;
 309       return false;
 310     }
 311   }
 312 
 313   _classpath_entry_table_size = _header->_classpath_entry_table_size;
 314   _validating_classpath_entry_table = false;
 315   return true;
 316 }
 317 
 318 
 319 // Read the FileMapInfo information from the file.
 320 
 321 bool FileMapInfo::init_from_file(int fd) {
 322   size_t sz = _header->data_size();
 323   char* addr = _header->data();
 324   size_t n = os::read(fd, addr, (unsigned int)sz);


src/share/vm/memory/filemap.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File