Sat, 07 Nov 2020 10:30:02 +0800
Added tag mips-jdk8u275-b01 for changeset eb6ee6a5f2fe
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. |
aoqi@0 | 8 | * |
aoqi@0 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 13 | * accompanied this code). |
aoqi@0 | 14 | * |
aoqi@0 | 15 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 18 | * |
aoqi@0 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 20 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 21 | * questions. |
aoqi@0 | 22 | */ |
aoqi@0 | 23 | |
aoqi@0 | 24 | /* |
aoqi@0 | 25 | * @test |
aoqi@0 | 26 | * @bug 6860965 |
aoqi@0 | 27 | * @summary Project Coin: binary literals |
aoqi@0 | 28 | */ |
aoqi@0 | 29 | |
aoqi@0 | 30 | public class BinaryLiterals { |
aoqi@0 | 31 | public static void main(String... args) throws Exception { |
aoqi@0 | 32 | new BinaryLiterals().run(); |
aoqi@0 | 33 | } |
aoqi@0 | 34 | |
aoqi@0 | 35 | public void run() throws Exception { |
aoqi@0 | 36 | test(0, 0B0); |
aoqi@0 | 37 | test(1, 0B1); |
aoqi@0 | 38 | test(2, 0B10); |
aoqi@0 | 39 | test(3, 0B11); |
aoqi@0 | 40 | |
aoqi@0 | 41 | test(0, 0b0); |
aoqi@0 | 42 | test(1, 0b1); |
aoqi@0 | 43 | test(2, 0b10); |
aoqi@0 | 44 | test(3, 0b11); |
aoqi@0 | 45 | |
aoqi@0 | 46 | test(-0, -0b0); |
aoqi@0 | 47 | test(-1, -0b1); |
aoqi@0 | 48 | test(-2, -0b10); |
aoqi@0 | 49 | test(-3, -0b11); |
aoqi@0 | 50 | |
aoqi@0 | 51 | test(-1, 0b11111111111111111111111111111111); |
aoqi@0 | 52 | test(-2, 0b11111111111111111111111111111110); |
aoqi@0 | 53 | test(-3, 0b11111111111111111111111111111101); |
aoqi@0 | 54 | |
aoqi@0 | 55 | test( 1, -0b11111111111111111111111111111111); |
aoqi@0 | 56 | test( 2, -0b11111111111111111111111111111110); |
aoqi@0 | 57 | test( 3, -0b11111111111111111111111111111101); |
aoqi@0 | 58 | |
aoqi@0 | 59 | test(0, 0b00); |
aoqi@0 | 60 | test(1, 0b001); |
aoqi@0 | 61 | test(2, 0b00010); |
aoqi@0 | 62 | test(3, 0b000011); |
aoqi@0 | 63 | |
aoqi@0 | 64 | // aaaabbbbccccddddeeeeffffgggghhhh |
aoqi@0 | 65 | test( 0x10, 0b10000); |
aoqi@0 | 66 | test( 0x100, 0b100000000); |
aoqi@0 | 67 | test( 0x10000, 0b10000000000000000); |
aoqi@0 | 68 | test(0x80000000, 0b10000000000000000000000000000000); |
aoqi@0 | 69 | test(0xffffffff, 0b11111111111111111111111111111111); |
aoqi@0 | 70 | |
aoqi@0 | 71 | test(0L, 0b0L); |
aoqi@0 | 72 | test(1L, 0b1L); |
aoqi@0 | 73 | test(2L, 0b10L); |
aoqi@0 | 74 | test(3L, 0b11L); |
aoqi@0 | 75 | |
aoqi@0 | 76 | test(0, 0b00L); |
aoqi@0 | 77 | test(1, 0b001L); |
aoqi@0 | 78 | test(2, 0b00010L); |
aoqi@0 | 79 | test(3, 0b000011L); |
aoqi@0 | 80 | |
aoqi@0 | 81 | // aaaabbbbccccddddeeeeffffgggghhhhiiiijjjjkkkkllllmmmmnnnnoooopppp |
aoqi@0 | 82 | test( 0x10L, 0b10000L); |
aoqi@0 | 83 | test( 0x100L, 0b100000000L); |
aoqi@0 | 84 | test( 0x10000L, 0b10000000000000000L); |
aoqi@0 | 85 | test( 0x80000000L, 0b10000000000000000000000000000000L); |
aoqi@0 | 86 | test( 0xffffffffL, 0b11111111111111111111111111111111L); |
aoqi@0 | 87 | test(0x8000000000000000L, 0b1000000000000000000000000000000000000000000000000000000000000000L); |
aoqi@0 | 88 | test(0xffffffffffffffffL, 0b1111111111111111111111111111111111111111111111111111111111111111L); |
aoqi@0 | 89 | |
aoqi@0 | 90 | test(0l, 0b0l); |
aoqi@0 | 91 | test(1l, 0b1l); |
aoqi@0 | 92 | test(2l, 0b10l); |
aoqi@0 | 93 | test(3l, 0b11l); |
aoqi@0 | 94 | |
aoqi@0 | 95 | test(0, 0b00l); |
aoqi@0 | 96 | test(1, 0b001l); |
aoqi@0 | 97 | test(2, 0b00010l); |
aoqi@0 | 98 | test(3, 0b000011l); |
aoqi@0 | 99 | |
aoqi@0 | 100 | // aaaabbbbccccddddeeeeffffgggghhhhiiiijjjjkkkkllllmmmmnnnnoooopppp |
aoqi@0 | 101 | test( 0x10l, 0b10000l); |
aoqi@0 | 102 | test( 0x100l, 0b100000000l); |
aoqi@0 | 103 | test( 0x10000l, 0b10000000000000000l); |
aoqi@0 | 104 | test( 0x80000000l, 0b10000000000000000000000000000000l); |
aoqi@0 | 105 | test( 0xffffffffl, 0b11111111111111111111111111111111l); |
aoqi@0 | 106 | test(0x8000000000000000l, 0b1000000000000000000000000000000000000000000000000000000000000000l); |
aoqi@0 | 107 | test(0xffffffffffffffffl, 0b1111111111111111111111111111111111111111111111111111111111111111l); |
aoqi@0 | 108 | |
aoqi@0 | 109 | if (errors > 0) |
aoqi@0 | 110 | throw new Exception(errors + " errors found"); |
aoqi@0 | 111 | } |
aoqi@0 | 112 | |
aoqi@0 | 113 | void test(int expect, int found) { |
aoqi@0 | 114 | count++; |
aoqi@0 | 115 | if (found != expect) |
aoqi@0 | 116 | error("test " + count + "\nexpected: 0x" + Integer.toHexString(expect) + "\n found: 0x" + Integer.toHexString(found)); |
aoqi@0 | 117 | } |
aoqi@0 | 118 | |
aoqi@0 | 119 | void test(long expect, long found) { |
aoqi@0 | 120 | count++; |
aoqi@0 | 121 | if (found != expect) |
aoqi@0 | 122 | error("test " + count + "\nexpected: 0x" + Long.toHexString(expect) + "\n found: 0x" + Long.toHexString(found)); |
aoqi@0 | 123 | } |
aoqi@0 | 124 | |
aoqi@0 | 125 | void error(String message) { |
aoqi@0 | 126 | System.out.println(message); |
aoqi@0 | 127 | errors++; |
aoqi@0 | 128 | } |
aoqi@0 | 129 | |
aoqi@0 | 130 | int count; |
aoqi@0 | 131 | int errors; |
aoqi@0 | 132 | } |