Skip to content

Commit

Permalink
8295058: test/langtools/tools/javac 116 test classes uses com.sun.too…
Browse files Browse the repository at this point in the history
…ls.classfile library

Reviewed-by: asotona
  • Loading branch information
xqoasis authored and asotona committed Aug 7, 2023
1 parent 4726960 commit 380418f
Show file tree
Hide file tree
Showing 117 changed files with 2,126 additions and 1,993 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,23 @@
* @bug 8009170
* @summary Regression: javac generates redundant bytecode in assignop involving
* arrays
* @modules jdk.jdeps/com.sun.tools.classfile
* @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
* @run main RedundantByteCodeInArrayTest
*/

import jdk.internal.classfile.*;
import jdk.internal.classfile.attribute.CodeAttribute;
import jdk.internal.classfile.constantpool.ConstantPool;
import java.io.File;
import java.io.IOException;

import com.sun.tools.classfile.Attribute;
import com.sun.tools.classfile.ClassFile;
import com.sun.tools.classfile.Code_attribute;
import com.sun.tools.classfile.Code_attribute.InvalidIndex;
import com.sun.tools.classfile.ConstantPool;
import com.sun.tools.classfile.ConstantPoolException;
import com.sun.tools.classfile.Descriptor.InvalidDescriptor;
import com.sun.tools.classfile.Method;

public class RedundantByteCodeInArrayTest {
public static void main(String[] args)
throws IOException, ConstantPoolException, InvalidDescriptor, InvalidIndex {
throws IOException {
new RedundantByteCodeInArrayTest()
.checkClassFile(new File(System.getProperty("test.classes", "."),
RedundantByteCodeInArrayTest.class.getName() + ".class"));
Expand All @@ -55,18 +53,18 @@ void arrMethod(int[] array, int p, int inc) {
}

void checkClassFile(File file)
throws IOException, ConstantPoolException, InvalidDescriptor, InvalidIndex {
ClassFile classFile = ClassFile.read(file);
ConstantPool constantPool = classFile.constant_pool;
throws IOException {
ClassModel classFile = Classfile.of().parse(file.toPath());
ConstantPool constantPool = classFile.constantPool();

//lets get all the methods in the class file.
for (Method method : classFile.methods) {
if (method.getName(constantPool).equals("arrMethod")) {
Code_attribute code = (Code_attribute) method.attributes
.get(Attribute.Code);
if (code.max_locals > 4)
for (MethodModel method : classFile.methods()) {
if (method.methodName().equalsString("arrMethod")) {
CodeAttribute code = method.findAttribute(Attributes.CODE).orElse(null);
assert code != null;
if (code.maxLocals() > 4)
throw new AssertionError("Too many locals for method arrMethod");
}
}
}
}
}
9 changes: 5 additions & 4 deletions test/langtools/tools/javac/StringConcat/WellKnownTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@
* questions.
*/

import com.sun.tools.classfile.*;
import com.sun.tools.classfile.ConstantPool.*;

/*
* @test
* @bug 8273914
* @summary Indy string concat changes order of operations
* @modules jdk.jdeps/com.sun.tools.classfile
* @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
*
* @compile -XDstringConcat=indy WellKnownTypes.java
* @run main WellKnownTypes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,18 @@
* @test
* @bug 7165659
* @summary javac incorrectly sets strictfp access flag on inner-classes
* @modules jdk.jdeps/com.sun.tools.classfile
* @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
* jdk.compiler/com.sun.tools.javac.util
*/

import java.io.File;

import com.sun.tools.classfile.AccessFlags;
import com.sun.tools.classfile.Attribute;
import com.sun.tools.classfile.ClassFile;
import com.sun.tools.classfile.InnerClasses_attribute;
import com.sun.tools.classfile.InnerClasses_attribute.Info;
import jdk.internal.classfile.*;
import jdk.internal.classfile.attribute.*;
import com.sun.tools.javac.util.Assert;

public class InnerClassAttrMustNotHaveStrictFPFlagTest {
Expand All @@ -50,11 +51,11 @@ private void run() throws Exception {
}

void analyzeClassFile(File path) throws Exception {
ClassFile classFile = ClassFile.read(path);
InnerClasses_attribute innerClasses =
(InnerClasses_attribute) classFile.attributes.get(Attribute.InnerClasses);
for (Info classInfo : innerClasses.classes) {
Assert.check(!classInfo.inner_class_access_flags.is(AccessFlags.ACC_STRICT),
ClassModel classFile = Classfile.of().parse(path.toPath());
InnerClassesAttribute innerClasses = classFile.findAttribute(Attributes.INNER_CLASSES).orElse(null);
assert innerClasses != null;
for (InnerClassInfo classInfo : innerClasses.classes()) {
Assert.check(classInfo.flagsMask() != Classfile.ACC_STRICT,
"Inner classes attribute must not have the ACC_STRICT flag set");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@
* @test
* @bug 8011181
* @summary javac, empty UTF8 entry generated for inner class
* @modules jdk.jdeps/com.sun.tools.classfile
* @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
* jdk.compiler/com.sun.tools.javac.util
*/

Expand All @@ -35,11 +39,8 @@
import java.nio.file.Paths;

import com.sun.tools.javac.util.Assert;
import com.sun.tools.classfile.ClassFile;

import static com.sun.tools.classfile.ConstantPool.CONSTANT_Utf8;
import static com.sun.tools.classfile.ConstantPool.CONSTANT_Utf8_info;
import static com.sun.tools.classfile.ConstantPool.CPInfo;
import jdk.internal.classfile.*;
import jdk.internal.classfile.constantpool.*;

public class EmptyUTF8ForInnerClassNameTest {

Expand All @@ -55,13 +56,13 @@ void run() throws Exception {
}

void checkClassFile(final Path path) throws Exception {
ClassFile classFile = ClassFile.read(
new BufferedInputStream(Files.newInputStream(path)));
for (CPInfo cpInfo : classFile.constant_pool.entries()) {
if (cpInfo.getTag() == CONSTANT_Utf8) {
CONSTANT_Utf8_info utf8Info = (CONSTANT_Utf8_info)cpInfo;
Assert.check(utf8Info.value.length() > 0,
"UTF8 with length 0 found at class " + classFile.getName());
ClassModel classFile = Classfile.of().parse(
new BufferedInputStream(Files.newInputStream(path)).readAllBytes());
for (int i = 1; i < classFile.constantPool().entryCount(); ++i) {
PoolEntry pe = classFile.constantPool().entryByIndex(i);
if (pe instanceof Utf8Entry utf8Info) {
Assert.check(utf8Info.stringValue().length() > 0,
"UTF8 with length 0 found at class " + classFile.thisClass().name());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@
* @test
* @bug 8028504
* @summary javac generates LocalVariableTable even with -g:none
* @modules jdk.jdeps/com.sun.tools.classfile
* @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
* @compile -g:none DontGenerateLVTForGNoneOpTest.java
* @run main DontGenerateLVTForGNoneOpTest
*/
Expand All @@ -35,10 +39,8 @@
import java.lang.annotation.Target;
import java.nio.file.Paths;

import com.sun.tools.classfile.Attribute;
import com.sun.tools.classfile.ClassFile;
import com.sun.tools.classfile.Code_attribute;
import com.sun.tools.classfile.Method;
import jdk.internal.classfile.*;
import jdk.internal.classfile.attribute.CodeAttribute;

public class DontGenerateLVTForGNoneOpTest {

Expand All @@ -52,11 +54,11 @@ void run() throws Exception {
}

void checkClassFile(final File cfile) throws Exception {
ClassFile classFile = ClassFile.read(cfile);
for (Method method : classFile.methods) {
Code_attribute code = (Code_attribute)method.attributes.get(Attribute.Code);
ClassModel classFile = Classfile.of().parse(cfile.toPath());
for (MethodModel method : classFile.methods()) {
CodeAttribute code = method.findAttribute(Attributes.CODE).orElse(null);
if (code != null) {
if (code.attributes.get(Attribute.LocalVariableTable) != null) {
if (code.findAttribute(Attributes.LOCAL_VARIABLE_TABLE).orElse(null) != null) {
throw new AssertionError("LVT shouldn't be generated for g:none");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@
* @test
* @summary
* @library /tools/lib
* @modules jdk.jdeps/com.sun.tools.classfile
* @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
* jdk.compiler/com.sun.tools.javac.api
* jdk.compiler/com.sun.tools.javac.main
* jdk.compiler/com.sun.tools.javac.util
Expand All @@ -37,7 +41,8 @@
import java.io.File;
import java.nio.file.Paths;

import com.sun.tools.classfile.*;
import jdk.internal.classfile.*;
import jdk.internal.classfile.attribute.*;
import com.sun.tools.javac.util.Assert;

import toolbox.JavacTask;
Expand All @@ -64,11 +69,12 @@ void run() throws Exception {
.run();

File cfile = new File(Paths.get(System.getProperty("user.dir"), "Test.class").toUri());
ClassFile classFile = ClassFile.read(cfile);
for (Method method: classFile.methods) {
if (method.getName(classFile.constant_pool).equals("foo")) {
Code_attribute codeAttr = (Code_attribute)method.attributes.get("Code");
Assert.check(codeAttr.max_locals == 0, "max locals found " + codeAttr.max_locals);
ClassModel classFile = Classfile.of().parse(cfile.toPath());
for (MethodModel method: classFile.methods()) {
if (method.methodName().stringValue().equals("foo")) {
CodeAttribute codeAttr = method.findAttribute(Attributes.CODE).orElse(null);
assert codeAttr != null;
Assert.check(codeAttr.maxLocals() == 0, "max locals found " + codeAttr.maxLocals());
}
}
}
Expand Down
11 changes: 8 additions & 3 deletions test/langtools/tools/javac/annotations/SyntheticParameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@
* @bug 8065132
* @summary Test generation of annotations on inner class parameters.
* @library /lib/annotations/
* @modules jdk.jdeps/com.sun.tools.classfile
* @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
* java.base/jdk.internal.classfile.impl
* @build annotations.classfile.ClassfileInspector SyntheticParameters
* @run main SyntheticParameters
*/
Expand All @@ -36,7 +41,7 @@
import java.io.*;
import java.lang.annotation.*;

import com.sun.tools.classfile.*;
import jdk.internal.classfile.ClassModel;

public class SyntheticParameters extends ClassfileInspector {

Expand Down Expand Up @@ -116,7 +121,7 @@ public class SyntheticParameters extends ClassfileInspector {

public static void main(String... args) throws Exception {
new SyntheticParameters().run(
new ClassFile[] { getClassFile(Inner_class, Inner.class),
new ClassModel[] { getClassFile(Inner_class, Inner.class),
getClassFile(Foo_class, Foo.class) },
new Expected[] { Inner_expected, Foo_expected });
}
Expand Down

1 comment on commit 380418f

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.