Skip to content

Conversation

@tstuefe
Copy link
Member

@tstuefe tstuefe commented Mar 31, 2025

In preparation for planned GC performance improvements (KLUT), I would like to reduce the average number of oop map entries.

For details, please see JBS issue text.


Patch results:

The patch brings a positive change of oop map size, reducing the likelihood of lengthy oop maps. Here the oop map size distribution over all JDK classes in the JDK image:

Before:

   5395  - non-static oop maps (0 entries)
   9330  - non-static oop maps (1 entries)
   1449  - non-static oop maps (2 entries)
    274  - non-static oop maps (3 entries)
    218  - non-static oop maps (4 entries)
     75  - non-static oop maps (5 entries)
      7  - non-static oop maps (6 entries)
      4  - non-static oop maps (7 entries)

Now:

   5395  - non-static oop maps (0 entries)
  10178  - non-static oop maps (1 entries)
    933  - non-static oop maps (2 entries)
    229  - non-static oop maps (3 entries)
     16  - non-static oop maps (4 entries)
      1  - non-static oop maps (5 entries)

For example, java.util.concurrent.ConcurrentHashMap$TreeNode is changed from having 2 entries to having just one entry, which is nice for a class that may be instantiated a lot:

Before:

java.util.concurrent.ConcurrentHashMap$TreeNode {0x000000000d1dddc0}
 - ---- non-static fields (9 words):
 - final 'hash' 'I' @12
 - final 'key' 'Ljava/lang/Object;' @16 
 - volatile 'val' 'Ljava/lang/Object;' @20 
 - volatile 'next' 'Ljava/util/concurrent/ConcurrentHashMap$Node;' @24       << last field of base class
 - 'red' 'Z' @28                                                             << derived class starts here, non-oops lead
 - 'parent' 'Ljava/util/concurrent/ConcurrentHashMap$TreeNode;' @32 
 - 'left' 'Ljava/util/concurrent/ConcurrentHashMap$TreeNode;' @36 
 - 'right' 'Ljava/util/concurrent/ConcurrentHashMap$TreeNode;' @40 
 - 'prev' 'Ljava/util/concurrent/ConcurrentHashMap$TreeNode;' @44 
 - non-static oop maps (2 entries): 16-24 32-44  

Now:

java.util.concurrent.ConcurrentHashMap$TreeNode {0x000000007e1de450}
 - ---- non-static fields (9 words):
 - final 'hash' 'I' @12 
 - final 'key' 'Ljava/lang/Object;' @16 
 - volatile 'val' 'Ljava/lang/Object;' @20 
 - volatile 'next' 'Ljava/util/concurrent/ConcurrentHashMap$Node;' @24       << last field of base class
 - 'parent' 'Ljava/util/concurrent/ConcurrentHashMap$TreeNode;' @28          << class starts here, oops lead
 - 'left' 'Ljava/util/concurrent/ConcurrentHashMap$TreeNode;' @32 
 - 'right' 'Ljava/util/concurrent/ConcurrentHashMap$TreeNode;' @36 
 - 'prev' 'Ljava/util/concurrent/ConcurrentHashMap$TreeNode;' @40 
 - 'red' 'Z' @44 
 - non-static oop maps (1 entries): 16-40 

Note how the sole primitive field of the derived class, "red", changed position to let oops lead.

Here a contrived example to demonstrate how reordering works across several inheritance levels:

Before:

GeneratedClass9730 {0x000000008f93ea50}
 - ---- non-static fields (11 words):
 - public 'derived0_I_0' 'I' @12 
 - public 'derived0_o_0' 'Ljava/lang/Object;' @16                            << last field of base class
 - public 'derived1_I_0' 'I' @20 
 - public 'derived1_o_0' 'Ljava/lang/Object;' @24                            << last field of derived class 1
 - public 'derived2_I_0' 'I' @28 
 - public 'derived2_o_0' 'Ljava/lang/Object;' @32                            << last field of derived class 2
 - public 'derived3_I_0' 'I' @36 
 - public 'derived3_o_0' 'Ljava/lang/Object;' @40                            << last field of derived class 3
 - public 'derived4_I_0' 'I' @44 
 - public 'derived4_o_0' 'Ljava/lang/Object;' @48                            << last field of derived class 4
 - public 'o0' 'Ljava/lang/Object;' @52                                      << this class starts here
 - non-static oop maps (5 entries): 16-16 24-24 32-32 40-40 48-52 

After

GeneratedClass9730 {0x00000000a793e5f8}
 - ---- non-static fields (11 words):
 - public 'derived0_I_0' 'I' @12 
 - public 'derived0_o_0' 'Ljava/lang/Object;' @16                            << last field of base class
 - public 'derived1_o_0' 'Ljava/lang/Object;' @20 
 - public 'derived1_I_0' 'I' @24                                             << last field of derived class 1
 - public 'derived2_I_0' 'I' @28 
 - public 'derived2_o_0' 'Ljava/lang/Object;' @32                            << last field of derived class 2
 - public 'derived3_o_0' 'Ljava/lang/Object;' @36 
 - public 'derived3_I_0' 'I' @40                                             << last field of derived class 3
 - public 'derived4_I_0' 'I' @44 
 - public 'derived4_o_0' 'Ljava/lang/Object;' @48                            << last field of derived class 4
 - public 'o0' 'Ljava/lang/Object;' @52                                      << this class starts here
 - non-static oop maps (3 entries): 16-20 32-36 48-52  

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-8353273: Reduce number of oop map entries in instances (Enhancement - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/24330/head:pull/24330
$ git checkout pull/24330

Update a local copy of the PR:
$ git checkout pull/24330
$ git pull https://git.openjdk.org/jdk.git pull/24330/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 24330

View PR using the GUI difftool:
$ git pr show -t 24330

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/24330.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Mar 31, 2025

👋 Welcome back stuefe! 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
Copy link

openjdk bot commented Mar 31, 2025

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

8353273: Reduce number of oop map entries in instances

Reviewed-by: lmesnik, fparain, jsjolen

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 17 new 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 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 changed the title JDK-8353273: Reduce average number of oop map entries in instance objects 8353273: Reduce average number of oop map entries in instance objects Mar 31, 2025
@openjdk
Copy link

openjdk bot commented Mar 31, 2025

@tstuefe The following label will be automatically applied to this pull request:

  • hotspot

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 pull request command.

@openjdk openjdk bot added the hotspot hotspot-dev@openjdk.org label Mar 31, 2025
@tstuefe tstuefe force-pushed the JDK-8353273-Reduce-average-number-of-oop-map-entries-in-instance-objects branch from 311266b to f52a3c4 Compare March 31, 2025 14:10
@tstuefe tstuefe force-pushed the JDK-8353273-Reduce-average-number-of-oop-map-entries-in-instance-objects branch from f52a3c4 to f4933c1 Compare March 31, 2025 14:12
@tstuefe tstuefe changed the title 8353273: Reduce average number of oop map entries in instance objects 8353273: Reduce number of oop map entries in instances Mar 31, 2025
@tstuefe tstuefe marked this pull request as ready for review March 31, 2025 16:26
@openjdk openjdk bot added the rfr Pull request is ready for review label Mar 31, 2025
@mlbridge
Copy link

mlbridge bot commented Mar 31, 2025

Webrevs

@tstuefe
Copy link
Member Author

tstuefe commented Apr 1, 2025

Ping @fparain ?

Copy link
Contributor

@fparain fparain 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.
Thank you for improving instances' layouts.

Fred

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Apr 1, 2025
@tstuefe
Copy link
Member Author

tstuefe commented Apr 1, 2025

Looks good to me. Thank you for improving instances' layouts.

Fred

Thanks Frederic :)

@fparain
Copy link
Contributor

fparain commented Apr 1, 2025

A possible improvement to this code would be to compute if the super class' layout ends with oops during the reconstruction (reconstruct_layout()), to avoid having to iterate over the fields a second time.

@tstuefe
Copy link
Member Author

tstuefe commented Apr 1, 2025

A possible improvement to this code would be to compute if the super class' layout ends with oops during the reconstruction (reconstruct_layout()), to avoid having to iterate over the fields a second time.

That is a good idea. A prior version of this stored the last field information after constructing the layout in the InstanceKlass (as a "ends_with_oop" bool) but I did not like that, since I did not wanted to add a new member to IK. But if we reconstruct the layout for the super class anyway, I can do the same there. Thansk!

@tstuefe
Copy link
Member Author

tstuefe commented Apr 2, 2025

@fparain I adapted your idea. I also added a regression test.
Thank you.

@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Apr 2, 2025
Copy link
Contributor

@fparain fparain left a comment

Choose a reason for hiding this comment

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

This version looks better.
Thank you for the changes.

Fred

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Apr 2, 2025
@tstuefe
Copy link
Member Author

tstuefe commented Apr 2, 2025

Thanks @fparain !

May I have a second review?

Copy link
Contributor

@jdksjolen jdksjolen left a comment

Choose a reason for hiding this comment

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

Hi,

Neat change. I have read up on how field layouts work, and this seems correct to me. Let me run this in our CI for a bit and see what comes out before I approve it, thank you.

Copy link
Contributor

@jdksjolen jdksjolen left a comment

Choose a reason for hiding this comment

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

Passes tests, approved.

@tstuefe tstuefe requested a review from lmesnik April 8, 2025 05:41
@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Apr 8, 2025
@openjdk openjdk bot added the ready Pull request is ready to be integrated label Apr 8, 2025
@tstuefe
Copy link
Member Author

tstuefe commented Apr 9, 2025

Thank you all.

/integrate

@openjdk
Copy link

openjdk bot commented Apr 9, 2025

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

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Apr 9, 2025

@tstuefe Pushed as commit 743d1c6.

💡 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

hotspot hotspot-dev@openjdk.org integrated Pull request has been integrated

Development

Successfully merging this pull request may close these issues.

4 participants