DontGenerateLVTForGNoneOpTest.java revision 2942:08092deced3f
1135446Strhodes/*
2262706Serwin * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
3135446Strhodes * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4135446Strhodes *
5193149Sdougb * This code is free software; you can redistribute it and/or modify it
6135446Strhodes * under the terms of the GNU General Public License version 2 only, as
7135446Strhodes * published by the Free Software Foundation.
8135446Strhodes *
9135446Strhodes * This code is distributed in the hope that it will be useful, but WITHOUT
10135446Strhodes * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11135446Strhodes * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12135446Strhodes * version 2 for more details (a copy is included in the LICENSE file that
13135446Strhodes * accompanied this code).
14135446Strhodes *
15135446Strhodes * You should have received a copy of the GNU General Public License version
16135446Strhodes * 2 along with this work; if not, write to the Free Software Foundation,
17135446Strhodes * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18254897Serwin *
19135446Strhodes * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20170222Sdougb * or visit www.oracle.com if you need additional information or have any
21170222Sdougb * questions.
22135446Strhodes */
23135446Strhodes
24135446Strhodes/*
25135446Strhodes * @test
26135446Strhodes * @bug 8028504
27135446Strhodes * @summary javac generates LocalVariableTable even with -g:none
28193149Sdougb * @modules jdk.jdeps/com.sun.tools.classfile
29135446Strhodes * @compile -g:none DontGenerateLVTForGNoneOpTest.java
30135446Strhodes * @run main DontGenerateLVTForGNoneOpTest
31135446Strhodes */
32135446Strhodes
33224092Sdougbimport java.io.File;
34135446Strhodesimport java.lang.annotation.ElementType;
35135446Strhodesimport java.lang.annotation.Target;
36135446Strhodesimport java.nio.file.Paths;
37224092Sdougb
38135446Strhodesimport com.sun.tools.classfile.Attribute;
39224092Sdougbimport com.sun.tools.classfile.ClassFile;
40224092Sdougbimport com.sun.tools.classfile.Code_attribute;
41224092Sdougbimport com.sun.tools.classfile.Method;
42224092Sdougb
43135446Strhodespublic class DontGenerateLVTForGNoneOpTest {
44193149Sdougb
45135446Strhodes    public static void main(String[] args) throws Exception {
46135446Strhodes        new DontGenerateLVTForGNoneOpTest().run();
47135446Strhodes    }
48170222Sdougb
49135446Strhodes    void run() throws Exception {
50135446Strhodes        checkClassFile(new File(Paths.get(System.getProperty("test.classes"),
51135446Strhodes                this.getClass().getName() + ".class").toUri()));
52135446Strhodes    }
53135446Strhodes
54135446Strhodes    void checkClassFile(final File cfile) throws Exception {
55193149Sdougb        ClassFile classFile = ClassFile.read(cfile);
56193149Sdougb        for (Method method : classFile.methods) {
57193149Sdougb            Code_attribute code = (Code_attribute)method.attributes.get(Attribute.Code);
58193149Sdougb            if (code != null) {
59254402Serwin                if (code.attributes.get(Attribute.LocalVariableTable) != null) {
60193149Sdougb                    throw new AssertionError("LVT shouldn't be generated for g:none");
61193149Sdougb                }
62193149Sdougb            }
63193149Sdougb        }
64193149Sdougb    }
65135446Strhodes
66135446Strhodes    public void bar() {
67135446Strhodes        try {
68135446Strhodes            System.out.println();
69135446Strhodes        } catch(@TA Exception e) {
70135446Strhodes        } catch(Throwable t) {}
71224092Sdougb    }
72224092Sdougb
73224092Sdougb    @Target(ElementType.TYPE_USE)
74224092Sdougb    @interface TA {}
75224092Sdougb}
76224092Sdougb