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 *
23 */
24
25 #include "compiler/compileLog.hpp"
26 #include "interpreter/linkResolver.hpp"
27 #include "memory/universe.hpp"
28 #include "oops/objArrayKlass.hpp"
29 #include "opto/addnode.hpp"
30 #include "opto/castnode.hpp"
31 #include "opto/memnode.hpp"
32 #include "opto/parse.hpp"
33 #include "opto/rootnode.hpp"
34 #include "opto/runtime.hpp"
35 #include "opto/subnode.hpp"
36 #include "runtime/deoptimization.hpp"
37 #include "runtime/handles.inline.hpp"
38
39 //=============================================================================
40 // Helper methods for _get* and _put* bytecodes
41 //=============================================================================
42 void Parse::do_field_access(bool is_get, bool is_field) {
43 bool will_link;
44 ciField* field = iter().get_field(will_link);
45 assert(will_link, "getfield: typeflow responsibility");
46
47 ciInstanceKlass* field_holder = field->holder();
48
49 if (is_field == field->is_static()) {
50 // Interpreter will throw java_lang_IncompatibleClassChangeError
51 // Check this before allowing <clinit> methods to access static fields
52 uncommon_trap(Deoptimization::Reason_unhandled,
53 Deoptimization::Action_none);
54 return;
55 }
56
57 // Deoptimize on putfield writes to call site target field outside of CallSite ctor.
58 if (!is_get && field->is_call_site_target() &&
59 !(method()->holder() == field_holder && method()->is_object_initializer())) {
60 uncommon_trap(Deoptimization::Reason_unhandled,
61 Deoptimization::Action_reinterpret,
62 nullptr, "put to call site target field");
63 return;
64 }
65
66 if (C->needs_clinit_barrier(field, method())) {
67 clinit_barrier(field_holder, method());
68 if (stopped()) return;
69 }
70
71 assert(field->will_link(method(), bc()), "getfield: typeflow responsibility");
72
73 // Note: We do not check for an unloaded field type here any more.
74
75 // Generate code for the object pointer.
76 Node* obj;
77 if (is_field) {
78 int obj_depth = is_get ? 0 : field->type()->size();
79 obj = null_check(peek(obj_depth));
80 // Compile-time detect of null-exception?
81 if (stopped()) return;
82
83 #ifdef ASSERT
84 const TypeInstPtr *tjp = TypeInstPtr::make(TypePtr::NotNull, iter().get_declared_field_holder());
85 assert(_gvn.type(obj)->higher_equal(tjp), "cast_up is no longer needed");
86 #endif
87
88 if (is_get) {
89 (void) pop(); // pop receiver before getting
90 do_get_xxx(obj, field, is_field);
91 } else {
92 do_put_xxx(obj, field, is_field);
93 (void) pop(); // pop receiver after putting
94 }
95 } else {
96 const TypeInstPtr* tip = TypeInstPtr::make(field_holder->java_mirror());
97 obj = _gvn.makecon(tip);
98 if (is_get) {
99 do_get_xxx(obj, field, is_field);
100 } else {
101 do_put_xxx(obj, field, is_field);
102 }
103 }
104 }
105
106
107 void Parse::do_get_xxx(Node* obj, ciField* field, bool is_field) {
108 BasicType bt = field->layout_type();
109
110 // Does this field have a constant value? If so, just push the value.
111 if (field->is_constant() &&
112 // Keep consistent with types found by ciTypeFlow: for an
113 // unloaded field type, ciTypeFlow::StateVector::do_getstatic()
114 // speculates the field is null. The code in the rest of this
115 // method does the same. We must not bypass it and use a non
116 // null constant here.
117 (bt != T_OBJECT || field->type()->is_loaded())) {
118 // final or stable field
119 Node* con = make_constant_from_field(field, obj);
120 if (con != nullptr) {
121 push_node(field->layout_type(), con);
122 return;
123 }
124 }
125
126 ciType* field_klass = field->type();
127 bool is_vol = field->is_volatile();
128
129 // Compute address and memory type.
130 int offset = field->offset_in_bytes();
131 const TypePtr* adr_type = C->alias_type(field)->adr_type();
132 Node *adr = basic_plus_adr(obj, obj, offset);
133 assert(C->get_alias_index(adr_type) == C->get_alias_index(_gvn.type(adr)->isa_ptr()),
134 "slice of address and input slice don't match");
135
136 // Build the resultant type of the load
137 const Type *type;
138
139 bool must_assert_null = false;
140
141 DecoratorSet decorators = IN_HEAP;
142 decorators |= is_vol ? MO_SEQ_CST : MO_UNORDERED;
143
144 bool is_obj = is_reference_type(bt);
145
146 if (is_obj) {
147 if (!field->type()->is_loaded()) {
148 type = TypeInstPtr::BOTTOM;
149 must_assert_null = true;
150 } else if (field->is_static_constant()) {
151 // This can happen if the constant oop is non-perm.
152 ciObject* con = field->constant_value().as_object();
153 // Do not "join" in the previous type; it doesn't add value,
154 // and may yield a vacuous result if the field is of interface type.
155 if (con->is_null_object()) {
156 type = TypePtr::NULL_PTR;
157 } else {
158 type = TypeOopPtr::make_from_constant(con)->isa_oopptr();
159 }
160 assert(type != nullptr, "field singleton type must be consistent");
161 } else {
162 type = TypeOopPtr::make_from_klass(field_klass->as_klass());
163 }
164 } else {
165 type = Type::get_const_basic_type(bt);
166 }
167
168 Node* ld = access_load_at(obj, adr, adr_type, type, bt, decorators);
169
170 // Adjust Java stack
171 if (type2size[bt] == 1)
172 push(ld);
173 else
174 push_pair(ld);
175
176 if (must_assert_null) {
177 // Do not take a trap here. It's possible that the program
178 // will never load the field's class, and will happily see
179 // null values in this field forever. Don't stumble into a
180 // trap for such a program, or we might get a long series
181 // of useless recompilations. (Or, we might load a class
182 // which should not be loaded.) If we ever see a non-null
183 // value, we will then trap and recompile. (The trap will
184 // not need to mention the class index, since the class will
185 // already have been loaded if we ever see a non-null value.)
186 // uncommon_trap(iter().get_field_signature_index());
187 if (PrintOpto && (Verbose || WizardMode)) {
188 method()->print_name(); tty->print_cr(" asserting nullness of field at bci: %d", bci());
189 }
190 if (C->log() != nullptr) {
191 C->log()->elem("assert_null reason='field' klass='%d'",
192 C->log()->identify(field->type()));
193 }
194 // If there is going to be a trap, put it at the next bytecode:
195 set_bci(iter().next_bci());
196 null_assert(peek());
197 set_bci(iter().cur_bci()); // put it back
198 }
199 }
200
201 void Parse::do_put_xxx(Node* obj, ciField* field, bool is_field) {
202 bool is_vol = field->is_volatile();
203
204 // Compute address and memory type.
205 int offset = field->offset_in_bytes();
206 const TypePtr* adr_type = C->alias_type(field)->adr_type();
207 Node* adr = basic_plus_adr(obj, obj, offset);
208 assert(C->get_alias_index(adr_type) == C->get_alias_index(_gvn.type(adr)->isa_ptr()),
209 "slice of address and input slice don't match");
210 BasicType bt = field->layout_type();
211 // Value to be stored
212 Node* val = type2size[bt] == 1 ? pop() : pop_pair();
213
214 DecoratorSet decorators = IN_HEAP;
215 decorators |= is_vol ? MO_SEQ_CST : MO_UNORDERED;
216
217 bool is_obj = is_reference_type(bt);
218
219 // Store the value.
220 const Type* field_type;
221 if (!field->type()->is_loaded()) {
222 field_type = TypeInstPtr::BOTTOM;
223 } else {
224 if (is_obj) {
225 field_type = TypeOopPtr::make_from_klass(field->type()->as_klass());
226 } else {
227 field_type = Type::BOTTOM;
228 }
229 }
230 access_store_at(obj, adr, adr_type, val, field_type, bt, decorators);
231
232 if (is_field) {
233 // Remember we wrote a volatile field.
234 // For not multiple copy atomic cpu (ppc64) a barrier should be issued
235 // in constructors which have such stores. See do_exits() in parse1.cpp.
236 if (is_vol) {
237 set_wrote_volatile(true);
238 }
239 set_wrote_fields(true);
240
241 // If the field is final, the rules of Java say we are in <init> or <clinit>.
242 // If the field is @Stable, we can be in any method, but we only care about
243 // constructors at this point.
244 //
245 // Note the presence of writes to final/@Stable non-static fields, so that we
246 // can insert a memory barrier later on to keep the writes from floating
247 // out of the constructor.
248 if (field->is_final() || field->is_stable()) {
249 if (field->is_final()) {
250 set_wrote_final(true);
251 }
252 if (field->is_stable()) {
253 set_wrote_stable(true);
254 }
255 if (AllocateNode::Ideal_allocation(obj) != nullptr) {
256 // Preserve allocation ptr to create precedent edge to it in membar
257 // generated on exit from constructor.
258 set_alloc_with_final_or_stable(obj);
259 }
260 }
261 }
262 }
263
264 //=============================================================================
265 void Parse::do_anewarray() {
266 bool will_link;
267 ciKlass* klass = iter().get_klass(will_link);
268
269 // Uncommon Trap when class that array contains is not loaded
270 // we need the loaded class for the rest of graph; do not
271 // initialize the container class (see Java spec)!!!
272 assert(will_link, "anewarray: typeflow responsibility");
273
274 ciObjArrayKlass* array_klass = ciObjArrayKlass::make(klass);
275 // Check that array_klass object is loaded
276 if (!array_klass->is_loaded()) {
277 // Generate uncommon_trap for unloaded array_class
278 uncommon_trap(Deoptimization::Reason_unloaded,
279 Deoptimization::Action_reinterpret,
280 array_klass);
281 return;
282 }
283
284 kill_dead_locals();
285
286 const TypeKlassPtr* array_klass_type = TypeKlassPtr::make(array_klass, Type::trust_interfaces);
287 Node* count_val = pop();
288 Node* obj = new_array(makecon(array_klass_type), count_val, 1);
289 push(obj);
290 }
291
292
293 void Parse::do_newarray(BasicType elem_type) {
294 kill_dead_locals();
295
296 Node* count_val = pop();
297 const TypeKlassPtr* array_klass = TypeKlassPtr::make(ciTypeArrayKlass::make(elem_type));
298 Node* obj = new_array(makecon(array_klass), count_val, 1);
299 // Push resultant oop onto stack
300 push(obj);
301 }
322 }
323 return array;
324 }
325
326 void Parse::do_multianewarray() {
327 int ndimensions = iter().get_dimensions();
328
329 // the m-dimensional array
330 bool will_link;
331 ciArrayKlass* array_klass = iter().get_klass(will_link)->as_array_klass();
332 assert(will_link, "multianewarray: typeflow responsibility");
333
334 // Note: Array classes are always initialized; no is_initialized check.
335
336 kill_dead_locals();
337
338 // get the lengths from the stack (first dimension is on top)
339 Node** length = NEW_RESOURCE_ARRAY(Node*, ndimensions + 1);
340 length[ndimensions] = nullptr; // terminating null for make_runtime_call
341 int j;
342 for (j = ndimensions-1; j >= 0 ; j--) length[j] = pop();
343
344 // The original expression was of this form: new T[length0][length1]...
345 // It is often the case that the lengths are small (except the last).
346 // If that happens, use the fast 1-d creator a constant number of times.
347 const int expand_limit = MIN2((int)MultiArrayExpandLimit, 100);
348 int64_t expand_count = 1; // count of allocations in the expansion
349 int64_t expand_fanout = 1; // running total fanout
350 for (j = 0; j < ndimensions-1; j++) {
351 int dim_con = find_int_con(length[j], -1);
352 // To prevent overflow, we use 64-bit values. Alternatively,
353 // we could clamp dim_con like so:
354 // dim_con = MIN2(dim_con, expand_limit);
355 expand_fanout *= dim_con;
356 expand_count += expand_fanout; // count the level-J sub-arrays
357 if (dim_con <= 0
358 || dim_con > expand_limit
359 || expand_count > expand_limit) {
360 expand_count = 0;
361 break;
362 }
|
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 *
23 */
24
25 #include "compiler/compileLog.hpp"
26 #include "interpreter/linkResolver.hpp"
27 #include "memory/universe.hpp"
28 #include "oops/flatArrayKlass.hpp"
29 #include "oops/objArrayKlass.hpp"
30 #include "opto/addnode.hpp"
31 #include "opto/castnode.hpp"
32 #include "opto/inlinetypenode.hpp"
33 #include "opto/memnode.hpp"
34 #include "opto/parse.hpp"
35 #include "opto/rootnode.hpp"
36 #include "opto/runtime.hpp"
37 #include "opto/subnode.hpp"
38 #include "runtime/deoptimization.hpp"
39 #include "runtime/handles.inline.hpp"
40
41 //=============================================================================
42 // Helper methods for _get* and _put* bytecodes
43 //=============================================================================
44
45 void Parse::do_field_access(bool is_get, bool is_field) {
46 bool will_link;
47 ciField* field = iter().get_field(will_link);
48 assert(will_link, "getfield: typeflow responsibility");
49
50 ciInstanceKlass* field_holder = field->holder();
51
52 if (is_get && is_field && field_holder->is_inlinetype() && peek()->is_InlineType()) {
53 InlineTypeNode* vt = peek()->as_InlineType();
54 null_check(vt);
55 Node* value = vt->field_value_by_offset(field->offset_in_bytes());
56 if (value->is_InlineType()) {
57 value = value->as_InlineType()->adjust_scalarization_depth(this);
58 }
59 pop();
60 push_node(field->layout_type(), value);
61 return;
62 }
63
64 if (is_field == field->is_static()) {
65 // Interpreter will throw java_lang_IncompatibleClassChangeError
66 // Check this before allowing <clinit> methods to access static fields
67 uncommon_trap(Deoptimization::Reason_unhandled,
68 Deoptimization::Action_none);
69 return;
70 }
71
72 // Deoptimize on putfield writes to call site target field outside of CallSite ctor.
73 if (!is_get && field->is_call_site_target() &&
74 !(method()->holder() == field_holder && method()->is_object_constructor())) {
75 uncommon_trap(Deoptimization::Reason_unhandled,
76 Deoptimization::Action_reinterpret,
77 nullptr, "put to call site target field");
78 return;
79 }
80
81 if (C->needs_clinit_barrier(field, method())) {
82 clinit_barrier(field_holder, method());
83 if (stopped()) return;
84 }
85
86 assert(field->will_link(method(), bc()), "getfield: typeflow responsibility");
87
88 // Note: We do not check for an unloaded field type here any more.
89
90 // Generate code for the object pointer.
91 Node* obj;
92 if (is_field) {
93 int obj_depth = is_get ? 0 : field->type()->size();
94 obj = null_check(peek(obj_depth));
95 // Compile-time detect of null-exception?
96 if (stopped()) return;
97
98 #ifdef ASSERT
99 const TypeInstPtr *tjp = TypeInstPtr::make(TypePtr::NotNull, iter().get_declared_field_holder());
100 assert(_gvn.type(obj)->higher_equal(tjp), "cast_up is no longer needed");
101 #endif
102
103 if (is_get) {
104 (void) pop(); // pop receiver before getting
105 do_get_xxx(obj, field);
106 } else {
107 do_put_xxx(obj, field, is_field);
108 if (stopped()) {
109 return;
110 }
111 (void) pop(); // pop receiver after putting
112 }
113 } else {
114 const TypeInstPtr* tip = TypeInstPtr::make(field_holder->java_mirror());
115 obj = _gvn.makecon(tip);
116 if (is_get) {
117 do_get_xxx(obj, field);
118 } else {
119 do_put_xxx(obj, field, is_field);
120 }
121 }
122 }
123
124 void Parse::do_get_xxx(Node* obj, ciField* field) {
125 BasicType bt = field->layout_type();
126 // Does this field have a constant value? If so, just push the value.
127 if (field->is_constant() && !field->is_flat() &&
128 // Keep consistent with types found by ciTypeFlow: for an
129 // unloaded field type, ciTypeFlow::StateVector::do_getstatic()
130 // speculates the field is null. The code in the rest of this
131 // method does the same. We must not bypass it and use a non
132 // null constant here.
133 (bt != T_OBJECT || field->type()->is_loaded())) {
134 // final or stable field
135 Node* con = make_constant_from_field(field, obj);
136 if (con != nullptr) {
137 push_node(field->layout_type(), con);
138 return;
139 }
140 }
141
142 ciType* field_klass = field->type();
143 field_klass = improve_abstract_inline_type_klass(field_klass);
144 int offset = field->offset_in_bytes();
145 bool must_assert_null = false;
146
147 Node* ld = nullptr;
148 if (field->is_null_free() && field_klass->as_inline_klass()->is_empty()) {
149 // Loading from a field of an empty inline type. Just return the default instance.
150 ld = InlineTypeNode::make_default(_gvn, field_klass->as_inline_klass());
151 } else if (field->is_flat()) {
152 // Loading from a flat inline type field.
153 ciInlineKlass* vk = field->type()->as_inline_klass();
154 bool is_naturally_atomic = vk->is_empty() || (field->is_null_free() && vk->nof_declared_nonstatic_fields() == 1);
155 bool needs_atomic_access = (!field->is_null_free() || field->is_volatile()) && !is_naturally_atomic;
156 ld = InlineTypeNode::make_from_flat(this, field_klass->as_inline_klass(), obj, obj, field->holder(), offset, needs_atomic_access, field->null_marker_offset());
157 } else {
158 // Build the resultant type of the load
159 const Type* type;
160 if (is_reference_type(bt)) {
161 if (!field_klass->is_loaded()) {
162 type = TypeInstPtr::BOTTOM;
163 must_assert_null = true;
164 } else if (field->is_static_constant()) {
165 // This can happen if the constant oop is non-perm.
166 ciObject* con = field->constant_value().as_object();
167 // Do not "join" in the previous type; it doesn't add value,
168 // and may yield a vacuous result if the field is of interface type.
169 if (con->is_null_object()) {
170 type = TypePtr::NULL_PTR;
171 } else {
172 type = TypeOopPtr::make_from_constant(con)->isa_oopptr();
173 }
174 assert(type != nullptr, "field singleton type must be consistent");
175 } else {
176 type = TypeOopPtr::make_from_klass(field_klass->as_klass());
177 if (field->is_null_free() && field->is_static()) {
178 // Check if static inline type field is already initialized
179 ciInstance* mirror = field->holder()->java_mirror();
180 ciObject* val = mirror->field_value(field).as_object();
181 if (!val->is_null_object()) {
182 type = type->join_speculative(TypePtr::NOTNULL);
183 }
184 }
185 }
186 } else {
187 type = Type::get_const_basic_type(bt);
188 }
189 Node* adr = basic_plus_adr(obj, obj, offset);
190 const TypePtr* adr_type = C->alias_type(field)->adr_type();
191 DecoratorSet decorators = IN_HEAP;
192 decorators |= field->is_volatile() ? MO_SEQ_CST : MO_UNORDERED;
193 ld = access_load_at(obj, adr, adr_type, type, bt, decorators);
194 if (field_klass->is_inlinetype()) {
195 // Load a non-flattened inline type from memory
196 ld = InlineTypeNode::make_from_oop(this, ld, field_klass->as_inline_klass(), field->is_null_free());
197 }
198 }
199
200 // Adjust Java stack
201 if (type2size[bt] == 1)
202 push(ld);
203 else
204 push_pair(ld);
205
206 if (must_assert_null) {
207 // Do not take a trap here. It's possible that the program
208 // will never load the field's class, and will happily see
209 // null values in this field forever. Don't stumble into a
210 // trap for such a program, or we might get a long series
211 // of useless recompilations. (Or, we might load a class
212 // which should not be loaded.) If we ever see a non-null
213 // value, we will then trap and recompile. (The trap will
214 // not need to mention the class index, since the class will
215 // already have been loaded if we ever see a non-null value.)
216 // uncommon_trap(iter().get_field_signature_index());
217 if (PrintOpto && (Verbose || WizardMode)) {
218 method()->print_name(); tty->print_cr(" asserting nullness of field at bci: %d", bci());
219 }
220 if (C->log() != nullptr) {
221 C->log()->elem("assert_null reason='field' klass='%d'",
222 C->log()->identify(field_klass));
223 }
224 // If there is going to be a trap, put it at the next bytecode:
225 set_bci(iter().next_bci());
226 null_assert(peek());
227 set_bci(iter().cur_bci()); // put it back
228 }
229 }
230
231 // If the field klass is an abstract value klass (for which we do not know the layout, yet), it could have a unique
232 // concrete sub klass for which we have a fixed layout. This allows us to use InlineTypeNodes instead.
233 ciType* Parse::improve_abstract_inline_type_klass(ciType* field_klass) {
234 Dependencies* dependencies = C->dependencies();
235 if (UseUniqueSubclasses && dependencies != nullptr && field_klass->is_instance_klass()) {
236 ciInstanceKlass* instance_klass = field_klass->as_instance_klass();
237 if (instance_klass->is_loaded() && instance_klass->is_abstract_value_klass()) {
238 ciInstanceKlass* sub_klass = instance_klass->unique_concrete_subklass();
239 if (sub_klass != nullptr && sub_klass != field_klass) {
240 field_klass = sub_klass;
241 dependencies->assert_abstract_with_unique_concrete_subtype(instance_klass, sub_klass);
242 }
243 }
244 }
245 return field_klass;
246 }
247
248 void Parse::do_put_xxx(Node* obj, ciField* field, bool is_field) {
249 bool is_vol = field->is_volatile();
250 int offset = field->offset_in_bytes();
251 BasicType bt = field->layout_type();
252 Node* val = type2size[bt] == 1 ? pop() : pop_pair();
253
254 if (field->is_null_free()) {
255 PreserveReexecuteState preexecs(this);
256 jvms()->set_should_reexecute(true);
257 inc_sp(1);
258 val = null_check(val);
259 if (stopped()) {
260 return;
261 }
262 }
263 if (obj->is_InlineType()) {
264 set_inline_type_field(obj, field, val);
265 return;
266 }
267 if (field->is_null_free() && field->type()->as_inline_klass()->is_empty()) {
268 // Storing to a field of an empty inline type. Ignore.
269 return;
270 } else if (field->is_flat()) {
271 // Storing to a flat inline type field.
272 ciInlineKlass* vk = field->type()->as_inline_klass();
273 if (!val->is_InlineType()) {
274 val = InlineTypeNode::make_from_oop(this, val, vk, field->is_null_free());
275 }
276 inc_sp(1);
277 bool is_naturally_atomic = vk->is_empty() || (field->is_null_free() && vk->nof_declared_nonstatic_fields() == 1);
278 bool needs_atomic_access = (!field->is_null_free() || field->is_volatile()) && !is_naturally_atomic;
279 val->as_InlineType()->store_flat(this, obj, obj, field->holder(), offset, needs_atomic_access, field->null_marker_offset(), IN_HEAP | MO_UNORDERED);
280 dec_sp(1);
281 } else {
282 // Store the value.
283 const Type* field_type;
284 if (!field->type()->is_loaded()) {
285 field_type = TypeInstPtr::BOTTOM;
286 } else {
287 if (is_reference_type(bt)) {
288 field_type = TypeOopPtr::make_from_klass(field->type()->as_klass());
289 } else {
290 field_type = Type::BOTTOM;
291 }
292 }
293 Node* adr = basic_plus_adr(obj, obj, offset);
294 const TypePtr* adr_type = C->alias_type(field)->adr_type();
295 DecoratorSet decorators = IN_HEAP;
296 decorators |= is_vol ? MO_SEQ_CST : MO_UNORDERED;
297 inc_sp(1);
298 access_store_at(obj, adr, adr_type, val, field_type, bt, decorators);
299 dec_sp(1);
300 }
301
302 if (is_field) {
303 // Remember we wrote a volatile field.
304 // For not multiple copy atomic cpu (ppc64) a barrier should be issued
305 // in constructors which have such stores. See do_exits() in parse1.cpp.
306 if (is_vol) {
307 set_wrote_volatile(true);
308 }
309 set_wrote_fields(true);
310
311 // If the field is final, the rules of Java say we are in <init> or <clinit>.
312 // If the field is @Stable, we can be in any method, but we only care about
313 // constructors at this point.
314 //
315 // Note the presence of writes to final/@Stable non-static fields, so that we
316 // can insert a memory barrier later on to keep the writes from floating
317 // out of the constructor.
318 if (field->is_final() || field->is_stable()) {
319 if (field->is_final()) {
320 set_wrote_final(true);
321 }
322 if (field->is_stable()) {
323 set_wrote_stable(true);
324 }
325 if (AllocateNode::Ideal_allocation(obj) != nullptr) {
326 // Preserve allocation ptr to create precedent edge to it in membar
327 // generated on exit from constructor.
328 set_alloc_with_final_or_stable(obj);
329 }
330 }
331 }
332 }
333
334 void Parse::set_inline_type_field(Node* obj, ciField* field, Node* val) {
335 assert(_method->is_object_constructor(), "inline type is initialized outside of constructor");
336 assert(obj->as_InlineType()->is_larval(), "must be larval");
337 assert(!_gvn.type(obj)->maybe_null(), "should never be null");
338
339 // Re-execute if buffering in below code triggers deoptimization.
340 PreserveReexecuteState preexecs(this);
341 jvms()->set_should_reexecute(true);
342 inc_sp(1);
343
344 if (!val->is_InlineType() && field->type()->is_inlinetype()) {
345 // Scalarize inline type field value
346 val = InlineTypeNode::make_from_oop(this, val, field->type()->as_inline_klass(), field->is_null_free());
347 } else if (val->is_InlineType() && !field->is_flat()) {
348 // Field value needs to be allocated because it can be merged with a non-inline type.
349 val = val->as_InlineType()->buffer(this);
350 }
351
352 // Clone the inline type node and set the new field value
353 InlineTypeNode* new_vt = obj->as_InlineType()->clone_if_required(&_gvn, _map);
354 new_vt->set_field_value_by_offset(field->offset_in_bytes(), val);
355 new_vt = new_vt->adjust_scalarization_depth(this);
356
357 // If the inline type is buffered and the caller might use the buffer, update it.
358 if (new_vt->is_allocated(&gvn()) && (!_caller->has_method() || C->inlining_incrementally() || _caller->method()->is_object_constructor())) {
359 new_vt->store(this, new_vt->get_oop(), new_vt->get_oop(), new_vt->bottom_type()->inline_klass(), 0, field->offset_in_bytes());
360
361 // Preserve allocation ptr to create precedent edge to it in membar
362 // generated on exit from constructor.
363 AllocateNode* alloc = AllocateNode::Ideal_allocation(new_vt->get_oop());
364 if (alloc != nullptr) {
365 set_alloc_with_final_or_stable(new_vt->get_oop());
366 }
367 set_wrote_final(true);
368 }
369
370 replace_in_map(obj, _gvn.transform(new_vt));
371 return;
372 }
373
374 //=============================================================================
375
376 void Parse::do_newarray() {
377 bool will_link;
378 ciKlass* klass = iter().get_klass(will_link);
379
380 // Uncommon Trap when class that array contains is not loaded
381 // we need the loaded class for the rest of graph; do not
382 // initialize the container class (see Java spec)!!!
383 assert(will_link, "newarray: typeflow responsibility");
384
385 ciArrayKlass* array_klass = ciArrayKlass::make(klass);
386
387 // Check that array_klass object is loaded
388 if (!array_klass->is_loaded()) {
389 // Generate uncommon_trap for unloaded array_class
390 uncommon_trap(Deoptimization::Reason_unloaded,
391 Deoptimization::Action_reinterpret,
392 array_klass);
393 return;
394 } else if (array_klass->element_klass() != nullptr &&
395 array_klass->element_klass()->is_inlinetype() &&
396 !array_klass->element_klass()->as_inline_klass()->is_initialized()) {
397 uncommon_trap(Deoptimization::Reason_uninitialized,
398 Deoptimization::Action_reinterpret,
399 nullptr);
400 return;
401 }
402
403 kill_dead_locals();
404
405 const TypeKlassPtr* array_klass_type = TypeKlassPtr::make(array_klass, Type::trust_interfaces);
406 Node* count_val = pop();
407 Node* obj = new_array(makecon(array_klass_type), count_val, 1);
408 push(obj);
409 }
410
411
412 void Parse::do_newarray(BasicType elem_type) {
413 kill_dead_locals();
414
415 Node* count_val = pop();
416 const TypeKlassPtr* array_klass = TypeKlassPtr::make(ciTypeArrayKlass::make(elem_type));
417 Node* obj = new_array(makecon(array_klass), count_val, 1);
418 // Push resultant oop onto stack
419 push(obj);
420 }
441 }
442 return array;
443 }
444
445 void Parse::do_multianewarray() {
446 int ndimensions = iter().get_dimensions();
447
448 // the m-dimensional array
449 bool will_link;
450 ciArrayKlass* array_klass = iter().get_klass(will_link)->as_array_klass();
451 assert(will_link, "multianewarray: typeflow responsibility");
452
453 // Note: Array classes are always initialized; no is_initialized check.
454
455 kill_dead_locals();
456
457 // get the lengths from the stack (first dimension is on top)
458 Node** length = NEW_RESOURCE_ARRAY(Node*, ndimensions + 1);
459 length[ndimensions] = nullptr; // terminating null for make_runtime_call
460 int j;
461 ciKlass* elem_klass = array_klass;
462 for (j = ndimensions-1; j >= 0; j--) {
463 length[j] = pop();
464 elem_klass = elem_klass->as_array_klass()->element_klass();
465 }
466 if (elem_klass != nullptr && elem_klass->is_inlinetype() && !elem_klass->as_inline_klass()->is_initialized()) {
467 inc_sp(ndimensions);
468 uncommon_trap(Deoptimization::Reason_uninitialized,
469 Deoptimization::Action_reinterpret,
470 nullptr);
471 return;
472 }
473
474 // The original expression was of this form: new T[length0][length1]...
475 // It is often the case that the lengths are small (except the last).
476 // If that happens, use the fast 1-d creator a constant number of times.
477 const int expand_limit = MIN2((int)MultiArrayExpandLimit, 100);
478 int64_t expand_count = 1; // count of allocations in the expansion
479 int64_t expand_fanout = 1; // running total fanout
480 for (j = 0; j < ndimensions-1; j++) {
481 int dim_con = find_int_con(length[j], -1);
482 // To prevent overflow, we use 64-bit values. Alternatively,
483 // we could clamp dim_con like so:
484 // dim_con = MIN2(dim_con, expand_limit);
485 expand_fanout *= dim_con;
486 expand_count += expand_fanout; // count the level-J sub-arrays
487 if (dim_con <= 0
488 || dim_con > expand_limit
489 || expand_count > expand_limit) {
490 expand_count = 0;
491 break;
492 }
|