/* * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. * */ import java.io.*; // Exercise JavaCritical native method signatures public class Generate { public static void main(String[] args) throws Exception { PrintStream j = new PrintStream(new FileOutputStream("JNITest.java")); generateJava(j); j.close(); j = new PrintStream(new FileOutputStream("JNITest.c")); generateJNI(j); generateJavaCritical(j); j.close(); } static void generateJava(PrintStream out) { out.println("public class JNITest {"); for (int i = 0; i < 255; i++) { out.printf(" static native void nativeTest%d(", i); for (int b = 0; b < 8; b++) { out.printf("%s a%d", (i & (1 << b)) == 0 ? "int" : "byte[]", b); if (b < 7) { out.print(", "); } else { out.println(");"); } } } out.println(" static byte[] array0 = new byte[1024];"); out.println(" static {"); out.println(" System.loadLibrary(\"jnitest\");"); out.println(" }"); out.println(" public static void main(String[] args) {"); out.println(" for (int i = 0; i < 20000; i++) {"); for (int i = 0; i < 255; i++) { out.printf(" nativeTest%d(", i); for (int b = 0; b < 8; b++) { if ((i & (1 << b)) == 0) { out.printf("(0xfeafd00f + %d)", b); } else { out.printf("array0"); } if (b < 7) { out.print(", "); } else { out.println(");"); } } } out.println(" }"); out.println(" }"); out.println("}"); } static void generateJNI(PrintStream out) { out.println("#include \"JNITest.h\""); out.println(); for (int i = 0; i < 255; i++) { out.printf("JNIEXPORT void JNICALL Java_JNITest_nativeTest%d(JNIEnv* env, jclass cl, ", i); for (int b = 0; b < 8; b++) { out.printf("%s a%d", (i & (1 << b)) == 0 ? "jint" : "jbyteArray", b); if (b < 7) { out.print(", "); } else { out.println(") {\n}\n\n"); } } } } static void generateJavaCritical(PrintStream out) { for (int i = 0; i < 255; i++) { out.printf("JNIEXPORT void JNICALL JavaCritical_JNITest_nativeTest%d(", i); for (int b = 0; b < 8; b++) { if ((i & (1 << b)) == 0) { out.printf("%s a%d", "jint", b); } else { out.printf("int a%dlen, %s a%d", b, "jbyte*", b); } if (b < 7) { out.print(", "); } else { out.println(") {\n"); } } for (int b = 0; b < 8; b++) { if ((i & (1 << b)) == 0) { out.printf(" if (a%d != 0x%x) fprintf(stderr, \"a%d %%d != %d in nativeTest%d\\n\", a%d);\n", b, b + 0xfeafd00f, b, b + 0xfeafd00f, i, b); } else { out.printf(" a%d[0] = 1;\n", b); } } out.println("}\n\n"); } } }