Mercurial > hg > truffle
annotate src/share/vm/classfile/javaClasses.cpp @ 538:fcb923bad68e jdk7-b47
Merge
author | trims |
---|---|
date | Tue, 10 Feb 2009 20:33:36 -0800 |
parents | c81d2ef51ca3 |
children | 0fbdb4381b99 |
rev | line source |
---|---|
0 | 1 /* |
196 | 2 * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. |
0 | 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
20 * CA 95054 USA or visit www.sun.com if you need additional information or | |
21 * have any questions. | |
22 * | |
23 */ | |
24 | |
25 # include "incls/_precompiled.incl" | |
26 # include "incls/_javaClasses.cpp.incl" | |
27 | |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
28 // Helpful routine for computing field offsets at run time rather than hardcoding them |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
29 static void |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
30 compute_offset(int &dest_offset, |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
31 klassOop klass_oop, symbolOop name_symbol, symbolOop signature_symbol) { |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
32 fieldDescriptor fd; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
33 instanceKlass* ik = instanceKlass::cast(klass_oop); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
34 if (!ik->find_local_field(name_symbol, signature_symbol, &fd)) { |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
35 ResourceMark rm; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
36 tty->print_cr("Invalid layout of %s at %s", ik->external_name(), name_symbol->as_C_string()); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
37 fatal("Invalid layout of preloaded class"); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
38 } |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
39 dest_offset = fd.offset(); |
0 | 40 } |
41 | |
42 // Same as above but for "optional" offsets that might not be present in certain JDK versions | |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
43 static void |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
44 compute_optional_offset(int& dest_offset, |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
45 klassOop klass_oop, symbolOop name_symbol, symbolOop signature_symbol) { |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
46 fieldDescriptor fd; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
47 instanceKlass* ik = instanceKlass::cast(klass_oop); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
48 if (ik->find_local_field(name_symbol, signature_symbol, &fd)) { |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
49 dest_offset = fd.offset(); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
50 } |
0 | 51 } |
52 | |
53 Handle java_lang_String::basic_create(int length, bool tenured, TRAPS) { | |
54 // Create the String object first, so there's a chance that the String | |
55 // and the char array it points to end up in the same cache line. | |
56 oop obj; | |
57 if (tenured) { | |
58 obj = instanceKlass::cast(SystemDictionary::string_klass())->allocate_permanent_instance(CHECK_NH); | |
59 } else { | |
60 obj = instanceKlass::cast(SystemDictionary::string_klass())->allocate_instance(CHECK_NH); | |
61 } | |
62 | |
63 // Create the char array. The String object must be handlized here | |
64 // because GC can happen as a result of the allocation attempt. | |
65 Handle h_obj(THREAD, obj); | |
66 typeArrayOop buffer; | |
67 if (tenured) { | |
68 buffer = oopFactory::new_permanent_charArray(length, CHECK_NH); | |
69 } else { | |
70 buffer = oopFactory::new_charArray(length, CHECK_NH); | |
71 } | |
72 | |
73 // Point the String at the char array | |
74 obj = h_obj(); | |
75 set_value(obj, buffer); | |
76 // No need to zero the offset, allocation zero'ed the entire String object | |
77 assert(offset(obj) == 0, "initial String offset should be zero"); | |
78 //set_offset(obj, 0); | |
79 set_count(obj, length); | |
80 | |
81 return h_obj; | |
82 } | |
83 | |
84 Handle java_lang_String::basic_create_from_unicode(jchar* unicode, int length, bool tenured, TRAPS) { | |
85 Handle h_obj = basic_create(length, tenured, CHECK_NH); | |
86 typeArrayOop buffer = value(h_obj()); | |
87 for (int index = 0; index < length; index++) { | |
88 buffer->char_at_put(index, unicode[index]); | |
89 } | |
90 return h_obj; | |
91 } | |
92 | |
93 Handle java_lang_String::create_from_unicode(jchar* unicode, int length, TRAPS) { | |
94 return basic_create_from_unicode(unicode, length, false, CHECK_NH); | |
95 } | |
96 | |
97 Handle java_lang_String::create_tenured_from_unicode(jchar* unicode, int length, TRAPS) { | |
98 return basic_create_from_unicode(unicode, length, true, CHECK_NH); | |
99 } | |
100 | |
101 oop java_lang_String::create_oop_from_unicode(jchar* unicode, int length, TRAPS) { | |
102 Handle h_obj = basic_create_from_unicode(unicode, length, false, CHECK_0); | |
103 return h_obj(); | |
104 } | |
105 | |
106 Handle java_lang_String::create_from_str(const char* utf8_str, TRAPS) { | |
107 if (utf8_str == NULL) { | |
108 return Handle(); | |
109 } | |
110 int length = UTF8::unicode_length(utf8_str); | |
111 Handle h_obj = basic_create(length, false, CHECK_NH); | |
112 if (length > 0) { | |
113 UTF8::convert_to_unicode(utf8_str, value(h_obj())->char_at_addr(0), length); | |
114 } | |
115 return h_obj; | |
116 } | |
117 | |
118 oop java_lang_String::create_oop_from_str(const char* utf8_str, TRAPS) { | |
119 Handle h_obj = create_from_str(utf8_str, CHECK_0); | |
120 return h_obj(); | |
121 } | |
122 | |
123 Handle java_lang_String::create_from_symbol(symbolHandle symbol, TRAPS) { | |
124 int length = UTF8::unicode_length((char*)symbol->bytes(), symbol->utf8_length()); | |
125 Handle h_obj = basic_create(length, false, CHECK_NH); | |
126 if (length > 0) { | |
127 UTF8::convert_to_unicode((char*)symbol->bytes(), value(h_obj())->char_at_addr(0), length); | |
128 } | |
129 return h_obj; | |
130 } | |
131 | |
132 // Converts a C string to a Java String based on current encoding | |
133 Handle java_lang_String::create_from_platform_dependent_str(const char* str, TRAPS) { | |
134 assert(str != NULL, "bad arguments"); | |
135 | |
136 typedef jstring (*to_java_string_fn_t)(JNIEnv*, const char *); | |
137 static to_java_string_fn_t _to_java_string_fn = NULL; | |
138 | |
139 if (_to_java_string_fn == NULL) { | |
140 void *lib_handle = os::native_java_library(); | |
141 _to_java_string_fn = CAST_TO_FN_PTR(to_java_string_fn_t, hpi::dll_lookup(lib_handle, "NewStringPlatform")); | |
142 if (_to_java_string_fn == NULL) { | |
143 fatal("NewStringPlatform missing"); | |
144 } | |
145 } | |
146 | |
147 jstring js = NULL; | |
148 { JavaThread* thread = (JavaThread*)THREAD; | |
149 assert(thread->is_Java_thread(), "must be java thread"); | |
22
90f5ddc7297b
6646946: Kernel installation failed on Japanese and Chinese XP SP2 (VM part)
coleenp
parents:
0
diff
changeset
|
150 HandleMark hm(thread); |
0 | 151 ThreadToNativeFromVM ttn(thread); |
152 js = (_to_java_string_fn)(thread->jni_environment(), str); | |
153 } | |
154 return Handle(THREAD, JNIHandles::resolve(js)); | |
155 } | |
156 | |
22
90f5ddc7297b
6646946: Kernel installation failed on Japanese and Chinese XP SP2 (VM part)
coleenp
parents:
0
diff
changeset
|
157 // Converts a Java String to a native C string that can be used for |
90f5ddc7297b
6646946: Kernel installation failed on Japanese and Chinese XP SP2 (VM part)
coleenp
parents:
0
diff
changeset
|
158 // native OS calls. |
90f5ddc7297b
6646946: Kernel installation failed on Japanese and Chinese XP SP2 (VM part)
coleenp
parents:
0
diff
changeset
|
159 char* java_lang_String::as_platform_dependent_str(Handle java_string, TRAPS) { |
90f5ddc7297b
6646946: Kernel installation failed on Japanese and Chinese XP SP2 (VM part)
coleenp
parents:
0
diff
changeset
|
160 |
90f5ddc7297b
6646946: Kernel installation failed on Japanese and Chinese XP SP2 (VM part)
coleenp
parents:
0
diff
changeset
|
161 typedef char* (*to_platform_string_fn_t)(JNIEnv*, jstring, bool*); |
90f5ddc7297b
6646946: Kernel installation failed on Japanese and Chinese XP SP2 (VM part)
coleenp
parents:
0
diff
changeset
|
162 static to_platform_string_fn_t _to_platform_string_fn = NULL; |
90f5ddc7297b
6646946: Kernel installation failed on Japanese and Chinese XP SP2 (VM part)
coleenp
parents:
0
diff
changeset
|
163 |
90f5ddc7297b
6646946: Kernel installation failed on Japanese and Chinese XP SP2 (VM part)
coleenp
parents:
0
diff
changeset
|
164 if (_to_platform_string_fn == NULL) { |
90f5ddc7297b
6646946: Kernel installation failed on Japanese and Chinese XP SP2 (VM part)
coleenp
parents:
0
diff
changeset
|
165 void *lib_handle = os::native_java_library(); |
90f5ddc7297b
6646946: Kernel installation failed on Japanese and Chinese XP SP2 (VM part)
coleenp
parents:
0
diff
changeset
|
166 _to_platform_string_fn = CAST_TO_FN_PTR(to_platform_string_fn_t, hpi::dll_lookup(lib_handle, "GetStringPlatformChars")); |
90f5ddc7297b
6646946: Kernel installation failed on Japanese and Chinese XP SP2 (VM part)
coleenp
parents:
0
diff
changeset
|
167 if (_to_platform_string_fn == NULL) { |
90f5ddc7297b
6646946: Kernel installation failed on Japanese and Chinese XP SP2 (VM part)
coleenp
parents:
0
diff
changeset
|
168 fatal("GetStringPlatformChars missing"); |
90f5ddc7297b
6646946: Kernel installation failed on Japanese and Chinese XP SP2 (VM part)
coleenp
parents:
0
diff
changeset
|
169 } |
90f5ddc7297b
6646946: Kernel installation failed on Japanese and Chinese XP SP2 (VM part)
coleenp
parents:
0
diff
changeset
|
170 } |
90f5ddc7297b
6646946: Kernel installation failed on Japanese and Chinese XP SP2 (VM part)
coleenp
parents:
0
diff
changeset
|
171 |
90f5ddc7297b
6646946: Kernel installation failed on Japanese and Chinese XP SP2 (VM part)
coleenp
parents:
0
diff
changeset
|
172 char *native_platform_string; |
90f5ddc7297b
6646946: Kernel installation failed on Japanese and Chinese XP SP2 (VM part)
coleenp
parents:
0
diff
changeset
|
173 { JavaThread* thread = (JavaThread*)THREAD; |
90f5ddc7297b
6646946: Kernel installation failed on Japanese and Chinese XP SP2 (VM part)
coleenp
parents:
0
diff
changeset
|
174 assert(thread->is_Java_thread(), "must be java thread"); |
90f5ddc7297b
6646946: Kernel installation failed on Japanese and Chinese XP SP2 (VM part)
coleenp
parents:
0
diff
changeset
|
175 JNIEnv *env = thread->jni_environment(); |
90f5ddc7297b
6646946: Kernel installation failed on Japanese and Chinese XP SP2 (VM part)
coleenp
parents:
0
diff
changeset
|
176 jstring js = (jstring) JNIHandles::make_local(env, java_string()); |
90f5ddc7297b
6646946: Kernel installation failed on Japanese and Chinese XP SP2 (VM part)
coleenp
parents:
0
diff
changeset
|
177 bool is_copy; |
90f5ddc7297b
6646946: Kernel installation failed on Japanese and Chinese XP SP2 (VM part)
coleenp
parents:
0
diff
changeset
|
178 HandleMark hm(thread); |
90f5ddc7297b
6646946: Kernel installation failed on Japanese and Chinese XP SP2 (VM part)
coleenp
parents:
0
diff
changeset
|
179 ThreadToNativeFromVM ttn(thread); |
90f5ddc7297b
6646946: Kernel installation failed on Japanese and Chinese XP SP2 (VM part)
coleenp
parents:
0
diff
changeset
|
180 native_platform_string = (_to_platform_string_fn)(env, js, &is_copy); |
90f5ddc7297b
6646946: Kernel installation failed on Japanese and Chinese XP SP2 (VM part)
coleenp
parents:
0
diff
changeset
|
181 assert(is_copy == JNI_TRUE, "is_copy value changed"); |
90f5ddc7297b
6646946: Kernel installation failed on Japanese and Chinese XP SP2 (VM part)
coleenp
parents:
0
diff
changeset
|
182 JNIHandles::destroy_local(js); |
90f5ddc7297b
6646946: Kernel installation failed on Japanese and Chinese XP SP2 (VM part)
coleenp
parents:
0
diff
changeset
|
183 } |
90f5ddc7297b
6646946: Kernel installation failed on Japanese and Chinese XP SP2 (VM part)
coleenp
parents:
0
diff
changeset
|
184 return native_platform_string; |
90f5ddc7297b
6646946: Kernel installation failed on Japanese and Chinese XP SP2 (VM part)
coleenp
parents:
0
diff
changeset
|
185 } |
90f5ddc7297b
6646946: Kernel installation failed on Japanese and Chinese XP SP2 (VM part)
coleenp
parents:
0
diff
changeset
|
186 |
0 | 187 Handle java_lang_String::char_converter(Handle java_string, jchar from_char, jchar to_char, TRAPS) { |
188 oop obj = java_string(); | |
189 // Typical usage is to convert all '/' to '.' in string. | |
190 typeArrayOop value = java_lang_String::value(obj); | |
191 int offset = java_lang_String::offset(obj); | |
192 int length = java_lang_String::length(obj); | |
193 | |
194 // First check if any from_char exist | |
195 int index; // Declared outside, used later | |
196 for (index = 0; index < length; index++) { | |
197 if (value->char_at(index + offset) == from_char) { | |
198 break; | |
199 } | |
200 } | |
201 if (index == length) { | |
202 // No from_char, so do not copy. | |
203 return java_string; | |
204 } | |
205 | |
206 // Create new UNICODE buffer. Must handlize value because GC | |
207 // may happen during String and char array creation. | |
208 typeArrayHandle h_value(THREAD, value); | |
209 Handle string = basic_create(length, false, CHECK_NH); | |
210 | |
211 typeArrayOop from_buffer = h_value(); | |
212 typeArrayOop to_buffer = java_lang_String::value(string()); | |
213 | |
214 // Copy contents | |
215 for (index = 0; index < length; index++) { | |
216 jchar c = from_buffer->char_at(index + offset); | |
217 if (c == from_char) { | |
218 c = to_char; | |
219 } | |
220 to_buffer->char_at_put(index, c); | |
221 } | |
222 return string; | |
223 } | |
224 | |
225 jchar* java_lang_String::as_unicode_string(oop java_string, int& length) { | |
226 typeArrayOop value = java_lang_String::value(java_string); | |
227 int offset = java_lang_String::offset(java_string); | |
228 length = java_lang_String::length(java_string); | |
229 | |
230 jchar* result = NEW_RESOURCE_ARRAY(jchar, length); | |
231 for (int index = 0; index < length; index++) { | |
232 result[index] = value->char_at(index + offset); | |
233 } | |
234 return result; | |
235 } | |
236 | |
237 symbolHandle java_lang_String::as_symbol(Handle java_string, TRAPS) { | |
238 oop obj = java_string(); | |
239 typeArrayOop value = java_lang_String::value(obj); | |
240 int offset = java_lang_String::offset(obj); | |
241 int length = java_lang_String::length(obj); | |
242 | |
243 ResourceMark rm(THREAD); | |
244 symbolHandle result; | |
245 | |
246 if (length > 0) { | |
247 int utf8_length = UNICODE::utf8_length(value->char_at_addr(offset), length); | |
248 char* chars = NEW_RESOURCE_ARRAY(char, utf8_length + 1); | |
249 UNICODE::convert_to_utf8(value->char_at_addr(offset), length, chars); | |
250 // Allocate the symbol | |
251 result = oopFactory::new_symbol_handle(chars, utf8_length, CHECK_(symbolHandle())); | |
252 } else { | |
253 result = oopFactory::new_symbol_handle("", 0, CHECK_(symbolHandle())); | |
254 } | |
255 return result; | |
256 } | |
257 | |
258 int java_lang_String::utf8_length(oop java_string) { | |
259 typeArrayOop value = java_lang_String::value(java_string); | |
260 int offset = java_lang_String::offset(java_string); | |
261 int length = java_lang_String::length(java_string); | |
262 jchar* position = (length == 0) ? NULL : value->char_at_addr(offset); | |
263 return UNICODE::utf8_length(position, length); | |
264 } | |
265 | |
266 char* java_lang_String::as_utf8_string(oop java_string) { | |
267 typeArrayOop value = java_lang_String::value(java_string); | |
268 int offset = java_lang_String::offset(java_string); | |
269 int length = java_lang_String::length(java_string); | |
270 jchar* position = (length == 0) ? NULL : value->char_at_addr(offset); | |
271 return UNICODE::as_utf8(position, length); | |
272 } | |
273 | |
274 char* java_lang_String::as_utf8_string(oop java_string, int start, int len) { | |
275 typeArrayOop value = java_lang_String::value(java_string); | |
276 int offset = java_lang_String::offset(java_string); | |
277 int length = java_lang_String::length(java_string); | |
278 assert(start + len <= length, "just checking"); | |
279 jchar* position = value->char_at_addr(offset + start); | |
280 return UNICODE::as_utf8(position, len); | |
281 } | |
282 | |
283 bool java_lang_String::equals(oop java_string, jchar* chars, int len) { | |
284 assert(SharedSkipVerify || | |
285 java_string->klass() == SystemDictionary::string_klass(), | |
286 "must be java_string"); | |
287 typeArrayOop value = java_lang_String::value(java_string); | |
288 int offset = java_lang_String::offset(java_string); | |
289 int length = java_lang_String::length(java_string); | |
290 if (length != len) { | |
291 return false; | |
292 } | |
293 for (int i = 0; i < len; i++) { | |
294 if (value->char_at(i + offset) != chars[i]) { | |
295 return false; | |
296 } | |
297 } | |
298 return true; | |
299 } | |
300 | |
301 void java_lang_String::print(Handle java_string, outputStream* st) { | |
302 oop obj = java_string(); | |
303 assert(obj->klass() == SystemDictionary::string_klass(), "must be java_string"); | |
304 typeArrayOop value = java_lang_String::value(obj); | |
305 int offset = java_lang_String::offset(obj); | |
306 int length = java_lang_String::length(obj); | |
307 | |
308 int end = MIN2(length, 100); | |
309 if (value == NULL) { | |
310 // This can happen if, e.g., printing a String | |
311 // object before its initializer has been called | |
312 st->print_cr("NULL"); | |
313 } else { | |
314 st->print("\""); | |
315 for (int index = 0; index < length; index++) { | |
316 st->print("%c", value->char_at(index + offset)); | |
317 } | |
318 st->print("\""); | |
319 } | |
320 } | |
321 | |
322 | |
323 oop java_lang_Class::create_mirror(KlassHandle k, TRAPS) { | |
324 assert(k->java_mirror() == NULL, "should only assign mirror once"); | |
325 // Use this moment of initialization to cache modifier_flags also, | |
326 // to support Class.getModifiers(). Instance classes recalculate | |
327 // the cached flags after the class file is parsed, but before the | |
328 // class is put into the system dictionary. | |
329 int computed_modifiers = k->compute_modifier_flags(CHECK_0); | |
330 k->set_modifier_flags(computed_modifiers); | |
331 if (SystemDictionary::class_klass_loaded()) { | |
332 // Allocate mirror (java.lang.Class instance) | |
333 Handle mirror = instanceKlass::cast(SystemDictionary::class_klass())->allocate_permanent_instance(CHECK_0); | |
334 // Setup indirections | |
335 mirror->obj_field_put(klass_offset, k()); | |
336 k->set_java_mirror(mirror()); | |
337 // It might also have a component mirror. This mirror must already exist. | |
338 if (k->oop_is_javaArray()) { | |
339 Handle comp_mirror; | |
340 if (k->oop_is_typeArray()) { | |
341 BasicType type = typeArrayKlass::cast(k->as_klassOop())->element_type(); | |
342 comp_mirror = Universe::java_mirror(type); | |
343 assert(comp_mirror.not_null(), "must have primitive mirror"); | |
344 } else if (k->oop_is_objArray()) { | |
345 klassOop element_klass = objArrayKlass::cast(k->as_klassOop())->element_klass(); | |
346 if (element_klass != NULL | |
347 && (Klass::cast(element_klass)->oop_is_instance() || | |
348 Klass::cast(element_klass)->oop_is_javaArray())) { | |
349 comp_mirror = Klass::cast(element_klass)->java_mirror(); | |
350 assert(comp_mirror.not_null(), "must have element mirror"); | |
351 } | |
352 // else some object array internal to the VM, like systemObjArrayKlassObj | |
353 } | |
354 if (comp_mirror.not_null()) { | |
355 // Two-way link between the array klass and its component mirror: | |
356 arrayKlass::cast(k->as_klassOop())->set_component_mirror(comp_mirror()); | |
357 set_array_klass(comp_mirror(), k->as_klassOop()); | |
358 } | |
359 } | |
360 return mirror(); | |
361 } else { | |
362 return NULL; | |
363 } | |
364 } | |
365 | |
366 | |
367 oop java_lang_Class::create_basic_type_mirror(const char* basic_type_name, BasicType type, TRAPS) { | |
368 // This should be improved by adding a field at the Java level or by | |
369 // introducing a new VM klass (see comment in ClassFileParser) | |
370 oop java_class = instanceKlass::cast(SystemDictionary::class_klass())->allocate_permanent_instance(CHECK_0); | |
371 if (type != T_VOID) { | |
372 klassOop aklass = Universe::typeArrayKlassObj(type); | |
373 assert(aklass != NULL, "correct bootstrap"); | |
374 set_array_klass(java_class, aklass); | |
375 } | |
376 return java_class; | |
377 } | |
378 | |
379 | |
380 klassOop java_lang_Class::as_klassOop(oop java_class) { | |
381 //%note memory_2 | |
382 klassOop k = klassOop(java_class->obj_field(klass_offset)); | |
383 assert(k == NULL || k->is_klass(), "type check"); | |
384 return k; | |
385 } | |
386 | |
387 | |
388 klassOop java_lang_Class::array_klass(oop java_class) { | |
389 klassOop k = klassOop(java_class->obj_field(array_klass_offset)); | |
390 assert(k == NULL || k->is_klass() && Klass::cast(k)->oop_is_javaArray(), "should be array klass"); | |
391 return k; | |
392 } | |
393 | |
394 | |
395 void java_lang_Class::set_array_klass(oop java_class, klassOop klass) { | |
396 assert(klass->is_klass() && Klass::cast(klass)->oop_is_javaArray(), "should be array klass"); | |
397 java_class->obj_field_put(array_klass_offset, klass); | |
398 } | |
399 | |
400 | |
401 methodOop java_lang_Class::resolved_constructor(oop java_class) { | |
402 oop constructor = java_class->obj_field(resolved_constructor_offset); | |
403 assert(constructor == NULL || constructor->is_method(), "should be method"); | |
404 return methodOop(constructor); | |
405 } | |
406 | |
407 | |
408 void java_lang_Class::set_resolved_constructor(oop java_class, methodOop constructor) { | |
409 assert(constructor->is_method(), "should be method"); | |
410 java_class->obj_field_put(resolved_constructor_offset, constructor); | |
411 } | |
412 | |
413 | |
414 bool java_lang_Class::is_primitive(oop java_class) { | |
415 klassOop k = klassOop(java_class->obj_field(klass_offset)); | |
416 return k == NULL; | |
417 } | |
418 | |
419 | |
420 BasicType java_lang_Class::primitive_type(oop java_class) { | |
421 assert(java_lang_Class::is_primitive(java_class), "just checking"); | |
422 klassOop ak = klassOop(java_class->obj_field(array_klass_offset)); | |
423 BasicType type = T_VOID; | |
424 if (ak != NULL) { | |
425 // Note: create_basic_type_mirror above initializes ak to a non-null value. | |
426 type = arrayKlass::cast(ak)->element_type(); | |
427 } else { | |
428 assert(java_class == Universe::void_mirror(), "only valid non-array primitive"); | |
429 } | |
430 assert(Universe::java_mirror(type) == java_class, "must be consistent"); | |
431 return type; | |
432 } | |
433 | |
434 | |
435 oop java_lang_Class::primitive_mirror(BasicType t) { | |
436 oop mirror = Universe::java_mirror(t); | |
437 assert(mirror != NULL && mirror->is_a(SystemDictionary::class_klass()), "must be a Class"); | |
438 assert(java_lang_Class::is_primitive(mirror), "must be primitive"); | |
439 return mirror; | |
440 } | |
441 | |
442 bool java_lang_Class::offsets_computed = false; | |
443 int java_lang_Class::classRedefinedCount_offset = -1; | |
514 | 444 int java_lang_Class::parallelCapable_offset = -1; |
0 | 445 |
446 void java_lang_Class::compute_offsets() { | |
447 assert(!offsets_computed, "offsets should be initialized only once"); | |
448 offsets_computed = true; | |
449 | |
450 klassOop k = SystemDictionary::class_klass(); | |
451 // The classRedefinedCount field is only present starting in 1.5, | |
452 // so don't go fatal. | |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
453 compute_optional_offset(classRedefinedCount_offset, |
0 | 454 k, vmSymbols::classRedefinedCount_name(), vmSymbols::int_signature()); |
514 | 455 |
456 // The field indicating parallelCapable (parallelLockMap) is only present starting in 7, | |
457 klassOop k1 = SystemDictionary::classloader_klass(); | |
458 compute_optional_offset(parallelCapable_offset, | |
459 k1, vmSymbols::parallelCapable_name(), vmSymbols::concurrenthashmap_signature()); | |
460 } | |
461 | |
462 // For class loader classes, parallelCapable defined | |
463 // based on non-null field | |
464 // Written to by java.lang.ClassLoader, vm only reads this field, doesn't set it | |
465 bool java_lang_Class::parallelCapable(oop class_loader) { | |
466 if (!JDK_Version::is_gte_jdk17x_version() | |
467 || parallelCapable_offset == -1) { | |
468 // Default for backward compatibility is false | |
469 return false; | |
470 } | |
471 return (class_loader->obj_field(parallelCapable_offset) != NULL); | |
0 | 472 } |
473 | |
474 int java_lang_Class::classRedefinedCount(oop the_class_mirror) { | |
475 if (!JDK_Version::is_gte_jdk15x_version() | |
476 || classRedefinedCount_offset == -1) { | |
477 // The classRedefinedCount field is only present starting in 1.5. | |
478 // If we don't have an offset for it then just return -1 as a marker. | |
479 return -1; | |
480 } | |
481 | |
482 return the_class_mirror->int_field(classRedefinedCount_offset); | |
483 } | |
484 | |
485 void java_lang_Class::set_classRedefinedCount(oop the_class_mirror, int value) { | |
486 if (!JDK_Version::is_gte_jdk15x_version() | |
487 || classRedefinedCount_offset == -1) { | |
488 // The classRedefinedCount field is only present starting in 1.5. | |
489 // If we don't have an offset for it then nothing to set. | |
490 return; | |
491 } | |
492 | |
493 the_class_mirror->int_field_put(classRedefinedCount_offset, value); | |
494 } | |
495 | |
496 | |
497 // Note: JDK1.1 and before had a privateInfo_offset field which was used for the | |
498 // platform thread structure, and a eetop offset which was used for thread | |
499 // local storage (and unused by the HotSpot VM). In JDK1.2 the two structures | |
500 // merged, so in the HotSpot VM we just use the eetop field for the thread | |
501 // instead of the privateInfo_offset. | |
502 // | |
503 // Note: The stackSize field is only present starting in 1.4. | |
504 | |
505 int java_lang_Thread::_name_offset = 0; | |
506 int java_lang_Thread::_group_offset = 0; | |
507 int java_lang_Thread::_contextClassLoader_offset = 0; | |
508 int java_lang_Thread::_inheritedAccessControlContext_offset = 0; | |
509 int java_lang_Thread::_priority_offset = 0; | |
510 int java_lang_Thread::_eetop_offset = 0; | |
511 int java_lang_Thread::_daemon_offset = 0; | |
512 int java_lang_Thread::_stillborn_offset = 0; | |
513 int java_lang_Thread::_stackSize_offset = 0; | |
514 int java_lang_Thread::_tid_offset = 0; | |
515 int java_lang_Thread::_thread_status_offset = 0; | |
516 int java_lang_Thread::_park_blocker_offset = 0; | |
517 int java_lang_Thread::_park_event_offset = 0 ; | |
518 | |
519 | |
520 void java_lang_Thread::compute_offsets() { | |
521 assert(_group_offset == 0, "offsets should be initialized only once"); | |
522 | |
523 klassOop k = SystemDictionary::thread_klass(); | |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
524 compute_offset(_name_offset, k, vmSymbols::name_name(), vmSymbols::char_array_signature()); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
525 compute_offset(_group_offset, k, vmSymbols::group_name(), vmSymbols::threadgroup_signature()); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
526 compute_offset(_contextClassLoader_offset, k, vmSymbols::contextClassLoader_name(), vmSymbols::classloader_signature()); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
527 compute_offset(_inheritedAccessControlContext_offset, k, vmSymbols::inheritedAccessControlContext_name(), vmSymbols::accesscontrolcontext_signature()); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
528 compute_offset(_priority_offset, k, vmSymbols::priority_name(), vmSymbols::int_signature()); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
529 compute_offset(_daemon_offset, k, vmSymbols::daemon_name(), vmSymbols::bool_signature()); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
530 compute_offset(_eetop_offset, k, vmSymbols::eetop_name(), vmSymbols::long_signature()); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
531 compute_offset(_stillborn_offset, k, vmSymbols::stillborn_name(), vmSymbols::bool_signature()); |
0 | 532 // The stackSize field is only present starting in 1.4, so don't go fatal. |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
533 compute_optional_offset(_stackSize_offset, k, vmSymbols::stackSize_name(), vmSymbols::long_signature()); |
0 | 534 // The tid and thread_status fields are only present starting in 1.5, so don't go fatal. |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
535 compute_optional_offset(_tid_offset, k, vmSymbols::thread_id_name(), vmSymbols::long_signature()); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
536 compute_optional_offset(_thread_status_offset, k, vmSymbols::thread_status_name(), vmSymbols::int_signature()); |
0 | 537 // The parkBlocker field is only present starting in 1.6, so don't go fatal. |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
538 compute_optional_offset(_park_blocker_offset, k, vmSymbols::park_blocker_name(), vmSymbols::object_signature()); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
539 compute_optional_offset(_park_event_offset, k, vmSymbols::park_event_name(), |
0 | 540 vmSymbols::long_signature()); |
541 } | |
542 | |
543 | |
544 JavaThread* java_lang_Thread::thread(oop java_thread) { | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
98
diff
changeset
|
545 return (JavaThread*)java_thread->address_field(_eetop_offset); |
0 | 546 } |
547 | |
548 | |
549 void java_lang_Thread::set_thread(oop java_thread, JavaThread* thread) { | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
98
diff
changeset
|
550 java_thread->address_field_put(_eetop_offset, (address)thread); |
0 | 551 } |
552 | |
553 | |
554 typeArrayOop java_lang_Thread::name(oop java_thread) { | |
555 oop name = java_thread->obj_field(_name_offset); | |
556 assert(name == NULL || (name->is_typeArray() && typeArrayKlass::cast(name->klass())->element_type() == T_CHAR), "just checking"); | |
557 return typeArrayOop(name); | |
558 } | |
559 | |
560 | |
561 void java_lang_Thread::set_name(oop java_thread, typeArrayOop name) { | |
562 assert(java_thread->obj_field(_name_offset) == NULL, "name should be NULL"); | |
563 java_thread->obj_field_put(_name_offset, name); | |
564 } | |
565 | |
566 | |
567 ThreadPriority java_lang_Thread::priority(oop java_thread) { | |
568 return (ThreadPriority)java_thread->int_field(_priority_offset); | |
569 } | |
570 | |
571 | |
572 void java_lang_Thread::set_priority(oop java_thread, ThreadPriority priority) { | |
573 java_thread->int_field_put(_priority_offset, priority); | |
574 } | |
575 | |
576 | |
577 oop java_lang_Thread::threadGroup(oop java_thread) { | |
578 return java_thread->obj_field(_group_offset); | |
579 } | |
580 | |
581 | |
582 bool java_lang_Thread::is_stillborn(oop java_thread) { | |
583 return java_thread->bool_field(_stillborn_offset) != 0; | |
584 } | |
585 | |
586 | |
587 // We never have reason to turn the stillborn bit off | |
588 void java_lang_Thread::set_stillborn(oop java_thread) { | |
589 java_thread->bool_field_put(_stillborn_offset, true); | |
590 } | |
591 | |
592 | |
593 bool java_lang_Thread::is_alive(oop java_thread) { | |
594 JavaThread* thr = java_lang_Thread::thread(java_thread); | |
595 return (thr != NULL); | |
596 } | |
597 | |
598 | |
599 bool java_lang_Thread::is_daemon(oop java_thread) { | |
600 return java_thread->bool_field(_daemon_offset) != 0; | |
601 } | |
602 | |
603 | |
604 void java_lang_Thread::set_daemon(oop java_thread) { | |
605 java_thread->bool_field_put(_daemon_offset, true); | |
606 } | |
607 | |
608 oop java_lang_Thread::context_class_loader(oop java_thread) { | |
609 return java_thread->obj_field(_contextClassLoader_offset); | |
610 } | |
611 | |
612 oop java_lang_Thread::inherited_access_control_context(oop java_thread) { | |
613 return java_thread->obj_field(_inheritedAccessControlContext_offset); | |
614 } | |
615 | |
616 | |
617 jlong java_lang_Thread::stackSize(oop java_thread) { | |
618 // The stackSize field is only present starting in 1.4 | |
619 if (_stackSize_offset > 0) { | |
620 assert(JDK_Version::is_gte_jdk14x_version(), "sanity check"); | |
621 return java_thread->long_field(_stackSize_offset); | |
622 } else { | |
623 return 0; | |
624 } | |
625 } | |
626 | |
627 // Write the thread status value to threadStatus field in java.lang.Thread java class. | |
628 void java_lang_Thread::set_thread_status(oop java_thread, | |
629 java_lang_Thread::ThreadStatus status) { | |
630 assert(JavaThread::current()->thread_state() == _thread_in_vm, "Java Thread is not running in vm"); | |
631 // The threadStatus is only present starting in 1.5 | |
632 if (_thread_status_offset > 0) { | |
633 java_thread->int_field_put(_thread_status_offset, status); | |
634 } | |
635 } | |
636 | |
637 // Read thread status value from threadStatus field in java.lang.Thread java class. | |
638 java_lang_Thread::ThreadStatus java_lang_Thread::get_thread_status(oop java_thread) { | |
639 assert(Thread::current()->is_VM_thread() || | |
640 JavaThread::current()->thread_state() == _thread_in_vm, | |
641 "Java Thread is not running in vm"); | |
642 // The threadStatus is only present starting in 1.5 | |
643 if (_thread_status_offset > 0) { | |
644 return (java_lang_Thread::ThreadStatus)java_thread->int_field(_thread_status_offset); | |
645 } else { | |
646 // All we can easily figure out is if it is alive, but that is | |
647 // enough info for a valid unknown status. | |
648 // These aren't restricted to valid set ThreadStatus values, so | |
649 // use JVMTI values and cast. | |
650 JavaThread* thr = java_lang_Thread::thread(java_thread); | |
651 if (thr == NULL) { | |
652 // the thread hasn't run yet or is in the process of exiting | |
653 return NEW; | |
654 } | |
655 return (java_lang_Thread::ThreadStatus)JVMTI_THREAD_STATE_ALIVE; | |
656 } | |
657 } | |
658 | |
659 | |
660 jlong java_lang_Thread::thread_id(oop java_thread) { | |
661 // The thread ID field is only present starting in 1.5 | |
662 if (_tid_offset > 0) { | |
663 return java_thread->long_field(_tid_offset); | |
664 } else { | |
665 return 0; | |
666 } | |
667 } | |
668 | |
669 oop java_lang_Thread::park_blocker(oop java_thread) { | |
242 | 670 assert(JDK_Version::current().supports_thread_park_blocker() && |
671 _park_blocker_offset != 0, "Must support parkBlocker field"); | |
0 | 672 |
673 if (_park_blocker_offset > 0) { | |
674 return java_thread->obj_field(_park_blocker_offset); | |
675 } | |
676 | |
677 return NULL; | |
678 } | |
679 | |
680 jlong java_lang_Thread::park_event(oop java_thread) { | |
681 if (_park_event_offset > 0) { | |
682 return java_thread->long_field(_park_event_offset); | |
683 } | |
684 return 0; | |
685 } | |
686 | |
687 bool java_lang_Thread::set_park_event(oop java_thread, jlong ptr) { | |
688 if (_park_event_offset > 0) { | |
689 java_thread->long_field_put(_park_event_offset, ptr); | |
690 return true; | |
691 } | |
692 return false; | |
693 } | |
694 | |
695 | |
696 const char* java_lang_Thread::thread_status_name(oop java_thread) { | |
697 assert(JDK_Version::is_gte_jdk15x_version() && _thread_status_offset != 0, "Must have thread status"); | |
698 ThreadStatus status = (java_lang_Thread::ThreadStatus)java_thread->int_field(_thread_status_offset); | |
699 switch (status) { | |
700 case NEW : return "NEW"; | |
701 case RUNNABLE : return "RUNNABLE"; | |
702 case SLEEPING : return "TIMED_WAITING (sleeping)"; | |
703 case IN_OBJECT_WAIT : return "WAITING (on object monitor)"; | |
704 case IN_OBJECT_WAIT_TIMED : return "TIMED_WAITING (on object monitor)"; | |
705 case PARKED : return "WAITING (parking)"; | |
706 case PARKED_TIMED : return "TIMED_WAITING (parking)"; | |
707 case BLOCKED_ON_MONITOR_ENTER : return "BLOCKED (on object monitor)"; | |
708 case TERMINATED : return "TERMINATED"; | |
709 default : return "UNKNOWN"; | |
710 }; | |
711 } | |
712 int java_lang_ThreadGroup::_parent_offset = 0; | |
713 int java_lang_ThreadGroup::_name_offset = 0; | |
714 int java_lang_ThreadGroup::_threads_offset = 0; | |
715 int java_lang_ThreadGroup::_groups_offset = 0; | |
716 int java_lang_ThreadGroup::_maxPriority_offset = 0; | |
717 int java_lang_ThreadGroup::_destroyed_offset = 0; | |
718 int java_lang_ThreadGroup::_daemon_offset = 0; | |
719 int java_lang_ThreadGroup::_vmAllowSuspension_offset = 0; | |
720 int java_lang_ThreadGroup::_nthreads_offset = 0; | |
721 int java_lang_ThreadGroup::_ngroups_offset = 0; | |
722 | |
723 oop java_lang_ThreadGroup::parent(oop java_thread_group) { | |
724 assert(java_thread_group->is_oop(), "thread group must be oop"); | |
725 return java_thread_group->obj_field(_parent_offset); | |
726 } | |
727 | |
728 // ("name as oop" accessor is not necessary) | |
729 | |
730 typeArrayOop java_lang_ThreadGroup::name(oop java_thread_group) { | |
731 oop name = java_thread_group->obj_field(_name_offset); | |
732 // ThreadGroup.name can be null | |
733 return name == NULL ? (typeArrayOop)NULL : java_lang_String::value(name); | |
734 } | |
735 | |
736 int java_lang_ThreadGroup::nthreads(oop java_thread_group) { | |
737 assert(java_thread_group->is_oop(), "thread group must be oop"); | |
738 return java_thread_group->int_field(_nthreads_offset); | |
739 } | |
740 | |
741 objArrayOop java_lang_ThreadGroup::threads(oop java_thread_group) { | |
742 oop threads = java_thread_group->obj_field(_threads_offset); | |
743 assert(threads != NULL, "threadgroups should have threads"); | |
744 assert(threads->is_objArray(), "just checking"); // Todo: Add better type checking code | |
745 return objArrayOop(threads); | |
746 } | |
747 | |
748 int java_lang_ThreadGroup::ngroups(oop java_thread_group) { | |
749 assert(java_thread_group->is_oop(), "thread group must be oop"); | |
750 return java_thread_group->int_field(_ngroups_offset); | |
751 } | |
752 | |
753 objArrayOop java_lang_ThreadGroup::groups(oop java_thread_group) { | |
754 oop groups = java_thread_group->obj_field(_groups_offset); | |
755 assert(groups == NULL || groups->is_objArray(), "just checking"); // Todo: Add better type checking code | |
756 return objArrayOop(groups); | |
757 } | |
758 | |
759 ThreadPriority java_lang_ThreadGroup::maxPriority(oop java_thread_group) { | |
760 assert(java_thread_group->is_oop(), "thread group must be oop"); | |
761 return (ThreadPriority) java_thread_group->int_field(_maxPriority_offset); | |
762 } | |
763 | |
764 bool java_lang_ThreadGroup::is_destroyed(oop java_thread_group) { | |
765 assert(java_thread_group->is_oop(), "thread group must be oop"); | |
766 return java_thread_group->bool_field(_destroyed_offset) != 0; | |
767 } | |
768 | |
769 bool java_lang_ThreadGroup::is_daemon(oop java_thread_group) { | |
770 assert(java_thread_group->is_oop(), "thread group must be oop"); | |
771 return java_thread_group->bool_field(_daemon_offset) != 0; | |
772 } | |
773 | |
774 bool java_lang_ThreadGroup::is_vmAllowSuspension(oop java_thread_group) { | |
775 assert(java_thread_group->is_oop(), "thread group must be oop"); | |
776 return java_thread_group->bool_field(_vmAllowSuspension_offset) != 0; | |
777 } | |
778 | |
779 void java_lang_ThreadGroup::compute_offsets() { | |
780 assert(_parent_offset == 0, "offsets should be initialized only once"); | |
781 | |
782 klassOop k = SystemDictionary::threadGroup_klass(); | |
783 | |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
784 compute_offset(_parent_offset, k, vmSymbols::parent_name(), vmSymbols::threadgroup_signature()); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
785 compute_offset(_name_offset, k, vmSymbols::name_name(), vmSymbols::string_signature()); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
786 compute_offset(_threads_offset, k, vmSymbols::threads_name(), vmSymbols::thread_array_signature()); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
787 compute_offset(_groups_offset, k, vmSymbols::groups_name(), vmSymbols::threadgroup_array_signature()); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
788 compute_offset(_maxPriority_offset, k, vmSymbols::maxPriority_name(), vmSymbols::int_signature()); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
789 compute_offset(_destroyed_offset, k, vmSymbols::destroyed_name(), vmSymbols::bool_signature()); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
790 compute_offset(_daemon_offset, k, vmSymbols::daemon_name(), vmSymbols::bool_signature()); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
791 compute_offset(_vmAllowSuspension_offset, k, vmSymbols::vmAllowSuspension_name(), vmSymbols::bool_signature()); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
792 compute_offset(_nthreads_offset, k, vmSymbols::nthreads_name(), vmSymbols::int_signature()); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
793 compute_offset(_ngroups_offset, k, vmSymbols::ngroups_name(), vmSymbols::int_signature()); |
0 | 794 } |
795 | |
796 oop java_lang_Throwable::backtrace(oop throwable) { | |
797 return throwable->obj_field_acquire(backtrace_offset); | |
798 } | |
799 | |
800 | |
801 void java_lang_Throwable::set_backtrace(oop throwable, oop value) { | |
802 throwable->release_obj_field_put(backtrace_offset, value); | |
803 } | |
804 | |
805 | |
806 oop java_lang_Throwable::message(oop throwable) { | |
807 return throwable->obj_field(detailMessage_offset); | |
808 } | |
809 | |
810 | |
811 oop java_lang_Throwable::message(Handle throwable) { | |
812 return throwable->obj_field(detailMessage_offset); | |
813 } | |
814 | |
815 | |
816 void java_lang_Throwable::set_message(oop throwable, oop value) { | |
817 throwable->obj_field_put(detailMessage_offset, value); | |
818 } | |
819 | |
820 | |
821 void java_lang_Throwable::clear_stacktrace(oop throwable) { | |
822 assert(JDK_Version::is_gte_jdk14x_version(), "should only be called in >= 1.4"); | |
823 throwable->obj_field_put(stackTrace_offset, NULL); | |
824 } | |
825 | |
826 | |
827 void java_lang_Throwable::print(oop throwable, outputStream* st) { | |
828 ResourceMark rm; | |
829 klassOop k = throwable->klass(); | |
830 assert(k != NULL, "just checking"); | |
831 st->print("%s", instanceKlass::cast(k)->external_name()); | |
832 oop msg = message(throwable); | |
833 if (msg != NULL) { | |
834 st->print(": %s", java_lang_String::as_utf8_string(msg)); | |
835 } | |
836 } | |
837 | |
838 | |
839 void java_lang_Throwable::print(Handle throwable, outputStream* st) { | |
840 ResourceMark rm; | |
841 klassOop k = throwable->klass(); | |
842 assert(k != NULL, "just checking"); | |
843 st->print("%s", instanceKlass::cast(k)->external_name()); | |
844 oop msg = message(throwable); | |
845 if (msg != NULL) { | |
846 st->print(": %s", java_lang_String::as_utf8_string(msg)); | |
847 } | |
848 } | |
849 | |
850 // Print stack trace element to resource allocated buffer | |
851 char* java_lang_Throwable::print_stack_element_to_buffer(methodOop method, int bci) { | |
852 // Get strings and string lengths | |
853 instanceKlass* klass = instanceKlass::cast(method->method_holder()); | |
854 const char* klass_name = klass->external_name(); | |
855 int buf_len = (int)strlen(klass_name); | |
856 char* source_file_name; | |
857 if (klass->source_file_name() == NULL) { | |
858 source_file_name = NULL; | |
859 } else { | |
860 source_file_name = klass->source_file_name()->as_C_string(); | |
861 buf_len += (int)strlen(source_file_name); | |
862 } | |
863 char* method_name = method->name()->as_C_string(); | |
864 buf_len += (int)strlen(method_name); | |
865 | |
866 // Allocate temporary buffer with extra space for formatting and line number | |
867 char* buf = NEW_RESOURCE_ARRAY(char, buf_len + 64); | |
868 | |
869 // Print stack trace line in buffer | |
870 sprintf(buf, "\tat %s.%s", klass_name, method_name); | |
871 if (method->is_native()) { | |
872 strcat(buf, "(Native Method)"); | |
873 } else { | |
874 int line_number = method->line_number_from_bci(bci); | |
875 if (source_file_name != NULL && (line_number != -1)) { | |
876 // Sourcename and linenumber | |
877 sprintf(buf + (int)strlen(buf), "(%s:%d)", source_file_name, line_number); | |
878 } else if (source_file_name != NULL) { | |
879 // Just sourcename | |
880 sprintf(buf + (int)strlen(buf), "(%s)", source_file_name); | |
881 } else { | |
882 // Neither soucename and linenumber | |
883 sprintf(buf + (int)strlen(buf), "(Unknown Source)"); | |
884 } | |
885 nmethod* nm = method->code(); | |
886 if (WizardMode && nm != NULL) { | |
513
2328d1d3f8cf
6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents:
242
diff
changeset
|
887 sprintf(buf + (int)strlen(buf), "(nmethod " PTR_FORMAT ")", (intptr_t)nm); |
0 | 888 } |
889 } | |
890 | |
891 return buf; | |
892 } | |
893 | |
894 | |
895 void java_lang_Throwable::print_stack_element(Handle stream, methodOop method, int bci) { | |
896 ResourceMark rm; | |
897 char* buf = print_stack_element_to_buffer(method, bci); | |
898 print_to_stream(stream, buf); | |
899 } | |
900 | |
901 void java_lang_Throwable::print_stack_element(outputStream *st, methodOop method, int bci) { | |
902 ResourceMark rm; | |
903 char* buf = print_stack_element_to_buffer(method, bci); | |
904 st->print_cr("%s", buf); | |
905 } | |
906 | |
907 void java_lang_Throwable::print_to_stream(Handle stream, const char* str) { | |
908 if (stream.is_null()) { | |
909 tty->print_cr("%s", str); | |
910 } else { | |
911 EXCEPTION_MARK; | |
912 JavaValue result(T_VOID); | |
913 Handle arg (THREAD, oopFactory::new_charArray(str, THREAD)); | |
914 if (!HAS_PENDING_EXCEPTION) { | |
915 JavaCalls::call_virtual(&result, | |
916 stream, | |
917 KlassHandle(THREAD, stream->klass()), | |
918 vmSymbolHandles::println_name(), | |
919 vmSymbolHandles::char_array_void_signature(), | |
920 arg, | |
921 THREAD); | |
922 } | |
923 // Ignore any exceptions. we are in the middle of exception handling. Same as classic VM. | |
924 if (HAS_PENDING_EXCEPTION) CLEAR_PENDING_EXCEPTION; | |
925 } | |
926 | |
927 } | |
928 | |
929 | |
930 const char* java_lang_Throwable::no_stack_trace_message() { | |
931 return "\t<<no stack trace available>>"; | |
932 } | |
933 | |
934 | |
935 // Currently used only for exceptions occurring during startup | |
936 void java_lang_Throwable::print_stack_trace(oop throwable, outputStream* st) { | |
937 Thread *THREAD = Thread::current(); | |
938 Handle h_throwable(THREAD, throwable); | |
939 while (h_throwable.not_null()) { | |
940 objArrayHandle result (THREAD, objArrayOop(backtrace(h_throwable()))); | |
941 if (result.is_null()) { | |
942 st->print_cr(no_stack_trace_message()); | |
943 return; | |
944 } | |
945 | |
946 while (result.not_null()) { | |
947 objArrayHandle methods (THREAD, | |
948 objArrayOop(result->obj_at(trace_methods_offset))); | |
949 typeArrayHandle bcis (THREAD, | |
950 typeArrayOop(result->obj_at(trace_bcis_offset))); | |
951 | |
952 if (methods.is_null() || bcis.is_null()) { | |
953 st->print_cr(no_stack_trace_message()); | |
954 return; | |
955 } | |
956 | |
957 int length = methods()->length(); | |
958 for (int index = 0; index < length; index++) { | |
959 methodOop method = methodOop(methods()->obj_at(index)); | |
960 if (method == NULL) goto handle_cause; | |
961 int bci = bcis->ushort_at(index); | |
962 print_stack_element(st, method, bci); | |
963 } | |
964 result = objArrayHandle(THREAD, objArrayOop(result->obj_at(trace_next_offset))); | |
965 } | |
966 handle_cause: | |
967 { | |
968 EXCEPTION_MARK; | |
969 JavaValue result(T_OBJECT); | |
970 JavaCalls::call_virtual(&result, | |
971 h_throwable, | |
972 KlassHandle(THREAD, h_throwable->klass()), | |
973 vmSymbolHandles::getCause_name(), | |
974 vmSymbolHandles::void_throwable_signature(), | |
975 THREAD); | |
976 // Ignore any exceptions. we are in the middle of exception handling. Same as classic VM. | |
977 if (HAS_PENDING_EXCEPTION) { | |
978 CLEAR_PENDING_EXCEPTION; | |
979 h_throwable = Handle(); | |
980 } else { | |
981 h_throwable = Handle(THREAD, (oop) result.get_jobject()); | |
982 if (h_throwable.not_null()) { | |
983 st->print("Caused by: "); | |
984 print(h_throwable, st); | |
985 st->cr(); | |
986 } | |
987 } | |
988 } | |
989 } | |
990 } | |
991 | |
992 | |
993 void java_lang_Throwable::print_stack_trace(oop throwable, oop print_stream) { | |
994 // Note: this is no longer used in Merlin, but we support it for compatibility. | |
995 Thread *thread = Thread::current(); | |
996 Handle stream(thread, print_stream); | |
997 objArrayHandle result (thread, objArrayOop(backtrace(throwable))); | |
998 if (result.is_null()) { | |
999 print_to_stream(stream, no_stack_trace_message()); | |
1000 return; | |
1001 } | |
1002 | |
1003 while (result.not_null()) { | |
1004 objArrayHandle methods (thread, | |
1005 objArrayOop(result->obj_at(trace_methods_offset))); | |
1006 typeArrayHandle bcis (thread, | |
1007 typeArrayOop(result->obj_at(trace_bcis_offset))); | |
1008 | |
1009 if (methods.is_null() || bcis.is_null()) { | |
1010 print_to_stream(stream, no_stack_trace_message()); | |
1011 return; | |
1012 } | |
1013 | |
1014 int length = methods()->length(); | |
1015 for (int index = 0; index < length; index++) { | |
1016 methodOop method = methodOop(methods()->obj_at(index)); | |
1017 if (method == NULL) return; | |
1018 int bci = bcis->ushort_at(index); | |
1019 print_stack_element(stream, method, bci); | |
1020 } | |
1021 result = objArrayHandle(thread, objArrayOop(result->obj_at(trace_next_offset))); | |
1022 } | |
1023 } | |
1024 | |
1025 // This class provides a simple wrapper over the internal structure of | |
1026 // exception backtrace to insulate users of the backtrace from needing | |
1027 // to know what it looks like. | |
1028 class BacktraceBuilder: public StackObj { | |
1029 private: | |
1030 Handle _backtrace; | |
1031 objArrayOop _head; | |
1032 objArrayOop _methods; | |
1033 typeArrayOop _bcis; | |
1034 int _index; | |
1035 bool _dirty; | |
1036 No_Safepoint_Verifier _nsv; | |
1037 | |
1038 public: | |
1039 | |
1040 enum { | |
1041 trace_methods_offset = java_lang_Throwable::trace_methods_offset, | |
1042 trace_bcis_offset = java_lang_Throwable::trace_bcis_offset, | |
1043 trace_next_offset = java_lang_Throwable::trace_next_offset, | |
1044 trace_size = java_lang_Throwable::trace_size, | |
1045 trace_chunk_size = java_lang_Throwable::trace_chunk_size | |
1046 }; | |
1047 | |
1048 // constructor for new backtrace | |
98
deb97b8ef02b
6679708: No_Safepoint_Verifier and BacktraceBuilder have uninitialized fields
never
parents:
22
diff
changeset
|
1049 BacktraceBuilder(TRAPS): _methods(NULL), _bcis(NULL), _head(NULL), _dirty(false) { |
0 | 1050 expand(CHECK); |
1051 _backtrace = _head; | |
1052 _index = 0; | |
1053 } | |
1054 | |
1055 void flush() { | |
1056 if (_dirty && _methods != NULL) { | |
1057 BarrierSet* bs = Universe::heap()->barrier_set(); | |
1058 assert(bs->has_write_ref_array_opt(), "Barrier set must have ref array opt"); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
98
diff
changeset
|
1059 bs->write_ref_array(MemRegion((HeapWord*)_methods->base(), |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
98
diff
changeset
|
1060 _methods->array_size())); |
0 | 1061 _dirty = false; |
1062 } | |
1063 } | |
1064 | |
1065 void expand(TRAPS) { | |
1066 flush(); | |
1067 | |
1068 objArrayHandle old_head(THREAD, _head); | |
1069 Pause_No_Safepoint_Verifier pnsv(&_nsv); | |
1070 | |
1071 objArrayOop head = oopFactory::new_objectArray(trace_size, CHECK); | |
1072 objArrayHandle new_head(THREAD, head); | |
1073 | |
1074 objArrayOop methods = oopFactory::new_objectArray(trace_chunk_size, CHECK); | |
1075 objArrayHandle new_methods(THREAD, methods); | |
1076 | |
1077 typeArrayOop bcis = oopFactory::new_shortArray(trace_chunk_size, CHECK); | |
1078 typeArrayHandle new_bcis(THREAD, bcis); | |
1079 | |
1080 if (!old_head.is_null()) { | |
1081 old_head->obj_at_put(trace_next_offset, new_head()); | |
1082 } | |
1083 new_head->obj_at_put(trace_methods_offset, new_methods()); | |
1084 new_head->obj_at_put(trace_bcis_offset, new_bcis()); | |
1085 | |
1086 _head = new_head(); | |
1087 _methods = new_methods(); | |
1088 _bcis = new_bcis(); | |
1089 _index = 0; | |
1090 } | |
1091 | |
1092 oop backtrace() { | |
1093 flush(); | |
1094 return _backtrace(); | |
1095 } | |
1096 | |
1097 inline void push(methodOop method, short bci, TRAPS) { | |
1098 if (_index >= trace_chunk_size) { | |
1099 methodHandle mhandle(THREAD, method); | |
1100 expand(CHECK); | |
1101 method = mhandle(); | |
1102 } | |
1103 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
98
diff
changeset
|
1104 _methods->obj_at_put(_index, method); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
98
diff
changeset
|
1105 // bad for UseCompressedOops |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
98
diff
changeset
|
1106 // *_methods->obj_at_addr(_index) = method; |
0 | 1107 _bcis->ushort_at_put(_index, bci); |
1108 _index++; | |
1109 _dirty = true; | |
1110 } | |
1111 | |
1112 methodOop current_method() { | |
1113 assert(_index >= 0 && _index < trace_chunk_size, "out of range"); | |
1114 return methodOop(_methods->obj_at(_index)); | |
1115 } | |
1116 | |
1117 jushort current_bci() { | |
1118 assert(_index >= 0 && _index < trace_chunk_size, "out of range"); | |
1119 return _bcis->ushort_at(_index); | |
1120 } | |
1121 }; | |
1122 | |
1123 | |
1124 void java_lang_Throwable::fill_in_stack_trace(Handle throwable, TRAPS) { | |
1125 if (!StackTraceInThrowable) return; | |
1126 ResourceMark rm(THREAD); | |
1127 | |
1128 // Start out by clearing the backtrace for this object, in case the VM | |
1129 // runs out of memory while allocating the stack trace | |
1130 set_backtrace(throwable(), NULL); | |
1131 if (JDK_Version::is_gte_jdk14x_version()) { | |
1132 // New since 1.4, clear lazily constructed Java level stacktrace if | |
1133 // refilling occurs | |
1134 clear_stacktrace(throwable()); | |
1135 } | |
1136 | |
1137 int max_depth = MaxJavaStackTraceDepth; | |
1138 JavaThread* thread = (JavaThread*)THREAD; | |
1139 BacktraceBuilder bt(CHECK); | |
1140 | |
1141 // Instead of using vframe directly, this version of fill_in_stack_trace | |
1142 // basically handles everything by hand. This significantly improved the | |
1143 // speed of this method call up to 28.5% on Solaris sparc. 27.1% on Windows. | |
1144 // See bug 6333838 for more details. | |
1145 // The "ASSERT" here is to verify this method generates the exactly same stack | |
1146 // trace as utilizing vframe. | |
1147 #ifdef ASSERT | |
1148 vframeStream st(thread); | |
1149 methodHandle st_method(THREAD, st.method()); | |
1150 #endif | |
1151 int total_count = 0; | |
1152 RegisterMap map(thread, false); | |
1153 int decode_offset = 0; | |
1154 nmethod* nm = NULL; | |
1155 bool skip_fillInStackTrace_check = false; | |
1156 bool skip_throwableInit_check = false; | |
1157 | |
1158 for (frame fr = thread->last_frame(); max_depth != total_count;) { | |
1159 methodOop method = NULL; | |
1160 int bci = 0; | |
1161 | |
1162 // Compiled java method case. | |
1163 if (decode_offset != 0) { | |
1164 DebugInfoReadStream stream(nm, decode_offset); | |
1165 decode_offset = stream.read_int(); | |
1166 method = (methodOop)nm->oop_at(stream.read_int()); | |
1167 bci = stream.read_bci(); | |
1168 } else { | |
1169 if (fr.is_first_frame()) break; | |
1170 address pc = fr.pc(); | |
1171 if (fr.is_interpreted_frame()) { | |
1172 intptr_t bcx = fr.interpreter_frame_bcx(); | |
1173 method = fr.interpreter_frame_method(); | |
1174 bci = fr.is_bci(bcx) ? bcx : method->bci_from((address)bcx); | |
1175 fr = fr.sender(&map); | |
1176 } else { | |
1177 CodeBlob* cb = fr.cb(); | |
1178 // HMMM QQQ might be nice to have frame return nm as NULL if cb is non-NULL | |
1179 // but non nmethod | |
1180 fr = fr.sender(&map); | |
1181 if (cb == NULL || !cb->is_nmethod()) { | |
1182 continue; | |
1183 } | |
1184 nm = (nmethod*)cb; | |
1185 if (nm->method()->is_native()) { | |
1186 method = nm->method(); | |
1187 bci = 0; | |
1188 } else { | |
1189 PcDesc* pd = nm->pc_desc_at(pc); | |
1190 decode_offset = pd->scope_decode_offset(); | |
1191 // if decode_offset is not equal to 0, it will execute the | |
1192 // "compiled java method case" at the beginning of the loop. | |
1193 continue; | |
1194 } | |
1195 } | |
1196 } | |
1197 #ifdef ASSERT | |
1198 assert(st_method() == method && st.bci() == bci, | |
1199 "Wrong stack trace"); | |
1200 st.next(); | |
1201 // vframeStream::method isn't GC-safe so store off a copy | |
1202 // of the methodOop in case we GC. | |
1203 if (!st.at_end()) { | |
1204 st_method = st.method(); | |
1205 } | |
1206 #endif | |
1207 if (!skip_fillInStackTrace_check) { | |
1208 // check "fillInStackTrace" only once, so we negate the flag | |
1209 // after the first time check. | |
1210 skip_fillInStackTrace_check = true; | |
1211 if (method->name() == vmSymbols::fillInStackTrace_name()) { | |
1212 continue; | |
1213 } | |
1214 } | |
1215 // skip <init> methods of the exceptions klass. If there is <init> methods | |
1216 // that belongs to a superclass of the exception we are going to skipping | |
1217 // them in stack trace. This is simlar to classic VM. | |
1218 if (!skip_throwableInit_check) { | |
1219 if (method->name() == vmSymbols::object_initializer_name() && | |
1220 throwable->is_a(method->method_holder())) { | |
1221 continue; | |
1222 } else { | |
1223 // if no "Throwable.init()" method found, we stop checking it next time. | |
1224 skip_throwableInit_check = true; | |
1225 } | |
1226 } | |
1227 bt.push(method, bci, CHECK); | |
1228 total_count++; | |
1229 } | |
1230 | |
1231 // Put completed stack trace into throwable object | |
1232 set_backtrace(throwable(), bt.backtrace()); | |
1233 } | |
1234 | |
1235 void java_lang_Throwable::fill_in_stack_trace(Handle throwable) { | |
1236 // No-op if stack trace is disabled | |
1237 if (!StackTraceInThrowable) { | |
1238 return; | |
1239 } | |
1240 | |
1241 // Disable stack traces for some preallocated out of memory errors | |
1242 if (!Universe::should_fill_in_stack_trace(throwable)) { | |
1243 return; | |
1244 } | |
1245 | |
1246 PRESERVE_EXCEPTION_MARK; | |
1247 | |
1248 JavaThread* thread = JavaThread::active(); | |
1249 fill_in_stack_trace(throwable, thread); | |
1250 // ignore exceptions thrown during stack trace filling | |
1251 CLEAR_PENDING_EXCEPTION; | |
1252 } | |
1253 | |
1254 void java_lang_Throwable::allocate_backtrace(Handle throwable, TRAPS) { | |
1255 // Allocate stack trace - backtrace is created but not filled in | |
1256 | |
1257 // No-op if stack trace is disabled | |
1258 if (!StackTraceInThrowable) return; | |
1259 | |
1260 objArrayOop h_oop = oopFactory::new_objectArray(trace_size, CHECK); | |
1261 objArrayHandle backtrace (THREAD, h_oop); | |
1262 objArrayOop m_oop = oopFactory::new_objectArray(trace_chunk_size, CHECK); | |
1263 objArrayHandle methods (THREAD, m_oop); | |
1264 typeArrayOop b = oopFactory::new_shortArray(trace_chunk_size, CHECK); | |
1265 typeArrayHandle bcis(THREAD, b); | |
1266 | |
1267 // backtrace has space for one chunk (next is NULL) | |
1268 backtrace->obj_at_put(trace_methods_offset, methods()); | |
1269 backtrace->obj_at_put(trace_bcis_offset, bcis()); | |
1270 set_backtrace(throwable(), backtrace()); | |
1271 } | |
1272 | |
1273 | |
1274 void java_lang_Throwable::fill_in_stack_trace_of_preallocated_backtrace(Handle throwable) { | |
1275 // Fill in stack trace into preallocated backtrace (no GC) | |
1276 | |
1277 // No-op if stack trace is disabled | |
1278 if (!StackTraceInThrowable) return; | |
1279 | |
1280 assert(throwable->is_a(SystemDictionary::throwable_klass()), "sanity check"); | |
1281 | |
1282 oop backtrace = java_lang_Throwable::backtrace(throwable()); | |
1283 assert(backtrace != NULL, "backtrace not preallocated"); | |
1284 | |
1285 oop m = objArrayOop(backtrace)->obj_at(trace_methods_offset); | |
1286 objArrayOop methods = objArrayOop(m); | |
1287 assert(methods != NULL && methods->length() > 0, "method array not preallocated"); | |
1288 | |
1289 oop b = objArrayOop(backtrace)->obj_at(trace_bcis_offset); | |
1290 typeArrayOop bcis = typeArrayOop(b); | |
1291 assert(bcis != NULL, "bci array not preallocated"); | |
1292 | |
1293 assert(methods->length() == bcis->length(), "method and bci arrays should match"); | |
1294 | |
1295 JavaThread* thread = JavaThread::current(); | |
1296 ResourceMark rm(thread); | |
1297 vframeStream st(thread); | |
1298 | |
1299 // Unlike fill_in_stack_trace we do not skip fillInStackTrace or throwable init | |
1300 // methods as preallocated errors aren't created by "java" code. | |
1301 | |
1302 // fill in as much stack trace as possible | |
1303 int max_chunks = MIN2(methods->length(), (int)MaxJavaStackTraceDepth); | |
1304 int chunk_count = 0; | |
1305 | |
1306 for (;!st.at_end(); st.next()) { | |
1307 // add element | |
1308 bcis->ushort_at_put(chunk_count, st.bci()); | |
1309 methods->obj_at_put(chunk_count, st.method()); | |
1310 | |
1311 chunk_count++; | |
1312 | |
1313 // Bail-out for deep stacks | |
1314 if (chunk_count >= max_chunks) break; | |
1315 } | |
1316 } | |
1317 | |
1318 | |
1319 int java_lang_Throwable::get_stack_trace_depth(oop throwable, TRAPS) { | |
1320 if (throwable == NULL) { | |
1321 THROW_0(vmSymbols::java_lang_NullPointerException()); | |
1322 } | |
1323 objArrayOop chunk = objArrayOop(backtrace(throwable)); | |
1324 int depth = 0; | |
1325 if (chunk != NULL) { | |
1326 // Iterate over chunks and count full ones | |
1327 while (true) { | |
1328 objArrayOop next = objArrayOop(chunk->obj_at(trace_next_offset)); | |
1329 if (next == NULL) break; | |
1330 depth += trace_chunk_size; | |
1331 chunk = next; | |
1332 } | |
1333 assert(chunk != NULL && chunk->obj_at(trace_next_offset) == NULL, "sanity check"); | |
1334 // Count element in remaining partial chunk | |
1335 objArrayOop methods = objArrayOop(chunk->obj_at(trace_methods_offset)); | |
1336 typeArrayOop bcis = typeArrayOop(chunk->obj_at(trace_bcis_offset)); | |
1337 assert(methods != NULL && bcis != NULL, "sanity check"); | |
1338 for (int i = 0; i < methods->length(); i++) { | |
1339 if (methods->obj_at(i) == NULL) break; | |
1340 depth++; | |
1341 } | |
1342 } | |
1343 return depth; | |
1344 } | |
1345 | |
1346 | |
1347 oop java_lang_Throwable::get_stack_trace_element(oop throwable, int index, TRAPS) { | |
1348 if (throwable == NULL) { | |
1349 THROW_0(vmSymbols::java_lang_NullPointerException()); | |
1350 } | |
1351 if (index < 0) { | |
1352 THROW_(vmSymbols::java_lang_IndexOutOfBoundsException(), NULL); | |
1353 } | |
1354 // Compute how many chunks to skip and index into actual chunk | |
1355 objArrayOop chunk = objArrayOop(backtrace(throwable)); | |
1356 int skip_chunks = index / trace_chunk_size; | |
1357 int chunk_index = index % trace_chunk_size; | |
1358 while (chunk != NULL && skip_chunks > 0) { | |
1359 chunk = objArrayOop(chunk->obj_at(trace_next_offset)); | |
1360 skip_chunks--; | |
1361 } | |
1362 if (chunk == NULL) { | |
1363 THROW_(vmSymbols::java_lang_IndexOutOfBoundsException(), NULL); | |
1364 } | |
1365 // Get method,bci from chunk | |
1366 objArrayOop methods = objArrayOop(chunk->obj_at(trace_methods_offset)); | |
1367 typeArrayOop bcis = typeArrayOop(chunk->obj_at(trace_bcis_offset)); | |
1368 assert(methods != NULL && bcis != NULL, "sanity check"); | |
1369 methodHandle method(THREAD, methodOop(methods->obj_at(chunk_index))); | |
1370 int bci = bcis->ushort_at(chunk_index); | |
1371 // Chunk can be partial full | |
1372 if (method.is_null()) { | |
1373 THROW_(vmSymbols::java_lang_IndexOutOfBoundsException(), NULL); | |
1374 } | |
1375 | |
1376 oop element = java_lang_StackTraceElement::create(method, bci, CHECK_0); | |
1377 return element; | |
1378 } | |
1379 | |
1380 oop java_lang_StackTraceElement::create(methodHandle method, int bci, TRAPS) { | |
1381 // SystemDictionary::stackTraceElement_klass() will be null for pre-1.4 JDKs | |
1382 assert(JDK_Version::is_gte_jdk14x_version(), "should only be called in >= 1.4"); | |
1383 | |
1384 // Allocate java.lang.StackTraceElement instance | |
1385 klassOop k = SystemDictionary::stackTraceElement_klass(); | |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1386 assert(k != NULL, "must be loaded in 1.4+"); |
0 | 1387 instanceKlassHandle ik (THREAD, k); |
1388 if (ik->should_be_initialized()) { | |
1389 ik->initialize(CHECK_0); | |
1390 } | |
1391 | |
1392 Handle element = ik->allocate_instance_handle(CHECK_0); | |
1393 // Fill in class name | |
1394 ResourceMark rm(THREAD); | |
1395 const char* str = instanceKlass::cast(method->method_holder())->external_name(); | |
1396 oop classname = StringTable::intern((char*) str, CHECK_0); | |
1397 java_lang_StackTraceElement::set_declaringClass(element(), classname); | |
1398 // Fill in method name | |
1399 oop methodname = StringTable::intern(method->name(), CHECK_0); | |
1400 java_lang_StackTraceElement::set_methodName(element(), methodname); | |
1401 // Fill in source file name | |
1402 symbolOop source = instanceKlass::cast(method->method_holder())->source_file_name(); | |
1403 oop filename = StringTable::intern(source, CHECK_0); | |
1404 java_lang_StackTraceElement::set_fileName(element(), filename); | |
1405 // File in source line number | |
1406 int line_number; | |
1407 if (method->is_native()) { | |
1408 // Negative value different from -1 below, enabling Java code in | |
1409 // class java.lang.StackTraceElement to distinguish "native" from | |
1410 // "no LineNumberTable". | |
1411 line_number = -2; | |
1412 } else { | |
1413 // Returns -1 if no LineNumberTable, and otherwise actual line number | |
1414 line_number = method->line_number_from_bci(bci); | |
1415 } | |
1416 java_lang_StackTraceElement::set_lineNumber(element(), line_number); | |
1417 | |
1418 return element(); | |
1419 } | |
1420 | |
1421 | |
1422 void java_lang_reflect_AccessibleObject::compute_offsets() { | |
1423 klassOop k = SystemDictionary::reflect_accessible_object_klass(); | |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1424 compute_offset(override_offset, k, vmSymbols::override_name(), vmSymbols::bool_signature()); |
0 | 1425 } |
1426 | |
1427 jboolean java_lang_reflect_AccessibleObject::override(oop reflect) { | |
1428 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); | |
1429 return (jboolean) reflect->bool_field(override_offset); | |
1430 } | |
1431 | |
1432 void java_lang_reflect_AccessibleObject::set_override(oop reflect, jboolean value) { | |
1433 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); | |
1434 reflect->bool_field_put(override_offset, (int) value); | |
1435 } | |
1436 | |
1437 void java_lang_reflect_Method::compute_offsets() { | |
1438 klassOop k = SystemDictionary::reflect_method_klass(); | |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1439 compute_offset(clazz_offset, k, vmSymbols::clazz_name(), vmSymbols::class_signature()); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1440 compute_offset(name_offset, k, vmSymbols::name_name(), vmSymbols::string_signature()); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1441 compute_offset(returnType_offset, k, vmSymbols::returnType_name(), vmSymbols::class_signature()); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1442 compute_offset(parameterTypes_offset, k, vmSymbols::parameterTypes_name(), vmSymbols::class_array_signature()); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1443 compute_offset(exceptionTypes_offset, k, vmSymbols::exceptionTypes_name(), vmSymbols::class_array_signature()); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1444 compute_offset(slot_offset, k, vmSymbols::slot_name(), vmSymbols::int_signature()); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1445 compute_offset(modifiers_offset, k, vmSymbols::modifiers_name(), vmSymbols::int_signature()); |
0 | 1446 // The generic signature and annotations fields are only present in 1.5 |
1447 signature_offset = -1; | |
1448 annotations_offset = -1; | |
1449 parameter_annotations_offset = -1; | |
1450 annotation_default_offset = -1; | |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1451 compute_optional_offset(signature_offset, k, vmSymbols::signature_name(), vmSymbols::string_signature()); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1452 compute_optional_offset(annotations_offset, k, vmSymbols::annotations_name(), vmSymbols::byte_array_signature()); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1453 compute_optional_offset(parameter_annotations_offset, k, vmSymbols::parameter_annotations_name(), vmSymbols::byte_array_signature()); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1454 compute_optional_offset(annotation_default_offset, k, vmSymbols::annotation_default_name(), vmSymbols::byte_array_signature()); |
0 | 1455 } |
1456 | |
1457 Handle java_lang_reflect_Method::create(TRAPS) { | |
1458 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); | |
1459 klassOop klass = SystemDictionary::reflect_method_klass(); | |
1460 // This class is eagerly initialized during VM initialization, since we keep a refence | |
1461 // to one of the methods | |
1462 assert(instanceKlass::cast(klass)->is_initialized(), "must be initialized"); | |
1463 return instanceKlass::cast(klass)->allocate_instance_handle(CHECK_NH); | |
1464 } | |
1465 | |
1466 oop java_lang_reflect_Method::clazz(oop reflect) { | |
1467 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); | |
1468 return reflect->obj_field(clazz_offset); | |
1469 } | |
1470 | |
1471 void java_lang_reflect_Method::set_clazz(oop reflect, oop value) { | |
1472 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); | |
1473 reflect->obj_field_put(clazz_offset, value); | |
1474 } | |
1475 | |
1476 int java_lang_reflect_Method::slot(oop reflect) { | |
1477 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); | |
1478 return reflect->int_field(slot_offset); | |
1479 } | |
1480 | |
1481 void java_lang_reflect_Method::set_slot(oop reflect, int value) { | |
1482 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); | |
1483 reflect->int_field_put(slot_offset, value); | |
1484 } | |
1485 | |
1486 oop java_lang_reflect_Method::name(oop method) { | |
1487 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); | |
1488 return method->obj_field(name_offset); | |
1489 } | |
1490 | |
1491 void java_lang_reflect_Method::set_name(oop method, oop value) { | |
1492 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); | |
1493 method->obj_field_put(name_offset, value); | |
1494 } | |
1495 | |
1496 oop java_lang_reflect_Method::return_type(oop method) { | |
1497 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); | |
1498 return method->obj_field(returnType_offset); | |
1499 } | |
1500 | |
1501 void java_lang_reflect_Method::set_return_type(oop method, oop value) { | |
1502 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); | |
1503 method->obj_field_put(returnType_offset, value); | |
1504 } | |
1505 | |
1506 oop java_lang_reflect_Method::parameter_types(oop method) { | |
1507 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); | |
1508 return method->obj_field(parameterTypes_offset); | |
1509 } | |
1510 | |
1511 void java_lang_reflect_Method::set_parameter_types(oop method, oop value) { | |
1512 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); | |
1513 method->obj_field_put(parameterTypes_offset, value); | |
1514 } | |
1515 | |
1516 oop java_lang_reflect_Method::exception_types(oop method) { | |
1517 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); | |
1518 return method->obj_field(exceptionTypes_offset); | |
1519 } | |
1520 | |
1521 void java_lang_reflect_Method::set_exception_types(oop method, oop value) { | |
1522 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); | |
1523 method->obj_field_put(exceptionTypes_offset, value); | |
1524 } | |
1525 | |
1526 int java_lang_reflect_Method::modifiers(oop method) { | |
1527 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); | |
1528 return method->int_field(modifiers_offset); | |
1529 } | |
1530 | |
1531 void java_lang_reflect_Method::set_modifiers(oop method, int value) { | |
1532 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); | |
1533 method->int_field_put(modifiers_offset, value); | |
1534 } | |
1535 | |
1536 bool java_lang_reflect_Method::has_signature_field() { | |
1537 return (signature_offset >= 0); | |
1538 } | |
1539 | |
1540 oop java_lang_reflect_Method::signature(oop method) { | |
1541 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); | |
1542 assert(has_signature_field(), "signature field must be present"); | |
1543 return method->obj_field(signature_offset); | |
1544 } | |
1545 | |
1546 void java_lang_reflect_Method::set_signature(oop method, oop value) { | |
1547 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); | |
1548 assert(has_signature_field(), "signature field must be present"); | |
1549 method->obj_field_put(signature_offset, value); | |
1550 } | |
1551 | |
1552 bool java_lang_reflect_Method::has_annotations_field() { | |
1553 return (annotations_offset >= 0); | |
1554 } | |
1555 | |
1556 oop java_lang_reflect_Method::annotations(oop method) { | |
1557 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); | |
1558 assert(has_annotations_field(), "annotations field must be present"); | |
1559 return method->obj_field(annotations_offset); | |
1560 } | |
1561 | |
1562 void java_lang_reflect_Method::set_annotations(oop method, oop value) { | |
1563 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); | |
1564 assert(has_annotations_field(), "annotations field must be present"); | |
1565 method->obj_field_put(annotations_offset, value); | |
1566 } | |
1567 | |
1568 bool java_lang_reflect_Method::has_parameter_annotations_field() { | |
1569 return (parameter_annotations_offset >= 0); | |
1570 } | |
1571 | |
1572 oop java_lang_reflect_Method::parameter_annotations(oop method) { | |
1573 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); | |
1574 assert(has_parameter_annotations_field(), "parameter annotations field must be present"); | |
1575 return method->obj_field(parameter_annotations_offset); | |
1576 } | |
1577 | |
1578 void java_lang_reflect_Method::set_parameter_annotations(oop method, oop value) { | |
1579 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); | |
1580 assert(has_parameter_annotations_field(), "parameter annotations field must be present"); | |
1581 method->obj_field_put(parameter_annotations_offset, value); | |
1582 } | |
1583 | |
1584 bool java_lang_reflect_Method::has_annotation_default_field() { | |
1585 return (annotation_default_offset >= 0); | |
1586 } | |
1587 | |
1588 oop java_lang_reflect_Method::annotation_default(oop method) { | |
1589 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); | |
1590 assert(has_annotation_default_field(), "annotation default field must be present"); | |
1591 return method->obj_field(annotation_default_offset); | |
1592 } | |
1593 | |
1594 void java_lang_reflect_Method::set_annotation_default(oop method, oop value) { | |
1595 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); | |
1596 assert(has_annotation_default_field(), "annotation default field must be present"); | |
1597 method->obj_field_put(annotation_default_offset, value); | |
1598 } | |
1599 | |
1600 void java_lang_reflect_Constructor::compute_offsets() { | |
1601 klassOop k = SystemDictionary::reflect_constructor_klass(); | |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1602 compute_offset(clazz_offset, k, vmSymbols::clazz_name(), vmSymbols::class_signature()); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1603 compute_offset(parameterTypes_offset, k, vmSymbols::parameterTypes_name(), vmSymbols::class_array_signature()); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1604 compute_offset(exceptionTypes_offset, k, vmSymbols::exceptionTypes_name(), vmSymbols::class_array_signature()); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1605 compute_offset(slot_offset, k, vmSymbols::slot_name(), vmSymbols::int_signature()); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1606 compute_offset(modifiers_offset, k, vmSymbols::modifiers_name(), vmSymbols::int_signature()); |
0 | 1607 // The generic signature and annotations fields are only present in 1.5 |
1608 signature_offset = -1; | |
1609 annotations_offset = -1; | |
1610 parameter_annotations_offset = -1; | |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1611 compute_optional_offset(signature_offset, k, vmSymbols::signature_name(), vmSymbols::string_signature()); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1612 compute_optional_offset(annotations_offset, k, vmSymbols::annotations_name(), vmSymbols::byte_array_signature()); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1613 compute_optional_offset(parameter_annotations_offset, k, vmSymbols::parameter_annotations_name(), vmSymbols::byte_array_signature()); |
0 | 1614 } |
1615 | |
1616 Handle java_lang_reflect_Constructor::create(TRAPS) { | |
1617 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); | |
1618 symbolHandle name = vmSymbolHandles::java_lang_reflect_Constructor(); | |
1619 klassOop k = SystemDictionary::resolve_or_fail(name, true, CHECK_NH); | |
1620 instanceKlassHandle klass (THREAD, k); | |
1621 // Ensure it is initialized | |
1622 klass->initialize(CHECK_NH); | |
1623 return klass->allocate_instance_handle(CHECK_NH); | |
1624 } | |
1625 | |
1626 oop java_lang_reflect_Constructor::clazz(oop reflect) { | |
1627 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); | |
1628 return reflect->obj_field(clazz_offset); | |
1629 } | |
1630 | |
1631 void java_lang_reflect_Constructor::set_clazz(oop reflect, oop value) { | |
1632 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); | |
1633 reflect->obj_field_put(clazz_offset, value); | |
1634 } | |
1635 | |
1636 oop java_lang_reflect_Constructor::parameter_types(oop constructor) { | |
1637 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); | |
1638 return constructor->obj_field(parameterTypes_offset); | |
1639 } | |
1640 | |
1641 void java_lang_reflect_Constructor::set_parameter_types(oop constructor, oop value) { | |
1642 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); | |
1643 constructor->obj_field_put(parameterTypes_offset, value); | |
1644 } | |
1645 | |
1646 oop java_lang_reflect_Constructor::exception_types(oop constructor) { | |
1647 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); | |
1648 return constructor->obj_field(exceptionTypes_offset); | |
1649 } | |
1650 | |
1651 void java_lang_reflect_Constructor::set_exception_types(oop constructor, oop value) { | |
1652 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); | |
1653 constructor->obj_field_put(exceptionTypes_offset, value); | |
1654 } | |
1655 | |
1656 int java_lang_reflect_Constructor::slot(oop reflect) { | |
1657 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); | |
1658 return reflect->int_field(slot_offset); | |
1659 } | |
1660 | |
1661 void java_lang_reflect_Constructor::set_slot(oop reflect, int value) { | |
1662 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); | |
1663 reflect->int_field_put(slot_offset, value); | |
1664 } | |
1665 | |
1666 int java_lang_reflect_Constructor::modifiers(oop constructor) { | |
1667 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); | |
1668 return constructor->int_field(modifiers_offset); | |
1669 } | |
1670 | |
1671 void java_lang_reflect_Constructor::set_modifiers(oop constructor, int value) { | |
1672 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); | |
1673 constructor->int_field_put(modifiers_offset, value); | |
1674 } | |
1675 | |
1676 bool java_lang_reflect_Constructor::has_signature_field() { | |
1677 return (signature_offset >= 0); | |
1678 } | |
1679 | |
1680 oop java_lang_reflect_Constructor::signature(oop constructor) { | |
1681 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); | |
1682 assert(has_signature_field(), "signature field must be present"); | |
1683 return constructor->obj_field(signature_offset); | |
1684 } | |
1685 | |
1686 void java_lang_reflect_Constructor::set_signature(oop constructor, oop value) { | |
1687 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); | |
1688 assert(has_signature_field(), "signature field must be present"); | |
1689 constructor->obj_field_put(signature_offset, value); | |
1690 } | |
1691 | |
1692 bool java_lang_reflect_Constructor::has_annotations_field() { | |
1693 return (annotations_offset >= 0); | |
1694 } | |
1695 | |
1696 oop java_lang_reflect_Constructor::annotations(oop constructor) { | |
1697 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); | |
1698 assert(has_annotations_field(), "annotations field must be present"); | |
1699 return constructor->obj_field(annotations_offset); | |
1700 } | |
1701 | |
1702 void java_lang_reflect_Constructor::set_annotations(oop constructor, oop value) { | |
1703 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); | |
1704 assert(has_annotations_field(), "annotations field must be present"); | |
1705 constructor->obj_field_put(annotations_offset, value); | |
1706 } | |
1707 | |
1708 bool java_lang_reflect_Constructor::has_parameter_annotations_field() { | |
1709 return (parameter_annotations_offset >= 0); | |
1710 } | |
1711 | |
1712 oop java_lang_reflect_Constructor::parameter_annotations(oop method) { | |
1713 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); | |
1714 assert(has_parameter_annotations_field(), "parameter annotations field must be present"); | |
1715 return method->obj_field(parameter_annotations_offset); | |
1716 } | |
1717 | |
1718 void java_lang_reflect_Constructor::set_parameter_annotations(oop method, oop value) { | |
1719 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); | |
1720 assert(has_parameter_annotations_field(), "parameter annotations field must be present"); | |
1721 method->obj_field_put(parameter_annotations_offset, value); | |
1722 } | |
1723 | |
1724 void java_lang_reflect_Field::compute_offsets() { | |
1725 klassOop k = SystemDictionary::reflect_field_klass(); | |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1726 compute_offset(clazz_offset, k, vmSymbols::clazz_name(), vmSymbols::class_signature()); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1727 compute_offset(name_offset, k, vmSymbols::name_name(), vmSymbols::string_signature()); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1728 compute_offset(type_offset, k, vmSymbols::type_name(), vmSymbols::class_signature()); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1729 compute_offset(slot_offset, k, vmSymbols::slot_name(), vmSymbols::int_signature()); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1730 compute_offset(modifiers_offset, k, vmSymbols::modifiers_name(), vmSymbols::int_signature()); |
0 | 1731 // The generic signature and annotations fields are only present in 1.5 |
1732 signature_offset = -1; | |
1733 annotations_offset = -1; | |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1734 compute_optional_offset(signature_offset, k, vmSymbols::signature_name(), vmSymbols::string_signature()); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1735 compute_optional_offset(annotations_offset, k, vmSymbols::annotations_name(), vmSymbols::byte_array_signature()); |
0 | 1736 } |
1737 | |
1738 Handle java_lang_reflect_Field::create(TRAPS) { | |
1739 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); | |
1740 symbolHandle name = vmSymbolHandles::java_lang_reflect_Field(); | |
1741 klassOop k = SystemDictionary::resolve_or_fail(name, true, CHECK_NH); | |
1742 instanceKlassHandle klass (THREAD, k); | |
1743 // Ensure it is initialized | |
1744 klass->initialize(CHECK_NH); | |
1745 return klass->allocate_instance_handle(CHECK_NH); | |
1746 } | |
1747 | |
1748 oop java_lang_reflect_Field::clazz(oop reflect) { | |
1749 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); | |
1750 return reflect->obj_field(clazz_offset); | |
1751 } | |
1752 | |
1753 void java_lang_reflect_Field::set_clazz(oop reflect, oop value) { | |
1754 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); | |
1755 reflect->obj_field_put(clazz_offset, value); | |
1756 } | |
1757 | |
1758 oop java_lang_reflect_Field::name(oop field) { | |
1759 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); | |
1760 return field->obj_field(name_offset); | |
1761 } | |
1762 | |
1763 void java_lang_reflect_Field::set_name(oop field, oop value) { | |
1764 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); | |
1765 field->obj_field_put(name_offset, value); | |
1766 } | |
1767 | |
1768 oop java_lang_reflect_Field::type(oop field) { | |
1769 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); | |
1770 return field->obj_field(type_offset); | |
1771 } | |
1772 | |
1773 void java_lang_reflect_Field::set_type(oop field, oop value) { | |
1774 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); | |
1775 field->obj_field_put(type_offset, value); | |
1776 } | |
1777 | |
1778 int java_lang_reflect_Field::slot(oop reflect) { | |
1779 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); | |
1780 return reflect->int_field(slot_offset); | |
1781 } | |
1782 | |
1783 void java_lang_reflect_Field::set_slot(oop reflect, int value) { | |
1784 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); | |
1785 reflect->int_field_put(slot_offset, value); | |
1786 } | |
1787 | |
1788 int java_lang_reflect_Field::modifiers(oop field) { | |
1789 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); | |
1790 return field->int_field(modifiers_offset); | |
1791 } | |
1792 | |
1793 void java_lang_reflect_Field::set_modifiers(oop field, int value) { | |
1794 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); | |
1795 field->int_field_put(modifiers_offset, value); | |
1796 } | |
1797 | |
1798 bool java_lang_reflect_Field::has_signature_field() { | |
1799 return (signature_offset >= 0); | |
1800 } | |
1801 | |
1802 oop java_lang_reflect_Field::signature(oop field) { | |
1803 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); | |
1804 assert(has_signature_field(), "signature field must be present"); | |
1805 return field->obj_field(signature_offset); | |
1806 } | |
1807 | |
1808 void java_lang_reflect_Field::set_signature(oop field, oop value) { | |
1809 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); | |
1810 assert(has_signature_field(), "signature field must be present"); | |
1811 field->obj_field_put(signature_offset, value); | |
1812 } | |
1813 | |
1814 bool java_lang_reflect_Field::has_annotations_field() { | |
1815 return (annotations_offset >= 0); | |
1816 } | |
1817 | |
1818 oop java_lang_reflect_Field::annotations(oop field) { | |
1819 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); | |
1820 assert(has_annotations_field(), "annotations field must be present"); | |
1821 return field->obj_field(annotations_offset); | |
1822 } | |
1823 | |
1824 void java_lang_reflect_Field::set_annotations(oop field, oop value) { | |
1825 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); | |
1826 assert(has_annotations_field(), "annotations field must be present"); | |
1827 field->obj_field_put(annotations_offset, value); | |
1828 } | |
1829 | |
1830 | |
1831 void sun_reflect_ConstantPool::compute_offsets() { | |
1832 klassOop k = SystemDictionary::reflect_constant_pool_klass(); | |
1833 // This null test can be removed post beta | |
1834 if (k != NULL) { | |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1835 compute_offset(_cp_oop_offset, k, vmSymbols::constantPoolOop_name(), vmSymbols::object_signature()); |
0 | 1836 } |
1837 } | |
1838 | |
1839 | |
1840 Handle sun_reflect_ConstantPool::create(TRAPS) { | |
1841 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); | |
1842 klassOop k = SystemDictionary::reflect_constant_pool_klass(); | |
1843 instanceKlassHandle klass (THREAD, k); | |
1844 // Ensure it is initialized | |
1845 klass->initialize(CHECK_NH); | |
1846 return klass->allocate_instance_handle(CHECK_NH); | |
1847 } | |
1848 | |
1849 | |
1850 oop sun_reflect_ConstantPool::cp_oop(oop reflect) { | |
1851 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); | |
1852 return reflect->obj_field(_cp_oop_offset); | |
1853 } | |
1854 | |
1855 | |
1856 void sun_reflect_ConstantPool::set_cp_oop(oop reflect, oop value) { | |
1857 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); | |
1858 reflect->obj_field_put(_cp_oop_offset, value); | |
1859 } | |
1860 | |
1861 void sun_reflect_UnsafeStaticFieldAccessorImpl::compute_offsets() { | |
1862 klassOop k = SystemDictionary::reflect_unsafe_static_field_accessor_impl_klass(); | |
1863 // This null test can be removed post beta | |
1864 if (k != NULL) { | |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1865 compute_offset(_base_offset, k, |
0 | 1866 vmSymbols::base_name(), vmSymbols::object_signature()); |
1867 } | |
1868 } | |
1869 | |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1870 oop java_lang_boxing_object::initialize_and_allocate(BasicType type, TRAPS) { |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1871 klassOop k = SystemDictionary::box_klass(type); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1872 if (k == NULL) return NULL; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1873 instanceKlassHandle h (THREAD, k); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1874 if (!h->is_initialized()) h->initialize(CHECK_0); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1875 return h->allocate_instance(THREAD); |
0 | 1876 } |
1877 | |
1878 | |
1879 oop java_lang_boxing_object::create(BasicType type, jvalue* value, TRAPS) { | |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1880 oop box = initialize_and_allocate(type, CHECK_0); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1881 if (box == NULL) return NULL; |
0 | 1882 switch (type) { |
1883 case T_BOOLEAN: | |
1884 box->bool_field_put(value_offset, value->z); | |
1885 break; | |
1886 case T_CHAR: | |
1887 box->char_field_put(value_offset, value->c); | |
1888 break; | |
1889 case T_FLOAT: | |
1890 box->float_field_put(value_offset, value->f); | |
1891 break; | |
1892 case T_DOUBLE: | |
165
437d03ea40b1
6703888: Compressed Oops: use the 32-bits gap after klass in a object
kvn
parents:
132
diff
changeset
|
1893 box->double_field_put(long_value_offset, value->d); |
0 | 1894 break; |
1895 case T_BYTE: | |
1896 box->byte_field_put(value_offset, value->b); | |
1897 break; | |
1898 case T_SHORT: | |
1899 box->short_field_put(value_offset, value->s); | |
1900 break; | |
1901 case T_INT: | |
1902 box->int_field_put(value_offset, value->i); | |
1903 break; | |
1904 case T_LONG: | |
165
437d03ea40b1
6703888: Compressed Oops: use the 32-bits gap after klass in a object
kvn
parents:
132
diff
changeset
|
1905 box->long_field_put(long_value_offset, value->j); |
0 | 1906 break; |
1907 default: | |
1908 return NULL; | |
1909 } | |
1910 return box; | |
1911 } | |
1912 | |
1913 | |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1914 BasicType java_lang_boxing_object::basic_type(oop box) { |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1915 if (box == NULL) return T_ILLEGAL; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1916 BasicType type = SystemDictionary::box_klass_type(box->klass()); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1917 if (type == T_OBJECT) // 'unknown' value returned by SD::bkt |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1918 return T_ILLEGAL; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1919 return type; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1920 } |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1921 |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1922 |
0 | 1923 BasicType java_lang_boxing_object::get_value(oop box, jvalue* value) { |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1924 BasicType type = SystemDictionary::box_klass_type(box->klass()); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1925 switch (type) { |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1926 case T_BOOLEAN: |
0 | 1927 value->z = box->bool_field(value_offset); |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1928 break; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1929 case T_CHAR: |
0 | 1930 value->c = box->char_field(value_offset); |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1931 break; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1932 case T_FLOAT: |
0 | 1933 value->f = box->float_field(value_offset); |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1934 break; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1935 case T_DOUBLE: |
165
437d03ea40b1
6703888: Compressed Oops: use the 32-bits gap after klass in a object
kvn
parents:
132
diff
changeset
|
1936 value->d = box->double_field(long_value_offset); |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1937 break; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1938 case T_BYTE: |
0 | 1939 value->b = box->byte_field(value_offset); |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1940 break; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1941 case T_SHORT: |
0 | 1942 value->s = box->short_field(value_offset); |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1943 break; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1944 case T_INT: |
0 | 1945 value->i = box->int_field(value_offset); |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1946 break; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1947 case T_LONG: |
165
437d03ea40b1
6703888: Compressed Oops: use the 32-bits gap after klass in a object
kvn
parents:
132
diff
changeset
|
1948 value->j = box->long_field(long_value_offset); |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1949 break; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1950 default: |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1951 return T_ILLEGAL; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1952 } // end switch |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1953 return type; |
0 | 1954 } |
1955 | |
1956 | |
1957 BasicType java_lang_boxing_object::set_value(oop box, jvalue* value) { | |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1958 BasicType type = SystemDictionary::box_klass_type(box->klass()); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1959 switch (type) { |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1960 case T_BOOLEAN: |
0 | 1961 box->bool_field_put(value_offset, value->z); |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1962 break; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1963 case T_CHAR: |
0 | 1964 box->char_field_put(value_offset, value->c); |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1965 break; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1966 case T_FLOAT: |
0 | 1967 box->float_field_put(value_offset, value->f); |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1968 break; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1969 case T_DOUBLE: |
165
437d03ea40b1
6703888: Compressed Oops: use the 32-bits gap after klass in a object
kvn
parents:
132
diff
changeset
|
1970 box->double_field_put(long_value_offset, value->d); |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1971 break; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1972 case T_BYTE: |
0 | 1973 box->byte_field_put(value_offset, value->b); |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1974 break; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1975 case T_SHORT: |
0 | 1976 box->short_field_put(value_offset, value->s); |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1977 break; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1978 case T_INT: |
0 | 1979 box->int_field_put(value_offset, value->i); |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1980 break; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1981 case T_LONG: |
165
437d03ea40b1
6703888: Compressed Oops: use the 32-bits gap after klass in a object
kvn
parents:
132
diff
changeset
|
1982 box->long_field_put(long_value_offset, value->j); |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1983 break; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1984 default: |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1985 return T_ILLEGAL; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1986 } // end switch |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
1987 return type; |
0 | 1988 } |
1989 | |
1990 | |
1991 // Support for java_lang_ref_Reference | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
98
diff
changeset
|
1992 oop java_lang_ref_Reference::pending_list_lock() { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
98
diff
changeset
|
1993 instanceKlass* ik = instanceKlass::cast(SystemDictionary::reference_klass()); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
98
diff
changeset
|
1994 char *addr = (((char *)ik->start_of_static_fields()) + static_lock_offset); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
98
diff
changeset
|
1995 if (UseCompressedOops) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
98
diff
changeset
|
1996 return oopDesc::load_decode_heap_oop((narrowOop *)addr); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
98
diff
changeset
|
1997 } else { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
98
diff
changeset
|
1998 return oopDesc::load_decode_heap_oop((oop*)addr); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
98
diff
changeset
|
1999 } |
0 | 2000 } |
2001 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
98
diff
changeset
|
2002 HeapWord *java_lang_ref_Reference::pending_list_addr() { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
98
diff
changeset
|
2003 instanceKlass* ik = instanceKlass::cast(SystemDictionary::reference_klass()); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
98
diff
changeset
|
2004 char *addr = (((char *)ik->start_of_static_fields()) + static_pending_offset); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
98
diff
changeset
|
2005 // XXX This might not be HeapWord aligned, almost rather be char *. |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
98
diff
changeset
|
2006 return (HeapWord*)addr; |
0 | 2007 } |
2008 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
98
diff
changeset
|
2009 oop java_lang_ref_Reference::pending_list() { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
98
diff
changeset
|
2010 char *addr = (char *)pending_list_addr(); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
98
diff
changeset
|
2011 if (UseCompressedOops) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
98
diff
changeset
|
2012 return oopDesc::load_decode_heap_oop((narrowOop *)addr); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
98
diff
changeset
|
2013 } else { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
98
diff
changeset
|
2014 return oopDesc::load_decode_heap_oop((oop*)addr); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
98
diff
changeset
|
2015 } |
0 | 2016 } |
2017 | |
2018 | |
2019 // Support for java_lang_ref_SoftReference | |
2020 | |
2021 jlong java_lang_ref_SoftReference::timestamp(oop ref) { | |
2022 return ref->long_field(timestamp_offset); | |
2023 } | |
2024 | |
2025 jlong java_lang_ref_SoftReference::clock() { | |
2026 instanceKlass* ik = instanceKlass::cast(SystemDictionary::soft_reference_klass()); | |
2027 int offset = ik->offset_of_static_fields() + static_clock_offset; | |
2028 | |
2029 return SystemDictionary::soft_reference_klass()->long_field(offset); | |
2030 } | |
2031 | |
2032 void java_lang_ref_SoftReference::set_clock(jlong value) { | |
2033 instanceKlass* ik = instanceKlass::cast(SystemDictionary::soft_reference_klass()); | |
2034 int offset = ik->offset_of_static_fields() + static_clock_offset; | |
2035 | |
2036 SystemDictionary::soft_reference_klass()->long_field_put(offset, value); | |
2037 } | |
2038 | |
2039 | |
2040 // Support for java_security_AccessControlContext | |
2041 | |
2042 int java_security_AccessControlContext::_context_offset = 0; | |
2043 int java_security_AccessControlContext::_privilegedContext_offset = 0; | |
2044 int java_security_AccessControlContext::_isPrivileged_offset = 0; | |
2045 | |
2046 | |
2047 void java_security_AccessControlContext::compute_offsets() { | |
2048 assert(_isPrivileged_offset == 0, "offsets should be initialized only once"); | |
2049 fieldDescriptor fd; | |
2050 instanceKlass* ik = instanceKlass::cast(SystemDictionary::AccessControlContext_klass()); | |
2051 | |
2052 if (!ik->find_local_field(vmSymbols::context_name(), vmSymbols::protectiondomain_signature(), &fd)) { | |
2053 fatal("Invalid layout of java.security.AccessControlContext"); | |
2054 } | |
2055 _context_offset = fd.offset(); | |
2056 | |
2057 if (!ik->find_local_field(vmSymbols::privilegedContext_name(), vmSymbols::accesscontrolcontext_signature(), &fd)) { | |
2058 fatal("Invalid layout of java.security.AccessControlContext"); | |
2059 } | |
2060 _privilegedContext_offset = fd.offset(); | |
2061 | |
2062 if (!ik->find_local_field(vmSymbols::isPrivileged_name(), vmSymbols::bool_signature(), &fd)) { | |
2063 fatal("Invalid layout of java.security.AccessControlContext"); | |
2064 } | |
2065 _isPrivileged_offset = fd.offset(); | |
2066 } | |
2067 | |
2068 | |
2069 oop java_security_AccessControlContext::create(objArrayHandle context, bool isPrivileged, Handle privileged_context, TRAPS) { | |
2070 assert(_isPrivileged_offset != 0, "offsets should have been initialized"); | |
2071 // Ensure klass is initialized | |
2072 instanceKlass::cast(SystemDictionary::AccessControlContext_klass())->initialize(CHECK_0); | |
2073 // Allocate result | |
2074 oop result = instanceKlass::cast(SystemDictionary::AccessControlContext_klass())->allocate_instance(CHECK_0); | |
2075 // Fill in values | |
2076 result->obj_field_put(_context_offset, context()); | |
2077 result->obj_field_put(_privilegedContext_offset, privileged_context()); | |
2078 result->bool_field_put(_isPrivileged_offset, isPrivileged); | |
2079 return result; | |
2080 } | |
2081 | |
2082 | |
2083 // Support for java_lang_ClassLoader | |
2084 | |
2085 oop java_lang_ClassLoader::parent(oop loader) { | |
2086 assert(loader->is_oop(), "loader must be oop"); | |
2087 return loader->obj_field(parent_offset); | |
2088 } | |
2089 | |
2090 | |
2091 bool java_lang_ClassLoader::is_trusted_loader(oop loader) { | |
2092 // Fix for 4474172; see evaluation for more details | |
2093 loader = non_reflection_class_loader(loader); | |
2094 | |
2095 oop cl = SystemDictionary::java_system_loader(); | |
2096 while(cl != NULL) { | |
2097 if (cl == loader) return true; | |
2098 cl = parent(cl); | |
2099 } | |
2100 return false; | |
2101 } | |
2102 | |
2103 oop java_lang_ClassLoader::non_reflection_class_loader(oop loader) { | |
2104 if (loader != NULL) { | |
2105 // See whether this is one of the class loaders associated with | |
2106 // the generated bytecodes for reflection, and if so, "magically" | |
2107 // delegate to its parent to prevent class loading from occurring | |
2108 // in places where applications using reflection didn't expect it. | |
2109 klassOop delegating_cl_class = SystemDictionary::reflect_delegating_classloader_klass(); | |
2110 // This might be null in non-1.4 JDKs | |
2111 if (delegating_cl_class != NULL && loader->is_a(delegating_cl_class)) { | |
2112 return parent(loader); | |
2113 } | |
2114 } | |
2115 return loader; | |
2116 } | |
2117 | |
2118 | |
2119 // Support for java_lang_System | |
2120 | |
2121 void java_lang_System::compute_offsets() { | |
2122 assert(offset_of_static_fields == 0, "offsets should be initialized only once"); | |
2123 | |
2124 instanceKlass* ik = instanceKlass::cast(SystemDictionary::system_klass()); | |
2125 offset_of_static_fields = ik->offset_of_static_fields(); | |
2126 } | |
2127 | |
2128 int java_lang_System::in_offset_in_bytes() { | |
2129 return (offset_of_static_fields + static_in_offset); | |
2130 } | |
2131 | |
2132 | |
2133 int java_lang_System::out_offset_in_bytes() { | |
2134 return (offset_of_static_fields + static_out_offset); | |
2135 } | |
2136 | |
2137 | |
2138 int java_lang_System::err_offset_in_bytes() { | |
2139 return (offset_of_static_fields + static_err_offset); | |
2140 } | |
2141 | |
2142 | |
2143 | |
2144 int java_lang_String::value_offset; | |
2145 int java_lang_String::offset_offset; | |
2146 int java_lang_String::count_offset; | |
2147 int java_lang_String::hash_offset; | |
2148 int java_lang_Class::klass_offset; | |
2149 int java_lang_Class::array_klass_offset; | |
2150 int java_lang_Class::resolved_constructor_offset; | |
2151 int java_lang_Class::number_of_fake_oop_fields; | |
2152 int java_lang_Throwable::backtrace_offset; | |
2153 int java_lang_Throwable::detailMessage_offset; | |
2154 int java_lang_Throwable::cause_offset; | |
2155 int java_lang_Throwable::stackTrace_offset; | |
2156 int java_lang_reflect_AccessibleObject::override_offset; | |
2157 int java_lang_reflect_Method::clazz_offset; | |
2158 int java_lang_reflect_Method::name_offset; | |
2159 int java_lang_reflect_Method::returnType_offset; | |
2160 int java_lang_reflect_Method::parameterTypes_offset; | |
2161 int java_lang_reflect_Method::exceptionTypes_offset; | |
2162 int java_lang_reflect_Method::slot_offset; | |
2163 int java_lang_reflect_Method::modifiers_offset; | |
2164 int java_lang_reflect_Method::signature_offset; | |
2165 int java_lang_reflect_Method::annotations_offset; | |
2166 int java_lang_reflect_Method::parameter_annotations_offset; | |
2167 int java_lang_reflect_Method::annotation_default_offset; | |
2168 int java_lang_reflect_Constructor::clazz_offset; | |
2169 int java_lang_reflect_Constructor::parameterTypes_offset; | |
2170 int java_lang_reflect_Constructor::exceptionTypes_offset; | |
2171 int java_lang_reflect_Constructor::slot_offset; | |
2172 int java_lang_reflect_Constructor::modifiers_offset; | |
2173 int java_lang_reflect_Constructor::signature_offset; | |
2174 int java_lang_reflect_Constructor::annotations_offset; | |
2175 int java_lang_reflect_Constructor::parameter_annotations_offset; | |
2176 int java_lang_reflect_Field::clazz_offset; | |
2177 int java_lang_reflect_Field::name_offset; | |
2178 int java_lang_reflect_Field::type_offset; | |
2179 int java_lang_reflect_Field::slot_offset; | |
2180 int java_lang_reflect_Field::modifiers_offset; | |
2181 int java_lang_reflect_Field::signature_offset; | |
2182 int java_lang_reflect_Field::annotations_offset; | |
2183 int java_lang_boxing_object::value_offset; | |
165
437d03ea40b1
6703888: Compressed Oops: use the 32-bits gap after klass in a object
kvn
parents:
132
diff
changeset
|
2184 int java_lang_boxing_object::long_value_offset; |
0 | 2185 int java_lang_ref_Reference::referent_offset; |
2186 int java_lang_ref_Reference::queue_offset; | |
2187 int java_lang_ref_Reference::next_offset; | |
2188 int java_lang_ref_Reference::discovered_offset; | |
2189 int java_lang_ref_Reference::static_lock_offset; | |
2190 int java_lang_ref_Reference::static_pending_offset; | |
2191 int java_lang_ref_Reference::number_of_fake_oop_fields; | |
2192 int java_lang_ref_SoftReference::timestamp_offset; | |
2193 int java_lang_ref_SoftReference::static_clock_offset; | |
2194 int java_lang_ClassLoader::parent_offset; | |
2195 int java_lang_System::offset_of_static_fields; | |
2196 int java_lang_System::static_in_offset; | |
2197 int java_lang_System::static_out_offset; | |
2198 int java_lang_System::static_err_offset; | |
2199 int java_lang_StackTraceElement::declaringClass_offset; | |
2200 int java_lang_StackTraceElement::methodName_offset; | |
2201 int java_lang_StackTraceElement::fileName_offset; | |
2202 int java_lang_StackTraceElement::lineNumber_offset; | |
2203 int java_lang_AssertionStatusDirectives::classes_offset; | |
2204 int java_lang_AssertionStatusDirectives::classEnabled_offset; | |
2205 int java_lang_AssertionStatusDirectives::packages_offset; | |
2206 int java_lang_AssertionStatusDirectives::packageEnabled_offset; | |
2207 int java_lang_AssertionStatusDirectives::deflt_offset; | |
2208 int java_nio_Buffer::_limit_offset; | |
2209 int sun_misc_AtomicLongCSImpl::_value_offset; | |
2210 int java_util_concurrent_locks_AbstractOwnableSynchronizer::_owner_offset = 0; | |
2211 int sun_reflect_ConstantPool::_cp_oop_offset; | |
2212 int sun_reflect_UnsafeStaticFieldAccessorImpl::_base_offset; | |
2213 | |
2214 | |
2215 // Support for java_lang_StackTraceElement | |
2216 | |
2217 void java_lang_StackTraceElement::set_fileName(oop element, oop value) { | |
2218 element->obj_field_put(fileName_offset, value); | |
2219 } | |
2220 | |
2221 void java_lang_StackTraceElement::set_declaringClass(oop element, oop value) { | |
2222 element->obj_field_put(declaringClass_offset, value); | |
2223 } | |
2224 | |
2225 void java_lang_StackTraceElement::set_methodName(oop element, oop value) { | |
2226 element->obj_field_put(methodName_offset, value); | |
2227 } | |
2228 | |
2229 void java_lang_StackTraceElement::set_lineNumber(oop element, int value) { | |
2230 element->int_field_put(lineNumber_offset, value); | |
2231 } | |
2232 | |
2233 | |
2234 // Support for java Assertions - java_lang_AssertionStatusDirectives. | |
2235 | |
2236 void java_lang_AssertionStatusDirectives::set_classes(oop o, oop val) { | |
2237 o->obj_field_put(classes_offset, val); | |
2238 } | |
2239 | |
2240 void java_lang_AssertionStatusDirectives::set_classEnabled(oop o, oop val) { | |
2241 o->obj_field_put(classEnabled_offset, val); | |
2242 } | |
2243 | |
2244 void java_lang_AssertionStatusDirectives::set_packages(oop o, oop val) { | |
2245 o->obj_field_put(packages_offset, val); | |
2246 } | |
2247 | |
2248 void java_lang_AssertionStatusDirectives::set_packageEnabled(oop o, oop val) { | |
2249 o->obj_field_put(packageEnabled_offset, val); | |
2250 } | |
2251 | |
2252 void java_lang_AssertionStatusDirectives::set_deflt(oop o, bool val) { | |
2253 o->bool_field_put(deflt_offset, val); | |
2254 } | |
2255 | |
2256 | |
2257 // Support for intrinsification of java.nio.Buffer.checkIndex | |
2258 int java_nio_Buffer::limit_offset() { | |
2259 return _limit_offset; | |
2260 } | |
2261 | |
2262 | |
2263 void java_nio_Buffer::compute_offsets() { | |
2264 klassOop k = SystemDictionary::java_nio_Buffer_klass(); | |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
2265 assert(k != NULL, "must be loaded in 1.4+"); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
2266 compute_offset(_limit_offset, k, vmSymbols::limit_name(), vmSymbols::int_signature()); |
0 | 2267 } |
2268 | |
2269 // Support for intrinsification of sun.misc.AtomicLongCSImpl.attemptUpdate | |
2270 int sun_misc_AtomicLongCSImpl::value_offset() { | |
2271 assert(SystemDictionary::sun_misc_AtomicLongCSImpl_klass() != NULL, "can't call this"); | |
2272 return _value_offset; | |
2273 } | |
2274 | |
2275 | |
2276 void sun_misc_AtomicLongCSImpl::compute_offsets() { | |
2277 klassOop k = SystemDictionary::sun_misc_AtomicLongCSImpl_klass(); | |
2278 // If this class is not present, its value field offset won't be referenced. | |
2279 if (k != NULL) { | |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
2280 compute_offset(_value_offset, k, vmSymbols::value_name(), vmSymbols::long_signature()); |
0 | 2281 } |
2282 } | |
2283 | |
2284 void java_util_concurrent_locks_AbstractOwnableSynchronizer::initialize(TRAPS) { | |
2285 if (_owner_offset != 0) return; | |
2286 | |
2287 assert(JDK_Version::is_gte_jdk16x_version(), "Must be JDK 1.6 or later"); | |
2288 SystemDictionary::load_abstract_ownable_synchronizer_klass(CHECK); | |
2289 klassOop k = SystemDictionary::abstract_ownable_synchronizer_klass(); | |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
2290 compute_offset(_owner_offset, k, |
0 | 2291 vmSymbols::exclusive_owner_thread_name(), vmSymbols::thread_signature()); |
2292 } | |
2293 | |
2294 oop java_util_concurrent_locks_AbstractOwnableSynchronizer::get_owner_threadObj(oop obj) { | |
2295 assert(_owner_offset != 0, "Must be initialized"); | |
2296 return obj->obj_field(_owner_offset); | |
2297 } | |
2298 | |
2299 // Compute hard-coded offsets | |
2300 // Invoked before SystemDictionary::initialize, so pre-loaded classes | |
2301 // are not available to determine the offset_of_static_fields. | |
2302 void JavaClasses::compute_hard_coded_offsets() { | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
98
diff
changeset
|
2303 const int x = heapOopSize; |
165
437d03ea40b1
6703888: Compressed Oops: use the 32-bits gap after klass in a object
kvn
parents:
132
diff
changeset
|
2304 const int header = instanceOopDesc::base_offset_in_bytes(); |
0 | 2305 |
2306 // Do the String Class | |
2307 java_lang_String::value_offset = java_lang_String::hc_value_offset * x + header; | |
2308 java_lang_String::offset_offset = java_lang_String::hc_offset_offset * x + header; | |
2309 java_lang_String::count_offset = java_lang_String::offset_offset + sizeof (jint); | |
2310 java_lang_String::hash_offset = java_lang_String::count_offset + sizeof (jint); | |
2311 | |
2312 // Do the Class Class | |
2313 java_lang_Class::klass_offset = java_lang_Class::hc_klass_offset * x + header; | |
2314 java_lang_Class::array_klass_offset = java_lang_Class::hc_array_klass_offset * x + header; | |
2315 java_lang_Class::resolved_constructor_offset = java_lang_Class::hc_resolved_constructor_offset * x + header; | |
2316 | |
2317 // This is NOT an offset | |
2318 java_lang_Class::number_of_fake_oop_fields = java_lang_Class::hc_number_of_fake_oop_fields; | |
2319 | |
2320 // Throwable Class | |
2321 java_lang_Throwable::backtrace_offset = java_lang_Throwable::hc_backtrace_offset * x + header; | |
2322 java_lang_Throwable::detailMessage_offset = java_lang_Throwable::hc_detailMessage_offset * x + header; | |
2323 java_lang_Throwable::cause_offset = java_lang_Throwable::hc_cause_offset * x + header; | |
2324 java_lang_Throwable::stackTrace_offset = java_lang_Throwable::hc_stackTrace_offset * x + header; | |
2325 | |
2326 // java_lang_boxing_object | |
165
437d03ea40b1
6703888: Compressed Oops: use the 32-bits gap after klass in a object
kvn
parents:
132
diff
changeset
|
2327 java_lang_boxing_object::value_offset = java_lang_boxing_object::hc_value_offset + header; |
437d03ea40b1
6703888: Compressed Oops: use the 32-bits gap after klass in a object
kvn
parents:
132
diff
changeset
|
2328 java_lang_boxing_object::long_value_offset = align_size_up((java_lang_boxing_object::hc_value_offset + header), BytesPerLong); |
0 | 2329 |
2330 // java_lang_ref_Reference: | |
2331 java_lang_ref_Reference::referent_offset = java_lang_ref_Reference::hc_referent_offset * x + header; | |
2332 java_lang_ref_Reference::queue_offset = java_lang_ref_Reference::hc_queue_offset * x + header; | |
2333 java_lang_ref_Reference::next_offset = java_lang_ref_Reference::hc_next_offset * x + header; | |
2334 java_lang_ref_Reference::discovered_offset = java_lang_ref_Reference::hc_discovered_offset * x + header; | |
2335 java_lang_ref_Reference::static_lock_offset = java_lang_ref_Reference::hc_static_lock_offset * x; | |
2336 java_lang_ref_Reference::static_pending_offset = java_lang_ref_Reference::hc_static_pending_offset * x; | |
2337 // Artificial fields for java_lang_ref_Reference | |
2338 // The first field is for the discovered field added in 1.4 | |
2339 java_lang_ref_Reference::number_of_fake_oop_fields = 1; | |
2340 | |
2341 // java_lang_ref_SoftReference Class | |
165
437d03ea40b1
6703888: Compressed Oops: use the 32-bits gap after klass in a object
kvn
parents:
132
diff
changeset
|
2342 java_lang_ref_SoftReference::timestamp_offset = align_size_up((java_lang_ref_SoftReference::hc_timestamp_offset * x + header), BytesPerLong); |
0 | 2343 // Don't multiply static fields because they are always in wordSize units |
2344 java_lang_ref_SoftReference::static_clock_offset = java_lang_ref_SoftReference::hc_static_clock_offset * x; | |
2345 | |
2346 // java_lang_ClassLoader | |
2347 java_lang_ClassLoader::parent_offset = java_lang_ClassLoader::hc_parent_offset * x + header; | |
2348 | |
2349 // java_lang_System | |
2350 java_lang_System::static_in_offset = java_lang_System::hc_static_in_offset * x; | |
2351 java_lang_System::static_out_offset = java_lang_System::hc_static_out_offset * x; | |
2352 java_lang_System::static_err_offset = java_lang_System::hc_static_err_offset * x; | |
2353 | |
2354 // java_lang_StackTraceElement | |
2355 java_lang_StackTraceElement::declaringClass_offset = java_lang_StackTraceElement::hc_declaringClass_offset * x + header; | |
2356 java_lang_StackTraceElement::methodName_offset = java_lang_StackTraceElement::hc_methodName_offset * x + header; | |
2357 java_lang_StackTraceElement::fileName_offset = java_lang_StackTraceElement::hc_fileName_offset * x + header; | |
2358 java_lang_StackTraceElement::lineNumber_offset = java_lang_StackTraceElement::hc_lineNumber_offset * x + header; | |
2359 java_lang_AssertionStatusDirectives::classes_offset = java_lang_AssertionStatusDirectives::hc_classes_offset * x + header; | |
2360 java_lang_AssertionStatusDirectives::classEnabled_offset = java_lang_AssertionStatusDirectives::hc_classEnabled_offset * x + header; | |
2361 java_lang_AssertionStatusDirectives::packages_offset = java_lang_AssertionStatusDirectives::hc_packages_offset * x + header; | |
2362 java_lang_AssertionStatusDirectives::packageEnabled_offset = java_lang_AssertionStatusDirectives::hc_packageEnabled_offset * x + header; | |
2363 java_lang_AssertionStatusDirectives::deflt_offset = java_lang_AssertionStatusDirectives::hc_deflt_offset * x + header; | |
2364 | |
2365 } | |
2366 | |
2367 | |
2368 // Compute non-hard-coded field offsets of all the classes in this file | |
2369 void JavaClasses::compute_offsets() { | |
2370 | |
2371 java_lang_Class::compute_offsets(); | |
2372 java_lang_System::compute_offsets(); | |
2373 java_lang_Thread::compute_offsets(); | |
2374 java_lang_ThreadGroup::compute_offsets(); | |
2375 java_security_AccessControlContext::compute_offsets(); | |
2376 // Initialize reflection classes. The layouts of these classes | |
2377 // changed with the new reflection implementation in JDK 1.4, and | |
2378 // since the Universe doesn't know what JDK version it is until this | |
2379 // point we defer computation of these offsets until now. | |
2380 java_lang_reflect_AccessibleObject::compute_offsets(); | |
2381 java_lang_reflect_Method::compute_offsets(); | |
2382 java_lang_reflect_Constructor::compute_offsets(); | |
2383 java_lang_reflect_Field::compute_offsets(); | |
2384 if (JDK_Version::is_gte_jdk14x_version()) { | |
2385 java_nio_Buffer::compute_offsets(); | |
2386 } | |
2387 if (JDK_Version::is_gte_jdk15x_version()) { | |
2388 sun_reflect_ConstantPool::compute_offsets(); | |
2389 sun_reflect_UnsafeStaticFieldAccessorImpl::compute_offsets(); | |
2390 } | |
2391 sun_misc_AtomicLongCSImpl::compute_offsets(); | |
2392 } | |
2393 | |
2394 #ifndef PRODUCT | |
2395 | |
2396 // These functions exist to assert the validity of hard-coded field offsets to guard | |
2397 // against changes in the class files | |
2398 | |
2399 bool JavaClasses::check_offset(const char *klass_name, int hardcoded_offset, const char *field_name, const char* field_sig) { | |
2400 EXCEPTION_MARK; | |
2401 fieldDescriptor fd; | |
2402 symbolHandle klass_sym = oopFactory::new_symbol_handle(klass_name, CATCH); | |
2403 klassOop k = SystemDictionary::resolve_or_fail(klass_sym, true, CATCH); | |
2404 instanceKlassHandle h_klass (THREAD, k); | |
2405 //instanceKlassHandle h_klass(klass); | |
2406 symbolHandle f_name = oopFactory::new_symbol_handle(field_name, CATCH); | |
2407 symbolHandle f_sig = oopFactory::new_symbol_handle(field_sig, CATCH); | |
2408 if (!h_klass->find_local_field(f_name(), f_sig(), &fd)) { | |
2409 tty->print_cr("Nonstatic field %s.%s not found", klass_name, field_name); | |
2410 return false; | |
2411 } | |
2412 if (fd.is_static()) { | |
2413 tty->print_cr("Nonstatic field %s.%s appears to be static", klass_name, field_name); | |
2414 return false; | |
2415 } | |
2416 if (fd.offset() == hardcoded_offset ) { | |
2417 return true; | |
2418 } else { | |
2419 tty->print_cr("Offset of nonstatic field %s.%s is hardcoded as %d but should really be %d.", | |
2420 klass_name, field_name, hardcoded_offset, fd.offset()); | |
2421 return false; | |
2422 } | |
2423 } | |
2424 | |
2425 | |
2426 bool JavaClasses::check_static_offset(const char *klass_name, int hardcoded_offset, const char *field_name, const char* field_sig) { | |
2427 EXCEPTION_MARK; | |
2428 fieldDescriptor fd; | |
2429 symbolHandle klass_sym = oopFactory::new_symbol_handle(klass_name, CATCH); | |
2430 klassOop k = SystemDictionary::resolve_or_fail(klass_sym, true, CATCH); | |
2431 instanceKlassHandle h_klass (THREAD, k); | |
2432 symbolHandle f_name = oopFactory::new_symbol_handle(field_name, CATCH); | |
2433 symbolHandle f_sig = oopFactory::new_symbol_handle(field_sig, CATCH); | |
2434 if (!h_klass->find_local_field(f_name(), f_sig(), &fd)) { | |
2435 tty->print_cr("Static field %s.%s not found", klass_name, field_name); | |
2436 return false; | |
2437 } | |
2438 if (!fd.is_static()) { | |
2439 tty->print_cr("Static field %s.%s appears to be nonstatic", klass_name, field_name); | |
2440 return false; | |
2441 } | |
2442 if (fd.offset() == hardcoded_offset + h_klass->offset_of_static_fields()) { | |
2443 return true; | |
2444 } else { | |
2445 tty->print_cr("Offset of static field %s.%s is hardcoded as %d but should really be %d.", klass_name, field_name, hardcoded_offset, fd.offset() - h_klass->offset_of_static_fields()); | |
2446 return false; | |
2447 } | |
2448 } | |
2449 | |
2450 | |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
2451 bool JavaClasses::check_constant(const char *klass_name, int hardcoded_constant, const char *field_name, const char* field_sig) { |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
2452 EXCEPTION_MARK; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
2453 fieldDescriptor fd; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
2454 symbolHandle klass_sym = oopFactory::new_symbol_handle(klass_name, CATCH); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
2455 klassOop k = SystemDictionary::resolve_or_fail(klass_sym, true, CATCH); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
2456 instanceKlassHandle h_klass (THREAD, k); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
2457 symbolHandle f_name = oopFactory::new_symbol_handle(field_name, CATCH); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
2458 symbolHandle f_sig = oopFactory::new_symbol_handle(field_sig, CATCH); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
2459 if (!h_klass->find_local_field(f_name(), f_sig(), &fd)) { |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
2460 tty->print_cr("Static field %s.%s not found", klass_name, field_name); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
2461 return false; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
2462 } |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
2463 if (!fd.is_static() || !fd.has_initial_value()) { |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
2464 tty->print_cr("Static field %s.%s appears to be non-constant", klass_name, field_name); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
2465 return false; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
2466 } |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
2467 if (!fd.initial_value_tag().is_int()) { |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
2468 tty->print_cr("Static field %s.%s is not an int", klass_name, field_name); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
2469 return false; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
2470 } |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
2471 jint field_value = fd.int_initial_value(); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
2472 if (field_value == hardcoded_constant) { |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
2473 return true; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
2474 } else { |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
2475 tty->print_cr("Constant value of static field %s.%s is hardcoded as %d but should really be %d.", klass_name, field_name, hardcoded_constant, field_value); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
2476 return false; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
2477 } |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
2478 } |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
2479 |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
2480 |
0 | 2481 // Check the hard-coded field offsets of all the classes in this file |
2482 | |
2483 void JavaClasses::check_offsets() { | |
2484 bool valid = true; | |
2485 | |
2486 #define CHECK_OFFSET(klass_name, cpp_klass_name, field_name, field_sig) \ | |
2487 valid &= check_offset(klass_name, cpp_klass_name :: field_name ## _offset, #field_name, field_sig) | |
2488 | |
165
437d03ea40b1
6703888: Compressed Oops: use the 32-bits gap after klass in a object
kvn
parents:
132
diff
changeset
|
2489 #define CHECK_LONG_OFFSET(klass_name, cpp_klass_name, field_name, field_sig) \ |
437d03ea40b1
6703888: Compressed Oops: use the 32-bits gap after klass in a object
kvn
parents:
132
diff
changeset
|
2490 valid &= check_offset(klass_name, cpp_klass_name :: long_ ## field_name ## _offset, #field_name, field_sig) |
437d03ea40b1
6703888: Compressed Oops: use the 32-bits gap after klass in a object
kvn
parents:
132
diff
changeset
|
2491 |
0 | 2492 #define CHECK_STATIC_OFFSET(klass_name, cpp_klass_name, field_name, field_sig) \ |
2493 valid &= check_static_offset(klass_name, cpp_klass_name :: static_ ## field_name ## _offset, #field_name, field_sig) | |
2494 | |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
2495 #define CHECK_CONSTANT(klass_name, cpp_klass_name, field_name, field_sig) \ |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
2496 valid &= check_constant(klass_name, cpp_klass_name :: field_name, #field_name, field_sig) |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
113
diff
changeset
|
2497 |
0 | 2498 // java.lang.String |
2499 | |
2500 CHECK_OFFSET("java/lang/String", java_lang_String, value, "[C"); | |
2501 CHECK_OFFSET("java/lang/String", java_lang_String, offset, "I"); | |
2502 CHECK_OFFSET("java/lang/String", java_lang_String, count, "I"); | |
2503 CHECK_OFFSET("java/lang/String", java_lang_String, hash, "I"); | |
2504 | |
2505 // java.lang.Class | |
2506 | |
2507 // Fake fields | |
2508 // CHECK_OFFSET("java/lang/Class", java_lang_Class, klass); // %%% this needs to be checked | |
2509 // CHECK_OFFSET("java/lang/Class", java_lang_Class, array_klass); // %%% this needs to be checked | |
2510 // CHECK_OFFSET("java/lang/Class", java_lang_Class, resolved_constructor); // %%% this needs to be checked | |
2511 | |
2512 // java.lang.Throwable | |
2513 | |
2514 CHECK_OFFSET("java/lang/Throwable", java_lang_Throwable, backtrace, "Ljava/lang/Object;"); | |
2515 CHECK_OFFSET("java/lang/Throwable", java_lang_Throwable, detailMessage, "Ljava/lang/String;"); | |
2516 CHECK_OFFSET("java/lang/Throwable", java_lang_Throwable, cause, "Ljava/lang/Throwable;"); | |
2517 CHECK_OFFSET("java/lang/Throwable", java_lang_Throwable, stackTrace, "[Ljava/lang/StackTraceElement;"); | |
2518 | |
2519 // Boxed primitive objects (java_lang_boxing_object) | |
2520 | |
2521 CHECK_OFFSET("java/lang/Boolean", java_lang_boxing_object, value, "Z"); | |
2522 CHECK_OFFSET("java/lang/Character", java_lang_boxing_object, value, "C"); | |
2523 CHECK_OFFSET("java/lang/Float", java_lang_boxing_object, value, "F"); | |
165
437d03ea40b1
6703888: Compressed Oops: use the 32-bits gap after klass in a object
kvn
parents:
132
diff
changeset
|
2524 CHECK_LONG_OFFSET("java/lang/Double", java_lang_boxing_object, value, "D"); |
0 | 2525 CHECK_OFFSET("java/lang/Byte", java_lang_boxing_object, value, "B"); |
2526 CHECK_OFFSET("java/lang/Short", java_lang_boxing_object, value, "S"); | |
2527 CHECK_OFFSET("java/lang/Integer", java_lang_boxing_object, value, "I"); | |
165
437d03ea40b1
6703888: Compressed Oops: use the 32-bits gap after klass in a object
kvn
parents:
132
diff
changeset
|
2528 CHECK_LONG_OFFSET("java/lang/Long", java_lang_boxing_object, value, "J"); |
0 | 2529 |
2530 // java.lang.ClassLoader | |
2531 | |
2532 CHECK_OFFSET("java/lang/ClassLoader", java_lang_ClassLoader, parent, "Ljava/lang/ClassLoader;"); | |
2533 | |
2534 // java.lang.System | |
2535 | |
2536 CHECK_STATIC_OFFSET("java/lang/System", java_lang_System, in, "Ljava/io/InputStream;"); | |
2537 CHECK_STATIC_OFFSET("java/lang/System", java_lang_System, out, "Ljava/io/PrintStream;"); | |
2538 CHECK_STATIC_OFFSET("java/lang/System", java_lang_System, err, "Ljava/io/PrintStream;"); | |
2539 | |
2540 // java.lang.StackTraceElement | |
2541 | |
2542 CHECK_OFFSET("java/lang/StackTraceElement", java_lang_StackTraceElement, declaringClass, "Ljava/lang/String;"); | |
2543 CHECK_OFFSET("java/lang/StackTraceElement", java_lang_StackTraceElement, methodName, "Ljava/lang/String;"); | |
2544 CHECK_OFFSET("java/lang/StackTraceElement", java_lang_StackTraceElement, fileName, "Ljava/lang/String;"); | |
2545 CHECK_OFFSET("java/lang/StackTraceElement", java_lang_StackTraceElement, lineNumber, "I"); | |
2546 | |
2547 // java.lang.ref.Reference | |
2548 | |
2549 CHECK_OFFSET("java/lang/ref/Reference", java_lang_ref_Reference, referent, "Ljava/lang/Object;"); | |
2550 CHECK_OFFSET("java/lang/ref/Reference", java_lang_ref_Reference, queue, "Ljava/lang/ref/ReferenceQueue;"); | |
2551 CHECK_OFFSET("java/lang/ref/Reference", java_lang_ref_Reference, next, "Ljava/lang/ref/Reference;"); | |
2552 // Fake field | |
2553 //CHECK_OFFSET("java/lang/ref/Reference", java_lang_ref_Reference, discovered, "Ljava/lang/ref/Reference;"); | |
2554 CHECK_STATIC_OFFSET("java/lang/ref/Reference", java_lang_ref_Reference, lock, "Ljava/lang/ref/Reference$Lock;"); | |
2555 CHECK_STATIC_OFFSET("java/lang/ref/Reference", java_lang_ref_Reference, pending, "Ljava/lang/ref/Reference;"); | |
2556 | |
2557 // java.lang.ref.SoftReference | |
2558 | |
2559 CHECK_OFFSET("java/lang/ref/SoftReference", java_lang_ref_SoftReference, timestamp, "J"); | |
2560 CHECK_STATIC_OFFSET("java/lang/ref/SoftReference", java_lang_ref_SoftReference, clock, "J"); | |
2561 | |
2562 // java.lang.AssertionStatusDirectives | |
2563 // | |
2564 // The CheckAssertionStatusDirectives boolean can be removed from here and | |
2565 // globals.hpp after the AssertionStatusDirectives class has been integrated | |
2566 // into merlin "for some time." Without it, the vm will fail with early | |
2567 // merlin builds. | |
2568 | |
2569 if (CheckAssertionStatusDirectives && JDK_Version::is_gte_jdk14x_version()) { | |
2570 const char* nm = "java/lang/AssertionStatusDirectives"; | |
2571 const char* sig = "[Ljava/lang/String;"; | |
2572 CHECK_OFFSET(nm, java_lang_AssertionStatusDirectives, classes, sig); | |
2573 CHECK_OFFSET(nm, java_lang_AssertionStatusDirectives, classEnabled, "[Z"); | |
2574 CHECK_OFFSET(nm, java_lang_AssertionStatusDirectives, packages, sig); | |
2575 CHECK_OFFSET(nm, java_lang_AssertionStatusDirectives, packageEnabled, "[Z"); | |
2576 CHECK_OFFSET(nm, java_lang_AssertionStatusDirectives, deflt, "Z"); | |
2577 } | |
2578 | |
2579 if (!valid) vm_exit_during_initialization("Hard-coded field offset verification failed"); | |
2580 } | |
2581 | |
2582 #endif // PRODUCT | |
2583 | |
2584 void javaClasses_init() { | |
2585 JavaClasses::compute_offsets(); | |
2586 JavaClasses::check_offsets(); | |
2587 FilteredFieldsMap::initialize(); // must be done after computing offsets. | |
2588 } |