40
40
*/
41
41
package com .oracle .graal .python .lib ;
42
42
43
- import static com .oracle .graal .python .builtins .objects .cext .structs .CFields .PyTypeObject__tp_dict ;
44
-
45
43
import com .oracle .graal .python .builtins .PythonBuiltinClassType ;
46
44
import com .oracle .graal .python .builtins .objects .cext .PythonAbstractNativeObject ;
47
45
import com .oracle .graal .python .builtins .objects .cext .capi .CExtNodes .PCallCapiFunction ;
48
46
import com .oracle .graal .python .builtins .objects .cext .capi .NativeCAPISymbol ;
49
- import com .oracle .graal .python .builtins .objects .cext .structs .CStructAccess ;
50
- import com .oracle .graal .python .builtins .objects .cext .structs .CStructAccessFactory ;
51
- import com .oracle .graal .python .builtins .objects .common .HashingStorageNodes .HashingStorageGetItem ;
52
- import com .oracle .graal .python .builtins .objects .common .HashingStorageNodes .HashingStorageSetItem ;
53
- import com .oracle .graal .python .builtins .objects .common .HashingStorageNodesFactory .HashingStorageGetItemNodeGen ;
54
- import com .oracle .graal .python .builtins .objects .dict .PDict ;
55
47
import com .oracle .graal .python .builtins .objects .type .PythonManagedClass ;
56
48
import com .oracle .graal .python .runtime .PythonContext ;
57
49
import com .oracle .truffle .api .Assumption ;
50
+ import com .oracle .truffle .api .CompilerDirectives ;
58
51
import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
59
52
import com .oracle .truffle .api .dsl .Cached ;
60
53
import com .oracle .truffle .api .dsl .Fallback ;
61
54
import com .oracle .truffle .api .dsl .GenerateInline ;
62
55
import com .oracle .truffle .api .dsl .GenerateUncached ;
63
56
import com .oracle .truffle .api .dsl .Specialization ;
57
+ import com .oracle .truffle .api .library .CachedLibrary ;
64
58
import com .oracle .truffle .api .nodes .Node ;
59
+ import com .oracle .truffle .api .nodes .UnexpectedResultException ;
60
+ import com .oracle .truffle .api .object .DynamicObjectLibrary ;
65
61
import com .oracle .truffle .api .object .HiddenKey ;
66
62
67
63
/**
@@ -87,14 +83,14 @@ protected static long pythonclasstype(PythonBuiltinClassType cls) {
87
83
public static final HiddenKey METHODS_FLAGS = new HiddenKey ("__methods_flags__" );
88
84
89
85
@ TruffleBoundary
90
- private static long populateMethodsFlags (PythonAbstractNativeObject cls , PDict dict ) {
86
+ private static long populateMethodsFlags (PythonAbstractNativeObject cls , DynamicObjectLibrary dynlib ) {
91
87
Long flags = (Long ) PCallCapiFunction .getUncached ().call (NativeCAPISymbol .FUN_GET_METHODS_FLAGS , cls .getPtr ());
92
- dict . setDictStorage ( HashingStorageSetItem . executeUncached ( dict . getDictStorage () , METHODS_FLAGS , flags ) );
88
+ dynlib . putLong ( cls , METHODS_FLAGS , flags );
93
89
return flags ;
94
90
}
95
91
96
92
protected static long getMethodsFlags (PythonAbstractNativeObject cls ) {
97
- return doNative (null , cls , CStructAccessFactory . ReadObjectNodeGen . getUncached (), HashingStorageGetItemNodeGen .getUncached ());
93
+ return doNative (cls , DynamicObjectLibrary .getUncached ());
98
94
}
99
95
100
96
// The assumption should hold unless `PyType_Modified` is called.
@@ -110,16 +106,17 @@ static long doNativeCached(@SuppressWarnings("unused") PythonAbstractNativeObjec
110
106
}
111
107
112
108
@ Specialization (replaces = "doNativeCached" )
113
- static long doNative (Node inliningTarget , PythonAbstractNativeObject cls ,
114
- @ Cached (inline = false ) CStructAccess .ReadObjectNode getTpDictNode ,
115
- @ Cached HashingStorageGetItem getItem ) {
109
+ static long doNative (PythonAbstractNativeObject cls ,
110
+ @ CachedLibrary (limit = "1" ) DynamicObjectLibrary dynlib ) {
116
111
// classes must have tp_dict since they are set during PyType_Ready
117
- PDict dict = (PDict ) getTpDictNode .readFromObj (cls , PyTypeObject__tp_dict );
118
- Object f = getItem .execute (inliningTarget , dict .getDictStorage (), METHODS_FLAGS );
119
- if (f == null ) {
120
- return populateMethodsFlags (cls , dict );
112
+ if (!dynlib .containsKey (cls , METHODS_FLAGS )) {
113
+ return populateMethodsFlags (cls , dynlib );
114
+ }
115
+ try {
116
+ return dynlib .getLongOrDefault (cls , METHODS_FLAGS , 0L );
117
+ } catch (UnexpectedResultException e ) {
118
+ throw CompilerDirectives .shouldNotReachHere (e );
121
119
}
122
- return (Long ) f ;
123
120
}
124
121
125
122
@ Fallback
0 commit comments