26
26
package jdk .graal .compiler .hotspot .replacements .arraycopy ;
27
27
28
28
import static jdk .graal .compiler .hotspot .GraalHotSpotVMConfig .INJECTED_VMCONFIG ;
29
+ import static jdk .graal .compiler .nodeinfo .NodeCycles .CYCLES_UNKNOWN ;
30
+ import static jdk .graal .compiler .nodeinfo .NodeSize .SIZE_UNKNOWN ;
29
31
import static jdk .graal .compiler .nodes .extended .BranchProbabilityNode .FREQUENT_PROBABILITY ;
30
32
import static jdk .graal .compiler .nodes .extended .BranchProbabilityNode .LIKELY_PROBABILITY ;
31
33
import static jdk .graal .compiler .nodes .extended .BranchProbabilityNode .SLOW_PATH_PROBABILITY ;
32
34
import static jdk .graal .compiler .nodes .extended .BranchProbabilityNode .probability ;
35
+ import static jdk .graal .compiler .replacements .SnippetTemplate .AbstractTemplates .findMethod ;
33
36
37
+ import org .graalvm .word .LocationIdentity ;
38
+
39
+ import jdk .graal .compiler .core .common .type .StampFactory ;
40
+ import jdk .graal .compiler .core .common .type .StampPair ;
41
+ import jdk .graal .compiler .graph .NodeClass ;
42
+ import jdk .graal .compiler .hotspot .nodes .HotSpotDirectCallTargetNode ;
34
43
import jdk .graal .compiler .hotspot .replacements .HotSpotReplacementsUtil ;
35
44
import jdk .graal .compiler .hotspot .word .KlassPointer ;
45
+ import jdk .graal .compiler .nodeinfo .InputType ;
46
+ import jdk .graal .compiler .nodeinfo .NodeInfo ;
47
+ import jdk .graal .compiler .nodes .CallTargetNode ;
48
+ import jdk .graal .compiler .nodes .InvokeWithExceptionNode ;
36
49
import jdk .graal .compiler .nodes .PiNode ;
37
50
import jdk .graal .compiler .nodes .SnippetAnchorNode ;
51
+ import jdk .graal .compiler .nodes .StructuredGraph ;
52
+ import jdk .graal .compiler .nodes .ValueNode ;
53
+ import jdk .graal .compiler .nodes .spi .Lowerable ;
54
+ import jdk .graal .compiler .nodes .spi .LoweringTool ;
38
55
import jdk .graal .compiler .replacements .arraycopy .ArrayCopyCallNode ;
39
56
import jdk .graal .compiler .replacements .arraycopy .ArrayCopySnippets ;
57
+ import jdk .graal .compiler .replacements .nodes .BasicArrayCopyNode ;
40
58
import jdk .graal .compiler .word .Word ;
41
- import org .graalvm .word .LocationIdentity ;
42
-
59
+ import jdk .vm .ci .hotspot .HotSpotCallingConventionType ;
43
60
import jdk .vm .ci .meta .JavaKind ;
44
61
45
62
public class HotSpotArraycopySnippets extends ArrayCopySnippets {
@@ -106,7 +123,8 @@ protected void doCheckcastArraycopySnippet(Object src, int srcPos, Object dest,
106
123
}
107
124
108
125
@ Override
109
- protected void doGenericArraycopySnippet (Object src , int srcPos , Object dest , int destPos , int length , JavaKind elementKind , LocationIdentity arrayLocation , Counters counters ) {
126
+ protected void doGenericArraycopySnippet (Object src , int srcPos , Object dest , int destPos , int length , JavaKind elementKind , LocationIdentity arrayLocation , Counters counters ,
127
+ boolean exceptionSeen ) {
110
128
counters .genericArraycopyDifferentTypeCounter .inc ();
111
129
counters .genericArraycopyDifferentTypeCopiedCounter .add (length );
112
130
int copiedElements = GenericArrayCopyCallNode .genericArraycopy (src , srcPos , dest , destPos , length );
@@ -116,7 +134,49 @@ protected void doGenericArraycopySnippet(Object src, int srcPos, Object dest, in
116
134
* elements (xor'd with -1).
117
135
*/
118
136
copiedElements ^= -1 ;
119
- System .arraycopy (src , srcPos + copiedElements , dest , destPos + copiedElements , length - copiedElements );
137
+ if (exceptionSeen ) {
138
+ HotSpotArrayCopyCallWithExceptionNode .arraycopyWithException (src , srcPos + copiedElements , dest , destPos + copiedElements , length - copiedElements , elementKind );
139
+ } else {
140
+ System .arraycopy (src , srcPos + copiedElements , dest , destPos + copiedElements , length - copiedElements );
141
+ }
142
+ }
143
+ }
144
+
145
+ @ Override
146
+ protected void doFailingArraycopySnippet (Object src , int srcPos , Object dest , int destPos , int length , JavaKind elementKind , Counters counters ) {
147
+ // Call System.arraycopy but have an exception edge for the call.
148
+ HotSpotArrayCopyCallWithExceptionNode .arraycopyWithException (src , srcPos , dest , destPos , length , elementKind );
149
+ }
150
+
151
+ @ NodeInfo (allowedUsageTypes = {InputType .Memory , InputType .Value }, cycles = CYCLES_UNKNOWN , size = SIZE_UNKNOWN )
152
+ public static final class HotSpotArrayCopyCallWithExceptionNode extends BasicArrayCopyNode implements Lowerable {
153
+ public static final NodeClass <HotSpotArrayCopyCallWithExceptionNode > TYPE = NodeClass .create (HotSpotArrayCopyCallWithExceptionNode .class );
154
+
155
+ public HotSpotArrayCopyCallWithExceptionNode (ValueNode src , ValueNode srcPos , ValueNode dest , ValueNode destPos , ValueNode length , JavaKind elementKind ) {
156
+ super (TYPE , src , srcPos , dest , destPos , length , elementKind );
120
157
}
158
+
159
+ @ Override
160
+ public void lower (LoweringTool tool ) {
161
+ // Based on SubstrateGenericArrayCopyCallNode.
162
+ if (graph ().getGuardsStage ().areFrameStatesAtDeopts ()) {
163
+ StructuredGraph graph = graph ();
164
+ ValueNode [] args = new ValueNode []{getSource (), getSourcePosition (), getDestination (), getDestinationPosition (), getLength ()};
165
+ var returnStamp = StampPair .create (StampFactory .forVoid (), StampFactory .forVoid ());
166
+ var target = findMethod (tool .getMetaAccess (), System .class , "arraycopy" );
167
+ var signature = target .getSignature ().toParameterTypes (null );
168
+ var callType = HotSpotCallingConventionType .JavaCall ;
169
+ var invokeKind = CallTargetNode .InvokeKind .Static ;
170
+ CallTargetNode ct = graph .add (new HotSpotDirectCallTargetNode (args , returnStamp , signature , target , callType , invokeKind ));
171
+
172
+ InvokeWithExceptionNode call = graph .add (new InvokeWithExceptionNode (ct , null , bci ()));
173
+ call .setStateAfter (stateAfter ());
174
+ call .setStateDuring (stateDuring ());
175
+ graph .replaceWithExceptionSplit (this , call );
176
+ }
177
+ }
178
+
179
+ @ NodeIntrinsic
180
+ public static native int arraycopyWithException (Object src , int srcPos , Object dest , int destPos , int length , @ ConstantNodeParameter JavaKind elementKind );
121
181
}
122
182
}
0 commit comments