6661247: Internal bug in 32-bit HotSpot optimizer while bit manipulations
Summary: copy elimination of a constant value results in incorrect execution
Reviewed-by: kvn, sgoldman, rasbold
--- a/hotspot/src/share/vm/opto/chaitin.hpp Tue Mar 18 23:54:17 2008 -0700
+++ b/hotspot/src/share/vm/opto/chaitin.hpp Wed Mar 19 15:14:36 2008 -0700
@@ -457,7 +457,8 @@
bool may_be_copy_of_callee( Node *def ) const;
// If nreg already contains the same constant as val then eliminate it
- bool eliminate_copy_of_constant(Node* val, Block *current_block, Node_List& value, Node_List ®nd,
+ bool eliminate_copy_of_constant(Node* val, Node* n,
+ Block *current_block, Node_List& value, Node_List ®nd,
OptoReg::Name nreg, OptoReg::Name nreg2);
// Extend the node to LRG mapping
void add_reference( const Node *node, const Node *old_node);
--- a/hotspot/src/share/vm/opto/postaloc.cpp Tue Mar 18 23:54:17 2008 -0700
+++ b/hotspot/src/share/vm/opto/postaloc.cpp Wed Mar 19 15:14:36 2008 -0700
@@ -253,7 +253,8 @@
// nodes can represent the same constant so the type and rule of the
// MachNode must be checked to ensure equivalence.
//
-bool PhaseChaitin::eliminate_copy_of_constant(Node* val, Block *current_block,
+bool PhaseChaitin::eliminate_copy_of_constant(Node* val, Node* n,
+ Block *current_block,
Node_List& value, Node_List& regnd,
OptoReg::Name nreg, OptoReg::Name nreg2) {
if (value[nreg] != val && val->is_Con() &&
@@ -269,12 +270,12 @@
// Since they are equivalent the second one if redundant and can
// be removed.
//
- // val will be replaced with the old value but val might have
+ // n will be replaced with the old value but n might have
// kills projections associated with it so remove them now so that
// yank_if_dead will be able to elminate the copy once the uses
// have been transferred to the old[value].
- for (DUIterator_Fast imax, i = val->fast_outs(imax); i < imax; i++) {
- Node* use = val->fast_out(i);
+ for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
+ Node* use = n->fast_out(i);
if (use->is_Proj() && use->outcnt() == 0) {
// Kill projections have no users and one input
use->set_req(0, C->top());
@@ -521,7 +522,7 @@
// then 'n' is a useless copy. Do not update the register->node
// mapping so 'n' will go dead.
if( value[nreg] != val ) {
- if (eliminate_copy_of_constant(val, b, value, regnd, nreg, OptoReg::Bad)) {
+ if (eliminate_copy_of_constant(val, n, b, value, regnd, nreg, OptoReg::Bad)) {
n->replace_by(regnd[nreg]);
j -= yank_if_dead(n,b,&value,®nd);
} else {
@@ -549,7 +550,7 @@
nreg_lo = tmp.find_first_elem();
}
if( value[nreg] != val || value[nreg_lo] != val ) {
- if (eliminate_copy_of_constant(n, b, value, regnd, nreg, nreg_lo)) {
+ if (eliminate_copy_of_constant(val, n, b, value, regnd, nreg, nreg_lo)) {
n->replace_by(regnd[nreg]);
j -= yank_if_dead(n,b,&value,®nd);
} else {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/compiler/6661247/Test.java Wed Mar 19 15:14:36 2008 -0700
@@ -0,0 +1,155 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ */
+
+/*
+ * @test
+ * @bug 6661247
+ * @summary Internal bug in 32-bit HotSpot optimizer while bit manipulations
+ */
+
+import java.util.Random;
+import java.nio.*;
+
+// This isn't a completely reliable test for 6661247 since the results
+// depend on what the local schedule looks like but it does reproduce
+// the issue in current builds.
+
+public class Test {
+
+ public static void test(boolean[] src, int srcPos, LongBuffer dest, long destPos, int count) {
+ int countStart = (destPos & 63) == 0 ? 0 : 64 - (int)(destPos & 63);
+ if (countStart > count)
+ countStart = count;
+ for (int srcPosMax = srcPos + countStart; srcPos < srcPosMax; srcPos++, destPos++) {
+ if (src[srcPos])
+ dest.put((int)(destPos >>> 6), dest.get((int)(destPos >>> 6)) | 1L << (destPos & 63));
+ else
+ dest.put((int)(destPos >>> 6), dest.get((int)(destPos >>> 6)) & ~(1L << (destPos & 63)));
+ }
+ count -= countStart;
+ int cnt = count >>> 6;
+ for (int k = (int)(destPos >>> 6), kMax = k + cnt; k < kMax; k++) {
+ int low = (src[srcPos] ? 1 : 0)
+ | (src[srcPos + 1] ? 1 << 1 : 0)
+ | (src[srcPos + 2] ? 1 << 2 : 0)
+ | (src[srcPos + 3] ? 1 << 3 : 0)
+ | (src[srcPos + 4] ? 1 << 4 : 0)
+ | (src[srcPos + 5] ? 1 << 5 : 0)
+ | (src[srcPos + 6] ? 1 << 6 : 0)
+ | (src[srcPos + 7] ? 1 << 7 : 0)
+ | (src[srcPos + 8] ? 1 << 8 : 0)
+ | (src[srcPos + 9] ? 1 << 9 : 0)
+ | (src[srcPos + 10] ? 1 << 10 : 0)
+ | (src[srcPos + 11] ? 1 << 11 : 0)
+ | (src[srcPos + 12] ? 1 << 12 : 0)
+ | (src[srcPos + 13] ? 1 << 13 : 0)
+ | (src[srcPos + 14] ? 1 << 14 : 0)
+ | (src[srcPos + 15] ? 1 << 15 : 0)
+ | (src[srcPos + 16] ? 1 << 16 : 0)
+ | (src[srcPos + 17] ? 1 << 17 : 0)
+ | (src[srcPos + 18] ? 1 << 18 : 0)
+ | (src[srcPos + 19] ? 1 << 19 : 0)
+ | (src[srcPos + 20] ? 1 << 20 : 0)
+ | (src[srcPos + 21] ? 1 << 21 : 0)
+ | (src[srcPos + 22] ? 1 << 22 : 0)
+ | (src[srcPos + 23] ? 1 << 23 : 0)
+ | (src[srcPos + 24] ? 1 << 24 : 0)
+ | (src[srcPos + 25] ? 1 << 25 : 0)
+ | (src[srcPos + 26] ? 1 << 26 : 0)
+ | (src[srcPos + 27] ? 1 << 27 : 0)
+ | (src[srcPos + 28] ? 1 << 28 : 0)
+ | (src[srcPos + 29] ? 1 << 29 : 0)
+ | (src[srcPos + 30] ? 1 << 30 : 0)
+ | (src[srcPos + 31] ? 1 << 31 : 0)
+ ;
+ srcPos += 32;
+ int high = (src[srcPos] ? 1 : 0) // PROBLEM!
+ | (src[srcPos + 1] ? 1 << 1 : 0)
+ | (src[srcPos + 2] ? 1 << 2 : 0)
+ | (src[srcPos + 3] ? 1 << 3 : 0)
+ | (src[srcPos + 4] ? 1 << 4 : 0)
+ | (src[srcPos + 5] ? 1 << 5 : 0)
+ | (src[srcPos + 6] ? 1 << 6 : 0)
+ | (src[srcPos + 7] ? 1 << 7 : 0)
+ | (src[srcPos + 8] ? 1 << 8 : 0)
+ | (src[srcPos + 9] ? 1 << 9 : 0)
+ | (src[srcPos + 10] ? 1 << 10 : 0)
+ | (src[srcPos + 11] ? 1 << 11 : 0)
+ | (src[srcPos + 12] ? 1 << 12 : 0)
+ | (src[srcPos + 13] ? 1 << 13 : 0)
+ | (src[srcPos + 14] ? 1 << 14 : 0)
+ | (src[srcPos + 15] ? 1 << 15 : 0)
+ | (src[srcPos + 16] ? 1 << 16 : 0)
+ | (src[srcPos + 17] ? 1 << 17 : 0)
+ | (src[srcPos + 18] ? 1 << 18 : 0)
+ | (src[srcPos + 19] ? 1 << 19 : 0)
+ | (src[srcPos + 20] ? 1 << 20 : 0)
+ | (src[srcPos + 21] ? 1 << 21 : 0)
+ | (src[srcPos + 22] ? 1 << 22 : 0)
+ | (src[srcPos + 23] ? 1 << 23 : 0)
+ | (src[srcPos + 24] ? 1 << 24 : 0)
+ | (src[srcPos + 25] ? 1 << 25 : 0)
+ | (src[srcPos + 26] ? 1 << 26 : 0)
+ | (src[srcPos + 27] ? 1 << 27 : 0)
+ | (src[srcPos + 28] ? 1 << 28 : 0)
+ | (src[srcPos + 29] ? 1 << 29 : 0)
+ | (src[srcPos + 30] ? 1 << 30 : 0)
+ | (src[srcPos + 31] ? 1 << 31 : 0)
+ ;
+ srcPos += 32;
+ dest.put(k, ((long)low & 0xFFFFFFFFL) | (((long)high) << 32));
+ destPos += 64;
+ }
+ int countFinish = count & 63;
+ for (int srcPosMax = srcPos + countFinish; srcPos < srcPosMax; srcPos++, destPos++) {
+ if (src[srcPos])
+ dest.put((int)(destPos >>> 6), dest.get((int)(destPos >>> 6)) | 1L << (destPos & 63));
+ else
+ dest.put((int)(destPos >>> 6), dest.get((int)(destPos >>> 6)) & ~(1L << (destPos & 63)));
+ }
+ }
+ public static void main(String[] args) {
+ Random r = new Random();
+ int entries = 1000;
+ boolean[] src = new boolean[entries * 64];
+ long[] dest = new long[entries];
+ long[] result = new long[entries];
+
+ for (int c = 0; c < 2000; c++) {
+ for (int i = 0; i < entries; i++) {
+ long l = r.nextLong();
+ for (int bit = 0; bit < 64; bit++) {
+ src[i * 64 + bit] = (l & (1L << bit)) != 0;
+ }
+ dest[i] = 0;
+ result[i] = l;
+ }
+ test(src, 0, LongBuffer.wrap(dest, 0, dest.length), 0, src.length);
+ for (int i = 0; i < entries; i++) {
+ if (dest[i] != result[i]) {
+ throw new InternalError(i + ": " + Long.toHexString(dest[i]) + " != " + Long.toHexString(result[i]));
+ }
+ }
+ }
+ }
+}