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 NullCheckDroppingsTest 26 * @bug 8054492 27 * @summary "Casting can result in redundant null checks in generated code" 28 * @library /testlibrary /testlibrary/whitebox /testlibrary/com/oracle/java/testlibrary 29 * @build NullCheckDroppingsTest 30 * @run main ClassFileInstaller sun.hotspot.WhiteBox 31 * sun.hotspot.WhiteBox$WhiteBoxPermission 32 * @run main ClassFileInstaller com.oracle.java.testlibrary.Platform 33 * @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI 34 * -Xmixed -XX:-BackgroundCompilation -XX:-TieredCompilation -XX:CompileThreshold=1000 35 * -XX:CompileCommand=exclude,NullCheckDroppingsTest::runTest NullCheckDroppingsTest 36 */ 37 38 import sun.hotspot.WhiteBox; 39 import sun.hotspot.code.NMethod; 40 import com.oracle.java.testlibrary.Platform; 41 42 import java.lang.reflect.Method; 43 import java.lang.invoke.MethodHandle; 44 import java.lang.invoke.MethodHandles; 45 import java.lang.invoke.MethodType; 46 import java.util.function.BiFunction; 47 48 public class NullCheckDroppingsTest { 49 50 private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox(); 51 52 static final BiFunction<Class, Object, Object> fCast = (c, o) -> c.cast(o); 53 54 static final MethodHandle SET_SSINK; 55 static final MethodHandle MH_CAST; 56 57 static { 58 try { 59 SET_SSINK = MethodHandles.lookup().findSetter(NullCheckDroppingsTest.class, "ssink", String.class); | 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 NullCheckDroppingsTest 26 * @bug 8054492 27 * @summary "Casting can result in redundant null checks in generated code" 28 * @library /testlibrary /../../test/lib /testlibrary/com/oracle/java/testlibrary 29 * @build NullCheckDroppingsTest 30 * @run main ClassFileInstaller jdk.testlib.WhiteBox 31 * jdk.testlib.WhiteBox$WhiteBoxPermission 32 * @run main ClassFileInstaller com.oracle.java.testlibrary.Platform 33 * @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI 34 * -Xmixed -XX:-BackgroundCompilation -XX:-TieredCompilation -XX:CompileThreshold=1000 35 * -XX:CompileCommand=exclude,NullCheckDroppingsTest::runTest NullCheckDroppingsTest 36 */ 37 38 import jdk.testlib.WhiteBox; 39 import jdk.testlib.code.NMethod; 40 import com.oracle.java.testlibrary.Platform; 41 42 import java.lang.reflect.Method; 43 import java.lang.invoke.MethodHandle; 44 import java.lang.invoke.MethodHandles; 45 import java.lang.invoke.MethodType; 46 import java.util.function.BiFunction; 47 48 public class NullCheckDroppingsTest { 49 50 private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox(); 51 52 static final BiFunction<Class, Object, Object> fCast = (c, o) -> c.cast(o); 53 54 static final MethodHandle SET_SSINK; 55 static final MethodHandle MH_CAST; 56 57 static { 58 try { 59 SET_SSINK = MethodHandles.lookup().findSetter(NullCheckDroppingsTest.class, "ssink", String.class); |