本文整理汇总了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);
}
示例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);
}