Re: RFR: 8345687: Improve the implementation of SegmentFactories::allocateSegment [v7]

2025-03-18 Thread Quan Anh Mai
On Thu, 13 Mar 2025 16:21:07 GMT, Maurizio Cimadamore wrote: >> Quan Anh Mai has updated the pull request incrementally with one additional >> commit since the last revision: >> >> expand wildcard imports > > Marked as reviewed by mcimadamore (Reviewer). @mcimadamore @JornVernee Thanks a lo

Re: RFR: 8345687: Improve the implementation of SegmentFactories::allocateSegment [v7]

2025-03-13 Thread Maurizio Cimadamore
On Thu, 13 Mar 2025 05:46:44 GMT, Quan Anh Mai wrote: >> Hi, >> >> This patch improves the performance of a typical `Arena::allocate` in >> several ways: >> >> - Delay the creation of the NativeMemorySegmentImpl. This avoids the merge >> of the instance with the one obtained from the call in

Re: RFR: 8345687: Improve the implementation of SegmentFactories::allocateSegment [v7]

2025-03-13 Thread Jorn Vernee
On Thu, 13 Mar 2025 05:46:44 GMT, Quan Anh Mai wrote: >> Hi, >> >> This patch improves the performance of a typical `Arena::allocate` in >> several ways: >> >> - Delay the creation of the NativeMemorySegmentImpl. This avoids the merge >> of the instance with the one obtained from the call in

Re: RFR: 8345687: Improve the implementation of SegmentFactories::allocateSegment [v6]

2025-03-13 Thread Quan Anh Mai
On Wed, 12 Mar 2025 11:15:29 GMT, Maurizio Cimadamore wrote: >> Quan Anh Mai has updated the pull request with a new target base due to a >> merge or a rebase. The incremental webrev excludes the unrelated changes >> brought in by the merge/rebase. The pull request contains nine additional >>

Re: RFR: 8345687: Improve the implementation of SegmentFactories::allocateSegment [v7]

2025-03-12 Thread Quan Anh Mai
> Hi, > > This patch improves the performance of a typical `Arena::allocate` in several > ways: > > - Delay the creation of the NativeMemorySegmentImpl. This avoids the merge of > the instance with the one obtained from the call in the uncommon path, > increasing the chance the object being sc

Re: RFR: 8345687: Improve the implementation of SegmentFactories::allocateSegment [v6]

2025-03-12 Thread Maurizio Cimadamore
On Fri, 7 Mar 2025 17:38:13 GMT, Quan Anh Mai wrote: >> Hi, >> >> This patch improves the performance of a typical `Arena::allocate` in >> several ways: >> >> - Delay the creation of the NativeMemorySegmentImpl. This avoids the merge >> of the instance with the one obtained from the call in t

Re: RFR: 8345687: Improve the implementation of SegmentFactories::allocateSegment [v6]

2025-03-07 Thread Quan Anh Mai
On Fri, 7 Mar 2025 17:38:13 GMT, Quan Anh Mai wrote: >> Hi, >> >> This patch improves the performance of a typical `Arena::allocate` in >> several ways: >> >> - Delay the creation of the NativeMemorySegmentImpl. This avoids the merge >> of the instance with the one obtained from the call in t

Re: RFR: 8345687: Improve the implementation of SegmentFactories::allocateSegment [v6]

2025-03-07 Thread Quan Anh Mai
> Hi, > > This patch improves the performance of a typical `Arena::allocate` in several > ways: > > - Delay the creation of the NativeMemorySegmentImpl. This avoids the merge of > the instance with the one obtained from the call in the uncommon path, > increasing the chance the object being sc

Re: RFR: 8345687: Improve the implementation of SegmentFactories::allocateSegment [v3]

2025-02-06 Thread Quan Anh Mai
On Wed, 5 Feb 2025 10:18:01 GMT, Maurizio Cimadamore wrote: >> Only the return value of `CALLOC` is converted to `MemorySegment` in an >> equivalent way, I believe passing a `MemorySegment` to a downcall involves >> acquiring the corresponding segment? As a result, `FREE` is made to accept >>

Re: RFR: 8345687: Improve the implementation of SegmentFactories::allocateSegment [v5]

2025-02-06 Thread Quan Anh Mai
> Hi, > > This patch improves the performance of a typical `Arena::allocate` in several > ways: > > - Delay the creation of the NativeMemorySegmentImpl. This avoids the merge of > the instance with the one obtained from the call in the uncommon path, > increasing the chance the object being sc

Re: RFR: 8345687: Improve the implementation of SegmentFactories::allocateSegment [v3]

2025-02-05 Thread Maurizio Cimadamore
On Sat, 25 Jan 2025 02:32:56 GMT, Quan Anh Mai wrote: >> But the address is immediately converted to memory segment using >> MemorySegment::ofAddress, which is what the linker does anyway? > > Only the return value of `CALLOC` is converted to `MemorySegment` in an > equivalent way, I believe pa

Re: RFR: 8345687: Improve the implementation of SegmentFactories::allocateSegment [v3]

2025-01-24 Thread Quan Anh Mai
On Fri, 24 Jan 2025 11:57:06 GMT, Maurizio Cimadamore wrote: >> The main goal here is that passing/receiving raw addresses as longs is >> cheaper than as `MemorySegment`s. > > But the address is immediately converted to memory segment using > MemorySegment::ofAddress, which is what the linker

Re: RFR: 8345687: Improve the implementation of SegmentFactories::allocateSegment [v3]

2025-01-24 Thread Maurizio Cimadamore
On Wed, 22 Jan 2025 16:45:39 GMT, Quan Anh Mai wrote: >> test/micro/org/openjdk/bench/java/lang/foreign/AllocTest.java line 77: >> >>> 75: var freeAddr = lookup.findOrThrow("free"); >>> 76: CALLOC = linker.downcallHandle(callocAddr, >>> FunctionDescriptor.of(ValueLayout.

Re: RFR: 8345687: Improve the implementation of SegmentFactories::allocateSegment [v3]

2025-01-22 Thread Quan Anh Mai
On Mon, 16 Dec 2024 11:01:11 GMT, Maurizio Cimadamore wrote: >> Quan Anh Mai has updated the pull request incrementally with two additional >> commits since the last revision: >> >> - wrong init >> - move segment instance creation to SegmentFactories > > test/micro/org/openjdk/bench/java/lan

Re: RFR: 8345687: Improve the implementation of SegmentFactories::allocateSegment [v4]

2025-01-22 Thread Quan Anh Mai
> Hi, > > This patch improves the performance of a typical `Arena::allocate` in several > ways: > > - Delay the creation of the NativeMemorySegmentImpl. This avoids the merge of > the instance with the one obtained from the call in the uncommon path, > increasing the chance the object being sc

Re: RFR: 8345687: Improve the implementation of SegmentFactories::allocateSegment [v3]

2024-12-16 Thread Maurizio Cimadamore
On Wed, 11 Dec 2024 19:29:13 GMT, Quan Anh Mai wrote: >> Hi, >> >> This patch improves the performance of a typical `Arena::allocate` in >> several ways: >> >> - Delay the creation of the NativeMemorySegmentImpl. This avoids the merge >> of the instance with the one obtained from the call in

Re: RFR: 8345687: Improve the implementation of SegmentFactories::allocateSegment [v3]

2024-12-12 Thread Jorn Vernee
On Wed, 11 Dec 2024 19:29:13 GMT, Quan Anh Mai wrote: >> Hi, >> >> This patch improves the performance of a typical `Arena::allocate` in >> several ways: >> >> - Delay the creation of the NativeMemorySegmentImpl. This avoids the merge >> of the instance with the one obtained from the call in

Re: RFR: 8345687: Improve the implementation of SegmentFactories::allocateSegment [v3]

2024-12-11 Thread Quan Anh Mai
On Wed, 11 Dec 2024 18:50:18 GMT, Maurizio Cimadamore wrote: >> I want to put it here so that even if `SegmentFactories::allocateNative` is >> not inlined, this small method will be more likely to be inlined and the >> segment can be non-escape, then. I have added a comment regarding class >>

Re: RFR: 8345687: Improve the implementation of SegmentFactories::allocateSegment [v3]

2024-12-11 Thread Quan Anh Mai
> Hi, > > This patch improves the performance of a typical `Arena::allocate` in several > ways: > > - Delay the creation of the NativeMemorySegmentImpl. This avoids the merge of > the instance with the one obtained from the call in the uncommon path, > increasing the chance the object being sc

Re: RFR: 8345687: Improve the implementation of SegmentFactories::allocateSegment [v2]

2024-12-11 Thread Maurizio Cimadamore
On Wed, 11 Dec 2024 18:37:06 GMT, Quan Anh Mai wrote: >> src/java.base/share/classes/jdk/internal/foreign/ArenaImpl.java line 53: >> >>> 51: Utils.checkAllocationSizeAndAlign(byteSize, byteAlignment); >>> 52: long address = SegmentFactories.allocateNative(byteSize, >>> byteAlign

Re: RFR: 8345687: Improve the implementation of SegmentFactories::allocateSegment [v2]

2024-12-11 Thread Quan Anh Mai
> Hi, > > This patch improves the performance of a typical `Arena::allocate` in several > ways: > > - Delay the creation of the NativeMemorySegmentImpl. This avoids the merge of > the instance with the one obtained from the call in the uncommon path, > increasing the chance the object being sc

Re: RFR: 8345687: Improve the implementation of SegmentFactories::allocateSegment [v2]

2024-12-11 Thread Quan Anh Mai
On Mon, 9 Dec 2024 12:48:07 GMT, Maurizio Cimadamore wrote: >> src/java.base/share/classes/jdk/internal/foreign/SegmentFactories.java line >> 213: >> >>> 211: >>> 212: @DontInline >>> 213: private static long allocateNativeOveraligned(long byteSize, long >>> byteAlignment, MemorySess

Re: RFR: 8345687: Improve the implementation of SegmentFactories::allocateSegment [v2]

2024-12-11 Thread Quan Anh Mai
On Fri, 6 Dec 2024 18:29:46 GMT, Jorn Vernee wrote: >> Quan Anh Mai has updated the pull request incrementally with one additional >> commit since the last revision: >> >> address review > > src/java.base/share/classes/jdk/internal/foreign/ArenaImpl.java line 53: > >> 51: Utils.check

Re: RFR: 8345687: Improve the implementation of SegmentFactories::allocateSegment

2024-12-11 Thread Quan Anh Mai
On Fri, 6 Dec 2024 16:30:47 GMT, Quan Anh Mai wrote: > Hi, > > This patch improves the performance of a typical `Arena::allocate` in several > ways: > > - Delay the creation of the NativeMemorySegmentImpl. This avoids the merge of > the instance with the one obtained from the call in the unco

Re: RFR: 8345687: Improve the implementation of SegmentFactories::allocateSegment

2024-12-09 Thread Maurizio Cimadamore
On Fri, 6 Dec 2024 18:33:33 GMT, Jorn Vernee wrote: >> Hi, >> >> This patch improves the performance of a typical `Arena::allocate` in >> several ways: >> >> - Delay the creation of the NativeMemorySegmentImpl. This avoids the merge >> of the instance with the one obtained from the call in th

Re: RFR: 8345687: Improve the implementation of SegmentFactories::allocateSegment

2024-12-06 Thread Jorn Vernee
On Fri, 6 Dec 2024 16:30:47 GMT, Quan Anh Mai wrote: > Hi, > > This patch improves the performance of a typical `Arena::allocate` in several > ways: > > - Delay the creation of the NativeMemorySegmentImpl. This avoids the merge of > the instance with the one obtained from the call in the unco

Re: RFR: 8345687: Improve the implementation of SegmentFactories::allocateSegment

2024-12-06 Thread Quan Anh Mai
On Fri, 6 Dec 2024 16:30:47 GMT, Quan Anh Mai wrote: > Hi, > > This patch improves the performance of a typical `Arena::allocate` in several > ways: > > - Delay the creation of the NativeMemorySegmentImpl. This avoids the merge of > the instance with the one obtained from the call in the unco