Skip to content

Commit 8f64ccc

Browse files
sarannatrobcasloz
authored andcommitted
8350485: C2: factor out common code in Node::grow() and Node::out_grow()
Reviewed-by: thartmann, rcastanedalo
1 parent c2be19c commit 8f64ccc

File tree

2 files changed

+32
-39
lines changed

2 files changed

+32
-39
lines changed

src/hotspot/share/opto/node.cpp

Lines changed: 28 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -675,55 +675,45 @@ void Node::destruct(PhaseValues* phase) {
675675
}
676676
}
677677

678-
//------------------------------grow-------------------------------------------
679-
// Grow the input array, making space for more edges
680-
void Node::grow(uint len) {
678+
// Resize input or output array to grow it to the next larger power-of-2 bigger
679+
// than len.
680+
void Node::resize_array(Node**& array, node_idx_t& max_size, uint len, bool needs_clearing) {
681681
Arena* arena = Compile::current()->node_arena();
682-
uint new_max = _max;
683-
if( new_max == 0 ) {
684-
_max = 4;
685-
_in = (Node**)arena->Amalloc(4*sizeof(Node*));
686-
Node** to = _in;
687-
to[0] = nullptr;
688-
to[1] = nullptr;
689-
to[2] = nullptr;
690-
to[3] = nullptr;
682+
uint new_max = max_size;
683+
if (new_max == 0) {
684+
max_size = 4;
685+
array = (Node**)arena->Amalloc(4 * sizeof(Node*));
686+
if (needs_clearing) {
687+
array[0] = nullptr;
688+
array[1] = nullptr;
689+
array[2] = nullptr;
690+
array[3] = nullptr;
691+
}
691692
return;
692693
}
693694
new_max = next_power_of_2(len);
694-
// Trimming to limit allows a uint8 to handle up to 255 edges.
695-
// Previously I was using only powers-of-2 which peaked at 128 edges.
696-
//if( new_max >= limit ) new_max = limit-1;
697-
_in = (Node**)arena->Arealloc(_in, _max*sizeof(Node*), new_max*sizeof(Node*));
698-
Copy::zero_to_bytes(&_in[_max], (new_max-_max)*sizeof(Node*)); // null all new space
699-
_max = new_max; // Record new max length
695+
assert(needs_clearing || (array != nullptr && array != NO_OUT_ARRAY), "out must have sensible value");
696+
array = (Node**)arena->Arealloc(array, max_size * sizeof(Node*), new_max * sizeof(Node*));
697+
if (needs_clearing) {
698+
Copy::zero_to_bytes(&array[max_size], (new_max - max_size) * sizeof(Node*)); // null all new space
699+
}
700+
max_size = new_max; // Record new max length
700701
// This assertion makes sure that Node::_max is wide enough to
701702
// represent the numerical value of new_max.
702-
assert(_max == new_max && _max > len, "int width of _max is too small");
703+
assert(max_size > len, "int width of _max or _outmax is too small");
704+
}
705+
706+
//------------------------------grow-------------------------------------------
707+
// Grow the input array, making space for more edges
708+
void Node::grow(uint len) {
709+
resize_array(_in, _max, len, true);
703710
}
704711

705712
//-----------------------------out_grow----------------------------------------
706713
// Grow the input array, making space for more edges
707-
void Node::out_grow( uint len ) {
714+
void Node::out_grow(uint len) {
708715
assert(!is_top(), "cannot grow a top node's out array");
709-
Arena* arena = Compile::current()->node_arena();
710-
uint new_max = _outmax;
711-
if( new_max == 0 ) {
712-
_outmax = 4;
713-
_out = (Node **)arena->Amalloc(4*sizeof(Node*));
714-
return;
715-
}
716-
new_max = next_power_of_2(len);
717-
// Trimming to limit allows a uint8 to handle up to 255 edges.
718-
// Previously I was using only powers-of-2 which peaked at 128 edges.
719-
//if( new_max >= limit ) new_max = limit-1;
720-
assert(_out != nullptr && _out != NO_OUT_ARRAY, "out must have sensible value");
721-
_out = (Node**)arena->Arealloc(_out,_outmax*sizeof(Node*),new_max*sizeof(Node*));
722-
//Copy::zero_to_bytes(&_out[_outmax], (new_max-_outmax)*sizeof(Node*)); // null all new space
723-
_outmax = new_max; // Record new max length
724-
// This assertion makes sure that Node::_max is wide enough to
725-
// represent the numerical value of new_max.
726-
assert(_outmax == new_max && _outmax > len, "int width of _outmax is too small");
716+
resize_array(_out, _outmax, len, false);
727717
}
728718

729719
#ifdef ASSERT

src/hotspot/share/opto/node.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,11 @@ class Node {
335335
void grow( uint len );
336336
// Grow the output array to the next larger power-of-2 bigger than len.
337337
void out_grow( uint len );
338+
// Resize input or output array to grow it to the next larger power-of-2
339+
// bigger than len.
340+
void resize_array(Node**& array, node_idx_t& max_size, uint len, bool needs_clearing);
338341

339-
public:
342+
public:
340343
// Each Node is assigned a unique small/dense number. This number is used
341344
// to index into auxiliary arrays of data and bit vectors.
342345
// The value of _idx can be changed using the set_idx() method.

0 commit comments

Comments
 (0)