Skip to content

8349110: [lworld] Intrinsics for Unsafe.get/putFlatValue #1482

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

Open
wants to merge 4 commits into
base: lworld
Choose a base branch
from

Conversation

merykitty
Copy link
Member

@merykitty merykitty commented Jun 6, 2025

Hi,

This PR implements intrinsics for Unsafe::get/putFlatValue and enables the corresponding tests in TestIntrinsics.

Please kindly review, thanks very much.


Progress

  • Change must not contain extraneous whitespace

Issue

  • JDK-8349110: [lworld] Intrinsics for Unsafe.get/putFlatValue (Bug - P3)

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 1482

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/valhalla/pull/1482.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jun 6, 2025

👋 Welcome back qamai! A progress list of the required criteria for merging this PR into lworld 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 Jun 6, 2025

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

8349110: [lworld] Intrinsics for Unsafe.get/putFlatValue

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 7 new commits pushed to the lworld 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.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@mlbridge
Copy link

mlbridge bot commented Jun 6, 2025

Webrevs

@TobiHartmann
Copy link
Member

Thanks for working on this Quan-Anh! I executed some quick testing and noticed that TestIntrinsics fails:

 359  InlineType  === _ 13 15 16 24 25 31 37 43 52 65 74 110 111  [[ 394 360 360 384 374 ]]  #compiler/valhalla/inlinetypes/MyValue1 (compiler/valhalla/inlinetypes/MyInterface):NotNull:exact *  Oop:compiler/valhalla/inlinetypes/MyValue1 (compiler/valhalla/inlinetypes/MyInterface):NotNull:exact * !orig=14 !jvms: TestIntrinsics::test72 @ bci:-1 (line 1456)
 394  AddP  === _ 359 360 87  [[ 399 ]]   Oop:compiler/valhalla/inlinetypes/MyValue1 (compiler/valhalla/inlinetypes/MyInterface):NotNull:exact+bot * [narrow] !jvms: TestIntrinsics::test72 @ bci:21 (line 1458)

# A fatal error has been detected by the Java Runtime Environment:
#
#  Internal Error (/workspace/open/src/hotspot/share/opto/compile.cpp:2073), pid=1806857, tid=1806873
#  assert(false) failed: Should have been buffered
#
# JRE version: Java(TM) SE Runtime Environment (25.0) (fastdebug build 25-lworld5ea-LTS-2025-06-11-1437268.tobias.hartmann.valhalla2)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (fastdebug 25-lworld5ea-LTS-2025-06-11-1437268.tobias.hartmann.valhalla2, mixed mode, compressed class ptrs, g1 gc, linux-amd64)
# Problematic frame:
# V  [libjvm.so+0xb384b1]  Compile::process_inline_types(PhaseIterGVN&, bool)+0xa11

Current CompileTask:
C2:3962  662    b        compiler.valhalla.inlinetypes.TestIntrinsics::test72 (78 bytes)

Stack: [0x00007f84bb8fa000,0x00007f84bb9fa000],  sp=0x00007f84bb9f5080,  free space=1004k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
V  [libjvm.so+0xb384b1]  Compile::process_inline_types(PhaseIterGVN&, bool)+0xa11  (compile.cpp:2073)
V  [libjvm.so+0xb55115]  Compile::Optimize()+0x1365  (compile.cpp:3033)
V  [libjvm.so+0xb57cff]  Compile::Compile(ciEnv*, ciMethod*, int, Options, DirectiveSet*)+0x1fef  (compile.cpp:874)
V  [libjvm.so+0x96de34]  C2Compiler::compile_method(ciEnv*, ciMethod*, int, bool, DirectiveSet*)+0x484  (c2compiler.cpp:143)
V  [libjvm.so+0xb659b8]  CompileBroker::invoke_compiler_on_method(CompileTask*)+0xb58  (compileBroker.cpp:2307)
V  [libjvm.so+0xb66b78]  CompileBroker::compiler_thread_loop()+0x568  (compileBroker.cpp:1951)
V  [libjvm.so+0x10e113b]  JavaThread::thread_main_inner()+0x13b  (javaThread.cpp:774)
V  [libjvm.so+0x1b5c406]  Thread::call_run()+0xb6  (thread.cpp:231)
V  [libjvm.so+0x17c7fb8]  thread_native_entry(Thread*)+0x128  (os_linux.cpp:875)

It mostly seems to fail on linux-aarch64-debug in various configurations for some reason but also once on x64 with -XX:+UnlockDiagnosticVMOptions -XX:-TieredCompilation -XX:+StressArrayCopyMacroNode -XX:+StressCallingConvention -XX:+StressLCM -XX:+StressGCM -XX:+StressCCP -XX:+StressIGVN -XX:+StressReflectiveCode -XX:+StressMethodHandleLinkerInlining -XX:+StressCompiledExceptionHandlers -XX:MaxNodeLimit=100000.

@TobiHartmann
Copy link
Member

I also noticed that there are still two leftover ToDos from JDK-8239003 in TestIntrinsics. I think test54 should be removed because C2 will bail out from compilation. I quickly checked and it also seems that we can re-enable the test with -XX:+DeoptimizeALot again.

@merykitty
Copy link
Member Author

@TobiHartmann It was because I need to buffer the InlineTypeNode if a load is required, I have added necessary handling for InlineTypeNode. For the TODOs in TestIntrinsics, test54 seems like it can be removed since it tries to pass a larval value object to another method, test79 and test84 can be reenabled. For test84, I think an allocation is still necessary for the return value, so I remove that IR condition.

@TobiHartmann
Copy link
Member

Thanks for investigating! What about this one?

// Don't run with DeoptimizeALot until JDK-8239003 is fixed
"-XX:-DeoptimizeALot")

@TobiHartmann
Copy link
Member

TobiHartmann commented Jun 16, 2025

For test84, I think an allocation is still necessary for the return value, so I remove that IR condition.

But that should only be needed if InlineTypeReturnedAsFields is turned off, right? Can we restrict the IR rule accordingly?

@merykitty
Copy link
Member Author

merykitty commented Jun 16, 2025

Thanks for investigating! What about this one?

Ah yes I missed that, removed!

But that should only be needed if InlineTypeReturnedAsFields is turned off, right? Can we restrict the IR rule accordingly?

Unfortunately MyValue1 has 15 GPR fields so I don't think it can be returned as fields.

@TobiHartmann
Copy link
Member

Unfortunately MyValue1 has 15 GPR fields so I don't think it can be returned as fields.

Ah, make sense! Thanks. I'll re-run testing.

@TobiHartmann
Copy link
Member

Testing looks good now except for one last failure with compiler/valhalla/inlinetypes/TestIntrinsics.java and -XX:Tier0BackedgeNotifyFreqLog=0 -XX:Tier2BackedgeNotifyFreqLog=0 -XX:Tier3BackedgeNotifyFreqLog=0 -XX:Tier2BackEdgeThreshold=1 -XX:Tier3BackEdgeThreshold=1 -XX:Tier4BackEdgeThreshold=1 -Xbatch:

# A fatal error has been detected by the Java Runtime Environment:
#
#  Internal Error (/opt/mach5/mesos/work_dir/slaves/d2398cde-9325-49c3-b030-8961a4f0a253-S509733/frameworks/1735e8a2-a1db-478c-8104-60c8b0af87dd-0196/executors/d98a4bd7-58a9-4f29-b8d0-431bc28dcc7e/runs/a5899c58-42e7-464d-909b-9619da50104d/workspace/open/src/hotspot/share/prims/unsafe.cpp:256), pid=2121432, tid=2121433
#  assert(_obj == nullptr || !_obj->is_inline_type() || _obj->mark().is_larval_state()) failed: must be an object instance or a larval inline type
#
# JRE version: Java(TM) SE Runtime Environment (25.0) (fastdebug build 25-lworld5ea-LTS-2025-06-16-1439046.tobias.hartmann.valhalla2)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (fastdebug 25-lworld5ea-LTS-2025-06-16-1439046.tobias.hartmann.valhalla2, mixed mode, sharing, tiered, compressed oops, compressed class ptrs, g1 gc, linux-amd64)
# Problematic frame:
# V  [libjvm.so+0x1bbe2be]  Unsafe_PutInt+0x28e

Stack: [0x00007ff7140b4000,0x00007ff7141b5000],  sp=0x00007ff7141b33b0,  free space=1020k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
V  [libjvm.so+0x1bbe2be]  Unsafe_PutInt+0x28e  (unsafe.cpp:256)
J 3090  jdk.internal.misc.Unsafe.putInt(Ljava/lang/Object;JI)V java.base@25-lworld5ea (0 bytes) @ 0x00007ff6fc8582c4 [0x00007ff6fc858220+0x00000000000000a4]
j  compiler.valhalla.inlinetypes.TestIntrinsics.test84(Lcompiler/valhalla/inlinetypes/MyValue1;)Lcompiler/valhalla/inlinetypes/MyValue1;+46
j  compiler.valhalla.inlinetypes.TestIntrinsics.test84_verifier()V+16
J 3280 c2 java.lang.invoke.LambdaForm$DMH+0x000000002e091000.invokeVirtual(Ljava/lang/Object;Ljava/lang/Object;)V java.base@25-lworld5ea (14 bytes) @ 0x00007ff6fc883fe0 [0x00007ff6fc883fa0+0x0000000000000040]
j  java.lang.invoke.LambdaForm$MH+0x000000002e105800.invoke(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;+35 java.base@25-lworld5ea
J 3271 c2 jdk.internal.reflect.DirectMethodHandleAccessor.invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object; java.base@25-lworld5ea (92 bytes) @ 0x00007ff6fc881c80 [0x00007ff6fc881ba0+0x00000000000000e0]
j  java.lang.reflect.Method.invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;+102 java.base@25-lworld5ea
j  compiler.lib.ir_framework.test.CustomRunTest.invokeTest()V+49
J 3044 c2 compiler.lib.ir_framework.test.AbstractTest.run()V (41 bytes) @ 0x00007ff6fc846620 [0x00007ff6fc8465a0+0x0000000000000080]
J 3052% c2 compiler.lib.ir_framework.test.TestVM.runTests()V (535 bytes) @ 0x00007ff6fc84afdc [0x00007ff6fc84af20+0x00000000000000bc]
j  compiler.lib.ir_framework.test.TestVM.start()V+9
j  compiler.lib.ir_framework.test.TestVM.main([Ljava/lang/String;)V+38
v  ~StubRoutines::call_stub 0x00007ff6fbd18001
V  [libjvm.so+0x10a5728]  JavaCalls::call_helper(JavaValue*, methodHandle const&, JavaCallArguments*, JavaThread*)+0x508  (javaCalls.cpp:429)
V  [libjvm.so+0x12037c0]  jni_invoke_static(JNIEnv_*, JavaValue*, _jobject*, JNICallType, _jmethodID*, JNI_ArgumentPusher*, JavaThread*) [clone .constprop.1]+0x420  (jni.cpp:887)
V  [libjvm.so+0x12077b4]  jni_CallStaticVoidMethod+0x214  (jni.cpp:1746)
C  [libjli.so+0x3b9a]  invokeStaticMainWithArgs+0x4a  (java.c:392)
C  [libjli.so+0x4c78]  JavaMain+0xf08  (java.c:640)
C  [libjli.so+0x8019]  ThreadJavaMain+0x9  (java_md.c:646)
Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
J 3090  jdk.internal.misc.Unsafe.putInt(Ljava/lang/Object;JI)V java.base@25-lworld5ea (0 bytes) @ 0x00007ff6fc858292 [0x00007ff6fc858220+0x0000000000000072]
j  compiler.valhalla.inlinetypes.TestIntrinsics.test84(Lcompiler/valhalla/inlinetypes/MyValue1;)Lcompiler/valhalla/inlinetypes/MyValue1;+46
j  compiler.valhalla.inlinetypes.TestIntrinsics.test84_verifier()V+16
J 3280 c2 java.lang.invoke.LambdaForm$DMH+0x000000002e091000.invokeVirtual(Ljava/lang/Object;Ljava/lang/Object;)V java.base@25-lworld5ea (14 bytes) @ 0x00007ff6fc883fe0 [0x00007ff6fc883fa0+0x0000000000000040]
j  java.lang.invoke.LambdaForm$MH+0x000000002e105800.invoke(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;+35 java.base@25-lworld5ea
J 3271 c2 jdk.internal.reflect.DirectMethodHandleAccessor.invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object; java.base@25-lworld5ea (92 bytes) @ 0x00007ff6fc881c80 [0x00007ff6fc881ba0+0x00000000000000e0]
j  java.lang.reflect.Method.invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;+102 java.base@25-lworld5ea
j  compiler.lib.ir_framework.test.CustomRunTest.invokeTest()V+49
J 3044 c2 compiler.lib.ir_framework.test.AbstractTest.run()V (41 bytes) @ 0x00007ff6fc846620 [0x00007ff6fc8465a0+0x0000000000000080]
J 3052% c2 compiler.lib.ir_framework.test.TestVM.runTests()V (535 bytes) @ 0x00007ff6fc84afdc [0x00007ff6fc84af20+0x00000000000000bc]
j  compiler.lib.ir_framework.test.TestVM.start()V+9
j  compiler.lib.ir_framework.test.TestVM.main([Ljava/lang/String;)V+38
v  ~StubRoutines::call_stub 0x00007ff6fbd18001

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants