47 // Loaded instance klass. 48 ciInstanceKlass::ciInstanceKlass(KlassHandle h_k) : 49 ciKlass(h_k) 50 { 51 assert(get_Klass()->is_instance_klass(), "wrong type"); 52 assert(get_instanceKlass()->is_loaded(), "must be at least loaded"); 53 InstanceKlass* ik = get_instanceKlass(); 54 55 AccessFlags access_flags = ik->access_flags(); 56 _flags = ciFlags(access_flags); 57 _has_finalizer = access_flags.has_finalizer(); 58 _has_subklass = ik->subklass() != NULL; 59 _init_state = ik->init_state(); 60 _nonstatic_field_size = ik->nonstatic_field_size(); 61 _has_nonstatic_fields = ik->has_nonstatic_fields(); 62 _has_default_methods = ik->has_default_methods(); 63 _is_anonymous = ik->is_anonymous(); 64 _nonstatic_fields = NULL; // initialized lazily by compute_nonstatic_fields 65 _nof_declared_nonstatic_fields = -1; // initialized lazily by compute_nonstatic_fields 66 _has_injected_fields = -1; 67 _implementor = NULL; // we will fill these lazily 68 69 Thread *thread = Thread::current(); 70 if (ciObjectFactory::is_initialized()) { 71 _loader = JNIHandles::make_local(thread, ik->class_loader()); 72 _protection_domain = JNIHandles::make_local(thread, 73 ik->protection_domain()); 74 _is_shared = false; 75 } else { 76 Handle h_loader(thread, ik->class_loader()); 77 Handle h_protection_domain(thread, ik->protection_domain()); 78 _loader = JNIHandles::make_global(h_loader); 79 _protection_domain = JNIHandles::make_global(h_protection_domain); 80 _is_shared = true; 81 } 82 83 // Lazy fields get filled in only upon request. 84 _super = NULL; 85 _java_mirror = NULL; 86 89 super(); 90 } 91 //compute_nonstatic_fields(); // done outside of constructor 92 } 93 94 _field_cache = NULL; 95 } 96 97 // Version for unloaded classes: 98 ciInstanceKlass::ciInstanceKlass(ciSymbol* name, 99 jobject loader, jobject protection_domain) 100 : ciKlass(name, T_OBJECT) 101 { 102 assert(name->byte_at(0) != '[', "not an instance klass"); 103 _init_state = (InstanceKlass::ClassState)0; 104 _nonstatic_field_size = -1; 105 _has_nonstatic_fields = false; 106 _nonstatic_fields = NULL; // initialized lazily by compute_nonstatic_fields 107 _nof_declared_nonstatic_fields = -1; // initialized lazily by compute_nonstatic_fields 108 _has_injected_fields = -1; 109 _is_anonymous = false; 110 _loader = loader; 111 _protection_domain = protection_domain; 112 _is_shared = false; 113 _super = NULL; 114 _java_mirror = NULL; 115 _field_cache = NULL; 116 } 117 118 119 120 // ------------------------------------------------------------------ 121 // ciInstanceKlass::compute_shared_is_initialized 122 void ciInstanceKlass::compute_shared_init_state() { 123 GUARDED_VM_ENTRY( 124 InstanceKlass* ik = get_instanceKlass(); 125 _init_state = ik->init_state(); 126 ) 127 } 128 129 // ------------------------------------------------------------------ 130 // ciInstanceKlass::compute_shared_has_subklass 131 bool ciInstanceKlass::compute_shared_has_subklass() { 132 GUARDED_VM_ENTRY( 133 InstanceKlass* ik = get_instanceKlass(); 134 _has_subklass = ik->subklass() != NULL; 135 return _has_subklass; 136 ) 137 } 138 139 // ------------------------------------------------------------------ 140 // ciInstanceKlass::loader 141 oop ciInstanceKlass::loader() { 142 ASSERT_IN_VM; 143 return JNIHandles::resolve(_loader); 144 } 145 629 if (impl == NULL) { 630 // Go into the VM to fetch the implementor. 631 { 632 VM_ENTRY_MARK; 633 Klass* k = get_instanceKlass()->implementor(); 634 if (k != NULL) { 635 if (k == get_instanceKlass()) { 636 // More than one implementors. Use 'this' in this case. 637 impl = this; 638 } else { 639 impl = CURRENT_THREAD_ENV->get_instance_klass(k); 640 } 641 } 642 } 643 // Memoize this result. 644 if (!is_shared()) { 645 _implementor = impl; 646 } 647 } 648 return impl; 649 } 650 651 // Utility class for printing of the contents of the static fields for 652 // use by compilation replay. It only prints out the information that 653 // could be consumed by the compiler, so for primitive types it prints 654 // out the actual value. For Strings it's the actual string value. 655 // For array types it it's first level array size since that's the 656 // only value which statically unchangeable. For all other reference 657 // types it simply prints out the dynamic type. 658 659 class StaticFieldPrinter : public FieldClosure { 660 protected: 661 outputStream* _out; 662 public: 663 StaticFieldPrinter(outputStream* out) : 664 _out(out) { 665 } 666 void do_field_helper(fieldDescriptor* fd, oop obj, bool flattened); 667 }; 668 | 47 // Loaded instance klass. 48 ciInstanceKlass::ciInstanceKlass(KlassHandle h_k) : 49 ciKlass(h_k) 50 { 51 assert(get_Klass()->is_instance_klass(), "wrong type"); 52 assert(get_instanceKlass()->is_loaded(), "must be at least loaded"); 53 InstanceKlass* ik = get_instanceKlass(); 54 55 AccessFlags access_flags = ik->access_flags(); 56 _flags = ciFlags(access_flags); 57 _has_finalizer = access_flags.has_finalizer(); 58 _has_subklass = ik->subklass() != NULL; 59 _init_state = ik->init_state(); 60 _nonstatic_field_size = ik->nonstatic_field_size(); 61 _has_nonstatic_fields = ik->has_nonstatic_fields(); 62 _has_default_methods = ik->has_default_methods(); 63 _is_anonymous = ik->is_anonymous(); 64 _nonstatic_fields = NULL; // initialized lazily by compute_nonstatic_fields 65 _nof_declared_nonstatic_fields = -1; // initialized lazily by compute_nonstatic_fields 66 _has_injected_fields = -1; 67 _has_derive_value_type = ik->is_derive_value_type() ? true : false; 68 _derive_value_type = NULL; 69 _implementor = NULL; // we will fill these lazily 70 71 Thread *thread = Thread::current(); 72 if (ciObjectFactory::is_initialized()) { 73 _loader = JNIHandles::make_local(thread, ik->class_loader()); 74 _protection_domain = JNIHandles::make_local(thread, 75 ik->protection_domain()); 76 _is_shared = false; 77 } else { 78 Handle h_loader(thread, ik->class_loader()); 79 Handle h_protection_domain(thread, ik->protection_domain()); 80 _loader = JNIHandles::make_global(h_loader); 81 _protection_domain = JNIHandles::make_global(h_protection_domain); 82 _is_shared = true; 83 } 84 85 // Lazy fields get filled in only upon request. 86 _super = NULL; 87 _java_mirror = NULL; 88 91 super(); 92 } 93 //compute_nonstatic_fields(); // done outside of constructor 94 } 95 96 _field_cache = NULL; 97 } 98 99 // Version for unloaded classes: 100 ciInstanceKlass::ciInstanceKlass(ciSymbol* name, 101 jobject loader, jobject protection_domain) 102 : ciKlass(name, T_OBJECT) 103 { 104 assert(name->byte_at(0) != '[', "not an instance klass"); 105 _init_state = (InstanceKlass::ClassState)0; 106 _nonstatic_field_size = -1; 107 _has_nonstatic_fields = false; 108 _nonstatic_fields = NULL; // initialized lazily by compute_nonstatic_fields 109 _nof_declared_nonstatic_fields = -1; // initialized lazily by compute_nonstatic_fields 110 _has_injected_fields = -1; 111 _has_derive_value_type = false; // When the class is loaded, the system checks if the loaded class 112 // has a derived value type (and sets the flag accordingly). 113 // TODO: Check if updating flag works properly (e.g., also in 114 // scenarios with concurrent accesses). 115 _derive_value_type = NULL; 116 _is_anonymous = false; 117 _loader = loader; 118 _protection_domain = protection_domain; 119 _is_shared = false; 120 _super = NULL; 121 _java_mirror = NULL; 122 _field_cache = NULL; 123 } 124 125 126 127 // ------------------------------------------------------------------ 128 // ciInstanceKlass::compute_shared_is_initialized 129 void ciInstanceKlass::compute_shared_init_state() { 130 GUARDED_VM_ENTRY( 131 InstanceKlass* ik = get_instanceKlass(); 132 _init_state = ik->init_state(); 133 if (ik->is_derive_value_type()) { 134 // When the class is loaded, the system checks if the loaded class 135 // has a derived value type (and sets the flag accordingly). 136 _has_derive_value_type = true; 137 } 138 ) 139 } 140 141 // ------------------------------------------------------------------ 142 // ciInstanceKlass::compute_shared_has_subklass 143 bool ciInstanceKlass::compute_shared_has_subklass() { 144 GUARDED_VM_ENTRY( 145 InstanceKlass* ik = get_instanceKlass(); 146 _has_subklass = ik->subklass() != NULL; 147 return _has_subklass; 148 ) 149 } 150 151 // ------------------------------------------------------------------ 152 // ciInstanceKlass::loader 153 oop ciInstanceKlass::loader() { 154 ASSERT_IN_VM; 155 return JNIHandles::resolve(_loader); 156 } 157 641 if (impl == NULL) { 642 // Go into the VM to fetch the implementor. 643 { 644 VM_ENTRY_MARK; 645 Klass* k = get_instanceKlass()->implementor(); 646 if (k != NULL) { 647 if (k == get_instanceKlass()) { 648 // More than one implementors. Use 'this' in this case. 649 impl = this; 650 } else { 651 impl = CURRENT_THREAD_ENV->get_instance_klass(k); 652 } 653 } 654 } 655 // Memoize this result. 656 if (!is_shared()) { 657 _implementor = impl; 658 } 659 } 660 return impl; 661 } 662 663 ciInstanceKlass* ciInstanceKlass::derive_value_type() { 664 if (_has_derive_value_type) { 665 // The _had_derive_value_type flag is updated when the class is loaded. Then, 666 // the derived value type is also linked. 667 if (_derive_value_type == NULL) { 668 VM_ENTRY_MARK; 669 InstanceKlass* k = get_instanceKlass()->derive_value_type_klass(); 670 _derive_value_type = CURRENT_THREAD_ENV->get_instance_klass(k); 671 } 672 return _derive_value_type; 673 } else { 674 return NULL; 675 } 676 } 677 678 // Utility class for printing of the contents of the static fields for 679 // use by compilation replay. It only prints out the information that 680 // could be consumed by the compiler, so for primitive types it prints 681 // out the actual value. For Strings it's the actual string value. 682 // For array types it it's first level array size since that's the 683 // only value which statically unchangeable. For all other reference 684 // types it simply prints out the dynamic type. 685 686 class StaticFieldPrinter : public FieldClosure { 687 protected: 688 outputStream* _out; 689 public: 690 StaticFieldPrinter(outputStream* out) : 691 _out(out) { 692 } 693 void do_field_helper(fieldDescriptor* fd, oop obj, bool flattened); 694 }; 695 |