Mercurial > hg > graal-compiler
comparison src/share/vm/ci/ciEnv.cpp @ 1602:136b78722a08
6939203: JSR 292 needs method handle constants
Summary: Add new CP types CONSTANT_MethodHandle, CONSTANT_MethodType; extend 'ldc' bytecode.
Reviewed-by: twisti, never
author | jrose |
---|---|
date | Wed, 09 Jun 2010 18:50:45 -0700 |
parents | c18cbe5936b8 |
children | e0ba4e04c839 |
comparison
equal
deleted
inserted
replaced
1585:49fac4acd688 | 1602:136b78722a08 |
---|---|
509 // ------------------------------------------------------------------ | 509 // ------------------------------------------------------------------ |
510 // ciEnv::get_constant_by_index_impl | 510 // ciEnv::get_constant_by_index_impl |
511 // | 511 // |
512 // Implementation of get_constant_by_index(). | 512 // Implementation of get_constant_by_index(). |
513 ciConstant ciEnv::get_constant_by_index_impl(constantPoolHandle cpool, | 513 ciConstant ciEnv::get_constant_by_index_impl(constantPoolHandle cpool, |
514 int index, | 514 int pool_index, int cache_index, |
515 ciInstanceKlass* accessor) { | 515 ciInstanceKlass* accessor) { |
516 bool ignore_will_link; | |
516 EXCEPTION_CONTEXT; | 517 EXCEPTION_CONTEXT; |
518 int index = pool_index; | |
519 if (cache_index >= 0) { | |
520 assert(index < 0, "only one kind of index at a time"); | |
521 ConstantPoolCacheEntry* cpc_entry = cpool->cache()->entry_at(cache_index); | |
522 index = cpc_entry->constant_pool_index(); | |
523 oop obj = cpc_entry->f1(); | |
524 if (obj != NULL) { | |
525 assert(obj->is_instance(), "must be an instance"); | |
526 ciObject* ciobj = get_object(obj); | |
527 return ciConstant(T_OBJECT, ciobj); | |
528 } | |
529 } | |
517 constantTag tag = cpool->tag_at(index); | 530 constantTag tag = cpool->tag_at(index); |
518 if (tag.is_int()) { | 531 if (tag.is_int()) { |
519 return ciConstant(T_INT, (jint)cpool->int_at(index)); | 532 return ciConstant(T_INT, (jint)cpool->int_at(index)); |
520 } else if (tag.is_long()) { | 533 } else if (tag.is_long()) { |
521 return ciConstant((jlong)cpool->long_at(index)); | 534 return ciConstant((jlong)cpool->long_at(index)); |
538 ciObject* constant = get_object(string); | 551 ciObject* constant = get_object(string); |
539 assert (constant->is_instance(), "must be an instance, or not? "); | 552 assert (constant->is_instance(), "must be an instance, or not? "); |
540 return ciConstant(T_OBJECT, constant); | 553 return ciConstant(T_OBJECT, constant); |
541 } else if (tag.is_klass() || tag.is_unresolved_klass()) { | 554 } else if (tag.is_klass() || tag.is_unresolved_klass()) { |
542 // 4881222: allow ldc to take a class type | 555 // 4881222: allow ldc to take a class type |
543 bool ignore; | 556 ciKlass* klass = get_klass_by_index_impl(cpool, index, ignore_will_link, accessor); |
544 ciKlass* klass = get_klass_by_index_impl(cpool, index, ignore, accessor); | |
545 if (HAS_PENDING_EXCEPTION) { | 557 if (HAS_PENDING_EXCEPTION) { |
546 CLEAR_PENDING_EXCEPTION; | 558 CLEAR_PENDING_EXCEPTION; |
547 record_out_of_memory_failure(); | 559 record_out_of_memory_failure(); |
548 return ciConstant(); | 560 return ciConstant(); |
549 } | 561 } |
550 assert (klass->is_instance_klass() || klass->is_array_klass(), | 562 assert (klass->is_instance_klass() || klass->is_array_klass(), |
551 "must be an instance or array klass "); | 563 "must be an instance or array klass "); |
552 return ciConstant(T_OBJECT, klass); | 564 return ciConstant(T_OBJECT, klass->java_mirror()); |
553 } else if (tag.is_object()) { | 565 } else if (tag.is_object()) { |
554 oop obj = cpool->object_at(index); | 566 oop obj = cpool->object_at(index); |
555 assert(obj->is_instance(), "must be an instance"); | 567 assert(obj->is_instance(), "must be an instance"); |
556 ciObject* ciobj = get_object(obj); | 568 ciObject* ciobj = get_object(obj); |
557 return ciConstant(T_OBJECT, ciobj); | 569 return ciConstant(T_OBJECT, ciobj); |
570 } else if (tag.is_method_type()) { | |
571 // must execute Java code to link this CP entry into cache[i].f1 | |
572 ciSymbol* signature = get_object(cpool->method_type_signature_at(index))->as_symbol(); | |
573 ciObject* ciobj = get_unloaded_method_type_constant(signature); | |
574 return ciConstant(T_OBJECT, ciobj); | |
575 } else if (tag.is_method_handle()) { | |
576 // must execute Java code to link this CP entry into cache[i].f1 | |
577 int ref_kind = cpool->method_handle_ref_kind_at(index); | |
578 int callee_index = cpool->method_handle_klass_index_at(index); | |
579 ciKlass* callee = get_klass_by_index_impl(cpool, callee_index, ignore_will_link, accessor); | |
580 ciSymbol* name = get_object(cpool->method_handle_name_ref_at(index))->as_symbol(); | |
581 ciSymbol* signature = get_object(cpool->method_handle_signature_ref_at(index))->as_symbol(); | |
582 ciObject* ciobj = get_unloaded_method_handle_constant(callee, name, signature, ref_kind); | |
583 return ciConstant(T_OBJECT, ciobj); | |
558 } else { | 584 } else { |
559 ShouldNotReachHere(); | 585 ShouldNotReachHere(); |
560 return ciConstant(); | 586 return ciConstant(); |
561 } | 587 } |
562 } | |
563 | |
564 // ------------------------------------------------------------------ | |
565 // ciEnv::is_unresolved_string_impl | |
566 // | |
567 // Implementation of is_unresolved_string(). | |
568 bool ciEnv::is_unresolved_string_impl(instanceKlass* accessor, int index) const { | |
569 EXCEPTION_CONTEXT; | |
570 assert(accessor->is_linked(), "must be linked before accessing constant pool"); | |
571 constantPoolOop cpool = accessor->constants(); | |
572 constantTag tag = cpool->tag_at(index); | |
573 return tag.is_unresolved_string(); | |
574 } | |
575 | |
576 // ------------------------------------------------------------------ | |
577 // ciEnv::is_unresolved_klass_impl | |
578 // | |
579 // Implementation of is_unresolved_klass(). | |
580 bool ciEnv::is_unresolved_klass_impl(instanceKlass* accessor, int index) const { | |
581 EXCEPTION_CONTEXT; | |
582 assert(accessor->is_linked(), "must be linked before accessing constant pool"); | |
583 constantPoolOop cpool = accessor->constants(); | |
584 constantTag tag = cpool->tag_at(index); | |
585 return tag.is_unresolved_klass(); | |
586 } | 588 } |
587 | 589 |
588 // ------------------------------------------------------------------ | 590 // ------------------------------------------------------------------ |
589 // ciEnv::get_constant_by_index | 591 // ciEnv::get_constant_by_index |
590 // | 592 // |
591 // Pull a constant out of the constant pool. How appropriate. | 593 // Pull a constant out of the constant pool. How appropriate. |
592 // | 594 // |
593 // Implementation note: this query is currently in no way cached. | 595 // Implementation note: this query is currently in no way cached. |
594 ciConstant ciEnv::get_constant_by_index(constantPoolHandle cpool, | 596 ciConstant ciEnv::get_constant_by_index(constantPoolHandle cpool, |
595 int index, | 597 int pool_index, int cache_index, |
596 ciInstanceKlass* accessor) { | 598 ciInstanceKlass* accessor) { |
597 GUARDED_VM_ENTRY(return get_constant_by_index_impl(cpool, index, accessor);) | 599 GUARDED_VM_ENTRY(return get_constant_by_index_impl(cpool, pool_index, cache_index, accessor);) |
598 } | |
599 | |
600 // ------------------------------------------------------------------ | |
601 // ciEnv::is_unresolved_string | |
602 // | |
603 // Check constant pool | |
604 // | |
605 // Implementation note: this query is currently in no way cached. | |
606 bool ciEnv::is_unresolved_string(ciInstanceKlass* accessor, | |
607 int index) const { | |
608 GUARDED_VM_ENTRY(return is_unresolved_string_impl(accessor->get_instanceKlass(), index); ) | |
609 } | |
610 | |
611 // ------------------------------------------------------------------ | |
612 // ciEnv::is_unresolved_klass | |
613 // | |
614 // Check constant pool | |
615 // | |
616 // Implementation note: this query is currently in no way cached. | |
617 bool ciEnv::is_unresolved_klass(ciInstanceKlass* accessor, | |
618 int index) const { | |
619 GUARDED_VM_ENTRY(return is_unresolved_klass_impl(accessor->get_instanceKlass(), index); ) | |
620 } | 600 } |
621 | 601 |
622 // ------------------------------------------------------------------ | 602 // ------------------------------------------------------------------ |
623 // ciEnv::get_field_by_index_impl | 603 // ciEnv::get_field_by_index_impl |
624 // | 604 // |