2013-11-19 23:35:43 +00:00
|
|
|
/*
|
2015-05-21 11:41:04 -07:00
|
|
|
* Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
|
2013-11-19 23:35:43 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @test
|
|
|
|
* @bug 8028504
|
|
|
|
* @summary javac generates LocalVariableTable even with -g:none
|
2023-08-07 15:49:11 +00:00
|
|
|
* @modules java.base/jdk.internal.classfile
|
|
|
|
* java.base/jdk.internal.classfile.attribute
|
|
|
|
* java.base/jdk.internal.classfile.constantpool
|
|
|
|
* java.base/jdk.internal.classfile.instruction
|
|
|
|
* java.base/jdk.internal.classfile.components
|
2013-11-19 23:35:43 +00:00
|
|
|
* @compile -g:none DontGenerateLVTForGNoneOpTest.java
|
|
|
|
* @run main DontGenerateLVTForGNoneOpTest
|
|
|
|
*/
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.lang.annotation.ElementType;
|
|
|
|
import java.lang.annotation.Target;
|
|
|
|
import java.nio.file.Paths;
|
|
|
|
|
2023-08-07 15:49:11 +00:00
|
|
|
import jdk.internal.classfile.*;
|
|
|
|
import jdk.internal.classfile.attribute.CodeAttribute;
|
2013-11-19 23:35:43 +00:00
|
|
|
|
|
|
|
public class DontGenerateLVTForGNoneOpTest {
|
|
|
|
|
|
|
|
public static void main(String[] args) throws Exception {
|
|
|
|
new DontGenerateLVTForGNoneOpTest().run();
|
|
|
|
}
|
|
|
|
|
|
|
|
void run() throws Exception {
|
|
|
|
checkClassFile(new File(Paths.get(System.getProperty("test.classes"),
|
|
|
|
this.getClass().getName() + ".class").toUri()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void checkClassFile(final File cfile) throws Exception {
|
2023-08-07 15:49:11 +00:00
|
|
|
ClassModel classFile = Classfile.of().parse(cfile.toPath());
|
|
|
|
for (MethodModel method : classFile.methods()) {
|
|
|
|
CodeAttribute code = method.findAttribute(Attributes.CODE).orElse(null);
|
2013-11-19 23:35:43 +00:00
|
|
|
if (code != null) {
|
2023-08-07 15:49:11 +00:00
|
|
|
if (code.findAttribute(Attributes.LOCAL_VARIABLE_TABLE).orElse(null) != null) {
|
2013-11-19 23:35:43 +00:00
|
|
|
throw new AssertionError("LVT shouldn't be generated for g:none");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void bar() {
|
|
|
|
try {
|
|
|
|
System.out.println();
|
|
|
|
} catch(@TA Exception e) {
|
|
|
|
} catch(Throwable t) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Target(ElementType.TYPE_USE)
|
|
|
|
@interface TA {}
|
|
|
|
}
|