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_CLASSLOADEREXT_HPP 26 #define SHARE_VM_CLASSFILE_CLASSLOADEREXT_HPP 27 28 #include "classfile/classLoader.hpp" 29 #include "classfile/systemDictionary.hpp" 30 #include "oops/instanceKlass.hpp" 31 #include "runtime/handles.hpp" 32 33 class ClassListParser; 34 35 class ClassLoaderExt: public ClassLoader { // AllStatic 36 public: 37 38 class Context { 39 const char* _file_name; 40 public: 41 Context(const char* class_name, const char* file_name, TRAPS) { 42 _file_name = file_name; 43 } 44 45 bool check(const ClassFileStream* stream, const int classpath_index) { 46 return true; 47 } 48 49 bool should_verify(int classpath_index) { 50 return false; 51 } 52 53 void record_result(Symbol* class_name, 54 const s2 classpath_index, 55 InstanceKlass* result, TRAPS) { 56 #if INCLUDE_CDS 57 assert(DumpSharedSpaces, "Sanity"); 58 oop loader = result->class_loader(); 59 s2 classloader_type = ClassLoader::BOOT_LOADER; 60 if (SystemDictionary::is_system_class_loader(loader)) { 61 classloader_type = ClassLoader::APP_LOADER; 62 ClassLoaderExt::set_has_app_classes(); 63 } else if (SystemDictionary::is_platform_class_loader(loader)) { 64 classloader_type = ClassLoader::PLATFORM_LOADER; 65 ClassLoaderExt::set_has_platform_classes(); 66 } 67 result->set_shared_classpath_index(classpath_index); 68 result->set_class_loader_type(classloader_type); 69 #endif 70 } 71 }; 72 73 static void append_boot_classpath(ClassPathEntry* new_entry) { 74 ClassLoader::add_to_boot_append_entries(new_entry); 75 } 76 static void setup_search_paths() {} 77 static bool is_boot_classpath(int classpath_index) { 78 return true; 79 } 80 static Klass* load_one_class(ClassListParser* parser, TRAPS); 81 #if INCLUDE_CDS 82 static void set_has_app_classes() {} 83 static void set_has_platform_classes() {} 84 static char* read_manifest(ClassPathEntry* entry, jint *manifest_size, TRAPS) { 85 return NULL; 86 } 87 static void process_jar_manifest(ClassPathEntry* entry, bool check_for_duplicates) {} 88 #endif 89 }; 90 91 #endif // SHARE_VM_CLASSFILE_CLASSLOADEREXT_HPP | 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_CLASSLOADEREXT_HPP 26 #define SHARE_VM_CLASSFILE_CLASSLOADEREXT_HPP 27 28 #include "classfile/classLoader.hpp" 29 #include "utilities/macros.hpp" 30 31 CDS_ONLY(class SharedPathsMiscInfoExt;) 32 CDS_ONLY(class ClassListParser;) 33 34 class ClassLoaderExt: public ClassLoader { // AllStatic 35 public: 36 enum SomeConstants { 37 max_classpath_index = 0x7fff 38 }; 39 // ClassLoaderExt::Context -- 40 // 41 // This is used by DumpSharedSpaces only - it enforces the same classloader 42 // delegation model as would be in run-time. I.e., 43 // + classes defined by the NULL class loader cannot load classes in the PLATFORM or APP paths. 44 // + classes defined by the PLATFORM class loader cannot load classes in the APP paths. 45 class Context { 46 static Thread* _dump_thread; 47 const char* _class_name; 48 const char* _file_name; 49 public: 50 const char* class_name() { 51 return _class_name; 52 } 53 const char* file_name() { 54 return _file_name; 55 } 56 57 Context(const char* class_name, const char* file_name, TRAPS) { 58 _class_name = class_name; 59 _file_name = file_name; 60 #if INCLUDE_CDS 61 if (!DumpSharedSpaces && !UseSharedSpaces) { 62 // Must not modify _app_paths_start_index if we're not using CDS. 63 assert(_app_paths_start_index == ClassLoaderExt::max_classpath_index, "must be"); 64 } 65 #endif 66 } 67 68 bool check(const ClassFileStream* stream, const int classpath_index) { 69 CDS_ONLY(return ClassLoaderExt::check(this, stream, classpath_index);) 70 NOT_CDS(return true;) 71 } 72 73 bool should_verify(int classpath_index) { 74 CDS_ONLY(return (classpath_index >= _app_paths_start_index);) 75 NOT_CDS(return false;) 76 } 77 78 void record_result(Symbol* class_name, 79 const s2 classpath_index, 80 InstanceKlass* result, 81 TRAPS) { 82 #if INCLUDE_CDS 83 ClassLoaderExt::record_result(this, class_name, classpath_index, result, THREAD); 84 #endif 85 } 86 87 ~Context() { 88 #if INCLUDE_CDS 89 if (!DumpSharedSpaces && !UseSharedSpaces) { 90 // Must not modify app_paths_start_index if we're not using CDS. 91 assert(_app_paths_start_index == ClassLoaderExt::max_classpath_index, "must be"); 92 } 93 #endif 94 } 95 }; // end ClassLoaderExt::Context 96 97 private: 98 #if INCLUDE_CDS 99 static char* get_class_path_attr(const char* jar_path, char* manifest, jint manifest_size); 100 static void setup_app_search_path(); // Only when -Xshare:dump 101 static SharedPathsMiscInfoExt* shared_paths_misc_info() { 102 return (SharedPathsMiscInfoExt*)_shared_paths_misc_info; 103 } 104 static jshort _app_paths_start_index; // index of first app JAR in shared classpath entry table 105 static bool _has_app_classes; 106 static bool _has_platform_classes; 107 #endif 108 109 public: 110 CDS_ONLY(static void process_jar_manifest(ClassPathEntry* entry, bool check_for_duplicates);) 111 112 // Called by JVMTI code to add boot classpath 113 static void append_boot_classpath(ClassPathEntry* new_entry) { 114 #if INCLUDE_CDS 115 if (UseAppCDS) { 116 warning("UseAppCDS is disabled because bootstrap classpath has been appended"); 117 UseAppCDS = false; 118 } 119 #endif 120 ClassLoader::add_to_boot_append_entries(new_entry); 121 } 122 123 static void setup_search_paths() NOT_CDS_RETURN; 124 125 #if INCLUDE_CDS 126 private: 127 static char* read_manifest(ClassPathEntry* entry, jint *manifest_size, bool clean_text, TRAPS); 128 static ClassPathEntry* find_classpath_entry_from_cache(const char* path, TRAPS); 129 130 public: 131 static char* read_manifest(ClassPathEntry* entry, jint *manifest_size, TRAPS) { 132 // Remove all the new-line continuations (which wrap long lines at 72 characters, see 133 // http://docs.oracle.com/javase/6/docs/technotes/guides/jar/jar.html#JAR%20Manifest), so 134 // that the manifest is easier to parse. 135 return read_manifest(entry, manifest_size, true, THREAD); 136 } 137 static char* read_raw_manifest(ClassPathEntry* entry, jint *manifest_size, TRAPS) { 138 // Do not remove new-line continuations, so we can easily pass it as an argument to 139 // java.util.jar.Manifest.getManifest() at run-time. 140 return read_manifest(entry, manifest_size, false, THREAD); 141 } 142 143 static void finalize_shared_paths_misc_info(); 144 145 static jshort app_paths_start_index() { return _app_paths_start_index; } 146 147 static void init_paths_start_index(jshort app_start) { 148 _app_paths_start_index = app_start; 149 } 150 151 static bool is_boot_classpath(int classpath_index) { 152 return classpath_index < _app_paths_start_index; 153 } 154 155 static bool has_platform_or_app_classes() { 156 return _has_app_classes || _has_platform_classes; 157 } 158 159 static bool check(class ClassLoaderExt::Context *context, 160 const ClassFileStream* stream, 161 const int classpath_index); 162 163 static void record_result(class ClassLoaderExt::Context *context, 164 Symbol* class_name, 165 const s2 classpath_index, 166 InstanceKlass* result, TRAPS); 167 static InstanceKlass* load_class(Symbol* h_name, const char* path, TRAPS); 168 static Klass* load_one_class(ClassListParser* parser, TRAPS); 169 static void set_has_app_classes() { 170 _has_app_classes = true; 171 } 172 static void set_has_platform_classes() { 173 _has_platform_classes = true; 174 } 175 #endif 176 }; 177 178 #endif // SHARE_VM_CLASSFILE_CLASSLOADEREXT_HPP |