Skip to content

Commit

Permalink
8315444: Convert test/jdk/tools to Classfile API
Browse files Browse the repository at this point in the history
Reviewed-by: asotona
  • Loading branch information
xqoasis authored and asotona committed Sep 7, 2023
1 parent 81f8c57 commit 2fd870a
Show file tree
Hide file tree
Showing 24 changed files with 142 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@
* @requires (vm.compMode != "Xcomp" & os.maxMemory >= 2g)
* @library /tools/lib
* @modules java.base/jdk.internal.jimage
* jdk.jdeps/com.sun.tools.classfile
* 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.jlink/jdk.tools.jimage
* jdk.compiler
* @build HijrahConfigCheck tests.*
Expand Down
6 changes: 5 additions & 1 deletion test/jdk/tools/jimage/JImageNonAsciiNameTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@
* @library ../lib
* /test/lib
* @modules java.base/jdk.internal.jimage
* jdk.jdeps/com.sun.tools.classfile
* 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.jlink/jdk.tools.jimage
* @build tests.*
* @run main/othervm JImageNonAsciiNameTest
Expand Down
6 changes: 5 additions & 1 deletion test/jdk/tools/jimage/JImageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@
* @bug 8222100
* @library ../lib
* @modules java.base/jdk.internal.jimage
* jdk.jdeps/com.sun.tools.classfile
* 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.jlink/jdk.tools.jmod
* jdk.jlink/jdk.tools.jimage
* jdk.jlink/jdk.tools.jlink.internal
Expand Down
6 changes: 5 additions & 1 deletion test/jdk/tools/jlink/DefaultProviderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@
* @requires vm.compMode != "Xcomp"
* @library ../lib
* @modules java.base/jdk.internal.jimage
* jdk.jdeps/com.sun.tools.classfile
* 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.jlink/jdk.tools.jlink.internal
* jdk.jlink/jdk.tools.jlink.plugin
* jdk.jlink/jdk.tools.jmod
Expand Down
6 changes: 5 additions & 1 deletion test/jdk/tools/jlink/ExplodedModuleNameTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@
* @summary Inconsistent handling of exploded modules in jlink
* @library ../lib
* @modules java.base/jdk.internal.jimage
* jdk.jdeps/com.sun.tools.classfile
* 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.jlink/jdk.tools.jlink.internal
* jdk.jlink/jdk.tools.jmod
* jdk.jlink/jdk.tools.jimage
Expand Down
6 changes: 5 additions & 1 deletion test/jdk/tools/jlink/IntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@
* @author Jean-Francois Denise
* @library ../lib
* @modules java.base/jdk.internal.jimage
* jdk.jdeps/com.sun.tools.classfile
* 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.jlink/jdk.tools.jlink.builder
* jdk.jlink/jdk.tools.jlink.internal
* jdk.jlink/jdk.tools.jlink.internal.plugins
Expand Down
6 changes: 5 additions & 1 deletion test/jdk/tools/jlink/JLink100Modules.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@
* @bug 8240567
* @library ../lib
* @modules java.base/jdk.internal.jimage
* jdk.jdeps/com.sun.tools.classfile
* 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.jlink/jdk.tools.jlink.internal
* jdk.jlink/jdk.tools.jlink.plugin
* jdk.jlink/jdk.tools.jmod
Expand Down
6 changes: 5 additions & 1 deletion test/jdk/tools/jlink/JLink2Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@
* @author Jean-Francois Denise
* @library ../lib
* @modules java.base/jdk.internal.jimage
* jdk.jdeps/com.sun.tools.classfile
* 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.jlink/jdk.tools.jlink.internal
* jdk.jlink/jdk.tools.jlink.plugin
* jdk.jlink/jdk.tools.jmod
Expand Down
6 changes: 5 additions & 1 deletion test/jdk/tools/jlink/JLinkDedupTestBatchSizeOne.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@
* @library /test/lib
* ../lib
* @modules java.base/jdk.internal.jimage
* jdk.jdeps/com.sun.tools.classfile
* 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.jlink/jdk.tools.jlink.internal
* jdk.jlink/jdk.tools.jlink.plugin
* jdk.jlink/jdk.tools.jmod
Expand Down
6 changes: 5 additions & 1 deletion test/jdk/tools/jlink/JLinkNegativeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@
* java.base/jdk.internal.classfile.constantpool
* java.base/jdk.internal.jimage
* java.base/jdk.internal.module
* jdk.jdeps/com.sun.tools.classfile
* 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.jlink/jdk.tools.jlink.internal
* jdk.jlink/jdk.tools.jmod
* jdk.jlink/jdk.tools.jimage
Expand Down
6 changes: 5 additions & 1 deletion test/jdk/tools/jlink/JLinkOptionsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@
* @author Jean-Francois Denise
* @library ../lib
* @modules java.base/jdk.internal.jimage
* jdk.jdeps/com.sun.tools.classfile
* 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.jlink/jdk.tools.jlink.internal
* jdk.jlink/jdk.tools.jlink.plugin
* jdk.jlink/jdk.tools.jmod
Expand Down
6 changes: 5 additions & 1 deletion test/jdk/tools/jlink/JLinkPluginsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@
* @requires (vm.compMode != "Xcomp" & os.maxMemory >= 2g)
* @library ../lib
* @modules java.base/jdk.internal.jimage
* jdk.jdeps/com.sun.tools.classfile
* 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.jlink/jdk.tools.jlink.internal
* jdk.jlink/jdk.tools.jmod
* jdk.jlink/jdk.tools.jimage
Expand Down
6 changes: 5 additions & 1 deletion test/jdk/tools/jlink/JLinkTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@
* @requires (vm.compMode != "Xcomp" & os.maxMemory >= 2g)
* @library ../lib
* @modules java.base/jdk.internal.jimage
* jdk.jdeps/com.sun.tools.classfile
* 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.jlink/jdk.tools.jlink.internal
* jdk.jlink/jdk.tools.jlink.plugin
* jdk.jlink/jdk.tools.jimage
Expand Down
6 changes: 5 additions & 1 deletion test/jdk/tools/jlink/ModuleNamesOrderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@
* @summary MODULES property should be topologically ordered and space-separated list
* @library ../lib
* @modules java.base/jdk.internal.jimage
* jdk.jdeps/com.sun.tools.classfile
* 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.jlink/jdk.tools.jlink.internal
* jdk.jlink/jdk.tools.jmod
* jdk.jlink/jdk.tools.jimage
Expand Down
6 changes: 5 additions & 1 deletion test/jdk/tools/jlink/NativeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@
* @author Andrei Eremeev
* @library ../lib
* @modules java.base/jdk.internal.jimage
* jdk.jdeps/com.sun.tools.classfile
* 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.jlink/jdk.tools.jlink.internal
* jdk.jlink/jdk.tools.jmod
* jdk.jlink/jdk.tools.jimage
Expand Down
6 changes: 5 additions & 1 deletion test/jdk/tools/jlink/plugins/AddOptionsPluginTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@
* @library ../../lib
* @library /test/lib
* @modules java.base/jdk.internal.jimage
* jdk.jdeps/com.sun.tools.classfile
* 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.jlink/jdk.tools.jlink.internal
* jdk.jlink/jdk.tools.jmod
* jdk.jlink/jdk.tools.jimage
Expand Down
6 changes: 5 additions & 1 deletion test/jdk/tools/jlink/plugins/CDSPluginTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@
* @library ../../lib
* @library /test/lib
* @modules java.base/jdk.internal.jimage
* jdk.jdeps/com.sun.tools.classfile
* 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.jlink/jdk.tools.jlink.internal
* jdk.jlink/jdk.tools.jmod
* jdk.jlink/jdk.tools.jimage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@
* @library ../../lib
* @summary Test --generate-jli-classes plugin
* @modules java.base/jdk.internal.jimage
* jdk.jdeps/com.sun.tools.classfile
* 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.jlink/jdk.tools.jlink.internal
* jdk.jlink/jdk.tools.jlink.internal.plugins
* jdk.jlink/jdk.tools.jmod
Expand Down
6 changes: 5 additions & 1 deletion test/jdk/tools/jlink/plugins/IncludeLocalesPluginTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@
* @requires (vm.compMode != "Xcomp" & os.maxMemory >= 2g)
* @library ../../lib
* @modules java.base/jdk.internal.jimage
* jdk.jdeps/com.sun.tools.classfile
* 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.jlink/jdk.tools.jlink.internal
* jdk.jlink/jdk.tools.jlink.internal.plugins
* jdk.jlink/jdk.tools.jlink.plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@
* @library ../../lib
* @library /test/lib
* @modules java.base/jdk.internal.jimage
* jdk.jdeps/com.sun.tools.classfile
* 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.jlink/jdk.tools.jlink.internal
* jdk.jlink/jdk.tools.jmod
* jdk.jlink/jdk.tools.jimage
Expand Down
6 changes: 5 additions & 1 deletion test/jdk/tools/jlink/plugins/StringSharingPluginTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@
* jdk.jlink/jdk.tools.jlink.plugin
* jdk.jlink/jdk.tools.jmod
* jdk.jlink/jdk.tools.jimage
* jdk.jdeps/com.sun.tools.classfile
* 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
* @run build tests.*
* @run main StringSharingPluginTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@
* jdk.jlink/jdk.tools.jlink.plugin
* jdk.jlink/jdk.tools.jimage
* jdk.jlink/jdk.tools.jmod
* jdk.jdeps/com.sun.tools.classfile
* 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
* @run main StripJavaDebugAttributesPluginTest
*/
Expand All @@ -42,19 +46,11 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.*;
import java.util.stream.Stream;

import com.sun.tools.classfile.Attribute;
import com.sun.tools.classfile.ClassFile;
import com.sun.tools.classfile.Code_attribute;
import com.sun.tools.classfile.ConstantPoolException;
import com.sun.tools.classfile.Method;

import jdk.internal.classfile.*;
import jdk.internal.classfile.attribute.CodeAttribute;
import jdk.tools.jlink.internal.ResourcePoolManager;
import jdk.tools.jlink.internal.plugins.StripJavaDebugAttributesPlugin;
import jdk.tools.jlink.plugin.Plugin;
Expand Down Expand Up @@ -141,21 +137,22 @@ private ResourcePoolEntry stripDebug(Plugin debug, ResourcePoolEntry classResour
return resPool.findEntry(classResource.path()).get();
}

private void checkDebugAttributes(byte[] strippedClassFile) throws IOException, ConstantPoolException {
ClassFile classFile = ClassFile.read(new ByteArrayInputStream(strippedClassFile));
String[] debugAttributes = new String[]{
Attribute.LineNumberTable,
Attribute.LocalVariableTable,
Attribute.LocalVariableTypeTable
};
for (Method method : classFile.methods) {
String methodName = method.getName(classFile.constant_pool);
Code_attribute code = (Code_attribute) method.attributes.get(Attribute.Code);
for (String attr : debugAttributes) {
if (code.attributes.get(attr) != null) {
throw new AssertionError("Debug attribute was not removed: " + attr +
" from method " + classFile.getName() + "#" + methodName);
}
private <T extends Attribute<T>> void checkDebugAttributes(byte[] strippedClassFile) {
ClassModel classFile = Classfile.of().parse(strippedClassFile);
for (MethodModel method : classFile.methods()) {
String methodName = method.methodName().stringValue();
CodeAttribute code = method.findAttribute(Attributes.CODE).orElseThrow();
if (code.findAttribute(Attributes.LINE_NUMBER_TABLE).orElse(null) != null) {
throw new AssertionError("Debug attribute was not removed: " + "LINE_NUMBER_TABLE" +
" from method " + classFile.thisClass().asInternalName() + "#" + methodName);
}
if (code.findAttribute(Attributes.LOCAL_VARIABLE_TABLE).orElse(null) != null) {
throw new AssertionError("Debug attribute was not removed: " + "LOCAL_VARIABLE_TABLE" +
" from method " + classFile.thisClass().asInternalName() + "#" + methodName);
}
if (code.findAttribute(Attributes.LOCAL_VARIABLE_TYPE_TABLE).orElse(null) != null) {
throw new AssertionError("Debug attribute was not removed: " + "LOCAL_VARIABLE_TYPE_TABLE" +
" from method " + classFile.thisClass().asInternalName() + "#" + methodName);
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion test/jdk/tools/jlink/plugins/VendorInfoPluginsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@
* @library ../../lib
* @library /test/lib
* @modules java.base/jdk.internal.jimage
* jdk.jdeps/com.sun.tools.classfile
* 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.jlink/jdk.tools.jlink.internal
* jdk.jlink/jdk.tools.jmod
* jdk.jlink/jdk.tools.jimage
Expand Down
17 changes: 8 additions & 9 deletions test/jdk/tools/lib/tests/JImageValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,16 @@
*/
package tests;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

import com.sun.tools.classfile.ClassFile;
import com.sun.tools.classfile.ConstantPoolException;
import jdk.internal.classfile.Classfile;
import jdk.internal.jimage.BasicImageReader;
import jdk.internal.jimage.ImageLocation;

Expand Down Expand Up @@ -224,11 +221,13 @@ public long getModuleLauncherExecutionTime() {
return moduleExecutionTime;
}

public static void readClass(byte[] clazz) throws IOException {
try (InputStream stream = new ByteArrayInputStream(clazz)) {
ClassFile.read(stream);
} catch (ConstantPoolException e) {
throw new IOException(e);
public static void readClass(byte[] clazz) throws IOException{
var errors = Classfile.of().parse(clazz).verify(null);
if (!errors.isEmpty()) {
var itr = errors.iterator();
var thrown = itr.next();
itr.forEachRemaining(thrown::addSuppressed);
throw new IOException(thrown);
}
}
}

1 comment on commit 2fd870a

@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.