jjg@1521: /* jjg@1521: * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved. jjg@1521: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jjg@1521: * jjg@1521: * This code is free software; you can redistribute it and/or modify it jjg@1521: * under the terms of the GNU General Public License version 2 only, as jjg@1521: * published by the Free Software Foundation. jjg@1521: * jjg@1521: * This code is distributed in the hope that it will be useful, but WITHOUT jjg@1521: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jjg@1521: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jjg@1521: * version 2 for more details (a copy is included in the LICENSE file that jjg@1521: * accompanied this code). jjg@1521: * jjg@1521: * You should have received a copy of the GNU General Public License version jjg@1521: * 2 along with this work; if not, write to the Free Software Foundation, jjg@1521: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jjg@1521: * jjg@1521: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA jjg@1521: * or visit www.oracle.com if you need additional information or have any jjg@1521: * questions. jjg@1521: */ jjg@1521: jjg@1521: import java.lang.annotation.*; jjg@1521: import java.io.*; jjg@1521: import java.net.URL; jjg@1521: import java.util.List; jjg@1521: jjg@1521: import com.sun.tools.classfile.*; jjg@1521: jjg@1521: /* jjg@1521: * @test jjg@1521: * @bug 6917130 8006775 jjg@1521: * @summary test that optimized away annotations are not emited to classfile jjg@1521: */ jjg@1521: jjg@1521: public class DeadCode extends ClassfileTestHelper { jjg@1521: public static void main(String[] args) throws Exception { jjg@1521: new DeadCode().run(); jjg@1521: } jjg@1521: jjg@1521: public void run() throws Exception { jjg@1521: expected_tinvisibles = 1; jjg@1521: expected_tvisibles = 0; jjg@1521: jjg@1521: ClassFile cf = getClassFile("DeadCode$Test.class"); jjg@1521: test(cf); jjg@1521: for (Field f : cf.fields) { jjg@1521: test(cf, f); jjg@1521: } jjg@1521: for (Method m: cf.methods) { jjg@1521: test(cf, m); jjg@1521: } jjg@1521: jjg@1521: countAnnotations(); jjg@1521: jjg@1521: if (errors > 0) jjg@1521: throw new Exception(errors + " errors found"); jjg@1521: System.out.println("PASSED"); jjg@1521: } jjg@1521: jjg@1521: /*********************** Test class *************************/ jjg@1521: static class Test { jjg@1521: @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) jjg@1521: @interface A {} jjg@1521: jjg@1521: void test() { jjg@1521: List o = null; jjg@1521: o.toString(); jjg@1521: jjg@1521: @A String m; jjg@1521: if (false) { jjg@1521: @A String a; jjg@1521: @A String b = "m"; jjg@1521: b.toString(); jjg@1521: List c = null; jjg@1521: c.toString(); jjg@1521: } jjg@1521: } jjg@1521: } jjg@1521: jjg@1521: }