Skip to content

Commit 5369e48

Browse files
committed
Caching condition profiles.
1 parent 08ac961 commit 5369e48

File tree

1 file changed

+19
-29
lines changed

1 file changed

+19
-29
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/PythonAbstractObject.java

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -441,8 +441,8 @@ public Object invokeMember(String member, Object[] arguments,
441441
@Exclusive @Cached LookupInheritedAttributeNode.Dynamic lookupGetattributeNode,
442442
@Exclusive @Cached CallNode callGetattributeNode,
443443
@Exclusive @Cached PExecuteNode executeNode,
444-
@Cached("createBinaryProfile()") ConditionProfile profileGetattribute,
445-
@Cached("createBinaryProfile()") ConditionProfile profileMember) throws UnknownIdentifierException, UnsupportedMessageException {
444+
@Exclusive @Cached("createBinaryProfile()") ConditionProfile profileGetattribute,
445+
@Exclusive @Cached("createBinaryProfile()") ConditionProfile profileMember) throws UnknownIdentifierException, UnsupportedMessageException {
446446
Object attrGetattribute = lookupGetattributeNode.execute(this, __GETATTRIBUTE__);
447447
if (profileGetattribute.profile(attrGetattribute != PNone.NO_VALUE)) {
448448
Object memberObj = callGetattributeNode.execute(null, attrGetattribute, this, member);
@@ -678,19 +678,7 @@ public final boolean isContextManager(@Exclusive @Cached HasInheritedAttributeNo
678678
@Exclusive @Cached("createBinaryProfile()") ConditionProfile profile) {
679679
return profile.profile(hasEnterNode.execute(this, __ENTER__) && hasExitNode.execute(this, __EXIT__));
680680
}
681-
682-
@ExportMessage
683-
public boolean isSequence(@Shared("thisObject") @Cached GetLazyClassNode getClassNode,
684-
@CachedLibrary(limit = "1") PythonTypeLibrary pythonTypeLibrary) {
685-
return pythonTypeLibrary.isSequenceType(getClassNode.execute(this));
686-
}
687-
688-
@ExportMessage
689-
public boolean isMapping(@Shared("thisObject") @Cached GetLazyClassNode getClassNode,
690-
@CachedLibrary(limit = "1") PythonTypeLibrary pythonTypeLibrary) {
691-
return pythonTypeLibrary.isMappingType(getClassNode.execute(this));
692-
}
693-
681+
694682
private static final String DATETIME_MODULE_NAME = "datetime";
695683
private static final String TIME_MODULE_NAME = "time";
696684
private static final String DATE_TYPE = "date";
@@ -701,17 +689,19 @@ public boolean isMapping(@Shared("thisObject") @Cached GetLazyClassNode getClass
701689
@ExportMessage
702690
public boolean isDate(@Shared("getClassNode") @Cached GetLazyClassNode getClassNode,
703691
@Shared("readTypeNode") @Cached ReadAttributeFromObjectNode readTypeNode,
704-
@Shared("isSubtypeNode") @Cached IsSubtypeNode.IsSubtypeWithoutFrameNode isSubtypeNode) {
692+
@Shared("isSubtypeNode") @Cached IsSubtypeNode.IsSubtypeWithoutFrameNode isSubtypeNode,
693+
@Shared("dateTimeModuleProfile") @Cached("createBinaryProfile()") ConditionProfile dateTimeModuleLoaded,
694+
@Shared("timeModuleProfile") @Cached("createBinaryProfile()") ConditionProfile timeModuleLoaded) {
705695
LazyPythonClass objType = getClassNode.execute(this);
706696
PDict importedModules = PythonLanguage.getContext().getImportedModules();
707697
Object module = importedModules.getItem(DATETIME_MODULE_NAME);
708-
if (module != null) {
698+
if (dateTimeModuleLoaded.profile(module != null)) {
709699
if (isSubtypeNode.executeWithGlobalState(objType, readTypeNode.execute(module, DATETIME_TYPE)) || isSubtypeNode.executeWithGlobalState(objType, readTypeNode.execute(module, DATE_TYPE))) {
710700
return true;
711701
}
712702
}
713703
module = importedModules.getItem(TIME_MODULE_NAME);
714-
if (module != null) {
704+
if (timeModuleLoaded.profile(module != null)) {
715705
if (isSubtypeNode.executeWithGlobalState(objType, readTypeNode.execute(module, STRUCT_TIME_TYPE))) {
716706
return true;
717707
}
@@ -725,8 +715,8 @@ public LocalDate asDate(@Shared("getClassNode") @Cached GetLazyClassNode getClas
725715
@Shared("isSubtypeNode") @Cached IsSubtypeNode.IsSubtypeWithoutFrameNode isSubtypeNode,
726716
@Shared("castToIntNode") @Cached CastToJavaIntNode castToIntNode,
727717
@CachedLibrary("this") InteropLibrary lib,
728-
@Cached("createBinaryProfile()") ConditionProfile dateTimeModuleLoaded,
729-
@Cached("createBinaryProfile()") ConditionProfile timeModuleLoaded) throws UnsupportedMessageException {
718+
@Shared("dateTimeModuleProfile") @Cached("createBinaryProfile()") ConditionProfile dateTimeModuleLoaded,
719+
@Shared("timeModuleProfile") @Cached("createBinaryProfile()") ConditionProfile timeModuleLoaded) throws UnsupportedMessageException {
730720
LazyPythonClass objType = getClassNode.execute(this);
731721
PDict importedModules = PythonLanguage.getContext().getImportedModules();
732722
Object module = importedModules.getItem(DATETIME_MODULE_NAME);
@@ -762,8 +752,8 @@ public LocalDate asDate(@Shared("getClassNode") @Cached GetLazyClassNode getClas
762752
public boolean isTime(@Shared("getClassNode") @Cached GetLazyClassNode getClassNode,
763753
@Shared("readTypeNode") @Cached ReadAttributeFromObjectNode readTypeNode,
764754
@Shared("isSubtypeNode") @Cached IsSubtypeNode.IsSubtypeWithoutFrameNode isSubtype,
765-
@Cached("createBinaryProfile()") ConditionProfile dateTimeModuleLoaded,
766-
@Cached("createBinaryProfile()") ConditionProfile timeModuleLoaded) {
755+
@Shared("dateTimeModuleProfile") @Cached("createBinaryProfile()") ConditionProfile dateTimeModuleLoaded,
756+
@Shared("timeModuleProfile") @Cached("createBinaryProfile()") ConditionProfile timeModuleLoaded) {
767757
LazyPythonClass objType = getClassNode.execute(this);
768758
PDict importedModules = PythonLanguage.getContext().getImportedModules();
769759
Object module = importedModules.getItem(DATETIME_MODULE_NAME);
@@ -787,8 +777,8 @@ public LocalTime asTime(@Shared("getClassNode") @Cached GetLazyClassNode getClas
787777
@Shared("isSubtypeNode") @Cached IsSubtypeNode.IsSubtypeWithoutFrameNode isSubtypeNode,
788778
@Shared("castToIntNode") @Cached CastToJavaIntNode castToIntNode,
789779
@CachedLibrary("this") InteropLibrary lib,
790-
@Cached("createBinaryProfile()") ConditionProfile dateTimeModuleLoaded,
791-
@Cached("createBinaryProfile()") ConditionProfile timeModuleLoaded) throws UnsupportedMessageException {
780+
@Shared("dateTimeModuleProfile") @Cached("createBinaryProfile()") ConditionProfile dateTimeModuleLoaded,
781+
@Shared("timeModuleProfile") @Cached("createBinaryProfile()") ConditionProfile timeModuleLoaded) throws UnsupportedMessageException {
792782
LazyPythonClass objType = getClassNode.execute(this);
793783
PDict importedModules = PythonLanguage.getContext().getImportedModules();
794784
Object module = importedModules.getItem(DATETIME_MODULE_NAME);
@@ -826,8 +816,8 @@ public boolean isTimeZone(@Shared("getClassNode") @Cached GetLazyClassNode getCl
826816
@Shared("readTypeNode") @Cached ReadAttributeFromObjectNode readTypeNode,
827817
@Shared("isSubtypeNode") @Cached IsSubtypeNode.IsSubtypeWithoutFrameNode isSubtype,
828818
@CachedLibrary(limit = "2") InteropLibrary lib,
829-
@Cached("createBinaryProfile()") ConditionProfile dateTimeModuleLoaded,
830-
@Cached("createBinaryProfile()") ConditionProfile timeModuleLoaded) {
819+
@Shared("dateTimeModuleProfile") @Cached("createBinaryProfile()") ConditionProfile dateTimeModuleLoaded,
820+
@Shared("timeModuleProfile") @Cached("createBinaryProfile()") ConditionProfile timeModuleLoaded) {
831821
LazyPythonClass objType = getClassNode.execute(this);
832822
PDict importedModules = PythonLanguage.getContext().getImportedModules();
833823
Object module = importedModules.getItem(DATETIME_MODULE_NAME);
@@ -880,8 +870,8 @@ public ZoneId asTimeZone(@Shared("getClassNode") @Cached GetLazyClassNode getCla
880870
@Shared("isSubtypeNode") @Cached IsSubtypeNode.IsSubtypeWithoutFrameNode isSubtypeNode,
881871
@Shared("castToIntNode") @Cached CastToJavaIntNode castToIntNode,
882872
@CachedLibrary(limit = "3") InteropLibrary lib,
883-
@Cached("createBinaryProfile()") ConditionProfile dateTimeModuleLoaded,
884-
@Cached("createBinaryProfile()") ConditionProfile timeModuleLoaded) throws UnsupportedMessageException {
873+
@Shared("dateTimeModuleProfile") @Cached("createBinaryProfile()") ConditionProfile dateTimeModuleLoaded,
874+
@Shared("timeModuleProfile") @Cached("createBinaryProfile()") ConditionProfile timeModuleLoaded) throws UnsupportedMessageException {
885875
if (!lib.isTimeZone(this)) {
886876
throw UnsupportedMessageException.create();
887877
}
@@ -1476,4 +1466,4 @@ public static PInteropDeleteAttributeNode getUncached() {
14761466
private static boolean objectHasAttribute(Object object, Object field) {
14771467
return ((PythonObject) object).getAttributeNames().contains(field);
14781468
}
1479-
}
1469+
}

0 commit comments

Comments
 (0)