author | coleenp |
Wed, 21 Mar 2018 19:45:24 -0400 | |
changeset 49480 | d7df2dd501ce |
parent 49341 | 4ad0085ad6d2 |
child 49739 | 00805b129186 |
permissions | -rw-r--r-- |
26135 | 1 |
/* |
49341 | 2 |
* Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved. |
26135 | 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_CLASSLOADEREXT_HPP |
|
26 |
#define SHARE_VM_CLASSFILE_CLASSLOADEREXT_HPP |
|
27 |
||
28 |
#include "classfile/classLoader.hpp" |
|
48138 | 29 |
#include "utilities/macros.hpp" |
26135 | 30 |
|
48138 | 31 |
CDS_ONLY(class SharedPathsMiscInfoExt;) |
32 |
CDS_ONLY(class ClassListParser;) |
|
34257
4be3504cc03b
8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
29199
diff
changeset
|
33 |
|
26135 | 34 |
class ClassLoaderExt: public ClassLoader { // AllStatic |
35 |
public: |
|
48138 | 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. |
|
26135 | 45 |
class Context { |
48138 | 46 |
static Thread* _dump_thread; |
47 |
const char* _class_name; |
|
26135 | 48 |
const char* _file_name; |
49 |
public: |
|
48138 | 50 |
const char* class_name() { |
51 |
return _class_name; |
|
52 |
} |
|
53 |
const char* file_name() { |
|
54 |
return _file_name; |
|
55 |
} |
|
56 |
||
26135 | 57 |
Context(const char* class_name, const char* file_name, TRAPS) { |
48138 | 58 |
_class_name = class_name; |
26135 | 59 |
_file_name = file_name; |
48138 | 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 |
|
26135 | 66 |
} |
67 |
||
68 |
bool should_verify(int classpath_index) { |
|
48138 | 69 |
CDS_ONLY(return (classpath_index >= _app_paths_start_index);) |
70 |
NOT_CDS(return false;) |
|
26135 | 71 |
} |
72 |
||
47991
a474466c4fdb
8187118: Remove appending -cp path to the boot class path at AppCDS dump time
jiangli
parents:
47216
diff
changeset
|
73 |
void record_result(Symbol* class_name, |
a474466c4fdb
8187118: Remove appending -cp path to the boot class path at AppCDS dump time
jiangli
parents:
47216
diff
changeset
|
74 |
const s2 classpath_index, |
48138 | 75 |
InstanceKlass* result, |
76 |
TRAPS) { |
|
39224
7c26725c0813
8158681: ClassLoader::classloader_type() is called from code not included under #if INCLUDE_CDS.
jiangli
parents:
38192
diff
changeset
|
77 |
#if INCLUDE_CDS |
48138 | 78 |
ClassLoaderExt::record_result(this, class_name, classpath_index, result, THREAD); |
79 |
#endif |
|
80 |
} |
|
81 |
||
82 |
~Context() { |
|
83 |
#if INCLUDE_CDS |
|
84 |
if (!DumpSharedSpaces && !UseSharedSpaces) { |
|
85 |
// Must not modify app_paths_start_index if we're not using CDS. |
|
86 |
assert(_app_paths_start_index == ClassLoaderExt::max_classpath_index, "must be"); |
|
47991
a474466c4fdb
8187118: Remove appending -cp path to the boot class path at AppCDS dump time
jiangli
parents:
47216
diff
changeset
|
87 |
} |
39224
7c26725c0813
8158681: ClassLoader::classloader_type() is called from code not included under #if INCLUDE_CDS.
jiangli
parents:
38192
diff
changeset
|
88 |
#endif |
26135 | 89 |
} |
48138 | 90 |
}; // end ClassLoaderExt::Context |
26135 | 91 |
|
48138 | 92 |
private: |
93 |
#if INCLUDE_CDS |
|
94 |
static char* get_class_path_attr(const char* jar_path, char* manifest, jint manifest_size); |
|
95 |
static void setup_app_search_path(); // Only when -Xshare:dump |
|
96 |
static SharedPathsMiscInfoExt* shared_paths_misc_info() { |
|
97 |
return (SharedPathsMiscInfoExt*)_shared_paths_misc_info; |
|
98 |
} |
|
99 |
static jshort _app_paths_start_index; // index of first app JAR in shared classpath entry table |
|
100 |
static bool _has_app_classes; |
|
101 |
static bool _has_platform_classes; |
|
102 |
#endif |
|
103 |
||
104 |
public: |
|
105 |
CDS_ONLY(static void process_jar_manifest(ClassPathEntry* entry, bool check_for_duplicates);) |
|
106 |
||
107 |
// Called by JVMTI code to add boot classpath |
|
27672
d24adedd3655
8064701: Some CDS optimizations should be disabled if bootclasspath is modified by JVMTI
iklam
parents:
26419
diff
changeset
|
108 |
static void append_boot_classpath(ClassPathEntry* new_entry) { |
48138 | 109 |
#if INCLUDE_CDS |
110 |
if (UseAppCDS) { |
|
111 |
warning("UseAppCDS is disabled because bootstrap classpath has been appended"); |
|
112 |
UseAppCDS = false; |
|
113 |
} |
|
114 |
#endif |
|
47991
a474466c4fdb
8187118: Remove appending -cp path to the boot class path at AppCDS dump time
jiangli
parents:
47216
diff
changeset
|
115 |
ClassLoader::add_to_boot_append_entries(new_entry); |
27672
d24adedd3655
8064701: Some CDS optimizations should be disabled if bootclasspath is modified by JVMTI
iklam
parents:
26419
diff
changeset
|
116 |
} |
48138 | 117 |
|
118 |
static void setup_search_paths() NOT_CDS_RETURN; |
|
119 |
||
47103
a993ec29ec75
8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
46329
diff
changeset
|
120 |
#if INCLUDE_CDS |
48138 | 121 |
private: |
122 |
static char* read_manifest(ClassPathEntry* entry, jint *manifest_size, bool clean_text, TRAPS); |
|
123 |
static ClassPathEntry* find_classpath_entry_from_cache(const char* path, TRAPS); |
|
124 |
||
125 |
public: |
|
47103
a993ec29ec75
8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
46329
diff
changeset
|
126 |
static char* read_manifest(ClassPathEntry* entry, jint *manifest_size, TRAPS) { |
48138 | 127 |
// Remove all the new-line continuations (which wrap long lines at 72 characters, see |
128 |
// http://docs.oracle.com/javase/6/docs/technotes/guides/jar/jar.html#JAR%20Manifest), so |
|
129 |
// that the manifest is easier to parse. |
|
130 |
return read_manifest(entry, manifest_size, true, THREAD); |
|
131 |
} |
|
132 |
static char* read_raw_manifest(ClassPathEntry* entry, jint *manifest_size, TRAPS) { |
|
133 |
// Do not remove new-line continuations, so we can easily pass it as an argument to |
|
134 |
// java.util.jar.Manifest.getManifest() at run-time. |
|
135 |
return read_manifest(entry, manifest_size, false, THREAD); |
|
136 |
} |
|
137 |
||
138 |
static void finalize_shared_paths_misc_info(); |
|
139 |
||
140 |
static jshort app_paths_start_index() { return _app_paths_start_index; } |
|
141 |
||
142 |
static void init_paths_start_index(jshort app_start) { |
|
143 |
_app_paths_start_index = app_start; |
|
144 |
} |
|
145 |
||
146 |
static bool is_boot_classpath(int classpath_index) { |
|
147 |
return classpath_index < _app_paths_start_index; |
|
47103
a993ec29ec75
8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
46329
diff
changeset
|
148 |
} |
48138 | 149 |
|
150 |
static bool has_platform_or_app_classes() { |
|
151 |
return _has_app_classes || _has_platform_classes; |
|
152 |
} |
|
153 |
||
154 |
static void record_result(class ClassLoaderExt::Context *context, |
|
155 |
Symbol* class_name, |
|
156 |
const s2 classpath_index, |
|
157 |
InstanceKlass* result, TRAPS); |
|
158 |
static InstanceKlass* load_class(Symbol* h_name, const char* path, TRAPS); |
|
159 |
static Klass* load_one_class(ClassListParser* parser, TRAPS); |
|
160 |
static void set_has_app_classes() { |
|
161 |
_has_app_classes = true; |
|
162 |
} |
|
163 |
static void set_has_platform_classes() { |
|
164 |
_has_platform_classes = true; |
|
165 |
} |
|
47103
a993ec29ec75
8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
46329
diff
changeset
|
166 |
#endif |
26135 | 167 |
}; |
168 |
||
169 |
#endif // SHARE_VM_CLASSFILE_CLASSLOADEREXT_HPP |