author | sogoel |
Thu, 05 Jun 2014 10:57:10 -0700 | |
changeset 24797 | 850ebd4d80a7 |
parent 16334 | 49b3f71982f6 |
child 30730 | d3ce7619db2c |
permissions | -rw-r--r-- |
16334
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
1 |
/* |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
2 |
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
4 |
* |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
8 |
* |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
13 |
* accompanied this code). |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
14 |
* |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
18 |
* |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
21 |
* questions. |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
22 |
*/ |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
23 |
|
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
24 |
/* |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
25 |
* @test |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
26 |
* @bug 8009170 |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
27 |
* @summary Regression: javac generates redundant bytecode in assignop involving |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
28 |
* arrays |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
29 |
* @run main RedundantByteCodeInArrayTest |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
30 |
*/ |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
31 |
|
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
32 |
import java.io.File; |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
33 |
import java.io.IOException; |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
34 |
|
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
35 |
import com.sun.tools.classfile.Attribute; |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
36 |
import com.sun.tools.classfile.ClassFile; |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
37 |
import com.sun.tools.classfile.Code_attribute; |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
38 |
import com.sun.tools.classfile.Code_attribute.InvalidIndex; |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
39 |
import com.sun.tools.classfile.ConstantPool; |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
40 |
import com.sun.tools.classfile.ConstantPoolException; |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
41 |
import com.sun.tools.classfile.Descriptor.InvalidDescriptor; |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
42 |
import com.sun.tools.classfile.Method; |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
43 |
|
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
44 |
public class RedundantByteCodeInArrayTest { |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
45 |
public static void main(String[] args) |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
46 |
throws IOException, ConstantPoolException, InvalidDescriptor, InvalidIndex { |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
47 |
new RedundantByteCodeInArrayTest() |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
48 |
.checkClassFile(new File(System.getProperty("test.classes", "."), |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
49 |
RedundantByteCodeInArrayTest.class.getName() + ".class")); |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
50 |
} |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
51 |
|
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
52 |
void arrMethod(int[] array, int p, int inc) { |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
53 |
array[p] += inc; |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
54 |
} |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
55 |
|
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
56 |
void checkClassFile(File file) |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
57 |
throws IOException, ConstantPoolException, InvalidDescriptor, InvalidIndex { |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
58 |
ClassFile classFile = ClassFile.read(file); |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
59 |
ConstantPool constantPool = classFile.constant_pool; |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
60 |
|
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
61 |
//lets get all the methods in the class file. |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
62 |
for (Method method : classFile.methods) { |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
63 |
if (method.getName(constantPool).equals("arrMethod")) { |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
64 |
Code_attribute code = (Code_attribute) method.attributes |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
65 |
.get(Attribute.Code); |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
66 |
if (code.max_locals > 4) |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
67 |
throw new AssertionError("Too many locals for method arrMethod"); |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
68 |
} |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
69 |
} |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
70 |
} |
49b3f71982f6
8009170: Regression: javac generates redundant bytecode in assignop involving arrays
vromero
parents:
diff
changeset
|
71 |
} |