Skip to content
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

8252689: Classes are loaded from jrt:/java.base even when CDS is used #134

Closed
wants to merge 3 commits into from
Closed

8252689: Classes are loaded from jrt:/java.base even when CDS is used #134

wants to merge 3 commits into from

Conversation

yminqi
Copy link
Contributor

@yminqi yminqi commented Sep 11, 2020

Java.util.jar.Manifest related classes not archived since they are neither in classlist or loaded in dump process. Manually create a dummy Manifest object will cause those classes loaded in dump and archived.


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8252689: Classes are loaded from jrt:/java.base even when CDS is used

Reviewers

Download

$ git fetch https://git.openjdk.java.net/jdk pull/134/head:pull/134
$ git checkout pull/134

@bridgekeeper
Copy link

bridgekeeper bot commented Sep 11, 2020

👋 Welcome back minqi! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr Pull request is ready for review label Sep 11, 2020
@openjdk
Copy link

openjdk bot commented Sep 11, 2020

@yminqi The following label will be automatically applied to this pull request: hotspot-runtime.

When this pull request is ready to be reviewed, an RFR email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label (add|remove) "label" command.

@openjdk openjdk bot added the hotspot-runtime hotspot-runtime-dev@openjdk.org label Sep 11, 2020
@mlbridge
Copy link

mlbridge bot commented Sep 11, 2020

Webrevs

@cl4es
Copy link
Member

cl4es commented Sep 11, 2020

I think you could achieve the same if you extend the HelloClasslist tool built and used to generate the default classlist file to include a manifest in its jar file. Add a dummy manifest.mf somewhere and edit the CLASSLIST_JAR target in GenerateLinkOptData to include it in the jar.

This would avoid hard-coding this in hotspot code and keep the responsibility of curating the default classlist in one place.

@iklam
Copy link
Member

iklam commented Sep 11, 2020

I think you could achieve the same if you extend the HelloClasslist tool built and used to generate the default classlist file to include a manifest in its jar file. Add a dummy manifest.mf somewhere and edit the CLASSLIST_JAR target in GenerateLinkOptData to include it in the jar.

This would avoid hard-coding this in hotspot code and keep the responsibility of curating the default classlist in one place.

During the JDK build, HelloClasslist is already packaged with a manifest:

$ jar tf ./support/classlist.jar
META-INF/
META-INF/MANIFEST.MF
build/tools/classlist/HelloClasslist.class

And the default CDS archive contains the 3 classes mentioned in the bug report:

$ ./images/jdk/bin/java -cp ./support/classlist.jar -verbose build.tools.classlist.HelloClasslist | \
    egrep '((java.util.jar.Attributes)|(java.util.LinkedHashMap)|(java.util.jar.Manifest.FastInputStream)) source'
[0.044s][info][class,load] java.util.jar.Attributes source: shared objects file
[0.044s][info][class,load] java.util.LinkedHashMap source: shared objects file
[0.044s][info][class,load] java.util.jar.Manifest$FastInputStream source: shared objects file

However, for some reason, if you run a simple HelloWorld.jar to collect the class list, these 3 classes are not loaded. As a result, these classes may not be stored in custom archives created from your own class lists.

$ jar tf ~/tmp/HelloWorld.jar
META-INF/
META-INF/MANIFEST.MF
HelloWorld.class
$ ./images/jdk/bin/java -Xshare:off -cp ~/tmp/HelloWorld.jar -verbose \
    -XX:DumpLoadedClassList=foo.list HelloWorld | egrep \
    '((java.util.jar.Attributes)|(java.util.LinkedHashMap)|(java.util.jar.Manifest.FastInputStream)) source' | wc
      0       0       0

I think the reason is the built-in class loader's Java code takes a different code path than the CDS shared class loading code (systemDictionaryShared.cpp). So we should exercise the CDS code during dump time to ensure that the classes used by CDS are always loaded.

iklam
iklam approved these changes Sep 11, 2020
@@ -1356,6 +1356,8 @@ void MetaspaceShared::preload_and_dump(TRAPS) {

HeapShared::init_for_dumping(THREAD);

// create a dummy manifest to cause more classes loaded
Copy link
Member

@iklam iklam Sep 11, 2020

Choose a reason for hiding this comment

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

How about: // exercise the manifest processing code to ensue classes used by CDS are always archived?

Copy link
Member

@dcubed-ojdk dcubed-ojdk Sep 11, 2020

Choose a reason for hiding this comment

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

s/ensue classes/ensure classes/

@@ -671,30 +687,17 @@ Handle SystemDictionaryShared::get_shared_jar_manifest(int shared_path_index, TR
Handle manifest ;
if (shared_jar_manifest(shared_path_index) == NULL) {
SharedClassPathEntry* ent = FileMapInfo::shared_path(shared_path_index);
long size = ent->manifest_size();
size_t size = (size_t)ent->manifest_size();
Copy link
Member

@iklam iklam Sep 11, 2020

Choose a reason for hiding this comment

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

size_t is unsigned, so I think you should change the following test to if (size == 0)

@openjdk
Copy link

openjdk bot commented Sep 11, 2020

@yminqi This change now passes all automated pre-integration checks. In addition to the automated checks, the change must also fulfill all project specific requirements

After integration, the commit message will be:

8252689: Classes are loaded from jrt:/java.base even when CDS is used

Reviewed-by: iklam, ccheung
  • If you would like to add a summary, use the /summary command.
  • To credit additional contributors, use the /contributor command.
  • To add additional solved issues, use the /issue command.

Since the source branch of this PR was last updated there have been 27 commits pushed to the master branch:

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid automatic rebasing, please merge master into your branch, and then specify the current head hash when integrating, like this: /integrate c5e63b639e9387eb45877cec291fc9141341e993.

➡️ 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 11, 2020
iklam
iklam approved these changes Sep 11, 2020
Copy link
Member

@calvinccheung calvinccheung left a comment

Looks good.

@yminqi
Copy link
Contributor Author

yminqi commented Sep 14, 2020

/integrate

@openjdk openjdk bot closed this Sep 14, 2020
@openjdk openjdk bot added integrated Pull request has been integrated and removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Sep 14, 2020
@openjdk
Copy link

openjdk bot commented Sep 14, 2020

@yminqi Since your change was applied there have been 27 commits pushed to the master branch:

Your commit was automatically rebased without conflicts.

Pushed as commit f978f6f.

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

@yminqi yminqi deleted the jdk-8252689 branch Sep 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot-runtime hotspot-runtime-dev@openjdk.org integrated Pull request has been integrated
5 participants