Skip to content

Commit eeb8cbc

Browse files
committed
Adding condition profiles, fixing library caching.
1 parent 4472350 commit eeb8cbc

File tree

1 file changed

+26
-18
lines changed

1 file changed

+26
-18
lines changed

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

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -670,11 +670,13 @@ public LocalDate asDate(@Shared("getClassNode") @Cached GetLazyClassNode getClas
670670
@Shared("readTypeNode") @Cached ReadAttributeFromObjectNode readTypeNode,
671671
@Shared("isSubtypeNode") @Cached IsSubtypeNode.IsSubtypeWithoutFrameNode isSubtypeNode,
672672
@Shared("castToIntNode") @Cached CastToJavaIntNode castToIntNode,
673-
@CachedLibrary(limit = "1") InteropLibrary lib) throws UnsupportedMessageException {
673+
@CachedLibrary("this") InteropLibrary lib,
674+
@Cached("createBinaryProfile()") ConditionProfile dateTimeModuleLoaded,
675+
@Cached("createBinaryProfile()") ConditionProfile timeModuleLoaded) throws UnsupportedMessageException {
674676
LazyPythonClass objType = getClassNode.execute(this);
675677
PDict importedModules = PythonLanguage.getContext().getImportedModules();
676678
Object module = importedModules.getItem(DATETIME_MODULE_NAME);
677-
if (module != null) {
679+
if (dateTimeModuleLoaded.profile(module != null)) {
678680
if (isSubtypeNode.executeWithGlobalState(objType, readTypeNode.execute(module, DATETIME_TYPE)) || isSubtypeNode.executeWithGlobalState(objType, readTypeNode.execute(module, DATE_TYPE))) {
679681
try {
680682
int year = castToIntNode.execute(lib.readMember(this, "year"));
@@ -687,7 +689,7 @@ public LocalDate asDate(@Shared("getClassNode") @Cached GetLazyClassNode getClas
687689
}
688690
}
689691
module = importedModules.getItem(TIME_MODULE_NAME);
690-
if (module != null) {
692+
if (timeModuleLoaded.profile(module != null)) {
691693
if (isSubtypeNode.executeWithGlobalState(objType, readTypeNode.execute(module, STRUCT_TIME_TYPE))) {
692694
try {
693695
int year = castToIntNode.execute(lib.readMember(this, "tm_year"));
@@ -705,17 +707,19 @@ public LocalDate asDate(@Shared("getClassNode") @Cached GetLazyClassNode getClas
705707
@ExportMessage
706708
public boolean isTime(@Shared("getClassNode") @Cached GetLazyClassNode getClassNode,
707709
@Shared("readTypeNode") @Cached ReadAttributeFromObjectNode readTypeNode,
708-
@Shared("isSubtypeNode") @Cached IsSubtypeNode.IsSubtypeWithoutFrameNode isSubtype) {
710+
@Shared("isSubtypeNode") @Cached IsSubtypeNode.IsSubtypeWithoutFrameNode isSubtype,
711+
@Cached("createBinaryProfile()") ConditionProfile dateTimeModuleLoaded,
712+
@Cached("createBinaryProfile()") ConditionProfile timeModuleLoaded) {
709713
LazyPythonClass objType = getClassNode.execute(this);
710714
PDict importedModules = PythonLanguage.getContext().getImportedModules();
711715
Object module = importedModules.getItem(DATETIME_MODULE_NAME);
712-
if (module != null) {
716+
if (dateTimeModuleLoaded.profile(module != null)) {
713717
if (isSubtype.executeWithGlobalState(objType, readTypeNode.execute(module, DATETIME_TYPE)) || isSubtype.executeWithGlobalState(objType, readTypeNode.execute(module, TIME_TYPE))) {
714718
return true;
715719
}
716720
}
717721
module = importedModules.getItem(TIME_MODULE_NAME);
718-
if (module != null) {
722+
if (timeModuleLoaded.profile(module != null)) {
719723
if (isSubtype.executeWithGlobalState(objType, readTypeNode.execute(module, STRUCT_TIME_TYPE))) {
720724
return true;
721725
}
@@ -728,11 +732,13 @@ public LocalTime asTime(@Shared("getClassNode") @Cached GetLazyClassNode getClas
728732
@Shared("readTypeNode") @Cached ReadAttributeFromObjectNode readTypeNode,
729733
@Shared("isSubtypeNode") @Cached IsSubtypeNode.IsSubtypeWithoutFrameNode isSubtypeNode,
730734
@Shared("castToIntNode") @Cached CastToJavaIntNode castToIntNode,
731-
@CachedLibrary(limit = "1") InteropLibrary lib) throws UnsupportedMessageException {
735+
@CachedLibrary("this") InteropLibrary lib,
736+
@Cached("createBinaryProfile()") ConditionProfile dateTimeModuleLoaded,
737+
@Cached("createBinaryProfile()") ConditionProfile timeModuleLoaded) throws UnsupportedMessageException {
732738
LazyPythonClass objType = getClassNode.execute(this);
733739
PDict importedModules = PythonLanguage.getContext().getImportedModules();
734740
Object module = importedModules.getItem(DATETIME_MODULE_NAME);
735-
if (module != null) {
741+
if (dateTimeModuleLoaded.profile(module != null)) {
736742
if (isSubtypeNode.executeWithGlobalState(objType, readTypeNode.execute(module, DATETIME_TYPE)) || isSubtypeNode.executeWithGlobalState(objType, readTypeNode.execute(module, TIME_TYPE))) {
737743
try {
738744
int hour = castToIntNode.execute(lib.readMember(this, "hour"));
@@ -746,7 +752,7 @@ public LocalTime asTime(@Shared("getClassNode") @Cached GetLazyClassNode getClas
746752
}
747753
}
748754
module = importedModules.getItem(TIME_MODULE_NAME);
749-
if (module != null) {
755+
if (timeModuleLoaded.profile(module != null)) {
750756
if (isSubtypeNode.executeWithGlobalState(objType, readTypeNode.execute(module, STRUCT_TIME_TYPE))) {
751757
try {
752758
int hour = castToIntNode.execute(lib.readMember(this, "tm_hour"));
@@ -764,13 +770,15 @@ public LocalTime asTime(@Shared("getClassNode") @Cached GetLazyClassNode getClas
764770
@ExportMessage
765771
public boolean isTimeZone(@Shared("getClassNode") @Cached GetLazyClassNode getClassNode,
766772
@Shared("readTypeNode") @Cached ReadAttributeFromObjectNode readTypeNode,
767-
@Shared("isSubtypeNode") @Cached IsSubtypeNode.IsSubtypeWithoutFrameNode isSubtype) {
773+
@Shared("isSubtypeNode") @Cached IsSubtypeNode.IsSubtypeWithoutFrameNode isSubtype,
774+
@CachedLibrary(limit = "2") InteropLibrary lib,
775+
@Cached("createBinaryProfile()") ConditionProfile dateTimeModuleLoaded,
776+
@Cached("createBinaryProfile()") ConditionProfile timeModuleLoaded) {
768777
LazyPythonClass objType = getClassNode.execute(this);
769778
PDict importedModules = PythonLanguage.getContext().getImportedModules();
770779
Object module = importedModules.getItem(DATETIME_MODULE_NAME);
771-
if (module != null) {
780+
if (dateTimeModuleLoaded.profile(module != null)) {
772781
if (isSubtype.executeWithGlobalState(objType, readTypeNode.execute(module, DATETIME_TYPE))) {
773-
InteropLibrary lib = InteropLibrary.getFactory().getUncached(this);
774782
try {
775783
Object tzinfo = lib.readMember(this, "tzinfo");
776784
if (tzinfo != PNone.NONE) {
@@ -783,7 +791,6 @@ public boolean isTimeZone(@Shared("getClassNode") @Cached GetLazyClassNode getCl
783791
return false;
784792
}
785793
} else if (isSubtype.executeWithGlobalState(objType, readTypeNode.execute(module, TIME_TYPE))) {
786-
InteropLibrary lib = InteropLibrary.getFactory().getUncached(this);
787794
try {
788795
Object tzinfo = lib.readMember(this, "tzinfo");
789796
if (tzinfo != PNone.NONE) {
@@ -798,9 +805,8 @@ public boolean isTimeZone(@Shared("getClassNode") @Cached GetLazyClassNode getCl
798805
}
799806
}
800807
module = importedModules.getItem(TIME_MODULE_NAME);
801-
if (module != null) {
808+
if (timeModuleLoaded.profile(module != null)) {
802809
if (isSubtype.executeWithGlobalState(objType, readTypeNode.execute(module, STRUCT_TIME_TYPE))) {
803-
InteropLibrary lib = InteropLibrary.getFactory().getUncached(this);
804810
try {
805811
Object tm_zone = lib.readMember(this, "tm_zone");
806812
if (tm_zone != PNone.NONE) {
@@ -819,14 +825,16 @@ public ZoneId asTimeZone(@Shared("getClassNode") @Cached GetLazyClassNode getCla
819825
@Shared("readTypeNode") @Cached ReadAttributeFromObjectNode readTypeNode,
820826
@Shared("isSubtypeNode") @Cached IsSubtypeNode.IsSubtypeWithoutFrameNode isSubtypeNode,
821827
@Shared("castToIntNode") @Cached CastToJavaIntNode castToIntNode,
822-
@CachedLibrary(limit = "1") InteropLibrary lib) throws UnsupportedMessageException {
828+
@CachedLibrary(limit = "3") InteropLibrary lib,
829+
@Cached("createBinaryProfile()") ConditionProfile dateTimeModuleLoaded,
830+
@Cached("createBinaryProfile()") ConditionProfile timeModuleLoaded) throws UnsupportedMessageException {
823831
if (!lib.isTimeZone(this)) {
824832
throw UnsupportedMessageException.create();
825833
}
826834
LazyPythonClass objType = getClassNode.execute(this);
827835
PDict importedModules = PythonLanguage.getContext().getImportedModules();
828836
Object module = importedModules.getItem(DATETIME_MODULE_NAME);
829-
if (module != null) {
837+
if (dateTimeModuleLoaded.profile(module != null)) {
830838
if (isSubtypeNode.executeWithGlobalState(objType, readTypeNode.execute(module, "datetime"))) {
831839
try {
832840
Object tzinfo = lib.readMember(this, "tzinfo");
@@ -856,7 +864,7 @@ public ZoneId asTimeZone(@Shared("getClassNode") @Cached GetLazyClassNode getCla
856864
}
857865
}
858866
module = importedModules.getItem(TIME_MODULE_NAME);
859-
if (module != null) {
867+
if (timeModuleLoaded.profile(module != null)) {
860868
if (isSubtypeNode.executeWithGlobalState(objType, readTypeNode.execute(module, "struct_time"))) {
861869
try {
862870
Object tm_zone = lib.readMember(this, "tm_zone");

0 commit comments

Comments
 (0)