< prev index next >

src/hotspot/share/opto/parse3.cpp

Print this page
@@ -162,12 +162,29 @@
      }
    } else {
      type = Type::get_const_basic_type(bt);
    }
  
-   Node* ld = access_load_at(obj, adr, adr_type, type, bt, decorators);
+   Node* ld = nullptr;
  
+   if (DoPartialEscapeAnalysis && is_field) { // non-static field a global
+     PEAState& as = jvms()->alloc_state();
+     VirtualState* vs = as.as_virtual(PEA(), obj);
+     if (vs != nullptr) { // obj is a virtual object
+       Node* val = vs->get_field(field);
+       // val is nullptr because the field is not explicitly initialized. It is 'null'.
+       // We only replace an instance pointer here. for array pointer, we need to cast 'val' from oop-ptr to aryptr.
+       if (is_obj && val != nullptr && type->isa_instptr()) {
+         ld = val;
+       }
+       // theoretically, we can replace ld with val if val is scalar or even nullptr.
+       // Graal has a feature called 'ReadElimination to do so.
+     }
+   }
+   if (ld == nullptr) {
+     ld = access_load_at(obj, adr, adr_type, type, bt, decorators);
+   }
    // Adjust Java stack
    if (type2size[bt] == 1)
      push(ld);
    else
      push_pair(ld);

@@ -222,10 +239,29 @@
        field_type = TypeOopPtr::make_from_klass(field->type()->as_klass());
      } else {
        field_type = Type::BOTTOM;
      }
    }
+ 
+   // if val is a valid object and the current path isn't dead
+   if (DoPartialEscapeAnalysis && !stopped()) {
+     PartialEscapeAnalysis* pea = PEA();
+     PEAState& state = jvms()->alloc_state();
+ 
+     // val is escaped if obj is escaped or is not trackable.
+     if (is_obj && !val->is_top()) {
+       // put_static_field or unknown dst or dst is escaped.
+       if (state.as_virtual(pea, val) != nullptr && (!is_field || state.as_virtual(pea, obj) == nullptr)) {
+         val = state.materialize(this, val);
+       }
+     }
+     VirtualState* vs = nullptr;
+     if (is_field && (vs = state.as_virtual(pea, obj)) != nullptr) {
+       vs->set_field(field, val);
+     }
+   }
+ 
    access_store_at(obj, adr, adr_type, val, field_type, bt, decorators);
  
    if (is_field) {
      // Remember we wrote a volatile field.
      // For not multiple copy atomic cpu (ppc64) a barrier should be issued
< prev index next >