|
1 | 1 | package org.enso.interpreter.runtime.data;
|
2 | 2 |
|
| 3 | +import com.oracle.truffle.api.CompilerDirectives; |
3 | 4 | import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
|
4 | 5 | import com.oracle.truffle.api.dsl.Bind;
|
5 | 6 | import com.oracle.truffle.api.interop.InteropLibrary;
|
|
12 | 13 | import org.enso.interpreter.runtime.callable.function.Function;
|
13 | 14 | import org.enso.interpreter.runtime.library.dispatch.TypesLibrary;
|
14 | 15 |
|
15 |
| -/** A runtime representation of a managed resource. */ |
| 16 | +/** |
| 17 | + * An Enso runtime representation of a managed resource. |
| 18 | + * |
| 19 | + * <p><b>Instance of this class</b> is convoluted with instances playing various roles: |
| 20 | + * |
| 21 | + * <ul> |
| 22 | + * <li>this {@link ManagedResource} points to {@code resource} |
| 23 | + * <li>this {@link ManagedResource} points to {@link PhantomReference} that is "phantom |
| 24 | + * referencing" {@code this} |
| 25 | + * <li>the implementation of {@link PhantomReference} is {@code Item} in {@link ResourceManager} |
| 26 | + * <li>the {@code Item} <em>"phantom referencing"</em> {@code this} {@link ManagedResource} is |
| 27 | + * stored in {@link ResourceManager} {@code pendingItems} collection. |
| 28 | + * <li>the {@code Item} has a pointer to the {@code resource} as well |
| 29 | + * <li>the {@code Item} has a pointer to the {@code finalizer} function |
| 30 | + * </ul> |
| 31 | + * |
| 32 | + * Once all this braided chunk of objects is eligible for GC because <b>nobody holds pointer to |
| 33 | + * {@link ManagedResource}</b>, the {@code Item} is put into {@link ResourceManager} {@code |
| 34 | + * referenceQueue} and process by the intricate machinery of {@link ResourceManager} and its {@code |
| 35 | + * ProcessItems} processor. |
| 36 | + */ |
16 | 37 | @ExportLibrary(InteropLibrary.class)
|
17 | 38 | @ExportLibrary(TypesLibrary.class)
|
18 | 39 | @Builtin(pkg = "resource", stdlibName = "Standard.Base.Runtime.Managed_Resource.Managed_Resource")
|
@@ -97,8 +118,16 @@ Type getType(@Bind("$node") Node node) {
|
97 | 118 |
|
98 | 119 | @ExportMessage
|
99 | 120 | @TruffleBoundary
|
| 121 | + public String toDisplayString(boolean allowSideEffects, @Bind("$node") Node node) { |
| 122 | + var type = getType(node); |
| 123 | + return type.getName() |
| 124 | + + " " |
| 125 | + + InteropLibrary.getUncached().toDisplayString(resource, allowSideEffects); |
| 126 | + } |
| 127 | + |
| 128 | + @ExportMessage.Ignore |
100 | 129 | @Override
|
101 |
| - public String toDisplayString(boolean allowSideEffects) { |
102 |
| - return resource.toString(); |
| 130 | + public Object toDisplayString(boolean allowSideEffects) { |
| 131 | + throw CompilerDirectives.shouldNotReachHere(); |
103 | 132 | }
|
104 | 133 | }
|
0 commit comments