ADDITIONAL SYSTEM INFORMATION :
-----------------------------------------------------------------
Ubuntu version:
-----------------------------------------------------------------
Linux ip-10-110-25-144 5.4.0-1045-aws #47~18.04.1-Ubuntu SMP Tue Apr 13 15:58:14 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
-----------------------------------------------------------------
JDK8 version:
-----------------------------------------------------------------
openjdk version "1.8.0_362"
OpenJDK Runtime Environment (build 1.8.0_362-8u372-ga~us1-0ubuntu1~18.04-b09)
OpenJDK 64-Bit Server VM (build 25.362-b09, mixed mode)
-----------------------------------------------------------------
JDK17 version:
-----------------------------------------------------------------
openjdk version "17.0.7" 2023-04-18
OpenJDK Runtime Environment (build 17.0.7+7-Ubuntu-0ubuntu118.04)
OpenJDK 64-Bit Server VM (build 17.0.7+7-Ubuntu-0ubuntu118.04, mixed mode, sharing)
A DESCRIPTION OF THE PROBLEM :
Calling AttachCurrentThread/DetachCurrentThread from an unattached native thread experiences up to 100% regression.
```
Time Taken | Mean | Standard Deviation | p999 | p99 | p95 | p90
----------------------------------------
jdk8 110039 μs | 10966.776800 ns | 56177.341432 ns | 532334 ns | 178610 ns | 9317 ns | 7873 ns
jdk17 179558 μs | 17924.003600 ns | 54217.940476 ns | 321488 ns | 122924 ns | 18141 ns | 15983 ns
----------------------------------------
jdk8 110509 μs | 11013.906400 ns | 55116.644885 ns | 513406 ns | 97419 ns | 9828 ns | 7960 ns
jdk17 177801 μs | 17749.037200 ns | 55293.117182 ns | 330321 ns | 111809 ns | 18062 ns | 16026 ns
----------------------------------------
jdk8 109543 μs | 10919.695700 ns | 56184.273630 ns | 543077 ns | 106345 ns | 9569 ns | 7974 ns
jdk17 179328 μs | 17901.148800 ns | 54683.063365 ns | 346205 ns | 112247 ns | 18124 ns | 16025 ns
----------------------------------------
jdk8 112088 μs | 11166.931300 ns | 55597.324850 ns | 529521 ns | 112062 ns | 10241 ns | 8825 ns
jdk17 178398 μs | 17808.946700 ns | 54630.243726 ns | 296359 ns | 116179 ns | 18323 ns | 16121 ns
----------------------------------------
jdk8 110469 μs | 11013.433300 ns | 54701.167789 ns | 598978 ns | 96847 ns | 10273 ns | 8487 ns
jdk17 175880 μs | 17555.650300 ns | 53842.205624 ns | 305101 ns | 114811 ns | 18063 ns | 15962 ns
----------------------------------------
```
Based on profiles taken, it seems to be related to Thread-SMR support, particularly ThreadsSMRSupport::wait_until_not_protected is taking a lot of time.
REGRESSION : Last worked in version 8
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
reproducing repo: https://github.com/alexjinghn/gradleJNI
```
git clone git@github.com:alexjinghn/gradleJNI.git
cd gradleJNI/
benchmark.sh 5 10000
```
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
performance of these two API should not change.
ACTUAL -
performance regression.
---------- BEGIN SOURCE ----------
reproducing repo: https://github.com/alexjinghn/gradleJNI
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Avoid attaching native threads to JVM as much as possible.
FREQUENCY : always