src/share/vm/classfile/classLoader.hpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File bug_8068687_metaindex Sdiff src/share/vm/classfile

src/share/vm/classfile/classLoader.hpp

Print this page


   1 /*
   2  * Copyright (c) 1997, 2014, 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  *
  23  */
  24 
  25 #ifndef SHARE_VM_CLASSFILE_CLASSLOADER_HPP
  26 #define SHARE_VM_CLASSFILE_CLASSLOADER_HPP
  27 
  28 #include "classfile/classFileParser.hpp"
  29 #include "runtime/perfData.hpp"
  30 #include "utilities/macros.hpp"
  31 
  32 // The VM class loader.
  33 #include <sys/stat.h>
  34 
  35 
  36 // Meta-index (optional, to be able to skip opening boot classpath jar files)
  37 class MetaIndex: public CHeapObj<mtClass> {
  38  private:
  39   char** _meta_package_names;
  40   int    _num_meta_package_names;
  41  public:
  42   MetaIndex(char** meta_package_names, int num_meta_package_names);
  43   ~MetaIndex();
  44   bool may_contain(const char* class_name);
  45 };
  46 
  47 
  48 // Class path entry (directory or zip file)
  49 
  50 class ClassPathEntry: public CHeapObj<mtClass> {
  51  private:
  52   ClassPathEntry* _next;
  53  public:
  54   // Next entry in class path
  55   ClassPathEntry* next()              { return _next; }
  56   void set_next(ClassPathEntry* next) {
  57     // may have unlocked readers, so write atomically.
  58     OrderAccess::release_store_ptr(&_next, next);
  59   }
  60   virtual bool is_jar_file() = 0;
  61   virtual const char* name() = 0;
  62   virtual bool is_lazy();
  63   // Constructor
  64   ClassPathEntry();
  65   // Attempt to locate file_name through this class path entry.
  66   // Returns a class file parsing stream if successfull.
  67   virtual ClassFileStream* open_stream(const char* name, TRAPS) = 0;


 105   const char*   _zip_name;   // Name of zip archive
 106  public:
 107   bool is_jar_file()  { return true;  }
 108   const char* name()  { return _zip_name; }
 109   ClassPathZipEntry(jzfile* zip, const char* zip_name);
 110   ~ClassPathZipEntry();
 111   u1* open_entry(const char* name, jint* filesize, bool nul_terminate, TRAPS);
 112   ClassFileStream* open_stream(const char* name, TRAPS);
 113   void contents_do(void f(const char* name, void* context), void* context);
 114   // Debugging
 115   NOT_PRODUCT(void compile_the_world(Handle loader, TRAPS);)
 116   NOT_PRODUCT(bool is_jrt();)
 117 };
 118 
 119 
 120 // For lazier loading of boot class path entries
 121 class LazyClassPathEntry: public ClassPathEntry {
 122  private:
 123   const char* _path; // dir or file
 124   struct stat _st;
 125   MetaIndex* _meta_index;
 126   bool _has_error;
 127   bool _throw_exception;
 128   volatile ClassPathEntry* _resolved_entry;
 129   ClassPathEntry* resolve_entry(TRAPS);
 130  public:
 131   bool is_jar_file();
 132   const char* name()  { return _path; }
 133   LazyClassPathEntry(const char* path, const struct stat* st, bool throw_exception);
 134   virtual ~LazyClassPathEntry();
 135   u1* open_entry(const char* name, jint* filesize, bool nul_terminate, TRAPS);
 136 
 137   ClassFileStream* open_stream(const char* name, TRAPS);
 138   void set_meta_index(MetaIndex* meta_index) { _meta_index = meta_index; }
 139   virtual bool is_lazy();
 140   // Debugging
 141   NOT_PRODUCT(void compile_the_world(Handle loader, TRAPS);)
 142   NOT_PRODUCT(bool is_jrt();)
 143 };
 144 
 145 // For java image files
 146 class ImageFile;
 147 class ClassPathImageEntry: public ClassPathEntry {
 148 private:
 149   ImageFile *_image;
 150 public:
 151   bool is_jar_file()  { return false;  }
 152   bool is_open()  { return _image != NULL; }
 153   const char* name();
 154   ClassPathImageEntry(char* name);
 155   ~ClassPathImageEntry();
 156   ClassFileStream* open_stream(const char* name, TRAPS);
 157 
 158   // Debugging


 214   static ClassPathEntry* _last_entry;
 215   static int _num_entries;
 216 
 217   // Hash table used to keep track of loaded packages
 218   static PackageHashtable* _package_hash_table;
 219   static const char* _shared_archive;
 220 
 221   // Info used by CDS
 222   CDS_ONLY(static SharedPathsMiscInfo * _shared_paths_misc_info;)
 223 
 224   // Hash function
 225   static unsigned int hash(const char *s, int n);
 226   // Returns the package file name corresponding to the specified package
 227   // or class name, or null if not found.
 228   static PackageInfo* lookup_package(const char *pkgname);
 229   // Adds a new package entry for the specified class or package name and
 230   // corresponding directory or jar file name.
 231   static bool add_package(const char *pkgname, int classpath_index, TRAPS);
 232 
 233   // Initialization
 234   static void setup_bootstrap_meta_index();
 235   static void setup_meta_index(const char* meta_index_path, const char* meta_index_dir,
 236                                int start_index);
 237   static void setup_bootstrap_search_path();
 238   static void setup_search_path(const char *class_path);
 239 
 240   static void load_zip_library();
 241   static ClassPathEntry* create_class_path_entry(const char *path, const struct stat* st,
 242                                                  bool lazy, bool throw_exception, TRAPS);
 243 
 244   // Canonicalizes path names, so strcmp will work properly. This is mainly
 245   // to avoid confusing the zip library
 246   static bool get_canonical_path(const char* orig, char* out, int len);
 247  public:
 248   static jboolean decompress(void *in, u8 inSize, void *out, u8 outSize, char **pmsg);
 249   static int crc32(int crc, const char* buf, int len);
 250   static bool update_class_path_entry_list(const char *path,
 251                                            bool check_for_duplicates,
 252                                            bool throw_exception=true);
 253   static void print_bootclasspath();
 254 
 255   // Timing
 256   static PerfCounter* perf_accumulated_time()         { return _perf_accumulated_time; }


   1 /*
   2  * Copyright (c) 1997, 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  *
  23  */
  24 
  25 #ifndef SHARE_VM_CLASSFILE_CLASSLOADER_HPP
  26 #define SHARE_VM_CLASSFILE_CLASSLOADER_HPP
  27 
  28 #include "classfile/classFileParser.hpp"
  29 #include "runtime/perfData.hpp"
  30 #include "utilities/macros.hpp"
  31 
  32 // The VM class loader.
  33 #include <sys/stat.h>
  34 
  35 












  36 // Class path entry (directory or zip file)
  37 
  38 class ClassPathEntry: public CHeapObj<mtClass> {
  39  private:
  40   ClassPathEntry* _next;
  41  public:
  42   // Next entry in class path
  43   ClassPathEntry* next()              { return _next; }
  44   void set_next(ClassPathEntry* next) {
  45     // may have unlocked readers, so write atomically.
  46     OrderAccess::release_store_ptr(&_next, next);
  47   }
  48   virtual bool is_jar_file() = 0;
  49   virtual const char* name() = 0;
  50   virtual bool is_lazy();
  51   // Constructor
  52   ClassPathEntry();
  53   // Attempt to locate file_name through this class path entry.
  54   // Returns a class file parsing stream if successfull.
  55   virtual ClassFileStream* open_stream(const char* name, TRAPS) = 0;


  93   const char*   _zip_name;   // Name of zip archive
  94  public:
  95   bool is_jar_file()  { return true;  }
  96   const char* name()  { return _zip_name; }
  97   ClassPathZipEntry(jzfile* zip, const char* zip_name);
  98   ~ClassPathZipEntry();
  99   u1* open_entry(const char* name, jint* filesize, bool nul_terminate, TRAPS);
 100   ClassFileStream* open_stream(const char* name, TRAPS);
 101   void contents_do(void f(const char* name, void* context), void* context);
 102   // Debugging
 103   NOT_PRODUCT(void compile_the_world(Handle loader, TRAPS);)
 104   NOT_PRODUCT(bool is_jrt();)
 105 };
 106 
 107 
 108 // For lazier loading of boot class path entries
 109 class LazyClassPathEntry: public ClassPathEntry {
 110  private:
 111   const char* _path; // dir or file
 112   struct stat _st;

 113   bool _has_error;
 114   bool _throw_exception;
 115   volatile ClassPathEntry* _resolved_entry;
 116   ClassPathEntry* resolve_entry(TRAPS);
 117  public:
 118   bool is_jar_file();
 119   const char* name()  { return _path; }
 120   LazyClassPathEntry(const char* path, const struct stat* st, bool throw_exception);
 121   virtual ~LazyClassPathEntry();
 122   u1* open_entry(const char* name, jint* filesize, bool nul_terminate, TRAPS);
 123 
 124   ClassFileStream* open_stream(const char* name, TRAPS);

 125   virtual bool is_lazy();
 126   // Debugging
 127   NOT_PRODUCT(void compile_the_world(Handle loader, TRAPS);)
 128   NOT_PRODUCT(bool is_jrt();)
 129 };
 130 
 131 // For java image files
 132 class ImageFile;
 133 class ClassPathImageEntry: public ClassPathEntry {
 134 private:
 135   ImageFile *_image;
 136 public:
 137   bool is_jar_file()  { return false;  }
 138   bool is_open()  { return _image != NULL; }
 139   const char* name();
 140   ClassPathImageEntry(char* name);
 141   ~ClassPathImageEntry();
 142   ClassFileStream* open_stream(const char* name, TRAPS);
 143 
 144   // Debugging


 200   static ClassPathEntry* _last_entry;
 201   static int _num_entries;
 202 
 203   // Hash table used to keep track of loaded packages
 204   static PackageHashtable* _package_hash_table;
 205   static const char* _shared_archive;
 206 
 207   // Info used by CDS
 208   CDS_ONLY(static SharedPathsMiscInfo * _shared_paths_misc_info;)
 209 
 210   // Hash function
 211   static unsigned int hash(const char *s, int n);
 212   // Returns the package file name corresponding to the specified package
 213   // or class name, or null if not found.
 214   static PackageInfo* lookup_package(const char *pkgname);
 215   // Adds a new package entry for the specified class or package name and
 216   // corresponding directory or jar file name.
 217   static bool add_package(const char *pkgname, int classpath_index, TRAPS);
 218 
 219   // Initialization



 220   static void setup_bootstrap_search_path();
 221   static void setup_search_path(const char *class_path);
 222 
 223   static void load_zip_library();
 224   static ClassPathEntry* create_class_path_entry(const char *path, const struct stat* st,
 225                                                  bool lazy, bool throw_exception, TRAPS);
 226 
 227   // Canonicalizes path names, so strcmp will work properly. This is mainly
 228   // to avoid confusing the zip library
 229   static bool get_canonical_path(const char* orig, char* out, int len);
 230  public:
 231   static jboolean decompress(void *in, u8 inSize, void *out, u8 outSize, char **pmsg);
 232   static int crc32(int crc, const char* buf, int len);
 233   static bool update_class_path_entry_list(const char *path,
 234                                            bool check_for_duplicates,
 235                                            bool throw_exception=true);
 236   static void print_bootclasspath();
 237 
 238   // Timing
 239   static PerfCounter* perf_accumulated_time()         { return _perf_accumulated_time; }


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