1 /*
2 * Copyright (c) 1999, 2018, Oracle and/or its affiliates. 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 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 *
73
74 assert(ciObjectFactory::is_initialized(), "not a shared field");
75
76 assert(klass->get_instanceKlass()->is_linked(), "must be linked before using its constant-pool");
77
78 constantPoolHandle cpool(THREAD, klass->get_instanceKlass()->constants());
79
80 // Get the field's name, signature, and type.
81 Symbol* name = cpool->name_ref_at(index);
82 _name = ciEnv::current(THREAD)->get_symbol(name);
83
84 int nt_index = cpool->name_and_type_ref_index_at(index);
85 int sig_index = cpool->signature_ref_index_at(nt_index);
86 Symbol* signature = cpool->symbol_at(sig_index);
87 _signature = ciEnv::current(THREAD)->get_symbol(signature);
88
89 BasicType field_type = FieldType::basic_type(signature);
90
91 // If the field is a pointer type, get the klass of the
92 // field.
93 if (field_type == T_OBJECT || field_type == T_ARRAY) {
94 bool ignore;
95 // This is not really a class reference; the index always refers to the
96 // field's type signature, as a symbol. Linkage checks do not apply.
97 _type = ciEnv::current(THREAD)->get_klass_by_index(cpool, sig_index, ignore, klass);
98 } else {
99 _type = ciType::make(field_type);
100 }
101
102 _name = (ciSymbol*)ciEnv::current(THREAD)->get_symbol(name);
103
104 // Get the field's declared holder.
105 //
106 // Note: we actually create a ciInstanceKlass for this klass,
107 // even though we may not need to.
108 int holder_index = cpool->klass_ref_index_at(index);
109 bool holder_is_accessible;
110
111 ciKlass* generic_declared_holder = ciEnv::current(THREAD)->get_klass_by_index(cpool, holder_index,
112 holder_is_accessible,
113 klass);
182 return;
183 }
184
185 assert(canonical_holder == field_desc.field_holder(), "just checking");
186 initialize_from(&field_desc);
187 }
188
189 ciField::ciField(fieldDescriptor *fd) :
190 _known_to_link_with_put(NULL), _known_to_link_with_get(NULL) {
191 ASSERT_IN_VM;
192
193 // Get the field's name, signature, and type.
194 ciEnv* env = CURRENT_ENV;
195 _name = env->get_symbol(fd->name());
196 _signature = env->get_symbol(fd->signature());
197
198 BasicType field_type = fd->field_type();
199
200 // If the field is a pointer type, get the klass of the
201 // field.
202 if (field_type == T_OBJECT || field_type == T_ARRAY) {
203 _type = NULL; // must call compute_type on first access
204 } else {
205 _type = ciType::make(field_type);
206 }
207
208 initialize_from(fd);
209
210 // Either (a) it is marked shared, or else (b) we are done bootstrapping.
211 assert(is_shared() || ciObjectFactory::is_initialized(),
212 "bootstrap classes must not create & cache unshared fields");
213 }
214
215 static bool trust_final_non_static_fields(ciInstanceKlass* holder) {
216 if (holder == NULL)
217 return false;
218 if (holder->name() == ciSymbol::java_lang_System())
219 // Never trust strangely unstable finals: System.out, etc.
220 return false;
221 // Even if general trusting is disabled, trust system-built closures in these packages.
222 if (holder->is_in_package("java/lang/invoke") || holder->is_in_package("sun/invoke"))
|
1 /*
2 * Copyright (c) 1999, 2019, Oracle and/or its affiliates. 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 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 *
73
74 assert(ciObjectFactory::is_initialized(), "not a shared field");
75
76 assert(klass->get_instanceKlass()->is_linked(), "must be linked before using its constant-pool");
77
78 constantPoolHandle cpool(THREAD, klass->get_instanceKlass()->constants());
79
80 // Get the field's name, signature, and type.
81 Symbol* name = cpool->name_ref_at(index);
82 _name = ciEnv::current(THREAD)->get_symbol(name);
83
84 int nt_index = cpool->name_and_type_ref_index_at(index);
85 int sig_index = cpool->signature_ref_index_at(nt_index);
86 Symbol* signature = cpool->symbol_at(sig_index);
87 _signature = ciEnv::current(THREAD)->get_symbol(signature);
88
89 BasicType field_type = FieldType::basic_type(signature);
90
91 // If the field is a pointer type, get the klass of the
92 // field.
93 if (is_reference_type(field_type)) {
94 bool ignore;
95 // This is not really a class reference; the index always refers to the
96 // field's type signature, as a symbol. Linkage checks do not apply.
97 _type = ciEnv::current(THREAD)->get_klass_by_index(cpool, sig_index, ignore, klass);
98 } else {
99 _type = ciType::make(field_type);
100 }
101
102 _name = (ciSymbol*)ciEnv::current(THREAD)->get_symbol(name);
103
104 // Get the field's declared holder.
105 //
106 // Note: we actually create a ciInstanceKlass for this klass,
107 // even though we may not need to.
108 int holder_index = cpool->klass_ref_index_at(index);
109 bool holder_is_accessible;
110
111 ciKlass* generic_declared_holder = ciEnv::current(THREAD)->get_klass_by_index(cpool, holder_index,
112 holder_is_accessible,
113 klass);
182 return;
183 }
184
185 assert(canonical_holder == field_desc.field_holder(), "just checking");
186 initialize_from(&field_desc);
187 }
188
189 ciField::ciField(fieldDescriptor *fd) :
190 _known_to_link_with_put(NULL), _known_to_link_with_get(NULL) {
191 ASSERT_IN_VM;
192
193 // Get the field's name, signature, and type.
194 ciEnv* env = CURRENT_ENV;
195 _name = env->get_symbol(fd->name());
196 _signature = env->get_symbol(fd->signature());
197
198 BasicType field_type = fd->field_type();
199
200 // If the field is a pointer type, get the klass of the
201 // field.
202 if (is_reference_type(field_type)) {
203 _type = NULL; // must call compute_type on first access
204 } else {
205 _type = ciType::make(field_type);
206 }
207
208 initialize_from(fd);
209
210 // Either (a) it is marked shared, or else (b) we are done bootstrapping.
211 assert(is_shared() || ciObjectFactory::is_initialized(),
212 "bootstrap classes must not create & cache unshared fields");
213 }
214
215 static bool trust_final_non_static_fields(ciInstanceKlass* holder) {
216 if (holder == NULL)
217 return false;
218 if (holder->name() == ciSymbol::java_lang_System())
219 // Never trust strangely unstable finals: System.out, etc.
220 return false;
221 // Even if general trusting is disabled, trust system-built closures in these packages.
222 if (holder->is_in_package("java/lang/invoke") || holder->is_in_package("sun/invoke"))
|