Skip to content

Commit 6db1135

Browse files
committed
Clean up our two remaining wrappers with full off-heap memory
1 parent fc419fb commit 6db1135

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/PyMemoryViewWrapper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
* Wrapper object for {@code PMemoryView}.
6666
*/
6767
public final class PyMemoryViewWrapper extends PythonAbstractObjectNativeWrapper {
68-
private Object replacement;
68+
private NativePointer replacement;
6969

7070
public PyMemoryViewWrapper(PythonObject delegate) {
7171
super(delegate);
@@ -144,7 +144,7 @@ private static long allocate(PMemoryView object) {
144144
return mem;
145145
}
146146

147-
public Object getReplacement(InteropLibrary lib) {
147+
public Object getReplacement() {
148148
if (replacement == null) {
149149
long ptr = allocate((PMemoryView) getDelegate());
150150
// TODO: need to convert to interop pointer for NFI for now

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/PythonClassNativeWrapper.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,15 +197,15 @@ public String toString() {
197197
return PythonUtils.formatJString("PythonClassNativeWrapper(%s, isNative=%s)", getDelegate(), isNative());
198198
}
199199

200-
public Object getReplacement(InteropLibrary lib) {
200+
public Object getReplacement() {
201201
if (CompilerDirectives.injectBranchProbability(CompilerDirectives.SLOWPATH_PROBABILITY, replacement == null)) {
202-
initializeReplacement(lib);
202+
initializeReplacement();
203203
}
204204
return replacement;
205205
}
206206

207207
@TruffleBoundary
208-
private void initializeReplacement(InteropLibrary lib) {
208+
private void initializeReplacement() {
209209
/*
210210
* Note: it's important that we first allocate the empty 'PyTypeStruct' and register it to
211211
* the wrapper before we do the type's initialization. Otherwise, we will run into an

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/transitions/GetReplacementNode.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,21 @@
4343
import com.oracle.graal.python.builtins.objects.cext.capi.PyMemoryViewWrapper;
4444
import com.oracle.graal.python.builtins.objects.cext.capi.PythonClassNativeWrapper;
4545
import com.oracle.graal.python.builtins.objects.cext.capi.PythonNativeWrapper;
46-
import com.oracle.truffle.api.dsl.Cached.Shared;
4746
import com.oracle.truffle.api.dsl.Fallback;
4847
import com.oracle.truffle.api.dsl.GenerateCached;
4948
import com.oracle.truffle.api.dsl.GenerateInline;
5049
import com.oracle.truffle.api.dsl.GenerateUncached;
5150
import com.oracle.truffle.api.dsl.Specialization;
5251
import com.oracle.truffle.api.interop.InteropLibrary;
53-
import com.oracle.truffle.api.library.CachedLibrary;
5452
import com.oracle.truffle.api.nodes.Node;
5553

54+
/**
55+
* Native wrappers are usually materialized lazily when they receive
56+
* {@link InteropLibrary#toNative(Object)}. A few native wrappers may emulate data structures where
57+
* it is more efficient to have off-heap memory that just replaces the object on the native side
58+
* (and is presumably somehow synced). These wrappers have specializations here so the users of this
59+
* node can return them directly for native access.
60+
*/
5661
@GenerateUncached
5762
@GenerateInline
5863
@GenerateCached(false)
@@ -61,15 +66,13 @@ public abstract class GetReplacementNode extends Node {
6166
public abstract Object execute(Node inliningTarget, PythonNativeWrapper wrapper);
6267

6368
@Specialization
64-
static Object doReplacingWrapper(PyMemoryViewWrapper wrapper,
65-
@Shared @CachedLibrary(limit = "3") InteropLibrary lib) {
66-
return wrapper.getReplacement(lib);
69+
static Object doReplacingWrapper(PyMemoryViewWrapper wrapper) {
70+
return wrapper.getReplacement();
6771
}
6872

6973
@Specialization
70-
static Object doReplacingWrapper(PythonClassNativeWrapper wrapper,
71-
@Shared @CachedLibrary(limit = "3") InteropLibrary lib) {
72-
return wrapper.getReplacement(lib);
74+
static Object doReplacingWrapper(PythonClassNativeWrapper wrapper) {
75+
return wrapper.getReplacement();
7376
}
7477

7578
@Fallback

0 commit comments

Comments
 (0)