48
48
import org .jruby .ast .GlobalVarNode ;
49
49
import org .jruby .ast .VCallNode ;
50
50
import org .jruby .ast .WhileNode ;
51
- import org .jruby .compiler .Constantizable ;
52
- import org .jruby .compiler .NotCompilableException ;
53
51
import org .jruby .ext .thread .ThreadLibrary ;
54
52
import org .jruby .ir .IRScriptBody ;
55
53
import org .jruby .javasupport .JavaSupport ;
56
54
import org .jruby .javasupport .JavaSupportImpl ;
57
55
import org .jruby .lexer .yacc .ISourcePosition ;
58
56
import org .jruby .parser .StaticScope ;
59
- import org .jruby .util .ClassDefiningClassLoader ;
60
57
import org .objectweb .asm .util .TraceClassVisitor ;
61
58
62
59
import jnr .constants .Constant ;
75
72
import org .jruby .ast .executable .ScriptAndCode ;
76
73
import org .jruby .common .IRubyWarnings .ID ;
77
74
import org .jruby .common .RubyWarnings ;
78
- import org .jruby .compiler .JITCompiler ;
79
75
import org .jruby .embed .Extension ;
80
76
import org .jruby .exceptions .JumpException ;
81
77
import org .jruby .exceptions .MainExitException ;
94
90
import org .jruby .internal .runtime .methods .CallConfiguration ;
95
91
import org .jruby .internal .runtime .methods .DynamicMethod ;
96
92
import org .jruby .internal .runtime .methods .JavaMethod ;
97
- import org .jruby .ir .Compiler ;
98
93
import org .jruby .ir .IRManager ;
99
94
import org .jruby .ir .interpreter .Interpreter ;
100
95
import org .jruby .ir .persistence .IRReader ;
104
99
import org .jruby .management .BeanManager ;
105
100
import org .jruby .management .BeanManagerFactory ;
106
101
import org .jruby .management .Config ;
102
+ import org .jruby .management .JITCompiler ;
107
103
import org .jruby .management .ParserStats ;
108
104
import org .jruby .parser .Parser ;
109
105
import org .jruby .parser .ParserConfiguration ;
@@ -280,9 +276,36 @@ private Ruby(RubyInstanceConfig config) {
280
276
objectSpacer = DISABLED_OBJECTSPACE ;
281
277
}
282
278
279
+ this .interpreter = new Interpreter (this );
280
+
281
+ if (getInstanceConfig ().getCompileMode ().shouldJIT ()) {
282
+ final Class <?> clazz ;
283
+
284
+ try {
285
+ clazz = getJRubyClassLoader ().loadClass ("org.jruby.ir.Compiler" );
286
+ } catch (Exception e ) {
287
+ throw new RuntimeException ("Compiler not available" , e );
288
+ }
289
+
290
+ try {
291
+ Constructor <?> con = clazz .getConstructor (Ruby .class );
292
+ compiler = (org .jruby .Compiler ) con .newInstance (this );
293
+ } catch (Exception e ) {
294
+ throw new RuntimeException ("Error while calling the constructor of IR Compiler" , e );
295
+ }
296
+ } else {
297
+ compiler = null ;
298
+ }
299
+
283
300
reinitialize (false );
284
301
}
285
302
303
+ private final org .jruby .Compiler compiler ;
304
+
305
+ public Compiler getCompiler () {
306
+ return compiler ;
307
+ }
308
+
286
309
public void registerMBeans () {
287
310
this .beanManager .register (jitCompiler );
288
311
this .beanManager .register (configBean );
@@ -471,7 +494,7 @@ public IRubyObject evalScriptlet(String script, DynamicScope scope) {
471
494
context .preEvalScriptlet (scope );
472
495
473
496
try {
474
- return Interpreter . getInstance () .execute (this , rootNode , context .getFrameSelf ());
497
+ return interpreter .execute (this , rootNode , context .getFrameSelf ());
475
498
} finally {
476
499
context .postEvalScriptlet ();
477
500
}
@@ -651,7 +674,7 @@ public IRubyObject runWithGetsLoop(Node scriptNode, boolean printing, boolean pr
651
674
boolean compile = getInstanceConfig ().getCompileMode ().shouldPrecompileCLI ();
652
675
if (compile ) {
653
676
try {
654
- script = tryCompile (scriptNode );
677
+ script = compiler . tryCompile (scriptNode );
655
678
if (Options .JIT_LOGGING .load ()) {
656
679
LOG .info ("Successfully compiled: " + scriptNode .getPosition ().getFile ());
657
680
}
@@ -764,7 +787,7 @@ private ScriptAndCode precompileCLI(Node scriptNode) {
764
787
// IR JIT does not handle all scripts yet, so let those that fail run in interpreter instead
765
788
// FIXME: restore error once JIT should handle everything
766
789
try {
767
- scriptAndCode = tryCompile (scriptNode , new ClassDefiningJRubyClassLoader (getJRubyClassLoader ()));
790
+ scriptAndCode = compiler . tryCompile (scriptNode , new ClassDefiningJRubyClassLoader (getJRubyClassLoader ()));
768
791
if (scriptAndCode != null && Options .JIT_LOGGING .load ()) {
769
792
LOG .info ("done compiling target script: " + scriptNode .getPosition ().getFile ());
770
793
}
@@ -779,18 +802,6 @@ private ScriptAndCode precompileCLI(Node scriptNode) {
779
802
return scriptAndCode ;
780
803
}
781
804
782
- /**
783
- * Try to compile the code associated with the given Node, returning an
784
- * instance of the successfully-compiled Script or null if the script could
785
- * not be compiled.
786
- *
787
- * @param node The node to attempt to compiled
788
- * @return an instance of the successfully-compiled Script, or null.
789
- */
790
- public Script tryCompile (Node node ) {
791
- return tryCompile (node , new ClassDefiningJRubyClassLoader (getJRubyClassLoader ())).script ();
792
- }
793
-
794
805
private void failForcedCompile (Node scriptNode ) throws RaiseException {
795
806
if (config .getCompileMode ().shouldPrecompileAll ()) {
796
807
throw newRuntimeError ("could not compile and compile mode is 'force': " + scriptNode .getPosition ().getFile ());
@@ -804,20 +815,6 @@ private void handeCompileError(Node node, Throwable t) {
804
815
}
805
816
}
806
817
807
- private ScriptAndCode tryCompile (Node node , ClassDefiningClassLoader classLoader ) {
808
- try {
809
- return Compiler .getInstance ().execute (this , node , classLoader );
810
- } catch (NotCompilableException e ) {
811
- if (Options .JIT_LOGGING .load ()) {
812
- LOG .error ("failed to compile target script " + node .getPosition ().getFile () + ": " + e .getLocalizedMessage ());
813
- if (Options .JIT_LOGGING_VERBOSE .load ()) {
814
- LOG .error (e );
815
- }
816
- }
817
- return null ;
818
- }
819
- }
820
-
821
818
public IRubyObject runScript (Script script ) {
822
819
return runScript (script , false );
823
820
}
@@ -856,7 +853,7 @@ public IRubyObject runInterpreter(ThreadContext context, ParseResult parseResult
856
853
}
857
854
858
855
try {
859
- return Interpreter . getInstance () .execute (this , parseResult , self );
856
+ return interpreter .execute (this , parseResult , self );
860
857
} catch (JumpException .ReturnJump rj ) {
861
858
return (IRubyObject ) rj .getValue ();
862
859
}
@@ -874,7 +871,7 @@ public IRubyObject runInterpreter(ThreadContext context, Node rootNode, IRubyObj
874
871
try {
875
872
876
873
// FIXME: retrieve from IRManager unless lifus does it later
877
- return Interpreter . getInstance () .execute (this , rootNode , self );
874
+ return interpreter .execute (this , rootNode , self );
878
875
} catch (JumpException .ReturnJump rj ) {
879
876
return (IRubyObject ) rj .getValue ();
880
877
}
@@ -2981,7 +2978,7 @@ public void compileAndLoadFile(String filename, InputStream in, boolean wrap) {
2981
2978
// script was not found in cache above, so proceed to compile
2982
2979
Node scriptNode = parseFile (readStream , filename , null );
2983
2980
if (script == null ) {
2984
- scriptAndCode = tryCompile (scriptNode , new ClassDefiningJRubyClassLoader (jrubyClassLoader ));
2981
+ scriptAndCode = compiler . tryCompile (scriptNode , new ClassDefiningJRubyClassLoader (jrubyClassLoader ));
2985
2982
if (scriptAndCode != null ) script = scriptAndCode .script ();
2986
2983
}
2987
2984
@@ -3058,6 +3055,8 @@ public JavaProxyClassFactory getJavaProxyClassFactory() {
3058
3055
return javaProxyClassFactory ;
3059
3056
}
3060
3057
3058
+ private final Interpreter interpreter ;
3059
+
3061
3060
public class CallTraceFuncHook extends EventHook {
3062
3061
private RubyProc traceFunc ;
3063
3062
private EnumSet <RubyEvent > interest =
@@ -4775,7 +4774,7 @@ private void setNetworkStack() {
4775
4774
}
4776
4775
4777
4776
/**
4778
- * @see org.jruby.compiler. Constantizable
4777
+ * @see Constantizable
4779
4778
*/
4780
4779
@ Override
4781
4780
public Object constant () {
0 commit comments