On constructors and compiler blackholes

Aleksey Shipilev shade at redhat.com
Wed Apr 13 14:00:31 UTC 2022


On 4/11/22 11:28, Andrew Haley wrote:
> The significant difference is that if we use compiler blackholes, C2 omits all of
> the fences that would usually be necessary. I guess that C2 detects that the
> newly-constructed AtomicLong is non-escaping.

Reproduced.

I think EA needs some knowledge about Blackhole arguments after all. This hack seems to resolve this 
particular trouble.

diff --git a/src/hotspot/share/opto/escape.cpp b/src/hotspot/share/opto/escape.cpp
index 3e02b18f50f..7fa88cb31dc 100644
--- a/src/hotspot/share/opto/escape.cpp
+++ b/src/hotspot/share/opto/escape.cpp
@@ -651,6 +651,13 @@ void ConnectionGraph::add_node_to_connection_graph(Node *n, Unique_Node_List *de
        add_java_object(n, PointsToNode::ArgEscape);
        break;
      }
+    case Op_Blackhole: {
+      add_local_var(n, PointsToNode::GlobalEscape);
+      // Don't process blackhole arguments until very late,
+      // since they might not be initialized yet.
+      delayed_worklist->push(n);
+      break;
+    }
      default:
        ; // Do nothing for nodes not related to EA.
    }
@@ -800,6 +807,26 @@ void ConnectionGraph::add_final_edges(Node *n) {
        }
        break;
      }
+    case Op_Blackhole: {
+      // All blackhole arguments are globally escaping.
+      for (uint i = 1; i < n->req(); i++) {
+        Node *in = n->in(i);
+        if (in == NULL) {
+          continue;  // ignore NULL
+        }
+        PointsToNode* ptn = ptnode_adr(in->_idx);
+        if (ptn == nullptr) {
+          // Not registered yet
+          add_local_var(in, PointsToNode::GlobalEscape);
+          ptn = ptnode_adr(in->_idx);
+        } else {
+          // Registered already, force the escape state
+          set_escape_state(ptn, PointsToNode::GlobalEscape NOT_PRODUCT(COMMA "blackhole"));
+        }
+        add_edge(n_ptn, ptn);
+      }
+      break;
+    }
      default: {
        // This method should be called only for EA specific nodes which may
        // miss some edges when they were created.


-- 
Thanks,
-Aleksey



More information about the jmh-dev mailing list