Skip to content

Commit 9ac8dfa

Browse files
committed
Merge branch 'master' into truffle-head
2 parents 7fd5d0e + 89b288b commit 9ac8dfa

File tree

102 files changed

+810
-1090
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+810
-1090
lines changed

.gitignore

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,9 @@ dependency-reduced-pom.xml
7979
install/updates.xml
8080

8181
# generated ITs
82-
maven/jruby/src/it/osgi_*equinox*
83-
maven/jruby/src/it/osgi_*felix-3*
84-
maven/jruby/src/it/osgi_*knoplerfish
82+
maven/jruby/src/it/osgi_*
8583
maven/jruby/src/it/j2ee_wlp
86-
maven/jruby-complete/src/it/osgi_many_bundles_with_embedded_gems_*
84+
maven/jruby-complete/src/it/osgi*
8785

8886
# IntelliJ project files
8987
.idea

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ matrix:
4242
jdk: oraclejdk7
4343
- env: TARGET='-Pcomplete'
4444
jdk: oraclejdk8
45+
- env: TARGET='-Posgi'
46+
jdk: openjdk7
47+
- env: TARGET='-Pj2ee'
48+
jdk: oraclejdk7
4549
fast_finish: true
4650
allow_failures:
4751
- env: TARGET='-Prake -Dtask=spec:compiler'

core/pom.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@
259259
end
260260

261261

262-
[ :dist, :'jruby-jars', :main, :all, :complete, :release, :snapshots ].each do |name|
262+
[ :osgi, :dist, :'jruby-jars', :main, :all, :complete, :release, :snapshots ].each do |name|
263263
profile name do
264264
plugin :shade do
265265
execute_goals( 'shade',

core/pom.xml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,63 @@
555555
</plugins>
556556
</build>
557557
<profiles>
558+
<profile>
559+
<id>osgi</id>
560+
<build>
561+
<plugins>
562+
<plugin>
563+
<artifactId>maven-shade-plugin</artifactId>
564+
<executions>
565+
<execution>
566+
<id>pack jruby-core-noasm.jar</id>
567+
<phase>verify</phase>
568+
<goals>
569+
<goal>shade</goal>
570+
</goals>
571+
<configuration>
572+
<shadedArtifactAttached>true</shadedArtifactAttached>
573+
<shadedClassifierName>noasm</shadedClassifierName>
574+
<artifactSet>
575+
<includes>
576+
<include>com.github.jnr:jnr-ffi</include>
577+
<include>org.ow2.asm:*</include>
578+
</includes>
579+
</artifactSet>
580+
<relocations>
581+
<relocation>
582+
<pattern>org.objectweb</pattern>
583+
<shadedPattern>org.jruby.org.objectweb</shadedPattern>
584+
</relocation>
585+
</relocations>
586+
</configuration>
587+
</execution>
588+
<execution>
589+
<id>pack jruby-core-complete.jar</id>
590+
<phase>verify</phase>
591+
<goals>
592+
<goal>shade</goal>
593+
</goals>
594+
<configuration>
595+
<shadedArtifactAttached>true</shadedArtifactAttached>
596+
<shadedClassifierName>complete</shadedClassifierName>
597+
<relocations>
598+
<relocation>
599+
<pattern>org.objectweb</pattern>
600+
<shadedPattern>org.jruby.org.objectweb</shadedPattern>
601+
</relocation>
602+
</relocations>
603+
<transformers>
604+
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
605+
<mainClass>org.jruby.Main</mainClass>
606+
</transformer>
607+
</transformers>
608+
</configuration>
609+
</execution>
610+
</executions>
611+
</plugin>
612+
</plugins>
613+
</build>
614+
</profile>
558615
<profile>
559616
<id>dist</id>
560617
<build>

core/src/main/java/org/jruby/ir/IRFlags.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,19 @@ public enum IRFlags {
4141
CAN_RECEIVE_NONLOCAL_RETURNS, // may receive a non-local return during execution
4242
HAS_BREAK_INSTRS, // contains at least one break
4343
HAS_END_BLOCKS, // has an end block. big de-opt flag
44-
HAS_EXPLICIT_CALL_PROTOCOL, // contains call protocol instrs. if so we don't need to manage bindings frame implicitly.
44+
HAS_EXPLICIT_CALL_PROTOCOL, // contains call protocol instrs => we don't need to manage bindings frame implicitly
4545
HAS_LOOPS, // has a loop
4646
HAS_NONLOCAL_RETURNS, // has a non-local return
4747
HAS_UNUSED_IMPLICIT_BLOCK_ARG,// Is %block implicit block arg unused?
4848
RECEIVES_CLOSURE_ARG, // This scope (or parent receives a closure
4949
RECEIVES_KEYWORD_ARGS, // receives keyword args
5050
REQUIRES_DYNSCOPE, // does this scope require a dynamic scope?
51-
USES_BACKREF_OR_LASTLINE, // Since backref ($~) and lastline ($_) vars are allocated space on the dynamic scope.
51+
USES_BACKREF_OR_LASTLINE, // Since backref ($~) and lastline ($_) vars are allocated space on the dynamic scope
5252
USES_EVAL, // calls eval
5353
USES_ZSUPER, // has zsuper instr
5454
REQUIRES_FRAME, // callee may read/write caller's frame elements
5555
REQUIRES_VISIBILITY, // callee may read/write caller's visibility
5656

5757
DYNSCOPE_ELIMINATED, // local var load/stores have been converted to tmp var accesses
58-
REUSE_PARENT_DYNSCOPE, // for clsoures -- reuse parent's dynscope
58+
REUSE_PARENT_DYNSCOPE, // for closures -- reuse parent's dynscope
5959
}

core/src/main/java/org/jruby/ir/IRManager.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
/**
1818
*/
1919
public class IRManager {
20-
public static String SAFE_COMPILER_PASSES = "LinearizeCFG";
21-
public static String DEFAULT_COMPILER_PASSES = "OptimizeTempVarsPass,LocalOptimizationPass,LinearizeCFG";
22-
public static String DEFAULT_JIT_PASSES = "AddLocalVarLoadStoreInstructions,AddCallProtocolInstructions,EnsureTempsAssigned,LinearizeCFG";
20+
public static String SAFE_COMPILER_PASSES = "";
21+
public static String DEFAULT_COMPILER_PASSES = "OptimizeTempVarsPass,LocalOptimizationPass";
22+
public static String DEFAULT_JIT_PASSES = "AddLocalVarLoadStoreInstructions,AddCallProtocolInstructions,EnsureTempsAssigned";
2323
public static String DEFAULT_INLINING_COMPILER_PASSES = "LocalOptimizationPass";
2424

2525
private int dummyMetaClassCount = 0;

core/src/main/java/org/jruby/ir/IRScope.java

Lines changed: 49 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.jruby.ir.passes.CompilerPass;
1212
import org.jruby.ir.passes.CompilerPassScheduler;
1313
import org.jruby.ir.passes.DeadCodeElimination;
14+
import org.jruby.ir.passes.OptimizeDynScopesPass;
1415
import org.jruby.ir.dataflow.analyses.StoreLocalVarPlacementProblem;
1516
import org.jruby.ir.dataflow.analyses.LiveVariablesProblem;
1617
import org.jruby.ir.passes.UnboxingPass;
@@ -105,6 +106,9 @@ public abstract class IRScope implements ParseResult {
105106
/** Map of name -> dataflow problem */
106107
private Map<String, DataFlowProblem> dfProbs;
107108

109+
/** What passes have been run on this scope? */
110+
private List<CompilerPass> executedPasses;
111+
108112
private Instr[] linearizedInstrArray;
109113
private List<BasicBlock> linearizedBBList;
110114
private Map<Integer, Integer> rescueMap;
@@ -163,6 +167,8 @@ protected IRScope(IRScope s, IRScope lexicalParent) {
163167
this.scopeId = globalScopeCount.getAndIncrement();
164168
this.relinearizeCFG = false;
165169

170+
this.executedPasses = new ArrayList<CompilerPass>();
171+
166172
setupLexicalContainment();
167173
}
168174

@@ -208,6 +214,8 @@ public IRScope(IRManager manager, IRScope lexicalParent, String name,
208214
this.scopeId = globalScopeCount.getAndIncrement();
209215
this.relinearizeCFG = false;
210216

217+
this.executedPasses = new ArrayList<CompilerPass>();
218+
211219
setupLexicalContainment();
212220
}
213221

@@ -538,6 +546,10 @@ private boolean isUnsafeScope() {
538546
return unsafeScope;
539547
}
540548

549+
public List<CompilerPass> getExecutedPasses() {
550+
return executedPasses;
551+
}
552+
541553
private void runCompilerPasses(List<CompilerPass> passes) {
542554
// SSS FIXME: Why is this again? Document this weirdness!
543555
// Forcibly clear out the shared eval-scope variable allocator each time this method executes
@@ -561,40 +573,28 @@ private void runCompilerPasses(List<CompilerPass> passes) {
561573

562574
CompilerPassScheduler scheduler = getManager().schedulePasses(passes);
563575
for (CompilerPass pass: scheduler) {
564-
if (pass.previouslyRun(this) == null) {
565-
pass.run(this);
566-
}
576+
pass.run(this);
567577
}
568578

569579
if (RubyInstanceConfig.IR_UNBOXING) {
570580
(new UnboxingPass()).run(this);
571581
}
572582
}
573583

574-
private void runDeadCodeAndVarLoadStorePasses() {
575-
// For scopes that don't require a dynamic scope,
576-
// inline-add lvar loads/store to tmp-var loads/stores.
584+
private void optimizeSimpleScopes() {
585+
// For safe scopes that don't require a dynamic scope,
586+
// run DCE since the analysis is less likely to be
587+
// stymied by escaped bindings.
577588
if (!isUnsafeScope() && !flags.contains(REQUIRES_DYNSCOPE)) {
578-
CompilerPass pass;
579-
pass = new DeadCodeElimination();
580-
if (pass.previouslyRun(this) == null) {
581-
pass.run(this);
582-
}
583-
584-
// This will run the simplified version of the pass
585-
// that doesn't require dataflow analysis and hence
586-
// can run on closures independent of enclosing scopes.
587-
pass = new AddLocalVarLoadStoreInstructions();
588-
if (pass.previouslyRun(this) == null) {
589-
((AddLocalVarLoadStoreInstructions)pass).eliminateLocalVars(this);
590-
setDataFlowSolution(StoreLocalVarPlacementProblem.NAME, new StoreLocalVarPlacementProblem());
591-
setDataFlowSolution(LiveVariablesProblem.NAME, null);
592-
}
589+
(new DeadCodeElimination()).run(this);
590+
(new OptimizeDynScopesPass()).run(this);
593591
}
594592
}
595593

596-
/** Run any necessary passes to get the IR ready for interpretation */
597-
public synchronized Instr[] prepareForInterpretation(boolean isLambda) {
594+
public void initScope(boolean isLambda) {
595+
// Reset linearization, if any exists
596+
resetLinearizationData();
597+
598598
// Build CFG and run compiler passes, if necessary
599599
if (getCFG() == null) {
600600
buildCFG();
@@ -615,41 +615,35 @@ public synchronized Instr[] prepareForInterpretation(boolean isLambda) {
615615
// Run DCE and var load/store passes where applicable
616616
// But, if we have been passed in a list of passes to run
617617
// on the commandline, skip this opt.
618-
runDeadCodeAndVarLoadStorePasses();
618+
optimizeSimpleScopes();
619619
}
620+
}
621+
622+
/** Run any necessary passes to get the IR ready for interpretation */
623+
public synchronized Instr[] prepareForInterpretation(boolean isLambda) {
624+
initScope(isLambda);
620625

621626
checkRelinearization();
622627

623628
if (linearizedInstrArray != null) return linearizedInstrArray;
624629

630+
// System.out.println("-- passes run for: " + this + " = " + java.util.Arrays.toString(executedPasses.toArray()));
631+
625632
// Linearize CFG, etc.
626633
return prepareInstructions();
627634
}
628635

629636
/* SSS FIXME: Do we need to synchronize on this? Cache this info in a scope field? */
630637
/** Run any necessary passes to get the IR ready for compilation */
631638
public synchronized List<BasicBlock> prepareForCompilation() {
632-
// Reset linearization, since we will add JIT-specific flow and instrs
633-
resetLinearizationData();
634-
635-
// Build CFG and run compiler passes, if necessary
636-
if (getCFG() == null) {
637-
buildCFG();
638-
}
639-
640-
// Add this always since we dont re-JIT a previously
641-
// JIT-ted closure. But, check if there are other
642-
// smarts available to us and eliminate adding this
643-
// code to every closure there is.
639+
// For lambdas, we need to add a global ensure block to catch
640+
// uncaught breaks and throw a LocalJumpError.
644641
//
645-
// Add a global ensure block to catch uncaught breaks
646-
// and throw a LocalJumpError.
647-
if (this instanceof IRClosure) {
648-
if (((IRClosure)this).addGEBForUncaughtBreaks()) {
649-
resetState();
650-
computeScopeFlags();
651-
}
652-
}
642+
// Since we dont re-JIT a previously JIT-ted closure,
643+
// mark all closures lambdas always. But, check if there are
644+
// other smarts available to us and eliminate adding
645+
// this code to every closure there is.
646+
initScope(this instanceof IRClosure);
653647

654648
runCompilerPasses(getManager().getJITPasses(this));
655649

@@ -1104,11 +1098,6 @@ public CFG cfg() {
11041098
return cfg;
11051099
}
11061100

1107-
public void resetDFProblemsState() {
1108-
dfProbs = new HashMap<String, DataFlowProblem>();
1109-
for (IRClosure c: nestedClosures) c.resetDFProblemsState();
1110-
}
1111-
11121101
public void resetState() {
11131102
relinearizeCFG = true;
11141103
linearizedInstrArray = null;
@@ -1127,8 +1116,17 @@ public void resetState() {
11271116
flags.remove(CAN_RECEIVE_NONLOCAL_RETURNS);
11281117
rescueMap = null;
11291118

1130-
// Reset dataflow problems state
1131-
resetDFProblemsState();
1119+
// Invalidate compiler pass state.
1120+
//
1121+
// SSS FIXME: This is to get around concurrent-modification issues
1122+
// since CompilerPass.invalidate modifies this, but some passes
1123+
// cannot be invalidated.
1124+
int i = 0;
1125+
while (i < executedPasses.size()) {
1126+
if (!executedPasses.get(i).invalidate(this)) {
1127+
i++;
1128+
}
1129+
}
11321130
}
11331131

11341132
public void inlineMethod(IRScope method, RubyModule implClass, int classToken, BasicBlock basicBlock, CallBase call, boolean cloneHost) {
@@ -1145,10 +1143,6 @@ public void inlineMethod(IRScope method, RubyModule implClass, int classToken, B
11451143
}
11461144
}
11471145

1148-
public void resetCFG() {
1149-
cfg = null;
1150-
}
1151-
11521146
/* Record a begin block -- not all scope implementations can handle them */
11531147
public void recordBeginBlock(IRClosure beginBlockClosure) {
11541148
throw new RuntimeException("BEGIN blocks cannot be added to: " + this.getClass().getName());

core/src/main/java/org/jruby/ir/instructions/CallBase.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,23 @@ public boolean computeScopeFlags(IRScope scope) {
164164
}
165165
}
166166

167+
// Kernel.local_variables inspects variables.
168+
// and JRuby implementation uses dyn-scope to access the static-scope
169+
// to output the local variables => we cannot strip dynscope in those cases.
170+
// FIXME: We need to decouple static-scope and dyn-scope.
171+
String mname = getMethodAddr().getName();
172+
if (mname.equals("local_variables")) {
173+
scope.getFlags().add(REQUIRES_DYNSCOPE);
174+
} else if (mname.equals("send") || mname.equals("__send__")) {
175+
Operand[] args = getCallArgs();
176+
if (args.length >= 1) {
177+
Operand meth = args[0];
178+
if (meth instanceof StringLiteral && "local_variables".equals(((StringLiteral)meth).string)) {
179+
scope.getFlags().add(REQUIRES_DYNSCOPE);
180+
}
181+
}
182+
}
183+
167184
return modifiedScope;
168185
}
169186
/**

core/src/main/java/org/jruby/ir/passes/AddCallProtocolInstructions.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
import java.util.ListIterator;
1616

1717
public class AddCallProtocolInstructions extends CompilerPass {
18-
boolean addedInstrs = false;
19-
2018
@Override
2119
public String getLabel() {
2220
return "Add Call Protocol Instructions (push/pop of dyn-scope, frame, impl-class values)";
@@ -157,22 +155,16 @@ public Object execute(IRScope scope, Object... data) {
157155
// Run on all nested closures.
158156
for (IRClosure c: scope.getClosures()) execute(c);
159157

160-
// Mark as done
161-
addedInstrs = true;
162-
163158
// LVA information is no longer valid after the pass
164-
scope.setDataFlowSolution(LiveVariablesProblem.NAME, null);
159+
// FIXME: Grrr ... this seems broken to have to create a new object to invalidate
160+
(new LiveVariableAnalysis()).invalidate(scope);
165161

166162
return null;
167163
}
168164

169165
@Override
170-
public Object previouslyRun(IRScope scope) {
171-
return addedInstrs ? new Object() : null;
172-
}
173-
174-
@Override
175-
public void invalidate(IRScope scope) {
166+
public boolean invalidate(IRScope scope) {
176167
// Cannot add call protocol instructions after we've added them once.
168+
return false;
177169
}
178170
}

0 commit comments

Comments
 (0)