1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/tools/javac/6627362/T6627362.java Wed Apr 27 01:34:52 2016 +0800 1.3 @@ -0,0 +1,120 @@ 1.4 +/* 1.5 + * Copyright (c) 2007, 2009, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + */ 1.26 + 1.27 +/* 1.28 + * @test 1.29 + * @bug 6627362 1.30 + * @summary javac generates code that uses array.clone, 1.31 + * which is not available on JavaCard 1.32 + */ 1.33 + 1.34 +import java.io.*; 1.35 +import java.lang.reflect.*; 1.36 +import java.net.*; 1.37 +import java.util.*; 1.38 + 1.39 +public class T6627362 { 1.40 + static String testSrc = System.getProperty("test.src", "."); 1.41 + 1.42 + public static void main(String... args) throws Exception { 1.43 + new T6627362().run(); 1.44 + } 1.45 + 1.46 + public void run() throws Exception { 1.47 + testStandard(); 1.48 + testNoClone(); 1.49 + if (errors > 0) 1.50 + throw new Error(errors + " test cases failed"); 1.51 + } 1.52 + 1.53 + void testStandard() throws Exception { 1.54 + // compile and disassemble E.java, check for reference to Object.clone() 1.55 + File x = new File(testSrc, "x"); 1.56 + String[] jcArgs = { "-d", ".", 1.57 + new File(x, "E.java").getPath() }; 1.58 + compile(jcArgs); 1.59 + 1.60 + String[] jpArgs = { "-classpath", ".", "-c", "E" }; 1.61 + 1.62 + StringWriter sw = new StringWriter(); 1.63 + javap(new PrintWriter(sw, true), jpArgs); 1.64 + check(sw.toString(), "Method \"[LE;\".clone:()Ljava/lang/Object;"); 1.65 + callValues(); 1.66 + } 1.67 + 1.68 + void testNoClone() throws Exception { 1.69 + // compile and disassemble E.java, using modified Object.java, 1.70 + // check for reference to System.arraycopy 1.71 + File x = new File(testSrc, "x"); 1.72 + String[] jcArgs = { "-d", ".", 1.73 + new File(x, "E.java").getPath(), 1.74 + new File(x, "Object.java").getPath()}; 1.75 + compile(jcArgs); 1.76 + 1.77 + String[] jpArgs = { "-classpath", ".", "-c", "E" }; 1.78 + 1.79 + StringWriter sw = new StringWriter(); 1.80 + javap(new PrintWriter(sw, true), jpArgs); 1.81 + check(sw.toString(), "// Method java/lang/System.arraycopy:(Ljava/lang/Object;ILjava/lang/Object;II)V"); 1.82 + callValues(); 1.83 + } 1.84 + 1.85 + void compile(String... args) { 1.86 + int rc = com.sun.tools.javac.Main.compile(args); 1.87 + if (rc != 0) 1.88 + throw new Error("javac failed: " + Arrays.asList(args) + ": " + rc); 1.89 + } 1.90 + 1.91 + void javap(PrintWriter out, String... args) throws Exception { 1.92 + int rc = com.sun.tools.javap.Main.run(args, out); 1.93 + if (rc != 0) 1.94 + throw new Error("javap failed: " + Arrays.asList(args) + ": " + rc); 1.95 + } 1.96 + 1.97 + void check(String s, String require) { 1.98 + System.out.println("Checking:\n" + s); 1.99 + if (s.indexOf(require) == -1) { 1.100 + System.err.println("Can't find " + require); 1.101 + errors++; 1.102 + } 1.103 + } 1.104 + 1.105 + void callValues() { 1.106 + try { 1.107 + File dot = new File(System.getProperty("user.dir")); 1.108 + ClassLoader cl = new URLClassLoader(new URL[] { dot.toURL() }); 1.109 + Class<?> e_class = cl.loadClass("E"); 1.110 + Method m = e_class.getMethod("values", new Class[] { }); 1.111 + //System.err.println(m); 1.112 + Object o = m.invoke(null, (Object[]) null); 1.113 + List<Object> v = Arrays.asList((Object[]) o); 1.114 + if (!v.toString().equals("[a, b, c]")) 1.115 + throw new Error("unexpected result for E.values(): " + v); 1.116 + } catch (Exception e) { 1.117 + throw new Error(e); 1.118 + } 1.119 + } 1.120 + 1.121 + int errors; 1.122 +} 1.123 +