6805724: ModLNode::Ideal() generates functionally incorrect graph when divisor is any (2^k-1) constant.

Mon, 16 Feb 2009 07:19:26 -0800

author
twisti
date
Mon, 16 Feb 2009 07:19:26 -0800
changeset 1003
30663ca5e8f4
parent 1002
bbef4344adb2
child 1004
2cacccded90f

6805724: ModLNode::Ideal() generates functionally incorrect graph when divisor is any (2^k-1) constant.
Summary: C2, ModLNode::Ideal() generates functionally incorrect graph when divisor is any (2^k-1) constant.
Reviewed-by: rasbold

src/share/vm/opto/divnode.cpp file | annotate | diff | comparison | revisions
src/share/vm/utilities/globalDefinitions.hpp file | annotate | diff | comparison | revisions
test/compiler/6805724/Test6805724.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/vm/opto/divnode.cpp	Fri Feb 13 09:09:35 2009 -0800
     1.2 +++ b/src/share/vm/opto/divnode.cpp	Mon Feb 16 07:19:26 2009 -0800
     1.3 @@ -1007,7 +1007,7 @@
     1.4  
     1.5    // Expand mod
     1.6    if( con >= 0 && con < max_jlong && is_power_of_2_long(con+1) ) {
     1.7 -    uint k = log2_long(con);       // Extract k
     1.8 +    uint k = exact_log2_long(con+1);  // Extract k
     1.9  
    1.10      // Basic algorithm by David Detlefs.  See fastmod_long.java for gory details.
    1.11      // Used to help a popular random number generator which does a long-mod
     2.1 --- a/src/share/vm/utilities/globalDefinitions.hpp	Fri Feb 13 09:09:35 2009 -0800
     2.2 +++ b/src/share/vm/utilities/globalDefinitions.hpp	Mon Feb 16 07:19:26 2009 -0800
     2.3 @@ -907,6 +907,14 @@
     2.4    return log2_intptr(x);
     2.5  }
     2.6  
     2.7 +//* the argument must be exactly a power of 2
     2.8 +inline int exact_log2_long(jlong x) {
     2.9 +  #ifdef ASSERT
    2.10 +    if (!is_power_of_2_long(x)) basic_fatal("x must be a power of 2");
    2.11 +  #endif
    2.12 +  return log2_long(x);
    2.13 +}
    2.14 +
    2.15  
    2.16  // returns integer round-up to the nearest multiple of s (s must be a power of two)
    2.17  inline intptr_t round_to(intptr_t x, uintx s) {
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/compiler/6805724/Test6805724.java	Mon Feb 16 07:19:26 2009 -0800
     3.3 @@ -0,0 +1,80 @@
     3.4 +/*
     3.5 + * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
     3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3.7 + *
     3.8 + * This code is free software; you can redistribute it and/or modify it
     3.9 + * under the terms of the GNU General Public License version 2 only, as
    3.10 + * published by the Free Software Foundation.
    3.11 + *
    3.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    3.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    3.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    3.15 + * version 2 for more details (a copy is included in the LICENSE file that
    3.16 + * accompanied this code).
    3.17 + *
    3.18 + * You should have received a copy of the GNU General Public License version
    3.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    3.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    3.21 + *
    3.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    3.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    3.24 + * have any questions.
    3.25 + */
    3.26 +
    3.27 +/**
    3.28 + * @test
    3.29 + * @bug 6805724
    3.30 + * @summary ModLNode::Ideal() generates functionally incorrect graph when divisor is any (2^k-1) constant.
    3.31 + *
    3.32 + * @run main/othervm -Xcomp -XX:CompileOnly=Test6805724.fcomp Test6805724
    3.33 + */
    3.34 +
    3.35 +import java.net.URLClassLoader;
    3.36 +
    3.37 +public class Test6805724 implements Runnable {
    3.38 +    // Initialize DIVISOR so that it is final in this class.
    3.39 +    static final long DIVISOR;  // 2^k-1 constant
    3.40 +
    3.41 +    static {
    3.42 +        long value = 0;
    3.43 +        try {
    3.44 +            value = Long.decode(System.getProperty("divisor"));
    3.45 +        } catch (Throwable t) {
    3.46 +            // This one is required for the Class.forName() in main.
    3.47 +        }
    3.48 +        DIVISOR = value;
    3.49 +    }
    3.50 +
    3.51 +    static long fint(long x) {
    3.52 +        return x % DIVISOR;
    3.53 +    }
    3.54 +
    3.55 +    static long fcomp(long x) {
    3.56 +        return x % DIVISOR;
    3.57 +    }
    3.58 +
    3.59 +    public void run() {
    3.60 +        long a = 0x617981E1L;
    3.61 +
    3.62 +        long expected = fint(a);
    3.63 +        long result = fcomp(a);
    3.64 +
    3.65 +        if (result != expected)
    3.66 +            throw new InternalError(result + " != " + expected);
    3.67 +    }
    3.68 +
    3.69 +    public static void main(String args[]) throws Exception {
    3.70 +        Class cl = Class.forName("Test6805724");
    3.71 +        URLClassLoader apploader = (URLClassLoader) cl.getClassLoader();
    3.72 +
    3.73 +        // Iterate over all 2^k-1 divisors.
    3.74 +        for (int k = 1; k < Long.SIZE; k++) {
    3.75 +            long divisor = (1L << k) - 1;
    3.76 +            System.setProperty("divisor", "" + divisor);
    3.77 +            ClassLoader loader = new URLClassLoader(apploader.getURLs(), apploader.getParent());
    3.78 +            Class c = loader.loadClass("Test6805724");
    3.79 +            Runnable r = (Runnable) c.newInstance();
    3.80 +            r.run();
    3.81 +        }
    3.82 +    }
    3.83 +}

mercurial