RFR: 8338417: Explicitly pin a virtual thread before acquiring the JFR string pool monitor [v3]

Alan Bateman alanb at openjdk.org
Thu Aug 15 14:34:48 UTC 2024


On Thu, 15 Aug 2024 14:16:11 GMT, Erik Gahlin <egahlin at openjdk.org> wrote:

>> src/jdk.jfr/share/classes/jdk/jfr/internal/StringPool.java line 86:
>> 
>>> 84: 
>>> 85:     private static void unpinVirtualThread() {
>>> 86:         if (Thread.currentThread().isVirtual() && ContinuationSupport.isSupported()) {
>> 
>> If you are at all concerned about overhead here then pin could return a boolean to indicate if the pin happened and oyu could then unpin just by checking that boolean and avoid doing the isVirtual and isSupported checks again.
>
> Would it be possible to create a boolean in the EventWriter that indicates if it is associated with a carrier thread or a normal thread (which can never be virtual) and then have two methods.
> 
>     long l = this.carrierThread ? StringPool.addPinnedString(s) : StringPool.addString(s);

Thread.currentThread() has an intrinsic, and isVirtual is just a type check. ContinuationSupport.isSupported reads a static final so will disappear once compiled. The pattern we are using in other areas is for the pin to return a boolean (like David suggested).

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

PR Review Comment: https://git.openjdk.org/jdk/pull/20588#discussion_r1718489921


More information about the core-libs-dev mailing list