1 /*
2  * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.
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 
26 package org.graalvm.compiler.core.test;
27 
28 import org.junit.Test;
29 import org.objectweb.asm.ClassWriter;
30 import org.objectweb.asm.MethodVisitor;
31 import org.objectweb.asm.Label;
32 
33 import jdk.vm.ci.meta.ResolvedJavaMethod;
34 
35 public class TwoSlotMarkerClearingTest extends CustomizedBytecodePatternTest {
36 
37     @Test
testTwoSlotMarkerClearing()38     public void testTwoSlotMarkerClearing() throws ClassNotFoundException {
39         Class<?> testClass = getClass("Test");
40         ResolvedJavaMethod t1 = getResolvedJavaMethod(testClass, "t1");
41         parseForCompile(t1);
42         ResolvedJavaMethod t2 = getResolvedJavaMethod(testClass, "t2");
43         parseForCompile(t2);
44     }
45 
46     @Override
generateClass(String className)47     protected byte[] generateClass(String className) {
48         ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
49         cw.visit(52, ACC_SUPER | ACC_PUBLIC, className, null, "java/lang/Object", null);
50 
51         String getDescriptor = "(" + "JII" + ")" + "I";
52         MethodVisitor t1 = cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "t1", getDescriptor, null, null);
53         t1.visitCode();
54         t1.visitVarInsn(ILOAD, 2);
55         t1.visitVarInsn(ISTORE, 0);
56         t1.visitVarInsn(ILOAD, 0);
57         Label label = new Label();
58         t1.visitJumpInsn(IFGE, label);
59         t1.visitVarInsn(ILOAD, 0);
60         t1.visitInsn(IRETURN);
61         t1.visitLabel(label);
62         t1.visitVarInsn(ILOAD, 3);
63         t1.visitInsn(IRETURN);
64         t1.visitMaxs(4, 1);
65         t1.visitEnd();
66 
67         getDescriptor = "(" + "IJIJ" + ")" + "J";
68         MethodVisitor t2 = cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "t2", getDescriptor, null, null);
69         t2.visitCode();
70         t2.visitVarInsn(LLOAD, 1);
71         t2.visitVarInsn(LSTORE, 0);
72         t2.visitVarInsn(ILOAD, 3);
73         Label label1 = new Label();
74         t2.visitJumpInsn(IFGE, label1);
75         t2.visitVarInsn(LLOAD, 0);
76         t2.visitInsn(LRETURN);
77         t2.visitLabel(label1);
78         t2.visitVarInsn(LLOAD, 4);
79         t2.visitInsn(LRETURN);
80         t2.visitMaxs(6, 2);
81         t2.visitEnd();
82 
83         cw.visitEnd();
84         return cw.toByteArray();
85     }
86 }
87