139
139
import com .oracle .truffle .api .nodes .IndirectCallNode ;
140
140
import com .oracle .truffle .api .nodes .Node ;
141
141
import com .oracle .truffle .api .nodes .RootNode ;
142
- import com .oracle .truffle .api .profiles .BranchProfile ;
143
- import com .oracle .truffle .api .profiles .ConditionProfile ;
144
142
import com .oracle .truffle .api .source .SourceSection ;
145
143
import org .truffleruby .parser .RubySource ;
146
144
@@ -1960,14 +1958,16 @@ public abstract static class RBSprintfFormatNode extends CoreMethodArrayArgument
1960
1958
@ Specialization (
1961
1959
guards = {
1962
1960
"libFormat.isRubyString(format)" ,
1963
- "equalNode.execute(libFormat, format, cachedFormat, cachedEncoding)" },
1961
+ "equalNode.execute(node, libFormat, format, cachedFormat, cachedEncoding)" },
1964
1962
limit = "2" )
1965
- protected Object typesCached (VirtualFrame frame , Object format ,
1963
+
1964
+ protected static Object typesCached (VirtualFrame frame , Object format ,
1966
1965
@ Cached @ Shared RubyStringLibrary libFormat ,
1967
1966
@ Cached ("asTruffleStringUncached(format)" ) TruffleString cachedFormat ,
1968
1967
@ Cached ("libFormat.getEncoding(format)" ) RubyEncoding cachedEncoding ,
1969
1968
@ Cached ("compileArgTypes(cachedFormat, cachedEncoding, byteArrayNode)" ) RubyArray cachedTypes ,
1970
- @ Cached StringHelperNodes .EqualSameEncodingNode equalNode ) {
1969
+ @ Cached StringHelperNodes .EqualSameEncodingNode equalNode ,
1970
+ @ Bind ("this" ) Node node ) {
1971
1971
return cachedTypes ;
1972
1972
}
1973
1973
@@ -1993,41 +1993,43 @@ protected RubyArray compileArgTypes(AbstractTruffleString format, RubyEncoding e
1993
1993
@ ReportPolymorphism
1994
1994
public abstract static class RBSprintfNode extends CoreMethodArrayArgumentsNode {
1995
1995
1996
- @ Child private TruffleString .FromByteArrayNode fromByteArrayNode ;
1997
-
1998
- private final BranchProfile exceptionProfile = BranchProfile .create ();
1999
- private final ConditionProfile resizeProfile = ConditionProfile .create ();
2000
-
2001
1996
@ Specialization (
2002
1997
guards = {
2003
1998
"libFormat.isRubyString(format)" ,
2004
- "equalNode.execute(libFormat, format, cachedFormat, cachedEncoding)" },
1999
+ "equalNode.execute(node, libFormat, format, cachedFormat, cachedEncoding)" },
2005
2000
limit = "2" )
2006
- protected RubyString formatCached (Object format , Object stringReader , RubyArray argArray ,
2001
+ protected static RubyString formatCached (Object format , Object stringReader , RubyArray argArray ,
2007
2002
@ Cached @ Shared ArrayToObjectArrayNode arrayToObjectArrayNode ,
2008
2003
@ Cached @ Shared RubyStringLibrary libFormat ,
2004
+ @ Cached @ Shared InlinedBranchProfile exceptionProfile ,
2005
+ @ Cached @ Shared InlinedConditionProfile resizeProfile ,
2006
+ @ Cached @ Shared TruffleString .FromByteArrayNode fromByteArrayNode ,
2009
2007
@ Cached ("asTruffleStringUncached(format)" ) TruffleString cachedFormat ,
2010
2008
@ Cached ("libFormat.getEncoding(format)" ) RubyEncoding cachedEncoding ,
2011
2009
@ Cached ("cachedFormat.byteLength(cachedEncoding.tencoding)" ) int cachedFormatLength ,
2012
2010
@ Cached ("create(compileFormat(cachedFormat, cachedEncoding, stringReader))" ) DirectCallNode formatNode ,
2013
- @ Cached StringHelperNodes .EqualSameEncodingNode equalNode ) {
2011
+ @ Cached StringHelperNodes .EqualSameEncodingNode equalNode ,
2012
+ @ Bind ("this" ) Node node ) {
2014
2013
final BytesResult result ;
2015
2014
final Object [] arguments = arrayToObjectArrayNode .executeToObjectArray (argArray );
2016
2015
try {
2017
2016
result = (BytesResult ) formatNode .call (new Object []{ arguments , arguments .length , null });
2018
2017
} catch (FormatException e ) {
2019
- exceptionProfile .enter ();
2020
- throw FormatExceptionTranslator .translate (getContext (), this , e );
2018
+ exceptionProfile .enter (node );
2019
+ throw FormatExceptionTranslator .translate (getContext (node ), node , e );
2021
2020
}
2022
2021
2023
- return finishFormat (cachedFormatLength , result );
2022
+ return finishFormat (node , cachedFormatLength , result , resizeProfile , fromByteArrayNode );
2024
2023
}
2025
2024
2026
2025
@ Specialization (
2027
2026
guards = "libFormat.isRubyString(format)" ,
2028
2027
replaces = "formatCached" , limit = "1" )
2029
2028
protected RubyString formatUncached (Object format , Object stringReader , RubyArray argArray ,
2030
2029
@ Cached IndirectCallNode formatNode ,
2030
+ @ Cached @ Shared InlinedBranchProfile exceptionProfile ,
2031
+ @ Cached @ Shared InlinedConditionProfile resizeProfile ,
2032
+ @ Cached @ Shared TruffleString .FromByteArrayNode fromByteArrayNode ,
2031
2033
@ Cached @ Shared ArrayToObjectArrayNode arrayToObjectArrayNode ,
2032
2034
@ Cached @ Shared RubyStringLibrary libFormat ) {
2033
2035
var tstring = libFormat .getTString (format );
@@ -2038,26 +2040,23 @@ protected RubyString formatUncached(Object format, Object stringReader, RubyArra
2038
2040
result = (BytesResult ) formatNode .call (compileFormat (tstring , encoding , stringReader ),
2039
2041
new Object []{ arguments , arguments .length , null });
2040
2042
} catch (FormatException e ) {
2041
- exceptionProfile .enter ();
2043
+ exceptionProfile .enter (this );
2042
2044
throw FormatExceptionTranslator .translate (getContext (), this , e );
2043
2045
}
2044
2046
2045
- return finishFormat (tstring .byteLength (encoding .tencoding ), result );
2047
+ return finishFormat (this , tstring .byteLength (encoding .tencoding ), result , resizeProfile , fromByteArrayNode );
2046
2048
}
2047
2049
2048
- private RubyString finishFormat (int formatLength , BytesResult result ) {
2050
+ private static RubyString finishFormat (Node node , int formatLength , BytesResult result ,
2051
+ InlinedConditionProfile resizeProfile , TruffleString .FromByteArrayNode fromByteArrayNode ) {
2049
2052
byte [] bytes = result .getOutput ();
2050
2053
2051
- if (resizeProfile .profile (bytes .length != result .getOutputLength ())) {
2054
+ if (resizeProfile .profile (node , bytes .length != result .getOutputLength ())) {
2052
2055
bytes = Arrays .copyOf (bytes , result .getOutputLength ());
2053
2056
}
2054
2057
2055
- if (fromByteArrayNode == null ) {
2056
- CompilerDirectives .transferToInterpreterAndInvalidate ();
2057
- fromByteArrayNode = insert (TruffleString .FromByteArrayNode .create ());
2058
- }
2059
-
2060
- return createString (fromByteArrayNode , bytes , result .getEncoding ().getEncodingForLength (formatLength ));
2058
+ return createString (node , fromByteArrayNode , bytes ,
2059
+ result .getEncoding ().getEncodingForLength (formatLength ));
2061
2060
}
2062
2061
2063
2062
@ TruffleBoundary
0 commit comments