Thu, 07 Jun 2012 20:30:57 -0700
7170079: Adjustments to build-infra makefiles
Reviewed-by: ohair, ohrstrom, ihse, jonas
Contributed-by: jonas <jonas.oreland@oracle.com>, erikj <erik.joelsson@oracle.com>, ihse <magnus.ihse.bursie@oracle.com>, tgranat <torbjorn.granat@oracle.com>, ykantser <yekaterina.kantserova@oracle.com>
ksrini@804 | 1 | /* |
ksrini@804 | 2 | * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. |
ksrini@804 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ksrini@804 | 4 | * |
ksrini@804 | 5 | * This code is free software; you can redistribute it and/or modify it |
ksrini@804 | 6 | * under the terms of the GNU General Public License version 2 only, as |
ksrini@804 | 7 | * published by the Free Software Foundation. |
ksrini@804 | 8 | * |
ksrini@804 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
ksrini@804 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ksrini@804 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ksrini@804 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
ksrini@804 | 13 | * accompanied this code). |
ksrini@804 | 14 | * |
ksrini@804 | 15 | * You should have received a copy of the GNU General Public License version |
ksrini@804 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
ksrini@804 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ksrini@804 | 18 | * |
ksrini@804 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ksrini@804 | 20 | * or visit www.oracle.com if you need additional information or have any |
ksrini@804 | 21 | * questions. |
ksrini@804 | 22 | */ |
ksrini@804 | 23 | |
ksrini@804 | 24 | /* |
ksrini@804 | 25 | * @test |
ksrini@804 | 26 | * @bug 6567415 |
ksrini@804 | 27 | * @summary Test to ensure javac does not go into an infinite loop, while |
ksrini@804 | 28 | * reading a classfile of a specific length. |
ksrini@804 | 29 | * @compile -XDignore.symbol.file T6567415.java |
ksrini@804 | 30 | * @run main T6567415 |
ksrini@804 | 31 | * @author ksrini |
ksrini@804 | 32 | */ |
ksrini@804 | 33 | |
ksrini@804 | 34 | import java.io.File; |
ksrini@804 | 35 | import java.io.FileInputStream; |
ksrini@804 | 36 | import java.io.FileOutputStream; |
ksrini@804 | 37 | import java.io.IOException; |
ksrini@804 | 38 | import java.io.PrintStream; |
ksrini@804 | 39 | import java.io.RandomAccessFile; |
ksrini@804 | 40 | import java.nio.ByteBuffer; |
ksrini@804 | 41 | import java.nio.MappedByteBuffer; |
ksrini@804 | 42 | import java.nio.channels.FileChannel; |
ksrini@804 | 43 | |
ksrini@804 | 44 | /* |
ksrini@804 | 45 | * this test compiles Bar.java into a classfile and enlarges the file to the |
ksrini@804 | 46 | * magic file length, then use this mutated file on the classpath to compile |
ksrini@804 | 47 | * Foo.java which references Bar.java and Ka-boom. QED. |
ksrini@804 | 48 | */ |
ksrini@804 | 49 | public class T6567415 { |
ksrini@804 | 50 | final static String TEST_FILE_NAME = "Bar"; |
ksrini@804 | 51 | final static String TEST_JAVA = TEST_FILE_NAME + ".java"; |
ksrini@804 | 52 | final static String TEST_CLASS = TEST_FILE_NAME + ".class"; |
ksrini@804 | 53 | |
ksrini@804 | 54 | final static String TEST2_FILE_NAME = "Foo"; |
ksrini@804 | 55 | final static String TEST2_JAVA = TEST2_FILE_NAME + ".java"; |
ksrini@804 | 56 | |
ksrini@804 | 57 | /* |
ksrini@804 | 58 | * the following is the initial buffer length set in ClassReader.java |
ksrini@804 | 59 | * thus this value needs to change if ClassReader buf length changes. |
ksrini@804 | 60 | */ |
ksrini@804 | 61 | |
ksrini@804 | 62 | final static int BAD_FILE_LENGTH = |
ksrini@804 | 63 | com.sun.tools.javac.jvm.ClassReader.INITIAL_BUFFER_SIZE; |
ksrini@804 | 64 | |
ksrini@804 | 65 | static void createClassFile() throws IOException { |
ksrini@804 | 66 | FileOutputStream fos = null; |
ksrini@804 | 67 | try { |
ksrini@804 | 68 | fos = new FileOutputStream(TEST_JAVA); |
ksrini@804 | 69 | PrintStream ps = new PrintStream(fos); |
ksrini@804 | 70 | ps.println("public class " + TEST_FILE_NAME + " {}"); |
ksrini@804 | 71 | } finally { |
ksrini@804 | 72 | fos.close(); |
ksrini@804 | 73 | } |
ksrini@804 | 74 | String cmds[] = {TEST_JAVA}; |
ksrini@804 | 75 | com.sun.tools.javac.Main.compile(cmds); |
ksrini@804 | 76 | } |
ksrini@804 | 77 | |
ksrini@804 | 78 | static void enlargeClassFile() throws IOException { |
ksrini@804 | 79 | File f = new File(TEST_CLASS); |
ksrini@804 | 80 | if (!f.exists()) { |
ksrini@804 | 81 | System.out.println("file not found: " + TEST_CLASS); |
ksrini@804 | 82 | System.exit(1); |
ksrini@804 | 83 | } |
ksrini@804 | 84 | File tfile = new File(f.getAbsolutePath() + ".tmp"); |
ksrini@804 | 85 | f.renameTo(tfile); |
ksrini@804 | 86 | |
ksrini@804 | 87 | RandomAccessFile raf = null; |
ksrini@804 | 88 | FileChannel wfc = null; |
ksrini@804 | 89 | |
ksrini@804 | 90 | FileInputStream fis = null; |
ksrini@804 | 91 | FileChannel rfc = null; |
ksrini@804 | 92 | |
ksrini@804 | 93 | try { |
ksrini@804 | 94 | raf = new RandomAccessFile(f, "rw"); |
ksrini@804 | 95 | wfc = raf.getChannel(); |
ksrini@804 | 96 | |
ksrini@804 | 97 | fis = new FileInputStream(tfile); |
ksrini@804 | 98 | rfc = fis.getChannel(); |
ksrini@804 | 99 | |
ksrini@804 | 100 | ByteBuffer bb = MappedByteBuffer.allocate(BAD_FILE_LENGTH); |
ksrini@804 | 101 | rfc.read(bb); |
ksrini@804 | 102 | bb.rewind(); |
ksrini@804 | 103 | wfc.write(bb); |
ksrini@804 | 104 | wfc.truncate(BAD_FILE_LENGTH); |
ksrini@804 | 105 | } finally { |
ksrini@804 | 106 | wfc.close(); |
ksrini@804 | 107 | raf.close(); |
ksrini@804 | 108 | rfc.close(); |
ksrini@804 | 109 | fis.close(); |
ksrini@804 | 110 | } |
ksrini@804 | 111 | System.out.println("file length = " + f.length()); |
ksrini@804 | 112 | } |
ksrini@804 | 113 | |
ksrini@804 | 114 | static void createJavaFile() throws IOException { |
ksrini@804 | 115 | FileOutputStream fos = null; |
ksrini@804 | 116 | try { |
ksrini@804 | 117 | fos = new FileOutputStream(TEST2_JAVA); |
ksrini@804 | 118 | PrintStream ps = new PrintStream(fos); |
ksrini@804 | 119 | ps.println("public class " + TEST2_FILE_NAME + |
ksrini@804 | 120 | " {" + TEST_FILE_NAME + " b = new " + |
ksrini@804 | 121 | TEST_FILE_NAME + " ();}"); |
ksrini@804 | 122 | } finally { |
ksrini@804 | 123 | fos.close(); |
ksrini@804 | 124 | } |
ksrini@804 | 125 | } |
ksrini@804 | 126 | |
ksrini@804 | 127 | public static void main(String... args) throws Exception { |
ksrini@804 | 128 | createClassFile(); |
ksrini@804 | 129 | enlargeClassFile(); |
ksrini@804 | 130 | createJavaFile(); |
ksrini@804 | 131 | Thread t = new Thread () { |
ksrini@804 | 132 | @Override |
ksrini@804 | 133 | public void run() { |
ksrini@804 | 134 | String cmds[] = {"-verbose", "-cp", ".", TEST2_JAVA}; |
ksrini@804 | 135 | int ret = com.sun.tools.javac.Main.compile(cmds); |
ksrini@804 | 136 | System.out.println("test compilation returns: " + ret); |
ksrini@804 | 137 | } |
ksrini@804 | 138 | }; |
ksrini@804 | 139 | t.start(); |
ksrini@804 | 140 | t.join(1000*10); |
ksrini@804 | 141 | System.out.println(t.getState()); |
ksrini@804 | 142 | if (t.isAlive()) { |
ksrini@804 | 143 | throw new RuntimeException("Error: compilation is looping"); |
ksrini@804 | 144 | } |
ksrini@804 | 145 | } |
ksrini@804 | 146 | } |