35
35
import com .oracle .truffle .api .library .CachedLibrary ;
36
36
import com .oracle .truffle .api .profiles .InlinedBranchProfile ;
37
37
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 ;
40
40
import com .oracle .truffle .api .strings .TruffleString ;
41
41
import com .oracle .truffle .api .strings .TruffleString .AsTruffleStringNode ;
42
42
import org .joni .Matcher ;
85
85
import com .oracle .truffle .api .frame .VirtualFrame ;
86
86
import com .oracle .truffle .api .nodes .ExplodeLoop ;
87
87
import com .oracle .truffle .api .nodes .Node ;
88
- import com .oracle .truffle .api .profiles .ConditionProfile ;
89
88
import org .truffleruby .language .dispatch .LazyDispatchNode ;
90
89
import org .truffleruby .language .library .RubyStringLibrary ;
91
90
import org .truffleruby .language .objects .AllocationTracing ;
@@ -870,7 +869,7 @@ public abstract static class MatchInRegionTRegexNode extends PrimitiveArrayArgum
870
869
871
870
872
871
@ Specialization (guards = "libString.isRubyString(string)" , limit = "1" )
873
- protected Object matchInRegionTRegex (
872
+ protected static Object matchInRegionTRegex (
874
873
RubyRegexp regexp ,
875
874
Object string ,
876
875
int fromPos ,
@@ -879,35 +878,37 @@ protected Object matchInRegionTRegex(
879
878
int startPos ,
880
879
boolean createMatchData ,
881
880
@ 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 ,
888
887
@ CachedLibrary (limit = "getInteropCacheLimit()" ) InteropLibrary regexInterop ,
889
888
@ CachedLibrary (limit = "getInteropCacheLimit()" ) InteropLibrary resultInterop ,
890
889
@ Cached PrepareRegexpEncodingNode prepareRegexpEncodingNode ,
891
890
@ Cached TRegexCompileNode tRegexCompileNode ,
892
891
@ Cached RubyStringLibrary libString ,
893
- @ Cached ( inline = false ) IntValueProfile groupCountProfile ,
892
+ @ Cached InlinedIntValueProfile groupCountProfile ,
894
893
@ Cached LazyDispatchNode warnOnFallbackNode ,
895
894
@ Cached LazyDispatchNode stringDupNode ,
896
895
@ Cached LazyTranslateInteropExceptionNode lazyTranslateInteropExceptionNode ,
897
896
@ Cached LazyMatchInRegionNode fallbackMatchInRegionNode ,
898
- @ Cached LazyTruffleStringSubstringByteIndexNode substringByteIndexNode ) {
897
+ @ Cached LazyTruffleStringSubstringByteIndexNode substringByteIndexNode ,
898
+ @ Bind ("this" ) Node node ) {
899
899
final Object tRegex ;
900
900
final RubyEncoding negotiatedEncoding = prepareRegexpEncodingNode .executePrepare (regexp , string );
901
901
var tstring = switchEncodingNode .execute (libString .getTString (string ), negotiatedEncoding .tencoding );
902
902
final int byteLength = tstring .byteLength (negotiatedEncoding .tencoding );
903
903
904
904
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 (
907
907
regexp ,
908
908
atStart ,
909
909
negotiatedEncoding )) == nil )) {
910
910
return fallbackToJoni (
911
+ node ,
911
912
regexp ,
912
913
string ,
913
914
negotiatedEncoding ,
@@ -916,30 +917,30 @@ protected Object matchInRegionTRegex(
916
917
atStart ,
917
918
startPos ,
918
919
createMatchData ,
919
- warnOnFallbackNode .get (this ),
920
- fallbackMatchInRegionNode .get (this ));
920
+ warnOnFallbackNode .get (node ),
921
+ fallbackMatchInRegionNode .get (node ));
921
922
}
922
923
923
- if (getContext ().getOptions ().REGEXP_INSTRUMENT_MATCH ) {
924
+ if (getContext (node ).getOptions ().REGEXP_INSTRUMENT_MATCH ) {
924
925
TruffleRegexpNodes .instrumentMatch (
925
926
MATCHED_REGEXPS_TREGEX ,
926
927
regexp ,
927
928
string ,
928
929
atStart ,
929
- getContext ().getOptions ().REGEXP_INSTRUMENT_MATCH_DETAILED );
930
+ getContext (node ).getOptions ().REGEXP_INSTRUMENT_MATCH_DETAILED );
930
931
}
931
932
932
933
int fromIndex = fromPos ;
933
934
final TruffleString tstringToMatch ;
934
935
final String execMethod ;
935
936
936
- if (createMatchDataProfile .profile (createMatchData )) {
937
- if (startPosNotZeroProfile .profile (startPos > 0 )) {
937
+ if (createMatchDataProfile .profile (node , createMatchData )) {
938
+ if (startPosNotZeroProfile .profile (node , startPos > 0 )) {
938
939
// If startPos != 0, then fromPos == startPos.
939
940
assert fromPos == startPos ;
940
941
fromIndex = 0 ;
941
942
942
- tstringToMatch = substringByteIndexNode .get (this ).execute (tstring , startPos , toPos - startPos ,
943
+ tstringToMatch = substringByteIndexNode .get (node ).execute (tstring , startPos , toPos - startPos ,
943
944
negotiatedEncoding .tencoding , true );
944
945
} else {
945
946
tstringToMatch = tstring ;
@@ -952,30 +953,30 @@ protected Object matchInRegionTRegex(
952
953
tstringToMatch = tstring ;
953
954
execMethod = "execBoolean" ;
954
955
}
955
- final Object result = invoke (regexInterop , tRegex , execMethod , lazyTranslateInteropExceptionNode .get (this ),
956
+ final Object result = invoke (regexInterop , tRegex , execMethod , lazyTranslateInteropExceptionNode .get (node ),
956
957
tstringToMatch , fromIndex );
957
958
958
- if (createMatchDataProfile .profile (createMatchData )) {
959
+ if (createMatchDataProfile .profile (node , createMatchData )) {
959
960
final boolean isMatch = (boolean ) readMember (resultInterop , result , "isMatch" ,
960
- lazyTranslateInteropExceptionNode .get (this ));
961
+ lazyTranslateInteropExceptionNode .get (node ));
961
962
962
- if (matchFoundProfile .profile (isMatch )) {
963
+ if (matchFoundProfile .profile (node , isMatch )) {
963
964
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 )));
966
967
final Region region = new Region (groupCount );
967
968
968
969
try {
969
- for (int group = 0 ; loopProfile .inject (group < groupCount ); group ++) {
970
+ for (int group = 0 ; loopProfile .inject (node , group < groupCount ); group ++) {
970
971
region .beg [group ] = RubyMatchData .LAZY ;
971
972
region .end [group ] = RubyMatchData .LAZY ;
972
- TruffleSafepoint .poll (this );
973
+ TruffleSafepoint .poll (node );
973
974
}
974
975
} finally {
975
- profileAndReportLoopCount (loopProfile , groupCount );
976
+ profileAndReportLoopCount (node , loopProfile , groupCount );
976
977
}
977
978
978
- return createMatchData (regexp , dupString (string , stringDupNode .get (this )), region , result );
979
+ return createMatchData (node , regexp , dupString (string , stringDupNode .get (node )), region , result );
979
980
} else {
980
981
return nil ;
981
982
}
@@ -984,13 +985,14 @@ protected Object matchInRegionTRegex(
984
985
}
985
986
}
986
987
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 ,
988
990
boolean atStart , int startPos , boolean createMatchData , DispatchNode warnOnFallbackNode ,
989
991
MatchInRegionNode fallbackMatchInRegionNode ) {
990
- if (getContext ().getOptions ().WARN_TRUFFLE_REGEX_MATCH_FALLBACK ) {
992
+ if (getContext (node ).getOptions ().WARN_TRUFFLE_REGEX_MATCH_FALLBACK ) {
991
993
992
994
warnOnFallbackNode .call (
993
- getContext ().getCoreLibrary ().truffleRegexpOperationsModule ,
995
+ getContext (node ).getCoreLibrary ().truffleRegexpOperationsModule ,
994
996
"warn_fallback" ,
995
997
new Object []{
996
998
regexp ,
@@ -1006,19 +1008,20 @@ private Object fallbackToJoni(RubyRegexp regexp, Object string, RubyEncoding enc
1006
1008
.executeMatchInRegion (regexp , string , fromPos , toPos , atStart , startPos , createMatchData );
1007
1009
}
1008
1010
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 ) {
1010
1013
final RubyMatchData matchData = new RubyMatchData (
1011
- coreLibrary ().matchDataClass ,
1012
- getLanguage ().matchDataShape ,
1014
+ coreLibrary (node ).matchDataClass ,
1015
+ getLanguage (node ).matchDataShape ,
1013
1016
regexp ,
1014
1017
string ,
1015
1018
region );
1016
1019
matchData .tRegexResult = tRegexResult ;
1017
- AllocationTracing .trace (matchData , this );
1020
+ AllocationTracing .trace (matchData , node );
1018
1021
return matchData ;
1019
1022
}
1020
1023
1021
- private Object readMember (InteropLibrary interop , Object receiver , String name ,
1024
+ private static Object readMember (InteropLibrary interop , Object receiver , String name ,
1022
1025
TranslateInteropExceptionNode translateInteropExceptionNode ) {
1023
1026
try {
1024
1027
return interop .readMember (receiver , name );
@@ -1027,7 +1030,7 @@ private Object readMember(InteropLibrary interop, Object receiver, String name,
1027
1030
}
1028
1031
}
1029
1032
1030
- private Object invoke (InteropLibrary interop , Object receiver , String member ,
1033
+ private static Object invoke (InteropLibrary interop , Object receiver , String member ,
1031
1034
TranslateInteropExceptionNode translateInteropExceptionNode , Object ... args ) {
1032
1035
try {
1033
1036
return interop .invokeMember (receiver , member , args );
@@ -1036,7 +1039,7 @@ private Object invoke(InteropLibrary interop, Object receiver, String member,
1036
1039
}
1037
1040
}
1038
1041
1039
- private Object dupString (Object string , DispatchNode stringDupNode ) {
1042
+ private static Object dupString (Object string , DispatchNode stringDupNode ) {
1040
1043
return stringDupNode .call (string , "dup" );
1041
1044
}
1042
1045
}
0 commit comments