test/tools/javac/T8028504/DontGenerateLVTForGNoneOpTest.java

Wed, 13 Aug 2014 14:50:00 -0700

author
katleman
date
Wed, 13 Aug 2014 14:50:00 -0700
changeset 2549
0b6cc4ea670f
parent 0
959103a6100f
permissions
-rw-r--r--

Added tag jdk8u40-b01 for changeset bf89a471779d

     1 /*
     2  * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  */
    24 /*
    25  * @test
    26  * @bug 8028504
    27  * @summary javac generates LocalVariableTable even with -g:none
    28  * @compile -g:none DontGenerateLVTForGNoneOpTest.java
    29  * @run main DontGenerateLVTForGNoneOpTest
    30  */
    32 import java.io.File;
    33 import java.lang.annotation.ElementType;
    34 import java.lang.annotation.Target;
    35 import java.nio.file.Paths;
    37 import com.sun.tools.classfile.Attribute;
    38 import com.sun.tools.classfile.ClassFile;
    39 import com.sun.tools.classfile.Code_attribute;
    40 import com.sun.tools.classfile.Method;
    42 public class DontGenerateLVTForGNoneOpTest {
    44     public static void main(String[] args) throws Exception {
    45         new DontGenerateLVTForGNoneOpTest().run();
    46     }
    48     void run() throws Exception {
    49         checkClassFile(new File(Paths.get(System.getProperty("test.classes"),
    50                 this.getClass().getName() + ".class").toUri()));
    51     }
    53     void checkClassFile(final File cfile) throws Exception {
    54         ClassFile classFile = ClassFile.read(cfile);
    55         for (Method method : classFile.methods) {
    56             Code_attribute code = (Code_attribute)method.attributes.get(Attribute.Code);
    57             if (code != null) {
    58                 if (code.attributes.get(Attribute.LocalVariableTable) != null) {
    59                     throw new AssertionError("LVT shouldn't be generated for g:none");
    60                 }
    61             }
    62         }
    63     }
    65     public void bar() {
    66         try {
    67             System.out.println();
    68         } catch(@TA Exception e) {
    69         } catch(Throwable t) {}
    70     }
    72     @Target(ElementType.TYPE_USE)
    73     @interface TA {}
    74 }

mercurial