Tue, 19 Nov 2013 23:35:43 +0000
8028504: javac generates LocalVariableTable even with -g:none
Reviewed-by: jjg, jlahoda
1.1 --- a/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java Tue Nov 19 22:14:51 2013 +0400 1.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java Tue Nov 19 23:35:43 2013 +0000 1.3 @@ -1174,9 +1174,8 @@ 1.4 } 1.5 1.6 // counter for number of generic local variables 1.7 - int nGenericVars = 0; 1.8 - 1.9 - if (code.varBufferSize > 0) { 1.10 + if (code.varDebugInfo && code.varBufferSize > 0) { 1.11 + int nGenericVars = 0; 1.12 int alenIdx = writeAttr(names.LocalVariableTable); 1.13 databuf.appendChar(code.getLVTSize()); 1.14 for (int i=0; i<code.varBufferSize; i++) { 1.15 @@ -1195,37 +1194,38 @@ 1.16 Type vartype = sym.erasure(types); 1.17 databuf.appendChar(pool.put(typeSig(vartype))); 1.18 databuf.appendChar(var.reg); 1.19 - if (needsLocalVariableTypeEntry(var.sym.type)) 1.20 + if (needsLocalVariableTypeEntry(var.sym.type)) { 1.21 nGenericVars++; 1.22 + } 1.23 } 1.24 } 1.25 endAttr(alenIdx); 1.26 acount++; 1.27 - } 1.28 1.29 - if (nGenericVars > 0) { 1.30 - int alenIdx = writeAttr(names.LocalVariableTypeTable); 1.31 - databuf.appendChar(nGenericVars); 1.32 - int count = 0; 1.33 + if (nGenericVars > 0) { 1.34 + alenIdx = writeAttr(names.LocalVariableTypeTable); 1.35 + databuf.appendChar(nGenericVars); 1.36 + int count = 0; 1.37 1.38 - for (int i=0; i<code.varBufferSize; i++) { 1.39 - Code.LocalVar var = code.varBuffer[i]; 1.40 - VarSymbol sym = var.sym; 1.41 - if (!needsLocalVariableTypeEntry(sym.type)) 1.42 - continue; 1.43 - for (Code.LocalVar.Range r : var.aliveRanges) { 1.44 - // write variable info 1.45 - databuf.appendChar(r.start_pc); 1.46 - databuf.appendChar(r.length); 1.47 - databuf.appendChar(pool.put(sym.name)); 1.48 - databuf.appendChar(pool.put(typeSig(sym.type))); 1.49 - databuf.appendChar(var.reg); 1.50 - count++; 1.51 + for (int i=0; i<code.varBufferSize; i++) { 1.52 + Code.LocalVar var = code.varBuffer[i]; 1.53 + VarSymbol sym = var.sym; 1.54 + if (!needsLocalVariableTypeEntry(sym.type)) 1.55 + continue; 1.56 + for (Code.LocalVar.Range r : var.aliveRanges) { 1.57 + // write variable info 1.58 + databuf.appendChar(r.start_pc); 1.59 + databuf.appendChar(r.length); 1.60 + databuf.appendChar(pool.put(sym.name)); 1.61 + databuf.appendChar(pool.put(typeSig(sym.type))); 1.62 + databuf.appendChar(var.reg); 1.63 + count++; 1.64 + } 1.65 } 1.66 + Assert.check(count == nGenericVars); 1.67 + endAttr(alenIdx); 1.68 + acount++; 1.69 } 1.70 - Assert.check(count == nGenericVars); 1.71 - endAttr(alenIdx); 1.72 - acount++; 1.73 } 1.74 1.75 if (code.stackMapBufferSize > 0) {
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/test/tools/javac/T8028504/DontGenerateLVTForGNoneOpTest.java Tue Nov 19 23:35:43 2013 +0000 2.3 @@ -0,0 +1,74 @@ 2.4 +/* 2.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.7 + * 2.8 + * This code is free software; you can redistribute it and/or modify it 2.9 + * under the terms of the GNU General Public License version 2 only, as 2.10 + * published by the Free Software Foundation. 2.11 + * 2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 2.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 2.15 + * version 2 for more details (a copy is included in the LICENSE file that 2.16 + * accompanied this code). 2.17 + * 2.18 + * You should have received a copy of the GNU General Public License version 2.19 + * 2 along with this work; if not, write to the Free Software Foundation, 2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2.21 + * 2.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2.23 + * or visit www.oracle.com if you need additional information or have any 2.24 + * questions. 2.25 + */ 2.26 + 2.27 +/* 2.28 + * @test 2.29 + * @bug 8028504 2.30 + * @summary javac generates LocalVariableTable even with -g:none 2.31 + * @compile -g:none DontGenerateLVTForGNoneOpTest.java 2.32 + * @run main DontGenerateLVTForGNoneOpTest 2.33 + */ 2.34 + 2.35 +import java.io.File; 2.36 +import java.lang.annotation.ElementType; 2.37 +import java.lang.annotation.Target; 2.38 +import java.nio.file.Paths; 2.39 + 2.40 +import com.sun.tools.classfile.Attribute; 2.41 +import com.sun.tools.classfile.ClassFile; 2.42 +import com.sun.tools.classfile.Code_attribute; 2.43 +import com.sun.tools.classfile.Method; 2.44 + 2.45 +public class DontGenerateLVTForGNoneOpTest { 2.46 + 2.47 + public static void main(String[] args) throws Exception { 2.48 + new DontGenerateLVTForGNoneOpTest().run(); 2.49 + } 2.50 + 2.51 + void run() throws Exception { 2.52 + checkClassFile(new File(Paths.get(System.getProperty("test.classes"), 2.53 + this.getClass().getName() + ".class").toUri())); 2.54 + } 2.55 + 2.56 + void checkClassFile(final File cfile) throws Exception { 2.57 + ClassFile classFile = ClassFile.read(cfile); 2.58 + for (Method method : classFile.methods) { 2.59 + Code_attribute code = (Code_attribute)method.attributes.get(Attribute.Code); 2.60 + if (code != null) { 2.61 + if (code.attributes.get(Attribute.LocalVariableTable) != null) { 2.62 + throw new AssertionError("LVT shouldn't be generated for g:none"); 2.63 + } 2.64 + } 2.65 + } 2.66 + } 2.67 + 2.68 + public void bar() { 2.69 + try { 2.70 + System.out.println(); 2.71 + } catch(@TA Exception e) { 2.72 + } catch(Throwable t) {} 2.73 + } 2.74 + 2.75 + @Target(ElementType.TYPE_USE) 2.76 + @interface TA {} 2.77 +}