Skip to content

Commit e48f1b1

Browse files
committed
use profiles for frame type in MaterializeFrameNode
1 parent ee38db2 commit e48f1b1

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/MaterializeFrameNode.java

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
import com.oracle.truffle.api.nodes.Node;
7777
import com.oracle.truffle.api.profiles.BranchProfile;
7878
import com.oracle.truffle.api.profiles.ConditionProfile;
79+
import com.oracle.truffle.api.profiles.ValueProfile;
7980

8081
/**
8182
* 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) {
317318

318319
public abstract void execute(VirtualFrame frame, PFrame pyframe, Frame frameToSync);
319320

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"}, //
321322
assumptions = "cachedFd.getVersion()", //
322323
limit = "1")
323324
@ExplodeLoop
324325
static void doLocalsStorageCached(PFrame pyFrame, Frame frameToSync,
326+
@Cached("createClassProfile()") ValueProfile frameProfile,
325327
@Cached("frameToSync.getFrameDescriptor()") FrameDescriptor cachedFd,
326328
@Cached(value = "getSlots(cachedFd)", dimensions = 1) FrameSlot[] cachedSlots) {
327329
boolean invalidState = false;
328330
LocalsStorage localsStorage = getLocalsStorage(pyFrame);
329-
MaterializedFrame target = localsStorage.getFrame();
331+
MaterializedFrame target = frameProfile.profile(localsStorage.getFrame());
330332
assert cachedFd == target.getFrameDescriptor();
331333

332334
for (int i = 0; i < cachedSlots.length; i++) {
@@ -390,15 +392,16 @@ static void doLocalsStorageCached(PFrame pyFrame, Frame frameToSync,
390392
}
391393
}
392394

393-
@Specialization(guards = {"hasLocalsStorage(pyFrame, frameToSync)", "frameToSync.getFrameDescriptor() == cachedFd"}, //
395+
@Specialization(guards = {"hasLocalsStorage(pyFrame, frameToSync, frameProfile)", "frameToSync.getFrameDescriptor() == cachedFd"}, //
394396
assumptions = "cachedFd.getVersion()", //
395397
limit = "1")
396398
static void doLocalsStorageLoop(PFrame pyFrame, Frame frameToSync,
399+
@Cached("createClassProfile()") ValueProfile frameProfile,
397400
@Cached("frameToSync.getFrameDescriptor()") FrameDescriptor cachedFd,
398401
@Cached(value = "getSlots(cachedFd)", dimensions = 1) FrameSlot[] cachedSlots) {
399402
boolean invalidState = false;
400403
LocalsStorage localsStorage = getLocalsStorage(pyFrame);
401-
MaterializedFrame target = localsStorage.getFrame();
404+
MaterializedFrame target = frameProfile.profile(localsStorage.getFrame());
402405
assert cachedFd == target.getFrameDescriptor();
403406

404407
for (int i = 0; i < cachedSlots.length; i++) {
@@ -462,13 +465,14 @@ static void doLocalsStorageLoop(PFrame pyFrame, Frame frameToSync,
462465
}
463466
}
464467

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) {
467471
FrameDescriptor fd = frameToSync.getFrameDescriptor();
468472
FrameSlot[] cachedSlots = getSlots(fd);
469473
try {
470474
LocalsStorage localsStorage = getLocalsStorage(pyFrame);
471-
MaterializedFrame target = localsStorage.getFrame();
475+
MaterializedFrame target = frameProfile.profile(localsStorage.getFrame());
472476
assert fd == target.getFrameDescriptor();
473477

474478
for (int i = 0; i < cachedSlots.length; i++) {
@@ -615,9 +619,10 @@ static void doGenericDict(VirtualFrame frame, PFrame pyFrame, Frame frameToSync)
615619
}
616620
}
617621

618-
@Specialization(guards = "isCustomLocalsObject(pyFrame, frameToSync)")
622+
@Specialization(guards = "isCustomLocalsObject(pyFrame, frameToSync, frameProfile)")
619623
@SuppressWarnings("unused")
620-
static void doCustomLocalsObject(PFrame pyFrame, Frame frameToSync) {
624+
static void doCustomLocalsObject(PFrame pyFrame, Frame frameToSync,
625+
@Cached("createClassProfile()") ValueProfile frameProfile) {
621626
// nothing to do; we already worked on the custom object
622627
}
623628

@@ -639,9 +644,9 @@ protected static ConditionProfile[] getProfiles(int n) {
639644
* same frame descriptor as the frame to synchronize. That means, the dict represents
640645
* unmodified set of frame values of the frame to sync.
641646
*/
642-
protected static boolean hasLocalsStorage(PFrame pyFrame, Frame frameToSync) {
647+
protected static boolean hasLocalsStorage(PFrame pyFrame, Frame frameToSync, ValueProfile frameProfile) {
643648
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();
645650
}
646651

647652
protected static boolean isDictWithCustomStorage(PFrame pyFrame) {
@@ -650,17 +655,17 @@ protected static boolean isDictWithCustomStorage(PFrame pyFrame) {
650655
return PythonObjectLibrary.getUncached().getLazyPythonClass(localsObject) == PythonBuiltinClassType.PDict;
651656
}
652657

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);
655660
}
656661

657662
protected static LocalsStorage getLocalsStorage(PFrame pyFrame) {
658663
return (LocalsStorage) ((PDict) pyFrame.getLocalsDict()).getDictStorage();
659664
}
660665

661-
private static FrameDescriptor getFd(HashingStorage storage) {
666+
private static FrameDescriptor getFd(HashingStorage storage, ValueProfile frameProfile) {
662667
if (storage instanceof LocalsStorage) {
663-
return ((LocalsStorage) storage).getFrame().getFrameDescriptor();
668+
return frameProfile.profile(((LocalsStorage) storage).getFrame()).getFrameDescriptor();
664669
}
665670
return null;
666671
}

0 commit comments

Comments
 (0)