Skip to content

Commit 27c2018

Browse files
eregonhorakivo
authored andcommitted
Move the limit to InteropLibrary for CExtNodes
* There is no gain to duplicate the code around the InteropNodes.execute() and it would force the specialization to be static + not share the helper nodes.
1 parent 6705877 commit 27c2018

File tree

1 file changed

+26
-29
lines changed

1 file changed

+26
-29
lines changed

src/main/java/org/truffleruby/cext/CExtNodes.java

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -176,29 +176,28 @@ private static long getNativeStringCapacity(Pointer pointer) {
176176
@Primitive(name = "call_with_c_mutex_and_frame")
177177
public abstract static class CallWithCExtLockAndFrameNode extends PrimitiveArrayArgumentsNode {
178178

179-
@Specialization(limit = "getCacheLimit()")
180-
protected static Object callWithCExtLockAndFrame(
179+
@Specialization
180+
protected Object callWithCExtLockAndFrame(
181181
VirtualFrame frame, Object receiver, RubyArray argsArray, Object specialVariables, Object block,
182-
@CachedLibrary("receiver") InteropLibrary receivers,
182+
@CachedLibrary(limit = "getCacheLimit()") InteropLibrary receivers,
183183
@Cached ArrayToObjectArrayNode arrayToObjectArrayNode,
184184
@Cached TranslateInteropExceptionNode translateInteropExceptionNode,
185185
@Cached InlinedConditionProfile ownedProfile,
186-
@Cached RunMarkOnExitNode runMarksNode,
187-
@Bind("this") Node node) {
188-
final ExtensionCallStack extensionStack = getLanguage(node)
186+
@Cached RunMarkOnExitNode runMarksNode) {
187+
final ExtensionCallStack extensionStack = getLanguage()
189188
.getCurrentThread()
190189
.getCurrentFiber().extensionCallStack;
191190
final boolean keywordsGiven = RubyArguments.getDescriptor(frame) instanceof KeywordArgumentsDescriptor;
192191
extensionStack.push(keywordsGiven, specialVariables, block);
193192
try {
194193
final Object[] args = arrayToObjectArrayNode.executeToObjectArray(argsArray);
195194

196-
if (getContext(node).getOptions().CEXT_LOCK) {
197-
final ReentrantLock lock = getContext(node).getCExtensionsLock();
198-
boolean owned = ownedProfile.profile(node, lock.isHeldByCurrentThread());
195+
if (getContext().getOptions().CEXT_LOCK) {
196+
final ReentrantLock lock = getContext().getCExtensionsLock();
197+
boolean owned = ownedProfile.profile(this, lock.isHeldByCurrentThread());
199198

200199
if (!owned) {
201-
MutexOperations.lockInternal(getContext(node), lock, node);
200+
MutexOperations.lockInternal(getContext(), lock, this);
202201
}
203202
try {
204203
return InteropNodes.execute(receiver, args, receivers, translateInteropExceptionNode);
@@ -229,28 +228,27 @@ protected int getCacheLimit() {
229228
@Primitive(name = "call_with_c_mutex_and_frame_and_unwrap")
230229
public abstract static class CallWithCExtLockAndFrameAndUnwrapNode extends PrimitiveArrayArgumentsNode {
231230

232-
@Specialization(limit = "getCacheLimit()")
233-
protected static Object callWithCExtLockAndFrame(
231+
@Specialization
232+
protected Object callWithCExtLockAndFrame(
234233
VirtualFrame frame, Object receiver, RubyArray argsArray, Object specialVariables, Object block,
235-
@CachedLibrary("receiver") InteropLibrary receivers,
234+
@CachedLibrary(limit = "getCacheLimit()") InteropLibrary receivers,
236235
@Cached ArrayToObjectArrayNode arrayToObjectArrayNode,
237236
@Cached TranslateInteropExceptionNode translateInteropExceptionNode,
238237
@Cached InlinedConditionProfile ownedProfile,
239238
@Cached RunMarkOnExitNode runMarksNode,
240-
@Cached UnwrapNode unwrapNode,
241-
@Bind("this") Node node) {
242-
final ExtensionCallStack extensionStack = getLanguage(node).getCurrentFiber().extensionCallStack;
239+
@Cached UnwrapNode unwrapNode) {
240+
final ExtensionCallStack extensionStack = getLanguage().getCurrentFiber().extensionCallStack;
243241
final boolean keywordsGiven = RubyArguments.getDescriptor(frame) instanceof KeywordArgumentsDescriptor;
244242
extensionStack.push(keywordsGiven, specialVariables, block);
245243
try {
246244
final Object[] args = arrayToObjectArrayNode.executeToObjectArray(argsArray);
247245

248-
if (getContext(node).getOptions().CEXT_LOCK) {
249-
final ReentrantLock lock = getContext(node).getCExtensionsLock();
250-
boolean owned = ownedProfile.profile(node, lock.isHeldByCurrentThread());
246+
if (getContext().getOptions().CEXT_LOCK) {
247+
final ReentrantLock lock = getContext().getCExtensionsLock();
248+
boolean owned = ownedProfile.profile(this, lock.isHeldByCurrentThread());
251249

252250
if (!owned) {
253-
MutexOperations.lockInternal(getContext(node), lock, node);
251+
MutexOperations.lockInternal(getContext(), lock, this);
254252
}
255253
try {
256254
return unwrapNode.execute(
@@ -285,21 +283,20 @@ public abstract static class CallWithCExtLockNode extends PrimitiveArrayArgument
285283

286284
public abstract Object execute(Object receiver, RubyArray argsArray);
287285

288-
@Specialization(limit = "getCacheLimit()")
289-
protected static Object callWithCExtLock(Object receiver, RubyArray argsArray,
290-
@CachedLibrary("receiver") InteropLibrary receivers,
286+
@Specialization
287+
protected Object callWithCExtLock(Object receiver, RubyArray argsArray,
288+
@CachedLibrary(limit = "getCacheLimit()") InteropLibrary receivers,
291289
@Cached ArrayToObjectArrayNode arrayToObjectArrayNode,
292290
@Cached TranslateInteropExceptionNode translateInteropExceptionNode,
293-
@Cached InlinedConditionProfile ownedProfile,
294-
@Bind("this") Node node) {
291+
@Cached InlinedConditionProfile ownedProfile) {
295292
final Object[] args = arrayToObjectArrayNode.executeToObjectArray(argsArray);
296293

297-
if (getContext(node).getOptions().CEXT_LOCK) {
298-
final ReentrantLock lock = getContext(node).getCExtensionsLock();
299-
boolean owned = ownedProfile.profile(node, lock.isHeldByCurrentThread());
294+
if (getContext().getOptions().CEXT_LOCK) {
295+
final ReentrantLock lock = getContext().getCExtensionsLock();
296+
boolean owned = ownedProfile.profile(this, lock.isHeldByCurrentThread());
300297

301298
if (!owned) {
302-
MutexOperations.lockInternal(getContext(node), lock, node);
299+
MutexOperations.lockInternal(getContext(), lock, this);
303300
}
304301
try {
305302
return InteropNodes.execute(receiver, args, receivers, translateInteropExceptionNode);

0 commit comments

Comments
 (0)