Path: blob/master/test/hotspot/jtreg/compiler/stable/TestStableUShort.java
41152 views
/*1* Copyright (c) 2016, 2018, 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* @test TestStableUShort25* @summary tests on stable fields and arrays26* @library /test/lib /27* @modules java.base/jdk.internal.misc28* @modules java.base/jdk.internal.vm.annotation29* @build sun.hotspot.WhiteBox30*31* @run main/bootclasspath/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+AlwaysIncrementalInline32* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp33* -XX:-TieredCompilation34* -XX:+FoldStableValues35* -XX:CompileOnly=::get,::get136* compiler.stable.TestStableUShort37* @run main/bootclasspath/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+AlwaysIncrementalInline38* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp39* -XX:-TieredCompilation40* -XX:-FoldStableValues41* -XX:CompileOnly=::get,::get142* compiler.stable.TestStableUShort43*44* @run main/bootclasspath/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+AlwaysIncrementalInline45* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp46* -XX:+TieredCompilation -XX:TieredStopAtLevel=147* -XX:+FoldStableValues48* -XX:CompileOnly=::get,::get149* compiler.stable.TestStableUShort50* @run main/bootclasspath/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+AlwaysIncrementalInline51* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp52* -XX:+TieredCompilation -XX:TieredStopAtLevel=153* -XX:-FoldStableValues54* -XX:CompileOnly=::get,::get155* compiler.stable.TestStableUShort56*/5758package compiler.stable;5960import jdk.internal.vm.annotation.Stable;6162import java.lang.reflect.InvocationTargetException;6364public class TestStableUShort {65static final boolean isStableEnabled = StableConfiguration.isStableEnabled;6667public static void main(String[] args) throws Exception {68run(UShortStable.class);69run(UShortArrayDim1.class);7071if (failed) {72throw new Error("TEST FAILED");73}74}7576/* ==================================================== */7778static class UShortStable {79public @Stable short v;8081public static final UShortStable c = new UShortStable();8283public static int get() { return c.v & 0xFFFF; }8485public static void test() throws Exception {86short v1 = -1, v2 = 1;8788c.v = v1; int r1 = get();89c.v = v2; int r2 = get();9091assertEquals(r1, v1 & 0xFFFF);92assertEquals(r2, (isStableEnabled ? v1 : v2) & 0xFFFF);93}94}9596/* ==================================================== */9798static class UShortArrayDim1 {99public @Stable short[] v;100101public static final UShortArrayDim1 c = new UShortArrayDim1();102103public static short[] get() { return c.v; }104public static int get1() { return get()[0] & 0xFFFF; }105106public static void test() throws Exception {107short v1 = -1, v2 = 1;108109c.v = new short[1];110c.v[0] = v1; int r1 = get1();111c.v[0] = v2; int r2 = get1();112113assertEquals(r1, v1 & 0xFFFF);114assertEquals(r2, (isStableEnabled ? v1 : v2) & 0xFFFF);115}116}117118/* ==================================================== */119// Auxiliary methods120static void assertEquals(int i, int j) { if (i != j) throw new AssertionError(i + " != " + j); }121static void assertTrue(boolean b) { if (!b) throw new AssertionError(); }122123static boolean failed = false;124125public static void run(Class<?> test) {126Throwable ex = null;127System.out.print(test.getName()+": ");128try {129test.getMethod("test").invoke(null);130} catch (InvocationTargetException e) {131ex = e.getCause();132} catch (Throwable e) {133ex = e;134} finally {135if (ex == null) {136System.out.println("PASSED");137} else {138failed = true;139System.out.println("FAILED");140ex.printStackTrace(System.out);141}142}143}144}145146147