Save This Page
Home » openjdk-7 » sun » misc » [javadoc | source]
    1   /*
    2    * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
    3    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    4    *
    5    * This code is free software; you can redistribute it and/or modify it
    6    * under the terms of the GNU General Public License version 2 only, as
    7    * published by the Free Software Foundation.  Sun designates this
    8    * particular file as subject to the "Classpath" exception as provided
    9    * by Sun in the LICENSE file that accompanied this code.
   10    *
   11    * This code is distributed in the hope that it will be useful, but WITHOUT
   12    * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   13    * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   14    * version 2 for more details (a copy is included in the LICENSE file that
   15    * accompanied this code).
   16    *
   17    * You should have received a copy of the GNU General Public License version
   18    * 2 along with this work; if not, write to the Free Software Foundation,
   19    * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   20    *
   21    * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   22    * CA 95054 USA or visit www.sun.com if you need additional information or
   23    * have any questions.
   24    */
   25   
   26   package sun.misc;
   27   
   28   import java.io.File;
   29   import java.io.IOException;
   30   
   31   /**
   32    * BootClassLoaderHook defines an interface for a hook to inject
   33    * into the bootstrap class loader.
   34    *
   35    * In jkernel build, the sun.jkernel.DownloadManager is set as
   36    * a BootClassLoaderHook by the jkernel VM after the VM is initialized.
   37    *
   38    * In other JDK builds, no hook is set.
   39    */
   40   public abstract class BootClassLoaderHook {
   41       private static BootClassLoaderHook bootLoaderHook = null;
   42       public static synchronized BootClassLoaderHook getHook() {
   43           return bootLoaderHook;
   44       }
   45   
   46       public static synchronized void setHook(BootClassLoaderHook hook) {
   47           if (!VM.isBooted()) {
   48               throw new InternalError("hook can only be set after VM is booted");
   49           }
   50           if (bootLoaderHook != null) {
   51               throw new InternalError("hook should not be reinitialized");
   52           }
   53           bootLoaderHook = hook;
   54       }
   55   
   56       protected BootClassLoaderHook() {
   57       }
   58   
   59       /**
   60        * A method to be invoked before a class loader loads
   61        * a bootstrap class.
   62        *
   63        * @param classname the binary name of the class
   64        */
   65       public static void preLoadClass(String classname) {
   66           BootClassLoaderHook hook = getHook();
   67           if (hook != null) {
   68               hook.loadBootstrapClass(classname);
   69           }
   70       }
   71   
   72       /**
   73        * A method to be invoked before a class loader loads
   74        * a resource.
   75        *
   76        * @param resourcename the resource name
   77        */
   78       public static void preLoadResource(String resourcename) {
   79           BootClassLoaderHook hook = getHook();
   80           if (hook != null) {
   81               hook.getBootstrapResource(resourcename);
   82           }
   83       }
   84   
   85       /**
   86        * A method to be invoked before a library is loaded.
   87        *
   88        * @param libname the name of the library
   89        */
   90       public static void preLoadLibrary(String libname) {
   91           BootClassLoaderHook hook = getHook();
   92           if (hook != null) {
   93               hook.loadLibrary(libname);
   94           }
   95       }
   96   
   97       private static final File[] EMPTY_FILE_ARRAY = new File[0];
   98   
   99       /**
  100        * Returns bootstrap class paths added by the hook.
  101        */
  102       public static File[] getBootstrapPaths() {
  103           BootClassLoaderHook hook = getHook();
  104           if (hook != null) {
  105               return hook.getAdditionalBootstrapPaths();
  106           } else {
  107               return EMPTY_FILE_ARRAY;
  108           }
  109       }
  110   
  111       /**
  112        * Returns a pathname of a JAR or class that the hook loads
  113        * per this loadClass request; or null.
  114        *
  115        * @param classname the binary name of the class
  116        */
  117       public abstract String loadBootstrapClass(String className);
  118   
  119       /**
  120        * Returns a pathname of a resource file that the hook loads
  121        * per this getResource request; or null.
  122        *
  123        * @param resourceName the resource name
  124        */
  125       public abstract String getBootstrapResource(String resourceName);
  126   
  127       /**
  128        * Returns true if the hook successfully performs an operation per
  129        * this loadLibrary request; or false if it fails.
  130        *
  131        * @param libname the name of the library
  132        */
  133       public abstract boolean loadLibrary(String libname);
  134   
  135       /**
  136        * Returns additional boot class paths added by the hook that
  137        * should be searched by the boot class loader.
  138        */
  139       public abstract File[] getAdditionalBootstrapPaths();
  140   
  141       /**
  142        * Returns true if the current thread is in the process of doing
  143        * a prefetching operation.
  144        */
  145       public abstract boolean isCurrentThreadPrefetching();
  146   
  147       /**
  148        * Returns true if the hook successfully prefetches the specified file.
  149        *
  150        * @param name a platform independent pathname
  151        */
  152       public abstract boolean prefetchFile(String name);
  153   }

Save This Page
Home » openjdk-7 » sun » misc » [javadoc | source]