9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 /*
26 * @test
27 * @bug 6778657
28 * @summary Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
29 */
30
31 public class Test {
32 public static void check_f2i(int expect) {
33 float check = expect;
34 check *= 2;
35 int actual = (int) check;
36 if (actual != expect)
37 throw new RuntimeException("expecting " + expect + ", got " + actual);
38 }
39
40 public static void check_f2l(long expect) {
41 float check = expect;
42 check *= 2;
43 long actual = (long) check;
44 if (actual != expect)
45 throw new RuntimeException("expecting " + expect + ", got " + actual);
46 }
47
48 public static void check_d2i(int expect) {
49 double check = expect;
50 check *= 2;
51 int actual = (int) check;
52 if (actual != expect)
53 throw new RuntimeException("expecting " + expect + ", got " + actual);
54 }
55
56 public static void check_d2l(long expect) {
57 double check = expect;
58 check *= 2;
59 long actual = (long) check;
60 if (actual != expect)
61 throw new RuntimeException("expecting " + expect + ", got " + actual);
62 }
63
64 public static void main(String[] args) {
65 check_f2i(Integer.MAX_VALUE);
66 check_f2i(Integer.MIN_VALUE);
67 check_f2l(Long.MAX_VALUE);
68 check_f2l(Long.MIN_VALUE);
69 check_d2i(Integer.MAX_VALUE);
70 check_d2i(Integer.MIN_VALUE);
71 check_d2l(Long.MAX_VALUE);
72 check_d2l(Long.MIN_VALUE);
73 }
74 }
75
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 /*
26 * @test
27 * @bug 6778657
28 * @summary Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
29 *
30 * @run main compiler.runtime.Test6778657
31 */
32
33 package compiler.runtime;
34
35 public class Test6778657 {
36 public static void check_f2i(int expect) {
37 float check = expect;
38 check *= 2;
39 int actual = (int) check;
40 if (actual != expect) {
41 throw new RuntimeException("expecting " + expect + ", got " + actual);
42 }
43 }
44
45 public static void check_f2l(long expect) {
46 float check = expect;
47 check *= 2;
48 long actual = (long) check;
49 if (actual != expect) {
50 throw new RuntimeException("expecting " + expect + ", got " + actual);
51 }
52 }
53
54 public static void check_d2i(int expect) {
55 double check = expect;
56 check *= 2;
57 int actual = (int) check;
58 if (actual != expect) {
59 throw new RuntimeException("expecting " + expect + ", got " + actual);
60 }
61 }
62
63 public static void check_d2l(long expect) {
64 double check = expect;
65 check *= 2;
66 long actual = (long) check;
67 if (actual != expect) {
68 throw new RuntimeException("expecting " + expect + ", got " + actual);
69 }
70 }
71
72 public static void main(String[] args) {
73 check_f2i(Integer.MAX_VALUE);
74 check_f2i(Integer.MIN_VALUE);
75 check_f2l(Long.MAX_VALUE);
76 check_f2l(Long.MIN_VALUE);
77 check_d2i(Integer.MAX_VALUE);
78 check_d2i(Integer.MIN_VALUE);
79 check_d2l(Long.MAX_VALUE);
80 check_d2l(Long.MIN_VALUE);
81 }
82 }
83
|