comparison 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
comparison
equal deleted inserted replaced
3:0a2f43d9f1f2 4:4be8c64c6aa6
1 /* 1 /*
2 * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. 2 * Copyright 1997-2009 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 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 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
68 static const char* vm_symbol_bodies = VM_SYMBOLS_DO(VM_SYMBOL_BODY, VM_ALIAS_IGNORE); 68 static const char* vm_symbol_bodies = VM_SYMBOLS_DO(VM_SYMBOL_BODY, VM_ALIAS_IGNORE);
69 69
70 void vmSymbols::initialize(TRAPS) { 70 void vmSymbols::initialize(TRAPS) {
71 assert((int)SID_LIMIT <= (1<<log2_SID_LIMIT), "must fit in this bitfield"); 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"); 72 assert((int)SID_LIMIT*5 > (1<<log2_SID_LIMIT), "make the bitfield smaller, please");
73 assert(vmIntrinsics::FLAG_LIMIT <= (1 << vmIntrinsics::log2_FLAG_LIMIT), "must fit in this bitfield");
73 74
74 if (!UseSharedSpaces) { 75 if (!UseSharedSpaces) {
75 const char* string = &vm_symbol_bodies[0]; 76 const char* string = &vm_symbol_bodies[0];
76 for (int index = (int)FIRST_SID; index < (int)SID_LIMIT; index++) { 77 for (int index = (int)FIRST_SID; index < (int)SID_LIMIT; index++) {
77 symbolOop sym = oopFactory::new_symbol(string, CHECK); 78 symbolOop sym = oopFactory::new_symbol(string, CHECK);
269 #endif //ASSERT 270 #endif //ASSERT
270 271
271 return sid; 272 return sid;
272 } 273 }
273 274
275 static vmIntrinsics::ID wrapper_intrinsic(BasicType type, bool unboxing) {
276 #define TYPE2(type, unboxing) ((int)(type)*2 + ((unboxing) ? 1 : 0))
277 switch (TYPE2(type, unboxing)) {
278 #define BASIC_TYPE_CASE(type, box, unbox) \
279 case TYPE2(type, false): return vmIntrinsics::box; \
280 case TYPE2(type, true): return vmIntrinsics::unbox
281 BASIC_TYPE_CASE(T_BOOLEAN, _Boolean_valueOf, _booleanValue);
282 BASIC_TYPE_CASE(T_BYTE, _Byte_valueOf, _byteValue);
283 BASIC_TYPE_CASE(T_CHAR, _Character_valueOf, _charValue);
284 BASIC_TYPE_CASE(T_SHORT, _Short_valueOf, _shortValue);
285 BASIC_TYPE_CASE(T_INT, _Integer_valueOf, _intValue);
286 BASIC_TYPE_CASE(T_LONG, _Long_valueOf, _longValue);
287 BASIC_TYPE_CASE(T_FLOAT, _Float_valueOf, _floatValue);
288 BASIC_TYPE_CASE(T_DOUBLE, _Double_valueOf, _doubleValue);
289 #undef BASIC_TYPE_CASE
290 }
291 #undef TYPE2
292 return vmIntrinsics::_none;
293 }
294
295 vmIntrinsics::ID vmIntrinsics::for_boxing(BasicType type) {
296 return wrapper_intrinsic(type, false);
297 }
298 vmIntrinsics::ID vmIntrinsics::for_unboxing(BasicType type) {
299 return wrapper_intrinsic(type, true);
300 }
301
302 methodOop vmIntrinsics::method_for(vmIntrinsics::ID id) {
303 if (id == _none) return NULL;
304 symbolOop cname = vmSymbols::symbol_at(class_for(id));
305 symbolOop mname = vmSymbols::symbol_at(name_for(id));
306 symbolOop msig = vmSymbols::symbol_at(signature_for(id));
307 if (cname == NULL || mname == NULL || msig == NULL) return NULL;
308 klassOop k = SystemDictionary::find_well_known_klass(cname);
309 if (k == NULL) return NULL;
310 return instanceKlass::cast(k)->find_method(mname, msig);
311 }
312
274 313
275 #define VM_INTRINSIC_INITIALIZE(id, klass, name, sig, flags) #id "\0" 314 #define VM_INTRINSIC_INITIALIZE(id, klass, name, sig, flags) #id "\0"
276 static const char* vm_intrinsic_name_bodies = 315 static const char* vm_intrinsic_name_bodies =
277 VM_INTRINSICS_DO(VM_INTRINSIC_INITIALIZE, 316 VM_INTRINSICS_DO(VM_INTRINSIC_INITIALIZE,
278 VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_ALIAS_IGNORE); 317 VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_ALIAS_IGNORE);
328 const int neg = JVM_ACC_STATIC; 367 const int neg = JVM_ACC_STATIC;
329 return (flags & (req | neg)) == req; 368 return (flags & (req | neg)) == req;
330 } 369 }
331 370
332 // These are for forming case labels: 371 // These are for forming case labels:
333 #define ID3(x, y, z) (( jint)(z) + \ 372 #define ID3(x, y, z) (( jlong)(z) + \
334 ((jint)(y) << vmSymbols::log2_SID_LIMIT) + \ 373 ((jlong)(y) << vmSymbols::log2_SID_LIMIT) + \
335 ((jint)(x) << (2*vmSymbols::log2_SID_LIMIT)) ) 374 ((jlong)(x) << (2*vmSymbols::log2_SID_LIMIT)) )
336 #define SID_ENUM(n) vmSymbols::VM_SYMBOL_ENUM_NAME(n) 375 #define SID_ENUM(n) vmSymbols::VM_SYMBOL_ENUM_NAME(n)
337 376
338 vmIntrinsics::ID vmIntrinsics::find_id(vmSymbols::SID holder, 377 vmIntrinsics::ID vmIntrinsics::find_id_impl(vmSymbols::SID holder,
339 vmSymbols::SID name, 378 vmSymbols::SID name,
340 vmSymbols::SID sig, 379 vmSymbols::SID sig,
341 jshort flags) { 380 jshort flags) {
342 assert((int)vmSymbols::SID_LIMIT <= (1<<vmSymbols::log2_SID_LIMIT), "must fit"); 381 assert((int)vmSymbols::SID_LIMIT <= (1<<vmSymbols::log2_SID_LIMIT), "must fit");
343 382
344 // Let the C compiler build the decision tree. 383 // Let the C compiler build the decision tree.
345 384
346 #define VM_INTRINSIC_CASE(id, klass, name, sig, fcode) \ 385 #define VM_INTRINSIC_CASE(id, klass, name, sig, fcode) \
381 #endif //PRODUCT 420 #endif //PRODUCT
382 return str; 421 return str;
383 } 422 }
384 423
385 424
386 // These are for friendly printouts of intrinsics: 425 // These are to get information about intrinsics.
426
427 #define ID4(x, y, z, f) ((ID3(x, y, z) << vmIntrinsics::log2_FLAG_LIMIT) | (jlong) (f))
428
429 static const jlong intrinsic_info_array[vmIntrinsics::ID_LIMIT+1] = {
430 #define VM_INTRINSIC_INFO(ignore_id, klass, name, sig, fcode) \
431 ID4(SID_ENUM(klass), SID_ENUM(name), SID_ENUM(sig), vmIntrinsics::fcode),
432
433 0, VM_INTRINSICS_DO(VM_INTRINSIC_INFO,
434 VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_ALIAS_IGNORE)
435 0
436 #undef VM_INTRINSIC_INFO
437 };
438
439 inline jlong intrinsic_info(vmIntrinsics::ID id) {
440 return intrinsic_info_array[vmIntrinsics::ID_from((int)id)];
441 }
387 442
388 vmSymbols::SID vmIntrinsics::class_for(vmIntrinsics::ID id) { 443 vmSymbols::SID vmIntrinsics::class_for(vmIntrinsics::ID id) {
389 #ifndef PRODUCT 444 jlong info = intrinsic_info(id);
390 #define VM_INTRINSIC_CASE(id, klass, name, sig, fcode) \ 445 int shift = 2*vmSymbols::log2_SID_LIMIT + log2_FLAG_LIMIT, mask = right_n_bits(vmSymbols::log2_SID_LIMIT);
391 case id: return SID_ENUM(klass); 446 assert(((ID4(1021,1022,1023,15) >> shift) & mask) == 1021, "");
392 447 return vmSymbols::SID( (info >> shift) & mask );
393 switch (id) {
394 VM_INTRINSICS_DO(VM_INTRINSIC_CASE,
395 VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_ALIAS_IGNORE);
396 }
397 #undef VM_INTRINSIC_CASE
398 #endif //PRODUCT
399 return vmSymbols::NO_SID;
400 } 448 }
401 449
402 vmSymbols::SID vmIntrinsics::name_for(vmIntrinsics::ID id) { 450 vmSymbols::SID vmIntrinsics::name_for(vmIntrinsics::ID id) {
403 #ifndef PRODUCT 451 jlong info = intrinsic_info(id);
404 #define VM_INTRINSIC_CASE(id, klass, name, sig, fcode) \ 452 int shift = vmSymbols::log2_SID_LIMIT + log2_FLAG_LIMIT, mask = right_n_bits(vmSymbols::log2_SID_LIMIT);
405 case id: return SID_ENUM(name); 453 assert(((ID4(1021,1022,1023,15) >> shift) & mask) == 1022, "");
406 454 return vmSymbols::SID( (info >> shift) & mask );
407 switch (id) {
408 VM_INTRINSICS_DO(VM_INTRINSIC_CASE,
409 VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_ALIAS_IGNORE);
410 }
411 #undef VM_INTRINSIC_CASE
412 #endif //PRODUCT
413 return vmSymbols::NO_SID;
414 } 455 }
415 456
416 vmSymbols::SID vmIntrinsics::signature_for(vmIntrinsics::ID id) { 457 vmSymbols::SID vmIntrinsics::signature_for(vmIntrinsics::ID id) {
417 #ifndef PRODUCT 458 jlong info = intrinsic_info(id);
418 #define VM_INTRINSIC_CASE(id, klass, name, sig, fcode) \ 459 int shift = log2_FLAG_LIMIT, mask = right_n_bits(vmSymbols::log2_SID_LIMIT);
419 case id: return SID_ENUM(sig); 460 assert(((ID4(1021,1022,1023,15) >> shift) & mask) == 1023, "");
420 461 return vmSymbols::SID( (info >> shift) & mask );
421 switch (id) {
422 VM_INTRINSICS_DO(VM_INTRINSIC_CASE,
423 VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_ALIAS_IGNORE);
424 }
425 #undef VM_INTRINSIC_CASE
426 #endif //PRODUCT
427 return vmSymbols::NO_SID;
428 } 462 }
429 463
430 vmIntrinsics::Flags vmIntrinsics::flags_for(vmIntrinsics::ID id) { 464 vmIntrinsics::Flags vmIntrinsics::flags_for(vmIntrinsics::ID id) {
431 #ifndef PRODUCT 465 jlong info = intrinsic_info(id);
432 #define VM_INTRINSIC_CASE(id, klass, name, sig, fcode) \ 466 int shift = 0, mask = right_n_bits(log2_FLAG_LIMIT);
433 case id: return fcode; 467 assert(((ID4(1021,1022,1023,15) >> shift) & mask) == 15, "");
434 468 return Flags( (info >> shift) & mask );
435 switch (id) {
436 VM_INTRINSICS_DO(VM_INTRINSIC_CASE,
437 VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_ALIAS_IGNORE);
438 }
439 #undef VM_INTRINSIC_CASE
440 #endif //PRODUCT
441 return F_none;
442 } 469 }
443 470
444 471
445 #ifndef PRODUCT 472 #ifndef PRODUCT
446 // verify_method performs an extra check on a matched intrinsic method 473 // verify_method performs an extra check on a matched intrinsic method