Print this page
rev 1026 : imported patch indy.compiler.inline.patch
Split |
Close |
Expand all |
Collapse all |
--- old/src/share/vm/opto/parse3.cpp
+++ new/src/share/vm/opto/parse3.cpp
1 1 /*
2 2 * Copyright 1998-2009 Sun Microsystems, Inc. All Rights Reserved.
3 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 4 *
5 5 * This code is free software; you can redistribute it and/or modify it
6 6 * under the terms of the GNU General Public License version 2 only, as
7 7 * published by the Free Software Foundation.
8 8 *
9 9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 12 * version 2 for more details (a copy is included in the LICENSE file that
13 13 * accompanied this code).
14 14 *
15 15 * You should have received a copy of the GNU General Public License version
16 16 * 2 along with this work; if not, write to the Free Software Foundation,
17 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 18 *
19 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 21 * have any questions.
22 22 *
23 23 */
24 24
25 25 #include "incls/_precompiled.incl"
26 26 #include "incls/_parse3.cpp.incl"
27 27
28 28 //=============================================================================
29 29 // Helper methods for _get* and _put* bytecodes
30 30 //=============================================================================
31 31 bool Parse::static_field_ok_in_clinit(ciField *field, ciMethod *method) {
32 32 // Could be the field_holder's <clinit> method, or <clinit> for a subklass.
33 33 // Better to check now than to Deoptimize as soon as we execute
34 34 assert( field->is_static(), "Only check if field is static");
35 35 // is_being_initialized() is too generous. It allows access to statics
36 36 // by threads that are not running the <clinit> before the <clinit> finishes.
37 37 // return field->holder()->is_being_initialized();
38 38
39 39 // The following restriction is correct but conservative.
40 40 // It is also desirable to allow compilation of methods called from <clinit>
41 41 // but this generated code will need to be made safe for execution by
42 42 // other threads, or the transition from interpreted to compiled code would
43 43 // need to be guarded.
44 44 ciInstanceKlass *field_holder = field->holder();
45 45
46 46 bool access_OK = false;
47 47 if (method->holder()->is_subclass_of(field_holder)) {
48 48 if (method->is_static()) {
49 49 if (method->name() == ciSymbol::class_initializer_name()) {
50 50 // OK to access static fields inside initializer
51 51 access_OK = true;
52 52 }
53 53 } else {
54 54 if (method->name() == ciSymbol::object_initializer_name()) {
55 55 // It's also OK to access static fields inside a constructor,
56 56 // because any thread calling the constructor must first have
57 57 // synchronized on the class by executing a '_new' bytecode.
58 58 access_OK = true;
59 59 }
60 60 }
61 61 }
62 62
63 63 return access_OK;
64 64
65 65 }
66 66
67 67
68 68 void Parse::do_field_access(bool is_get, bool is_field) {
69 69 bool will_link;
70 70 ciField* field = iter().get_field(will_link);
71 71 assert(will_link, "getfield: typeflow responsibility");
72 72
73 73 ciInstanceKlass* field_holder = field->holder();
74 74
75 75 if (is_field == field->is_static()) {
76 76 // Interpreter will throw java_lang_IncompatibleClassChangeError
77 77 // Check this before allowing <clinit> methods to access static fields
78 78 uncommon_trap(Deoptimization::Reason_unhandled,
79 79 Deoptimization::Action_none);
80 80 return;
81 81 }
82 82
83 83 if (!is_field && !field_holder->is_initialized()) {
84 84 if (!static_field_ok_in_clinit(field, method())) {
85 85 uncommon_trap(Deoptimization::Reason_uninitialized,
86 86 Deoptimization::Action_reinterpret,
87 87 NULL, "!static_field_ok_in_clinit");
88 88 return;
89 89 }
90 90 }
91 91
92 92 assert(field->will_link(method()->holder(), bc()), "getfield: typeflow responsibility");
93 93
94 94 // Note: We do not check for an unloaded field type here any more.
95 95
96 96 // Generate code for the object pointer.
97 97 Node* obj;
98 98 if (is_field) {
99 99 int obj_depth = is_get ? 0 : field->type()->size();
100 100 obj = do_null_check(peek(obj_depth), T_OBJECT);
101 101 // Compile-time detect of null-exception?
102 102 if (stopped()) return;
103 103
104 104 const TypeInstPtr *tjp = TypeInstPtr::make(TypePtr::NotNull, iter().get_declared_field_holder());
105 105 assert(_gvn.type(obj)->higher_equal(tjp), "cast_up is no longer needed");
106 106
107 107 if (is_get) {
108 108 --_sp; // pop receiver before getting
109 109 do_get_xxx(tjp, obj, field, is_field);
110 110 } else {
111 111 do_put_xxx(tjp, obj, field, is_field);
112 112 --_sp; // pop receiver after putting
113 113 }
114 114 } else {
115 115 const TypeKlassPtr* tkp = TypeKlassPtr::make(field_holder);
116 116 obj = _gvn.makecon(tkp);
117 117 if (is_get) {
↓ open down ↓ |
117 lines elided |
↑ open up ↑ |
118 118 do_get_xxx(tkp, obj, field, is_field);
119 119 } else {
120 120 do_put_xxx(tkp, obj, field, is_field);
121 121 }
122 122 }
123 123 }
124 124
125 125
126 126 void Parse::do_get_xxx(const TypePtr* obj_type, Node* obj, ciField* field, bool is_field) {
127 127 // Does this field have a constant value? If so, just push the value.
128 - if (field->is_constant() && push_constant(field->constant_value())) return;
128 + if (field->is_constant()) {
129 + if (field->is_static()) {
130 + // final static field
131 + if (push_constant(field->constant_value()))
132 + return;
133 + }
134 + else {
135 + // final non-static field of a trusted class ({java,sun}.dyn
136 + // classes).
137 + if (obj->is_Con()) {
138 + const TypeOopPtr* oop_ptr = obj->bottom_type()->isa_oopptr();
139 + ciObject* constant_oop = oop_ptr->const_oop();
140 + ciConstant constant = field->constant_value_of(constant_oop);
141 +
142 + if (push_constant(constant, true))
143 + return;
144 + }
145 + }
146 + }
129 147
130 148 ciType* field_klass = field->type();
131 149 bool is_vol = field->is_volatile();
132 150
133 151 // Compute address and memory type.
134 152 int offset = field->offset_in_bytes();
135 153 const TypePtr* adr_type = C->alias_type(field)->adr_type();
136 154 Node *adr = basic_plus_adr(obj, obj, offset);
137 155 BasicType bt = field->layout_type();
138 156
139 157 // Build the resultant type of the load
140 158 const Type *type;
141 159
142 160 bool must_assert_null = false;
143 161
144 162 if( bt == T_OBJECT ) {
145 163 if (!field->type()->is_loaded()) {
146 164 type = TypeInstPtr::BOTTOM;
147 165 must_assert_null = true;
148 - } else if (field->is_constant()) {
166 + } else if (field->is_constant() && field->is_static()) {
149 167 // This can happen if the constant oop is non-perm.
150 168 ciObject* con = field->constant_value().as_object();
151 169 // Do not "join" in the previous type; it doesn't add value,
152 170 // and may yield a vacuous result if the field is of interface type.
153 171 type = TypeOopPtr::make_from_constant(con)->isa_oopptr();
154 172 assert(type != NULL, "field singleton type must be consistent");
155 173 } else {
156 174 type = TypeOopPtr::make_from_klass(field_klass->as_klass());
157 175 }
158 176 } else {
159 177 type = Type::get_const_basic_type(bt);
160 178 }
161 179 // Build the load.
162 180 Node* ld = make_load(NULL, adr, type, bt, adr_type, is_vol);
163 181
164 182 // Adjust Java stack
165 183 if (type2size[bt] == 1)
166 184 push(ld);
167 185 else
168 186 push_pair(ld);
169 187
170 188 if (must_assert_null) {
171 189 // Do not take a trap here. It's possible that the program
172 190 // will never load the field's class, and will happily see
173 191 // null values in this field forever. Don't stumble into a
174 192 // trap for such a program, or we might get a long series
175 193 // of useless recompilations. (Or, we might load a class
176 194 // which should not be loaded.) If we ever see a non-null
177 195 // value, we will then trap and recompile. (The trap will
178 196 // not need to mention the class index, since the class will
179 197 // already have been loaded if we ever see a non-null value.)
180 198 // uncommon_trap(iter().get_field_signature_index());
181 199 #ifndef PRODUCT
182 200 if (PrintOpto && (Verbose || WizardMode)) {
183 201 method()->print_name(); tty->print_cr(" asserting nullness of field at bci: %d", bci());
184 202 }
185 203 #endif
186 204 if (C->log() != NULL) {
187 205 C->log()->elem("assert_null reason='field' klass='%d'",
188 206 C->log()->identify(field->type()));
189 207 }
190 208 // If there is going to be a trap, put it at the next bytecode:
191 209 set_bci(iter().next_bci());
192 210 do_null_assert(peek(), T_OBJECT);
193 211 set_bci(iter().cur_bci()); // put it back
194 212 }
195 213
196 214 // If reference is volatile, prevent following memory ops from
197 215 // floating up past the volatile read. Also prevents commoning
198 216 // another volatile read.
199 217 if (field->is_volatile()) {
200 218 // Memory barrier includes bogus read of value to force load BEFORE membar
201 219 insert_mem_bar(Op_MemBarAcquire, ld);
202 220 }
203 221 }
204 222
205 223 void Parse::do_put_xxx(const TypePtr* obj_type, Node* obj, ciField* field, bool is_field) {
206 224 bool is_vol = field->is_volatile();
207 225 // If reference is volatile, prevent following memory ops from
208 226 // floating down past the volatile write. Also prevents commoning
209 227 // another volatile read.
210 228 if (is_vol) insert_mem_bar(Op_MemBarRelease);
211 229
212 230 // Compute address and memory type.
213 231 int offset = field->offset_in_bytes();
214 232 const TypePtr* adr_type = C->alias_type(field)->adr_type();
215 233 Node* adr = basic_plus_adr(obj, obj, offset);
216 234 BasicType bt = field->layout_type();
217 235 // Value to be stored
218 236 Node* val = type2size[bt] == 1 ? pop() : pop_pair();
219 237 // Round doubles before storing
220 238 if (bt == T_DOUBLE) val = dstore_rounding(val);
221 239
222 240 // Store the value.
223 241 Node* store;
224 242 if (bt == T_OBJECT) {
225 243 const TypeOopPtr* field_type;
226 244 if (!field->type()->is_loaded()) {
227 245 field_type = TypeInstPtr::BOTTOM;
228 246 } else {
229 247 field_type = TypeOopPtr::make_from_klass(field->type()->as_klass());
230 248 }
231 249 store = store_oop_to_object( control(), obj, adr, adr_type, val, field_type, bt);
232 250 } else {
233 251 store = store_to_memory( control(), adr, val, bt, adr_type, is_vol );
234 252 }
235 253
236 254 // If reference is volatile, prevent following volatiles ops from
237 255 // floating up before the volatile write.
238 256 if (is_vol) {
239 257 // First place the specific membar for THIS volatile index. This first
240 258 // membar is dependent on the store, keeping any other membars generated
241 259 // below from floating up past the store.
242 260 int adr_idx = C->get_alias_index(adr_type);
243 261 insert_mem_bar_volatile(Op_MemBarVolatile, adr_idx);
244 262
245 263 // Now place a membar for AliasIdxBot for the unknown yet-to-be-parsed
246 264 // volatile alias indices. Skip this if the membar is redundant.
247 265 if (adr_idx != Compile::AliasIdxBot) {
248 266 insert_mem_bar_volatile(Op_MemBarVolatile, Compile::AliasIdxBot);
249 267 }
250 268
251 269 // Finally, place alias-index-specific membars for each volatile index
252 270 // that isn't the adr_idx membar. Typically there's only 1 or 2.
253 271 for( int i = Compile::AliasIdxRaw; i < C->num_alias_types(); i++ ) {
254 272 if (i != adr_idx && C->alias_type(i)->is_volatile()) {
255 273 insert_mem_bar_volatile(Op_MemBarVolatile, i);
256 274 }
257 275 }
258 276 }
259 277
260 278 // If the field is final, the rules of Java say we are in <init> or <clinit>.
261 279 // Note the presence of writes to final non-static fields, so that we
262 280 // can insert a memory barrier later on to keep the writes from floating
263 281 // out of the constructor.
264 282 if (is_field && field->is_final()) {
265 283 set_wrote_final(true);
266 284 }
267 285 }
268 286
269 287
270 288 bool Parse::push_constant(ciConstant constant, bool require_constant) {
271 289 switch (constant.basic_type()) {
272 290 case T_BOOLEAN: push( intcon(constant.as_boolean()) ); break;
273 291 case T_INT: push( intcon(constant.as_int()) ); break;
274 292 case T_CHAR: push( intcon(constant.as_char()) ); break;
275 293 case T_BYTE: push( intcon(constant.as_byte()) ); break;
276 294 case T_SHORT: push( intcon(constant.as_short()) ); break;
277 295 case T_FLOAT: push( makecon(TypeF::make(constant.as_float())) ); break;
278 296 case T_DOUBLE: push_pair( makecon(TypeD::make(constant.as_double())) ); break;
279 297 case T_LONG: push_pair( longcon(constant.as_long()) ); break;
280 298 case T_ARRAY:
281 299 case T_OBJECT: {
282 300 // cases:
283 301 // can_be_constant = (oop not scavengable || ScavengeRootsInCode != 0)
284 302 // should_be_constant = (oop not scavengable || ScavengeRootsInCode >= 2)
285 303 // An oop is not scavengable if it is in the perm gen.
286 304 ciObject* oop_constant = constant.as_object();
287 305 if (oop_constant->is_null_object()) {
288 306 push( zerocon(T_OBJECT) );
289 307 break;
290 308 } else if (require_constant || oop_constant->should_be_constant()) {
291 309 push( makecon(TypeOopPtr::make_from_constant(oop_constant, require_constant)) );
292 310 break;
293 311 } else {
294 312 // we cannot inline the oop, but we can use it later to narrow a type
295 313 return false;
296 314 }
297 315 }
298 316 case T_ILLEGAL: {
299 317 // Invalid ciConstant returned due to OutOfMemoryError in the CI
300 318 assert(C->env()->failing(), "otherwise should not see this");
301 319 // These always occur because of object types; we are going to
302 320 // bail out anyway, so make the stack depths match up
303 321 push( zerocon(T_OBJECT) );
304 322 return false;
305 323 }
306 324 default:
307 325 ShouldNotReachHere();
308 326 return false;
309 327 }
310 328
311 329 // success
312 330 return true;
313 331 }
314 332
315 333
316 334
317 335 //=============================================================================
318 336 void Parse::do_anewarray() {
319 337 bool will_link;
320 338 ciKlass* klass = iter().get_klass(will_link);
321 339
322 340 // Uncommon Trap when class that array contains is not loaded
323 341 // we need the loaded class for the rest of graph; do not
324 342 // initialize the container class (see Java spec)!!!
325 343 assert(will_link, "anewarray: typeflow responsibility");
326 344
327 345 ciObjArrayKlass* array_klass = ciObjArrayKlass::make(klass);
328 346 // Check that array_klass object is loaded
329 347 if (!array_klass->is_loaded()) {
330 348 // Generate uncommon_trap for unloaded array_class
331 349 uncommon_trap(Deoptimization::Reason_unloaded,
332 350 Deoptimization::Action_reinterpret,
333 351 array_klass);
334 352 return;
335 353 }
336 354
337 355 kill_dead_locals();
338 356
339 357 const TypeKlassPtr* array_klass_type = TypeKlassPtr::make(array_klass);
340 358 Node* count_val = pop();
341 359 Node* obj = new_array(makecon(array_klass_type), count_val, 1);
342 360 push(obj);
343 361 }
344 362
345 363
346 364 void Parse::do_newarray(BasicType elem_type) {
347 365 kill_dead_locals();
348 366
349 367 Node* count_val = pop();
350 368 const TypeKlassPtr* array_klass = TypeKlassPtr::make(ciTypeArrayKlass::make(elem_type));
351 369 Node* obj = new_array(makecon(array_klass), count_val, 1);
352 370 // Push resultant oop onto stack
353 371 push(obj);
354 372 }
355 373
356 374 // Expand simple expressions like new int[3][5] and new Object[2][nonConLen].
357 375 // Also handle the degenerate 1-dimensional case of anewarray.
358 376 Node* Parse::expand_multianewarray(ciArrayKlass* array_klass, Node* *lengths, int ndimensions, int nargs) {
359 377 Node* length = lengths[0];
360 378 assert(length != NULL, "");
361 379 Node* array = new_array(makecon(TypeKlassPtr::make(array_klass)), length, nargs);
362 380 if (ndimensions > 1) {
363 381 jint length_con = find_int_con(length, -1);
364 382 guarantee(length_con >= 0, "non-constant multianewarray");
365 383 ciArrayKlass* array_klass_1 = array_klass->as_obj_array_klass()->element_klass()->as_array_klass();
366 384 const TypePtr* adr_type = TypeAryPtr::OOPS;
367 385 const TypeOopPtr* elemtype = _gvn.type(array)->is_aryptr()->elem()->make_oopptr();
368 386 const intptr_t header = arrayOopDesc::base_offset_in_bytes(T_OBJECT);
369 387 for (jint i = 0; i < length_con; i++) {
370 388 Node* elem = expand_multianewarray(array_klass_1, &lengths[1], ndimensions-1, nargs);
371 389 intptr_t offset = header + ((intptr_t)i << LogBytesPerHeapOop);
372 390 Node* eaddr = basic_plus_adr(array, offset);
373 391 store_oop_to_array(control(), array, eaddr, adr_type, elem, elemtype, T_OBJECT);
374 392 }
375 393 }
376 394 return array;
377 395 }
378 396
379 397 void Parse::do_multianewarray() {
380 398 int ndimensions = iter().get_dimensions();
381 399
382 400 // the m-dimensional array
383 401 bool will_link;
384 402 ciArrayKlass* array_klass = iter().get_klass(will_link)->as_array_klass();
385 403 assert(will_link, "multianewarray: typeflow responsibility");
386 404
387 405 // Note: Array classes are always initialized; no is_initialized check.
388 406
389 407 enum { MAX_DIMENSION = 5 };
390 408 if (ndimensions > MAX_DIMENSION || ndimensions <= 0) {
391 409 uncommon_trap(Deoptimization::Reason_unhandled,
392 410 Deoptimization::Action_none);
393 411 return;
394 412 }
395 413
396 414 kill_dead_locals();
397 415
398 416 // get the lengths from the stack (first dimension is on top)
399 417 Node* length[MAX_DIMENSION+1];
400 418 length[ndimensions] = NULL; // terminating null for make_runtime_call
401 419 int j;
402 420 for (j = ndimensions-1; j >= 0 ; j--) length[j] = pop();
403 421
404 422 // The original expression was of this form: new T[length0][length1]...
405 423 // It is often the case that the lengths are small (except the last).
406 424 // If that happens, use the fast 1-d creator a constant number of times.
407 425 const jint expand_limit = MIN2((juint)MultiArrayExpandLimit, (juint)100);
408 426 jint expand_count = 1; // count of allocations in the expansion
409 427 jint expand_fanout = 1; // running total fanout
410 428 for (j = 0; j < ndimensions-1; j++) {
411 429 jint dim_con = find_int_con(length[j], -1);
412 430 expand_fanout *= dim_con;
413 431 expand_count += expand_fanout; // count the level-J sub-arrays
414 432 if (dim_con <= 0
415 433 || dim_con > expand_limit
416 434 || expand_count > expand_limit) {
417 435 expand_count = 0;
418 436 break;
419 437 }
420 438 }
421 439
422 440 // Can use multianewarray instead of [a]newarray if only one dimension,
423 441 // or if all non-final dimensions are small constants.
424 442 if (expand_count == 1 || (1 <= expand_count && expand_count <= expand_limit)) {
425 443 Node* obj = expand_multianewarray(array_klass, &length[0], ndimensions, ndimensions);
426 444 push(obj);
427 445 return;
428 446 }
429 447
430 448 address fun = NULL;
431 449 switch (ndimensions) {
432 450 //case 1: Actually, there is no case 1. It's handled by new_array.
433 451 case 2: fun = OptoRuntime::multianewarray2_Java(); break;
434 452 case 3: fun = OptoRuntime::multianewarray3_Java(); break;
435 453 case 4: fun = OptoRuntime::multianewarray4_Java(); break;
436 454 case 5: fun = OptoRuntime::multianewarray5_Java(); break;
437 455 default: ShouldNotReachHere();
438 456 };
439 457
440 458 Node* c = make_runtime_call(RC_NO_LEAF | RC_NO_IO,
441 459 OptoRuntime::multianewarray_Type(ndimensions),
442 460 fun, NULL, TypeRawPtr::BOTTOM,
443 461 makecon(TypeKlassPtr::make(array_klass)),
444 462 length[0], length[1], length[2],
445 463 length[3], length[4]);
446 464 Node* res = _gvn.transform(new (C, 1) ProjNode(c, TypeFunc::Parms));
447 465
448 466 const Type* type = TypeOopPtr::make_from_klass_raw(array_klass);
449 467
450 468 // Improve the type: We know it's not null, exact, and of a given length.
451 469 type = type->is_ptr()->cast_to_ptr_type(TypePtr::NotNull);
452 470 type = type->is_aryptr()->cast_to_exactness(true);
453 471
454 472 const TypeInt* ltype = _gvn.find_int_type(length[0]);
455 473 if (ltype != NULL)
456 474 type = type->is_aryptr()->cast_to_size(ltype);
457 475
458 476 // We cannot sharpen the nested sub-arrays, since the top level is mutable.
459 477
460 478 Node* cast = _gvn.transform( new (C, 2) CheckCastPPNode(control(), res, type) );
461 479 push(cast);
462 480
463 481 // Possible improvements:
464 482 // - Make a fast path for small multi-arrays. (W/ implicit init. loops.)
465 483 // - Issue CastII against length[*] values, to TypeInt::POS.
466 484 }
↓ open down ↓ |
308 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX