Skip to content

Commit e26e77c

Browse files
committed
make references to globals weak
1 parent dde6975 commit e26e77c

File tree

3 files changed

+25
-25
lines changed

3 files changed

+25
-25
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public static DeleteGlobalNode create(String attributeId) {
6767

6868
@Specialization(guards = {"getGlobals(frame) == cachedGlobals", "isDict(cachedGlobals)"}, assumptions = "singleContextAssumption", limit = "1")
6969
Object deleteDictCached(VirtualFrame frame,
70-
@Cached("getGlobals(frame)") Object cachedGlobals,
70+
@Cached(value = "getGlobals(frame)", weak = true) Object cachedGlobals,
7171
@Cached DeleteItemNode deleteNode) {
7272
deleteNode.executeWith(frame, cachedGlobals, attributeId);
7373
return PNone.NONE;
@@ -82,7 +82,7 @@ Object deleteDict(VirtualFrame frame,
8282

8383
@Specialization(guards = {"getGlobals(frame) == cachedGlobals", "isModule(cachedGlobals)"}, assumptions = "singleContextAssumption", limit = "1")
8484
Object deleteModuleCached(VirtualFrame frame,
85-
@Cached("getGlobals(frame)") Object cachedGlobals,
85+
@Cached(value = "getGlobals(frame)", weak = true) Object cachedGlobals,
8686
@Cached DeleteAttributeNode storeNode) {
8787
storeNode.execute(frame, cachedGlobals, attributeId);
8888
return PNone.NONE;

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public StatementNode makeWriteNode(ExpressionNode rhs) {
8686

8787
@Specialization(guards = {"getGlobals(frame) == cachedGlobals", "isModule(cachedGlobals)"}, assumptions = "singleContextAssumption", limit = "1")
8888
protected Object readGlobalCached(@SuppressWarnings("unused") VirtualFrame frame,
89-
@Cached("getGlobals(frame)") Object cachedGlobals) {
89+
@Cached(value = "getGlobals(frame)", weak = true) Object cachedGlobals) {
9090
Object result = readFromModuleNode.execute(cachedGlobals, attributeId);
9191
return returnGlobalOrBuiltin(result);
9292
}
@@ -104,8 +104,8 @@ protected static HashingStorage getStorage(Object cachedGlobals) {
104104
@Specialization(guards = {"getGlobals(frame) == cachedGlobals", "isBuiltinDict(cachedGlobals, builtinProfile)",
105105
"getStorage(cachedGlobals) == cachedStorage"}, assumptions = "singleContextAssumption", limit = "1")
106106
protected Object readGlobalBuiltinDictCachedUnchangedStorage(@SuppressWarnings("unused") VirtualFrame frame,
107-
@SuppressWarnings("unused") @Cached("getGlobals(frame)") Object cachedGlobals,
108-
@Cached("getStorage(cachedGlobals)") HashingStorage cachedStorage,
107+
@SuppressWarnings("unused") @Cached(value = "getGlobals(frame)", weak = true) Object cachedGlobals,
108+
@Cached(value = "getStorage(getGlobals(frame))", weak = true) HashingStorage cachedStorage,
109109
@CachedLibrary("cachedStorage") HashingStorageLibrary hlib,
110110
@SuppressWarnings("unused") @Cached IsBuiltinClassProfile builtinProfile) {
111111
Object result = hlib.getItem(cachedStorage, attributeId);
@@ -119,7 +119,7 @@ protected static HashingStorage getDictStorage(Object cachedGlobals) {
119119
@Specialization(guards = {"getGlobals(frame) == cachedGlobals",
120120
"isBuiltinDict(cachedGlobals, builtinProfile)"}, assumptions = "singleContextAssumption", replaces = "readGlobalBuiltinDictCachedUnchangedStorage", limit = "1")
121121
protected Object readGlobalBuiltinDictCached(@SuppressWarnings("unused") VirtualFrame frame,
122-
@Cached("getGlobals(frame)") Object cachedGlobals,
122+
@Cached(value = "getGlobals(frame)", weak = true) Object cachedGlobals,
123123
@CachedLibrary(value = "getDictStorage(cachedGlobals)") HashingStorageLibrary hlib,
124124
@Cached @SuppressWarnings("unused") IsBuiltinClassProfile builtinProfile) {
125125
Object result = hlib.getItem(getDictStorage(cachedGlobals), attributeId);
@@ -140,7 +140,7 @@ protected Object readGlobalBuiltinDict(VirtualFrame frame,
140140

141141
@Specialization(guards = {"getGlobals(frame) == cachedGlobals", "isDict(cachedGlobals)"}, rewriteOn = PException.class, assumptions = "singleContextAssumption", limit = "1")
142142
protected Object readGlobalDictCached(VirtualFrame frame,
143-
@Cached("getGlobals(frame)") Object cachedGlobals,
143+
@Cached(value = "getGlobals(frame)", weak = true) Object cachedGlobals,
144144
@Cached GetItemNode getItemNode) {
145145
return returnGlobalOrBuiltin(getItemNode.execute(frame, cachedGlobals, attributeId));
146146
}

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

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ private static PDict getGlobalsDict(VirtualFrame frame) {
109109

110110
@Specialization(guards = {"getGlobals(frame) == cachedGlobals", "isBuiltinDict(cachedGlobals, builtinProfile)"}, assumptions = "singleContextAssumption", limit = "1")
111111
void writeDictBooleanCached(VirtualFrame frame, boolean value,
112-
@Cached("getGlobals(frame)") Object cachedGlobals,
113-
@Cached("create()") HashingCollectionNodes.SetItemNode storeNode) {
112+
@Cached(value = "getGlobals(frame)", weak = true) Object cachedGlobals,
113+
@Cached HashingCollectionNodes.SetItemNode storeNode) {
114114
storeNode.execute(frame, (PDict) cachedGlobals, attributeId, value);
115115
}
116116

@@ -122,49 +122,49 @@ void writeDictBoolean(VirtualFrame frame, boolean value,
122122

123123
@Specialization(guards = {"getGlobals(frame) == cachedGlobals", "isBuiltinDict(cachedGlobals, builtinProfile)"}, assumptions = "singleContextAssumption", limit = "1")
124124
void writeDictIntCached(VirtualFrame frame, int value,
125-
@Cached("getGlobals(frame)") Object cachedGlobals,
126-
@Cached("create()") HashingCollectionNodes.SetItemNode storeNode) {
125+
@Cached(value = "getGlobals(frame)", weak = true) Object cachedGlobals,
126+
@Cached HashingCollectionNodes.SetItemNode storeNode) {
127127
storeNode.execute(frame, (PDict) cachedGlobals, attributeId, value);
128128
}
129129

130130
@Specialization(guards = "isBuiltinDict(getGlobals(frame), builtinProfile)", replaces = "writeDictIntCached")
131131
void writeDictInt(VirtualFrame frame, int value,
132-
@Cached("create()") HashingCollectionNodes.SetItemNode storeNode) {
132+
@Cached HashingCollectionNodes.SetItemNode storeNode) {
133133
storeNode.execute(frame, getGlobalsDict(frame), attributeId, value);
134134
}
135135

136136
@Specialization(guards = {"getGlobals(frame) == cachedGlobals", "isBuiltinDict(cachedGlobals, builtinProfile)"}, assumptions = "singleContextAssumption", limit = "1")
137137
void writeDictLongCached(VirtualFrame frame, long value,
138-
@Cached("getGlobals(frame)") Object cachedGlobals,
139-
@Cached("create()") HashingCollectionNodes.SetItemNode storeNode) {
138+
@Cached(value = "getGlobals(frame)", weak = true) Object cachedGlobals,
139+
@Cached HashingCollectionNodes.SetItemNode storeNode) {
140140
storeNode.execute(frame, (PDict) cachedGlobals, attributeId, value);
141141
}
142142

143143
@Specialization(guards = "isBuiltinDict(getGlobals(frame), builtinProfile)", replaces = "writeDictLongCached")
144144
void writeDictLong(VirtualFrame frame, long value,
145-
@Cached("create()") HashingCollectionNodes.SetItemNode storeNode) {
145+
@Cached HashingCollectionNodes.SetItemNode storeNode) {
146146
storeNode.execute(frame, getGlobalsDict(frame), attributeId, value);
147147
}
148148

149149
@Specialization(guards = {"getGlobals(frame) == cachedGlobals", "isBuiltinDict(cachedGlobals, builtinProfile)"}, assumptions = "singleContextAssumption", limit = "1")
150150
void writeDictDoubleCached(VirtualFrame frame, double value,
151-
@Cached("getGlobals(frame)") Object cachedGlobals,
152-
@Cached("create()") HashingCollectionNodes.SetItemNode storeNode) {
151+
@Cached(value = "getGlobals(frame)", weak = true) Object cachedGlobals,
152+
@Cached HashingCollectionNodes.SetItemNode storeNode) {
153153
storeNode.execute(frame, (PDict) cachedGlobals, attributeId, value);
154154
}
155155

156156
@Specialization(guards = "isBuiltinDict(getGlobals(frame), builtinProfile)", replaces = "writeDictDoubleCached")
157157
void writeDictDouble(VirtualFrame frame, double value,
158-
@Cached("create()") HashingCollectionNodes.SetItemNode storeNode) {
158+
@Cached HashingCollectionNodes.SetItemNode storeNode) {
159159
storeNode.execute(frame, getGlobalsDict(frame), attributeId, value);
160160
}
161161

162162
@Specialization(replaces = {
163163
"writeDictBooleanCached", "writeDictBoolean", "writeDictInt", "writeDictIntCached", "writeDictLong", "writeDictLongCached", "writeDictDouble", "writeDictDoubleCached"
164164
}, guards = {"getGlobals(frame) == cachedGlobals", "isBuiltinDict(cachedGlobals, builtinProfile)"}, assumptions = "singleContextAssumption", limit = "1")
165165
void writeDictObjectCached(VirtualFrame frame, Object value,
166-
@Cached("getGlobals(frame)") Object cachedGlobals,
167-
@Cached("create()") HashingCollectionNodes.SetItemNode storeNode) {
166+
@Cached(value = "getGlobals(frame)", weak = true) Object cachedGlobals,
167+
@Cached HashingCollectionNodes.SetItemNode storeNode) {
168168
storeNode.execute(frame, (PDict) cachedGlobals, attributeId, value);
169169
}
170170

@@ -173,7 +173,7 @@ void writeDictObjectCached(VirtualFrame frame, Object value,
173173
"writeDictObjectCached"
174174
}, guards = "isBuiltinDict(getGlobals(frame), builtinProfile)")
175175
void writeDictObject(VirtualFrame frame, Object value,
176-
@Cached("create()") HashingCollectionNodes.SetItemNode storeNode) {
176+
@Cached HashingCollectionNodes.SetItemNode storeNode) {
177177
storeNode.execute(frame, getGlobalsDict(frame), attributeId, value);
178178
}
179179

@@ -182,8 +182,8 @@ void writeDictObject(VirtualFrame frame, Object value,
182182
"writeDictObject", "writeDictObjectCached"
183183
}, guards = {"getGlobals(frame) == cachedGlobals", "isDict(cachedGlobals)"}, assumptions = "singleContextAssumption", limit = "1")
184184
void writeGenericDictCached(VirtualFrame frame, Object value,
185-
@Cached("getGlobals(frame)") Object cachedGlobals,
186-
@Cached("create()") SetItemNode storeNode) {
185+
@Cached(value = "getGlobals(frame)", weak = true) Object cachedGlobals,
186+
@Cached SetItemNode storeNode) {
187187
storeNode.executeWith(frame, cachedGlobals, attributeId, value);
188188
}
189189

@@ -192,13 +192,13 @@ void writeGenericDictCached(VirtualFrame frame, Object value,
192192
"writeDictObject", "writeDictObjectCached", "writeGenericDictCached",
193193
}, guards = "isDict(getGlobals(frame))")
194194
void writeGenericDict(VirtualFrame frame, Object value,
195-
@Cached("create()") SetItemNode storeNode) {
195+
@Cached SetItemNode storeNode) {
196196
storeNode.executeWith(frame, PArguments.getGlobals(frame), attributeId, value);
197197
}
198198

199199
@Specialization(guards = {"getGlobals(frame) == cachedGlobals", "isModule(getGlobals(frame))"}, assumptions = "singleContextAssumption", limit = "1")
200200
void writeModuleCached(VirtualFrame frame, Object value,
201-
@Cached("getGlobals(frame)") Object cachedGlobals,
201+
@Cached(value = "getGlobals(frame)", weak = true) Object cachedGlobals,
202202
@Cached("create(attributeId)") SetAttributeNode storeNode) {
203203
storeNode.executeVoid(frame, cachedGlobals, value);
204204
}

0 commit comments

Comments
 (0)