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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "ci/ciConstant.hpp"
27 #include "ci/ciEnv.hpp"
28 #include "ci/ciField.hpp"
29 #include "ci/ciInstance.hpp"
30 #include "ci/ciInstanceKlass.hpp"
31 #include "ci/ciMethod.hpp"
32 #include "ci/ciNullObject.hpp"
33 #include "ci/ciReplay.hpp"
34 #include "ci/ciSymbols.hpp"
35 #include "ci/ciUtilities.inline.hpp"
36 #include "classfile/javaClasses.hpp"
37 #include "classfile/javaClasses.inline.hpp"
38 #include "classfile/systemDictionary.hpp"
39 #include "classfile/vmClasses.hpp"
40 #include "classfile/vmSymbols.hpp"
41 #include "code/codeCache.hpp"
42 #include "code/scopeDesc.hpp"
43 #include "compiler/compilationLog.hpp"
44 #include "compiler/compilationPolicy.hpp"
45 #include "compiler/compileBroker.hpp"
46 #include "compiler/compilerEvent.hpp"
47 #include "compiler/compileLog.hpp"
48 #include "compiler/compileTask.hpp"
510 }
511
512 Handle loader;
513 Handle domain;
514 if (accessing_klass != nullptr) {
515 loader = Handle(current, accessing_klass->loader());
516 domain = Handle(current, accessing_klass->protection_domain());
517 }
518
519 Klass* found_klass = require_local ?
520 SystemDictionary::find_instance_or_array_klass(current, sym, loader, domain) :
521 SystemDictionary::find_constrained_instance_or_array_klass(current, sym, loader);
522
523 // If we fail to find an array klass, look again for its element type.
524 // The element type may be available either locally or via constraints.
525 // In either case, if we can find the element type in the system dictionary,
526 // we must build an array type around it. The CI requires array klasses
527 // to be loaded if their element klasses are loaded, except when memory
528 // is exhausted.
529 if (Signature::is_array(sym) &&
530 (sym->char_at(1) == JVM_SIGNATURE_ARRAY || sym->char_at(1) == JVM_SIGNATURE_CLASS)) {
531 // We have an unloaded array.
532 // Build it on the fly if the element class exists.
533 SignatureStream ss(sym, false);
534 ss.skip_array_prefix(1);
535 // Get element ciKlass recursively.
536 ciKlass* elem_klass =
537 get_klass_by_name_impl(accessing_klass,
538 cpool,
539 get_symbol(ss.as_symbol()),
540 require_local);
541 if (elem_klass != nullptr && elem_klass->is_loaded()) {
542 // Now make an array for it
543 return ciObjArrayKlass::make_impl(elem_klass);
544 }
545 }
546
547 if (found_klass == nullptr && !cpool.is_null() && cpool->has_preresolution()) {
548 // Look inside the constant pool for pre-resolved class entries.
549 for (int i = cpool->length() - 1; i >= 1; i--) {
550 if (cpool->tag_at(i).is_klass()) {
551 Klass* kls = cpool->resolved_klass_at(i);
552 if (kls->name() == sym) {
553 found_klass = kls;
554 break;
555 }
556 }
557 }
558 }
559
560 if (found_klass != nullptr) {
561 // Found it. Build a CI handle.
562 return get_klass(found_klass);
563 }
564
565 if (require_local) return nullptr;
566
567 // Not yet loaded into the VM, or not governed by loader constraints.
568 // Make a CI representative for it.
569 return get_unloaded_klass(accessing_klass, name);
570 }
571
572 // ------------------------------------------------------------------
573 // ciEnv::get_klass_by_name
574 ciKlass* ciEnv::get_klass_by_name(ciKlass* accessing_klass,
575 ciSymbol* klass_name,
576 bool require_local) {
577 GUARDED_VM_ENTRY(return get_klass_by_name_impl(accessing_klass,
578 constantPoolHandle(),
579 klass_name,
580 require_local);)
581 }
582
583 // ------------------------------------------------------------------
584 // ciEnv::get_klass_by_index_impl
585 //
586 // Implementation of get_klass_by_index.
587 ciKlass* ciEnv::get_klass_by_index_impl(const constantPoolHandle& cpool,
588 int index,
635 ciKlass* ciKlass = get_klass(klass);
636 is_accessible = true;
637 if (ReplayCompiles && ciKlass == _unloaded_ciinstance_klass) {
638 // Klass was unresolved at replay dump time and therefore not accessible.
639 is_accessible = false;
640 }
641 return ciKlass;
642 }
643
644 // ------------------------------------------------------------------
645 // ciEnv::get_klass_by_index
646 //
647 // Get a klass from the constant pool.
648 ciKlass* ciEnv::get_klass_by_index(const constantPoolHandle& cpool,
649 int index,
650 bool& is_accessible,
651 ciInstanceKlass* accessor) {
652 GUARDED_VM_ENTRY(return get_klass_by_index_impl(cpool, index, is_accessible, accessor);)
653 }
654
655 // ------------------------------------------------------------------
656 // ciEnv::unbox_primitive_value
657 //
658 // Unbox a primitive and return it as a ciConstant.
659 ciConstant ciEnv::unbox_primitive_value(ciObject* cibox, BasicType expected_bt) {
660 jvalue value;
661 BasicType bt = java_lang_boxing_object::get_value(cibox->get_oop(), &value);
662 if (bt != expected_bt && expected_bt != T_ILLEGAL) {
663 assert(false, "type mismatch: %s vs %s", type2name(expected_bt), cibox->klass()->name()->as_klass_external_name());
664 return ciConstant();
665 }
666 switch (bt) {
667 case T_BOOLEAN: return ciConstant(bt, value.z);
668 case T_BYTE: return ciConstant(bt, value.b);
669 case T_SHORT: return ciConstant(bt, value.s);
670 case T_CHAR: return ciConstant(bt, value.c);
671 case T_INT: return ciConstant(bt, value.i);
672 case T_LONG: return ciConstant(value.j);
673 case T_FLOAT: return ciConstant(value.f);
674 case T_DOUBLE: return ciConstant(value.d);
731 return ciConstant((jfloat)cpool->float_at(index));
732 } else if (tag.is_double()) {
733 return ciConstant((jdouble)cpool->double_at(index));
734 } else if (tag.is_string()) {
735 EXCEPTION_CONTEXT;
736 assert(obj_index >= 0, "should have an object index");
737 oop string = cpool->string_at(index, obj_index, THREAD);
738 if (HAS_PENDING_EXCEPTION) {
739 CLEAR_PENDING_EXCEPTION;
740 record_out_of_memory_failure();
741 return ciConstant();
742 }
743 ciInstance* constant = get_object(string)->as_instance();
744 return ciConstant(T_OBJECT, constant);
745 } else if (tag.is_unresolved_klass_in_error()) {
746 return ciConstant(T_OBJECT, get_unloaded_klass_mirror(nullptr));
747 } else if (tag.is_klass() || tag.is_unresolved_klass()) {
748 bool will_link;
749 ciKlass* klass = get_klass_by_index_impl(cpool, index, will_link, accessor);
750 ciInstance* mirror = (will_link ? klass->java_mirror() : get_unloaded_klass_mirror(klass));
751 return ciConstant(T_OBJECT, mirror);
752 } else if (tag.is_method_type() || tag.is_method_type_in_error()) {
753 // must execute Java code to link this CP entry into cache[i].f1
754 assert(obj_index >= 0, "should have an object index");
755 ciSymbol* signature = get_symbol(cpool->method_type_signature_at(index));
756 ciObject* ciobj = get_unloaded_method_type_constant(signature);
757 return ciConstant(T_OBJECT, ciobj);
758 } else if (tag.is_method_handle() || tag.is_method_handle_in_error()) {
759 // must execute Java code to link this CP entry into cache[i].f1
760 assert(obj_index >= 0, "should have an object index");
761 bool ignore_will_link;
762 int ref_kind = cpool->method_handle_ref_kind_at(index);
763 int callee_index = cpool->method_handle_klass_index_at(index);
764 ciKlass* callee = get_klass_by_index_impl(cpool, callee_index, ignore_will_link, accessor);
765 ciSymbol* name = get_symbol(cpool->method_handle_name_ref_at(index));
766 ciSymbol* signature = get_symbol(cpool->method_handle_signature_ref_at(index));
767 ciObject* ciobj = get_unloaded_method_handle_constant(callee, name, signature, ref_kind);
768 return ciConstant(T_OBJECT, ciobj);
769 } else if (tag.is_dynamic_constant() || tag.is_dynamic_constant_in_error()) {
770 assert(obj_index >= 0, "should have an object index");
771 return ciConstant(T_OBJECT, unloaded_ciinstance()); // unresolved dynamic constant
|
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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "ci/ciConstant.hpp"
27 #include "ci/ciEnv.hpp"
28 #include "ci/ciField.hpp"
29 #include "ci/ciInlineKlass.hpp"
30 #include "ci/ciInstance.hpp"
31 #include "ci/ciInstanceKlass.hpp"
32 #include "ci/ciMethod.hpp"
33 #include "ci/ciNullObject.hpp"
34 #include "ci/ciReplay.hpp"
35 #include "ci/ciSymbols.hpp"
36 #include "ci/ciUtilities.inline.hpp"
37 #include "classfile/javaClasses.hpp"
38 #include "classfile/javaClasses.inline.hpp"
39 #include "classfile/systemDictionary.hpp"
40 #include "classfile/vmClasses.hpp"
41 #include "classfile/vmSymbols.hpp"
42 #include "code/codeCache.hpp"
43 #include "code/scopeDesc.hpp"
44 #include "compiler/compilationLog.hpp"
45 #include "compiler/compilationPolicy.hpp"
46 #include "compiler/compileBroker.hpp"
47 #include "compiler/compilerEvent.hpp"
48 #include "compiler/compileLog.hpp"
49 #include "compiler/compileTask.hpp"
511 }
512
513 Handle loader;
514 Handle domain;
515 if (accessing_klass != nullptr) {
516 loader = Handle(current, accessing_klass->loader());
517 domain = Handle(current, accessing_klass->protection_domain());
518 }
519
520 Klass* found_klass = require_local ?
521 SystemDictionary::find_instance_or_array_klass(current, sym, loader, domain) :
522 SystemDictionary::find_constrained_instance_or_array_klass(current, sym, loader);
523
524 // If we fail to find an array klass, look again for its element type.
525 // The element type may be available either locally or via constraints.
526 // In either case, if we can find the element type in the system dictionary,
527 // we must build an array type around it. The CI requires array klasses
528 // to be loaded if their element klasses are loaded, except when memory
529 // is exhausted.
530 if (Signature::is_array(sym) &&
531 (sym->char_at(1) == JVM_SIGNATURE_ARRAY ||
532 sym->char_at(1) == JVM_SIGNATURE_CLASS ||
533 sym->char_at(1) == JVM_SIGNATURE_PRIMITIVE_OBJECT )) {
534 // We have an unloaded array.
535 // Build it on the fly if the element class exists.
536 SignatureStream ss(sym, false);
537 ss.skip_array_prefix(1);
538 // Get element ciKlass recursively.
539 ciKlass* elem_klass =
540 get_klass_by_name_impl(accessing_klass,
541 cpool,
542 get_symbol(ss.as_symbol()),
543 require_local);
544 if (elem_klass != nullptr && elem_klass->is_loaded()) {
545 // Now make an array for it
546 bool null_free_array = sym->is_Q_array_signature() && sym->char_at(1) == JVM_SIGNATURE_PRIMITIVE_OBJECT;
547 return ciArrayKlass::make(elem_klass, null_free_array);
548 }
549 }
550
551 if (found_klass == nullptr && !cpool.is_null() && cpool->has_preresolution()) {
552 // Look inside the constant pool for pre-resolved class entries.
553 for (int i = cpool->length() - 1; i >= 1; i--) {
554 if (cpool->tag_at(i).is_klass()) {
555 Klass* kls = cpool->resolved_klass_at(i);
556 if (kls->name() == sym) {
557 found_klass = kls;
558 break;
559 }
560 }
561 }
562 }
563
564 if (found_klass != nullptr) {
565 // Found it. Build a CI handle.
566 return get_klass(found_klass);
567 }
568
569 if (require_local) return nullptr;
570
571 // Not yet loaded into the VM, or not governed by loader constraints.
572 // Make a CI representative for it.
573 int i = 0;
574 while (sym->char_at(i) == JVM_SIGNATURE_ARRAY) {
575 i++;
576 }
577 if (i > 0 && sym->char_at(i) == JVM_SIGNATURE_PRIMITIVE_OBJECT) {
578 // An unloaded array class of inline types is an ObjArrayKlass, an
579 // unloaded inline type class is an InstanceKlass. For consistency,
580 // make the signature of the unloaded array of inline type use L
581 // rather than Q.
582 char* new_name = name_buffer(sym->utf8_length()+1);
583 strncpy(new_name, (char*)sym->base(), sym->utf8_length());
584 new_name[i] = JVM_SIGNATURE_CLASS;
585 new_name[sym->utf8_length()] = '\0';
586 return get_unloaded_klass(accessing_klass, ciSymbol::make(new_name));
587 }
588 return get_unloaded_klass(accessing_klass, name);
589 }
590
591 // ------------------------------------------------------------------
592 // ciEnv::get_klass_by_name
593 ciKlass* ciEnv::get_klass_by_name(ciKlass* accessing_klass,
594 ciSymbol* klass_name,
595 bool require_local) {
596 GUARDED_VM_ENTRY(return get_klass_by_name_impl(accessing_klass,
597 constantPoolHandle(),
598 klass_name,
599 require_local);)
600 }
601
602 // ------------------------------------------------------------------
603 // ciEnv::get_klass_by_index_impl
604 //
605 // Implementation of get_klass_by_index.
606 ciKlass* ciEnv::get_klass_by_index_impl(const constantPoolHandle& cpool,
607 int index,
654 ciKlass* ciKlass = get_klass(klass);
655 is_accessible = true;
656 if (ReplayCompiles && ciKlass == _unloaded_ciinstance_klass) {
657 // Klass was unresolved at replay dump time and therefore not accessible.
658 is_accessible = false;
659 }
660 return ciKlass;
661 }
662
663 // ------------------------------------------------------------------
664 // ciEnv::get_klass_by_index
665 //
666 // Get a klass from the constant pool.
667 ciKlass* ciEnv::get_klass_by_index(const constantPoolHandle& cpool,
668 int index,
669 bool& is_accessible,
670 ciInstanceKlass* accessor) {
671 GUARDED_VM_ENTRY(return get_klass_by_index_impl(cpool, index, is_accessible, accessor);)
672 }
673
674 // ------------------------------------------------------------------
675 // ciEnv::is_inline_klass
676 //
677 // Check if the klass is an inline klass.
678 bool ciEnv::has_Q_signature(const constantPoolHandle& cpool, int index) {
679 GUARDED_VM_ENTRY(return cpool->klass_name_at(index)->is_Q_signature();)
680 }
681
682 // ------------------------------------------------------------------
683 // ciEnv::unbox_primitive_value
684 //
685 // Unbox a primitive and return it as a ciConstant.
686 ciConstant ciEnv::unbox_primitive_value(ciObject* cibox, BasicType expected_bt) {
687 jvalue value;
688 BasicType bt = java_lang_boxing_object::get_value(cibox->get_oop(), &value);
689 if (bt != expected_bt && expected_bt != T_ILLEGAL) {
690 assert(false, "type mismatch: %s vs %s", type2name(expected_bt), cibox->klass()->name()->as_klass_external_name());
691 return ciConstant();
692 }
693 switch (bt) {
694 case T_BOOLEAN: return ciConstant(bt, value.z);
695 case T_BYTE: return ciConstant(bt, value.b);
696 case T_SHORT: return ciConstant(bt, value.s);
697 case T_CHAR: return ciConstant(bt, value.c);
698 case T_INT: return ciConstant(bt, value.i);
699 case T_LONG: return ciConstant(value.j);
700 case T_FLOAT: return ciConstant(value.f);
701 case T_DOUBLE: return ciConstant(value.d);
758 return ciConstant((jfloat)cpool->float_at(index));
759 } else if (tag.is_double()) {
760 return ciConstant((jdouble)cpool->double_at(index));
761 } else if (tag.is_string()) {
762 EXCEPTION_CONTEXT;
763 assert(obj_index >= 0, "should have an object index");
764 oop string = cpool->string_at(index, obj_index, THREAD);
765 if (HAS_PENDING_EXCEPTION) {
766 CLEAR_PENDING_EXCEPTION;
767 record_out_of_memory_failure();
768 return ciConstant();
769 }
770 ciInstance* constant = get_object(string)->as_instance();
771 return ciConstant(T_OBJECT, constant);
772 } else if (tag.is_unresolved_klass_in_error()) {
773 return ciConstant(T_OBJECT, get_unloaded_klass_mirror(nullptr));
774 } else if (tag.is_klass() || tag.is_unresolved_klass()) {
775 bool will_link;
776 ciKlass* klass = get_klass_by_index_impl(cpool, index, will_link, accessor);
777 ciInstance* mirror = (will_link ? klass->java_mirror() : get_unloaded_klass_mirror(klass));
778 if (klass->is_loaded() && tag.is_Qdescriptor_klass()) {
779 return ciConstant(T_OBJECT, klass->as_inline_klass()->val_mirror());
780 } else {
781 return ciConstant(T_OBJECT, mirror);
782 }
783 } else if (tag.is_method_type() || tag.is_method_type_in_error()) {
784 // must execute Java code to link this CP entry into cache[i].f1
785 assert(obj_index >= 0, "should have an object index");
786 ciSymbol* signature = get_symbol(cpool->method_type_signature_at(index));
787 ciObject* ciobj = get_unloaded_method_type_constant(signature);
788 return ciConstant(T_OBJECT, ciobj);
789 } else if (tag.is_method_handle() || tag.is_method_handle_in_error()) {
790 // must execute Java code to link this CP entry into cache[i].f1
791 assert(obj_index >= 0, "should have an object index");
792 bool ignore_will_link;
793 int ref_kind = cpool->method_handle_ref_kind_at(index);
794 int callee_index = cpool->method_handle_klass_index_at(index);
795 ciKlass* callee = get_klass_by_index_impl(cpool, callee_index, ignore_will_link, accessor);
796 ciSymbol* name = get_symbol(cpool->method_handle_name_ref_at(index));
797 ciSymbol* signature = get_symbol(cpool->method_handle_signature_ref_at(index));
798 ciObject* ciobj = get_unloaded_method_handle_constant(callee, name, signature, ref_kind);
799 return ciConstant(T_OBJECT, ciobj);
800 } else if (tag.is_dynamic_constant() || tag.is_dynamic_constant_in_error()) {
801 assert(obj_index >= 0, "should have an object index");
802 return ciConstant(T_OBJECT, unloaded_ciinstance()); // unresolved dynamic constant
|