89
89
import jdk .graal .compiler .nodes .ConstantNode ;
90
90
import jdk .graal .compiler .nodes .EndNode ;
91
91
import jdk .graal .compiler .nodes .FieldLocationIdentity ;
92
+ import jdk .graal .compiler .nodes .FixedGuardNode ;
92
93
import jdk .graal .compiler .nodes .IfNode ;
93
94
import jdk .graal .compiler .nodes .LogicNode ;
94
95
import jdk .graal .compiler .nodes .MergeNode ;
169
170
import jdk .vm .ci .code .Architecture ;
170
171
import jdk .vm .ci .code .TargetDescription ;
171
172
import jdk .vm .ci .meta .ConstantReflectionProvider ;
173
+ import jdk .vm .ci .meta .DeoptimizationAction ;
174
+ import jdk .vm .ci .meta .DeoptimizationReason ;
172
175
import jdk .vm .ci .meta .JavaKind ;
173
176
import jdk .vm .ci .meta .MetaAccessProvider ;
174
177
import jdk .vm .ci .meta .ResolvedJavaField ;
@@ -244,7 +247,7 @@ public void run() {
244
247
registerBigIntegerPlugins (invocationPlugins , config , replacements );
245
248
registerSHAPlugins (invocationPlugins , config , replacements );
246
249
registerBase64Plugins (invocationPlugins , config , metaAccess , replacements );
247
- registerUnsafePlugins (invocationPlugins , replacements );
250
+ registerUnsafePlugins (invocationPlugins , replacements , config );
248
251
StandardGraphBuilderPlugins .registerInvocationPlugins (snippetReflection , invocationPlugins , replacements , true , false , true , graalRuntime .getHostProviders ().getLowerer ());
249
252
registerArrayPlugins (invocationPlugins , replacements , config );
250
253
registerStringPlugins (invocationPlugins , replacements , wordTypes , foreignCalls , config );
@@ -479,7 +482,7 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec
479
482
});
480
483
}
481
484
482
- private static void registerUnsafePlugins (InvocationPlugins plugins , Replacements replacements ) {
485
+ private static void registerUnsafePlugins (InvocationPlugins plugins , Replacements replacements , GraalHotSpotVMConfig config ) {
483
486
Registration r = new Registration (plugins , "jdk.internal.misc.Unsafe" , replacements );
484
487
r .register (new InvocationPlugin ("copyMemory0" , Receiver .class , Object .class , long .class , Object .class , long .class , long .class ) {
485
488
@ Override
@@ -492,6 +495,19 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec
492
495
r .register (new InvocationPlugin ("allocateInstance" , Receiver .class , Class .class ) {
493
496
@ Override
494
497
public boolean apply (GraphBuilderContext b , ResolvedJavaMethod targetMethod , Receiver unsafe , ValueNode clazz ) {
498
+ if (b .getGraph ().getProfilingInfo () != null && b .getGraph ().getProfilingInfo ().getDeoptimizationCount (DeoptimizationReason .RuntimeConstraint ) > 20 ) {
499
+ // Heuristic to prevent deoptimization loops.
500
+ return false ;
501
+ }
502
+ if (config .shouldNotifyObjectAllocAddress != 0 ) {
503
+ try (HotSpotInvocationPluginHelper helper = new HotSpotInvocationPluginHelper (b , targetMethod , config )) {
504
+ OffsetAddressNode address = OffsetAddressNode .create (helper .asWord (config .shouldNotifyObjectAllocAddress ));
505
+ ValueNode shouldPostVMObjectAlloc = b .add (new JavaReadNode (JavaKind .Int , address , LocationIdentity .ANY_LOCATION , BarrierType .NONE , MemoryOrderMode .PLAIN , false ));
506
+ LogicNode testShouldPostVMObjectAlloc = IntegerEqualsNode .create (shouldPostVMObjectAlloc , ConstantNode .forInt (0 ), NodeView .DEFAULT );
507
+ FixedGuardNode guard = new FixedGuardNode (testShouldPostVMObjectAlloc , DeoptimizationReason .RuntimeConstraint , DeoptimizationAction .InvalidateRecompile );
508
+ b .add (guard );
509
+ }
510
+ }
495
511
/* Emits a null-check for the otherwise unused receiver. */
496
512
unsafe .get (true );
497
513
/*
0 commit comments