Skip to content

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

Closed
wants to merge 235 commits into from

Conversation

asotona
Copy link
Member

@asotona asotona commented Nov 29, 2022

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

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8294969: Convert jdk.jdeps javap to use the Classfile API (Sub-task - P4)

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

asotona and others added 30 commits June 10, 2022 14:20
…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.
@asotona
Copy link
Member Author

asotona commented Jul 27, 2023

Important fixes have been integrated and all tests are now passing.

Please review.

Thanks,
Adam

@bridgekeeper
Copy link

bridgekeeper bot commented Aug 24, 2023

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

@asotona
Copy link
Member Author

asotona commented Aug 28, 2023

keep open

}
}
}

private AnnotationWriter annotationWriter;
private ClassWriter classWriter;
private Map<Integer, List<Note>> pcMap;
private CodeAttribute lr;
Copy link
Contributor

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

Copy link
Member Author

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);
Copy link
Contributor

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?

Copy link
Member Author

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.
Copy link
Contributor

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?

Copy link
Member Author

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) {
Copy link
Contributor

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 {
Copy link
Contributor

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

Copy link
Member Author

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
Copy link
Contributor

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

Copy link
Member Author

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???
Copy link
Contributor

Choose a reason for hiding this comment

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

what about this comment?

Copy link
Member Author

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 ???
Copy link
Contributor

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

Copy link
Member Author

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);

Copy link
Contributor

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)

Copy link
Member Author

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.

Copy link
Contributor

@vicente-romero-oracle vicente-romero-oracle left a 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

@openjdk
Copy link

openjdk bot commented Sep 15, 2023

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

8294969: Convert jdk.jdeps javap to use the Classfile API

Reviewed-by: vromero

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 master branch:

  • 8dfde28: 8315485: (fs) Move java/nio/file/Path/Misc.java tests into java/nio/file/Path/PathOps.java
  • 3c743cf: 8312126: NullPointerException in CertStore.getCRLs after 8297955
  • bd26813: 8316295: Serial: Remove empty Generation::promotion_failure_occurred
  • 42dc6b5: 8316182: RISC-V: SA stack walking code having trouble finding sender frame when invoking LambdaForms is involved
  • 31c4e03: 8314551: More generic way to handshake GC threads with monitor deflation
  • 89cb290: 8312165: Fix typos in java.desktop Swing
  • 25f32f3: 8316160: Remove sun.misc.Unsafe.{shouldBeInitialized,ensureClassInitialized}
  • 86dde5e: 8316001: GC: Make TestArrayAllocatorMallocLimit use createTestJvm
  • 4f864fa: 8314136: Test java/net/httpclient/CancelRequestTest.java failed: WARNING: tracker for HttpClientImpl(42) has outstanding operations
  • 4070829: 8315931: RISC-V: xxxMaxVectorTestsSmokeTest fails when using RVV
  • ... and 10 more: https://git.openjdk.org/jdk/compare/b2e91060db82a13e993227f538c8d54b41a9796b...master

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 master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Sep 15, 2023
@asotona
Copy link
Member Author

asotona commented Sep 18, 2023

/integrate

@openjdk
Copy link

openjdk bot commented Sep 18, 2023

Going to push as commit 1203e11.
Since your change was applied there have been 31 commits pushed to the master branch:

  • fbc766e: 8315988: Parallel: Make TestAggressiveHeap use createTestJvm
  • aa0ebee: 8316341: sun/security/pkcs11/PKCS11Test.java needs adjustment on Linux ppc64le Ubuntu 22
  • ca3fe7b: 8315932: runtime/InvocationTests spend a lot of time on dependency verification
  • f440329: 8316391: (zipfs) ZipFileSystem.readFullyAt does not tolerate short reads
  • 4b8f5d0: 8316273: JDK-8315818 broke JVMCIPrintProperties on libgraal
  • e624198: 8316387: Exclude more failing multicast tests on AIX after JDK-8315651
  • c92bdb0: 8316187: Modernize examples in StringTokenizer and {Date,Number}Format
  • 8f46abc: 8315889: Open source several Swing HTMLDocument related tests
  • 0050447: 8316148: Remove sun/tools/jhsdb/JStackStressTest.java from problem list
  • 149acd1: 8316207: Fix typos in java.io.StreamTokenizer
  • ... and 21 more: https://git.openjdk.org/jdk/compare/b2e91060db82a13e993227f538c8d54b41a9796b...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Sep 18, 2023
@openjdk openjdk bot closed this Sep 18, 2023
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Sep 18, 2023
@openjdk
Copy link

openjdk bot commented Sep 18, 2023

@asotona Pushed as commit 1203e11.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler compiler-dev@openjdk.org core-libs core-libs-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

8 participants