author | iklam |
Tue, 28 Nov 2017 09:47:04 -0800 | |
changeset 48155 | 551de50b4ff7 |
parent 48138 | 78b2ecdd3c4b |
child 48383 | d6388b652504 |
permissions | -rw-r--r-- |
34257
4be3504cc03b
8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff
changeset
|
1 |
/* |
48138 | 2 |
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. |
34257
4be3504cc03b
8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4be3504cc03b
8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff
changeset
|
4 |
* |
4be3504cc03b
8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
4be3504cc03b
8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
4be3504cc03b
8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
4be3504cc03b
8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff
changeset
|
8 |
* |
4be3504cc03b
8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
4be3504cc03b
8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
4be3504cc03b
8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
4be3504cc03b
8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
4be3504cc03b
8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff
changeset
|
13 |
* accompanied this code). |
4be3504cc03b
8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff
changeset
|
14 |
* |
4be3504cc03b
8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
4be3504cc03b
8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
4be3504cc03b
8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
4be3504cc03b
8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff
changeset
|
18 |
* |
4be3504cc03b
8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
4be3504cc03b
8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
4be3504cc03b
8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff
changeset
|
21 |
* questions. |
4be3504cc03b
8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff
changeset
|
22 |
* |
4be3504cc03b
8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff
changeset
|
23 |
*/ |
4be3504cc03b
8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff
changeset
|
24 |
|
4be3504cc03b
8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff
changeset
|
25 |
#include "precompiled.hpp" |
48138 | 26 |
#include "jvm.h" |
27 |
#include "jimage.hpp" |
|
34257
4be3504cc03b
8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff
changeset
|
28 |
#include "classfile/classListParser.hpp" |
48138 | 29 |
#include "classfile/classLoaderExt.hpp" |
30 |
#include "classfile/sharedClassUtil.hpp" |
|
31 |
#include "classfile/symbolTable.hpp" |
|
32 |
#include "classfile/systemDictionary.hpp" |
|
33 |
#include "classfile/systemDictionaryShared.hpp" |
|
34 |
#include "memory/metaspaceShared.hpp" |
|
35 |
#include "memory/resourceArea.hpp" |
|
36 |
#include "runtime/fieldType.hpp" |
|
37 |
#include "runtime/javaCalls.hpp" |
|
38 |
#include "utilities/defaultStream.hpp" |
|
39 |
#include "utilities/hashtable.inline.hpp" |
|
40 |
#include "utilities/macros.hpp" |
|
41 |
||
42 |
ClassListParser* ClassListParser::_instance = NULL; |
|
34257
4be3504cc03b
8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff
changeset
|
43 |
|
4be3504cc03b
8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff
changeset
|
44 |
ClassListParser::ClassListParser(const char* file) { |
48138 | 45 |
assert(_instance == NULL, "must be singleton"); |
46 |
_instance = this; |
|
34257
4be3504cc03b
8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff
changeset
|
47 |
_classlist_file = file; |
4be3504cc03b
8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff
changeset
|
48 |
_file = fopen(file, "r"); |
48138 | 49 |
_line_no = 0; |
50 |
_interfaces = new (ResourceObj::C_HEAP, mtClass) GrowableArray<int>(10, true); |
|
51 |
||
34257
4be3504cc03b
8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff
changeset
|
52 |
if (_file == NULL) { |
4be3504cc03b
8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff
changeset
|
53 |
char errmsg[JVM_MAXPATHLEN]; |
4be3504cc03b
8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff
changeset
|
54 |
os::lasterror(errmsg, JVM_MAXPATHLEN); |
4be3504cc03b
8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff
changeset
|
55 |
vm_exit_during_initialization("Loading classlist failed", errmsg); |
4be3504cc03b
8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff
changeset
|
56 |
} |
4be3504cc03b
8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff
changeset
|
57 |
} |
4be3504cc03b
8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff
changeset
|
58 |
|
4be3504cc03b
8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff
changeset
|
59 |
ClassListParser::~ClassListParser() { |
4be3504cc03b
8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff
changeset
|
60 |
if (_file) { |
4be3504cc03b
8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff
changeset
|
61 |
fclose(_file); |
4be3504cc03b
8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff
changeset
|
62 |
} |
48138 | 63 |
_instance = NULL; |
34257
4be3504cc03b
8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff
changeset
|
64 |
} |
4be3504cc03b
8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff
changeset
|
65 |
|
4be3504cc03b
8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff
changeset
|
66 |
bool ClassListParser::parse_one_line() { |
4be3504cc03b
8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff
changeset
|
67 |
for (;;) { |
4be3504cc03b
8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff
changeset
|
68 |
if (fgets(_line, sizeof(_line), _file) == NULL) { |
4be3504cc03b
8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff
changeset
|
69 |
return false; |
4be3504cc03b
8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff
changeset
|
70 |
} |
48138 | 71 |
++ _line_no; |
72 |
_line_len = (int)strlen(_line); |
|
73 |
if (_line_len > _max_allowed_line_len) { |
|
74 |
error("input line too long (must be no longer than %d chars)", _max_allowed_line_len); |
|
34257
4be3504cc03b
8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff
changeset
|
75 |
} |
4be3504cc03b
8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff
changeset
|
76 |
if (*_line == '#') { // comment |
4be3504cc03b
8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff
changeset
|
77 |
continue; |
4be3504cc03b
8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff
changeset
|
78 |
} |
4be3504cc03b
8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff
changeset
|
79 |
break; |
4be3504cc03b
8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff
changeset
|
80 |
} |
4be3504cc03b
8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff
changeset
|
81 |
|
48138 | 82 |
_id = _unspecified; |
83 |
_super = _unspecified; |
|
84 |
_interfaces->clear(); |
|
85 |
_source = NULL; |
|
86 |
_interfaces_specified = false; |
|
87 |
||
88 |
{ |
|
89 |
int len = (int)strlen(_line); |
|
90 |
int i; |
|
91 |
// Replace \t\r\n with ' ' |
|
92 |
for (i=0; i<len; i++) { |
|
93 |
if (_line[i] == '\t' || _line[i] == '\r' || _line[i] == '\n') { |
|
94 |
_line[i] = ' '; |
|
95 |
} |
|
96 |
} |
|
97 |
||
98 |
// Remove trailing newline/space |
|
99 |
while (len > 0) { |
|
100 |
if (_line[len-1] == ' ') { |
|
101 |
_line[len-1] = '\0'; |
|
102 |
len --; |
|
103 |
} else { |
|
104 |
break; |
|
105 |
} |
|
106 |
} |
|
107 |
_line_len = len; |
|
108 |
_class_name = _line; |
|
109 |
} |
|
110 |
||
111 |
if ((_token = strchr(_line, ' ')) == NULL) { |
|
112 |
// No optional arguments are specified. |
|
113 |
return true; |
|
114 |
} |
|
115 |
||
116 |
// Mark the end of the name, and go to the next input char |
|
117 |
*_token++ = '\0'; |
|
118 |
||
119 |
while (*_token) { |
|
120 |
skip_whitespaces(); |
|
121 |
||
122 |
if (parse_int_option("id:", &_id)) { |
|
123 |
continue; |
|
124 |
} else if (parse_int_option("super:", &_super)) { |
|
125 |
check_already_loaded("Super class", _super); |
|
126 |
continue; |
|
127 |
} else if (skip_token("interfaces:")) { |
|
128 |
int i; |
|
129 |
while (try_parse_int(&i)) { |
|
130 |
check_already_loaded("Interface", i); |
|
131 |
_interfaces->append(i); |
|
132 |
} |
|
133 |
} else if (skip_token("source:")) { |
|
134 |
skip_whitespaces(); |
|
135 |
_source = _token; |
|
136 |
char* s = strchr(_token, ' '); |
|
137 |
if (s == NULL) { |
|
138 |
break; // end of input line |
|
139 |
} else { |
|
140 |
*s = '\0'; // mark the end of _source |
|
141 |
_token = s+1; |
|
142 |
} |
|
143 |
} else { |
|
144 |
error("Unknown input"); |
|
145 |
} |
|
146 |
} |
|
147 |
||
148 |
// if src is specified |
|
149 |
// id super interfaces must all be specified |
|
150 |
// loader may be specified |
|
151 |
// else |
|
152 |
// # the class is loaded from classpath |
|
153 |
// id may be specified |
|
154 |
// super, interfaces, loader must not be specified |
|
34257
4be3504cc03b
8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff
changeset
|
155 |
return true; |
4be3504cc03b
8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff
changeset
|
156 |
} |
4be3504cc03b
8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff
changeset
|
157 |
|
48138 | 158 |
void ClassListParser::skip_whitespaces() { |
159 |
while (*_token == ' ' || *_token == '\t') { |
|
160 |
_token ++; |
|
161 |
} |
|
162 |
} |
|
163 |
||
164 |
void ClassListParser::skip_non_whitespaces() { |
|
165 |
while (*_token && *_token != ' ' && *_token != '\t') { |
|
166 |
_token ++; |
|
167 |
} |
|
168 |
} |
|
169 |
||
170 |
void ClassListParser::parse_int(int* value) { |
|
171 |
skip_whitespaces(); |
|
172 |
if (sscanf(_token, "%i", value) == 1) { |
|
173 |
skip_non_whitespaces(); |
|
174 |
if (*value < 0) { |
|
175 |
error("Error: negative integers not allowed (%d)", *value); |
|
176 |
} |
|
177 |
} else { |
|
178 |
error("Error: expected integer"); |
|
179 |
} |
|
180 |
} |
|
181 |
||
182 |
bool ClassListParser::try_parse_int(int* value) { |
|
183 |
skip_whitespaces(); |
|
184 |
if (sscanf(_token, "%i", value) == 1) { |
|
185 |
skip_non_whitespaces(); |
|
186 |
return true; |
|
187 |
} |
|
188 |
return false; |
|
189 |
} |
|
190 |
||
191 |
bool ClassListParser::skip_token(const char* option_name) { |
|
192 |
size_t len = strlen(option_name); |
|
193 |
if (strncmp(_token, option_name, len) == 0) { |
|
194 |
_token += len; |
|
195 |
return true; |
|
196 |
} else { |
|
197 |
return false; |
|
198 |
} |
|
199 |
} |
|
200 |
||
201 |
bool ClassListParser::parse_int_option(const char* option_name, int* value) { |
|
202 |
if (skip_token(option_name)) { |
|
203 |
if (*value != _unspecified) { |
|
204 |
error("%s specified twice", option_name); |
|
205 |
} else { |
|
206 |
parse_int(value); |
|
207 |
return true; |
|
208 |
} |
|
209 |
} |
|
210 |
return false; |
|
211 |
} |
|
212 |
||
213 |
void ClassListParser::print_specified_interfaces() { |
|
214 |
const int n = _interfaces->length(); |
|
215 |
jio_fprintf(defaultStream::error_stream(), "Currently specified interfaces[%d] = {\n", n); |
|
216 |
for (int i=0; i<n; i++) { |
|
217 |
InstanceKlass* k = lookup_class_by_id(_interfaces->at(i)); |
|
218 |
jio_fprintf(defaultStream::error_stream(), " %4d = %s\n", _interfaces->at(i), k->name()->as_klass_external_name()); |
|
219 |
} |
|
220 |
jio_fprintf(defaultStream::error_stream(), "}\n"); |
|
221 |
} |
|
222 |
||
223 |
void ClassListParser::print_actual_interfaces(InstanceKlass *ik) { |
|
224 |
int n = ik->local_interfaces()->length(); |
|
225 |
jio_fprintf(defaultStream::error_stream(), "Actual interfaces[%d] = {\n", n); |
|
226 |
for (int i = 0; i < n; i++) { |
|
227 |
InstanceKlass* e = InstanceKlass::cast(ik->local_interfaces()->at(i)); |
|
228 |
jio_fprintf(defaultStream::error_stream(), " %s\n", e->name()->as_klass_external_name()); |
|
229 |
} |
|
230 |
jio_fprintf(defaultStream::error_stream(), "}\n"); |
|
231 |
} |
|
232 |
||
233 |
void ClassListParser::error(const char *msg, ...) { |
|
234 |
va_list ap; |
|
235 |
va_start(ap, msg); |
|
236 |
int error_index = _token - _line; |
|
237 |
if (error_index >= _line_len) { |
|
238 |
error_index = _line_len - 1; |
|
239 |
} |
|
240 |
if (error_index < 0) { |
|
241 |
error_index = 0; |
|
242 |
} |
|
243 |
||
244 |
jio_fprintf(defaultStream::error_stream(), |
|
245 |
"An error has occurred while processing class list file %s %d:%d.\n", |
|
246 |
_classlist_file, _line_no, (error_index + 1)); |
|
247 |
jio_vfprintf(defaultStream::error_stream(), msg, ap); |
|
248 |
||
249 |
if (_line_len <= 0) { |
|
250 |
jio_fprintf(defaultStream::error_stream(), "\n"); |
|
251 |
} else { |
|
252 |
jio_fprintf(defaultStream::error_stream(), ":\n"); |
|
253 |
for (int i=0; i<_line_len; i++) { |
|
254 |
char c = _line[i]; |
|
255 |
if (c == '\0') { |
|
256 |
jio_fprintf(defaultStream::error_stream(), "%s", " "); |
|
257 |
} else { |
|
258 |
jio_fprintf(defaultStream::error_stream(), "%c", c); |
|
259 |
} |
|
260 |
} |
|
261 |
jio_fprintf(defaultStream::error_stream(), "\n"); |
|
262 |
for (int i=0; i<error_index; i++) { |
|
263 |
jio_fprintf(defaultStream::error_stream(), "%s", " "); |
|
264 |
} |
|
265 |
jio_fprintf(defaultStream::error_stream(), "^\n"); |
|
266 |
} |
|
267 |
||
268 |
vm_exit_during_initialization("class list format error.", NULL); |
|
269 |
va_end(ap); |
|
270 |
} |
|
271 |
||
272 |
// This function is used for loading classes for customized class loaders |
|
273 |
// during archive dumping. |
|
274 |
InstanceKlass* ClassListParser::load_class_from_source(Symbol* class_name, TRAPS) { |
|
48155
551de50b4ff7
8191927: Enable AppCDS for custom loaders on all 64-bit Linux and AIX
iklam
parents:
48138
diff
changeset
|
275 |
#if !(defined(_LP64) && (defined(LINUX)|| defined(SOLARIS) || defined(AIX))) |
551de50b4ff7
8191927: Enable AppCDS for custom loaders on all 64-bit Linux and AIX
iklam
parents:
48138
diff
changeset
|
276 |
// The only supported platforms are: (1) Linux/64-bit; (2) Solaris/64-bit; (3) AIX/64-bit |
551de50b4ff7
8191927: Enable AppCDS for custom loaders on all 64-bit Linux and AIX
iklam
parents:
48138
diff
changeset
|
277 |
// |
551de50b4ff7
8191927: Enable AppCDS for custom loaders on all 64-bit Linux and AIX
iklam
parents:
48138
diff
changeset
|
278 |
// This #if condition should be in sync with the areCustomLoadersSupportedForCDS |
551de50b4ff7
8191927: Enable AppCDS for custom loaders on all 64-bit Linux and AIX
iklam
parents:
48138
diff
changeset
|
279 |
// method in test/lib/jdk/test/lib/Platform.java. |
48138 | 280 |
error("AppCDS custom class loaders not supported on this platform"); |
281 |
#endif |
|
282 |
||
283 |
assert(UseAppCDS, "must be"); |
|
284 |
if (!is_super_specified()) { |
|
285 |
error("If source location is specified, super class must be also specified"); |
|
286 |
} |
|
287 |
if (!is_id_specified()) { |
|
288 |
error("If source location is specified, id must be also specified"); |
|
289 |
} |
|
290 |
InstanceKlass* k = ClassLoaderExt::load_class(class_name, _source, THREAD); |
|
291 |
||
292 |
if (strncmp(_class_name, "java/", 5) == 0) { |
|
293 |
log_info(cds)("Prohibited package for non-bootstrap classes: %s.class from %s", |
|
294 |
_class_name, _source); |
|
295 |
return NULL; |
|
296 |
} |
|
297 |
||
298 |
if (k != NULL) { |
|
299 |
if (k->local_interfaces()->length() != _interfaces->length()) { |
|
300 |
print_specified_interfaces(); |
|
301 |
print_actual_interfaces(k); |
|
302 |
error("The number of interfaces (%d) specified in class list does not match the class file (%d)", |
|
303 |
_interfaces->length(), k->local_interfaces()->length()); |
|
304 |
} |
|
305 |
||
306 |
if (!SystemDictionaryShared::add_non_builtin_klass(class_name, ClassLoaderData::the_null_class_loader_data(), |
|
307 |
k, THREAD)) { |
|
308 |
error("Duplicated class %s", _class_name); |
|
309 |
} |
|
310 |
||
311 |
// This tells JVM_FindLoadedClass to not find this class. |
|
312 |
k->set_shared_classpath_index(UNREGISTERED_INDEX); |
|
313 |
} |
|
314 |
||
315 |
return k; |
|
316 |
} |
|
317 |
||
318 |
InstanceKlass* ClassListParser::load_current_class(TRAPS) { |
|
319 |
TempNewSymbol class_name_symbol = SymbolTable::new_symbol(_class_name, THREAD); |
|
320 |
guarantee(!HAS_PENDING_EXCEPTION, "Exception creating a symbol."); |
|
321 |
||
322 |
InstanceKlass *klass = NULL; |
|
323 |
if (!is_loading_from_source()) { |
|
324 |
if (is_super_specified()) { |
|
325 |
error("If source location is not specified, super class must not be specified"); |
|
326 |
} |
|
327 |
if (are_interfaces_specified()) { |
|
328 |
error("If source location is not specified, interface(s) must not be specified"); |
|
329 |
} |
|
330 |
||
331 |
bool non_array = !FieldType::is_array(class_name_symbol); |
|
332 |
||
333 |
Handle s = java_lang_String::create_from_symbol(class_name_symbol, CHECK_0); |
|
334 |
// Translate to external class name format, i.e., convert '/' chars to '.' |
|
335 |
Handle string = java_lang_String::externalize_classname(s, CHECK_0); |
|
336 |
JavaValue result(T_OBJECT); |
|
337 |
InstanceKlass* spec_klass = non_array ? |
|
338 |
SystemDictionary::ClassLoader_klass() : SystemDictionary::Class_klass(); |
|
339 |
Symbol* method_name = non_array ? |
|
340 |
vmSymbols::loadClass_name() : vmSymbols::forName_name(); |
|
341 |
Handle loader = Handle(THREAD, SystemDictionary::java_system_loader()); |
|
342 |
||
343 |
if (non_array) { |
|
344 |
JavaCalls::call_virtual(&result, |
|
345 |
loader, //SystemDictionary::java_system_loader(), |
|
346 |
spec_klass, |
|
347 |
method_name, //vmSymbols::loadClass_name(), |
|
348 |
vmSymbols::string_class_signature(), |
|
349 |
string, |
|
350 |
THREAD); |
|
351 |
} else { |
|
352 |
JavaCalls::call_static(&result, |
|
353 |
spec_klass, |
|
354 |
method_name, |
|
355 |
vmSymbols::string_class_signature(), |
|
356 |
string, |
|
357 |
CHECK_NULL); |
|
358 |
} |
|
359 |
assert(result.get_type() == T_OBJECT, "just checking"); |
|
360 |
oop obj = (oop) result.get_jobject(); |
|
361 |
if (!HAS_PENDING_EXCEPTION && (obj != NULL)) { |
|
362 |
if (non_array) { |
|
363 |
klass = InstanceKlass::cast(java_lang_Class::as_Klass(obj)); |
|
364 |
} else { |
|
365 |
klass = static_cast<InstanceKlass*>(java_lang_Class::array_klass_acquire(obj)); |
|
366 |
} |
|
367 |
} else { // load classes in bootclasspath/a |
|
368 |
if (HAS_PENDING_EXCEPTION) { |
|
369 |
CLEAR_PENDING_EXCEPTION; |
|
370 |
} |
|
371 |
||
372 |
if (non_array) { |
|
373 |
Klass* k = SystemDictionary::resolve_or_null(class_name_symbol, CHECK_NULL); |
|
374 |
if (k != NULL) { |
|
375 |
klass = InstanceKlass::cast(k); |
|
376 |
} else { |
|
377 |
if (!HAS_PENDING_EXCEPTION) { |
|
378 |
THROW_NULL(vmSymbols::java_lang_ClassNotFoundException()); |
|
379 |
} |
|
380 |
} |
|
381 |
} |
|
382 |
} |
|
383 |
} else { |
|
384 |
// If "source:" tag is specified, all super class and super interfaces must be specified in the |
|
385 |
// class list file. |
|
386 |
if (UseAppCDS) { |
|
387 |
klass = load_class_from_source(class_name_symbol, CHECK_NULL); |
|
388 |
} |
|
389 |
} |
|
390 |
||
391 |
if (klass != NULL && is_id_specified()) { |
|
392 |
int id = this->id(); |
|
393 |
SystemDictionaryShared::update_shared_entry(klass, id); |
|
394 |
InstanceKlass* old = table()->lookup(id); |
|
395 |
if (old != NULL && old != klass) { |
|
396 |
error("Duplicated ID %d for class %s", id, _class_name); |
|
397 |
} |
|
398 |
table()->add(id, klass); |
|
399 |
} |
|
400 |
||
401 |
return klass; |
|
402 |
} |
|
403 |
||
404 |
bool ClassListParser::is_loading_from_source() { |
|
405 |
return (_source != NULL); |
|
406 |
} |
|
407 |
||
408 |
InstanceKlass* ClassListParser::lookup_class_by_id(int id) { |
|
409 |
InstanceKlass* klass = table()->lookup(id); |
|
410 |
if (klass == NULL) { |
|
411 |
error("Class ID %d has not been defined", id); |
|
412 |
} |
|
413 |
return klass; |
|
414 |
} |
|
415 |
||
416 |
||
417 |
InstanceKlass* ClassListParser::lookup_super_for_current_class(Symbol* super_name) { |
|
418 |
if (!is_loading_from_source()) { |
|
419 |
return NULL; |
|
420 |
} |
|
421 |
||
422 |
InstanceKlass* k = lookup_class_by_id(super()); |
|
423 |
if (super_name != k->name()) { |
|
424 |
error("The specified super class %s (id %d) does not match actual super class %s", |
|
425 |
k->name()->as_klass_external_name(), super(), |
|
426 |
super_name->as_klass_external_name()); |
|
427 |
} |
|
428 |
return k; |
|
429 |
} |
|
430 |
||
431 |
InstanceKlass* ClassListParser::lookup_interface_for_current_class(Symbol* interface_name) { |
|
432 |
if (!is_loading_from_source()) { |
|
433 |
return NULL; |
|
434 |
} |
|
435 |
||
436 |
const int n = _interfaces->length(); |
|
437 |
if (n == 0) { |
|
438 |
error("Class %s implements the interface %s, but no interface has been specified in the input line", |
|
439 |
_class_name, interface_name->as_klass_external_name()); |
|
440 |
ShouldNotReachHere(); |
|
441 |
} |
|
442 |
||
443 |
int i; |
|
444 |
for (i=0; i<n; i++) { |
|
445 |
InstanceKlass* k = lookup_class_by_id(_interfaces->at(i)); |
|
446 |
if (interface_name == k->name()) { |
|
447 |
return k; |
|
448 |
} |
|
449 |
} |
|
450 |
||
451 |
// interface_name is not specified by the "interfaces:" keyword. |
|
452 |
print_specified_interfaces(); |
|
453 |
error("The interface %s implemented by class %s does not match any of the specified interface IDs", |
|
454 |
interface_name->as_klass_external_name(), _class_name); |
|
455 |
ShouldNotReachHere(); |
|
456 |
return NULL; |
|
457 |
} |
|
458 |