Path: blob/master/test/hotspot/jtreg/compiler/c1/Test6932496.java
41149 views
/*1* Copyright (c) 2010, 2015, 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 693249626* @summary incorrect deopt of jsr subroutine on 64 bit c127* @modules java.base/jdk.internal.org.objectweb.asm28*29* @run main/othervm -Xcomp30* -XX:CompileCommand=compileonly,compiler.c1.Test6932496::test31* compiler.c1.Test693249632*/3334package compiler.c1;3536import jdk.internal.org.objectweb.asm.ClassWriter;37import jdk.internal.org.objectweb.asm.FieldVisitor;38import jdk.internal.org.objectweb.asm.Label;39import jdk.internal.org.objectweb.asm.MethodVisitor;40import jdk.internal.org.objectweb.asm.Opcodes;41import jdk.internal.org.objectweb.asm.Type;4243import java.io.IOException;44import java.lang.reflect.Method;45import java.nio.file.Files;46import java.nio.file.Paths;4748public class Test6932496 extends ClassLoader {49private static final int CLASS_FILE_VERSION = 49;50private static final String CLASS_TEST = "Test";51private static final String CLASS_OBJECT = "java/lang/Object";52private static final String METHOD_INIT = "<init>";53private static final String METHOD_TEST = "test";54private static final String DESC_VOID_METHOD = "()V";55private static final String FIELD_FLAG = "flag";5657public static void main(String[] args) {58Test6932496 test = new Test6932496();59test.execute();60}6162private void execute() {63byte[] bytecode = Test6932496.generateTestClass();6465try {66Files.write(Paths.get("Test.class.dump"), bytecode);67} catch (IOException e) {68System.err.println("classfile dump failed : " + e.getMessage());69e.printStackTrace();70}71try {72Class aClass = defineClass(CLASS_TEST, bytecode, 0, bytecode.length);73Method test = aClass.getDeclaredMethod(METHOD_TEST);74test.invoke(null);75} catch (ClassFormatError | IllegalArgumentException76| ReflectiveOperationException e) {77throw new RuntimeException("TESTBUG : generated class is invalid", e);78}79}8081/*82public class Test {83volatile boolean flag = false;84public static void m() {85try {86} finally {87Test test = new Test();88test.flag = true;89}90}91}92*/93private static byte[] generateTestClass() {94ClassWriter cw = new ClassWriter(0);95cw.visit(CLASS_FILE_VERSION, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER,96CLASS_TEST, null, CLASS_OBJECT, null);97// volatile boolean flag;98{99FieldVisitor fv = cw.visitField(Opcodes.ACC_VOLATILE, FIELD_FLAG,100Type.BOOLEAN_TYPE.getDescriptor(),101/* signature = */ null, /* value = */ null);102}103104/*105public Test() {106flag = false;107}108*/109{110MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC,111METHOD_INIT, DESC_VOID_METHOD,112/* signature = */ null, /* exceptions = */ null);113114mv.visitCode();115mv.visitVarInsn(Opcodes.ALOAD, 0);116mv.visitMethodInsn(Opcodes.INVOKESPECIAL, CLASS_OBJECT, METHOD_INIT,117DESC_VOID_METHOD, false);118119mv.visitVarInsn(Opcodes.ALOAD, 0);120mv.visitInsn(Opcodes.ICONST_0);121mv.visitFieldInsn(Opcodes.PUTFIELD, CLASS_TEST, FIELD_FLAG,122Type.BOOLEAN_TYPE.getDescriptor());123124mv.visitInsn(Opcodes.RETURN);125mv.visitMaxs(/* stack = */ 2, /* locals = */ 1);126mv.visitEnd();127}128129/*130public static void m() {131try {132} finally {133Test test = new Test();134test.flag = true;135}136}137*/138{139MethodVisitor mv = cw.visitMethod(140Opcodes.ACC_STATIC + Opcodes.ACC_PUBLIC,141METHOD_TEST, DESC_VOID_METHOD,142/* signature = */ null, /* exceptions = */ null);143Label beginLabel = new Label();144Label block1EndLabel = new Label();145Label handlerLabel = new Label();146Label block2EndLabel = new Label();147Label label = new Label();148Label endLabel = new Label();149150mv.visitCode();151mv.visitTryCatchBlock(beginLabel, block1EndLabel, handlerLabel,152/* type = <any> */ null);153mv.visitTryCatchBlock(handlerLabel, block2EndLabel, handlerLabel,154/* type = <any> */ null);155156mv.visitLabel(beginLabel);157mv.visitJumpInsn(Opcodes.JSR, label);158mv.visitLabel(block1EndLabel);159mv.visitJumpInsn(Opcodes.GOTO, endLabel);160161mv.visitLabel(handlerLabel);162mv.visitVarInsn(Opcodes.ASTORE, 0);163mv.visitJumpInsn(Opcodes.JSR, label);164mv.visitLabel(block2EndLabel);165mv.visitVarInsn(Opcodes.ALOAD, 0);166mv.visitInsn(Opcodes.ATHROW);167168mv.visitLabel(label);169mv.visitVarInsn(Opcodes.ASTORE, 1);170mv.visitTypeInsn(Opcodes.NEW, CLASS_TEST);171mv.visitInsn(Opcodes.DUP);172mv.visitMethodInsn(Opcodes.INVOKESPECIAL, CLASS_TEST, METHOD_INIT,173DESC_VOID_METHOD);174mv.visitVarInsn(Opcodes.ASTORE, 2);175176mv.visitVarInsn(Opcodes.ALOAD, 2);177mv.visitInsn(Opcodes.ICONST_1);178mv.visitFieldInsn(Opcodes.PUTFIELD, CLASS_TEST, FIELD_FLAG,179Type.BOOLEAN_TYPE.getDescriptor());180181mv.visitVarInsn(Opcodes.RET, 1);182183mv.visitLabel(endLabel);184mv.visitInsn(Opcodes.RETURN);185mv.visitMaxs(/* stack = */ 2, /* locals = */ 3);186mv.visitEnd();187}188189cw.visitEnd();190return cw.toByteArray();191}192}193194195