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