Skip to content

Commit 51eb8d6

Browse files
committed
Convert StringToNativeNode to DSL inlinable
1 parent 7c8d8d5 commit 51eb8d6

File tree

2 files changed

+26
-26
lines changed

2 files changed

+26
-26
lines changed

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

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515

1616
import com.oracle.truffle.api.TruffleSafepoint;
1717
import com.oracle.truffle.api.dsl.Bind;
18-
import com.oracle.truffle.api.dsl.NeverDefault;
18+
import com.oracle.truffle.api.dsl.GenerateCached;
19+
import com.oracle.truffle.api.dsl.GenerateInline;
1920
import com.oracle.truffle.api.object.DynamicObjectLibrary;
2021
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
2122
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
@@ -35,7 +36,6 @@
3536
import org.truffleruby.builtins.CoreMethodArrayArgumentsNode;
3637
import org.truffleruby.builtins.CoreMethodNode;
3738
import org.truffleruby.builtins.PrimitiveArrayArgumentsNode;
38-
import org.truffleruby.cext.CExtNodesFactory.StringToNativeNodeGen;
3939
import org.truffleruby.cext.UnwrapNode.UnwrapCArrayNode;
4040
import org.truffleruby.core.MarkingService.ExtensionCallStack;
4141
import org.truffleruby.core.MarkingServiceNodes;
@@ -713,7 +713,7 @@ public abstract static class RbEncCodeRangeClear extends CoreMethodArrayArgument
713713
@Specialization
714714
protected RubyString clearCodeRange(RubyString string,
715715
@Cached StringToNativeNode stringToNativeNode) {
716-
stringToNativeNode.executeToNative(string);
716+
stringToNativeNode.executeToNative(this, string);
717717
string.clearCodeRange();
718718

719719
return string;
@@ -814,7 +814,7 @@ public abstract static class RbStrCapacityNode extends CoreMethodArrayArgumentsN
814814
@Specialization
815815
protected long capacity(Object string,
816816
@Cached StringToNativeNode stringToNativeNode) {
817-
return getNativeStringCapacity(stringToNativeNode.executeToNative(string));
817+
return getNativeStringCapacity(stringToNativeNode.executeToNative(this, string));
818818
}
819819
}
820820

@@ -827,7 +827,7 @@ protected RubyString strSetLen(RubyString string, int newByteLength,
827827
@Cached StringToNativeNode stringToNativeNode,
828828
@Cached MutableTruffleString.FromNativePointerNode fromNativePointerNode,
829829
@Cached InlinedConditionProfile minLengthOneProfile) {
830-
var pointer = stringToNativeNode.executeToNative(string);
830+
var pointer = stringToNativeNode.executeToNative(this, string);
831831

832832
var encoding = libString.getEncoding(string);
833833
int minLength = encoding.jcoding.minLength();
@@ -857,7 +857,7 @@ protected RubyString rbStrResize(RubyString string, int newByteLength,
857857
@Cached RubyStringLibrary libString,
858858
@Cached StringToNativeNode stringToNativeNode,
859859
@Cached MutableTruffleString.FromNativePointerNode fromNativePointerNode) {
860-
var pointer = stringToNativeNode.executeToNative(string);
860+
var pointer = stringToNativeNode.executeToNative(this, string);
861861
var tencoding = libString.getTEncoding(string);
862862
int byteLength = string.tstring.byteLength(tencoding);
863863

@@ -886,7 +886,7 @@ protected RubyString trStrCapaResize(RubyString string, int newCapacity,
886886
@Cached RubyStringLibrary libString,
887887
@Cached StringToNativeNode stringToNativeNode,
888888
@Cached MutableTruffleString.FromNativePointerNode fromNativePointerNode) {
889-
var pointer = stringToNativeNode.executeToNative(string);
889+
var pointer = stringToNativeNode.executeToNative(this, string);
890890
var tencoding = libString.getTEncoding(string);
891891

892892
if (getNativeStringCapacity(pointer) == newCapacity) {
@@ -1337,33 +1337,30 @@ protected int rbHash(Object object,
13371337
}
13381338
}
13391339

1340+
@GenerateInline
1341+
@GenerateCached(false)
13401342
public abstract static class StringToNativeNode extends RubyBaseNode {
13411343

1342-
@NeverDefault
1343-
public static StringToNativeNode create() {
1344-
return StringToNativeNodeGen.create();
1345-
}
1346-
1347-
public abstract Pointer executeToNative(Object string);
1344+
public abstract Pointer executeToNative(Node node, Object string);
13481345

13491346
@Specialization
1350-
protected Pointer toNative(RubyString string,
1347+
protected static Pointer toNative(Node node, RubyString string,
13511348
@Cached RubyStringLibrary libString,
13521349
@Cached InlinedConditionProfile convertProfile,
1353-
@Cached TruffleString.CopyToNativeMemoryNode copyToNativeMemoryNode,
1354-
@Cached MutableTruffleString.FromNativePointerNode fromNativePointerNode,
1355-
@Cached TruffleString.GetInternalNativePointerNode getInternalNativePointerNode) {
1350+
@Cached(inline = false) TruffleString.CopyToNativeMemoryNode copyToNativeMemoryNode,
1351+
@Cached(inline = false) MutableTruffleString.FromNativePointerNode fromNativePointerNode,
1352+
@Cached(inline = false) TruffleString.GetInternalNativePointerNode getInternalNativePointerNode) {
13561353
var tstring = string.tstring;
13571354
var tencoding = libString.getTEncoding(string);
13581355

13591356
final Pointer pointer;
13601357

1361-
if (convertProfile.profile(this, tstring.isNative())) {
1358+
if (convertProfile.profile(node, tstring.isNative())) {
13621359
assert tstring.isMutable();
13631360
pointer = (Pointer) getInternalNativePointerNode.execute(tstring, tencoding);
13641361
} else {
13651362
int byteLength = tstring.byteLength(tencoding);
1366-
pointer = allocateAndCopyToNative(getLanguage(), getContext(), tstring, tencoding, byteLength,
1363+
pointer = allocateAndCopyToNative(getLanguage(node), getContext(node), tstring, tencoding, byteLength,
13671364
copyToNativeMemoryNode);
13681365

13691366
var nativeTString = fromNativePointerNode.execute(pointer, 0, byteLength, tencoding, false);
@@ -1374,8 +1371,8 @@ protected Pointer toNative(RubyString string,
13741371
}
13751372

13761373
@Specialization
1377-
protected Pointer toNativeImmutable(ImmutableRubyString string) {
1378-
return string.getNativeString(getLanguage());
1374+
protected static Pointer toNativeImmutable(Node node, ImmutableRubyString string) {
1375+
return string.getNativeString(getLanguage(node));
13791376
}
13801377

13811378
public static Pointer allocateAndCopyToNative(RubyLanguage language, RubyContext context,
@@ -1394,7 +1391,7 @@ public abstract static class StringPointerToNativeNode extends PrimitiveArrayArg
13941391
@Specialization
13951392
protected long toNative(Object string,
13961393
@Cached StringToNativeNode stringToNativeNode) {
1397-
return stringToNativeNode.executeToNative(string).getAddress();
1394+
return stringToNativeNode.executeToNative(this, string).getAddress();
13981395
}
13991396
}
14001397

@@ -1404,7 +1401,7 @@ public abstract static class StringToFFIPointerNode extends CoreMethodArrayArgum
14041401
@Specialization
14051402
protected RubyPointer toNative(Object string,
14061403
@Cached StringToNativeNode stringToNativeNode) {
1407-
var pointer = stringToNativeNode.executeToNative(string);
1404+
var pointer = stringToNativeNode.executeToNative(this, string);
14081405

14091406
final RubyPointer instance = new RubyPointer(
14101407
coreLibrary().truffleFFIPointerClass,

src/main/java/org/truffleruby/core/format/convert/StringToPointerNode.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import java.util.List;
1414

1515
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
16+
import com.oracle.truffle.api.dsl.Bind;
17+
import com.oracle.truffle.api.nodes.Node;
1618
import org.truffleruby.cext.CExtNodes;
1719
import org.truffleruby.core.format.FormatFrameDescriptor;
1820
import org.truffleruby.core.format.FormatNode;
@@ -35,11 +37,12 @@ protected long toPointer(Nil nil) {
3537

3638
@SuppressWarnings("unchecked")
3739
@Specialization(guards = "strings.isRubyString(string)", limit = "1")
38-
protected long toPointer(VirtualFrame frame, Object string,
40+
protected static long toPointer(VirtualFrame frame, Object string,
3941
@Cached CExtNodes.StringToNativeNode stringToNativeNode,
40-
@Cached RubyStringLibrary strings) {
42+
@Cached RubyStringLibrary strings,
43+
@Bind("this") Node node) {
4144

42-
final Pointer pointer = stringToNativeNode.executeToNative(string);
45+
final Pointer pointer = stringToNativeNode.executeToNative(node, string);
4346

4447
List<Pointer> associated = (List<Pointer>) frame.getObject(FormatFrameDescriptor.ASSOCIATED_SLOT);
4548

0 commit comments

Comments
 (0)