From 612c38cdc92a3e169fe83846920407d50263044a Mon Sep 17 00:00:00 2001
From: Xin Liu <xliu@openjdk.org>
Date: Wed, 20 May 2020 11:29:11 -0700
Subject: [PATCH] 8245051: c1 is broken if it is compiled by gcc without
 -fno-lifetime-dse

Initialize BlockBegin block id in constructor rather than operator new

Reviewed-by: kbarrett, thartmann
---
 src/hotspot/share/c1/c1_Instruction.hpp | 7 ++-----
 src/hotspot/share/c1/c1_ValueMap.cpp    | 1 +
 2 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/src/hotspot/share/c1/c1_Instruction.hpp b/src/hotspot/share/c1/c1_Instruction.hpp
index 09644580f2a..9716d4d00ec 100644
--- a/src/hotspot/share/c1/c1_Instruction.hpp
+++ b/src/hotspot/share/c1/c1_Instruction.hpp
@@ -303,7 +303,6 @@ class Instruction: public CompilationResourceObj {
   XHandlers*   _exception_handlers;              // Flat list of exception handlers covering this instruction
 
   friend class UseCountComputer;
-  friend class BlockBegin;
 
   void update_exception_state(ValueStack* state);
 
@@ -349,7 +348,6 @@ class Instruction: public CompilationResourceObj {
   void* operator new(size_t size) throw() {
     Compilation* c = Compilation::current();
     void* res = c->arena()->Amalloc(size);
-    ((Instruction*)res)->_id = c->get_next_id();
     return res;
   }
 
@@ -410,7 +408,7 @@ class Instruction: public CompilationResourceObj {
 
   // creation
   Instruction(ValueType* type, ValueStack* state_before = NULL, bool type_is_constant = false)
-  :
+  : _id(Compilation::current()->get_next_id()),
 #ifndef PRODUCT
   _printable_bci(-99),
 #endif
@@ -1649,8 +1647,6 @@ LEAF(BlockBegin, StateSplit)
    void* operator new(size_t size) throw() {
     Compilation* c = Compilation::current();
     void* res = c->arena()->Amalloc(size);
-    ((BlockBegin*)res)->_id = c->get_next_id();
-    ((BlockBegin*)res)->_block_id = c->get_next_block_id();
     return res;
   }
 
@@ -1662,6 +1658,7 @@ LEAF(BlockBegin, StateSplit)
   // creation
   BlockBegin(int bci)
   : StateSplit(illegalType)
+  , _block_id(Compilation::current()->get_next_block_id())
   , _bci(bci)
   , _depth_first_number(-1)
   , _linear_scan_number(-1)
diff --git a/src/hotspot/share/c1/c1_ValueMap.cpp b/src/hotspot/share/c1/c1_ValueMap.cpp
index 88ee5fe72b7..016ea3c99c0 100644
--- a/src/hotspot/share/c1/c1_ValueMap.cpp
+++ b/src/hotspot/share/c1/c1_ValueMap.cpp
@@ -488,6 +488,7 @@ GlobalValueNumbering::GlobalValueNumbering(IR* ir)
   : _compilation(ir->compilation())
   , _current_map(NULL)
   , _value_maps(ir->linear_scan_order()->length(), ir->linear_scan_order()->length(), NULL)
+  , _has_substitutions(false)
 {
   TRACE_VALUE_NUMBERING(tty->print_cr("****** start of global value numbering"));