Path: blob/master/test/hotspot/jtreg/compiler/conversions/TestPrimitiveConversions.java
41152 views
/*1* Copyright (c) 2019, 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*/2223package compiler.conversions;2425import jdk.test.lib.Asserts;2627/*28* @test29* @bug 823461730* @summary Test implicit narrowing conversion of primivite values at putfield.31* @library /test/lib /32* @compile Conversion.jasm33* @run main/othervm -Xbatch -XX:CompileCommand=dontinline,compiler.conversions.Conversion::*34* compiler.conversions.TestPrimitiveConversions35*/36public class TestPrimitiveConversions {3738public static void main(String[] args) {39Conversion conv = new Conversion();40for (int i = 0; i < 100_000; ++i) {41int res = conv.testBooleanConst();42Asserts.assertEquals(res, 0);43res = conv.testBoolean(2); // 2^1 (maximum boolean value is 1)44Asserts.assertEquals(res, 0);45res = conv.testByteConst();46Asserts.assertEquals(res, 0);47res = conv.testByte(256); // 2^8 (maximum byte value is 2^7-1)48Asserts.assertEquals(res, 0);49res = conv.testCharConst();50Asserts.assertEquals(res, 0);51res = conv.testChar(131072); // 2^17 (maximum char value is 2^16-1)52Asserts.assertEquals(res, 0);53res = conv.testShortConst();54Asserts.assertEquals(res, 0);55res = conv.testShort(65536); // 2^16 (maximum short value is 2^15-1)56Asserts.assertEquals(res, 0);57}58}59}606162