Skip to content

Commit 750d361

Browse files
committed
Thread-safety fixes
1 parent b4b90ed commit 750d361

File tree

9 files changed

+43
-27
lines changed

9 files changed

+43
-27
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1610,7 +1610,7 @@ public Object doIt(VirtualFrame frame, Object[] args, PKeyword[] kwargs) {
16101610
// we already have a Truffle debugger attached, it'll stop here
16111611
return PNone.NONE;
16121612
} else if (getContext().isInitialized()) {
1613-
if (getSysModuleNode == null) {
1613+
if (callNode == null) {
16141614
CompilerDirectives.transferToInterpreterAndInvalidate();
16151615
getSysModuleNode = insert(HashingStorageNodes.GetItemNode.create());
16161616
getBreakpointhookNode = insert(ReadAttributeFromObjectNode.create());

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MarshalModuleBuiltins.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2019, Oracle and/or its affiliates.
2+
* Copyright (c) 2017, 2020, Oracle and/or its affiliates.
33
* Copyright (c) 2013, Regents of the University of California
44
*
55
* All rights reserved.
@@ -245,8 +245,10 @@ abstract static class MarshallerNode extends PNodeWithState {
245245
protected MarshallerNode getRecursiveNode() {
246246
if (recursiveNode == null) {
247247
CompilerDirectives.transferToInterpreterAndInvalidate();
248-
recursiveNode = insert(create());
249-
recursiveNode.depth += 1;
248+
synchronized (this) {
249+
recursiveNode = insert(create());
250+
recursiveNode.depth += 1;
251+
}
250252
}
251253
return recursiveNode;
252254
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MathModuleBuiltins.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@ public boolean isClose(long a, long b, double rel_tol, double abs_tol) {
878878

879879
@Fallback
880880
public boolean isClose(VirtualFrame frame, Object a, Object b, Object rel_tol, Object abs_tol) {
881-
if (castANode == null) {
881+
if (castAbsNode == null) {
882882
CompilerDirectives.transferToInterpreterAndInvalidate();
883883
castANode = insert(CastToDoubleNode.create());
884884
castBNode = insert(CastToDoubleNode.create());
@@ -989,7 +989,7 @@ public double ldexpPIL(PInt mantissa, long exp) {
989989
@Fallback
990990
public double ldexpOO(VirtualFrame frame, Object mantissa, Object exp) {
991991
if (PGuards.isInteger(exp) || PGuards.isPInt(exp) || (exp instanceof Boolean)) {
992-
if (castNode == null) {
992+
if (recursiveNode == null) {
993993
CompilerDirectives.transferToInterpreterAndInvalidate();
994994
castNode = insert(CastToDoubleNode.create());
995995
recursiveNode = insert(LdexpNode.create());

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/superobject/SuperBuiltins.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -397,7 +397,7 @@ public Object get(SuperObject self, Object obj, @SuppressWarnings("unused") Obje
397397
// not binding to an object or already bound
398398
return this;
399399
} else {
400-
if (superInit == null) {
400+
if (getType == null) {
401401
CompilerDirectives.transferToInterpreterAndInvalidate();
402402
superInit = insert(SuperInitNodeFactory.create());
403403
getType = insert(GetTypeNodeGen.create());
@@ -483,7 +483,7 @@ public Object get(VirtualFrame frame, SuperObject self, Object attr) {
483483
* Only pass 'obj' param if this is instance-mode super (See SF ID #743627)
484484
*/
485485
// acts as a branch profile
486-
if (getObject == null) {
486+
if (callGet == null) {
487487
CompilerDirectives.transferToInterpreterAndInvalidate();
488488
getObject = insert(GetObjectNodeGen.create());
489489
callGet = insert(CallTernaryMethodNode.create());

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/zipimporter/ZipImporterBuiltins.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2019, Oracle and/or its affiliates.
2+
* Copyright (c) 2017, 2020, Oracle and/or its affiliates.
33
* Copyright (c) 2013, Regents of the University of California
44
*
55
* All rights reserved.
@@ -357,10 +357,9 @@ public PNone init(VirtualFrame frame, PZipImporter self, PBytes path,
357357
@Specialization
358358
public PNone init(VirtualFrame frame, PZipImporter self, PythonObject path) {
359359
// at first we need to find out, whether path object has __fspath__ method
360-
if (getClassNode == null) {
360+
if (findFspathNode == null) {
361361
CompilerDirectives.transferToInterpreterAndInvalidate();
362362
getClassNode = insert(GetLazyClassNode.create());
363-
CompilerDirectives.transferToInterpreterAndInvalidate();
364363
findFspathNode = insert(LookupAttributeInMRONode.create(SpecialMethodNames.__FSPATH__));
365364
}
366365
Object result = findFspathNode.execute(getClassNode.execute(path));

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/control/ForNode.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2019, Oracle and/or its affiliates.
2+
* Copyright (c) 2017, 2020, Oracle and/or its affiliates.
33
* Copyright (c) 2013, Regents of the University of California
44
*
55
* All rights reserved.
@@ -184,8 +184,15 @@ public StatementNode getBody() {
184184
public void executeVoid(VirtualFrame frame) {
185185
if (iteratorSlot == null) {
186186
CompilerDirectives.transferToInterpreterAndInvalidate();
187-
iteratorSlot = frame.getFrameDescriptor().addFrameSlot(new Object(), FrameSlotKind.Object);
188-
((ForRepeatingNode) loopNode.getRepeatingNode()).iteratorSlot = iteratorSlot;
187+
getLock().lock();
188+
try {
189+
if (iteratorSlot == null) {
190+
iteratorSlot = frame.getFrameDescriptor().addFrameSlot(new Object(), FrameSlotKind.Object);
191+
((ForRepeatingNode) loopNode.getRepeatingNode()).iteratorSlot = iteratorSlot;
192+
}
193+
} finally {
194+
getLock().unlock();
195+
}
189196
}
190197
frame.setObject(iteratorSlot, iterator.execute(frame));
191198
try {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/generator/GeneratorAccessNode.java

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2019, Oracle and/or its affiliates.
2+
* Copyright (c) 2017, 2020, Oracle and/or its affiliates.
33
* Copyright (c) 2014, Regents of the University of California
44
*
55
* All rights reserved.
@@ -65,10 +65,14 @@ private GeneratorControlData getControlData(VirtualFrame frame) {
6565
public boolean isActive(VirtualFrame frame, int flagSlot) {
6666
if (active.length <= flagSlot) {
6767
CompilerDirectives.transferToInterpreterAndInvalidate();
68-
byte[] newActive = new byte[flagSlot + 1];
69-
Arrays.fill(newActive, UNSET);
70-
System.arraycopy(active, 0, newActive, 0, active.length);
71-
active = newActive;
68+
synchronized (this) {
69+
if (active.length <= flagSlot) {
70+
byte[] newActive = new byte[flagSlot + 1];
71+
Arrays.fill(newActive, UNSET);
72+
System.arraycopy(active, 0, newActive, 0, active.length);
73+
active = newActive;
74+
}
75+
}
7276
}
7377
if (active[flagSlot] == UNSET) {
7478
CompilerDirectives.transferToInterpreterAndInvalidate();
@@ -94,10 +98,14 @@ public void setActive(VirtualFrame frame, int flagSlot, boolean value) {
9498
public int getIndex(VirtualFrame frame, int blockIndexSlot) {
9599
if (indices.length <= blockIndexSlot) {
96100
CompilerDirectives.transferToInterpreterAndInvalidate();
97-
int[] newIndices = new int[blockIndexSlot + 1];
98-
Arrays.fill(newIndices, UNSET);
99-
System.arraycopy(indices, 0, newIndices, 0, indices.length);
100-
indices = newIndices;
101+
synchronized (this) {
102+
if (indices.length <= blockIndexSlot) {
103+
int[] newIndices = new int[blockIndexSlot + 1];
104+
Arrays.fill(newIndices, UNSET);
105+
System.arraycopy(indices, 0, newIndices, 0, indices.length);
106+
indices = newIndices;
107+
}
108+
}
101109
}
102110
if (indices[blockIndexSlot] == UNSET) {
103111
CompilerDirectives.transferToInterpreterAndInvalidate();

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/statement/AssertNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ public void executeVoid(VirtualFrame frame) {
6666
if (assertionsEnabled == null) {
6767
CompilerDirectives.transferToInterpreterAndInvalidate();
6868
PythonContext context = getContext();
69-
assertionsEnabled = !PythonOptions.getOption(context, PythonOptions.PythonOptimizeFlag);
7069
javaExceptionsFailAssertions = PythonOptions.getOption(context, PythonOptions.CatchAllExceptions);
70+
assertionsEnabled = !PythonOptions.getOption(context, PythonOptions.PythonOptimizeFlag);
7171
}
7272
if (assertionsEnabled) {
7373
try {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/statement/ImportFromNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2019, Oracle and/or its affiliates.
2+
* Copyright (c) 2017, 2020, Oracle and/or its affiliates.
33
* Copyright (c) 2013, Regents of the University of California
44
*
55
* All rights reserved.
@@ -119,7 +119,7 @@ public void executeVoid(VirtualFrame frame) {
119119
throw pe;
120120
}
121121
String fullname = pkgname + "." + attr;
122-
if (getItem == null) {
122+
if (readModules == null) {
123123
CompilerDirectives.transferToInterpreterAndInvalidate();
124124
getItem = insert(GetItemNode.create());
125125
readModules = insert(ReadAttributeFromObjectNode.create());

0 commit comments

Comments
 (0)