Skip to content

Commit b46b62f

Browse files
committed
slightly improve class access
1 parent 17534a4 commit b46b62f

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/object/GetClassNode.java

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,25 @@
6868
@TypeSystemReference(PythonTypes.class)
6969
@ImportStatic({PGuards.class})
7070
public abstract class GetClassNode extends PNodeWithContext {
71+
private final ValueProfile classProfile = ValueProfile.createClassProfile();
72+
7173
public static GetClassNode create() {
7274
return GetClassNodeGen.create();
7375
}
7476

75-
public abstract PythonClass execute(Object object);
77+
public abstract PythonClass execute(boolean object);
78+
79+
public abstract PythonClass execute(int object);
80+
81+
public abstract PythonClass execute(long object);
82+
83+
public abstract PythonClass execute(double object);
84+
85+
public final PythonClass execute(Object object) {
86+
return executeGetClass(classProfile.profile(object));
87+
}
88+
89+
public abstract PythonClass executeGetClass(Object object);
7690

7791
@Specialization(assumptions = "singleContextAssumption()")
7892
protected PythonClass getIt(@SuppressWarnings("unused") GetSetDescriptor object,
@@ -191,23 +205,7 @@ protected PythonClass getIt(PythonNativeObject object,
191205
return getNativeClassNode.execute(object);
192206
}
193207

194-
@SuppressWarnings("unchecked")
195-
protected Class<? extends PythonObject> asPythonObjectSubclass(Class<? extends Object> clazz) {
196-
Class<? extends PythonObject> retval = null;
197-
if (PythonObject.class.isAssignableFrom(clazz)) {
198-
retval = (Class<? extends PythonObject>) clazz;
199-
}
200-
return retval;
201-
}
202-
203-
@Specialization(guards = {"object.getClass() == cachedClass"}, limit = "5")
204-
protected PythonClass getPythonClassCached(Object object,
205-
@Cached("asPythonObjectSubclass(object.getClass())") Class<? extends PythonObject> cachedClass,
206-
@Cached("createIdentityProfile()") ValueProfile profile) {
207-
return profile.profile(cachedClass.cast(object).getPythonClass());
208-
}
209-
210-
@Specialization(replaces = "getPythonClassCached")
208+
@Specialization
211209
protected PythonClass getPythonClassGeneric(PythonObject object,
212210
@Cached("createIdentityProfile()") ValueProfile profile) {
213211
return profile.profile(object.getPythonClass());

mx.graalpython/mx_graalpython_bench_param.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
'boolean-logic': ITER_15 + ['1000'],
7373
'builtin-len-tuple': ITER_10 + [],
7474
'builtin-len': ITER_25 + [],
75+
'class_access': ITER_25 + ['50000'],
7576
'call-method-polymorphic': ITER_10 + ['1000'],
7677
'for-range': ITER_25 + ['50000'],
7778
'function-call': ITER_25 + [],

0 commit comments

Comments
 (0)