comparison src/share/vm/opto/compile.cpp @ 2376:c7f3d0b4570f

7017732: move static fields into Class to prepare for perm gen removal Reviewed-by: kvn, coleenp, twisti, stefank
author never
date Fri, 18 Mar 2011 16:00:34 -0700
parents b92c45f2bc75
children 7e88bdae86ec e6beb62de02d
comparison
equal deleted inserted replaced
2375:d673ef06fe96 2376:c7f3d0b4570f
1 /* 1 /*
2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 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 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
1200 } 1200 }
1201 1201
1202 // Oop pointers need some flattening 1202 // Oop pointers need some flattening
1203 const TypeInstPtr *to = tj->isa_instptr(); 1203 const TypeInstPtr *to = tj->isa_instptr();
1204 if( to && _AliasLevel >= 2 && to != TypeOopPtr::BOTTOM ) { 1204 if( to && _AliasLevel >= 2 && to != TypeOopPtr::BOTTOM ) {
1205 ciInstanceKlass *k = to->klass()->as_instance_klass();
1205 if( ptr == TypePtr::Constant ) { 1206 if( ptr == TypePtr::Constant ) {
1206 // No constant oop pointers (such as Strings); they alias with 1207 if (to->klass() != ciEnv::current()->Class_klass() ||
1207 // unknown strings. 1208 offset < k->size_helper() * wordSize) {
1208 assert(!is_known_inst, "not scalarizable allocation"); 1209 // No constant oop pointers (such as Strings); they alias with
1209 tj = to = TypeInstPtr::make(TypePtr::BotPTR,to->klass(),false,0,offset); 1210 // unknown strings.
1211 assert(!is_known_inst, "not scalarizable allocation");
1212 tj = to = TypeInstPtr::make(TypePtr::BotPTR,to->klass(),false,0,offset);
1213 }
1210 } else if( is_known_inst ) { 1214 } else if( is_known_inst ) {
1211 tj = to; // Keep NotNull and klass_is_exact for instance type 1215 tj = to; // Keep NotNull and klass_is_exact for instance type
1212 } else if( ptr == TypePtr::NotNull || to->klass_is_exact() ) { 1216 } else if( ptr == TypePtr::NotNull || to->klass_is_exact() ) {
1213 // During the 2nd round of IterGVN, NotNull castings are removed. 1217 // During the 2nd round of IterGVN, NotNull castings are removed.
1214 // Make sure the Bottom and NotNull variants alias the same. 1218 // Make sure the Bottom and NotNull variants alias the same.
1215 // Also, make sure exact and non-exact variants alias the same. 1219 // Also, make sure exact and non-exact variants alias the same.
1216 tj = to = TypeInstPtr::make(TypePtr::BotPTR,to->klass(),false,0,offset); 1220 tj = to = TypeInstPtr::make(TypePtr::BotPTR,to->klass(),false,0,offset);
1217 } 1221 }
1218 // Canonicalize the holder of this field 1222 // Canonicalize the holder of this field
1219 ciInstanceKlass *k = to->klass()->as_instance_klass();
1220 if (offset >= 0 && offset < instanceOopDesc::base_offset_in_bytes()) { 1223 if (offset >= 0 && offset < instanceOopDesc::base_offset_in_bytes()) {
1221 // First handle header references such as a LoadKlassNode, even if the 1224 // First handle header references such as a LoadKlassNode, even if the
1222 // object's klass is unloaded at compile time (4965979). 1225 // object's klass is unloaded at compile time (4965979).
1223 if (!is_known_inst) { // Do it only for non-instance types 1226 if (!is_known_inst) { // Do it only for non-instance types
1224 tj = to = TypeInstPtr::make(TypePtr::BotPTR, env()->Object_klass(), false, NULL, offset); 1227 tj = to = TypeInstPtr::make(TypePtr::BotPTR, env()->Object_klass(), false, NULL, offset);
1225 } 1228 }
1226 } else if (offset < 0 || offset >= k->size_helper() * wordSize) { 1229 } else if (offset < 0 || offset >= k->size_helper() * wordSize) {
1227 to = NULL; 1230 // Static fields are in the space above the normal instance
1228 tj = TypeOopPtr::BOTTOM; 1231 // fields in the java.lang.Class instance.
1229 offset = tj->offset(); 1232 if (to->klass() != ciEnv::current()->Class_klass()) {
1233 to = NULL;
1234 tj = TypeOopPtr::BOTTOM;
1235 offset = tj->offset();
1236 }
1230 } else { 1237 } else {
1231 ciInstanceKlass *canonical_holder = k->get_canonical_holder(offset); 1238 ciInstanceKlass *canonical_holder = k->get_canonical_holder(offset);
1232 if (!k->equals(canonical_holder) || tj->offset() != offset) { 1239 if (!k->equals(canonical_holder) || tj->offset() != offset) {
1233 if( is_known_inst ) { 1240 if( is_known_inst ) {
1234 tj = to = TypeInstPtr::make(to->ptr(), canonical_holder, true, NULL, offset, to->instance_id()); 1241 tj = to = TypeInstPtr::make(to->ptr(), canonical_holder, true, NULL, offset, to->instance_id());
1397 for (int i = 0; i < new_ats; i++) _alias_types[old_ats+i] = &ats[i]; 1404 for (int i = 0; i < new_ats; i++) _alias_types[old_ats+i] = &ats[i];
1398 } 1405 }
1399 1406
1400 1407
1401 //--------------------------------find_alias_type------------------------------ 1408 //--------------------------------find_alias_type------------------------------
1402 Compile::AliasType* Compile::find_alias_type(const TypePtr* adr_type, bool no_create) { 1409 Compile::AliasType* Compile::find_alias_type(const TypePtr* adr_type, bool no_create, ciField* original_field) {
1403 if (_AliasLevel == 0) 1410 if (_AliasLevel == 0)
1404 return alias_type(AliasIdxBot); 1411 return alias_type(AliasIdxBot);
1405 1412
1406 AliasCacheEntry* ace = probe_alias_cache(adr_type); 1413 AliasCacheEntry* ace = probe_alias_cache(adr_type);
1407 if (ace->_adr_type == adr_type) { 1414 if (ace->_adr_type == adr_type) {
1462 } 1469 }
1463 // %%% (We would like to finalize JavaThread::threadObj_offset(), 1470 // %%% (We would like to finalize JavaThread::threadObj_offset(),
1464 // but the base pointer type is not distinctive enough to identify 1471 // but the base pointer type is not distinctive enough to identify
1465 // references into JavaThread.) 1472 // references into JavaThread.)
1466 1473
1467 // Check for final instance fields. 1474 // Check for final fields.
1468 const TypeInstPtr* tinst = flat->isa_instptr(); 1475 const TypeInstPtr* tinst = flat->isa_instptr();
1469 if (tinst && tinst->offset() >= instanceOopDesc::base_offset_in_bytes()) { 1476 if (tinst && tinst->offset() >= instanceOopDesc::base_offset_in_bytes()) {
1470 ciInstanceKlass *k = tinst->klass()->as_instance_klass(); 1477 ciField* field;
1471 ciField* field = k->get_field_by_offset(tinst->offset(), false); 1478 if (tinst->const_oop() != NULL &&
1479 tinst->klass() == ciEnv::current()->Class_klass() &&
1480 tinst->offset() >= (tinst->klass()->as_instance_klass()->size_helper() * wordSize)) {
1481 // static field
1482 ciInstanceKlass* k = tinst->const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass();
1483 field = k->get_field_by_offset(tinst->offset(), true);
1484 } else {
1485 ciInstanceKlass *k = tinst->klass()->as_instance_klass();
1486 field = k->get_field_by_offset(tinst->offset(), false);
1487 }
1488 assert(field == NULL ||
1489 original_field == NULL ||
1490 (field->holder() == original_field->holder() &&
1491 field->offset() == original_field->offset() &&
1492 field->is_static() == original_field->is_static()), "wrong field?");
1472 // Set field() and is_rewritable() attributes. 1493 // Set field() and is_rewritable() attributes.
1473 if (field != NULL) alias_type(idx)->set_field(field); 1494 if (field != NULL) alias_type(idx)->set_field(field);
1474 }
1475 const TypeKlassPtr* tklass = flat->isa_klassptr();
1476 // Check for final static fields.
1477 if (tklass && tklass->klass()->is_instance_klass()) {
1478 ciInstanceKlass *k = tklass->klass()->as_instance_klass();
1479 ciField* field = k->get_field_by_offset(tklass->offset(), true);
1480 // Set field() and is_rewritable() attributes.
1481 if (field != NULL) alias_type(idx)->set_field(field);
1482 } 1495 }
1483 } 1496 }
1484 1497
1485 // Fill the cache for next time. 1498 // Fill the cache for next time.
1486 ace->_adr_type = adr_type; 1499 ace->_adr_type = adr_type;
1500 1513
1501 1514
1502 Compile::AliasType* Compile::alias_type(ciField* field) { 1515 Compile::AliasType* Compile::alias_type(ciField* field) {
1503 const TypeOopPtr* t; 1516 const TypeOopPtr* t;
1504 if (field->is_static()) 1517 if (field->is_static())
1505 t = TypeKlassPtr::make(field->holder()); 1518 t = TypeInstPtr::make(field->holder()->java_mirror());
1506 else 1519 else
1507 t = TypeOopPtr::make_from_klass_raw(field->holder()); 1520 t = TypeOopPtr::make_from_klass_raw(field->holder());
1508 AliasType* atp = alias_type(t->add_offset(field->offset_in_bytes())); 1521 AliasType* atp = alias_type(t->add_offset(field->offset_in_bytes()), field);
1509 assert(field->is_final() == !atp->is_rewritable(), "must get the rewritable bits correct"); 1522 assert(field->is_final() == !atp->is_rewritable(), "must get the rewritable bits correct");
1510 return atp; 1523 return atp;
1511 } 1524 }
1512 1525
1513 1526
1520 1533
1521 // Handle special cases. 1534 // Handle special cases.
1522 if (adr_type == NULL) return true; 1535 if (adr_type == NULL) return true;
1523 if (adr_type == TypePtr::BOTTOM) return true; 1536 if (adr_type == TypePtr::BOTTOM) return true;
1524 1537
1525 return find_alias_type(adr_type, true) != NULL; 1538 return find_alias_type(adr_type, true, NULL) != NULL;
1526 } 1539 }
1527 1540
1528 //-----------------------------must_alias-------------------------------------- 1541 //-----------------------------must_alias--------------------------------------
1529 // True if all values of the given address type are in the given alias category. 1542 // True if all values of the given address type are in the given alias category.
1530 bool Compile::must_alias(const TypePtr* adr_type, int alias_idx) { 1543 bool Compile::must_alias(const TypePtr* adr_type, int alias_idx) {