Skip to content

Conversation

@albertnetymk
Copy link
Member

@albertnetymk albertnetymk commented Nov 11, 2025

Trivial removing obsoleted code for unsupported arch.

Test: tier1


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-8371643: Remove ThreadLocalAllocBuffer::_reserve_for_allocation_prefetch (Enhancement - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 28240

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Nov 11, 2025

👋 Welcome back ayang! 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 Nov 11, 2025

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

8371643: Remove ThreadLocalAllocBuffer::_reserve_for_allocation_prefetch

Reviewed-by: mdoerr, kvn, tschatzl

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 19 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 8371643 8371643: Remove ThreadLocalAllocBuffer::_reserve_for_allocation_prefetch Nov 11, 2025
@openjdk openjdk bot added the hotspot hotspot-dev@openjdk.org label Nov 11, 2025
@openjdk
Copy link

openjdk bot commented Nov 11, 2025

@albertnetymk 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 rfr Pull request is ready for review label Nov 11, 2025
@mlbridge
Copy link

mlbridge bot commented Nov 11, 2025

Webrevs

@vnkozlov
Copy link
Contributor

What happens if TLAB is at the end of heap page? Are you sure "prefetch" instructions on all OpenJDK platforms can touch unmapped memory? I see PPC can use AllocatePrefetchStyle == 3.

@vnkozlov
Copy link
Contributor

Please ask all OpenJDK platforms supporters to test these changes.

Note, when this code was introduced we did not have so many platforms.

Copy link
Contributor

@vnkozlov vnkozlov left a comment

Choose a reason for hiding this comment

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

You missed code in HS agent: src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/VM.java

@albertnetymk
Copy link
Member Author

albertnetymk commented Nov 11, 2025

What happens if TLAB is at the end of heap page? Are you sure "prefetch" instructions on all OpenJDK platforms can touch unmapped memory? I see PPC can use AllocatePrefetchStyle == 3.

In every <arch>.ad file, there is // Must be safe to execute with invalid address (cannot fault) for prefetching.

I searched online that all currently supported platforms don't fault on prefetching invalid addresses.

@openjdk openjdk bot added the serviceability serviceability-dev@openjdk.org label Nov 11, 2025
@openjdk
Copy link

openjdk bot commented Nov 11, 2025

@albertnetymk serviceability has been added to this pull request based on files touched in new commit(s).

Copy link
Contributor

@vnkozlov vnkozlov left a comment

Choose a reason for hiding this comment

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

I ran our testing (tier1-5) and there are no new failures. So I approve this change.
But you need second review. Preferable from other platforms supporters (RISC-V, PPC64, s390)

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Nov 12, 2025
@TheRealMDoerr
Copy link
Contributor

We have seen crashes on many platforms (including x64) while running make run-test TEST=runtime/cds/appcds/aotClassLinking/LambdaInExcludedClass.java JTREG="VM_OPTIONS=-XX:+UseCompactObjectHeaders":

SIGSEGV (0xb) at pc=0x00007f2f95a61e7a, pid=18554, tid=18557
V  [libjvm.so+0x15bfe7a]  MemAllocator::finish(HeapWordImpl**) const+0xca  (klass.inline.hpp:72)
V  [libjvm.so+0x15c029f]  ObjAllocator::initialize(HeapWordImpl**) const+0x2f  (memAllocator.cpp:391)
V  [libjvm.so+0xb0630b]  CollectedHeap::fill_with_object(HeapWordImpl**, unsigned long, bool)+0x27b  (collectedHeap.cpp:491)
V  [libjvm.so+0x1c7a0bb]  ThreadLocalAllocBuffer::retire(ThreadLocalAllocStats*)+0x11b  (threadLocalAllocBuffer.cpp:118)
V  [libjvm.so+0x15c0b14]  MemAllocator::mem_allocate_inside_tlab_slow(MemAllocator::Allocation&) const+0x84  (memAllocator.cpp:286)
V  [libjvm.so+0x15c13ab]  MemAllocator::mem_allocate(MemAllocator::Allocation&) const+0xbb  (memAllocator.cpp:340)
V  [libjvm.so+0x15c14f9]  MemAllocator::allocate() const+0xa9  (memAllocator.cpp:353)
V  [libjvm.so+0x1cc052e]  TypeArrayKlass::allocate_common(int, bool, JavaThread*)+0x13e  (collectedHeap.inline.hpp:41)
V  [libjvm.so+0x16fbc98]  oopFactory::new_typeArray(BasicType, int, JavaThread*)+0x38  (typeArrayKlass.hpp:51)
V  [libjvm.so+0x106b0f3]  java_lang_Class::restore_archived_mirror(Klass*, Handle, Handle, Handle, JavaThread*)+0x413  (javaClasses.cpp:1246)
V  [libjvm.so+0x14100bc]  Klass::restore_unshareable_info(ClassLoaderData*, Handle, JavaThread*)+0x66c  (klass.cpp:903)
V  [libjvm.so+0xfe2cb1]  InstanceKlass::restore_unshareable_info(ClassLoaderData*, Handle, PackageEntry*, JavaThread*)+0x81  (instanceKlass.cpp:2823)
V  [libjvm.so+0x1c0f5ad]  SystemDictionary::preload_class(Handle, InstanceKlass*, JavaThread*)+0x1ed  (systemDictionary.cpp:1198)
V  [libjvm.so+0x676e83]  AOTLinkedClassBulkLoader::preload_classes_in_table(Array<InstanceKlass*>*, char const*, Handle, JavaThread*)+0x1a3  (aotLinkedClassBulkLoader.cpp:103)
V  [libjvm.so+0x679af5]  AOTLinkedClassBulkLoader::preload_classes_impl(JavaThread*)+0x165  (aotLinkedClassBulkLoader.cpp:76)
V  [libjvm.so+0x67c371]  AOTLinkedClassBulkLoader::preload_classes(JavaThread*)+0x11  (aotLinkedClassBulkLoader.cpp:61)
V  [libjvm.so+0x1d5bf30]  vmClasses::resolve_all(JavaThread*)+0x3e0  (vmClasses.cpp:126)
V  [libjvm.so+0x1c0f28c]  SystemDictionary::initialize(JavaThread*)+0x10c  (systemDictionary.cpp:1623)
V  [libjvm.so+0x1cc74ca]  Universe::genesis(JavaThread*)+0xfa  (universe.cpp:451)
V  [libjvm.so+0x1ccbbf5]  universe2_init()+0x35  (universe.cpp:1119)
V  [libjvm.so+0xfd5709]  init_globals2()+0x9  (init.cpp:173)
V  [libjvm.so+0x1c926b1]  Threads::create_vm(JavaVMInitArgs*, bool*)+0x3a1  (threads.cpp:622)
V  [libjvm.so+0x118b634]  JNI_CreateJavaVM+0x54  (jni.cpp:3591)
C  [libjli.so+0x3d7f]  JavaMain+0x8f  (java.c:1506)
C  [libjli.so+0x7ad9]  ThreadJavaMain+0x9  (java_md.c:646)

@albertnetymk
Copy link
Member Author

... make run-test TEST=runtime/cds/appcds/aotClassLinking/LambdaInExcludedClass.java JTREG="VM_OPTIONS=-XX:+UseCompactObjectHeaders"

I suspect the crash is caused by a preexisting issue that is exposed by this patch.

In vmClasses::resolve_all:

#if INCLUDE_CDS
  if (CDSConfig::is_using_aot_linked_classes()) {
    AOTLinkedClassBulkLoader::preload_classes(THREAD);
  }
#endif

  // Preload commonly used klasses
  vmClassID scan = vmClassID::FIRST;
  // first do Object, then String, Class
  resolve_through(VM_CLASS_ID(Object_klass), scan, CHECK);
  CollectedHeap::set_filler_object_klass(vmClasses::Object_klass());

The filler-klass is not initialized when preload_classes is invoked, but preload_classes use heap-allocation, which may require filler-obj.

@iklam What do you think?

/cc hotspot-gc

@openjdk openjdk bot added the hotspot-gc hotspot-gc-dev@openjdk.org label Nov 13, 2025
@openjdk
Copy link

openjdk bot commented Nov 13, 2025

@albertnetymk
The hotspot-gc label was successfully added.

Copy link
Contributor

@tschatzl tschatzl left a comment

Choose a reason for hiding this comment

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

Change looks good, but these AOT-related crashes should be fixed first.

@iklam
Copy link
Member

iklam commented Nov 13, 2025

The filler-klass is not initialized when preload_classes is invoked, but preload_classes use heap-allocation, which may require filler-obj.

@iklam What do you think?

I am working on a fix now.

@iklam
Copy link
Member

iklam commented Nov 14, 2025

The filler-klass is not initialized when preload_classes is invoked, but preload_classes use heap-allocation, which may require filler-obj.
@iklam What do you think?

I am working on a fix now.

The fix is quite simple. See #28315

@iklam
Copy link
Member

iklam commented Nov 14, 2025

@albertnetymk I've pushed #28315. Please verify if it fixes the crash before integrating this PR. Thanks!

@TheRealMDoerr
Copy link
Contributor

@albertnetymk I've pushed #28315. Please verify if it fixes the crash before integrating this PR. Thanks!

The crashes are fixed. Thanks!

@TheRealMDoerr
Copy link
Contributor

This change looks incomplete to me. @vnkozlov: Shouldn't we remove AllocatePrefetchStyle == 3 completely? PhaseMacroExpand::prefetch_allocation still mentions "BIS instruction is used on SPARC as prefetch". Please note that PPC64 also still has an implementation for it (nodes with predicate(AllocatePrefetchStyle == 3)). I guess that we don't need it any more. Maybe we should check performance again.

@albertnetymk
Copy link
Member Author

AllocatePrefetchStyle == 3 means "generate one prefetch instruction per cache line".

This patch removes the reserved alignment that was required for AllocatePrefetchStyle == 3 on SPARC, but that does not imply that AllocatePrefetchStyle == 3 itself should be removed. (Maybe a separate ticket if it's indeed deemed useless.)

PhaseMacroExpand::prefetch_allocation still mentions "BIS instruction is used on SPARC as prefetch".

Will remove it in the next revision.

@TheRealMDoerr
Copy link
Contributor

At least PPC64 will need an update because your change breaks the following nodes:

diff --git a/src/hotspot/cpu/ppc/ppc.ad b/src/hotspot/cpu/ppc/ppc.ad
index 7fcd096d2ad..c169d673aaf 100644
--- a/src/hotspot/cpu/ppc/ppc.ad
+++ b/src/hotspot/cpu/ppc/ppc.ad
@@ -6328,36 +6328,8 @@ instruct loadConD_Ex(regD dst, immD src) %{
 // Prefetch instructions.
 // Must be safe to execute with invalid address (cannot fault).
 
-// Special prefetch versions which use the dcbz instruction.
-instruct prefetch_alloc_zero(indirectMemory mem, iRegLsrc src) %{
-  match(PrefetchAllocation (AddP mem src));
-  predicate(AllocatePrefetchStyle == 3);
-  ins_cost(MEMORY_REF_COST);
-
-  format %{ "PREFETCH $mem, 2, $src \t// Prefetch write-many with zero" %}
-  size(4);
-  ins_encode %{
-    __ dcbz($src$$Register, $mem$$base$$Register);
-  %}
-  ins_pipe(pipe_class_memory);
-%}
-
-instruct prefetch_alloc_zero_no_offset(indirectMemory mem) %{
-  match(PrefetchAllocation mem);
-  predicate(AllocatePrefetchStyle == 3);
-  ins_cost(MEMORY_REF_COST);
-
-  format %{ "PREFETCH $mem, 2 \t// Prefetch write-many with zero" %}
-  size(4);
-  ins_encode %{
-    __ dcbz($mem$$base$$Register);
-  %}
-  ins_pipe(pipe_class_memory);
-%}
-
 instruct prefetch_alloc(indirectMemory mem, iRegLsrc src) %{
   match(PrefetchAllocation (AddP mem src));
-  predicate(AllocatePrefetchStyle != 3);
   ins_cost(MEMORY_REF_COST);
 
   format %{ "PREFETCH $mem, 2, $src \t// Prefetch write-many" %}
@@ -6370,7 +6342,6 @@ instruct prefetch_alloc(indirectMemory mem, iRegLsrc src) %{
 
 instruct prefetch_alloc_no_offset(indirectMemory mem) %{
   match(PrefetchAllocation mem);
-  predicate(AllocatePrefetchStyle != 3);
   ins_cost(MEMORY_REF_COST);
 
   format %{ "PREFETCH $mem, 2 \t// Prefetch write-many" %}

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

@TheRealMDoerr TheRealMDoerr left a comment

Choose a reason for hiding this comment

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

Thanks for the updates! make run-test TEST=test/hotspot/jtreg/compiler/c2 JTREG="VM_OPTIONS=-XX:AllocatePrefetchStyle=3" has passed on PPC64. I agree, the general AllocatePrefetchStyle==3 topic can be discussed separately.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Nov 17, 2025
@albertnetymk
Copy link
Member Author

Thanks for review.

/integrate

@openjdk
Copy link

openjdk bot commented Nov 18, 2025

Going to push as commit 50a3049.
Since your change was applied there have been 39 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 Nov 18, 2025
@openjdk openjdk bot closed this Nov 18, 2025
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Nov 18, 2025
@albertnetymk albertnetymk deleted the remove-tlab-reserve branch November 18, 2025 09:37
@openjdk
Copy link

openjdk bot commented Nov 18, 2025

@albertnetymk Pushed as commit 50a3049.

💡 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 hotspot-gc hotspot-gc-dev@openjdk.org integrated Pull request has been integrated serviceability serviceability-dev@openjdk.org

Development

Successfully merging this pull request may close these issues.

5 participants