⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 classloader.java

📁 gcc3.2.1源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
   *       compile-time constant initializer.   * <LI>  Create the internal representation of the ``vtable''.   * </UL>   * For <code>gcj</code>-compiled classes, only the first step is   * performed.  The compiler will have done the rest already.   * <P>   * This is called by the system automatically,   * as part of class initialization; there is no reason to ever call   * this method directly.     * <P>    * For historical reasons, this method has a name which is easily   * misunderstood.  Java classes are never ``resolved''.  Classes are   * linked; whereas method and field references are resolved.   *   * @param     clazz the class to link.   * @exception java.lang.LinkageError   */  protected final void resolveClass(Class clazz)  {    resolveClass0(clazz);  }  static void resolveClass0(Class clazz)  {    synchronized (clazz)      {	try {	  linkClass0 (clazz);	} catch (Throwable x) {	  markClassErrorState0 (clazz);	  if (x instanceof Error)	    throw (Error)x;	  else    	    throw new java.lang.InternalError	      ("unexpected exception during linking: " + x);	}      }  }  /** Internal method.  Calls _Jv_PrepareClass and   * _Jv_PrepareCompiledClass.  This is only called from resolveClass.  */   private static native void linkClass0(Class clazz);  /** Internal method.  Marks the given clazz to be in an erroneous   * state, and calls notifyAll() on the class object.  This should only   * be called when the caller has the lock on the class object.  */  private static native void markClassErrorState0(Class clazz);  /**   * Defines a new package and creates a Package object.   * The package should be defined before any class in the package is   * defined with <code>defineClass()</code>. The package should not yet   * be defined before in this classloader or in one of its parents (which   * means that <code>getPackage()</code> should return <code>null</code>).   * All parameters except the <code>name</code> of the package may be   * <code>null</code>.   * <p>   * Subclasses should call this method from their <code>findClass()</code>   * implementation before calling <code>defineClass()</code> on a Class   * in a not yet defined Package (which can be checked by calling   * <code>getPackage()</code>).   *   * @param name The name of the Package   * @param specTitle The name of the specification   * @param specVendor The name of the specification designer   * @param specVersion The version of this specification   * @param implTitle The name of the implementation   * @param implVendor The vendor that wrote this implementation   * @param implVersion The version of this implementation   * @param sealed If sealed the origin of the package classes   * @return the Package object for the specified package   *   * @exception IllegalArgumentException if the package name is null or if   * it was already defined by this classloader or one of its parents.   *   * @see Package   * @since 1.2   */  protected Package definePackage(String name,				  String specTitle, String specVendor,				  String specVersion, String implTitle,				  String implVendor, String implVersion,				  URL sealed)  {    if (getPackage(name) != null)      throw new IllegalArgumentException("Package " + name					 + " already defined");    Package p = new Package(name,			    specTitle, specVendor, specVersion,			    implTitle, implVendor, implVersion,			    sealed);    synchronized (definedPackages)    {      definedPackages.put(name, p);    }    return p;  }  /**   * Returns the Package object for the requested package name. It returns   * null when the package is not defined by this classloader or one of its   * parents.   *   * @since 1.2   */  protected Package getPackage(String name)  {    Package p;    if (parent == null)      // XXX - Should we use the bootstrap classloader?      p = null;    else      p = parent.getPackage(name);    if (p == null)      {        synchronized (definedPackages)	{	  p = (Package) definedPackages.get(name);	}      }    return p;  }  /**   * Returns all Package objects defined by this classloader and its parents.   *   * @since 1.2   */  protected Package[] getPackages()  {    Package[] allPackages;    // Get all our packages.    Package[] packages;    synchronized(definedPackages)    {      packages = new Package[definedPackages.size()];      definedPackages.values().toArray(packages);    }    // If we have a parent get all packages defined by our parents.    if (parent != null)      {	Package[] parentPackages = parent.getPackages();	allPackages = new Package[parentPackages.length + packages.length];	System.arraycopy(parentPackages, 0, allPackages, 0,			 parentPackages.length);	System.arraycopy(packages, 0, allPackages, parentPackages.length,			 packages.length);      }    else      // XXX - Should we use the bootstrap classloader?      allPackages = packages;    return allPackages;  }  /**    * Returns a class found in a system-specific way, typically   * via the <code>java.class.path</code> system property.  Loads the    * class if necessary.   *   * @param     name the class to resolve.   * @return    the class loaded.   * @exception java.lang.LinkageError    * @exception java.lang.ClassNotFoundException    */  protected final Class findSystemClass(String name)     throws java.lang.ClassNotFoundException  {    return gnu.gcj.runtime.VMClassLoader.instance.loadClass (name);  }  /*   * Does currently nothing. FIXME.   */   protected final void setSigners(Class claz, Object[] signers) {    /* claz.setSigners (signers); */  }  /**   * If a class named <code>name</code> was previously loaded using   * this <code>ClassLoader</code>, then it is returned.  Otherwise   * it returns <code>null</code>.  (Unlike the JDK this is native,   * since we implement the class table internally.)   * @param     name  class to find.   * @return    the class loaded, or null.   */   protected final native Class findLoadedClass(String name);  public static InputStream getSystemResourceAsStream(String name) {    return getSystemClassLoader().getResourceAsStream (name);  }  public static URL getSystemResource(String name) {    return getSystemClassLoader().getResource (name);  }  /**   *   Return an InputStream representing the resource name.     *   This is essentially like    *   <code>getResource(name).openStream()</code>, except   *   it masks out any IOException and returns null on failure.   * @param   name  resource to load   * @return  an InputStream, or null   * @see     java.lang.ClassLoader#getResource(String)   * @see     java.io.InputStream   */  public InputStream getResourceAsStream(String name)   {    try {      URL res = getResource (name);      if (res == null) return null;      return res.openStream ();    } catch (java.io.IOException x) {      return null;    }  }   /**   * Return an java.io.URL representing the resouce <code>name</code>.     * The default implementation just returns <code>null</code>.   * @param   name  resource to load   * @return  a URL, or null if there is no such resource.   * @see     java.lang.ClassLoader#getResourceAsBytes(String)   * @see     java.lang.ClassLoader#getResourceAsStream(String)   * @see     java.io.URL   */  public URL getResource (String name)   {    // The rules say search the parent class if non-null,    // otherwise search the built-in class loader (assumed to be    // the system ClassLoader).  If not found, call    // findResource().    URL result = null;    ClassLoader delegate = parent;    if (delegate == null)      delegate = getSystemClassLoader ();	    // Protect ourselves from looping.    if (this != delegate)      result = delegate.getResource (name);    if (result != null)      return result;    else      return findResource (name);  }  protected URL findResource (String name)  {    // Default to returning null.  Derived classes implement this.    return null;  }  public final Enumeration getResources (String name) throws IOException  {    // The rules say search the parent class if non-null,    // otherwise search the built-in class loader (assumed to be    // the system ClassLoader).  If not found, call    // findResource().    Enumeration result = null;    ClassLoader delegate = parent;    if (delegate == null)      delegate = getSystemClassLoader ();	    // Protect ourselves from looping.    if (this != delegate)      result = delegate.getResources (name);    if (result != null)      return result;    else      return findResources (name);  }  protected Enumeration findResources (String name) throws IOException  {    // Default to returning null.  Derived classes implement this.    return null;  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -