Path: blob/master/test/functional/cmdLineTests/lockWordAlignment/src/IntLongObjectAlignmentTestGenerator.java
6004 views
/*******************************************************************************1* Copyright (c) 2001, 2021 IBM Corp. and others2*3* This program and the accompanying materials are made available under4* the terms of the Eclipse Public License 2.0 which accompanies this5* distribution and is available at https://www.eclipse.org/legal/epl-2.0/6* or the Apache License, Version 2.0 which accompanies this distribution and7* is available at https://www.apache.org/licenses/LICENSE-2.0.8*9* This Source Code may also be made available under the following10* Secondary Licenses when the conditions for such availability set11* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU12* General Public License, version 2 with the GNU Classpath13* Exception [1] and GNU General Public License, version 2 with the14* OpenJDK Assembly Exception [2].15*16* [1] https://www.gnu.org/software/classpath/license.html17* [2] http://openjdk.java.net/legal/assembly-exception.html18*19* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception20*******************************************************************************/2122import static jdk.internal.org.objectweb.asm.Opcodes.ACC_PRIVATE;23import static jdk.internal.org.objectweb.asm.Opcodes.ACC_PUBLIC;24import static jdk.internal.org.objectweb.asm.Opcodes.ACC_STATIC;25import static jdk.internal.org.objectweb.asm.Opcodes.ACC_SUPER;26import static jdk.internal.org.objectweb.asm.Opcodes.ALOAD;27import static jdk.internal.org.objectweb.asm.Opcodes.ASTORE;28import static jdk.internal.org.objectweb.asm.Opcodes.GETSTATIC;29import static jdk.internal.org.objectweb.asm.Opcodes.IFEQ;30import static jdk.internal.org.objectweb.asm.Opcodes.INVOKESPECIAL;31import static jdk.internal.org.objectweb.asm.Opcodes.INVOKESTATIC;32import static jdk.internal.org.objectweb.asm.Opcodes.INVOKEVIRTUAL;33import static jdk.internal.org.objectweb.asm.Opcodes.LCMP;34import static jdk.internal.org.objectweb.asm.Opcodes.LCONST_0;35import static jdk.internal.org.objectweb.asm.Opcodes.LLOAD;36import static jdk.internal.org.objectweb.asm.Opcodes.LREM;37import static jdk.internal.org.objectweb.asm.Opcodes.LSTORE;38import static jdk.internal.org.objectweb.asm.Opcodes.RETURN;39import static jdk.internal.org.objectweb.asm.Opcodes.V1_7;4041import java.io.FileOutputStream;42import java.io.IOException;43import java.util.Arrays;4445import jdk.internal.org.objectweb.asm.ClassWriter;46import jdk.internal.org.objectweb.asm.FieldVisitor;47import jdk.internal.org.objectweb.asm.Label;48import jdk.internal.org.objectweb.asm.MethodVisitor;49import jdk.internal.org.objectweb.asm.Opcodes;50import jdk.internal.org.objectweb.asm.Type;5152public class IntLongObjectAlignmentTestGenerator {5354private static String className;55private static String fileName;56private static String parent = "level_2_I";5758public static void main(String[] args) throws Throwable {5960parent = "level_2_I";61permuteString("", "ijo");6263parent = "level_2_J";64permuteString("", "ijo");6566parent = "level_2_O";67permuteString("", "ijo");6869}7071public static void printCommand() {72//System.out.println("java -Xbootclasspath/p:. " + className );73//System.out.println("java -Xbootclasspath/p:. -Xlockword:noLockword=" + className + " " + className);7475System.out.println("<test id=\"Check " + className + " is aligned\">");76System.out.println(" <command>$EXE$ $TESTSBOOTCLASSPATH$ $OBJECTTESTSBOOTCLASSPATH$ main " + className + "</command>");77System.out.println(" <return value=\"0\" />");78System.out.println(" <output type=\"failure\">not aligned</output>");79System.out.println(" <output type=\"failure\">Unhandled Exception</output>");80System.out.println(" <output type=\"failure\">Exception:</output>");81System.out.println(" <output type=\"failure\">Processing dump event</output>");82System.out.println("</test>");8384System.out.println("<test id=\"Check " + className + " is still aligned with -Xlockword:noLockword\">");85System.out.println(" <command>$EXE$ $TESTSBOOTCLASSPATH$ $OBJECTTESTSBOOTCLASSPATH$ -Xlockword:noLockword=" + className + " main " + className + "</command>");86System.out.println(" <return value=\"0\" />");87System.out.println(" <output type=\"failure\">not aligned</output>");88System.out.println(" <output type=\"failure\">Unhandled Exception</output>");89System.out.println(" <output type=\"failure\">Exception:</output>");90System.out.println(" <output type=\"failure\">Processing dump event</output>");91System.out.println("</test>");92}9394public static void permuteString(String beginningString, String endingString) throws Throwable {95if (endingString.length() <= 1) {9697className = beginningString + endingString + "_extends_" + parent;98fileName = className + ".class";99100FileOutputStream fos = new FileOutputStream(fileName);101fos.write(makeExample("level_2_I", beginningString + endingString));102fos.flush();103fos.close();104printCommand();105} else {106for (int i = 0; i < endingString.length(); i++) {107String newString = endingString.substring(0, i) + endingString.substring(i + 1);108permuteString(beginningString + endingString.charAt(i), newString);109}110}111}112113public static byte[] makeExample(String parent, String args)114throws Throwable {115116ClassWriter cw = new ClassWriter(0);117FieldVisitor fv = null;118MethodVisitor mv;119cw.visit(V1_7, ACC_SUPER, className, null, parent, null);120121char argsArr[] = args.toCharArray();122for (char ch : argsArr) {123switch (ch) {124case 'i':125fv = cw.visitField(ACC_PRIVATE, "i", "I", null, null);126break;127case 'j':128fv = cw.visitField(ACC_PRIVATE, "l", "J", null, null);129break;130case 'o':131fv = cw.visitField(ACC_PRIVATE, "o", "Ljava/lang/Object;",132null, null);133break;134default:135}136fv.visitEnd();137}138139{140mv = cw.visitMethod(0, "<init>", "()V", null, null);141mv.visitCode();142mv.visitVarInsn(ALOAD, 0);143mv.visitMethodInsn(INVOKESPECIAL, parent, "<init>", "()V");144mv.visitInsn(RETURN);145mv.visitMaxs(1, 1);146mv.visitEnd();147}148149cw.visitEnd();150151return cw.toByteArray();152153}154}155156157