Skip to content

Commit

Permalink
[GR-14542] Improve stack size option.
Browse files Browse the repository at this point in the history
PullRequest: graal/3233
  • Loading branch information
Palez committed Mar 25, 2019
2 parents af8cee5 + daa6049 commit fe04394
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,33 @@ public void execute(VirtualFrame frame) {

public void initialize() {
assert this.threadingStack == null;
this.threadingStack = new LLVMThreadingStack(Thread.currentThread(), env.getOptions().get(SulongEngineOption.STACK_SIZE_KB));
this.threadingStack = new LLVMThreadingStack(Thread.currentThread(), parseStackSize(env.getOptions().get(SulongEngineOption.STACK_SIZE)));
for (ContextExtension ext : contextExtensions) {
ext.initialize();
}
}

public static long parseStackSize(String v) {
String valueString = v.trim().toLowerCase();
long scale = 1;
if (valueString.endsWith("k")) {
scale = 1024L;
} else if (valueString.endsWith("m")) {
scale = 1024L * 1024L;
} else if (valueString.endsWith("g")) {
scale = 1024L * 1024L * 1024L;
} else if (valueString.endsWith("t")) {
scale = 1024L * 1024L * 1024L * 1024L;
}

if (scale != 1) {
/* Remove trailing scale character. */
valueString = valueString.substring(0, valueString.length() - 1);
}

return Long.parseLong(valueString) * scale;
}

public boolean isInitialized() {
return threadingStack != null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2018, Oracle and/or its affiliates.
* Copyright (c) 2016, 2019, Oracle and/or its affiliates.
*
* All rights reserved.
*
Expand Down Expand Up @@ -43,7 +43,7 @@ public final class LLVMStack {

public static final String FRAME_ID = "<stackpointer>";

private final int stackSize;
private final long stackSize;

private long lowerBounds;
private long upperBounds;
Expand All @@ -52,7 +52,7 @@ public final class LLVMStack {
private long stackPointer;
private long uniquesRegionPointer;

public LLVMStack(int stackSize) {
public LLVMStack(long stackSize) {
this.stackSize = stackSize;

lowerBounds = 0;
Expand Down Expand Up @@ -187,7 +187,7 @@ public long toPointer(VirtualFrame frame, FrameSlot stackPointerSlot) {

@TruffleBoundary
private void allocate(LLVMMemory memory) {
long size = stackSize * 1024L;
long size = stackSize;
long stackAllocation = memory.allocateMemory(size).asNative();
lowerBounds = stackAllocation;
upperBounds = stackAllocation + size;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2018, Oracle and/or its affiliates.
* Copyright (c) 2016, 2019, Oracle and/or its affiliates.
*
* All rights reserved.
*
Expand Down Expand Up @@ -40,10 +40,10 @@
public final class LLVMThreadingStack {
// we are not able to clean up a thread local properly, so we are using a map instead
private final Map<Thread, LLVMStack> threadMap;
private final int stackSize;
private final long stackSize;
private final Thread mainThread;

public LLVMThreadingStack(Thread mainTread, int stackSize) {
public LLVMThreadingStack(Thread mainTread, long stackSize) {
this.mainThread = mainTread;
this.stackSize = stackSize;
this.threadMap = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,20 @@
import org.graalvm.options.OptionDescriptor;
import org.graalvm.options.OptionDescriptors;
import org.graalvm.options.OptionKey;
import org.graalvm.options.OptionStability;

import com.oracle.truffle.api.CompilerAsserts;
import com.oracle.truffle.api.Option;
import com.oracle.truffle.api.TruffleLanguage;
import org.graalvm.options.OptionStability;

public final class SulongEngineOption {

public static final String OPTION_ARRAY_SEPARATOR = ":";

// @formatter:off
@Option(name = "llvm.stackSizeKB", category = OptionCategory.USER, help = "The stack size in KB.") public static final OptionKey<Integer> STACK_SIZE_KB = new OptionKey<>(81920);
@Option(name = "llvm.stackSize", category = OptionCategory.USER, stability = OptionStability.STABLE,
help = "The stack size, please end the input with one of: k, m, g, or t. (Note: the stack size will be in bytes if no appropriate suffix is give.)")
public static final OptionKey<String> STACK_SIZE = new OptionKey<>("81920k");

public static final String LIBRARY_PATH_NAME = "llvm.libraryPath";
@Option(name = LIBRARY_PATH_NAME, category = OptionCategory.USER, stability = OptionStability.STABLE, //
Expand Down

0 comments on commit fe04394

Please sign in to comment.