diff options
author | dwagelaar | 2013-05-21 12:48:18 +0000 |
---|---|---|
committer | dwagelaar | 2013-05-21 12:48:18 +0000 |
commit | e93843540766e2e031155798e3a6378c094727d9 (patch) | |
tree | 756fd9ea2bb9222d9548e7be7eab03b1141637d0 /plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse | |
parent | 07d964d1e0581f92bbd730917a07c83fddc8e48d (diff) | |
download | org.eclipse.atl-e93843540766e2e031155798e3a6378c094727d9.tar.gz org.eclipse.atl-e93843540766e2e031155798e3a6378c094727d9.tar.xz org.eclipse.atl-e93843540766e2e031155798e3a6378c094727d9.zip |
EMFTVM bytecode loading performance issue: allow ExecEnv.loadModule()
without bytecode validation + only validate first-time load in
ExecEnvPool.
Diffstat (limited to 'plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse')
5 files changed, 43 insertions, 11 deletions
diff --git a/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/ExecEnv.java b/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/ExecEnv.java index 8138557e..568bc8c2 100644 --- a/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/ExecEnv.java +++ b/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/ExecEnv.java @@ -469,6 +469,21 @@ public interface ExecEnv extends EObject { /** * <!-- begin-user-doc --> + * Loads the module with the given <code>name</code> and its imports + * closure into this {@link ExecEnv} using the <code>resolver</code>, + * and registers its contents for execution. + * @param resolver the module file resolver + * @param name the module name + * @param validate if <code>true</code>, validates the loaded bytecode + * @return the loaded module + * <!-- end-user-doc --> + * @model resolverDataType="org.eclipse.m2m.atl.emftvm.ModuleResolver" + * @generated + */ + Module loadModule(ModuleResolver resolver, String name, boolean validate); + + /** + * <!-- begin-user-doc --> * Finds an {@link Operation} registered within this {@link ExecEnv}. * @param context the context type of the operation * @param name the operation name diff --git a/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/Rule.java b/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/Rule.java index 2aacea31..b7dea8bf 100644 --- a/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/Rule.java +++ b/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/Rule.java @@ -529,7 +529,7 @@ public interface Rule extends NamedElement { * @return the rule application result, or <code>null</code> if the rule did not match * @throws VMException if this is not a {@link RuleMode#MANUAL} rule * <!-- end-user-doc --> - * @model frameDataType="org.eclipse.m2m.atl.emftvm.StackFrame" valuesDataType="org.eclipse.m2m.atl.emftvm.EObjectArray" + * @model frameDataType="org.eclipse.m2m.atl.emftvm.StackFrame" valuesDataType="org.eclipse.m2m.atl.emftvm.EJavaObjectArray" * @generated */ Object matchManual(StackFrame frame, Object[] values); diff --git a/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/impl/EmftvmPackageImpl.java b/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/impl/EmftvmPackageImpl.java index 214d873a..a0df4d56 100644 --- a/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/impl/EmftvmPackageImpl.java +++ b/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/impl/EmftvmPackageImpl.java @@ -3375,6 +3375,11 @@ public class EmftvmPackageImpl extends EPackageImpl implements EmftvmPackage { addEParameter(op, this.getModuleResolver(), "resolver", 0, 1, IS_UNIQUE, IS_ORDERED); addEParameter(op, theEcorePackage.getEString(), "name", 0, 1, IS_UNIQUE, IS_ORDERED); + op = addEOperation(execEnvEClass, this.getModule(), "loadModule", 0, 1, IS_UNIQUE, IS_ORDERED); + addEParameter(op, this.getModuleResolver(), "resolver", 0, 1, IS_UNIQUE, IS_ORDERED); + addEParameter(op, theEcorePackage.getEString(), "name", 0, 1, IS_UNIQUE, IS_ORDERED); + addEParameter(op, theEcorePackage.getEBoolean(), "validate", 0, 1, IS_UNIQUE, IS_ORDERED); + op = addEOperation(execEnvEClass, this.getOperation(), "findOperation", 0, 1, IS_UNIQUE, IS_ORDERED); addEParameter(op, theEcorePackage.getEJavaObject(), "context", 0, 1, IS_UNIQUE, IS_ORDERED); addEParameter(op, theEcorePackage.getEString(), "name", 0, 1, IS_UNIQUE, IS_ORDERED); @@ -3719,14 +3724,14 @@ public class EmftvmPackageImpl extends EPackageImpl implements EmftvmPackage { op = addEOperation(ruleEClass, ecorePackage.getEJavaObject(), "matchManual", 0, 1, IS_UNIQUE, IS_ORDERED); addEParameter(op, this.getStackFrame(), "frame", 0, 1, IS_UNIQUE, IS_ORDERED); - addEParameter(op, this.getEObjectArray(), "values", 0, 1, IS_UNIQUE, IS_ORDERED); + addEParameter(op, this.getEJavaObjectArray(), "values", 0, 1, IS_UNIQUE, IS_ORDERED); op = addEOperation(ruleEClass, theEcorePackage.getEBoolean(), "matchOne", 0, 1, IS_UNIQUE, IS_ORDERED); addEParameter(op, this.getStackFrame(), "frame", 0, 1, IS_UNIQUE, IS_ORDERED); g1 = createEGenericType(theEcorePackage.getEMap()); g2 = createEGenericType(theEcorePackage.getEString()); g1.getETypeArguments().add(g2); - g2 = createEGenericType(theEcorePackage.getEObject()); + g2 = createEGenericType(theEcorePackage.getEJavaObject()); g1.getETypeArguments().add(g2); addEParameter(op, g1, "valuesMap", 0, 1, IS_UNIQUE, IS_ORDERED); diff --git a/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/impl/ExecEnvImpl.java b/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/impl/ExecEnvImpl.java index 600cad62..fd36dbeb 100644 --- a/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/impl/ExecEnvImpl.java +++ b/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/impl/ExecEnvImpl.java @@ -1166,6 +1166,16 @@ public class ExecEnvImpl extends EObjectImpl implements ExecEnv { * @generated NOT */ public synchronized Module loadModule(final ModuleResolver resolver, final String name) { + return loadModule(resolver, name, true); + } + + /** + * <!-- begin-user-doc. --> + * {@inheritDoc} + * <!-- end-user-doc --> + * @generated NOT + */ + public Module loadModule(final ModuleResolver resolver, final String name, final boolean validate) { resetJITCompiler(); if (isRuleStateCompiled()) { for (Rule r : getRules()) { @@ -1185,7 +1195,7 @@ public class ExecEnvImpl extends EObjectImpl implements ExecEnv { } final Module module = resolver.resolveModule(name); internalModules.put(name, module); - resolveImports(module, resolver); + resolveImports(module, resolver, validate); for (Feature f : module.getFeatures()) { registerFeature(f); } @@ -1196,7 +1206,7 @@ public class ExecEnvImpl extends EObjectImpl implements ExecEnv { for (Rule r : getRules()) { resolveSuperRules(r); } - if (module.eResource() != null) { // skip built-in native modules + if (validate && module.eResource() != null) { // skip built-in native modules final Object invalidObject = validate(module); if (invalidObject != null) { throw new VMException(null, String.format("Byte code validation of %s failed", invalidObject)); @@ -1210,13 +1220,13 @@ public class ExecEnvImpl extends EObjectImpl implements ExecEnv { e.getMessage()), e); } } - + /** * Validates the bytecode of <code>module</code>. * @param module the module to validate * @return <code>null</code> if <code>module</code> is valid, otherwise the first invalid object */ - private Object validate(Module module) { + private Object validate(final Module module) { final Diagnostic diag = Diagnostician.INSTANCE.validate(module); if (diag.getSeverity() != Diagnostic.OK) { return diag; @@ -1241,11 +1251,12 @@ public class ExecEnvImpl extends EObjectImpl implements ExecEnv { * Resolves the imports list of module. * @param module * @param resolver + * @param validate */ - private void resolveImports(final Module module, final ModuleResolver resolver) { + private void resolveImports(final Module module, final ModuleResolver resolver, final boolean validate) { final EList<Module> eImports = module.getEImports(); for (String imp : module.getImports()) { - Module impModule = loadModule(resolver, imp); + Module impModule = loadModule(resolver, imp, validate); eImports.add(impModule); } } diff --git a/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/util/ExecEnvPool.java b/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/util/ExecEnvPool.java index c0517ea1..a14a2e0c 100644 --- a/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/util/ExecEnvPool.java +++ b/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/util/ExecEnvPool.java @@ -78,6 +78,7 @@ public class ExecEnvPool { * @return the first available {@link ExecEnv} instance from this pool */ public synchronized ExecEnv getExecEnv() { + final boolean validate = !isFrozen(); // Only validate bytecode for first time load setFrozen(true); final Queue<SoftReference<ExecEnv>> freePool = getFreePool(); ExecEnv execEnv = null; @@ -97,7 +98,7 @@ public class ExecEnvPool { } final ModuleResolver moduleResolver = moduleResolverFactory.createModuleResolver(); for (String module : getModules()) { - execEnv.loadModule(moduleResolver, module); + execEnv.loadModule(moduleResolver, module, validate); } } getPool().add(new SoftReference<ExecEnv>(execEnv)); @@ -148,7 +149,7 @@ public class ExecEnvPool { * * @return whether this {@link ExecEnvPool} has been frozen, i.e. no new metamodels or modules can be loaded */ - public boolean isFrozen() { + public synchronized boolean isFrozen() { return frozen; } |