On Tue, 16 Jun 2026 12:14:41 GMT, David Simms <[email protected]> wrote:

>> This is a "*sub-review pull request*" for the first 
>> [preview](https://openjdk.org/jeps/12) of [JEP 401: Value Classes and 
>> Objects](https://openjdk.org/jeps/401), specifically 
>> [JDK-8317278](https://bugs.openjdk.org/browse/JDK-8317278): JVM 
>> implementation of value classes and objects.
>> 
>>> [!NOTE]
>>> This pull request and the other sub-review pull requests listed below are 
>>> based on the "*master pull request*" 
>>> (https://github.com/openjdk/jdk/pull/31120). It contains the same full set 
>>> of code changes as the "*master pull request*" to preserve the full 
>>> implementation context; the language compiler, JVM, and standard library 
>>> changes are intertwined. This separate pull requests exist only to 
>>> subdivide the review and related discussion by area.
>> 
>> Other areas for review:
>> 
>> - [JDK-8317277](https://bugs.openjdk.org/browse/JDK-8317277): Java language 
>> implementation of value classes and objects
>>   - https://github.com/openjdk/jdk/pull/31121
>> - [JDK-8317279](https://bugs.openjdk.org/browse/JDK-8317279): Standard 
>> library implementation of value classes and objects
>>   - https://github.com/openjdk/jdk/pull/31123
>> 
>> Code changes resulting from the review process should be made in 
>> [`valhalla/lworld`](https://github.com/openjdk/valhalla/).
>> 
>> `valhalla/lworld` is currently updated from `jdk/master` whenever a weekly 
>> [`jdk` tag](https://github.com/openjdk/jdk/tags) is created. At that time, 
>> code changes from `valhalla/lworld` will be propagated to the master pull 
>> request and to all sub-review pull requests, including this one.
>> 
>> Ultimately, review sign-off will be recorded on the "*master pull request*", 
>> and this pull request will be closed without integration.
>> 
>> This pull request has a large code surface area and often conflicts with 
>> `jdk/master` on a daily basis. Refer to 
>> [`valhalla/lworld`](https://github.com/openjdk/valhalla/) for the latest 
>> state of the project code, keeping in mind that it may lag several days 
>> behind `jdk/master`. Both repositories may be needed as references during 
>> review.
>> 
>> ---------
>> - [x] I confirm that I make this contribution in accordance with the 
>> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai).
>
> David Simms has updated the pull request with a new target base due to a 
> merge or a rebase. The pull request now contains 2822 commits:
> 
>  - Merge branch '8317277' into jep401_sub_review_8317278
>  - Merge remote-tracking branch 'valhalla/lworld' into 8317277
>  - 8386690: [lworld] cherry-pick JDK-8386124 Test 
> serviceability/sa/TestG1HeapRegion.java failed: Address of G1HeapRegion does 
> not match
>    
>    Reviewed-by: liach
>  - 8385743: [lworld] investigate and address build related comments in the 
> Valhalla PR
>    
>    Reviewed-by: liach, erikj
>  - 8376346: [lworld] Basic Shenandoah support
>    
>    Reviewed-by: qamai
>  - 8386598: [lworld] C1 acmp profiling fix and minor cleanup
>    
>    Reviewed-by: mchevalier
>  - 8386618: [lworld] Remove unused entry_guard_Relocation
>    
>    Reviewed-by: chagedorn, jsjolen, jsikstro
>  - Merge
>    
>    Merge jdk-28+2
>  - 8386623: [lworld] Cleanup module support for system modules in JDK 
> exploded build with preview resources
>    
>    Reviewed-by: liach
>  - 8386316: [lworld] Replace Valhalla since version with 28
>    
>    Reviewed-by: darcy
>  - ... and 2812 more: https://git.openjdk.org/jdk/compare/6def7d55...c2d3cf01

src/hotspot/share/c1/c1_LIRGenerator.cpp line 2391:

> 2389:       assert(x->delayed() == nullptr, "Delayed LoadIndexed only apply 
> to loaded_flat_arrays");
> 2390:       index.load_item();
> 2391:       // if we are loading from a flat array, load it using a runtime 
> call

Hi, I was failing this test on RISC-V, and the C1 log indicates that it's 
related to the code here.

import java.util.*;

public class ArrayFlatteningTest {
    // Simplified binarySort pattern
    static <T> void mySort(T[] a, int lo, int hi, Comparator<? super T> c) {
        for (int start = lo + 1; start < hi; start++) {
            T pivot = a[start];
            int left = lo;
            int right = start;
            while (left < right) {
                int mid = (left + right) >>> 1;
                if (c.compare(pivot, a[mid]) < 0)
                    right = mid;
                else
                    left = mid + 1;
            }
            int n = start - left;
            switch (n) {
                case 2:  a[left + 2] = a[left + 1];
                case 1:  a[left + 1] = a[left];
                         break;
                default: System.arraycopy(a, left, a, left + 1, n);
            }
            a[left] = pivot;
        }
    }

    public static void main(String[] args) {
        Comparator<Integer> cmp = new Comparator<Integer>() {
            public int compare(Integer o1, Integer o2) {
                return o1.compareTo(o2);
            }
        };
        Random rnd = new Random(42);
        for (int i = 0; i < 10000; i++) {
            Integer[] arr = new Integer[32];
            for (int j = 0; j < arr.length; j++) {
                arr[j] = Integer.valueOf(rnd.nextInt());
            }
            mySort(arr, arr.length / 3, arr.length / 2, cmp);
        }
        System.out.println("SUCCESS");
    }
}


C1 log like this:

CompileCommand: compileonly ArrayFlatteningTest.mySort intx compileonly = 1111
LIR:
B14 [0, 0] sux: B15
__id_Instruction___________________________________________
   0 label [label:0x00007f8f9c031f90]
   2 std_entry
     move [c_rarg1|L] [stack:8|L]
     move [c_rarg2|I] [stack:15|I]
     move [c_rarg3|I] [stack:14|I]
     move [c_rarg4|L] [stack:12|L]
  12 branch [AL]   [B15]

B15 std [0, 0] preds: B14 sux: B0
__id_Instruction___________________________________________
  14 label [label:0x00007f8f9c032218]
  16 branch [AL]   [B0]

B0 std [0, 5] preds: B15 sux: B1
__id_Instruction___________________________________________
  18 label [label:0x00007fbe9c36e040]
  20 move [int:1|I] [c_rarg0|I]
  22 add [c_rarg2|I] [c_rarg0|I] [c_rarg0|I]
  26 branch [AL]   [B1]

B1 bb lh [5, 8] preds: B0 B13 sux: B3 B2
__id_Instruction___________________________________________
  28 label [label:0x00007fbe9c36e2f0]
  30 branch [GE] [c_rarg0|I] [c_rarg3|I] [B3]
  32 branch [AL]   [B2]

B2 [11, 24] preds: B1 sux: B4
__id_Instruction___________________________________________
  34 label [label:0x00007fbe9c36e5a0]
  36 move [Base:[c_rarg1|L] Disp: 12|I] [t2|I]  [bci:14]
  38 branch [AE] [c_rarg0|I] [t2|I] [RangeCheckStub: 0x00007f8f9c038848] 
[bci:14]
     move [c_rarg0|I] [t2|I]
  40 flat_array_check [c_rarg1|L] [c_rarg6|M] [label:0x00007f8f9c038bc0]
  42 move [Base:[c_rarg1|L] Index:[t2|I] * 8 Disp: 16|L] [c_rarg5|L]
     move [c_rarg5|L] [stack:10|L]
  44 label [label:0x00007f8f9c038c58]
  46 move [t2|I] [c_rarg0|I]
  48 move [c_rarg2|I] [c_rarg6|I]
     move [t2|I] [stack:7|I]
  50 branch [AL]   [B4]

B4 bb lh [24, 28] preds: B2 B9 sux: B6 B5
__id_Instruction___________________________________________
  52 label [label:0x00007fbe9c36eb00]
  54 branch [GE] [c_rarg6|I] [c_rarg0|I] [B6]
  56 branch [AL]   [B5]

B5 [31, 52] preds: B4 sux: B8 B7
__id_Instruction___________________________________________
  58 label [label:0x00007fbe9c36edb0]
  60 add [c_rarg0|I] [c_rarg6|I] [c_rarg7|I]
  62 ushift_right [c_rarg7|I] [int:1|I] [c_rarg7|I]
  64 move [Base:[c_rarg1|L] Disp: 12|I] [x28|I]
  66 branch [AE] [c_rarg7|I] [x28|I] [RangeCheckStub: 0x00007f8f9c039738] 
[bci:46]
     move [c_rarg0|I] [stack:6|I]
  68 flat_array_check [c_rarg1|L] [x30|M] [label:0x00007f8f9c039ab0]
  70 move [Base:[c_rarg1|L] Index:[c_rarg7|I] * 8 Disp: 16|L] [x29|L]
  72 label [label:0x00007f8f9c039b48]
  74 move [c_rarg5|L] [c_rarg2|L]
  76 move [x29|L] [c_rarg3|L]
  78 move [c_rarg4|L] [c_rarg1|L]
     move [c_rarg6|I] [stack:5|I]
     move [c_rarg7|I] [stack:4|I]
  80 icvirtual call: [addr: 0x0000000000000000] [recv: [c_rarg1|L]] [result: 
[c_rarg0|I]] [bci:47]
  84 move [int:0|I] [c_rarg1|I]
  86 branch [GE] [c_rarg0|I] [c_rarg1|I] [B8]
  88 branch [AL]   [B7]

B7 [55, 59] preds: B5 sux: B9
__id_Instruction___________________________________________
  90 label [label:0x00007fbe9c2826b0]
  92 move [stack:4|I] [c_rarg7|I]
  94 move [stack:5|I] [c_rarg6|I]
  96 branch [AL]   [B9]

B8 [62, 68] preds: B5 sux: B9
__id_Instruction___________________________________________
  98 label [label:0x00007fbe9c282960]
     move [stack:4|I] [c_rarg7|I]
 100 move [int:1|I] [c_rarg1|I]
 102 add [c_rarg7|I] [c_rarg1|I] [c_rarg1|I]
 104 move [stack:6|I] [c_rarg7|I]
 106 move [c_rarg1|I] [c_rarg6|I]
 108 branch [AL]   [B9]

B9 le [68, 68] preds: B7 B8 sux: B4
__id_Instruction___________________________________________
 110 label [label:0x00007fbe9c282c10]
 112 safepoint    [bci:68]
 114 move [c_rarg7|I] [c_rarg0|I]
     move [stack:10|L] [c_rarg5|L]
     move [stack:12|L] [c_rarg4|L]
     move [stack:8|L] [c_rarg1|L]
 118 branch [AL]   [B4]

B6 [71, 80] preds: B4 sux: B16 B11 B12
__id_Instruction___________________________________________
 120 label [label:0x00007fbe9c282400]
     move [stack:7|I] [c_rarg0|I]
 122 sub [c_rarg0|I] [c_rarg6|I] [c_rarg5|I]
 124 branch [EQ] [c_rarg5|I] [int:1|I] [B16]
 126 branch [EQ] [c_rarg5|I] [int:2|I] [B11]
 128 branch [AL]   [B12]

B16 [120, 120] preds: B6 sux: B10
__id_Instruction___________________________________________
 130 label [label:0x00007f8f9c032b18]
     move [c_rarg0|I] [stack:7|I]
     move [stack:8|L] [c_rarg1|L]
 132 branch [AL]   [B10]

B12 [133, 146] preds: B6 sux: B13
__id_Instruction___________________________________________
 134 label [label:0x00007fbe9c283420]
     move [c_rarg0|I] [stack:7|I]
 136 move [int:1|I] [c_rarg1|I]
 138 add [c_rarg6|I] [c_rarg1|I] [c_rarg4|I]
 140 move [stack:8|L] [c_rarg1|L]
 142 move [c_rarg6|I] [c_rarg2|I]
 144 move [stack:8|L] [c_rarg3|L]
     move [c_rarg6|I] [stack:5|I]
 150 static call: [addr: 0x0000000000000000] [bci:143]
     move [stack:5|I] [c_rarg6|I]
     move [stack:10|L] [c_rarg5|L]
     move [stack:7|I] [t2|I]
     move [stack:8|L] [c_rarg1|L]
 152 branch [AL]   [B13]

B11 [108, 120] preds: B6 sux: B10
__id_Instruction___________________________________________
 154 label [label:0x00007fbe9c283170]
     move [c_rarg0|I] [stack:7|I]
     move [stack:8|L] [c_rarg1|L]
 156 move [int:1|I] [c_rarg0|I]
 158 add [c_rarg6|I] [c_rarg0|I] [t2|I]
 160 move [Base:[c_rarg1|L] Disp: 12|I] [c_rarg0|I]
 162 branch [AE] [t2|I] [c_rarg0|I] [RangeCheckStub: 0x00007f8f9c03c1e8] 
[bci:118]
 164 move [int:2|I] [c_rarg0|I]
 166 add [c_rarg6|I] [c_rarg0|I] [c_rarg2|I]
 168 flat_array_check [c_rarg1|L] [c_rarg4|M] [label:0x00007f8f9c03c560]
 170 move [Base:[c_rarg1|L] Index:[t2|I] * 8 Disp: 16|L] [c_rarg3|L]
 172 label [label:0x00007f8f9c03c5f8]
 174 move [Base:[c_rarg1|L] Disp: 12|I] [c_rarg0|I]
 176 branch [AE] [c_rarg2|I] [c_rarg0|I] [RangeCheckStub: 0x00007f8f9c03ca48] 
[bci:119]
 178 store_check [c_rarg3|L] [c_rarg1|L] [c_rarg0|L] [t2|L] [c_rarg4|L]   
[bci:119]
 180 flat_array_check [c_rarg1|L] [t2|M] [label:0x00007f8f9c03d020]
 182 null_free_array_check [c_rarg1|L] [c_rarg0|M]
 184 branch [EQ] [c_rarg0|M] [metadata:0x0000000000000000|M] 
[label:0x00007f8f9c03d310]
 186 null_check [c_rarg3|L]   [bci:119]
 188 label [label:0x00007f8f9c03d310]
 190 leal [Base:[c_rarg1|L] Index:[c_rarg2|I] * 8 Disp: 16|L] [c_rarg0c_rarg0|J]
 192 move [c_rarg3|L] [Base:[c_rarg0c_rarg0|J] Disp: 0|L]
 196 ushift_right [c_rarg0c_rarg0|J] [int:9|I] [c_rarg0c_rarg0|J]
 198 move [lng:139982429126656|J] [t2t2|J]
 200 move [int:0|I] [Base:[c_rarg0c_rarg0|J] Index:[t2t2|J] Disp: 0|B]
 202 label [label:0x00007f8f9c03d0b8]
 204 branch [AL]   [B10]

B10 [120, 130] preds: B16 B11 sux: B13
__id_Instruction___________________________________________
 206 label [label:0x00007fbe9c282ec0]
 208 move [Base:[c_rarg1|L] Disp: 12|I] [c_rarg0|I]
 210 branch [AE] [c_rarg6|I] [c_rarg0|I] [RangeCheckStub: 0x00007f8f9c03dbe8] 
[bci:128]
 212 move [int:1|I] [c_rarg0|I]
 214 add [c_rarg6|I] [c_rarg0|I] [t2|I]
 216 flat_array_check [c_rarg1|L] [c_rarg3|M] [label:0x00007f8f9c03df60]
 218 move [Base:[c_rarg1|L] Index:[c_rarg6|I] * 8 Disp: 16|L] [c_rarg2|L]
 220 label [label:0x00007f8f9c03dff8]
 222 move [Base:[c_rarg1|L] Disp: 12|I] [c_rarg0|I]
 224 branch [AE] [t2|I] [c_rarg0|I] [RangeCheckStub: 0x00007f8f9c03e3b0] 
[bci:129]
 226 store_check [c_rarg2|L] [c_rarg1|L] [c_rarg0|L] [c_rarg3|L] [c_rarg4|L]   
[bci:129]
 228 flat_array_check [c_rarg1|L] [c_rarg3|M] [label:0x00007f8f9c03ea08]
 230 null_free_array_check [c_rarg1|L] [c_rarg0|M]
 232 branch [EQ] [c_rarg0|M] [metadata:0x0000000000000000|M] 
[label:0x00007f8f9c03ecf8]
 234 null_check [c_rarg2|L]   [bci:129]
 236 label [label:0x00007f8f9c03ecf8]
 238 leal [Base:[c_rarg1|L] Index:[t2|I] * 8 Disp: 16|L] [c_rarg0c_rarg0|J]
 240 move [c_rarg2|L] [Base:[c_rarg0c_rarg0|J] Disp: 0|L]
 244 ushift_right [c_rarg0c_rarg0|J] [int:9|I] [c_rarg0c_rarg0|J]
 246 move [lng:139982429126656|J] [t2t2|J]
 248 move [int:0|I] [Base:[c_rarg0c_rarg0|J] Index:[t2t2|J] Disp: 0|B]
 250 label [label:0x00007f8f9c03eaa0]
     move [stack:10|L] [c_rarg5|L]
     move [stack:7|I] [t2|I]
 252 branch [AL]   [B13]

B13 le [146, 155] preds: B10 B12 sux: B1
__id_Instruction___________________________________________
 254 label [label:0x00007fbe9c2836f0]
 256 move [Base:[c_rarg1|L] Disp: 12|I] [c_rarg0|I]
 258 branch [AE] [c_rarg6|I] [c_rarg0|I] [RangeCheckStub: 0x00007f8f9c03f5d0] 
[bci:151]
 260 store_check [c_rarg5|L] [c_rarg1|L] [c_rarg0|L] [c_rarg2|L] [c_rarg3|L]   
[bci:151]
 262 flat_array_check [c_rarg1|L] [c_rarg2|M] [label:0x00007f8f9c03fba8]
 264 null_free_array_check [c_rarg1|L] [c_rarg0|M]
 266 branch [EQ] [c_rarg0|M] [metadata:0x0000000000000000|M] 
[label:0x00007f8f9c03fe98]
 268 null_check [c_rarg5|L]   [bci:151]
 270 label [label:0x00007f8f9c03fe98]
 272 leal [Base:[c_rarg1|L] Index:[c_rarg6|I] * 8 Disp: 16|L] [c_rarg0c_rarg0|J]
 274 move [c_rarg5|L] [Base:[c_rarg0c_rarg0|J] Disp: 0|L]
 278 ushift_right [c_rarg0c_rarg0|J] [int:9|I] [c_rarg0c_rarg0|J]
 280 move [lng:139982429126656|J] [c_rarg2c_rarg2|J]
 282 move [int:0|I] [Base:[c_rarg0c_rarg0|J] Index:[c_rarg2c_rarg2|J] Disp: 0|B]
 284 label [label:0x00007f8f9c03fc40]
 286 move [int:1|I] [c_rarg0|I]
 288 add [t2|I] [c_rarg0|I] [t2|I]
 290 safepoint    [bci:155]
     move [t2|I] [c_rarg0|I]
     move [stack:12|L] [c_rarg4|L]
     move [stack:14|I] [c_rarg3|I]
     move [stack:15|I] [c_rarg2|I]
 294 branch [AL]   [B1]

B3 [158, 158] preds: B1
__id_Instruction___________________________________________
 296 label [label:0x00007fbe9c36e850]
 298 return

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007fbea10931a0, pid=1655387, tid=1655390
#
# JRE version: OpenJDK Runtime Environment (28.0) (fastdebug build 
28-internal-adhoc.ocg02554262.valhalla)
# Java VM: OpenJDK 64-Bit Server VM (fastdebug 
28-internal-adhoc.ocg02554262.valhalla, mixed mode, tiered, serial gc, 
linux-riscv64)
# Problematic frame:
# J 3 c1 
ArrayFlatteningTest.mySort([Ljava/lang/Object;IILjava/util/Comparator;)V (159 
bytes) @ 0x00007fbea10931a0 [0x00007fbea1092d00+0x00000000000004a0]
#
# Core dump will be written. Default location: /home/zifeihan/core.1655387
#
# An error report file with more information is saved as:
# /home/zifeihan/hs_err_pid1655387.log
[9.601s][warning][os] Loading hsdis library failed
#
# If you would like to submit a bug report, please visit:
#   https://bugreport.java.com/bugreport/crash.jsp
#


In block B2, we see a spill `move [c_rarg5|L] [stack:10|L]` inserted by RA, I 
suspect the problem lies in the jump at `__j(_continuation);` in 
`LoadFlattenedArrayStub`, which does not consider the spill inserted by RA.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/31122#discussion_r3456766597

Reply via email to