Repository navigation
perf(jit): call Unsafe, System.arraycopy and other common natives directly from compiled code, cutting slow concurrency and digest tests by 10 to 30% - #142
Conversation
|
No actionable comments were generated in the recent review. Summary
Merge Risk:
|
…rom compiled code without a native call
…call, and name element types in its mismatch message as HotSpot does
…read and the clocks to plain JS
There was a problem hiding this comment.
The PR inlines a set of HotSpot-intrinsic natives (Unsafe accessors and atomics, System.arraycopy, Class.isInstance, Object.getClass/hashCode, Thread.currentThread, System.nanoTime/currentTimeMillis, identityHashCode) directly into compiled code as JS expressions or calls to runtime helpers, and allows inlined methods to inline these natives too. It also changes the arraycopy type-mismatch message to use Java element names and object-array wording. The full unit suite and OpenJDK passing tests are reported green.
I reviewed the diff for bugs, wrong logic, unhandled errors, and data-loss risks. The inlining guard change correctly lets trivial natives bypass the no-code check, nativeArgs now returns an array and both callers are updated, the arraycopy wrapper sets the native method and pc on PendingThrow for stack traces, and the CAS/getAndSet/getAndAdd extractions preserve the old read-modify-write semantics. I found no defect I can demonstrate from the diff alone.
One item is worth verifying because I cannot see the definition it depends on: elemName returns c.javaName for primitive component classes. If javaName returns internal JVM descriptors (I, J) rather than Java source names (int, long), the arraycopy mismatch message would not change as the PR claims. The reported test results suggest it is correct, but it is not visible in the diff.
review-bot, model nvidia/nemotron-3.5-super-vl:free, verdict approve
de5cc62 to
7757c18
Compare
|
On |
There was a problem hiding this comment.
The PR inlines HotSpot-intrinsic natives (Unsafe accessors/atomics, System.arraycopy, Class.isInstance, Object.getClass/hashCode, identityHashCode, Thread.currentThread/carrierThread, nanoTime, currentTimeMillis) as compiled-code expressions, and allows trivial natives to be inlined into callers. It also changes the arraycopy type-mismatch message to use primitive type names and "object array" for object arrays, and adds two compiled-code tests. The full suite and OpenJDK passing tests are reported as passing.
review-bot, model nvidia/nemotron-3.5-super-vl:free, verdict approve
What this changes
The slowest OpenJDK tests set how long each CI shard takes. Their profiles showed compiled code calling a small set of natives over and over through the generic native-call path: an argument array, a try/catch, a generator check, and a thread-state check after each call. These are Unsafe's field, array and memory accessors and atomics, which ConcurrentHashMap, atomics, VarHandles, locks and fork/join use, plus
System.arraycopyand a few others. HotSpot intrinsifies all of them.Compiled code now calls these natives directly, as an inline expression or a call to a runtime helper:
Unsafeget/put, including the Volatile, Acquire, Release and Opaque forms, plus compareAndSet, weakCompareAndSet, compareAndExchange, getAndSet and getAndAdd, for every kind. perf(jit): compile Unsafe array element access inline and copy short strings with a loop #141's inline primitive-array path still runs first for get/put on a primitive array of the matching kind. Other bases now take the direct call instead of the native.Class.isInstance,Object.getClass,Object.hashCodewhen the receiver's class doesn't override it,System.identityHashCode,Thread.currentThread,Thread.currentCarrierThread,System.nanoTimeandSystem.currentTimeMillis.System.arraycopy. Its exceptions keep theSystem.arraycopy(Native Method)frame at the top of the stack trace, as on HotSpot.The arraycopy type-mismatch message named element types the way HotSpot does only for object arrays. Before:
can not copy I[] into J[]. After:can not copy int[] into long[], andobject array[]for object arrays.Tests
The first master run was slower than the second, so the second is the fair baseline.
ReentrantLocklock and unlock, 1M times: 198 to 232 on master, 123 to 158 on the branchLockSupport.park/unparkbetween two threads: unchanged, 47 to 78 on bothLinkedBlockingQueue: 279, 279 on master; 174, 178 on the branchConcurrentHashMap: 394, 396 on master; 321, 324 on the branchUnsafeCompiled: field, array, byte-view and direct-buffer VarHandles, atomics, ConcurrentHashMap andClass.isInstance, in loops long enough to compile.ArraycopyCompiled: copies and every arraycopy exception with its stack trace, also from a method inlined into its caller.UnsafeArrays, from perf(jit): compile Unsafe array element access inline and copy short strings with a loop #141, still passes after the rebase.passing.txtunderjava/util/concurrent,java/lang/invoke,java/nio/Bufferandjava/lang/refpassed, 75 tests.pnpm typecheckpasses.