Skip to content

Commit 88f8918

Browse files
committed
python threads: setting the stack size has no effect on thread creation, since the java thread stack size != python thread stack size
- python threads are created using the default jvm decided stack size
1 parent 26199a4 commit 88f8918

File tree

3 files changed

+12
-18
lines changed

3 files changed

+12
-18
lines changed

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

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,7 @@ long getCount() {
125125
abstract static class GetThreadStackSizeNode extends PythonUnaryBuiltinNode {
126126
@Specialization
127127
long getStackSize(@SuppressWarnings("unused") PNone stackSize) {
128-
return getContext().getThreadStackSize();
129-
}
130-
131-
@Specialization
132-
long getStackSize(int stackSize,
133-
@Cached("createBinaryProfile()") ConditionProfile invalidSizeProfile) {
134-
if (invalidSizeProfile.profile(stackSize < 0)) {
135-
throw raise(ValueError, "size must be 0 or a positive value");
136-
}
137-
return getContext().getAndSetThreadStackSize(stackSize);
128+
return getContext().getPythonThreadStackSize();
138129
}
139130

140131
@Specialization
@@ -143,7 +134,7 @@ long getStackSize(long stackSize,
143134
if (invalidSizeProfile.profile(stackSize < 0)) {
144135
throw raise(ValueError, "size must be 0 or a positive value");
145136
}
146-
return getContext().getAndSetThreadStackSize(stackSize);
137+
return getContext().getAndSetPythonsThreadStackSize(stackSize);
147138
}
148139
}
149140

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/thread/CreateThreadNode.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ public PThread execute(VirtualFrame frame, PythonClass cls, Object callable, Obj
6767
PythonContext context = getContext();
6868
TruffleContext truffleContext = context.getEnv().getContext();
6969

70-
return factory().createThread(cls, context.getThreadGroup(), context.getThreadStackSize(), () -> {
70+
// TODO: python thread stack size != java thread stack size
71+
// ignore setting the stack size for the moment
72+
return factory().createThread(cls, context.getThreadGroup(), 0, () -> {
7173
Object previous = truffleContext.enter();
7274
Object[] arguments = getArgsNode.executeWith(args);
7375
PKeyword[] keywords = getKwArgsNode.executeWith(kwargs);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonContext.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ public final class PythonContext {
6464
private final HashMap<Object, CallTarget> atExitHooks = new HashMap<>();
6565
private final AtomicLong globalId = new AtomicLong(Integer.MAX_VALUE * 2L + 4L);
6666
private final ThreadGroup threadGroup = new ThreadGroup(GRAALPYTHON_THREADS);
67-
private final AtomicLong threadStackSize = new AtomicLong(0); // the VM will set it to whatever
68-
// it likes
67+
68+
// if set to 0 the VM will set it to whatever it likes
69+
private final AtomicLong pythonThreadStackSize = new AtomicLong(0);
6970

7071
@CompilationFinal private TruffleLanguage.Env env;
7172

@@ -108,12 +109,12 @@ public ThreadGroup getThreadGroup() {
108109
}
109110

110111
@TruffleBoundary(allowInlining = true)
111-
public long getThreadStackSize() {
112-
return threadStackSize.get();
112+
public long getPythonThreadStackSize() {
113+
return pythonThreadStackSize.get();
113114
}
114115

115-
public long getAndSetThreadStackSize(long value) {
116-
return threadStackSize.getAndSet(value);
116+
public long getAndSetPythonsThreadStackSize(long value) {
117+
return pythonThreadStackSize.getAndSet(value);
117118
}
118119

119120
@TruffleBoundary(allowInlining = true)

0 commit comments

Comments
 (0)