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