6818072: Load Ductus using Class.forName if exist instead of using the service loader
authormchung
Tue, 14 Apr 2009 17:43:45 -0700
changeset 1181e61d93fc8ed1
parent 1180 e3b4eb55a696
child 1182 d609ae2faac2
6818072: Load Ductus using Class.forName if exist instead of using the service loader
Summary: First attempt Class.forName to load Ductus class before using service loader
Reviewed-by: flar, prr
src/share/classes/sun/java2d/pipe/RenderingEngine.java
     1.1 --- a/src/share/classes/sun/java2d/pipe/RenderingEngine.java	Wed Apr 08 15:40:56 2009 -0700
     1.2 +++ b/src/share/classes/sun/java2d/pipe/RenderingEngine.java	Tue Apr 14 17:43:45 2009 -0700
     1.3 @@ -95,6 +95,11 @@
     1.4       * <pre>
     1.5       *     java -Dsun.java2d.renderer=&lt;classname&gt;
     1.6       * </pre>
     1.7 +     *
     1.8 +     * If no specific {@code RenderingEngine} is specified on the command
     1.9 +     * or Ductus renderer is specified, it will attempt loading the
    1.10 +     * sun.dc.DuctusRenderingEngine class using Class.forName as a fastpath;
    1.11 +     * if not found, use the ServiceLoader.
    1.12       * If no specific {@code RenderingEngine} is specified on the command
    1.13       * line then the last one returned by enumerating all subclasses of
    1.14       * {@code RenderingEngine} known to the ServiceLoader is used.
    1.15 @@ -115,9 +120,21 @@
    1.16          reImpl = (RenderingEngine)
    1.17              AccessController.doPrivileged(new PrivilegedAction() {
    1.18                  public Object run() {
    1.19 +                    final String ductusREClass = "sun.dc.DuctusRenderingEngine";
    1.20                      String reClass =
    1.21 -                        System.getProperty("sun.java2d.renderer",
    1.22 -                                           "sun.dc.DuctusRenderingEngine");
    1.23 +                        System.getProperty("sun.java2d.renderer", ductusREClass);
    1.24 +                    if (reClass.equals(ductusREClass)) {
    1.25 +                        try {
    1.26 +                            Class cls = Class.forName(ductusREClass);
    1.27 +                            return cls.newInstance();
    1.28 +                        } catch (ClassNotFoundException x) {
    1.29 +                            // not found
    1.30 +                        } catch (IllegalAccessException x) {
    1.31 +                            // should not reach here
    1.32 +                        } catch (InstantiationException x) {
    1.33 +                            // should not reach here
    1.34 +                        }
    1.35 +                    }
    1.36  
    1.37                      ServiceLoader<RenderingEngine> reLoader =
    1.38                          ServiceLoader.loadInstalled(RenderingEngine.class);