Sat, 22 Dec 2018 13:10:38 -0800
Added tag jdk8u202-b25 for changeset 15d8c732039b
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 8009170
27 * @summary Regression: javac generates redundant bytecode in assignop involving
28 * arrays
29 * @run main RedundantByteCodeInArrayTest
30 */
32 import java.io.File;
33 import java.io.IOException;
35 import com.sun.tools.classfile.Attribute;
36 import com.sun.tools.classfile.ClassFile;
37 import com.sun.tools.classfile.Code_attribute;
38 import com.sun.tools.classfile.Code_attribute.InvalidIndex;
39 import com.sun.tools.classfile.ConstantPool;
40 import com.sun.tools.classfile.ConstantPoolException;
41 import com.sun.tools.classfile.Descriptor.InvalidDescriptor;
42 import com.sun.tools.classfile.Method;
44 public class RedundantByteCodeInArrayTest {
45 public static void main(String[] args)
46 throws IOException, ConstantPoolException, InvalidDescriptor, InvalidIndex {
47 new RedundantByteCodeInArrayTest()
48 .checkClassFile(new File(System.getProperty("test.classes", "."),
49 RedundantByteCodeInArrayTest.class.getName() + ".class"));
50 }
52 void arrMethod(int[] array, int p, int inc) {
53 array[p] += inc;
54 }
56 void checkClassFile(File file)
57 throws IOException, ConstantPoolException, InvalidDescriptor, InvalidIndex {
58 ClassFile classFile = ClassFile.read(file);
59 ConstantPool constantPool = classFile.constant_pool;
61 //lets get all the methods in the class file.
62 for (Method method : classFile.methods) {
63 if (method.getName(constantPool).equals("arrMethod")) {
64 Code_attribute code = (Code_attribute) method.attributes
65 .get(Attribute.Code);
66 if (code.max_locals > 4)
67 throw new AssertionError("Too many locals for method arrMethod");
68 }
69 }
70 }
71 }