# HG changeset patch # User Doug Simon # Date 1382370139 -7200 # Node ID 128bf29518a037ad221f894ef8788ed0353a243f # Parent 0806a46dced5690fa019fa9fb05a3c984f1e976a added limited ability for one HotSpotBackendFactory to override another diff -r 0806a46dced5 -r 128bf29518a0 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java Mon Oct 21 17:41:27 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java Mon Oct 21 17:42:19 2013 +0200 @@ -105,11 +105,11 @@ for (HotSpotBackendFactory factory : ServiceLoader.loadInstalled(HotSpotBackendFactory.class)) { if (factory.getArchitecture().equalsIgnoreCase(architecture)) { if (factory.getGraalRuntimeName().equals(GraalRuntime.getValue())) { - assert selected == null; + assert selected == null || checkFactoryOverriding(selected, factory); selected = factory; } if (factory.getGraalRuntimeName().equals("basic")) { - assert basic == null; + assert basic == null || checkFactoryOverriding(basic, factory); basic = factory; } else { nonBasic = factory; @@ -135,6 +135,18 @@ } /** + * Checks that a factory overriding is valid. A factory B can only override/replace a factory A + * if the B.getClass() is a subclass of A.getClass(). This models the assumption that B is + * extends the behavior of A and has therefore understood the behavior expected of A. + * + * @param baseFactory + * @param overridingFactory + */ + private static boolean checkFactoryOverriding(HotSpotBackendFactory baseFactory, HotSpotBackendFactory overridingFactory) { + return baseFactory.getClass().isAssignableFrom(overridingFactory.getClass()); + } + + /** * Gets the kind of a word value on the {@linkplain #getHostBackend() host} backend. */ public static Kind getHostWordKind() {