@@ -15,7 +15,7 @@ mutable struct ClusterSerializer{I<:IO} <: AbstractSerializer
15
15
16
16
pid:: Int # Worker we are connected to.
17
17
tn_obj_sent:: Set{UInt64} # TypeName objects sent
18
- glbs_sent:: Dict{UInt64, UInt64} # (key,value) -> (objectid, hash_value)
18
+ glbs_sent:: Dict{Symbol, Tuple{ UInt64, UInt64}} # (key,value) -> (symbol, ( hash_value, objectid) )
19
19
glbs_in_tnobj:: Dict{UInt64, Vector{Symbol}} # Track globals referenced in
20
20
# anonymous functions.
21
21
anonfunc_id:: UInt64
@@ -116,10 +116,11 @@ function serialize(s::ClusterSerializer, g::GlobalRef)
116
116
invoke (serialize, Tuple{AbstractSerializer, GlobalRef}, s, g)
117
117
end
118
118
119
- # Send/resend a global object if
120
- # a) has not been sent previously, i.e., we are seeing this objectid for the first time, or,
119
+ # Send/resend a global binding if
120
+ # a) has not been sent previously, i.e., we are seeing this binding for the first time, or,
121
121
# b) hash value has changed or
122
- # c) is a bits type
122
+ # c) hash value is same but of a different object, i.e. objectid has changed or
123
+ # d) is a bits type
123
124
function syms_2b_sent (s:: ClusterSerializer , identifier)
124
125
lst = Symbol[]
125
126
check_syms = get (s. glbs_in_tnobj, identifier, [])
@@ -129,10 +130,12 @@ function syms_2b_sent(s::ClusterSerializer, identifier)
129
130
if isbits (v)
130
131
push! (lst, sym)
131
132
else
132
- oid = objectid (v)
133
- if haskey (s. glbs_sent, oid)
134
- # We have sent this object before, see if it has changed.
135
- s. glbs_sent[oid] != hash (sym, hash (v)) && push! (lst, sym)
133
+ if haskey (s. glbs_sent, sym)
134
+ # We have sent this binding before, see if it has changed.
135
+ hval, oid = s. glbs_sent[sym]
136
+ if hval != hash (sym, hash (v)) || oid != objectid (v)
137
+ push! (lst, sym)
138
+ end
136
139
else
137
140
push! (lst, sym)
138
141
end
144
147
function serialize_global_from_main (s:: ClusterSerializer , sym)
145
148
v = getfield (Main, sym)
146
149
147
- oid = objectid (v)
148
- record_v = true
149
- if isbits (v)
150
- record_v = false
151
- elseif ! haskey (s. glbs_sent, oid)
152
- # set up a finalizer the first time this object is sent
153
- try
154
- finalizer (v) do x
155
- delete_global_tracker (s,x)
156
- end
157
- catch ex
158
- # Do not track objects that cannot be finalized.
159
- if isa (ex, ErrorException)
160
- record_v = false
161
- else
162
- rethrow ()
163
- end
164
- end
150
+ if ! isbits (v)
151
+ s. glbs_sent[sym] = (hash (sym, hash (v)), objectid (v))
165
152
end
166
- record_v && (s. glbs_sent[oid] = hash (sym, hash (v)))
167
153
168
154
serialize (s, isconst (Main, sym))
169
155
serialize (s, v)
@@ -180,17 +166,6 @@ function deserialize_global_from_main(s::ClusterSerializer, sym)
180
166
return nothing
181
167
end
182
168
183
- function delete_global_tracker (s:: ClusterSerializer , v)
184
- oid = objectid (v)
185
- if haskey (s. glbs_sent, oid)
186
- delete! (s. glbs_sent, oid)
187
- end
188
-
189
- # TODO : A global binding is released and gc'ed here but it continues
190
- # to occupy memory on the remote node. Would be nice to release memory
191
- # if possible.
192
- end
193
-
194
169
function cleanup_tname_glbs (s:: ClusterSerializer , identifier)
195
170
delete! (s. glbs_in_tnobj, identifier)
196
171
end
0 commit comments