|
8 | 8 |
|
9 | 9 | (ns ^{:skip-wiki true}
|
10 | 10 | clojure.core.async.impl.dispatch
|
11 |
| - (:import [java.util.concurrent Executors ExecutorService ThreadFactory])) |
| 11 | + (:import [java.util.concurrent Executors ExecutorService ThreadFactory] |
| 12 | + [java.lang.invoke MethodHandles MethodHandle MethodType])) |
12 | 13 |
|
13 | 14 | (set! *warn-on-reflection* true)
|
14 | 15 |
|
|
77 | 78 | (when (or (< maj major)
|
78 | 79 | (< min minor)
|
79 | 80 | (< incr incremental))
|
80 |
| - (throw (ex-info (str "Clojure version greater than " maj "." min "." incr |
81 |
| - " required to run this version of core.async") |
| 81 | + (throw (ex-info (str "Clojure version greater than or equal to " maj "." min "." incr |
| 82 | + " required to the the go block analyzer.") |
82 | 83 | {:clojure-version *clojure-version*})))))
|
83 | 84 |
|
84 | 85 | (def virtual-threads-available?
|
|
103 | 104 | (and virtual-threads-available?
|
104 | 105 | (not= (vthreads-directive) "avoid")))
|
105 | 106 |
|
106 |
| -(def ^:private virtual? |
| 107 | +(def ^:private virtual-thread? |
107 | 108 | (if virtual-threads-available?
|
108 |
| - (eval `(fn [^Thread t#] (~'.isVirtual t#))) |
| 109 | + (let [lookup (MethodHandles/lookup) |
| 110 | + t (MethodType/methodType Boolean/TYPE) |
| 111 | + ^MethodHandle mh (.findVirtual lookup Thread "isVirtual" t)] |
| 112 | + (fn [^Thread thread] |
| 113 | + (.invokeWithArguments mh [thread]))) |
109 | 114 | (constantly false)))
|
110 | 115 |
|
111 | 116 | (defn in-vthread? []
|
112 | 117 | (and virtual-threads-available?
|
113 |
| - (virtual? (Thread/currentThread)))) |
| 118 | + (virtual-thread? (Thread/currentThread)))) |
114 | 119 |
|
115 | 120 | (defn report-vthreads-not-available-error! []
|
116 | 121 | (throw (ex-info "Code compiled to target virtual threads, but is running without vthread support."
|
|
0 commit comments