Thu, 10 Oct 2013 14:58:04 +0200
8001931: The new build system whitespace cleanup
Reviewed-by: tbell, simonis, erikj
jjg@86 | 1 | /* |
ohair@554 | 2 | * Copyright (c) 2007, 2009, Oracle and/or its affiliates. All rights reserved. |
jjg@86 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
jjg@86 | 4 | * |
jjg@86 | 5 | * This code is free software; you can redistribute it and/or modify it |
jjg@86 | 6 | * under the terms of the GNU General Public License version 2 only, as |
jjg@86 | 7 | * published by the Free Software Foundation. |
jjg@86 | 8 | * |
jjg@86 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
jjg@86 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
jjg@86 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
jjg@86 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
jjg@86 | 13 | * accompanied this code). |
jjg@86 | 14 | * |
jjg@86 | 15 | * You should have received a copy of the GNU General Public License version |
jjg@86 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
jjg@86 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
jjg@86 | 18 | * |
ohair@554 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@554 | 20 | * or visit www.oracle.com if you need additional information or have any |
ohair@554 | 21 | * questions. |
jjg@86 | 22 | */ |
jjg@86 | 23 | |
jjg@86 | 24 | /* |
jjg@86 | 25 | * @test |
jjg@86 | 26 | * @bug 6627362 |
jjg@86 | 27 | * @summary javac generates code that uses array.clone, |
jjg@86 | 28 | * which is not available on JavaCard |
jjg@86 | 29 | */ |
jjg@86 | 30 | |
jjg@86 | 31 | import java.io.*; |
jjg@86 | 32 | import java.lang.reflect.*; |
jjg@86 | 33 | import java.net.*; |
jjg@86 | 34 | import java.util.*; |
jjg@86 | 35 | |
jjg@86 | 36 | public class T6627362 { |
jjg@86 | 37 | static String testSrc = System.getProperty("test.src", "."); |
jjg@86 | 38 | |
jjg@86 | 39 | public static void main(String... args) throws Exception { |
jjg@86 | 40 | new T6627362().run(); |
jjg@86 | 41 | } |
jjg@86 | 42 | |
jjg@86 | 43 | public void run() throws Exception { |
jjg@86 | 44 | testStandard(); |
jjg@86 | 45 | testNoClone(); |
jjg@86 | 46 | if (errors > 0) |
jjg@86 | 47 | throw new Error(errors + " test cases failed"); |
jjg@86 | 48 | } |
jjg@86 | 49 | |
jjg@86 | 50 | void testStandard() throws Exception { |
jjg@86 | 51 | // compile and disassemble E.java, check for reference to Object.clone() |
jjg@86 | 52 | File x = new File(testSrc, "x"); |
jjg@86 | 53 | String[] jcArgs = { "-d", ".", |
jjg@86 | 54 | new File(x, "E.java").getPath() }; |
jjg@86 | 55 | compile(jcArgs); |
jjg@86 | 56 | |
jjg@86 | 57 | String[] jpArgs = { "-classpath", ".", "-c", "E" }; |
jjg@86 | 58 | |
jjg@86 | 59 | StringWriter sw = new StringWriter(); |
jjg@86 | 60 | javap(new PrintWriter(sw, true), jpArgs); |
jjg@86 | 61 | check(sw.toString(), "Method \"[LE;\".clone:()Ljava/lang/Object;"); |
jjg@86 | 62 | callValues(); |
jjg@86 | 63 | } |
jjg@86 | 64 | |
jjg@86 | 65 | void testNoClone() throws Exception { |
jjg@86 | 66 | // compile and disassemble E.java, using modified Object.java, |
jjg@86 | 67 | // check for reference to System.arraycopy |
jjg@86 | 68 | File x = new File(testSrc, "x"); |
jjg@86 | 69 | String[] jcArgs = { "-d", ".", |
jjg@86 | 70 | new File(x, "E.java").getPath(), |
jjg@86 | 71 | new File(x, "Object.java").getPath()}; |
jjg@86 | 72 | compile(jcArgs); |
jjg@86 | 73 | |
jjg@86 | 74 | String[] jpArgs = { "-classpath", ".", "-c", "E" }; |
jjg@86 | 75 | |
jjg@86 | 76 | StringWriter sw = new StringWriter(); |
jjg@86 | 77 | javap(new PrintWriter(sw, true), jpArgs); |
jjg@394 | 78 | check(sw.toString(), "// Method java/lang/System.arraycopy:(Ljava/lang/Object;ILjava/lang/Object;II)V"); |
jjg@86 | 79 | callValues(); |
jjg@86 | 80 | } |
jjg@86 | 81 | |
jjg@86 | 82 | void compile(String... args) { |
jjg@86 | 83 | int rc = com.sun.tools.javac.Main.compile(args); |
jjg@86 | 84 | if (rc != 0) |
jjg@86 | 85 | throw new Error("javac failed: " + Arrays.asList(args) + ": " + rc); |
jjg@86 | 86 | } |
jjg@86 | 87 | |
jjg@86 | 88 | void javap(PrintWriter out, String... args) throws Exception { |
jjg@394 | 89 | int rc = com.sun.tools.javap.Main.run(args, out); |
jjg@86 | 90 | if (rc != 0) |
jjg@86 | 91 | throw new Error("javap failed: " + Arrays.asList(args) + ": " + rc); |
jjg@86 | 92 | } |
jjg@86 | 93 | |
jjg@86 | 94 | void check(String s, String require) { |
jjg@394 | 95 | System.out.println("Checking:\n" + s); |
jjg@86 | 96 | if (s.indexOf(require) == -1) { |
jjg@86 | 97 | System.err.println("Can't find " + require); |
jjg@86 | 98 | errors++; |
jjg@86 | 99 | } |
jjg@86 | 100 | } |
jjg@86 | 101 | |
jjg@86 | 102 | void callValues() { |
jjg@86 | 103 | try { |
jjg@86 | 104 | File dot = new File(System.getProperty("user.dir")); |
jjg@86 | 105 | ClassLoader cl = new URLClassLoader(new URL[] { dot.toURL() }); |
jjg@86 | 106 | Class<?> e_class = cl.loadClass("E"); |
jjg@86 | 107 | Method m = e_class.getMethod("values", new Class[] { }); |
jjg@86 | 108 | //System.err.println(m); |
jjg@86 | 109 | Object o = m.invoke(null, (Object[]) null); |
jjg@86 | 110 | List<Object> v = Arrays.asList((Object[]) o); |
jjg@86 | 111 | if (!v.toString().equals("[a, b, c]")) |
jjg@86 | 112 | throw new Error("unexpected result for E.values(): " + v); |
jjg@86 | 113 | } catch (Exception e) { |
jjg@86 | 114 | throw new Error(e); |
jjg@86 | 115 | } |
jjg@86 | 116 | } |
jjg@86 | 117 | |
jjg@86 | 118 | int errors; |
jjg@86 | 119 | } |
jjg@86 | 120 |