Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/test/tools/javac/6627362/T6627362.java
38813 views
/*1* Copyright (c) 2007, 2009, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 662736226* @summary javac generates code that uses array.clone,27* which is not available on JavaCard28*/2930import java.io.*;31import java.lang.reflect.*;32import java.net.*;33import java.util.*;3435public class T6627362 {36static String testSrc = System.getProperty("test.src", ".");3738public static void main(String... args) throws Exception {39new T6627362().run();40}4142public void run() throws Exception {43testStandard();44testNoClone();45if (errors > 0)46throw new Error(errors + " test cases failed");47}4849void testStandard() throws Exception {50// compile and disassemble E.java, check for reference to Object.clone()51File x = new File(testSrc, "x");52String[] jcArgs = { "-d", ".",53new File(x, "E.java").getPath() };54compile(jcArgs);5556String[] jpArgs = { "-classpath", ".", "-c", "E" };5758StringWriter sw = new StringWriter();59javap(new PrintWriter(sw, true), jpArgs);60check(sw.toString(), "Method \"[LE;\".clone:()Ljava/lang/Object;");61callValues();62}6364void testNoClone() throws Exception {65// compile and disassemble E.java, using modified Object.java,66// check for reference to System.arraycopy67File x = new File(testSrc, "x");68String[] jcArgs = { "-d", ".",69new File(x, "E.java").getPath(),70new File(x, "Object.java").getPath()};71compile(jcArgs);7273String[] jpArgs = { "-classpath", ".", "-c", "E" };7475StringWriter sw = new StringWriter();76javap(new PrintWriter(sw, true), jpArgs);77check(sw.toString(), "// Method java/lang/System.arraycopy:(Ljava/lang/Object;ILjava/lang/Object;II)V");78callValues();79}8081void compile(String... args) {82int rc = com.sun.tools.javac.Main.compile(args);83if (rc != 0)84throw new Error("javac failed: " + Arrays.asList(args) + ": " + rc);85}8687void javap(PrintWriter out, String... args) throws Exception {88int rc = com.sun.tools.javap.Main.run(args, out);89if (rc != 0)90throw new Error("javap failed: " + Arrays.asList(args) + ": " + rc);91}9293void check(String s, String require) {94System.out.println("Checking:\n" + s);95if (s.indexOf(require) == -1) {96System.err.println("Can't find " + require);97errors++;98}99}100101void callValues() {102try {103File dot = new File(System.getProperty("user.dir"));104ClassLoader cl = new URLClassLoader(new URL[] { dot.toURL() });105Class<?> e_class = cl.loadClass("E");106Method m = e_class.getMethod("values", new Class[] { });107//System.err.println(m);108Object o = m.invoke(null, (Object[]) null);109List<Object> v = Arrays.asList((Object[]) o);110if (!v.toString().equals("[a, b, c]"))111throw new Error("unexpected result for E.values(): " + v);112} catch (Exception e) {113throw new Error(e);114}115}116117int errors;118}119120121122