Skip to content

Commit a0bd29c

Browse files
committed
Mark native arrays when the storage pointer has escaped.
1 parent 6c6155f commit a0bd29c

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

lib/truffle/truffle/cext.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,6 +1495,8 @@ def rb_data_typed_object_wrap(ruby_class, data, data_type, mark, free, size)
14951495
end
14961496

14971497
def run_marker(obj)
1498+
Primitive.array_mark_store(obj) if Primitive.array_store_native?(obj)
1499+
14981500
mark = Primitive.object_hidden_var_get obj, DATA_MARKER
14991501
unless Truffle::Interop.null?(mark)
15001502
create_mark_list(obj)

lib/truffle/truffle/cext_structs.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ def polyglot_pointer?
295295
end
296296

297297
def polyglot_as_pointer
298+
Primitive.cext_mark_object_on_call_exit(@array)
298299
Primitive.array_store_address(@array)
299300
end
300301

src/main/java/org/truffleruby/core/array/ArrayNodes.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2371,6 +2371,25 @@ protected boolean isStoreNative(RubyArray array,
23712371
@CachedLibrary("store") ArrayStoreLibrary stores) {
23722372
return stores.isNative(store);
23732373
}
2374+
2375+
@Specialization(guards = "!isRubyArray(array)")
2376+
protected boolean isStoreNativeNonArray(Object array) {
2377+
return false;
2378+
}
2379+
}
2380+
2381+
@Primitive(name = "array_mark_store")
2382+
@ImportStatic(ArrayGuards.class)
2383+
public abstract static class MarkNativeStoreNode extends PrimitiveArrayArgumentsNode {
2384+
2385+
@Specialization
2386+
protected Object markNativeStore(RubyArray array) {
2387+
Object store = array.getStore();
2388+
if (store instanceof NativeArrayStorage) {
2389+
((NativeArrayStorage) store).preserveMembers();
2390+
}
2391+
return nil;
2392+
}
23742393
}
23752394

23762395
@Primitive(name = "array_flatten_helper", lowerFixnum = 2)

0 commit comments

Comments
 (0)