76
76
import com .oracle .truffle .api .nodes .Node ;
77
77
import com .oracle .truffle .api .profiles .BranchProfile ;
78
78
import com .oracle .truffle .api .profiles .ConditionProfile ;
79
+ import com .oracle .truffle .api .profiles .ValueProfile ;
79
80
80
81
/**
81
82
* This node makes sure that the current frame has a filled-in PFrame object with a backref
@@ -317,16 +318,17 @@ public SyncFrameValuesNode(boolean adoptable) {
317
318
318
319
public abstract void execute (VirtualFrame frame , PFrame pyframe , Frame frameToSync );
319
320
320
- @ Specialization (guards = {"hasLocalsStorage(pyFrame, frameToSync)" , "frameToSync.getFrameDescriptor() == cachedFd" , "cachedSlots.length < 32" }, //
321
+ @ Specialization (guards = {"hasLocalsStorage(pyFrame, frameToSync, frameProfile )" , "frameToSync.getFrameDescriptor() == cachedFd" , "cachedSlots.length < 32" }, //
321
322
assumptions = "cachedFd.getVersion()" , //
322
323
limit = "1" )
323
324
@ ExplodeLoop
324
325
static void doLocalsStorageCached (PFrame pyFrame , Frame frameToSync ,
326
+ @ Cached ("createClassProfile()" ) ValueProfile frameProfile ,
325
327
@ Cached ("frameToSync.getFrameDescriptor()" ) FrameDescriptor cachedFd ,
326
328
@ Cached (value = "getSlots(cachedFd)" , dimensions = 1 ) FrameSlot [] cachedSlots ) {
327
329
boolean invalidState = false ;
328
330
LocalsStorage localsStorage = getLocalsStorage (pyFrame );
329
- MaterializedFrame target = localsStorage .getFrame ();
331
+ MaterializedFrame target = frameProfile . profile ( localsStorage .getFrame () );
330
332
assert cachedFd == target .getFrameDescriptor ();
331
333
332
334
for (int i = 0 ; i < cachedSlots .length ; i ++) {
@@ -390,15 +392,16 @@ static void doLocalsStorageCached(PFrame pyFrame, Frame frameToSync,
390
392
}
391
393
}
392
394
393
- @ Specialization (guards = {"hasLocalsStorage(pyFrame, frameToSync)" , "frameToSync.getFrameDescriptor() == cachedFd" }, //
395
+ @ Specialization (guards = {"hasLocalsStorage(pyFrame, frameToSync, frameProfile )" , "frameToSync.getFrameDescriptor() == cachedFd" }, //
394
396
assumptions = "cachedFd.getVersion()" , //
395
397
limit = "1" )
396
398
static void doLocalsStorageLoop (PFrame pyFrame , Frame frameToSync ,
399
+ @ Cached ("createClassProfile()" ) ValueProfile frameProfile ,
397
400
@ Cached ("frameToSync.getFrameDescriptor()" ) FrameDescriptor cachedFd ,
398
401
@ Cached (value = "getSlots(cachedFd)" , dimensions = 1 ) FrameSlot [] cachedSlots ) {
399
402
boolean invalidState = false ;
400
403
LocalsStorage localsStorage = getLocalsStorage (pyFrame );
401
- MaterializedFrame target = localsStorage .getFrame ();
404
+ MaterializedFrame target = frameProfile . profile ( localsStorage .getFrame () );
402
405
assert cachedFd == target .getFrameDescriptor ();
403
406
404
407
for (int i = 0 ; i < cachedSlots .length ; i ++) {
@@ -462,13 +465,14 @@ static void doLocalsStorageLoop(PFrame pyFrame, Frame frameToSync,
462
465
}
463
466
}
464
467
465
- @ Specialization (guards = "hasLocalsStorage(pyFrame, frameToSync)" , replaces = {"doLocalsStorageCached" , "doLocalsStorageLoop" })
466
- static void doLocalsStorageUncached (PFrame pyFrame , Frame frameToSync ) {
468
+ @ Specialization (guards = "hasLocalsStorage(pyFrame, frameToSync, frameProfile)" , replaces = {"doLocalsStorageCached" , "doLocalsStorageLoop" })
469
+ static void doLocalsStorageUncached (PFrame pyFrame , Frame frameToSync ,
470
+ @ Cached ("createClassProfile()" ) ValueProfile frameProfile ) {
467
471
FrameDescriptor fd = frameToSync .getFrameDescriptor ();
468
472
FrameSlot [] cachedSlots = getSlots (fd );
469
473
try {
470
474
LocalsStorage localsStorage = getLocalsStorage (pyFrame );
471
- MaterializedFrame target = localsStorage .getFrame ();
475
+ MaterializedFrame target = frameProfile . profile ( localsStorage .getFrame () );
472
476
assert fd == target .getFrameDescriptor ();
473
477
474
478
for (int i = 0 ; i < cachedSlots .length ; i ++) {
@@ -615,9 +619,10 @@ static void doGenericDict(VirtualFrame frame, PFrame pyFrame, Frame frameToSync)
615
619
}
616
620
}
617
621
618
- @ Specialization (guards = "isCustomLocalsObject(pyFrame, frameToSync)" )
622
+ @ Specialization (guards = "isCustomLocalsObject(pyFrame, frameToSync, frameProfile )" )
619
623
@ SuppressWarnings ("unused" )
620
- static void doCustomLocalsObject (PFrame pyFrame , Frame frameToSync ) {
624
+ static void doCustomLocalsObject (PFrame pyFrame , Frame frameToSync ,
625
+ @ Cached ("createClassProfile()" ) ValueProfile frameProfile ) {
621
626
// nothing to do; we already worked on the custom object
622
627
}
623
628
@@ -639,9 +644,9 @@ protected static ConditionProfile[] getProfiles(int n) {
639
644
* same frame descriptor as the frame to synchronize. That means, the dict represents
640
645
* unmodified set of frame values of the frame to sync.
641
646
*/
642
- protected static boolean hasLocalsStorage (PFrame pyFrame , Frame frameToSync ) {
647
+ protected static boolean hasLocalsStorage (PFrame pyFrame , Frame frameToSync , ValueProfile frameProfile ) {
643
648
Object localsObject = pyFrame .getLocalsDict ();
644
- return localsObject instanceof PDict && getFd (((PDict ) localsObject ).getDictStorage ()) == frameToSync .getFrameDescriptor ();
649
+ return localsObject instanceof PDict && getFd (((PDict ) localsObject ).getDictStorage (), frameProfile ) == frameToSync .getFrameDescriptor ();
645
650
}
646
651
647
652
protected static boolean isDictWithCustomStorage (PFrame pyFrame ) {
@@ -650,17 +655,17 @@ protected static boolean isDictWithCustomStorage(PFrame pyFrame) {
650
655
return PythonObjectLibrary .getUncached ().getLazyPythonClass (localsObject ) == PythonBuiltinClassType .PDict ;
651
656
}
652
657
653
- protected static boolean isCustomLocalsObject (PFrame pyFrame , Frame frameToSync ) {
654
- return !hasLocalsStorage (pyFrame , frameToSync );
658
+ protected static boolean isCustomLocalsObject (PFrame pyFrame , Frame frameToSync , ValueProfile frameProfile ) {
659
+ return !hasLocalsStorage (pyFrame , frameToSync , frameProfile );
655
660
}
656
661
657
662
protected static LocalsStorage getLocalsStorage (PFrame pyFrame ) {
658
663
return (LocalsStorage ) ((PDict ) pyFrame .getLocalsDict ()).getDictStorage ();
659
664
}
660
665
661
- private static FrameDescriptor getFd (HashingStorage storage ) {
666
+ private static FrameDescriptor getFd (HashingStorage storage , ValueProfile frameProfile ) {
662
667
if (storage instanceof LocalsStorage ) {
663
- return (( LocalsStorage ) storage ).getFrame ().getFrameDescriptor ();
668
+ return frameProfile . profile ((( LocalsStorage ) storage ).getFrame () ).getFrameDescriptor ();
664
669
}
665
670
return null ;
666
671
}
0 commit comments