当前位置: 首页>>代码示例>>Java>>正文


Java CodeInstaller.initialize方法代码示例

本文整理汇总了Java中jdk.nashorn.internal.runtime.CodeInstaller.initialize方法的典型用法代码示例。如果您正苦于以下问题:Java CodeInstaller.initialize方法的具体用法?Java CodeInstaller.initialize怎么用?Java CodeInstaller.initialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在jdk.nashorn.internal.runtime.CodeInstaller的用法示例。


在下文中一共展示了CodeInstaller.initialize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: transform

import jdk.nashorn.internal.runtime.CodeInstaller; //导入方法依赖的package包/类
@Override
FunctionNode transform(final Compiler compiler, final CompilationPhases phases, final FunctionNode fn) {
    final DebugLogger log = compiler.getLogger();

    final Map<String, Class<?>> installedClasses = new LinkedHashMap<>();

    boolean first = true;
    Class<?> rootClass = null;
    long length = 0L;

    final CodeInstaller origCodeInstaller = compiler.getCodeInstaller();
    final Map<String, byte[]> bytecode = compiler.getBytecode();
    final CodeInstaller codeInstaller = bytecode.size() > 1 ? origCodeInstaller.getMultiClassCodeInstaller() : origCodeInstaller;

    for (final Entry<String, byte[]> entry : bytecode.entrySet()) {
        final String className = entry.getKey();
        //assert !first || className.equals(compiler.getFirstCompileUnit().getUnitClassName()) : "first=" + first + " className=" + className + " != " + compiler.getFirstCompileUnit().getUnitClassName();
        final byte[] code = entry.getValue();
        length += code.length;

        final Class<?> clazz = codeInstaller.install(className, code);
        if (first) {
            rootClass = clazz;
            first = false;
        }
        installedClasses.put(className, clazz);
    }

    if (rootClass == null) {
        throw new CompilationException("Internal compiler error: root class not found!");
    }

    final Object[] constants = compiler.getConstantData().toArray();
    codeInstaller.initialize(installedClasses.values(), compiler.getSource(), constants);

    // initialize transient fields on recompilable script function data
    for (final Object constant: constants) {
        if (constant instanceof RecompilableScriptFunctionData) {
            ((RecompilableScriptFunctionData)constant).initTransients(compiler.getSource(), codeInstaller);
        }
    }

    // initialize function in the compile units
    for (final CompileUnit unit : compiler.getCompileUnits()) {
        if (!unit.isUsed()) {
            continue;
        }
        unit.setCode(installedClasses.get(unit.getUnitClassName()));
        unit.initializeFunctionsCode();
    }

    if (log.isEnabled()) {
        final StringBuilder sb = new StringBuilder();

        sb.append("Installed class '").
            append(rootClass.getSimpleName()).
            append('\'').
            append(" [").
            append(rootClass.getName()).
            append(", size=").
            append(length).
            append(" bytes, ").
            append(compiler.getCompileUnits().size()).
            append(" compile unit(s)]");

        log.fine(sb.toString());
    }

    return fn.setRootClass(null, rootClass);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:71,代码来源:CompilationPhase.java

示例2: transform

import jdk.nashorn.internal.runtime.CodeInstaller; //导入方法依赖的package包/类
@Override
FunctionNode transform(final Compiler compiler, final CompilationPhases phases, final FunctionNode fn) {
    final DebugLogger log = compiler.getLogger();

    final Map<String, Class<?>> installedClasses = new LinkedHashMap<>();

    boolean first = true;
    Class<?> rootClass = null;
    long length = 0L;

    final CodeInstaller       codeInstaller = compiler.getCodeInstaller();
    final Map<String, byte[]> bytecode      = compiler.getBytecode();

    for (final Entry<String, byte[]> entry : bytecode.entrySet()) {
        final String className = entry.getKey();
        //assert !first || className.equals(compiler.getFirstCompileUnit().getUnitClassName()) : "first=" + first + " className=" + className + " != " + compiler.getFirstCompileUnit().getUnitClassName();
        final byte[] code = entry.getValue();
        length += code.length;

        final Class<?> clazz = codeInstaller.install(className, code);
        if (first) {
            rootClass = clazz;
            first = false;
        }
        installedClasses.put(className, clazz);
    }

    if (rootClass == null) {
        throw new CompilationException("Internal compiler error: root class not found!");
    }

    final Object[] constants = compiler.getConstantData().toArray();
    codeInstaller.initialize(installedClasses.values(), compiler.getSource(), constants);

    // initialize transient fields on recompilable script function data
    for (final Object constant: constants) {
        if (constant instanceof RecompilableScriptFunctionData) {
            ((RecompilableScriptFunctionData)constant).initTransients(compiler.getSource(), codeInstaller);
        }
    }

    // initialize function in the compile units
    for (final CompileUnit unit : compiler.getCompileUnits()) {
        if (!unit.isUsed()) {
            continue;
        }
        unit.setCode(installedClasses.get(unit.getUnitClassName()));
        unit.initializeFunctionsCode();
    }

    if (log.isEnabled()) {
        final StringBuilder sb = new StringBuilder();

        sb.append("Installed class '").
            append(rootClass.getSimpleName()).
            append('\'').
            append(" [").
            append(rootClass.getName()).
            append(", size=").
            append(length).
            append(" bytes, ").
            append(compiler.getCompileUnits().size()).
            append(" compile unit(s)]");

        log.fine(sb.toString());
    }

    return fn.setRootClass(null, rootClass);
}
 
开发者ID:ojdkbuild,项目名称:lookaside_java-1.8.0-openjdk,代码行数:70,代码来源:CompilationPhase.java


注:本文中的jdk.nashorn.internal.runtime.CodeInstaller.initialize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。