twisti@1259: /* trims@1907: * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. twisti@1259: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. twisti@1259: * twisti@1259: * This code is free software; you can redistribute it and/or modify it twisti@1259: * under the terms of the GNU General Public License version 2 only, as twisti@1259: * published by the Free Software Foundation. twisti@1259: * twisti@1259: * This code is distributed in the hope that it will be useful, but WITHOUT twisti@1259: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or twisti@1259: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License twisti@1259: * version 2 for more details (a copy is included in the LICENSE file that twisti@1259: * accompanied this code). twisti@1259: * twisti@1259: * You should have received a copy of the GNU General Public License version twisti@1259: * 2 along with this work; if not, write to the Free Software Foundation, twisti@1259: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. twisti@1259: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. twisti@1259: */ twisti@1259: twisti@1259: /** twisti@1259: * @test twisti@1259: * @bug 5057225 twisti@1259: * @summary Remove useless I2L conversions twisti@1259: * twisti@1259: * @run main/othervm -Xcomp -XX:CompileOnly=Test5057225.doload Test5057225 twisti@1259: */ twisti@1259: twisti@1259: import java.net.URLClassLoader; twisti@1259: twisti@1259: public class Test5057225 { twisti@1259: static byte[] ba = new byte[] { -1 }; twisti@1259: static short[] sa = new short[] { -1 }; twisti@1259: static int[] ia = new int[] { -1 }; twisti@1259: twisti@1259: static final long[] BYTE_MASKS = { twisti@1259: 0x0FL, twisti@1259: 0x7FL, // 7-bit twisti@1259: 0xFFL, twisti@1259: }; twisti@1259: twisti@1259: static final long[] SHORT_MASKS = { twisti@1259: 0x000FL, twisti@1259: 0x007FL, // 7-bit twisti@1259: 0x00FFL, twisti@1259: 0x0FFFL, twisti@1259: 0x3FFFL, // 14-bit twisti@1259: 0x7FFFL, // 15-bit twisti@1259: 0xFFFFL, twisti@1259: }; twisti@1259: twisti@1259: static final long[] INT_MASKS = { twisti@1259: 0x0000000FL, twisti@1259: 0x0000007FL, // 7-bit twisti@1259: 0x000000FFL, twisti@1259: 0x00000FFFL, twisti@1259: 0x00003FFFL, // 14-bit twisti@1259: 0x00007FFFL, // 15-bit twisti@1259: 0x0000FFFFL, twisti@1259: 0x00FFFFFFL, twisti@1259: 0x7FFFFFFFL, // 31-bit twisti@1259: 0xFFFFFFFFL, twisti@1259: }; twisti@1259: twisti@1259: public static void main(String[] args) throws Exception { twisti@1259: for (int i = 0; i < BYTE_MASKS.length; i++) { twisti@1259: System.setProperty("value", "" + BYTE_MASKS[i]); twisti@1259: loadAndRunClass("Test5057225$loadUB2L"); twisti@1259: } twisti@1259: twisti@1259: for (int i = 0; i < SHORT_MASKS.length; i++) { twisti@1259: System.setProperty("value", "" + SHORT_MASKS[i]); twisti@1259: loadAndRunClass("Test5057225$loadUS2L"); twisti@1259: } twisti@1259: twisti@1259: for (int i = 0; i < INT_MASKS.length; i++) { twisti@1259: System.setProperty("value", "" + INT_MASKS[i]); twisti@1259: loadAndRunClass("Test5057225$loadUI2L"); twisti@1259: } twisti@1259: } twisti@1259: twisti@1259: static void check(long result, long expected) { twisti@1259: if (result != expected) twisti@1259: throw new InternalError(result + " != " + expected); twisti@1259: } twisti@1259: twisti@1259: static void loadAndRunClass(String classname) throws Exception { twisti@1259: Class cl = Class.forName(classname); twisti@1259: URLClassLoader apploader = (URLClassLoader) cl.getClassLoader(); twisti@1259: ClassLoader loader = new URLClassLoader(apploader.getURLs(), apploader.getParent()); twisti@1259: Class c = loader.loadClass(classname); twisti@1259: Runnable r = (Runnable) c.newInstance(); twisti@1259: r.run(); twisti@1259: } twisti@1259: twisti@1259: public static class loadUB2L implements Runnable { twisti@1259: static final long MASK; twisti@1259: static { twisti@1259: long value = 0; twisti@1259: try { twisti@1259: value = Long.decode(System.getProperty("value")); twisti@1259: } catch (Throwable e) {} twisti@1259: MASK = value; twisti@1259: } twisti@1259: twisti@1259: public void run() { check(doload(ba), MASK); } twisti@1259: static long doload(byte[] ba) { return ba[0] & MASK; } twisti@1259: } twisti@1259: twisti@1259: public static class loadUS2L implements Runnable { twisti@1259: static final long MASK; twisti@1259: static { twisti@1259: long value = 0; twisti@1259: try { twisti@1259: value = Long.decode(System.getProperty("value")); twisti@1259: } catch (Throwable e) {} twisti@1259: MASK = value; twisti@1259: } twisti@1259: twisti@1259: public void run() { check(doload(sa), MASK); } twisti@1259: static long doload(short[] sa) { return sa[0] & MASK; } twisti@1259: } twisti@1259: twisti@1259: public static class loadUI2L implements Runnable { twisti@1259: static final long MASK; twisti@1259: static { twisti@1259: long value = 0; twisti@1259: try { twisti@1259: value = Long.decode(System.getProperty("value")); twisti@1259: } catch (Throwable e) {} twisti@1259: MASK = value; twisti@1259: } twisti@1259: twisti@1259: public void run() { check(doload(ia), MASK); } twisti@1259: static long doload(int[] ia) { return ia[0] & MASK; } twisti@1259: } twisti@1259: }