changeset 39252:a3644fa2b8b4

8155046: Parse::Block construction using undefined behavior Summary: Blocks should be created via constructor and placement new. Reviewed-by: kvn
author thartmann
date Wed, 01 Jun 2016 14:22:18 +0200
parents a691c50d2b16
children bd5fe208734e
files hotspot/src/share/vm/opto/parse.hpp hotspot/src/share/vm/opto/parse1.cpp
diffstat 2 files changed, 13 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/hotspot/src/share/vm/opto/parse.hpp	Tue May 31 20:43:12 2016 +0000
+++ b/hotspot/src/share/vm/opto/parse.hpp	Wed Jun 01 14:22:18 2016 +0200
@@ -166,14 +166,11 @@
     int                _all_successors; // Include exception paths also.
     Block**            _successors;
 
-    // Use init_node/init_graph to initialize Blocks.
-    // Block() : _live_locals((uintptr_t*)NULL,0) { ShouldNotReachHere(); }
-    Block() : _live_locals() { ShouldNotReachHere(); }
-
    public:
 
     // Set up the block data structure itself.
-    void init_node(Parse* outer, int po);
+    Block(Parse* outer, int rpo);
+
     // Set up the block's relations to other blocks.
     void init_graph(Parse* outer);
 
--- a/hotspot/src/share/vm/opto/parse1.cpp	Tue May 31 20:43:12 2016 +0000
+++ b/hotspot/src/share/vm/opto/parse1.cpp	Wed Jun 01 14:22:18 2016 +0200
@@ -1235,29 +1235,33 @@
   // Create the blocks.
   _block_count = flow()->block_count();
   _blocks = NEW_RESOURCE_ARRAY(Block, _block_count);
-  Copy::zero_to_bytes(_blocks, sizeof(Block)*_block_count);
-
-  int rpo;
 
   // Initialize the structs.
-  for (rpo = 0; rpo < block_count(); rpo++) {
+  for (int rpo = 0; rpo < block_count(); rpo++) {
     Block* block = rpo_at(rpo);
-    block->init_node(this, rpo);
+    new(block) Block(this, rpo);
   }
 
   // Collect predecessor and successor information.
-  for (rpo = 0; rpo < block_count(); rpo++) {
+  for (int rpo = 0; rpo < block_count(); rpo++) {
     Block* block = rpo_at(rpo);
     block->init_graph(this);
   }
 }
 
 //-------------------------------init_node-------------------------------------
-void Parse::Block::init_node(Parse* outer, int rpo) {
+Parse::Block::Block(Parse* outer, int rpo) : _live_locals() {
   _flow = outer->flow()->rpo_at(rpo);
   _pred_count = 0;
   _preds_parsed = 0;
   _count = 0;
+  _is_parsed = false;
+  _is_handler = false;
+  _has_merged_backedge = false;
+  _start_map = NULL;
+  _num_successors = 0;
+  _all_successors = 0;
+  _successors = NULL;
   assert(pred_count() == 0 && preds_parsed() == 0, "sanity");
   assert(!(is_merged() || is_parsed() || is_handler() || has_merged_backedge()), "sanity");
   assert(_live_locals.size() == 0, "sanity");