src/share/vm/opto/parse3.cpp

changeset 5658
edb5ab0f3fe5
parent 5437
fcf521c3fbc6
child 6313
de95063c0e34
child 6479
2113136690bc
     1.1 --- a/src/share/vm/opto/parse3.cpp	Mon Sep 09 19:53:28 2013 +0200
     1.2 +++ b/src/share/vm/opto/parse3.cpp	Tue Sep 10 14:51:48 2013 -0700
     1.3 @@ -147,7 +147,15 @@
     1.4  void Parse::do_get_xxx(Node* obj, ciField* field, bool is_field) {
     1.5    // Does this field have a constant value?  If so, just push the value.
     1.6    if (field->is_constant()) {
     1.7 -    // final field
     1.8 +    // final or stable field
     1.9 +    const Type* stable_type = NULL;
    1.10 +    if (FoldStableValues && field->is_stable()) {
    1.11 +      stable_type = Type::get_const_type(field->type());
    1.12 +      if (field->type()->is_array_klass()) {
    1.13 +        int stable_dimension = field->type()->as_array_klass()->dimension();
    1.14 +        stable_type = stable_type->is_aryptr()->cast_to_stable(true, stable_dimension);
    1.15 +      }
    1.16 +    }
    1.17      if (field->is_static()) {
    1.18        // final static field
    1.19        if (C->eliminate_boxing()) {
    1.20 @@ -167,11 +175,10 @@
    1.21            }
    1.22          }
    1.23        }
    1.24 -      if (push_constant(field->constant_value()))
    1.25 +      if (push_constant(field->constant_value(), false, false, stable_type))
    1.26          return;
    1.27 -    }
    1.28 -    else {
    1.29 -      // final non-static field
    1.30 +    } else {
    1.31 +      // final or stable non-static field
    1.32        // Treat final non-static fields of trusted classes (classes in
    1.33        // java.lang.invoke and sun.invoke packages and subpackages) as
    1.34        // compile time constants.
    1.35 @@ -179,8 +186,12 @@
    1.36          const TypeOopPtr* oop_ptr = obj->bottom_type()->isa_oopptr();
    1.37          ciObject* constant_oop = oop_ptr->const_oop();
    1.38          ciConstant constant = field->constant_value_of(constant_oop);
    1.39 -        if (push_constant(constant, true))
    1.40 -          return;
    1.41 +        if (FoldStableValues && field->is_stable() && constant.is_null_or_zero()) {
    1.42 +          // fall through to field load; the field is not yet initialized
    1.43 +        } else {
    1.44 +          if (push_constant(constant, true, false, stable_type))
    1.45 +            return;
    1.46 +        }
    1.47        }
    1.48      }
    1.49    }
    1.50 @@ -301,7 +312,8 @@
    1.51    // Note the presence of writes to final non-static fields, so that we
    1.52    // can insert a memory barrier later on to keep the writes from floating
    1.53    // out of the constructor.
    1.54 -  if (is_field && field->is_final()) {
    1.55 +  // Any method can write a @Stable field; insert memory barriers after those also.
    1.56 +  if (is_field && (field->is_final() || field->is_stable())) {
    1.57      set_wrote_final(true);
    1.58      // Preserve allocation ptr to create precedent edge to it in membar
    1.59      // generated on exit from constructor.
    1.60 @@ -314,35 +326,21 @@
    1.61  }
    1.62  
    1.63  
    1.64 -bool Parse::push_constant(ciConstant constant, bool require_constant, bool is_autobox_cache) {
    1.65 +
    1.66 +bool Parse::push_constant(ciConstant constant, bool require_constant, bool is_autobox_cache, const Type* stable_type) {
    1.67 +  const Type* con_type = Type::make_from_constant(constant, require_constant, is_autobox_cache);
    1.68    switch (constant.basic_type()) {
    1.69 -  case T_BOOLEAN:  push( intcon(constant.as_boolean()) ); break;
    1.70 -  case T_INT:      push( intcon(constant.as_int())     ); break;
    1.71 -  case T_CHAR:     push( intcon(constant.as_char())    ); break;
    1.72 -  case T_BYTE:     push( intcon(constant.as_byte())    ); break;
    1.73 -  case T_SHORT:    push( intcon(constant.as_short())   ); break;
    1.74 -  case T_FLOAT:    push( makecon(TypeF::make(constant.as_float())) );  break;
    1.75 -  case T_DOUBLE:   push_pair( makecon(TypeD::make(constant.as_double())) );  break;
    1.76 -  case T_LONG:     push_pair( longcon(constant.as_long()) ); break;
    1.77    case T_ARRAY:
    1.78 -  case T_OBJECT: {
    1.79 +  case T_OBJECT:
    1.80      // cases:
    1.81      //   can_be_constant    = (oop not scavengable || ScavengeRootsInCode != 0)
    1.82      //   should_be_constant = (oop not scavengable || ScavengeRootsInCode >= 2)
    1.83      // An oop is not scavengable if it is in the perm gen.
    1.84 -    ciObject* oop_constant = constant.as_object();
    1.85 -    if (oop_constant->is_null_object()) {
    1.86 -      push( zerocon(T_OBJECT) );
    1.87 -      break;
    1.88 -    } else if (require_constant || oop_constant->should_be_constant()) {
    1.89 -      push( makecon(TypeOopPtr::make_from_constant(oop_constant, require_constant, is_autobox_cache)) );
    1.90 -      break;
    1.91 -    } else {
    1.92 -      // we cannot inline the oop, but we can use it later to narrow a type
    1.93 -      return false;
    1.94 -    }
    1.95 -  }
    1.96 -  case T_ILLEGAL: {
    1.97 +    if (stable_type != NULL && con_type != NULL && con_type->isa_oopptr())
    1.98 +      con_type = con_type->join(stable_type);
    1.99 +    break;
   1.100 +
   1.101 +  case T_ILLEGAL:
   1.102      // Invalid ciConstant returned due to OutOfMemoryError in the CI
   1.103      assert(C->env()->failing(), "otherwise should not see this");
   1.104      // These always occur because of object types; we are going to
   1.105 @@ -350,17 +348,16 @@
   1.106      push( zerocon(T_OBJECT) );
   1.107      return false;
   1.108    }
   1.109 -  default:
   1.110 -    ShouldNotReachHere();
   1.111 +
   1.112 +  if (con_type == NULL)
   1.113 +    // we cannot inline the oop, but we can use it later to narrow a type
   1.114      return false;
   1.115 -  }
   1.116  
   1.117 -  // success
   1.118 +  push_node(constant.basic_type(), makecon(con_type));
   1.119    return true;
   1.120  }
   1.121  
   1.122  
   1.123 -
   1.124  //=============================================================================
   1.125  void Parse::do_anewarray() {
   1.126    bool will_link;

mercurial