Skip to content

Commit

Permalink
[Truffle] Use some static options for now.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisseaton committed Dec 3, 2016
1 parent 2b0b653 commit 352db68
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
7 changes: 5 additions & 2 deletions truffle/src/main/java/org/jruby/truffle/Main.java
Expand Up @@ -56,6 +56,9 @@

public class Main {

private static final boolean METRICS_TIME = OptionsBuilder.readSystemProperty(OptionsCatalog.METRICS_TIME);
private static final boolean METRICS_MEMORY_USED_ON_EXIT = OptionsBuilder.readSystemProperty(OptionsCatalog.METRICS_MEMORY_USED_ON_EXIT);

public static void main(String[] args) {
printTruffleTimeMetric("before-main");

Expand Down Expand Up @@ -130,15 +133,15 @@ private static void doShowVersion(RubyInstanceConfig config) {
}

public static void printTruffleTimeMetric(String id) {
if (OptionsBuilder.readSystemProperty(OptionsCatalog.METRICS_TIME)) {
if (METRICS_TIME) {
final long millis = System.currentTimeMillis();
System.err.printf("%s %d.%03d%n", id, millis / 1000, millis % 1000);
}
}

private static void printTruffleMemoryMetric() {
// Memory stats aren't available on AOT.
if (!TruffleOptions.AOT && (boolean) OptionsBuilder.readSystemProperty(OptionsCatalog.METRICS_MEMORY_USED_ON_EXIT)) {
if (!TruffleOptions.AOT && METRICS_MEMORY_USED_ON_EXIT) {
for (int n = 0; n < 10; n++) {
System.gc();
}
Expand Down
Expand Up @@ -95,7 +95,7 @@ public static DynamicObject createThreadLocals(RubyContext context) {
}

public static void initialize(final DynamicObject thread, RubyContext context, Node currentNode, final Object[] arguments, final DynamicObject block) {
if (OptionsBuilder.readSystemProperty(OptionsCatalog.SHARED_OBJECTS_ENABLED)) {
if (SharedObjects.ENABLED) {
SharedObjects.shareDeclarationFrame(block);
}

Expand Down Expand Up @@ -333,7 +333,7 @@ public synchronized void registerThread(DynamicObject thread) {
initializeCurrentThread(thread);
runningRubyThreads.add(thread);

if ((boolean) OptionsBuilder.readSystemProperty(OptionsCatalog.SHARED_OBJECTS_ENABLED) && runningRubyThreads.size() > 1) {
if (SharedObjects.ENABLED && runningRubyThreads.size() > 1) {
context.getSharedObjects().startSharing();
SharedObjects.writeBarrier(thread);
}
Expand Down
Expand Up @@ -94,7 +94,7 @@ public Object execute(VirtualFrame frame) {
final Object value = callNode.call(frame, arguments);

// The return value will be leaked to Java, share it.
if ((boolean) OptionsBuilder.readSystemProperty(OptionsCatalog.SHARED_OBJECTS_ENABLED)) {
if (SharedObjects.ENABLED) {
SharedObjects.writeBarrier(value);
}

Expand Down
Expand Up @@ -26,6 +26,11 @@

public class SharedObjects {

// TODO CS 3-Dec-16 these shouldn't be static
public static final boolean ENABLED = OptionsBuilder.readSystemProperty(OptionsCatalog.SHARED_OBJECTS_ENABLED);
public static final boolean SHARE_ALL = OptionsBuilder.readSystemProperty(OptionsCatalog.SHARED_OBJECTS_SHARE_ALL);
public static final boolean DEBUG = OptionsBuilder.readSystemProperty(OptionsCatalog.SHARED_OBJECTS_DEBUG);

private final RubyContext context;
// No need for volatile since we change this before starting the 2nd Thread
private boolean sharing = false;
Expand Down Expand Up @@ -69,7 +74,7 @@ private static void shareContextRoots(RubyContext context) {
public static void shareDeclarationFrame(DynamicObject block) {
final Deque<DynamicObject> stack = new ArrayDeque<>();

if ((boolean) OptionsBuilder.readSystemProperty(OptionsCatalog.SHARED_OBJECTS_DEBUG)) {
if (DEBUG) {
final SourceSection sourceSection = Layouts.PROC.getSharedMethodInfo(block).getSourceSection();
System.err.println("Sharing decl frame of " + SourceSectionUtils.fileLine(sourceSection));
}
Expand Down Expand Up @@ -102,11 +107,11 @@ public static boolean isShared(DynamicObject object) {
}

public static boolean isShared(Shape shape) {
return (boolean) OptionsBuilder.readSystemProperty(OptionsCatalog.SHARED_OBJECTS_ENABLED) && ((boolean) OptionsBuilder.readSystemProperty(OptionsCatalog.SHARED_OBJECTS_SHARE_ALL) || shape.isShared());
return ENABLED && (SHARE_ALL || shape.isShared());
}

public static void writeBarrier(Object value) {
if ((boolean) OptionsBuilder.readSystemProperty(OptionsCatalog.SHARED_OBJECTS_ENABLED) && value instanceof DynamicObject && !isShared((DynamicObject) value)) {
if (ENABLED && value instanceof DynamicObject && !isShared((DynamicObject) value)) {
shareObject(value);
}
}
Expand Down

0 comments on commit 352db68

Please sign in to comment.