Search in sources :

Example 16 with RefBoolean

use of lucee.commons.lang.types.RefBoolean in project Lucee by lucee.

the class InstrumentationFactory method getInstrumentation.

public static synchronized Instrumentation getInstrumentation(final Config config) {
    final Log log = config.getLog("application");
    final CFMLEngine engine = ConfigWebUtil.getEngine(config);
    Instrumentation instr = _getInstrumentation(log, config);
    // agent already exist
    if (instr != null)
        return instr;
    AccessController.doPrivileged(new PrivilegedAction<Object>() {

        @Override
        public Object run() {
            ClassLoader ccl = Thread.currentThread().getContextClassLoader();
            Thread.currentThread().setContextClassLoader(ClassLoader.getSystemClassLoader());
            try {
                JavaVendor vendor = JavaVendor.getCurrentVendor();
                Resource toolsJar = null;
                // When running on IBM, the attach api classes are packaged in vm.jar which is a part
                // of the default vm classpath.
                RefBoolean useOurOwn = new RefBooleanImpl(true);
                // if (!vendor.isIBM()) {
                // If we can't find the tools.jar and we're not on IBM we can't load the agent.
                toolsJar = findToolsJar(config, log, useOurOwn);
                if (toolsJar == null) {
                    return null;
                }
                // }
                log.info("Instrumentation", "tools.jar used:" + toolsJar);
                // add the attach native library
                if (useOurOwn.toBooleanValue())
                    addAttachIfNecessary(config, log);
                Class<?> vmClass = loadVMClass(toolsJar, log, vendor);
                log.info("Instrumentation", "loaded VirtualMachine class:" + (vmClass == null ? "null" : vmClass.getName()));
                if (vmClass == null) {
                    return null;
                }
                String agentPath = createAgentJar(log, config).getAbsolutePath();
                if (agentPath == null) {
                    return null;
                }
                log.info("Instrumentation", "try to load agent (path:" + agentPath + ")");
                loadAgent(config, log, agentPath, vmClass);
            // log.info("Instrumentation","agent loaded (path:"+agentPath+")");
            } catch (IOException ioe) {
                log.log(Log.LEVEL_INFO, "Instrumentation", ioe);
            } finally {
                Thread.currentThread().setContextClassLoader(ccl);
            }
            return null;
        }
    });
    // If the load(...) agent call was successful, this variable will no
    // longer be null.
    instr = _getInstrumentation(log, config);
    if (instr == null) {
        try {
            Resource agentJar = createAgentJar(log, config);
            throw new PageRuntimeException(new ApplicationException(Constants.NAME + " was not able to load a Agent dynamically! " + "You need to load one manually by adding the following to your JVM arguments [-javaagent:\"" + (agentJar) + "\"]"));
        } catch (IOException ioe) {
            SystemOut.printDate(ioe);
        }
    }
    return instr;
}
Also used : RefBoolean(lucee.commons.lang.types.RefBoolean) Log(lucee.commons.io.log.Log) Resource(lucee.commons.io.res.Resource) FileResource(lucee.commons.io.res.type.file.FileResource) Instrumentation(java.lang.instrument.Instrumentation) IOException(java.io.IOException) ApplicationException(lucee.runtime.exp.ApplicationException) URLClassLoader(java.net.URLClassLoader) CFMLEngine(lucee.loader.engine.CFMLEngine) PageRuntimeException(lucee.runtime.exp.PageRuntimeException) RefBooleanImpl(lucee.commons.lang.types.RefBooleanImpl)

Aggregations

RefBoolean (lucee.commons.lang.types.RefBoolean)16 RefBooleanImpl (lucee.commons.lang.types.RefBooleanImpl)16 IOException (java.io.IOException)3 ParserString (lucee.commons.lang.ParserString)3 PageException (lucee.runtime.exp.PageException)3 ColumnExpression (lucee.runtime.sql.exp.ColumnExpression)3 ValueString (lucee.runtime.sql.exp.value.ValueString)3 Entry (java.util.Map.Entry)2 Resource (lucee.commons.io.res.Resource)2 Component (lucee.runtime.Component)2 PageSource (lucee.runtime.PageSource)2 ApplicationException (lucee.runtime.exp.ApplicationException)2 PageRuntimeException (lucee.runtime.exp.PageRuntimeException)2 TemplateException (lucee.runtime.exp.TemplateException)2 Expression (lucee.runtime.sql.exp.Expression)2 Attribute (lucee.transformer.bytecode.statement.tag.Attribute)2 Expression (lucee.transformer.expression.Expression)2 LitString (lucee.transformer.expression.literal.LitString)2 TagLibTagAttr (lucee.transformer.library.tag.TagLibTagAttr)2 Instrumentation (java.lang.instrument.Instrumentation)1