jjg@86: /* xdono@404: * Copyright 2007-2009 Sun Microsystems, Inc. All Rights Reserved. jjg@86: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jjg@86: * jjg@86: * This code is free software; you can redistribute it and/or modify it jjg@86: * under the terms of the GNU General Public License version 2 only, as jjg@86: * published by the Free Software Foundation. jjg@86: * jjg@86: * This code is distributed in the hope that it will be useful, but WITHOUT jjg@86: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jjg@86: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jjg@86: * version 2 for more details (a copy is included in the LICENSE file that jjg@86: * accompanied this code). jjg@86: * jjg@86: * You should have received a copy of the GNU General Public License version jjg@86: * 2 along with this work; if not, write to the Free Software Foundation, jjg@86: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jjg@86: * jjg@86: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, jjg@86: * CA 95054 USA or visit www.sun.com if you need additional information or jjg@86: * have any questions. jjg@86: */ jjg@86: jjg@86: /* jjg@86: * @test jjg@86: * @bug 6627362 jjg@86: * @summary javac generates code that uses array.clone, jjg@86: * which is not available on JavaCard jjg@86: */ jjg@86: jjg@86: import java.io.*; jjg@86: import java.lang.reflect.*; jjg@86: import java.net.*; jjg@86: import java.util.*; jjg@86: jjg@86: public class T6627362 { jjg@86: static String testSrc = System.getProperty("test.src", "."); jjg@86: jjg@86: public static void main(String... args) throws Exception { jjg@86: new T6627362().run(); jjg@86: } jjg@86: jjg@86: public void run() throws Exception { jjg@86: testStandard(); jjg@86: testNoClone(); jjg@86: if (errors > 0) jjg@86: throw new Error(errors + " test cases failed"); jjg@86: } jjg@86: jjg@86: void testStandard() throws Exception { jjg@86: // compile and disassemble E.java, check for reference to Object.clone() jjg@86: File x = new File(testSrc, "x"); jjg@86: String[] jcArgs = { "-d", ".", jjg@86: new File(x, "E.java").getPath() }; jjg@86: compile(jcArgs); jjg@86: jjg@86: String[] jpArgs = { "-classpath", ".", "-c", "E" }; jjg@86: jjg@86: StringWriter sw = new StringWriter(); jjg@86: javap(new PrintWriter(sw, true), jpArgs); jjg@86: check(sw.toString(), "Method \"[LE;\".clone:()Ljava/lang/Object;"); jjg@86: callValues(); jjg@86: } jjg@86: jjg@86: void testNoClone() throws Exception { jjg@86: // compile and disassemble E.java, using modified Object.java, jjg@86: // check for reference to System.arraycopy jjg@86: File x = new File(testSrc, "x"); jjg@86: String[] jcArgs = { "-d", ".", jjg@86: new File(x, "E.java").getPath(), jjg@86: new File(x, "Object.java").getPath()}; jjg@86: compile(jcArgs); jjg@86: jjg@86: String[] jpArgs = { "-classpath", ".", "-c", "E" }; jjg@86: jjg@86: StringWriter sw = new StringWriter(); jjg@86: javap(new PrintWriter(sw, true), jpArgs); jjg@394: check(sw.toString(), "// Method java/lang/System.arraycopy:(Ljava/lang/Object;ILjava/lang/Object;II)V"); jjg@86: callValues(); jjg@86: } jjg@86: jjg@86: void compile(String... args) { jjg@86: int rc = com.sun.tools.javac.Main.compile(args); jjg@86: if (rc != 0) jjg@86: throw new Error("javac failed: " + Arrays.asList(args) + ": " + rc); jjg@86: } jjg@86: jjg@86: void javap(PrintWriter out, String... args) throws Exception { jjg@394: int rc = com.sun.tools.javap.Main.run(args, out); jjg@86: if (rc != 0) jjg@86: throw new Error("javap failed: " + Arrays.asList(args) + ": " + rc); jjg@86: } jjg@86: jjg@86: void check(String s, String require) { jjg@394: System.out.println("Checking:\n" + s); jjg@86: if (s.indexOf(require) == -1) { jjg@86: System.err.println("Can't find " + require); jjg@86: errors++; jjg@86: } jjg@86: } jjg@86: jjg@86: void callValues() { jjg@86: try { jjg@86: File dot = new File(System.getProperty("user.dir")); jjg@86: ClassLoader cl = new URLClassLoader(new URL[] { dot.toURL() }); jjg@86: Class e_class = cl.loadClass("E"); jjg@86: Method m = e_class.getMethod("values", new Class[] { }); jjg@86: //System.err.println(m); jjg@86: Object o = m.invoke(null, (Object[]) null); jjg@86: List v = Arrays.asList((Object[]) o); jjg@86: if (!v.toString().equals("[a, b, c]")) jjg@86: throw new Error("unexpected result for E.values(): " + v); jjg@86: } catch (Exception e) { jjg@86: throw new Error(e); jjg@86: } jjg@86: } jjg@86: jjg@86: int errors; jjg@86: } jjg@86: