1 /*
2 * Copyright 1999-2007 Sun Microsystems, Inc. All Rights Reserved.
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 *
69 _cp_index = index;
70 constantPoolHandle cpool(thread, klass->get_instanceKlass()->constants());
71
72 // Get the field's name, signature, and type.
73 symbolHandle name (thread, cpool->name_ref_at(index));
74 _name = ciEnv::current(thread)->get_object(name())->as_symbol();
75
76 int nt_index = cpool->name_and_type_ref_index_at(index);
77 int sig_index = cpool->signature_ref_index_at(nt_index);
78 symbolHandle signature (thread, cpool->symbol_at(sig_index));
79 _signature = ciEnv::current(thread)->get_object(signature())->as_symbol();
80
81 BasicType field_type = FieldType::basic_type(signature());
82
83 // If the field is a pointer type, get the klass of the
84 // field.
85 if (field_type == T_OBJECT || field_type == T_ARRAY) {
86 bool ignore;
87 // This is not really a class reference; the index always refers to the
88 // field's type signature, as a symbol. Linkage checks do not apply.
89 _type = ciEnv::current(thread)->get_klass_by_index(klass, sig_index, ignore);
90 } else {
91 _type = ciType::make(field_type);
92 }
93
94 _name = (ciSymbol*)ciEnv::current(thread)->get_object(name());
95
96 // Get the field's declared holder.
97 //
98 // Note: we actually create a ciInstanceKlass for this klass,
99 // even though we may not need to.
100 int holder_index = cpool->klass_ref_index_at(index);
101 bool holder_is_accessible;
102 ciInstanceKlass* declared_holder =
103 ciEnv::current(thread)->get_klass_by_index(klass, holder_index,
104 holder_is_accessible)
105 ->as_instance_klass();
106
107 // The declared holder of this field may not have been loaded.
108 // Bail out with partial field information.
109 if (!holder_is_accessible) {
110 // _cp_index and _type have already been set.
111 // The default values for _flags and _constant_value will suffice.
112 // We need values for _holder, _offset, and _is_constant,
113 _holder = declared_holder;
114 _offset = -1;
115 _is_constant = false;
116 return;
117 }
118
119 instanceKlass* loaded_decl_holder = declared_holder->get_instanceKlass();
120
121 // Perform the field lookup.
122 fieldDescriptor field_desc;
123 klassOop canonical_holder =
124 loaded_decl_holder->find_field(name(), signature(), &field_desc);
125 if (canonical_holder == NULL) {
151 if (field_type == T_OBJECT || field_type == T_ARRAY) {
152 _type = NULL; // must call compute_type on first access
153 } else {
154 _type = ciType::make(field_type);
155 }
156
157 initialize_from(fd);
158
159 // Either (a) it is marked shared, or else (b) we are done bootstrapping.
160 assert(is_shared() || ciObjectFactory::is_initialized(),
161 "bootstrap classes must not create & cache unshared fields");
162 }
163
164 void ciField::initialize_from(fieldDescriptor* fd) {
165 // Get the flags, offset, and canonical holder of the field.
166 _flags = ciFlags(fd->access_flags());
167 _offset = fd->offset();
168 _holder = CURRENT_ENV->get_object(fd->field_holder())->as_instance_klass();
169
170 // Check to see if the field is constant.
171 if (_holder->is_initialized() &&
172 this->is_final() && this->is_static()) {
173 // This field just may be constant. The only cases where it will
174 // not be constant are:
175 //
176 // 1. The field holds a non-perm-space oop. The field is, strictly
177 // speaking, constant but we cannot embed non-perm-space oops into
178 // generated code. For the time being we need to consider the
179 // field to be not constant.
180 // 2. The field is a *special* static&final field whose value
181 // may change. The three examples are java.lang.System.in,
182 // java.lang.System.out, and java.lang.System.err.
183
184 klassOop k = _holder->get_klassOop();
185 assert( SystemDictionary::system_klass() != NULL, "Check once per vm");
186 if( k == SystemDictionary::system_klass() ) {
187 // Check offsets for case 2: System.in, System.out, or System.err
188 if( _offset == java_lang_System::in_offset_in_bytes() ||
189 _offset == java_lang_System::out_offset_in_bytes() ||
190 _offset == java_lang_System::err_offset_in_bytes() ) {
191 _is_constant = false;
192 return;
|
1 /*
2 * Copyright 1999-2009 Sun Microsystems, Inc. All Rights Reserved.
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 *
69 _cp_index = index;
70 constantPoolHandle cpool(thread, klass->get_instanceKlass()->constants());
71
72 // Get the field's name, signature, and type.
73 symbolHandle name (thread, cpool->name_ref_at(index));
74 _name = ciEnv::current(thread)->get_object(name())->as_symbol();
75
76 int nt_index = cpool->name_and_type_ref_index_at(index);
77 int sig_index = cpool->signature_ref_index_at(nt_index);
78 symbolHandle signature (thread, cpool->symbol_at(sig_index));
79 _signature = ciEnv::current(thread)->get_object(signature())->as_symbol();
80
81 BasicType field_type = FieldType::basic_type(signature());
82
83 // If the field is a pointer type, get the klass of the
84 // field.
85 if (field_type == T_OBJECT || field_type == T_ARRAY) {
86 bool ignore;
87 // This is not really a class reference; the index always refers to the
88 // field's type signature, as a symbol. Linkage checks do not apply.
89 _type = ciEnv::current(thread)->get_klass_by_index(cpool, sig_index, ignore, klass);
90 } else {
91 _type = ciType::make(field_type);
92 }
93
94 _name = (ciSymbol*)ciEnv::current(thread)->get_object(name());
95
96 // Get the field's declared holder.
97 //
98 // Note: we actually create a ciInstanceKlass for this klass,
99 // even though we may not need to.
100 int holder_index = cpool->klass_ref_index_at(index);
101 bool holder_is_accessible;
102 ciInstanceKlass* declared_holder =
103 ciEnv::current(thread)->get_klass_by_index(cpool, holder_index,
104 holder_is_accessible,
105 klass)->as_instance_klass();
106
107 // The declared holder of this field may not have been loaded.
108 // Bail out with partial field information.
109 if (!holder_is_accessible) {
110 // _cp_index and _type have already been set.
111 // The default values for _flags and _constant_value will suffice.
112 // We need values for _holder, _offset, and _is_constant,
113 _holder = declared_holder;
114 _offset = -1;
115 _is_constant = false;
116 return;
117 }
118
119 instanceKlass* loaded_decl_holder = declared_holder->get_instanceKlass();
120
121 // Perform the field lookup.
122 fieldDescriptor field_desc;
123 klassOop canonical_holder =
124 loaded_decl_holder->find_field(name(), signature(), &field_desc);
125 if (canonical_holder == NULL) {
151 if (field_type == T_OBJECT || field_type == T_ARRAY) {
152 _type = NULL; // must call compute_type on first access
153 } else {
154 _type = ciType::make(field_type);
155 }
156
157 initialize_from(fd);
158
159 // Either (a) it is marked shared, or else (b) we are done bootstrapping.
160 assert(is_shared() || ciObjectFactory::is_initialized(),
161 "bootstrap classes must not create & cache unshared fields");
162 }
163
164 void ciField::initialize_from(fieldDescriptor* fd) {
165 // Get the flags, offset, and canonical holder of the field.
166 _flags = ciFlags(fd->access_flags());
167 _offset = fd->offset();
168 _holder = CURRENT_ENV->get_object(fd->field_holder())->as_instance_klass();
169
170 // Check to see if the field is constant.
171 if (_holder->is_initialized() && this->is_final()) {
172 if (!this->is_static()) {
173 // A field can be constant if it's a final static field or if it's
174 // a final non-static field of a trusted class ({java,sun}.dyn).
175 if (_holder->is_in_package("java.dyn") || _holder->is_in_package("sun.dyn")) {
176 _is_constant = true;
177 return;
178 }
179 _is_constant = false;
180 return;
181 }
182
183 // This field just may be constant. The only cases where it will
184 // not be constant are:
185 //
186 // 1. The field holds a non-perm-space oop. The field is, strictly
187 // speaking, constant but we cannot embed non-perm-space oops into
188 // generated code. For the time being we need to consider the
189 // field to be not constant.
190 // 2. The field is a *special* static&final field whose value
191 // may change. The three examples are java.lang.System.in,
192 // java.lang.System.out, and java.lang.System.err.
193
194 klassOop k = _holder->get_klassOop();
195 assert( SystemDictionary::system_klass() != NULL, "Check once per vm");
196 if( k == SystemDictionary::system_klass() ) {
197 // Check offsets for case 2: System.in, System.out, or System.err
198 if( _offset == java_lang_System::in_offset_in_bytes() ||
199 _offset == java_lang_System::out_offset_in_bytes() ||
200 _offset == java_lang_System::err_offset_in_bytes() ) {
201 _is_constant = false;
202 return;
|