@@ -180,22 +180,51 @@ const GLOBAL_CI_CACHES_LOCK = ReentrantLock()
180
180
181
181
function CC. setindex! (cache:: CodeCache , ci:: CodeInstance , mi:: MethodInstance )
182
182
# make sure the invalidation callback is attached to the method instance
183
- callback (mi, max_world) = invalidate_code_cache (cache, mi, max_world)
183
+ add_codecache_callback! (cache, mi)
184
+ cis = get! (cache. dict, mi, CodeInstance[])
185
+ push! (cis, ci)
186
+ end
187
+
188
+ # invalidation (like invalidate_method_instance, but for our cache)
189
+ struct CodeCacheCallback
190
+ cache:: CodeCache
191
+ end
192
+
193
+ @static if VERSION ≥ v " 1.11.0-DEV.798"
194
+
195
+ function add_codecache_callback! (cache:: CodeCache , mi:: MethodInstance )
196
+ callback = CodeCacheCallback (cache)
197
+ CC. add_invalidation_callback! (callback, mi)
198
+ end
199
+ function (callback:: CodeCacheCallback )(replaced:: MethodInstance , max_world:: UInt32 )
200
+ cis = get (callback. cache. dict, replaced, nothing )
201
+ if cis === nothing
202
+ return
203
+ end
204
+ for ci in cis
205
+ if ci. max_world == ~ 0 % Csize_t
206
+ @assert ci. min_world - 1 <= max_world " attempting to set illogical constraints"
207
+ ci. max_world = max_world
208
+ end
209
+ @assert ci. max_world <= max_world
210
+ end
211
+ end
212
+
213
+ else
214
+
215
+ function add_codecache_callback! (cache:: CodeCache , mi:: MethodInstance )
216
+ callback = CodeCacheCallback (cache)
184
217
if ! isdefined (mi, :callbacks )
185
218
mi. callbacks = Any[callback]
186
219
elseif ! in (callback, mi. callbacks)
187
220
push! (mi. callbacks, callback)
188
221
end
189
-
190
- cis = get! (cache. dict, mi, CodeInstance[])
191
- push! (cis, ci)
192
222
end
193
-
194
- # invalidation (like invalidate_method_instance, but for our cache)
195
- function invalidate_code_cache (cache:: CodeCache , replaced:: MethodInstance , max_world, seen= Set {MethodInstance} ())
223
+ function (callback:: CodeCacheCallback )(replaced:: MethodInstance , max_world:: UInt32 ,
224
+ seen:: Set{MethodInstance} = Set {MethodInstance} ())
196
225
push! (seen, replaced)
197
226
198
- cis = get (cache. dict, replaced, nothing )
227
+ cis = get (callback . cache. dict, replaced, nothing )
199
228
if cis === nothing
200
229
return
201
230
end
@@ -225,11 +254,12 @@ function invalidate_code_cache(cache::CodeCache, replaced::MethodInstance, max_w
225
254
# replaced.backedges = Any[]
226
255
227
256
for mi in backedges
228
- invalidate_code_cache (cache, mi:: MethodInstance , max_world, seen)
257
+ callback ( mi:: MethodInstance , max_world, seen)
229
258
end
230
259
end
231
260
end
232
261
262
+ end
233
263
234
264
# # method overrides
235
265
0 commit comments