Skip to content

Commit a62b9d3

Browse files
committed
Using inline profiles in matchInRegionTRegex specialization
1 parent 47e5274 commit a62b9d3

File tree

2 files changed

+45
-42
lines changed

2 files changed

+45
-42
lines changed

src/main/java/org/truffleruby/core/regexp/TruffleRegexpNodes.java

Lines changed: 44 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
import com.oracle.truffle.api.library.CachedLibrary;
3636
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
3737
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
38-
import com.oracle.truffle.api.profiles.IntValueProfile;
39-
import com.oracle.truffle.api.profiles.LoopConditionProfile;
38+
import com.oracle.truffle.api.profiles.InlinedIntValueProfile;
39+
import com.oracle.truffle.api.profiles.InlinedLoopConditionProfile;
4040
import com.oracle.truffle.api.strings.TruffleString;
4141
import com.oracle.truffle.api.strings.TruffleString.AsTruffleStringNode;
4242
import org.joni.Matcher;
@@ -85,7 +85,6 @@
8585
import com.oracle.truffle.api.frame.VirtualFrame;
8686
import com.oracle.truffle.api.nodes.ExplodeLoop;
8787
import com.oracle.truffle.api.nodes.Node;
88-
import com.oracle.truffle.api.profiles.ConditionProfile;
8988
import org.truffleruby.language.dispatch.LazyDispatchNode;
9089
import org.truffleruby.language.library.RubyStringLibrary;
9190
import org.truffleruby.language.objects.AllocationTracing;
@@ -870,7 +869,7 @@ public abstract static class MatchInRegionTRegexNode extends PrimitiveArrayArgum
870869

871870

872871
@Specialization(guards = "libString.isRubyString(string)", limit = "1")
873-
protected Object matchInRegionTRegex(
872+
protected static Object matchInRegionTRegex(
874873
RubyRegexp regexp,
875874
Object string,
876875
int fromPos,
@@ -879,35 +878,37 @@ protected Object matchInRegionTRegex(
879878
int startPos,
880879
boolean createMatchData,
881880
@Cached TruffleString.SwitchEncodingNode switchEncodingNode,
882-
@Cached(inline = false) ConditionProfile createMatchDataProfile,
883-
@Cached(inline = false) ConditionProfile matchFoundProfile,
884-
@Cached(inline = false) ConditionProfile tRegexCouldNotCompileProfile,
885-
@Cached(inline = false) ConditionProfile tRegexIncompatibleProfile,
886-
@Cached(inline = false) ConditionProfile startPosNotZeroProfile,
887-
@Cached(inline = false) LoopConditionProfile loopProfile,
881+
@Cached InlinedConditionProfile createMatchDataProfile,
882+
@Cached InlinedConditionProfile matchFoundProfile,
883+
@Cached InlinedConditionProfile tRegexCouldNotCompileProfile,
884+
@Cached InlinedConditionProfile tRegexIncompatibleProfile,
885+
@Cached InlinedConditionProfile startPosNotZeroProfile,
886+
@Cached InlinedLoopConditionProfile loopProfile,
888887
@CachedLibrary(limit = "getInteropCacheLimit()") InteropLibrary regexInterop,
889888
@CachedLibrary(limit = "getInteropCacheLimit()") InteropLibrary resultInterop,
890889
@Cached PrepareRegexpEncodingNode prepareRegexpEncodingNode,
891890
@Cached TRegexCompileNode tRegexCompileNode,
892891
@Cached RubyStringLibrary libString,
893-
@Cached(inline = false) IntValueProfile groupCountProfile,
892+
@Cached InlinedIntValueProfile groupCountProfile,
894893
@Cached LazyDispatchNode warnOnFallbackNode,
895894
@Cached LazyDispatchNode stringDupNode,
896895
@Cached LazyTranslateInteropExceptionNode lazyTranslateInteropExceptionNode,
897896
@Cached LazyMatchInRegionNode fallbackMatchInRegionNode,
898-
@Cached LazyTruffleStringSubstringByteIndexNode substringByteIndexNode) {
897+
@Cached LazyTruffleStringSubstringByteIndexNode substringByteIndexNode,
898+
@Bind("this") Node node) {
899899
final Object tRegex;
900900
final RubyEncoding negotiatedEncoding = prepareRegexpEncodingNode.executePrepare(regexp, string);
901901
var tstring = switchEncodingNode.execute(libString.getTString(string), negotiatedEncoding.tencoding);
902902
final int byteLength = tstring.byteLength(negotiatedEncoding.tencoding);
903903

904904
if (tRegexIncompatibleProfile
905-
.profile(toPos < fromPos || toPos != byteLength || fromPos < 0) ||
906-
tRegexCouldNotCompileProfile.profile((tRegex = tRegexCompileNode.executeTRegexCompile(
905+
.profile(node, toPos < fromPos || toPos != byteLength || fromPos < 0) ||
906+
tRegexCouldNotCompileProfile.profile(node, (tRegex = tRegexCompileNode.executeTRegexCompile(
907907
regexp,
908908
atStart,
909909
negotiatedEncoding)) == nil)) {
910910
return fallbackToJoni(
911+
node,
911912
regexp,
912913
string,
913914
negotiatedEncoding,
@@ -916,30 +917,30 @@ protected Object matchInRegionTRegex(
916917
atStart,
917918
startPos,
918919
createMatchData,
919-
warnOnFallbackNode.get(this),
920-
fallbackMatchInRegionNode.get(this));
920+
warnOnFallbackNode.get(node),
921+
fallbackMatchInRegionNode.get(node));
921922
}
922923

923-
if (getContext().getOptions().REGEXP_INSTRUMENT_MATCH) {
924+
if (getContext(node).getOptions().REGEXP_INSTRUMENT_MATCH) {
924925
TruffleRegexpNodes.instrumentMatch(
925926
MATCHED_REGEXPS_TREGEX,
926927
regexp,
927928
string,
928929
atStart,
929-
getContext().getOptions().REGEXP_INSTRUMENT_MATCH_DETAILED);
930+
getContext(node).getOptions().REGEXP_INSTRUMENT_MATCH_DETAILED);
930931
}
931932

932933
int fromIndex = fromPos;
933934
final TruffleString tstringToMatch;
934935
final String execMethod;
935936

936-
if (createMatchDataProfile.profile(createMatchData)) {
937-
if (startPosNotZeroProfile.profile(startPos > 0)) {
937+
if (createMatchDataProfile.profile(node, createMatchData)) {
938+
if (startPosNotZeroProfile.profile(node, startPos > 0)) {
938939
// If startPos != 0, then fromPos == startPos.
939940
assert fromPos == startPos;
940941
fromIndex = 0;
941942

942-
tstringToMatch = substringByteIndexNode.get(this).execute(tstring, startPos, toPos - startPos,
943+
tstringToMatch = substringByteIndexNode.get(node).execute(tstring, startPos, toPos - startPos,
943944
negotiatedEncoding.tencoding, true);
944945
} else {
945946
tstringToMatch = tstring;
@@ -952,30 +953,30 @@ protected Object matchInRegionTRegex(
952953
tstringToMatch = tstring;
953954
execMethod = "execBoolean";
954955
}
955-
final Object result = invoke(regexInterop, tRegex, execMethod, lazyTranslateInteropExceptionNode.get(this),
956+
final Object result = invoke(regexInterop, tRegex, execMethod, lazyTranslateInteropExceptionNode.get(node),
956957
tstringToMatch, fromIndex);
957958

958-
if (createMatchDataProfile.profile(createMatchData)) {
959+
if (createMatchDataProfile.profile(node, createMatchData)) {
959960
final boolean isMatch = (boolean) readMember(resultInterop, result, "isMatch",
960-
lazyTranslateInteropExceptionNode.get(this));
961+
lazyTranslateInteropExceptionNode.get(node));
961962

962-
if (matchFoundProfile.profile(isMatch)) {
963+
if (matchFoundProfile.profile(node, isMatch)) {
963964
final int groupCount = groupCountProfile
964-
.profile((int) readMember(regexInterop, tRegex, "groupCount",
965-
lazyTranslateInteropExceptionNode.get(this)));
965+
.profile(node, (int) readMember(regexInterop, tRegex, "groupCount",
966+
lazyTranslateInteropExceptionNode.get(node)));
966967
final Region region = new Region(groupCount);
967968

968969
try {
969-
for (int group = 0; loopProfile.inject(group < groupCount); group++) {
970+
for (int group = 0; loopProfile.inject(node, group < groupCount); group++) {
970971
region.beg[group] = RubyMatchData.LAZY;
971972
region.end[group] = RubyMatchData.LAZY;
972-
TruffleSafepoint.poll(this);
973+
TruffleSafepoint.poll(node);
973974
}
974975
} finally {
975-
profileAndReportLoopCount(loopProfile, groupCount);
976+
profileAndReportLoopCount(node, loopProfile, groupCount);
976977
}
977978

978-
return createMatchData(regexp, dupString(string, stringDupNode.get(this)), region, result);
979+
return createMatchData(node, regexp, dupString(string, stringDupNode.get(node)), region, result);
979980
} else {
980981
return nil;
981982
}
@@ -984,13 +985,14 @@ protected Object matchInRegionTRegex(
984985
}
985986
}
986987

987-
private Object fallbackToJoni(RubyRegexp regexp, Object string, RubyEncoding encoding, int fromPos, int toPos,
988+
private static Object fallbackToJoni(Node node, RubyRegexp regexp, Object string, RubyEncoding encoding,
989+
int fromPos, int toPos,
988990
boolean atStart, int startPos, boolean createMatchData, DispatchNode warnOnFallbackNode,
989991
MatchInRegionNode fallbackMatchInRegionNode) {
990-
if (getContext().getOptions().WARN_TRUFFLE_REGEX_MATCH_FALLBACK) {
992+
if (getContext(node).getOptions().WARN_TRUFFLE_REGEX_MATCH_FALLBACK) {
991993

992994
warnOnFallbackNode.call(
993-
getContext().getCoreLibrary().truffleRegexpOperationsModule,
995+
getContext(node).getCoreLibrary().truffleRegexpOperationsModule,
994996
"warn_fallback",
995997
new Object[]{
996998
regexp,
@@ -1006,19 +1008,20 @@ private Object fallbackToJoni(RubyRegexp regexp, Object string, RubyEncoding enc
10061008
.executeMatchInRegion(regexp, string, fromPos, toPos, atStart, startPos, createMatchData);
10071009
}
10081010

1009-
private Object createMatchData(RubyRegexp regexp, Object string, Region region, Object tRegexResult) {
1011+
private static Object createMatchData(Node node, RubyRegexp regexp, Object string, Region region,
1012+
Object tRegexResult) {
10101013
final RubyMatchData matchData = new RubyMatchData(
1011-
coreLibrary().matchDataClass,
1012-
getLanguage().matchDataShape,
1014+
coreLibrary(node).matchDataClass,
1015+
getLanguage(node).matchDataShape,
10131016
regexp,
10141017
string,
10151018
region);
10161019
matchData.tRegexResult = tRegexResult;
1017-
AllocationTracing.trace(matchData, this);
1020+
AllocationTracing.trace(matchData, node);
10181021
return matchData;
10191022
}
10201023

1021-
private Object readMember(InteropLibrary interop, Object receiver, String name,
1024+
private static Object readMember(InteropLibrary interop, Object receiver, String name,
10221025
TranslateInteropExceptionNode translateInteropExceptionNode) {
10231026
try {
10241027
return interop.readMember(receiver, name);
@@ -1027,7 +1030,7 @@ private Object readMember(InteropLibrary interop, Object receiver, String name,
10271030
}
10281031
}
10291032

1030-
private Object invoke(InteropLibrary interop, Object receiver, String member,
1033+
private static Object invoke(InteropLibrary interop, Object receiver, String member,
10311034
TranslateInteropExceptionNode translateInteropExceptionNode, Object... args) {
10321035
try {
10331036
return interop.invokeMember(receiver, member, args);
@@ -1036,7 +1039,7 @@ private Object invoke(InteropLibrary interop, Object receiver, String member,
10361039
}
10371040
}
10381041

1039-
private Object dupString(Object string, DispatchNode stringDupNode) {
1042+
private static Object dupString(Object string, DispatchNode stringDupNode) {
10401043
return stringDupNode.call(string, "dup");
10411044
}
10421045
}

src/main/java/org/truffleruby/language/RubyBaseNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ protected Node getNode() {
122122
return getNode(this);
123123
}
124124

125-
private static Node getNode(Node node) {
125+
protected static Node getNode(Node node) {
126126
boolean adoptable = node != null && node.isAdoptable();
127127
CompilerAsserts.partialEvaluationConstant(adoptable);
128128
if (adoptable) {

0 commit comments

Comments
 (0)