Mercurial > hg > truffle
comparison truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/Truffle.java @ 22111:8b72dfac5cc7
Allow selecting the TruffleRuntime using a system property
author | Christian Wimmer <christian.wimmer@oracle.com> |
---|---|
date | Wed, 26 Aug 2015 14:39:11 -0700 |
parents | d5d416ced577 |
children | dc83cc1f94f2 |
comparison
equal
deleted
inserted
replaced
22106:3b2ae36a942f | 22111:8b72dfac5cc7 |
---|---|
42 public static TruffleRuntime getRuntime() { | 42 public static TruffleRuntime getRuntime() { |
43 return RUNTIME; | 43 return RUNTIME; |
44 } | 44 } |
45 | 45 |
46 private static TruffleRuntime initRuntime() { | 46 private static TruffleRuntime initRuntime() { |
47 if (TruffleOptions.ForceInterpreter) { | |
48 /* | |
49 * Force Truffle to run in interpreter mode even if we have a specialized implementation | |
50 * of TruffleRuntime available. | |
51 */ | |
52 return new DefaultTruffleRuntime(); | |
53 } | |
54 | |
55 return AccessController.doPrivileged(new PrivilegedAction<TruffleRuntime>() { | 47 return AccessController.doPrivileged(new PrivilegedAction<TruffleRuntime>() { |
56 public TruffleRuntime run() { | 48 public TruffleRuntime run() { |
49 String runtimeClassName = System.getProperty("truffle.TruffleRuntime"); | |
50 if (runtimeClassName != null) { | |
51 try { | |
52 ClassLoader cl = Thread.currentThread().getContextClassLoader(); | |
53 Class<?> runtimeClass = Class.forName(runtimeClassName, false, cl); | |
54 return (TruffleRuntime) runtimeClass.newInstance(); | |
55 } catch (Throwable e) { | |
56 // Fail fast for other errors | |
57 throw (InternalError) new InternalError().initCause(e); | |
58 } | |
59 } | |
60 | |
57 TruffleRuntimeAccess access = null; | 61 TruffleRuntimeAccess access = null; |
58 Class<?> servicesClass = null; | 62 Class<?> servicesClass = null; |
59 try { | 63 try { |
60 servicesClass = Class.forName("jdk.internal.jvmci.service.Services"); | 64 servicesClass = Class.forName("jdk.internal.jvmci.service.Services"); |
61 } catch (ClassNotFoundException e) { | 65 } catch (ClassNotFoundException e) { |
75 // Fail fast for other errors | 79 // Fail fast for other errors |
76 throw (InternalError) new InternalError().initCause(e); | 80 throw (InternalError) new InternalError().initCause(e); |
77 } | 81 } |
78 } | 82 } |
79 // TODO: try standard ServiceLoader? | 83 // TODO: try standard ServiceLoader? |
84 | |
80 if (access != null) { | 85 if (access != null) { |
81 return access.getRuntime(); | 86 return access.getRuntime(); |
82 } | 87 } |
83 return new DefaultTruffleRuntime(); | 88 return new DefaultTruffleRuntime(); |
84 } | 89 } |