Loads com.sun.tools.attach.VirtualMachine. (This method was implemented
in Hong Kong'14.)

@param toolsJarFile
Location of tools.jar
@return com.sun.tools.attach.VirtualMachine class
@throws Exception
If execution was not successful
344068
private static Class<?> loadVirtualMachine(File toolsJarFile) throws Exception {
        // We used to add tools.jar to SystemClassLoader but that was triggering
        // a bug in Java compiler when running some experiments (e.g.,
        // CommonsMath).
        if (toolsJarFile == null) {
            return null;
        }
        URLClassLoader loader = new URLClassLoader(new URL[] { toolsJarFile.toURI().toURL() },
                ClassLoader.getSystemClassLoader());
        return loader.loadClass("com.sun.tools.attach.VirtualMachine");
    }
1204041
public static URLClassLoader loadJarToSystemClassLoader(File jarFile) {
		URLClassLoader urlClassLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
		loadJar(urlClassLoader, jarFile);
		return urlClassLoader;
	}
556232
public static Pair<InMemoryJarfile, String> loadAndUpgradeCatalogFromJar(InMemoryJarfile jarfile, boolean isXDCR)
        throws IOException
    {
        // Let VoltCompiler do a version check and upgrade the catalog on the fly.
        // I.e. jarfile may be modified.
        VoltCompiler compiler = new VoltCompiler(isXDCR);
        String upgradedFromVersion = compiler.upgradeCatalogAsNeeded(jarfile);
        return new Pair<>(jarfile, upgradedFromVersion);
    }
1194584
public JavaClass readFromClassPath(String classFile)
    throws IOException
  {
    Thread thread = Thread.currentThread();
    ClassLoader loader = thread.getContextClassLoader();
    
    InputStream is = loader.getResourceAsStream(classFile);
    try {
      return parse(is);
    } finally {
      is.close();
    }
  }
1098455
private void loadJar(final JarFileInfo jarFileInfo) {
        final String JAR_SUFFIX = ".jar";

        jarFiles.add(jarFileInfo);
        jarFileInfo.getJarFile()
                .stream()
                .parallel()
                .filter(je -> !je.isDirectory() && je.getName().toLowerCase().endsWith(JAR_SUFFIX))
                .forEach(je -> {
                    try {
                        JarEntryInfo jarEntryInfo = new JarEntryInfo(jarFileInfo, je);
                        File tempFile = createJarFile(jarEntryInfo);

                        debug(String.format("Loading inner JAR %s from temp file %s", jarEntryInfo.getJarEntry(), getFilenameForLog(tempFile)));

                        // Construct ProtectionDomain for this inner JAR:
                        URL url = tempFile.toURI().toURL();
                        ProtectionDomain pdParent = jarFileInfo.getProtectionDomain();
                        // 'csParent' is never null: top JAR has it, classloader creates it for child JAR:
                        CodeSource csParent = pdParent.getCodeSource();
                        Certificate[] certParent = csParent.getCertificates();
                        CodeSource csChild = certParent == null
                                ? new CodeSource(url, csParent.getCodeSigners())
                                : new CodeSource(url, certParent);
                        ProtectionDomain pdChild = new ProtectionDomain(csChild, pdParent.getPermissions(), pdParent.getClassLoader(), pdParent.getPrincipals());
                        loadJar(new JarFileInfo(new JarFile(tempFile), jarEntryInfo.getName(), jarFileInfo, pdChild, tempFile));
                    } catch (IOException e) {
                        throw new RuntimeException(String.format("Cannot load jar entries from jar %s", je.getName().toLowerCase()), e);
                    } catch (EeClassLoaderException e) {
                        throw new RuntimeException("ERROR on loading inner JAR: " + e.getMessageAll());
                    }
                });
    }
62805
public void loadJar(File fileJar)
	throws IOException
	{
		JarFile jar = null;
		
		try
		{
			jar = new JarFile(fileJar);
			
			Enumeration<JarEntry> enumerations = jar.entries();
			JarEntry entry = null;
			byte[] classByte = null;
			ByteArrayOutputStream byteStream = null;
			
			String fileName = null;
			String className = null;
			Class<?> jarClass = null;
			while(enumerations.hasMoreElements())
			{
				entry = (JarEntry)enumerations.nextElement();
				
				if(entry.isDirectory())
					continue;  //skip directories
				
				fileName = entry.getName();
				
				if(!fileName.endsWith(".class"))
					continue; //skip non classes
				InputStream is = jar.getInputStream(entry);
				byteStream = new ByteArrayOutputStream();
				
				IO.write(byteStream, is);
				classByte = byteStream.toByteArray();
				
				className = formatClassName(fileName);
				
				Debugger.println(this,"className="+className);
				jarClass = defineClass(className, classByte, 0, classByte.length,null);
				classes.put(className, jarClass);
				
				classByte = null;
				byteStream = null;
			}//end while
		}
		finally
		{
			if(jar !=null)
				{ try{ jar.close(); } catch(Exception e){e.printStackTrace();} }
		}
		
	}
475916
@Override
    @Trivial
    public void open() throws ClassSource_Exception {
        String methodName = "open";
        if ( tc.isEntryEnabled() ) {
            String msg = MessageFormat.format(
                "[ {0} ] State [ {1} ]",
                new Object[] { getHashText(), Integer.valueOf(opens) });
            Tr.entry(tc, methodName, msg);
        }

        if ( (opens < 0) ||
             ((opens == 0) && (jarFile != null)) ||
             ((opens > 0) && (jarFile == null)) ) {

            Tr.warning(tc, "ANNO_CLASSSOURCE_JAR_STATE_BAD", getHashText(), getJarPath(), Integer.valueOf(opens));

            String eMsg = "[ " + getHashText() + " ]" +
                " Failed to open [ " + getJarPath() + " ]" +
                " Count of opens [ " + opens + " ]" +
                " Jar state [ " + jarFile + " ]";
            throw getFactory().newClassSourceException(eMsg);
        }

        opens++;

        if ( jarFile == null ) {
            try {
                jarFile = UtilImpl_FileUtils.createJarFile(jarPath); // throws IOException
            } catch ( IOException e ) {
                Tr.warning(tc, "ANNO_CLASSSOURCE_OPEN4_EXCEPTION", getHashText(), jarPath);
                String eMsg = "[ " + getHashText() + " ] Failed to open [ " + jarPath + " ]";
                throw getFactory().wrapIntoClassSourceException(CLASS_NAME, methodName, eMsg, e);
            }

            if ( tc.isEntryEnabled() ) {
                Tr.exit(tc, methodName, MessageFormat.format("[ {0} ] RETURN (new open)", getHashText()));
            }

        } else {
            if ( tc.isEntryEnabled() ) {
                Tr.exit(tc, methodName, MessageFormat.format("[ {0} ] RETURN (already open)", getHashText()));
            }
        }
    }
522858
private static Class<?> loadJamaMatrixClass() 
            throws ClassNotFoundException {

        try {
            Class<?> clazz = Class.forName("Jama.Matrix");
            return clazz;
            
        } catch (ClassNotFoundException cnfe) {

            // If we see a CNFE, don't immediately give up.  It's most likely
            // that this class is being invoked from inside a .jar, so see if
            // the user specified where JAMA is manually.
            String jamaProp = System.getProperty("jama.path");
            
            // if not, rethrow since the class does not exist
            if (jamaProp == null)
                throw cnfe;

            File jamaJarFile = new File(jamaProp);            
            try {
                // Otherwise, try to load the class from the specified .jar file
                java.net.URLClassLoader classLoader = 
                    new java.net.URLClassLoader(
                        new java.net.URL[] { jamaJarFile.toURI().toURL() });
                
                Class<?> clazz = Class.forName("Jama.Matrix", true,
                                               classLoader);
                return clazz;
            } catch (Exception e) {
                // fall through and rethrow original
            }
            
            throw cnfe;
        }
    }
160703
private void loadFromClasspath() {
        URL url = null;
        try {
            // this is the new location of the file, working on Java 8, Java 9 class path and Java 9 module path
            ClassLoader loader = Thread.currentThread().getContextClassLoader();
            if (loader == null) {
                loader = RenameHandler.class.getClassLoader();
            }
            if (LOG) {
                System.err.println("Loading from classpath: " + loader);
            }
            Enumeration<URL> en = loader.getResources("META-INF/org/joda/convert/Renamed.ini");
            while (en.hasMoreElements()) {
                url = en.nextElement();
                if (LOG) {
                    System.err.println("Loading file: " + url);
                }
                List<String> lines = loadRenameFile(url);
                parseRenameFile(lines, url);
            }
        } catch (Exception ex) {
            if (LOG) {
                ex.printStackTrace(System.err);
            }
            throw new IllegalStateException("Unable to load Renamed.ini: " + url + ": " + ex.getMessage(), ex);
        }
    }
24151
protected Set<Class<?>> loadAllClass(File jarFile, ScriptClassLoader loader) throws Exception {
		Set<Class<?>> clzzs = new HashSet<Class<?>>();
		JarFile jf = new JarFile(jarFile);
		try {
			loader.addURL(jarFile.toURI().toURL());// 添加文件到加载器
			Enumeration<JarEntry> it = jf.entries();
			while (it.hasMoreElements()) {
				JarEntry jarEntry = it.nextElement();
				if (jarEntry.getName().endsWith(".class")) {
					String className = jarEntry.getName().replace("/", ".").replaceAll(".class", "");
					clzzs.add(loader.findClass(className));
				}
			}
		} finally {
			jf.close();
		}
		return clzzs;
	}
625885
private static void loadAgent(Config config, Log log, String agentJar, Class<?> vmClass) {
	try {

	    // addAttach(config,log);

	    // first obtain the PID of the currently-running process
	    // ### this relies on the undocumented convention of the
	    // RuntimeMXBean's
	    // ### name starting with the PID, but there appears to be no other
	    // ### way to obtain the current process' id, which we need for
	    // ### the attach process
	    RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
	    String pid = runtime.getName();
	    if (pid.indexOf("@") != -1) pid = pid.substring(0, pid.indexOf("@"));
	    log.info("Instrumentation", "pid:" + pid);
	    // JDK1.6: now attach to the current VM so we can deploy a new agent
	    // ### this is a Sun JVM specific feature; other JVMs may offer
	    // ### this feature, but in an implementation-dependent way
	    Object vm = vmClass.getMethod("attach", new Class<?>[] { String.class }).invoke(null, new Object[] { pid });
	    // now deploy the actual agent, which will wind up calling
	    // agentmain()
	    vmClass.getMethod("loadAgent", new Class[] { String.class }).invoke(vm, new Object[] { agentJar });
	    vmClass.getMethod("detach", new Class[] {}).invoke(vm, new Object[] {});
	}
	catch (Throwable t) {
	    ExceptionUtil.rethrowIfNecessary(t);
	    // Log the message from the exception. Don't log the entire
	    // stack as this is expected when running on a JDK that doesn't
	    // support the Attach API.
	    log.log(Log.LEVEL_INFO, "Instrumentation", t);

	}
    }
40605
private void createClassLoader() {
        if (!Utils.isNullOrEmpty(settings.getJarFiles())) {
            try {
                String[] files = settings.getJarFiles().split(";");
                List<URL> urls = newArrayList();
                for (String path : files) {
                    File file = new File(path);
                    if (file.isFile()) {
                        urls.add(file.toURI().toURL());
                    }
                }
                classLoader = new Java4CppClassLoader(urls.toArray(new URL[files.length]), classLoader);
            } catch (Exception e) {
                throw new RuntimeException("Failed to load jar " + e.getMessage());
            }
        }
    }
695198
public static Driver loadDriver(final File jar) {
        try {
            return loadDriver(jar.toURI().toURL());
        } catch (java.net.MalformedURLException e) {
            throw new RuntimeException(e);
        } // end of catch
    }
1166588
public synchronized static boolean maybeLoad() {
        try {
            if (!Utils.getBoolean(System.getProperties(), "jafka_mx4jenable", false)) {
                return false;
            }
            if (httpAdaptor != null) {
                logger.warn("mx4j has started");
                return true;
            }
            logger.debug("Will try to load mx4j now, if it's in the classpath");
            //MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
            //ObjectName processorName = new ObjectName("Server:name=XSLTProcessor");

            httpAdaptorClass = Class.forName("mx4j.tools.adaptor.http.HttpAdaptor");
            httpAdaptor = httpAdaptorClass.newInstance();
            httpAdaptorClass.getMethod("setHost", String.class).invoke(httpAdaptor, getAddress());
            httpAdaptorClass.getMethod("setPort", Integer.TYPE).invoke(httpAdaptor, getPort());

            //ObjectName httpName = new ObjectName("system:name=http");
            //mbs.registerMBean(httpAdaptor, httpName);
            Utils.registerMBean(httpAdaptor, "system:name=http");

            Class<?> xsltProcessorClass = Class.forName("mx4j.tools.adaptor.http.XSLTProcessor");
            Object xsltProcessor = xsltProcessorClass.newInstance();
            httpAdaptorClass.getMethod("setProcessor", Class.forName("mx4j.tools.adaptor.http.ProcessorMBean")).invoke(
                    httpAdaptor, xsltProcessor);
            //mbs.registerMBean(xsltProcessor, processorName);
            Utils.registerMBean(xsltProcessor, "Server:name=XSLTProcessor");
            httpAdaptorClass.getMethod("start").invoke(httpAdaptor);
            logger.info("mx4j successfuly loaded");
            return true;
        } catch (ClassNotFoundException e) {
            logger.info("Will not load MX4J, mx4j-tools.jar is not in the classpath");
        } catch (Exception e) {
            logger.warn("Could not start register mbean in JMX", e);
        }
        return false;
    }
1354908
def _tools_classpath(self):
    

    javac_classpath = Java.global_javac_classpath(self.context.products)
    if javac_classpath:
      return javac_classpath

    self.set_distribution(jdk=True)
    jars = self.dist.find_libs(['tools.jar'])
    if len(jars) != 1:
      raise TaskError('Expected a single `tools.jar` entry for {}; got: {}'.format(
        self.dist, jars))
    return jars
1038027
public static synchronized void detach() throws Exception { // NOPMD
		if (jvmVirtualMachine != null) {
			final Class<?> virtualMachineClass = jvmVirtualMachine.getClass();
			final Method detachMethod = virtualMachineClass.getMethod("detach");
			jvmVirtualMachine = invoke(detachMethod, jvmVirtualMachine);
			jvmVirtualMachine = null;
		}
	}
797905
static PluginMeta loadMeta(final File jar) throws IOException {
        FileInputStream fileInputStream = new FileInputStream(jar);
        try{
            final ZipInputStream zipinput = new ZipInputStream(fileInputStream);
            final PluginMeta metadata = ScriptPluginProviderLoader.loadMeta(jar, zipinput);
            return metadata;
        }finally {
            fileInputStream.close();
        }
    }