--- a/hotspot/src/share/vm/opto/graphKit.cpp Mon Sep 15 09:58:26 2008 -0700
+++ b/hotspot/src/share/vm/opto/graphKit.cpp Wed Sep 17 08:29:17 2008 -0700
@@ -1049,10 +1049,19 @@
//-------------------------load_array_length-----------------------------------
Node* GraphKit::load_array_length(Node* array) {
// Special-case a fresh allocation to avoid building nodes:
- Node* alen = AllocateArrayNode::Ideal_length(array, &_gvn);
- if (alen != NULL) return alen;
- Node *r_adr = basic_plus_adr(array, arrayOopDesc::length_offset_in_bytes());
- return _gvn.transform( new (C, 3) LoadRangeNode(0, immutable_memory(), r_adr, TypeInt::POS));
+ AllocateArrayNode* alloc = AllocateArrayNode::Ideal_array_allocation(array, &_gvn);
+ Node *alen;
+ if (alloc == NULL) {
+ Node *r_adr = basic_plus_adr(array, arrayOopDesc::length_offset_in_bytes());
+ alen = _gvn.transform( new (C, 3) LoadRangeNode(0, immutable_memory(), r_adr, TypeInt::POS));
+ } else {
+ alen = alloc->Ideal_length();
+ Node* ccast = alloc->make_ideal_length(_gvn.type(array)->is_aryptr(), &_gvn);
+ if (ccast != alen) {
+ alen = _gvn.transform(ccast);
+ }
+ }
+ return alen;
}
//------------------------------do_null_check----------------------------------
@@ -2833,20 +2842,18 @@
assert(just_allocated_object(control()) == javaoop, "just allocated");
#ifdef ASSERT
- { // Verify that the AllocateNode::Ideal_foo recognizers work:
- Node* kn = alloc->in(AllocateNode::KlassNode);
- Node* ln = alloc->in(AllocateNode::ALength);
- assert(AllocateNode::Ideal_klass(rawoop, &_gvn) == kn,
- "Ideal_klass works");
- assert(AllocateNode::Ideal_klass(javaoop, &_gvn) == kn,
- "Ideal_klass works");
+ { // Verify that the AllocateNode::Ideal_allocation recognizers work:
+ assert(AllocateNode::Ideal_allocation(rawoop, &_gvn) == alloc,
+ "Ideal_allocation works");
+ assert(AllocateNode::Ideal_allocation(javaoop, &_gvn) == alloc,
+ "Ideal_allocation works");
if (alloc->is_AllocateArray()) {
- assert(AllocateArrayNode::Ideal_length(rawoop, &_gvn) == ln,
- "Ideal_length works");
- assert(AllocateArrayNode::Ideal_length(javaoop, &_gvn) == ln,
- "Ideal_length works");
+ assert(AllocateArrayNode::Ideal_array_allocation(rawoop, &_gvn) == alloc->as_AllocateArray(),
+ "Ideal_allocation works");
+ assert(AllocateArrayNode::Ideal_array_allocation(javaoop, &_gvn) == alloc->as_AllocateArray(),
+ "Ideal_allocation works");
} else {
- assert(ln->is_top(), "no length, please");
+ assert(alloc->in(AllocateNode::ALength)->is_top(), "no length, please");
}
}
#endif //ASSERT
@@ -3095,25 +3102,20 @@
// (This happens via a non-constant argument to inline_native_newArray.)
// In any case, the value of klass_node provides the desired array type.
const TypeInt* length_type = _gvn.find_int_type(length);
- const TypeInt* narrow_length_type = NULL;
const TypeOopPtr* ary_type = _gvn.type(klass_node)->is_klassptr()->as_instance_type();
if (ary_type->isa_aryptr() && length_type != NULL) {
// Try to get a better type than POS for the size
ary_type = ary_type->is_aryptr()->cast_to_size(length_type);
- narrow_length_type = ary_type->is_aryptr()->size();
- if (narrow_length_type == length_type)
- narrow_length_type = NULL;
}
Node* javaoop = set_output_for_allocation(alloc, ary_type, raw_mem_only);
- // Cast length on remaining path to be positive:
- if (narrow_length_type != NULL) {
- Node* ccast = new (C, 2) CastIINode(length, narrow_length_type);
- ccast->set_req(0, control());
- _gvn.set_type_bottom(ccast);
- record_for_igvn(ccast);
- if (map()->find_edge(length) >= 0) {
+ // Cast length on remaining path to be as narrow as possible
+ if (map()->find_edge(length) >= 0) {
+ Node* ccast = alloc->make_ideal_length(ary_type, &_gvn);
+ if (ccast != length) {
+ _gvn.set_type_bottom(ccast);
+ record_for_igvn(ccast);
replace_in_map(length, ccast);
}
}