src/share/vm/classfile/classLoader.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File classpath.06 Sdiff src/share/vm/classfile

src/share/vm/classfile/classLoader.cpp

Print this page




  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/classFileStream.hpp"
  27 #include "classfile/classLoader.hpp"
  28 #include "classfile/classLoaderData.inline.hpp"
  29 #include "classfile/classLoaderExt.hpp"
  30 #include "classfile/javaClasses.hpp"
  31 #include "classfile/jimage.hpp"
  32 #include "classfile/klassFactory.hpp"
  33 #include "classfile/systemDictionary.hpp"
  34 #include "classfile/vmSymbols.hpp"
  35 #include "compiler/compileBroker.hpp"
  36 #include "gc/shared/collectedHeap.inline.hpp"
  37 #include "gc/shared/generation.hpp"
  38 #include "interpreter/bytecodeStream.hpp"
  39 #include "interpreter/oopMapCache.hpp"

  40 #include "memory/allocation.inline.hpp"
  41 #include "memory/filemap.hpp"
  42 #include "memory/oopFactory.hpp"
  43 #include "memory/universe.inline.hpp"
  44 #include "oops/instanceKlass.hpp"
  45 #include "oops/instanceRefKlass.hpp"
  46 #include "oops/objArrayOop.inline.hpp"
  47 #include "oops/oop.inline.hpp"
  48 #include "oops/symbol.hpp"
  49 #include "prims/jvm_misc.hpp"
  50 #include "runtime/arguments.hpp"
  51 #include "runtime/compilationPolicy.hpp"
  52 #include "runtime/fprofiler.hpp"
  53 #include "runtime/handles.hpp"
  54 #include "runtime/handles.inline.hpp"
  55 #include "runtime/init.hpp"
  56 #include "runtime/interfaceSupport.hpp"
  57 #include "runtime/java.hpp"
  58 #include "runtime/javaCalls.hpp"
  59 #include "runtime/os.hpp"


 400   (*JImageResourceIterator)(_jimage, (JImageResourceVisitor_t)ctw_visitor, (void *)&loader);
 401   if (HAS_PENDING_EXCEPTION) {
 402     if (PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())) {
 403       CLEAR_PENDING_EXCEPTION;
 404       tty->print_cr("\nCompileTheWorld : Ran out of memory\n");
 405       tty->print_cr("Increase class metadata storage if a limit was set");
 406     } else {
 407       tty->print_cr("\nCompileTheWorld : Unexpected exception occurred\n");
 408     }
 409   }
 410 }
 411 
 412 bool ClassPathImageEntry::is_jrt() {
 413   return string_ends_with(name(), BOOT_IMAGE_NAME);
 414 }
 415 #endif
 416 
 417 #if INCLUDE_CDS
 418 void ClassLoader::exit_with_path_failure(const char* error, const char* message) {
 419   assert(DumpSharedSpaces, "only called at dump time");
 420   tty->print_cr("Hint: enable -XX:+TraceClassPaths to diagnose the failure");
 421   vm_exit_during_initialization(error, message);
 422 }
 423 #endif
 424 
 425 void ClassLoader::trace_class_path(outputStream* out, const char* msg, const char* name) {
 426   if (!TraceClassPaths) {
 427     return;
 428   }
 429 
 430   if (msg) {
 431     out->print("%s", msg);
 432   }
 433   if (name) {
 434     if (strlen(name) < 256) {
 435       out->print("%s", name);
 436     } else {
 437       // For very long paths, we need to print each character separately,
 438       // as print_cr() has a length limit
 439       while (name[0] != '\0') {
 440         out->print("%c", name[0]);
 441         name++;
 442       }
 443     }
 444   }
 445   if (msg && msg[0] == '[') {
 446     out->print_cr("]");
 447   } else {
 448     out->cr();
 449   }
 450 }
 451 
 452 #if INCLUDE_CDS
 453 void ClassLoader::check_shared_classpath(const char *path) {
 454   if (strcmp(path, "") == 0) {
 455     exit_with_path_failure("Cannot have empty path in archived classpaths", NULL);
 456   }
 457 
 458   struct stat st;
 459   if (os::stat(path, &st) == 0) {
 460     if ((st.st_mode & S_IFREG) != S_IFREG) { // is directory
 461       if (!os::dir_is_empty(path)) {
 462         tty->print_cr("Error: non-empty directory '%s'", path);
 463         exit_with_path_failure("CDS allows only empty directories in archived classpaths", NULL);
 464       }
 465     }
 466   }
 467 }
 468 #endif
 469 
 470 void ClassLoader::setup_bootstrap_search_path() {
 471   assert(_first_entry == NULL, "should not setup bootstrap class search path twice");
 472   const char* sys_class_path = Arguments::get_sysclasspath();

 473   if (PrintSharedArchiveAndExit) {
 474     // Don't print sys_class_path - this is the bootcp of this current VM process, not necessarily
 475     // the same as the bootcp of the shared archive.
 476   } else {
 477     trace_class_path(tty, "[Bootstrap loader class path=", sys_class_path);

 478   }
 479 #if INCLUDE_CDS
 480   if (DumpSharedSpaces) {
 481     _shared_paths_misc_info->add_boot_classpath(sys_class_path);
 482   }
 483 #endif
 484   setup_search_path(sys_class_path);
 485 }
 486 
 487 #if INCLUDE_CDS
 488 int ClassLoader::get_shared_paths_misc_info_size() {
 489   return _shared_paths_misc_info->get_used_bytes();
 490 }
 491 
 492 void* ClassLoader::get_shared_paths_misc_info() {
 493   return _shared_paths_misc_info->buffer();
 494 }
 495 
 496 bool ClassLoader::check_shared_paths_misc_info(void *buf, int size) {
 497   SharedPathsMiscInfo* checker = SharedClassUtil::allocate_shared_paths_misc_info((char*)buf, size);


 561         new_entry = new ClassPathZipEntry(zip, path);
 562       } else {
 563         ResourceMark rm(thread);
 564         char *msg;
 565         if (error_msg == NULL) {
 566           msg = NEW_RESOURCE_ARRAY(char, strlen(path) + 128); ;
 567           jio_snprintf(msg, strlen(path) + 127, "error in opening JAR file %s", path);
 568         } else {
 569           int len = (int)(strlen(path) + strlen(error_msg) + 128);
 570           msg = NEW_RESOURCE_ARRAY(char, len); ;
 571           jio_snprintf(msg, len - 1, "error in opening JAR file <%s> %s", error_msg, path);
 572         }
 573         // Don't complain about bad jar files added via -Xbootclasspath/a:.
 574         if (throw_exception && is_init_completed()) {
 575           THROW_MSG_(vmSymbols::java_lang_ClassNotFoundException(), msg, NULL);
 576         } else {
 577           return NULL;
 578         }
 579       }
 580     }
 581     if (TraceClassPaths) {
 582       tty->print_cr("[Opened %s]", path);
 583     }
 584     log_info(classload)("opened: %s", path);
 585   } else {
 586     // Directory
 587     new_entry = new ClassPathDirEntry(path);
 588     log_info(classload)("path: %s", path);
 589   }
 590   return new_entry;
 591 }
 592 
 593 
 594 // Create a class path zip entry for a given path (return NULL if not found
 595 // or zip/JAR file cannot be opened)
 596 ClassPathZipEntry* ClassLoader::create_class_path_zip_entry(const char *path) {
 597   // check for a regular file
 598   struct stat st;
 599   if (os::stat(path, &st) == 0) {
 600     if ((st.st_mode & S_IFREG) == S_IFREG) {
 601       char canonical_path[JVM_MAXPATHLEN];
 602       if (get_canonical_path(path, canonical_path, JVM_MAXPATHLEN)) {
 603         char* error_msg = NULL;




  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/classFileStream.hpp"
  27 #include "classfile/classLoader.hpp"
  28 #include "classfile/classLoaderData.inline.hpp"
  29 #include "classfile/classLoaderExt.hpp"
  30 #include "classfile/javaClasses.hpp"
  31 #include "classfile/jimage.hpp"
  32 #include "classfile/klassFactory.hpp"
  33 #include "classfile/systemDictionary.hpp"
  34 #include "classfile/vmSymbols.hpp"
  35 #include "compiler/compileBroker.hpp"
  36 #include "gc/shared/collectedHeap.inline.hpp"
  37 #include "gc/shared/generation.hpp"
  38 #include "interpreter/bytecodeStream.hpp"
  39 #include "interpreter/oopMapCache.hpp"
  40 #include "logging/logTag.hpp"
  41 #include "memory/allocation.inline.hpp"
  42 #include "memory/filemap.hpp"
  43 #include "memory/oopFactory.hpp"
  44 #include "memory/universe.inline.hpp"
  45 #include "oops/instanceKlass.hpp"
  46 #include "oops/instanceRefKlass.hpp"
  47 #include "oops/objArrayOop.inline.hpp"
  48 #include "oops/oop.inline.hpp"
  49 #include "oops/symbol.hpp"
  50 #include "prims/jvm_misc.hpp"
  51 #include "runtime/arguments.hpp"
  52 #include "runtime/compilationPolicy.hpp"
  53 #include "runtime/fprofiler.hpp"
  54 #include "runtime/handles.hpp"
  55 #include "runtime/handles.inline.hpp"
  56 #include "runtime/init.hpp"
  57 #include "runtime/interfaceSupport.hpp"
  58 #include "runtime/java.hpp"
  59 #include "runtime/javaCalls.hpp"
  60 #include "runtime/os.hpp"


 401   (*JImageResourceIterator)(_jimage, (JImageResourceVisitor_t)ctw_visitor, (void *)&loader);
 402   if (HAS_PENDING_EXCEPTION) {
 403     if (PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())) {
 404       CLEAR_PENDING_EXCEPTION;
 405       tty->print_cr("\nCompileTheWorld : Ran out of memory\n");
 406       tty->print_cr("Increase class metadata storage if a limit was set");
 407     } else {
 408       tty->print_cr("\nCompileTheWorld : Unexpected exception occurred\n");
 409     }
 410   }
 411 }
 412 
 413 bool ClassPathImageEntry::is_jrt() {
 414   return string_ends_with(name(), BOOT_IMAGE_NAME);
 415 }
 416 #endif
 417 
 418 #if INCLUDE_CDS
 419 void ClassLoader::exit_with_path_failure(const char* error, const char* message) {
 420   assert(DumpSharedSpaces, "only called at dump time");
 421   tty->print_cr("Hint: enable -Xlog:classpath=info to diagnose the failure");
 422   vm_exit_during_initialization(error, message);
 423 }
 424 #endif
 425 
 426 void ClassLoader::trace_class_path(const char* msg, const char* name) {
 427   if (log_is_enabled(Info, classpath)) {
 428     ResourceMark rm;
 429     outputStream* out = LogHandle(classpath)::info_stream();

 430     if (msg) {
 431       out->print("%s", msg);
 432     }
 433     if (name) {
 434       if (strlen(name) < 256) {
 435         out->print("%s", name);
 436       } else {
 437         // For very long paths, we need to print each character separately,
 438         // as print_cr() has a length limit
 439         while (name[0] != '\0') {
 440           out->print("%c", name[0]);
 441           name++;
 442         }
 443       }
 444     }



 445     out->cr();
 446   }
 447 }
 448 
 449 #if INCLUDE_CDS
 450 void ClassLoader::check_shared_classpath(const char *path) {
 451   if (strcmp(path, "") == 0) {
 452     exit_with_path_failure("Cannot have empty path in archived classpaths", NULL);
 453   }
 454 
 455   struct stat st;
 456   if (os::stat(path, &st) == 0) {
 457     if ((st.st_mode & S_IFREG) != S_IFREG) { // is directory
 458       if (!os::dir_is_empty(path)) {
 459         tty->print_cr("Error: non-empty directory '%s'", path);
 460         exit_with_path_failure("CDS allows only empty directories in archived classpaths", NULL);
 461       }
 462     }
 463   }
 464 }
 465 #endif
 466 
 467 void ClassLoader::setup_bootstrap_search_path() {
 468   assert(_first_entry == NULL, "should not setup bootstrap class search path twice");
 469   const char* sys_class_path = Arguments::get_sysclasspath();
 470   const char* java_class_path = Arguments::get_appclasspath();
 471   if (PrintSharedArchiveAndExit) {
 472     // Don't print sys_class_path - this is the bootcp of this current VM process, not necessarily
 473     // the same as the bootcp of the shared archive.
 474   } else {
 475     trace_class_path("bootstrap loader class path=", sys_class_path);
 476     trace_class_path("classpath: ", java_class_path);
 477   }
 478 #if INCLUDE_CDS
 479   if (DumpSharedSpaces) {
 480     _shared_paths_misc_info->add_boot_classpath(sys_class_path);
 481   }
 482 #endif
 483   setup_search_path(sys_class_path);
 484 }
 485 
 486 #if INCLUDE_CDS
 487 int ClassLoader::get_shared_paths_misc_info_size() {
 488   return _shared_paths_misc_info->get_used_bytes();
 489 }
 490 
 491 void* ClassLoader::get_shared_paths_misc_info() {
 492   return _shared_paths_misc_info->buffer();
 493 }
 494 
 495 bool ClassLoader::check_shared_paths_misc_info(void *buf, int size) {
 496   SharedPathsMiscInfo* checker = SharedClassUtil::allocate_shared_paths_misc_info((char*)buf, size);


 560         new_entry = new ClassPathZipEntry(zip, path);
 561       } else {
 562         ResourceMark rm(thread);
 563         char *msg;
 564         if (error_msg == NULL) {
 565           msg = NEW_RESOURCE_ARRAY(char, strlen(path) + 128); ;
 566           jio_snprintf(msg, strlen(path) + 127, "error in opening JAR file %s", path);
 567         } else {
 568           int len = (int)(strlen(path) + strlen(error_msg) + 128);
 569           msg = NEW_RESOURCE_ARRAY(char, len); ;
 570           jio_snprintf(msg, len - 1, "error in opening JAR file <%s> %s", error_msg, path);
 571         }
 572         // Don't complain about bad jar files added via -Xbootclasspath/a:.
 573         if (throw_exception && is_init_completed()) {
 574           THROW_MSG_(vmSymbols::java_lang_ClassNotFoundException(), msg, NULL);
 575         } else {
 576           return NULL;
 577         }
 578       }
 579     }
 580     log_info(classpath)("opened: %s", path);


 581     log_info(classload)("opened: %s", path);
 582   } else {
 583     // Directory
 584     new_entry = new ClassPathDirEntry(path);
 585     log_info(classload)("path: %s", path);
 586   }
 587   return new_entry;
 588 }
 589 
 590 
 591 // Create a class path zip entry for a given path (return NULL if not found
 592 // or zip/JAR file cannot be opened)
 593 ClassPathZipEntry* ClassLoader::create_class_path_zip_entry(const char *path) {
 594   // check for a regular file
 595   struct stat st;
 596   if (os::stat(path, &st) == 0) {
 597     if ((st.st_mode & S_IFREG) == S_IFREG) {
 598       char canonical_path[JVM_MAXPATHLEN];
 599       if (get_canonical_path(path, canonical_path, JVM_MAXPATHLEN)) {
 600         char* error_msg = NULL;


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