1 /* 2 * Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 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 * @test 26 * @bug 5057225 27 * @summary Remove useless I2L conversions 28 * @modules java.base/jdk.internal.misc 29 * @library /testlibrary 30 * 31 * @run main/othervm -Xcomp 32 * -XX:CompileCommand=compileonly,compiler.c2.Test5057225::doload 33 * compiler.c2.Test5057225 34 */ 35 36 package compiler.c2; 37 import jdk.test.lib.Utils; 38 39 public class Test5057225 { 40 static byte[] ba = new byte[] { -1 }; 41 static short[] sa = new short[] { -1 }; 42 static int[] ia = new int[] { -1 }; 43 44 static final long[] BYTE_MASKS = { 45 0x0FL, 46 0x7FL, // 7-bit 47 0xFFL, 48 }; 49 50 static final long[] SHORT_MASKS = { 51 0x000FL, 52 0x007FL, // 7-bit 53 0x00FFL, 54 0x0FFFL, 55 0x3FFFL, // 14-bit 56 0x7FFFL, // 15-bit 57 0xFFFFL, 58 }; 59 60 static final long[] INT_MASKS = { 61 0x0000000FL, 62 0x0000007FL, // 7-bit 63 0x000000FFL, 64 0x00000FFFL, 65 0x00003FFFL, // 14-bit 66 0x00007FFFL, // 15-bit 67 0x0000FFFFL, 68 0x00FFFFFFL, 69 0x7FFFFFFFL, // 31-bit 70 0xFFFFFFFFL, 71 }; 72 73 public static void main(String[] args) throws Exception { 74 for (int i = 0; i < BYTE_MASKS.length; i++) { 75 System.setProperty("value", "" + BYTE_MASKS[i]); 76 loadAndRunClass(Test5057225.class.getName() + "$loadUB2L"); 77 } 78 79 for (int i = 0; i < SHORT_MASKS.length; i++) { 80 System.setProperty("value", "" + SHORT_MASKS[i]); 81 loadAndRunClass(Test5057225.class.getName() + "$loadUS2L"); 82 } 83 84 for (int i = 0; i < INT_MASKS.length; i++) { 85 System.setProperty("value", "" + INT_MASKS[i]); 86 loadAndRunClass(Test5057225.class.getName() + "$loadUI2L"); 87 } 88 } 89 90 static void check(long result, long expected) { 91 if (result != expected) 92 throw new InternalError(result + " != " + expected); 93 } 94 95 static void loadAndRunClass(String classname) throws Exception { 96 Class cl = Class.forName(classname); 97 ClassLoader apploader = cl.getClassLoader(); 98 ClassLoader loader 99 = Utils.getTestClassPathURLClassLoader(apploader.getParent()); 100 Class c = loader.loadClass(classname); 101 Runnable r = (Runnable) c.newInstance(); 102 r.run(); 103 } 104 105 public static class loadUB2L implements Runnable { 106 static final long MASK; 107 static { 108 long value = 0; 109 try { 110 value = Long.decode(System.getProperty("value")); 111 } catch (Throwable e) {} 112 MASK = value; 113 } 114 115 public void run() { check(doload(ba), MASK); } 116 static long doload(byte[] ba) { return ba[0] & MASK; } 117 } 118 119 public static class loadUS2L implements Runnable { 120 static final long MASK; 121 static { 122 long value = 0; 123 try { 124 value = Long.decode(System.getProperty("value")); 125 } catch (Throwable e) {} 126 MASK = value; 127 } 128 129 public void run() { check(doload(sa), MASK); } 130 static long doload(short[] sa) { return sa[0] & MASK; } 131 } 132 133 public static class loadUI2L implements Runnable { 134 static final long MASK; 135 static { 136 long value = 0; 137 try { 138 value = Long.decode(System.getProperty("value")); 139 } catch (Throwable e) {} 140 MASK = value; 141 } 142 143 public void run() { check(doload(ia), MASK); } 144 static long doload(int[] ia) { return ia[0] & MASK; } 145 } 146 }