Path: blob/master/test/hotspot/jtreg/compiler/c2/Test5057225.java
41149 views
/*1* Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 505722526* @summary Remove useless I2L conversions27* @modules java.base/jdk.internal.misc28* @library /test/lib29*30* @run main/othervm -Xcomp31* -XX:CompileCommand=compileonly,compiler.c2.Test5057225::doload32* compiler.c2.Test505722533*/3435package compiler.c2;36import jdk.test.lib.Utils;3738public class Test5057225 {39static byte[] ba = new byte[] { -1 };40static short[] sa = new short[] { -1 };41static int[] ia = new int[] { -1 };4243static final long[] BYTE_MASKS = {440x0FL,450x7FL, // 7-bit460xFFL,47};4849static final long[] SHORT_MASKS = {500x000FL,510x007FL, // 7-bit520x00FFL,530x0FFFL,540x3FFFL, // 14-bit550x7FFFL, // 15-bit560xFFFFL,57};5859static final long[] INT_MASKS = {600x0000000FL,610x0000007FL, // 7-bit620x000000FFL,630x00000FFFL,640x00003FFFL, // 14-bit650x00007FFFL, // 15-bit660x0000FFFFL,670x00FFFFFFL,680x7FFFFFFFL, // 31-bit690xFFFFFFFFL,70};7172public static void main(String[] args) throws Exception {73for (int i = 0; i < BYTE_MASKS.length; i++) {74System.setProperty("value", "" + BYTE_MASKS[i]);75loadAndRunClass(Test5057225.class.getName() + "$loadUB2L");76}7778for (int i = 0; i < SHORT_MASKS.length; i++) {79System.setProperty("value", "" + SHORT_MASKS[i]);80loadAndRunClass(Test5057225.class.getName() + "$loadUS2L");81}8283for (int i = 0; i < INT_MASKS.length; i++) {84System.setProperty("value", "" + INT_MASKS[i]);85loadAndRunClass(Test5057225.class.getName() + "$loadUI2L");86}87}8889static void check(long result, long expected) {90if (result != expected)91throw new InternalError(result + " != " + expected);92}9394static void loadAndRunClass(String classname) throws Exception {95Class cl = Class.forName(classname);96ClassLoader apploader = cl.getClassLoader();97ClassLoader loader98= Utils.getTestClassPathURLClassLoader(apploader.getParent());99Class c = loader.loadClass(classname);100Runnable r = (Runnable) c.newInstance();101r.run();102}103104public static class loadUB2L implements Runnable {105static final long MASK;106static {107long value = 0;108try {109value = Long.decode(System.getProperty("value"));110} catch (Throwable e) {}111MASK = value;112}113114public void run() { check(doload(ba), MASK); }115static long doload(byte[] ba) { return ba[0] & MASK; }116}117118public static class loadUS2L implements Runnable {119static final long MASK;120static {121long value = 0;122try {123value = Long.decode(System.getProperty("value"));124} catch (Throwable e) {}125MASK = value;126}127128public void run() { check(doload(sa), MASK); }129static long doload(short[] sa) { return sa[0] & MASK; }130}131132public static class loadUI2L implements Runnable {133static final long MASK;134static {135long value = 0;136try {137value = Long.decode(System.getProperty("value"));138} catch (Throwable e) {}139MASK = value;140}141142public void run() { check(doload(ia), MASK); }143static long doload(int[] ia) { return ia[0] & MASK; }144}145}146147148