comparison src/share/vm/opto/memnode.cpp @ 3278:66b0e2371912

7026700: regression in 6u24-rev-b23: Crash in C2 compiler in PhaseIdealLoop::build_loop_late_post Summary: memory slices should be always created for non-static fields after allocation Reviewed-by: never
author kvn
date Wed, 20 Apr 2011 18:29:35 -0700
parents cb162b348743
children 286c498ae0d4
comparison
equal deleted inserted replaced
3277:d934e4b931e9 3278:66b0e2371912
1257 Node *region = mem->in(0); 1257 Node *region = mem->in(0);
1258 if (region == NULL) { 1258 if (region == NULL) {
1259 return NULL; // Wait stable graph 1259 return NULL; // Wait stable graph
1260 } 1260 }
1261 uint cnt = mem->req(); 1261 uint cnt = mem->req();
1262 for( uint i = 1; i < cnt; i++ ) { 1262 for (uint i = 1; i < cnt; i++) {
1263 Node* rc = region->in(i);
1264 if (rc == NULL || phase->type(rc) == Type::TOP)
1265 return NULL; // Wait stable graph
1263 Node *in = mem->in(i); 1266 Node *in = mem->in(i);
1264 if( in == NULL ) { 1267 if (in == NULL) {
1265 return NULL; // Wait stable graph 1268 return NULL; // Wait stable graph
1266 } 1269 }
1267 } 1270 }
1268 // Check for loop invariant. 1271 // Check for loop invariant.
1269 if (cnt == 3) { 1272 if (cnt == 3) {
1270 for( uint i = 1; i < cnt; i++ ) { 1273 for (uint i = 1; i < cnt; i++) {
1271 Node *in = mem->in(i); 1274 Node *in = mem->in(i);
1272 Node* m = MemNode::optimize_memory_chain(in, addr_t, phase); 1275 Node* m = MemNode::optimize_memory_chain(in, addr_t, phase);
1273 if (m == mem) { 1276 if (m == mem) {
1274 set_req(MemNode::Memory, mem->in(cnt - i)); // Skip this phi. 1277 set_req(MemNode::Memory, mem->in(cnt - i)); // Skip this phi.
1275 return this; 1278 return this;
1279 // Split through Phi (see original code in loopopts.cpp). 1282 // Split through Phi (see original code in loopopts.cpp).
1280 assert(phase->C->have_alias_type(addr_t), "instance should have alias type"); 1283 assert(phase->C->have_alias_type(addr_t), "instance should have alias type");
1281 1284
1282 // Do nothing here if Identity will find a value 1285 // Do nothing here if Identity will find a value
1283 // (to avoid infinite chain of value phis generation). 1286 // (to avoid infinite chain of value phis generation).
1284 if ( !phase->eqv(this, this->Identity(phase)) ) 1287 if (!phase->eqv(this, this->Identity(phase)))
1285 return NULL; 1288 return NULL;
1286 1289
1287 // Skip the split if the region dominates some control edge of the address. 1290 // Skip the split if the region dominates some control edge of the address.
1288 if (cnt == 3 && !MemNode::all_controls_dominate(address, region)) 1291 if (!MemNode::all_controls_dominate(address, region))
1289 return NULL; 1292 return NULL;
1290 1293
1291 const Type* this_type = this->bottom_type(); 1294 const Type* this_type = this->bottom_type();
1292 int this_index = phase->C->get_alias_index(addr_t); 1295 int this_index = phase->C->get_alias_index(addr_t);
1293 int this_offset = addr_t->offset(); 1296 int this_offset = addr_t->offset();
1294 int this_iid = addr_t->is_oopptr()->instance_id(); 1297 int this_iid = addr_t->is_oopptr()->instance_id();
1295 int wins = 0;
1296 PhaseIterGVN *igvn = phase->is_IterGVN(); 1298 PhaseIterGVN *igvn = phase->is_IterGVN();
1297 Node *phi = new (igvn->C, region->req()) PhiNode(region, this_type, NULL, this_iid, this_index, this_offset); 1299 Node *phi = new (igvn->C, region->req()) PhiNode(region, this_type, NULL, this_iid, this_index, this_offset);
1298 for( uint i = 1; i < region->req(); i++ ) { 1300 for (uint i = 1; i < region->req(); i++) {
1299 Node *x; 1301 Node *x;
1300 Node* the_clone = NULL; 1302 Node* the_clone = NULL;
1301 if( region->in(i) == phase->C->top() ) { 1303 if (region->in(i) == phase->C->top()) {
1302 x = phase->C->top(); // Dead path? Use a dead data op 1304 x = phase->C->top(); // Dead path? Use a dead data op
1303 } else { 1305 } else {
1304 x = this->clone(); // Else clone up the data op 1306 x = this->clone(); // Else clone up the data op
1305 the_clone = x; // Remember for possible deletion. 1307 the_clone = x; // Remember for possible deletion.
1306 // Alter data node to use pre-phi inputs 1308 // Alter data node to use pre-phi inputs
1307 if( this->in(0) == region ) { 1309 if (this->in(0) == region) {
1308 x->set_req( 0, region->in(i) ); 1310 x->set_req(0, region->in(i));
1309 } else { 1311 } else {
1310 x->set_req( 0, NULL ); 1312 x->set_req(0, NULL);
1311 } 1313 }
1312 for( uint j = 1; j < this->req(); j++ ) { 1314 for (uint j = 1; j < this->req(); j++) {
1313 Node *in = this->in(j); 1315 Node *in = this->in(j);
1314 if( in->is_Phi() && in->in(0) == region ) 1316 if (in->is_Phi() && in->in(0) == region)
1315 x->set_req( j, in->in(i) ); // Use pre-Phi input for the clone 1317 x->set_req(j, in->in(i)); // Use pre-Phi input for the clone
1316 } 1318 }
1317 } 1319 }
1318 // Check for a 'win' on some paths 1320 // Check for a 'win' on some paths
1319 const Type *t = x->Value(igvn); 1321 const Type *t = x->Value(igvn);
1320 1322
1321 bool singleton = t->singleton(); 1323 bool singleton = t->singleton();
1322 1324
1323 // See comments in PhaseIdealLoop::split_thru_phi(). 1325 // See comments in PhaseIdealLoop::split_thru_phi().
1324 if( singleton && t == Type::TOP ) { 1326 if (singleton && t == Type::TOP) {
1325 singleton &= region->is_Loop() && (i != LoopNode::EntryControl); 1327 singleton &= region->is_Loop() && (i != LoopNode::EntryControl);
1326 } 1328 }
1327 1329
1328 if( singleton ) { 1330 if (singleton) {
1329 wins++;
1330 x = igvn->makecon(t); 1331 x = igvn->makecon(t);
1331 } else { 1332 } else {
1332 // We now call Identity to try to simplify the cloned node. 1333 // We now call Identity to try to simplify the cloned node.
1333 // Note that some Identity methods call phase->type(this). 1334 // Note that some Identity methods call phase->type(this).
1334 // Make sure that the type array is big enough for 1335 // Make sure that the type array is big enough for
1338 // If x is a TypeNode, capture any more-precise type permanently into Node 1339 // If x is a TypeNode, capture any more-precise type permanently into Node
1339 // otherwise it will be not updated during igvn->transform since 1340 // otherwise it will be not updated during igvn->transform since
1340 // igvn->type(x) is set to x->Value() already. 1341 // igvn->type(x) is set to x->Value() already.
1341 x->raise_bottom_type(t); 1342 x->raise_bottom_type(t);
1342 Node *y = x->Identity(igvn); 1343 Node *y = x->Identity(igvn);
1343 if( y != x ) { 1344 if (y != x) {
1344 wins++;
1345 x = y; 1345 x = y;
1346 } else { 1346 } else {
1347 y = igvn->hash_find(x); 1347 y = igvn->hash_find(x);
1348 if( y ) { 1348 if (y) {
1349 wins++;
1350 x = y; 1349 x = y;
1351 } else { 1350 } else {
1352 // Else x is a new node we are keeping 1351 // Else x is a new node we are keeping
1353 // We do not need register_new_node_with_optimizer 1352 // We do not need register_new_node_with_optimizer
1354 // because set_type has already been called. 1353 // because set_type has already been called.
1358 } 1357 }
1359 if (x != the_clone && the_clone != NULL) 1358 if (x != the_clone && the_clone != NULL)
1360 igvn->remove_dead_node(the_clone); 1359 igvn->remove_dead_node(the_clone);
1361 phi->set_req(i, x); 1360 phi->set_req(i, x);
1362 } 1361 }
1363 if( wins > 0 ) { 1362 // Record Phi
1364 // Record Phi 1363 igvn->register_new_node_with_optimizer(phi);
1365 igvn->register_new_node_with_optimizer(phi); 1364 return phi;
1366 return phi;
1367 }
1368 igvn->remove_dead_node(phi);
1369 return NULL;
1370 } 1365 }
1371 1366
1372 //------------------------------Ideal------------------------------------------ 1367 //------------------------------Ideal------------------------------------------
1373 // If the load is from Field memory and the pointer is non-null, we can 1368 // If the load is from Field memory and the pointer is non-null, we can
1374 // zero out the control input. 1369 // zero out the control input.
1675 } 1670 }
1676 1671
1677 // If we are loading from a freshly-allocated object, produce a zero, 1672 // If we are loading from a freshly-allocated object, produce a zero,
1678 // if the load is provably beyond the header of the object. 1673 // if the load is provably beyond the header of the object.
1679 // (Also allow a variable load from a fresh array to produce zero.) 1674 // (Also allow a variable load from a fresh array to produce zero.)
1680 if (ReduceFieldZeroing) { 1675 const TypeOopPtr *tinst = tp->isa_oopptr();
1676 bool is_instance = (tinst != NULL) && tinst->is_known_instance_field();
1677 if (ReduceFieldZeroing || is_instance) {
1681 Node* value = can_see_stored_value(mem,phase); 1678 Node* value = can_see_stored_value(mem,phase);
1682 if (value != NULL && value->is_Con()) 1679 if (value != NULL && value->is_Con())
1683 return value->bottom_type(); 1680 return value->bottom_type();
1684 } 1681 }
1685 1682
1686 const TypeOopPtr *tinst = tp->isa_oopptr(); 1683 if (is_instance) {
1687 if (tinst != NULL && tinst->is_known_instance_field()) {
1688 // If we have an instance type and our memory input is the 1684 // If we have an instance type and our memory input is the
1689 // programs's initial memory state, there is no matching store, 1685 // programs's initial memory state, there is no matching store,
1690 // so just return a zero of the appropriate type 1686 // so just return a zero of the appropriate type
1691 Node *mem = in(MemNode::Memory); 1687 Node *mem = in(MemNode::Memory);
1692 if (mem->is_Parm() && mem->in(0)->is_Start()) { 1688 if (mem->is_Parm() && mem->in(0)->is_Start()) {