Mercurial > hg > truffle
annotate src/share/vm/classfile/vmSymbols.cpp @ 1972:f95d63e2154a
6989984: Use standard include model for Hospot
Summary: Replaced MakeDeps and the includeDB files with more standardized solutions.
Reviewed-by: coleenp, kvn, kamg
author | stefank |
---|---|
date | Tue, 23 Nov 2010 13:22:55 -0800 |
parents | c18cbe5936b8 |
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:
1138
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1138
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:
1138
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
26 #include "classfile/vmSymbols.hpp" | |
27 #include "memory/oopFactory.hpp" | |
28 #include "oops/oop.inline.hpp" | |
29 #include "runtime/handles.inline.hpp" | |
30 #include "utilities/xmlstream.hpp" | |
0 | 31 |
32 | |
33 symbolOop vmSymbols::_symbols[vmSymbols::SID_LIMIT]; | |
34 | |
35 symbolOop vmSymbols::_type_signatures[T_VOID+1] = { NULL /*, NULL...*/ }; | |
36 | |
37 inline int compare_symbol(symbolOop a, symbolOop b) { | |
38 if (a == b) return 0; | |
39 // follow the natural address order: | |
40 return (address)a > (address)b ? +1 : -1; | |
41 } | |
42 | |
43 static vmSymbols::SID vm_symbol_index[vmSymbols::SID_LIMIT]; | |
44 extern "C" { | |
45 static int compare_vmsymbol_sid(const void* void_a, const void* void_b) { | |
46 symbolOop a = vmSymbols::symbol_at(*((vmSymbols::SID*) void_a)); | |
47 symbolOop b = vmSymbols::symbol_at(*((vmSymbols::SID*) void_b)); | |
48 return compare_symbol(a, b); | |
49 } | |
50 } | |
51 | |
52 #ifndef PRODUCT | |
53 #define VM_SYMBOL_ENUM_NAME_BODY(name, string) #name "\0" | |
54 static const char* vm_symbol_enum_names = | |
55 VM_SYMBOLS_DO(VM_SYMBOL_ENUM_NAME_BODY, VM_ALIAS_IGNORE) | |
56 "\0"; | |
57 static const char* vm_symbol_enum_name(vmSymbols::SID sid) { | |
58 const char* string = &vm_symbol_enum_names[0]; | |
59 int skip = (int)sid - (int)vmSymbols::FIRST_SID; | |
60 for (; skip != 0; skip--) { | |
61 size_t skiplen = strlen(string); | |
62 if (skiplen == 0) return "<unknown>"; // overflow | |
63 string += skiplen+1; | |
64 } | |
65 return string; | |
66 } | |
67 #endif //PRODUCT | |
68 | |
69 // Put all the VM symbol strings in one place. | |
70 // Makes for a more compact libjvm. | |
71 #define VM_SYMBOL_BODY(name, string) string "\0" | |
72 static const char* vm_symbol_bodies = VM_SYMBOLS_DO(VM_SYMBOL_BODY, VM_ALIAS_IGNORE); | |
73 | |
74 void vmSymbols::initialize(TRAPS) { | |
75 assert((int)SID_LIMIT <= (1<<log2_SID_LIMIT), "must fit in this bitfield"); | |
76 assert((int)SID_LIMIT*5 > (1<<log2_SID_LIMIT), "make the bitfield smaller, please"); | |
1133
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
77 assert(vmIntrinsics::FLAG_LIMIT <= (1 << vmIntrinsics::log2_FLAG_LIMIT), "must fit in this bitfield"); |
0 | 78 |
79 if (!UseSharedSpaces) { | |
80 const char* string = &vm_symbol_bodies[0]; | |
81 for (int index = (int)FIRST_SID; index < (int)SID_LIMIT; index++) { | |
82 symbolOop sym = oopFactory::new_symbol(string, CHECK); | |
83 _symbols[index] = sym; | |
84 string += strlen(string); // skip string body | |
85 string += 1; // skip trailing null | |
86 } | |
87 | |
88 _type_signatures[T_BYTE] = byte_signature(); | |
89 _type_signatures[T_CHAR] = char_signature(); | |
90 _type_signatures[T_DOUBLE] = double_signature(); | |
91 _type_signatures[T_FLOAT] = float_signature(); | |
92 _type_signatures[T_INT] = int_signature(); | |
93 _type_signatures[T_LONG] = long_signature(); | |
94 _type_signatures[T_SHORT] = short_signature(); | |
95 _type_signatures[T_BOOLEAN] = bool_signature(); | |
96 _type_signatures[T_VOID] = void_signature(); | |
97 // no single signatures for T_OBJECT or T_ARRAY | |
98 } | |
99 | |
100 #ifdef ASSERT | |
101 // Check for duplicates: | |
102 for (int i1 = (int)FIRST_SID; i1 < (int)SID_LIMIT; i1++) { | |
103 symbolOop sym = symbol_at((SID)i1); | |
104 for (int i2 = (int)FIRST_SID; i2 < i1; i2++) { | |
105 if (symbol_at((SID)i2) == sym) { | |
106 tty->print("*** Duplicate VM symbol SIDs %s(%d) and %s(%d): \"", | |
107 vm_symbol_enum_name((SID)i2), i2, | |
108 vm_symbol_enum_name((SID)i1), i1); | |
109 sym->print_symbol_on(tty); | |
110 tty->print_cr("\""); | |
111 } | |
112 } | |
113 } | |
114 #endif //ASSERT | |
115 | |
116 // Create an index for find_id: | |
117 { | |
118 for (int index = (int)FIRST_SID; index < (int)SID_LIMIT; index++) { | |
119 vm_symbol_index[index] = (SID)index; | |
120 } | |
121 int num_sids = SID_LIMIT-FIRST_SID; | |
122 qsort(&vm_symbol_index[FIRST_SID], num_sids, sizeof(vm_symbol_index[0]), | |
123 compare_vmsymbol_sid); | |
124 } | |
125 | |
126 #ifdef ASSERT | |
127 { | |
128 // Spot-check correspondence between strings, symbols, and enums: | |
129 assert(_symbols[NO_SID] == NULL, "must be"); | |
130 const char* str = "java/lang/Object"; | |
131 symbolOop sym = oopFactory::new_symbol(str, CHECK); | |
132 assert(strcmp(str, (char*)sym->base()) == 0, ""); | |
133 assert(sym == java_lang_Object(), ""); | |
134 SID sid = VM_SYMBOL_ENUM_NAME(java_lang_Object); | |
135 assert(find_sid(sym) == sid, ""); | |
136 assert(symbol_at(sid) == sym, ""); | |
137 | |
138 // Make sure find_sid produces the right answer in each case. | |
139 for (int index = (int)FIRST_SID; index < (int)SID_LIMIT; index++) { | |
140 sym = symbol_at((SID)index); | |
141 sid = find_sid(sym); | |
142 assert(sid == (SID)index, "symbol index works"); | |
143 // Note: If there are duplicates, this assert will fail. | |
144 // A "Duplicate VM symbol" message will have already been printed. | |
145 } | |
146 | |
147 // The string "format" happens (at the moment) not to be a vmSymbol, | |
148 // though it is a method name in java.lang.String. | |
149 str = "format"; | |
150 sym = oopFactory::new_symbol(str, CHECK); | |
151 sid = find_sid(sym); | |
152 assert(sid == NO_SID, "symbol index works (negative test)"); | |
153 } | |
154 #endif | |
155 } | |
156 | |
157 | |
158 #ifndef PRODUCT | |
159 const char* vmSymbols::name_for(vmSymbols::SID sid) { | |
160 if (sid == NO_SID) | |
161 return "NO_SID"; | |
162 const char* string = &vm_symbol_bodies[0]; | |
163 for (int index = (int)FIRST_SID; index < (int)SID_LIMIT; index++) { | |
164 if (index == (int)sid) | |
165 return string; | |
166 string += strlen(string); // skip string body | |
167 string += 1; // skip trailing null | |
168 } | |
169 return "BAD_SID"; | |
170 } | |
171 #endif | |
172 | |
173 | |
174 | |
175 void vmSymbols::oops_do(OopClosure* f, bool do_all) { | |
176 for (int index = (int)FIRST_SID; index < (int)SID_LIMIT; index++) { | |
177 f->do_oop((oop*) &_symbols[index]); | |
178 } | |
179 for (int i = 0; i < T_VOID+1; i++) { | |
180 if (_type_signatures[i] != NULL) { | |
181 assert(i >= T_BOOLEAN, "checking"); | |
182 f->do_oop((oop*)&_type_signatures[i]); | |
183 } else if (do_all) { | |
184 f->do_oop((oop*)&_type_signatures[i]); | |
185 } | |
186 } | |
187 } | |
188 | |
189 | |
190 BasicType vmSymbols::signature_type(symbolOop s) { | |
191 assert(s != NULL, "checking"); | |
192 for (int i = T_BOOLEAN; i < T_VOID+1; i++) { | |
193 if (s == _type_signatures[i]) { | |
194 return (BasicType)i; | |
195 } | |
196 } | |
197 return T_OBJECT; | |
198 } | |
199 | |
200 | |
201 static int mid_hint = (int)vmSymbols::FIRST_SID+1; | |
202 | |
203 #ifndef PRODUCT | |
204 static int find_sid_calls, find_sid_probes; | |
205 // (Typical counts are calls=7000 and probes=17000.) | |
206 #endif | |
207 | |
208 vmSymbols::SID vmSymbols::find_sid(symbolOop symbol) { | |
209 // Handle the majority of misses by a bounds check. | |
210 // Then, use a binary search over the index. | |
211 // Expected trip count is less than log2_SID_LIMIT, about eight. | |
212 // This is slow but acceptable, given that calls are not | |
213 // dynamically common. (methodOop::intrinsic_id has a cache.) | |
214 NOT_PRODUCT(find_sid_calls++); | |
215 int min = (int)FIRST_SID, max = (int)SID_LIMIT - 1; | |
216 SID sid = NO_SID, sid1; | |
217 int cmp1; | |
218 sid1 = vm_symbol_index[min]; | |
219 cmp1 = compare_symbol(symbol, symbol_at(sid1)); | |
220 if (cmp1 <= 0) { // before the first | |
221 if (cmp1 == 0) sid = sid1; | |
222 } else { | |
223 sid1 = vm_symbol_index[max]; | |
224 cmp1 = compare_symbol(symbol, symbol_at(sid1)); | |
225 if (cmp1 >= 0) { // after the last | |
226 if (cmp1 == 0) sid = sid1; | |
227 } else { | |
228 // After checking the extremes, do a binary search. | |
229 ++min; --max; // endpoints are done | |
230 int mid = mid_hint; // start at previous success | |
231 while (max >= min) { | |
232 assert(mid >= min && mid <= max, ""); | |
233 NOT_PRODUCT(find_sid_probes++); | |
234 sid1 = vm_symbol_index[mid]; | |
235 cmp1 = compare_symbol(symbol, symbol_at(sid1)); | |
236 if (cmp1 == 0) { | |
237 mid_hint = mid; | |
238 sid = sid1; | |
239 break; | |
240 } | |
241 if (cmp1 < 0) | |
242 max = mid - 1; // symbol < symbol_at(sid) | |
243 else | |
244 min = mid + 1; | |
245 | |
246 // Pick a new probe point: | |
247 mid = (max + min) / 2; | |
248 } | |
249 } | |
250 } | |
251 | |
252 #ifdef ASSERT | |
253 // Perform the exhaustive self-check the first 1000 calls, | |
254 // and every 100 calls thereafter. | |
255 static int find_sid_check_count = -2000; | |
256 if ((uint)++find_sid_check_count > (uint)100) { | |
257 if (find_sid_check_count > 0) find_sid_check_count = 0; | |
258 | |
259 // Make sure this is the right answer, using linear search. | |
260 // (We have already proven that there are no duplicates in the list.) | |
261 SID sid2 = NO_SID; | |
262 for (int index = (int)FIRST_SID; index < (int)SID_LIMIT; index++) { | |
263 symbolOop sym2 = symbol_at((SID)index); | |
264 if (sym2 == symbol) { | |
265 sid2 = (SID)index; | |
266 break; | |
267 } | |
268 } | |
269 // Unless it's a duplicate, assert that the sids are the same. | |
270 if (_symbols[sid] != _symbols[sid2]) { | |
271 assert(sid == sid2, "binary same as linear search"); | |
272 } | |
273 } | |
274 #endif //ASSERT | |
275 | |
276 return sid; | |
277 } | |
278 | |
1133
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
279 static vmIntrinsics::ID wrapper_intrinsic(BasicType type, bool unboxing) { |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
280 #define TYPE2(type, unboxing) ((int)(type)*2 + ((unboxing) ? 1 : 0)) |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
281 switch (TYPE2(type, unboxing)) { |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
282 #define BASIC_TYPE_CASE(type, box, unbox) \ |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
283 case TYPE2(type, false): return vmIntrinsics::box; \ |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
284 case TYPE2(type, true): return vmIntrinsics::unbox |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
285 BASIC_TYPE_CASE(T_BOOLEAN, _Boolean_valueOf, _booleanValue); |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
286 BASIC_TYPE_CASE(T_BYTE, _Byte_valueOf, _byteValue); |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
287 BASIC_TYPE_CASE(T_CHAR, _Character_valueOf, _charValue); |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
288 BASIC_TYPE_CASE(T_SHORT, _Short_valueOf, _shortValue); |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
289 BASIC_TYPE_CASE(T_INT, _Integer_valueOf, _intValue); |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
290 BASIC_TYPE_CASE(T_LONG, _Long_valueOf, _longValue); |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
291 BASIC_TYPE_CASE(T_FLOAT, _Float_valueOf, _floatValue); |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
292 BASIC_TYPE_CASE(T_DOUBLE, _Double_valueOf, _doubleValue); |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
293 #undef BASIC_TYPE_CASE |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
294 } |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
295 #undef TYPE2 |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
296 return vmIntrinsics::_none; |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
297 } |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
298 |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
299 vmIntrinsics::ID vmIntrinsics::for_boxing(BasicType type) { |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
300 return wrapper_intrinsic(type, false); |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
301 } |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
302 vmIntrinsics::ID vmIntrinsics::for_unboxing(BasicType type) { |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
303 return wrapper_intrinsic(type, true); |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
304 } |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
305 |
1138
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1133
diff
changeset
|
306 vmIntrinsics::ID vmIntrinsics::for_raw_conversion(BasicType src, BasicType dest) { |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1133
diff
changeset
|
307 #define SRC_DEST(s,d) (((int)(s) << 4) + (int)(d)) |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1133
diff
changeset
|
308 switch (SRC_DEST(src, dest)) { |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1133
diff
changeset
|
309 case SRC_DEST(T_INT, T_FLOAT): return vmIntrinsics::_intBitsToFloat; |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1133
diff
changeset
|
310 case SRC_DEST(T_FLOAT, T_INT): return vmIntrinsics::_floatToRawIntBits; |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1133
diff
changeset
|
311 |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1133
diff
changeset
|
312 case SRC_DEST(T_LONG, T_DOUBLE): return vmIntrinsics::_longBitsToDouble; |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1133
diff
changeset
|
313 case SRC_DEST(T_DOUBLE, T_LONG): return vmIntrinsics::_doubleToRawLongBits; |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1133
diff
changeset
|
314 } |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1133
diff
changeset
|
315 #undef SRC_DEST |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1133
diff
changeset
|
316 |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1133
diff
changeset
|
317 return vmIntrinsics::_none; |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1133
diff
changeset
|
318 } |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1133
diff
changeset
|
319 |
1133
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
320 methodOop vmIntrinsics::method_for(vmIntrinsics::ID id) { |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
321 if (id == _none) return NULL; |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
322 symbolOop cname = vmSymbols::symbol_at(class_for(id)); |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
323 symbolOop mname = vmSymbols::symbol_at(name_for(id)); |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
324 symbolOop msig = vmSymbols::symbol_at(signature_for(id)); |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
325 if (cname == NULL || mname == NULL || msig == NULL) return NULL; |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
326 klassOop k = SystemDictionary::find_well_known_klass(cname); |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
327 if (k == NULL) return NULL; |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
328 return instanceKlass::cast(k)->find_method(mname, msig); |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
329 } |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
330 |
0 | 331 |
332 #define VM_INTRINSIC_INITIALIZE(id, klass, name, sig, flags) #id "\0" | |
333 static const char* vm_intrinsic_name_bodies = | |
334 VM_INTRINSICS_DO(VM_INTRINSIC_INITIALIZE, | |
335 VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_ALIAS_IGNORE); | |
336 | |
337 static const char* vm_intrinsic_name_table[vmIntrinsics::ID_LIMIT]; | |
338 | |
339 const char* vmIntrinsics::name_at(vmIntrinsics::ID id) { | |
340 const char** nt = &vm_intrinsic_name_table[0]; | |
341 if (nt[_none] == NULL) { | |
342 char* string = (char*) &vm_intrinsic_name_bodies[0]; | |
343 for (int index = FIRST_ID; index < ID_LIMIT; index++) { | |
344 nt[index] = string; | |
345 string += strlen(string); // skip string body | |
346 string += 1; // skip trailing null | |
347 } | |
348 assert(!strcmp(nt[_hashCode], "_hashCode"), "lined up"); | |
349 nt[_none] = "_none"; | |
350 } | |
351 if ((uint)id < (uint)ID_LIMIT) | |
352 return vm_intrinsic_name_table[(uint)id]; | |
353 else | |
354 return "(unknown intrinsic)"; | |
355 } | |
356 | |
357 // These are flag-matching functions: | |
358 inline bool match_F_R(jshort flags) { | |
359 const int req = 0; | |
360 const int neg = JVM_ACC_STATIC | JVM_ACC_SYNCHRONIZED; | |
361 return (flags & (req | neg)) == req; | |
362 } | |
1080
7c57aead6d3e
6892658: C2 should optimize some stringbuilder patterns
never
parents:
196
diff
changeset
|
363 inline bool match_F_Y(jshort flags) { |
7c57aead6d3e
6892658: C2 should optimize some stringbuilder patterns
never
parents:
196
diff
changeset
|
364 const int req = JVM_ACC_SYNCHRONIZED; |
7c57aead6d3e
6892658: C2 should optimize some stringbuilder patterns
never
parents:
196
diff
changeset
|
365 const int neg = JVM_ACC_STATIC; |
7c57aead6d3e
6892658: C2 should optimize some stringbuilder patterns
never
parents:
196
diff
changeset
|
366 return (flags & (req | neg)) == req; |
7c57aead6d3e
6892658: C2 should optimize some stringbuilder patterns
never
parents:
196
diff
changeset
|
367 } |
0 | 368 inline bool match_F_RN(jshort flags) { |
369 const int req = JVM_ACC_NATIVE; | |
370 const int neg = JVM_ACC_STATIC | JVM_ACC_SYNCHRONIZED; | |
371 return (flags & (req | neg)) == req; | |
372 } | |
373 inline bool match_F_S(jshort flags) { | |
374 const int req = JVM_ACC_STATIC; | |
375 const int neg = JVM_ACC_SYNCHRONIZED; | |
376 return (flags & (req | neg)) == req; | |
377 } | |
378 inline bool match_F_SN(jshort flags) { | |
379 const int req = JVM_ACC_STATIC | JVM_ACC_NATIVE; | |
380 const int neg = JVM_ACC_SYNCHRONIZED; | |
381 return (flags & (req | neg)) == req; | |
382 } | |
45
48a3fa21394b
6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents:
0
diff
changeset
|
383 inline bool match_F_RNY(jshort flags) { |
48a3fa21394b
6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents:
0
diff
changeset
|
384 const int req = JVM_ACC_NATIVE | JVM_ACC_SYNCHRONIZED; |
48a3fa21394b
6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents:
0
diff
changeset
|
385 const int neg = JVM_ACC_STATIC; |
48a3fa21394b
6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents:
0
diff
changeset
|
386 return (flags & (req | neg)) == req; |
48a3fa21394b
6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents:
0
diff
changeset
|
387 } |
0 | 388 |
389 // These are for forming case labels: | |
1133
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
390 #define ID3(x, y, z) (( jlong)(z) + \ |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
391 ((jlong)(y) << vmSymbols::log2_SID_LIMIT) + \ |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
392 ((jlong)(x) << (2*vmSymbols::log2_SID_LIMIT)) ) |
0 | 393 #define SID_ENUM(n) vmSymbols::VM_SYMBOL_ENUM_NAME(n) |
394 | |
1133
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
395 vmIntrinsics::ID vmIntrinsics::find_id_impl(vmSymbols::SID holder, |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
396 vmSymbols::SID name, |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
397 vmSymbols::SID sig, |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
398 jshort flags) { |
0 | 399 assert((int)vmSymbols::SID_LIMIT <= (1<<vmSymbols::log2_SID_LIMIT), "must fit"); |
400 | |
401 // Let the C compiler build the decision tree. | |
402 | |
403 #define VM_INTRINSIC_CASE(id, klass, name, sig, fcode) \ | |
404 case ID3(SID_ENUM(klass), SID_ENUM(name), SID_ENUM(sig)): \ | |
405 if (!match_##fcode(flags)) break; \ | |
406 return id; | |
407 | |
408 switch (ID3(holder, name, sig)) { | |
409 VM_INTRINSICS_DO(VM_INTRINSIC_CASE, | |
410 VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_ALIAS_IGNORE); | |
411 } | |
412 return vmIntrinsics::_none; | |
413 | |
414 #undef VM_INTRINSIC_CASE | |
415 } | |
416 | |
417 | |
418 const char* vmIntrinsics::short_name_as_C_string(vmIntrinsics::ID id, char* buf, int buflen) { | |
419 const char* str = name_at(id); | |
420 #ifndef PRODUCT | |
421 const char* kname = vmSymbols::name_for(class_for(id)); | |
422 const char* mname = vmSymbols::name_for(name_for(id)); | |
423 const char* sname = vmSymbols::name_for(signature_for(id)); | |
424 const char* fname = ""; | |
425 switch (flags_for(id)) { | |
1080
7c57aead6d3e
6892658: C2 should optimize some stringbuilder patterns
never
parents:
196
diff
changeset
|
426 case F_Y: fname = "synchronized "; break; |
0 | 427 case F_RN: fname = "native "; break; |
428 case F_SN: fname = "native static "; break; | |
429 case F_S: fname = "static "; break; | |
45
48a3fa21394b
6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents:
0
diff
changeset
|
430 case F_RNY:fname = "native synchronized "; break; |
0 | 431 } |
432 const char* kptr = strrchr(kname, '/'); | |
433 if (kptr != NULL) kname = kptr + 1; | |
434 int len = jio_snprintf(buf, buflen, "%s: %s%s.%s%s", | |
435 str, fname, kname, mname, sname); | |
436 if (len < buflen) | |
437 str = buf; | |
438 #endif //PRODUCT | |
439 return str; | |
440 } | |
441 | |
442 | |
1133
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
443 // These are to get information about intrinsics. |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
444 |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
445 #define ID4(x, y, z, f) ((ID3(x, y, z) << vmIntrinsics::log2_FLAG_LIMIT) | (jlong) (f)) |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
446 |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
447 static const jlong intrinsic_info_array[vmIntrinsics::ID_LIMIT+1] = { |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
448 #define VM_INTRINSIC_INFO(ignore_id, klass, name, sig, fcode) \ |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
449 ID4(SID_ENUM(klass), SID_ENUM(name), SID_ENUM(sig), vmIntrinsics::fcode), |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
450 |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
451 0, VM_INTRINSICS_DO(VM_INTRINSIC_INFO, |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
452 VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_ALIAS_IGNORE) |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
453 0 |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
454 #undef VM_INTRINSIC_INFO |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
455 }; |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
456 |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
457 inline jlong intrinsic_info(vmIntrinsics::ID id) { |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
458 return intrinsic_info_array[vmIntrinsics::ID_from((int)id)]; |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
459 } |
0 | 460 |
461 vmSymbols::SID vmIntrinsics::class_for(vmIntrinsics::ID id) { | |
1133
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
462 jlong info = intrinsic_info(id); |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
463 int shift = 2*vmSymbols::log2_SID_LIMIT + log2_FLAG_LIMIT, mask = right_n_bits(vmSymbols::log2_SID_LIMIT); |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
464 assert(((ID4(1021,1022,1023,15) >> shift) & mask) == 1021, ""); |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
465 return vmSymbols::SID( (info >> shift) & mask ); |
0 | 466 } |
467 | |
468 vmSymbols::SID vmIntrinsics::name_for(vmIntrinsics::ID id) { | |
1133
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
469 jlong info = intrinsic_info(id); |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
470 int shift = vmSymbols::log2_SID_LIMIT + log2_FLAG_LIMIT, mask = right_n_bits(vmSymbols::log2_SID_LIMIT); |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
471 assert(((ID4(1021,1022,1023,15) >> shift) & mask) == 1022, ""); |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
472 return vmSymbols::SID( (info >> shift) & mask ); |
0 | 473 } |
474 | |
475 vmSymbols::SID vmIntrinsics::signature_for(vmIntrinsics::ID id) { | |
1133
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
476 jlong info = intrinsic_info(id); |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
477 int shift = log2_FLAG_LIMIT, mask = right_n_bits(vmSymbols::log2_SID_LIMIT); |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
478 assert(((ID4(1021,1022,1023,15) >> shift) & mask) == 1023, ""); |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
479 return vmSymbols::SID( (info >> shift) & mask ); |
0 | 480 } |
481 | |
482 vmIntrinsics::Flags vmIntrinsics::flags_for(vmIntrinsics::ID id) { | |
1133
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
483 jlong info = intrinsic_info(id); |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
484 int shift = 0, mask = right_n_bits(log2_FLAG_LIMIT); |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
485 assert(((ID4(1021,1022,1023,15) >> shift) & mask) == 15, ""); |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1080
diff
changeset
|
486 return Flags( (info >> shift) & mask ); |
0 | 487 } |
488 | |
489 | |
490 #ifndef PRODUCT | |
491 // verify_method performs an extra check on a matched intrinsic method | |
492 | |
493 static bool match_method(methodOop m, symbolOop n, symbolOop s) { | |
494 return (m->name() == n && | |
495 m->signature() == s); | |
496 } | |
497 | |
498 static vmIntrinsics::ID match_method_with_klass(methodOop m, symbolOop mk) { | |
499 #define VM_INTRINSIC_MATCH(id, klassname, namepart, sigpart, flags) \ | |
500 { symbolOop k = vmSymbols::klassname(); \ | |
501 if (mk == k) { \ | |
502 symbolOop n = vmSymbols::namepart(); \ | |
503 symbolOop s = vmSymbols::sigpart(); \ | |
504 if (match_method(m, n, s)) \ | |
505 return vmIntrinsics::id; \ | |
506 } } | |
507 VM_INTRINSICS_DO(VM_INTRINSIC_MATCH, | |
508 VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_ALIAS_IGNORE); | |
509 return vmIntrinsics::_none; | |
510 #undef VM_INTRINSIC_MATCH | |
511 } | |
512 | |
513 void vmIntrinsics::verify_method(ID actual_id, methodOop m) { | |
514 symbolOop mk = Klass::cast(m->method_holder())->name(); | |
515 ID declared_id = match_method_with_klass(m, mk); | |
516 | |
517 if (declared_id == actual_id) return; // success | |
518 | |
519 if (declared_id == _none && actual_id != _none && mk == vmSymbols::java_lang_StrictMath()) { | |
520 // Here are a few special cases in StrictMath not declared in vmSymbols.hpp. | |
521 switch (actual_id) { | |
522 case _min: | |
523 case _max: | |
524 case _dsqrt: | |
525 declared_id = match_method_with_klass(m, vmSymbols::java_lang_Math()); | |
526 if (declared_id == actual_id) return; // acceptable alias | |
527 break; | |
528 } | |
529 } | |
530 | |
531 const char* declared_name = name_at(declared_id); | |
532 const char* actual_name = name_at(actual_id); | |
533 methodHandle mh = m; | |
534 m = NULL; | |
535 ttyLocker ttyl; | |
536 if (xtty != NULL) { | |
537 xtty->begin_elem("intrinsic_misdeclared actual='%s' declared='%s'", | |
538 actual_name, declared_name); | |
539 xtty->method(mh); | |
540 xtty->end_elem(""); | |
541 } | |
542 if (PrintMiscellaneous && (WizardMode || Verbose)) { | |
543 tty->print_cr("*** misidentified method; %s(%d) should be %s(%d):", | |
544 declared_name, declared_id, actual_name, actual_id); | |
45
48a3fa21394b
6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents:
0
diff
changeset
|
545 mh()->print_short_name(tty); |
0 | 546 tty->cr(); |
547 } | |
548 } | |
549 #endif //PRODUCT |