-
Notifications
You must be signed in to change notification settings - Fork 6.1k
8294969: Convert jdk.jdeps javap to use the Classfile API #11411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…e and added test (openjdk#11)
…lang.reflect.AccesFlag in Classfile API and tests
…andleInfo implemented RebuildingTransformation and added to Transforms and CorpusTest reduced CorpusTestHelper output and adjusted TEST.properties
MethodParameterInfo name parameter changed to Optional added MethodParameterInfo::ofParameter(Optional<String>,int) implemented TemporaryConstantPool::stringEntry adjusted BoundAttribute and RebuildingTransformation test helper
EnclosingMethodAttribute factory method changed to accept Optionals added EnclosingMethodAttribute::of(ClassDesc,Optional<String>,Optional<MethodTypeDesc>) added EnclosingMethodAttribute accessor methods InnerClassInfo all factory methods changed to accept Optionals added NestHostAttribute::of(ClassDesc) added SourceIDAttribute::of(String) changes reflected in BoundAttribute and RebuildTransformation test helper
* added TypeAnnotation factory methods accepting ClassDesc and AnnotationElement... AnnotationValue.OfConstant sub-classed to allow switch pattern matching RebuildingTransformation test helper adjusted * added TypeAnnotation.TargetInfo factory methods with validity checking for multi-target types adjusted RebuildTransformation test helper
…Symbol (openjdk#13) refactored to FieldModel::fieldTypeSymbol and MethodModel::methodTypeSymbol (openjdk#13) added round testing of signatures in RebuildTransformation test helper
… a frame type. Doing so, make the chop size available to consumers of frames.
…ptor argument slots
…ass cast and throw ConstantPoolException instead
fix of javap ConstantWriter to print DynamicConstantPoolEntry without accessing BSM attribute
Important fixes have been integrated and all tests are now passing. Please review. Thanks, |
@asotona This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration! |
keep open |
} | ||
} | ||
} | ||
|
||
private AnnotationWriter annotationWriter; | ||
private ClassWriter classWriter; | ||
private Map<Integer, List<Note>> pcMap; | ||
private CodeAttribute lr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: name lr
doesn't relate much to the type of the field
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, lr
historically came from label resolver, I'll fix it.
int res = com.sun.tools.javap.Main.run( | ||
new String[]{"-c", System.getProperty("test.classes") + "/InvalidSignature.class"}, | ||
new PrintWriter(sw)); | ||
System.out.println(sw); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this for debug purpose only?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is the test fix.
8260403 says "javap should be more robust", however to expect zero exit code for invalid class is wrong.
It suppose to expect non-zero exit code and fail only on fatal errors or unhandled CP errors.
@@ -0,0 +1,50 @@ | |||
/* | |||
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't this test testing the same as: test/langtools/tools/javap/8260403/T8260403.java
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The principle of the test is the same, but it tests intentionally different class malformations (on a different level).
if (!method.access_flags.is(AccessFlags.ACC_STATIC)) | ||
++n; // for 'this' | ||
argCount = Integer.toString(n); | ||
} catch (ConstantPoolException e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice clean-up
@@ -50,19 +46,21 @@ | |||
public class LocalVariableTableWriter extends InstructionDetailWriter { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: two spaces between extends
and InstructionDetailWriter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed, thanks
FloatEntry readFloatEntry(int offset); | ||
|
||
/** | ||
* {@return the field ref entry whose index is given at the specified |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that ref
in these APIs should be reference
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed, thanks
println("ModuleTarget:"); | ||
indent(+1); | ||
print("target_platform: #" + attr.targetPlatform().index()); | ||
//ToDo find the spec - can be null??? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about this comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed according to the available spec information
println("SourceFile: \"" + attr.sourceFile().stringValue() + "\""); | ||
case SourceIDAttribute attr -> | ||
constantWriter.write(attr.sourceId().index()); | ||
// case StackMapAttribute ??? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this comment can be removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed, thanks
* a constant value entry | ||
*/ | ||
ConstantValueEntry readConstantValueEntry(int offset); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that all this additional API surface carries its weight in ClassReader, when each of these methods just called readEntry() and casts to the desired type? I can see two alternate ways here:
- Ordinary casts at the use site (worse error handling, but ultimately the same result), or
- A single method
T readEntry(int pos, Class t)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need at least <T extends PoolEntry> T readEntry(int pos, Class<T> t)
to throw ConstantPoolException
instead of ClassCastException
from broken entries.
# Conflicts: # src/java.base/share/classes/jdk/internal/classfile/impl/ClassReaderImpl.java
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good to me
@asotona This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 20 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
/integrate |
Going to push as commit 1203e11.
Your commit was automatically rebased without conflicts. |
javap uses proprietary com.sun.tools.classfile library to parse class files.
This patch converts javap to use Classfile API.
Please review.
Thanks,
Adam
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/11411/head:pull/11411
$ git checkout pull/11411
Update a local copy of the PR:
$ git checkout pull/11411
$ git pull https://git.openjdk.org/jdk.git pull/11411/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 11411
View PR using the GUI difftool:
$ git pr show -t 11411
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/11411.diff
Webrev
Link to Webrev Comment