Skip to content

Commit

Permalink
[Truffle] Use number of back-jumps as well as invocations for compila…
Browse files Browse the repository at this point in the history
…tion threshold.
  • Loading branch information
chrisseaton committed Feb 8, 2014
1 parent 92ac436 commit 0db48a6
Showing 1 changed file with 35 additions and 14 deletions.
49 changes: 35 additions & 14 deletions core/src/main/java/org/jruby/truffle/nodes/control/WhileNode.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved. This
* Copyright (c) 2013, 2014 Oracle and/or its affiliates. All rights reserved. This
* code is released under a tri EPL/GPL/LGPL license. You can use it,
* redistribute it and/or modify it under the terms of the:
*
Expand Down Expand Up @@ -39,24 +39,45 @@ public WhileNode(RubyContext context, SourceSection sourceSection, BooleanCastNo

@Override
public Object execute(VirtualFrame frame) {
outer: while (condition.executeBoolean(frame)) {
while (true) {
try {
body.execute(frame);
continue outer;
} catch (BreakException e) {
breakProfile.enter();
return e.getResult();
} catch (NextException e) {
nextProfile.enter();
continue outer;
} catch (RedoException e) {
redoProfile.enter();
int count = 0;

try {
outer: while (condition.executeBoolean(frame)) {
while (true) {
try {
body.execute(frame);

if (CompilerDirectives.inInterpreter()) {
count++;
}

continue outer;
} catch (BreakException e) {
breakProfile.enter();
return e.getResult();
} catch (NextException e) {
nextProfile.enter();
continue outer;
} catch (RedoException e) {
redoProfile.enter();
}
}
}
} finally {
if (CompilerDirectives.inInterpreter()) {
reportLoopCount(count);
}
}

return NilPlaceholder.INSTANCE;
}

private void reportLoopCount(int count) {
CompilerAsserts.neverPartOfCompilation();
RootNode root = NodeUtil.findOutermostRootNode(this);
if (root != null) {
root.reportLoopCount(count);
}
}

}

0 comments on commit 0db48a6

Please sign in to comment.