From 63369acd7e6020a2148f40f6bab96b0b2ba392d8 Mon Sep 17 00:00:00 2001 From: Antti Villberg Date: Sat, 11 Jan 2020 12:48:13 +0200 Subject: [PATCH] Simupedia tuning step 2 Change-Id: Ia670688f46ab27a930b472e1d3bd713df5f04ba3 --- .../org/simantics/acorn/OperationQueue.java | 1 - .../db/impl/graph/ReadGraphImpl.java | 4 +- .../simantics/db/impl/query/QueryCache.java | 2 +- .../db/impl/query/QueryCacheBase.java | 4 - .../db/impl/query/QueryListening.java | 95 ++-- .../db/layer0/request/PropertyInfo.java | 46 +- .../AbstractExpressionCompilationRequest.java | 4 +- .../layer0/util/SessionGarbageCollection.java | 8 +- .../StandardGraphPropertyVariable.java | 2 +- .../procore/internal/SessionImplSocket.java | 2 +- .../request/ServerSCLHandlerValueRequest.java | 404 +++++++++--------- .../server/request/ServerSCLValueRequest.java | 36 +- .../request/ServerSCLValueRequestBase.java | 43 ++ .../project/management/PlatformUtil.java | 15 +- .../module/repository/ModuleRepository.java | 11 +- .../runtime/ExpressionClassLoader.java | 8 +- .../scl/compiler/runtime/RuntimeModule.java | 35 +- .../scl/compiler/top/ExpressionEvaluator.java | 2 +- .../src/org/simantics/scl/osgi/SCLOsgi.java | 41 +- ...CompileProceduralComponentTypeRequest.java | 4 + 20 files changed, 411 insertions(+), 356 deletions(-) create mode 100644 bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLValueRequestBase.java diff --git a/bundles/org.simantics.acorn/src/org/simantics/acorn/OperationQueue.java b/bundles/org.simantics.acorn/src/org/simantics/acorn/OperationQueue.java index 48b891f0e..c5cf5f7bf 100644 --- a/bundles/org.simantics.acorn/src/org/simantics/acorn/OperationQueue.java +++ b/bundles/org.simantics.acorn/src/org/simantics/acorn/OperationQueue.java @@ -165,7 +165,6 @@ class OperationQueue { if(!operations.isEmpty() || !tasks.isEmpty()) return 0; long start = System.nanoTime(); - System.err.println("start =" + start); try { wait(5000); diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ReadGraphImpl.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ReadGraphImpl.java index ba39c57df..dcb48a0f0 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ReadGraphImpl.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ReadGraphImpl.java @@ -1950,10 +1950,8 @@ public class ReadGraphImpl implements AsyncReadGraph { assert (request != null); - //ITask task = ThreadLogger.task(request); ListenerBase listener = procedure != null ? getListenerBase(procedure) : null; - T result = QueryCache.resultReadEntry(this, request, parent, listener, procedure); - //task.finish(); + T result = (T)QueryCache.runnerReadEntry(this, request, parent, listener, procedure, true); return result; } diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryCache.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryCache.java index 5cf0e87b9..35ebdbc65 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryCache.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryCache.java @@ -625,7 +625,7 @@ public class QueryCache extends QueryCacheBase { } } - ReadEntry getOrCreateReadEntry(ReadGraphImpl graph, Read r, boolean needsToBlock) throws DatabaseException { + private final ReadEntry getOrCreateReadEntry(ReadGraphImpl graph, Read r, boolean needsToBlock) throws DatabaseException { ReadEntry existing = null; synchronized(readEntryMap) { existing = (ReadEntry)readEntryMap.get(r); diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryCacheBase.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryCacheBase.java index d0d3322a7..deeb65fdd 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryCacheBase.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryCacheBase.java @@ -905,10 +905,6 @@ public class QueryCacheBase { return wrap.get(); } - public static T resultReadEntry(ReadGraphImpl graph, Read r, CacheEntry parent, ListenerBase listener, AsyncProcedure procedure) throws DatabaseException { - return (T)QueryCache.runnerReadEntry(graph, r, parent, listener, procedure, true); - } - public static T resultAsyncReadEntry(ReadGraphImpl graph, AsyncRead r, CacheEntry parent, ListenerBase listener, AsyncProcedure procedure) throws DatabaseException { return (T)QueryCache.runnerAsyncReadEntry(graph, r, parent, listener, procedure, true); } diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryListening.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryListening.java index b873bfd73..db9d0310f 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryListening.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryListening.java @@ -46,9 +46,6 @@ public class QueryListening { private Consumer consumer; private Map addedEntries = new HashMap<>(); - int execCount=0; - int queueCount = 0; - static class TL extends ThreadLocal> { Map> allQueues = new HashMap<>(); @@ -179,33 +176,70 @@ public class QueryListening { return !scheduledListeners.isEmpty(); } - public synchronized void dispatch(Runnable r) { - queueCount++; - consumer.accept(r); + static class RegisterParentRunnable implements Runnable { + + final CacheEntry parent; + final CacheEntry child; + + public RegisterParentRunnable(CacheEntry parent, CacheEntry child) { + this.parent = parent; + this.child = child; + } + + @Override + public void run() { + child.addParent(parent); + if (Development.DEVELOPMENT) { + if(Development.getProperty(DevelopmentKeys.QUERYPROCESSOR_DEPENDENCIES, Bindings.BOOLEAN)) { + System.out.println(child + " -> " + parent); + } + } + } + + } + + static class RegisterListenerRunnable implements Runnable { + + final QueryListening queryListening; + final ListenerBase base; + final Object procedure; + final CacheEntry parent; + final CacheEntry entry; + + public RegisterListenerRunnable(QueryListening queryListening, ListenerBase base, Object procedure, CacheEntry parent, CacheEntry entry) { + this.queryListening = queryListening; + this.base = base;; + this.procedure = procedure; + this.parent = parent; + this.entry = entry; + } + + @Override + public void run() { + queryListening.addListener(entry, base, procedure); + } + } void registerDependencies(ReadGraphImpl graph, CacheEntry child, CacheEntry parent, ListenerBase listener, Object procedure, boolean inferred) { - dispatch(() -> { + if(inferred) { + assert(listener == null); + return; + } - if (parent != null && !inferred) { - try { - if(!child.isImmutable(graph)) - child.addParent(parent); - } catch (DatabaseException e) { - LOGGER.error("Error while registering query dependencies", e); - } - if (Development.DEVELOPMENT) { - if(Development.getProperty(DevelopmentKeys.QUERYPROCESSOR_DEPENDENCIES, Bindings.BOOLEAN)) { - System.out.println(child + " -> " + parent); - } - } + if(parent != null) { + try { + if(!child.isImmutable(graph)) + consumer.accept(new RegisterParentRunnable(parent, child)); + } catch (DatabaseException e) { + LOGGER.error("Error while registering query dependencies", e); } + } - if (listener != null) - registerListener(child, listener, procedure); - - }); + if(listener != null) + if(!listener.isDisposed()) + consumer.accept(new RegisterListenerRunnable(this, listener, procedure, parent, child)); } @@ -213,26 +247,13 @@ public class QueryListening { if(base == null) return; - dispatch(() -> { - + consumer.accept(() -> { ListenerEntry entry = addedEntries.get(base); if(entry != null) entry.setLastKnown(result); - }); } - public ListenerEntry registerListener(final CacheEntry entry, final ListenerBase base, final Object procedure) { - - assert (entry != null); - - if (base.isDisposed()) - return null; - - return addListener(entry, base, procedure); - - } - /* * Registers a listener and returns an entry iff the entry was added */ diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/PropertyInfo.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/PropertyInfo.java index 150c760aa..a7ef69c8b 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/PropertyInfo.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/PropertyInfo.java @@ -30,6 +30,7 @@ import org.simantics.utils.datastructures.Pair; public class PropertyInfo { public final Resource predicate; public final String name; + public final boolean isImmutable; public final boolean isHasProperty; public final boolean isFunctional; public final Set classifications; @@ -42,9 +43,10 @@ public class PropertyInfo { public final Map> subliteralPredicates; public final ValueAccessor valueAccessor; public final boolean hasEnumerationRange; - public PropertyInfo(Resource predicate, String name, boolean isFunctional, boolean isHasProperty, Set classifications, VariableBuilder builder, Resource literalRange, Datatype requiredDatatype, String definedUnit, String requiredValueType, Binding defaultBinding, Map> subliteralPredicates, ValueAccessor valueAccessor, boolean hasEnumerationRange) { + public PropertyInfo(Resource predicate, String name, boolean isImmutable, boolean isFunctional, boolean isHasProperty, Set classifications, VariableBuilder builder, Resource literalRange, Datatype requiredDatatype, String definedUnit, String requiredValueType, Binding defaultBinding, Map> subliteralPredicates, ValueAccessor valueAccessor, boolean hasEnumerationRange) { this.predicate = predicate; this.name = name; + this.isImmutable = isImmutable; this.isFunctional = isFunctional; this.isHasProperty = isHasProperty; this.classifications = classifications; @@ -71,7 +73,7 @@ public class PropertyInfo { Binding defaultBinding = requiredDatatype != null ? Bindings.getBinding(requiredDatatype) : null; - return new PropertyInfo(predicate, name, isFunctional, isHasProperty, classifications, builder, literalRange, requiredDatatype, definedUnit, requiredValueType, defaultBinding, subliteralPredicates, valueAccessor, hasEnumerationRange); + return new PropertyInfo(predicate, name, graph.isImmutable(predicate), isFunctional, isHasProperty, classifications, builder, literalRange, requiredDatatype, definedUnit, requiredValueType, defaultBinding, subliteralPredicates, valueAccessor, hasEnumerationRange); } public boolean hasClassification(String classification) { @@ -107,20 +109,22 @@ public class PropertyInfo { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((builder == null) ? 0 : builder.hashCode()); - result = prime * result + ((classifications == null) ? 0 : classifications.hashCode()); - result = prime * result + ((defaultBinding == null) ? 0 : defaultBinding.hashCode()); - result = prime * result + ((definedUnit == null) ? 0 : definedUnit.hashCode()); - result = prime * result + (hasEnumerationRange ? 1231 : 1237); - result = prime * result + (isFunctional ? 1231 : 1237); - result = prime * result + (isHasProperty ? 1231 : 1237); - result = prime * result + ((literalRange == null) ? 0 : literalRange.hashCode()); - result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + ((predicate == null) ? 0 : predicate.hashCode()); - result = prime * result + ((requiredDatatype == null) ? 0 : requiredDatatype.hashCode()); - result = prime * result + ((requiredValueType == null) ? 0 : requiredValueType.hashCode()); - result = prime * result + ((subliteralPredicates == null) ? 0 : subliteralPredicates.hashCode()); - result = prime * result + ((valueAccessor == null) ? 0 : valueAccessor.hashCode()); + if(!isImmutable) { + result = prime * result + ((builder == null) ? 0 : builder.hashCode()); + result = prime * result + ((classifications == null) ? 0 : classifications.hashCode()); + result = prime * result + ((defaultBinding == null) ? 0 : defaultBinding.hashCode()); + result = prime * result + ((definedUnit == null) ? 0 : definedUnit.hashCode()); + result = prime * result + (hasEnumerationRange ? 1231 : 1237); + result = prime * result + (isFunctional ? 1231 : 1237); + result = prime * result + (isHasProperty ? 1231 : 1237); + result = prime * result + ((literalRange == null) ? 0 : literalRange.hashCode()); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((requiredDatatype == null) ? 0 : requiredDatatype.hashCode()); + result = prime * result + ((requiredValueType == null) ? 0 : requiredValueType.hashCode()); + result = prime * result + ((subliteralPredicates == null) ? 0 : subliteralPredicates.hashCode()); + result = prime * result + ((valueAccessor == null) ? 0 : valueAccessor.hashCode()); + } return result; } @Override @@ -132,6 +136,13 @@ public class PropertyInfo { if (getClass() != obj.getClass()) return false; PropertyInfo other = (PropertyInfo) obj; + if (predicate == null) { + if (other.predicate != null) + return false; + } else if (!predicate.equals(other.predicate)) + return false; + if(isImmutable) + return true; if (builder == null) { if (other.builder != null) return false; @@ -168,11 +179,6 @@ public class PropertyInfo { return false; } else if (!name.equals(other.name)) return false; - if (predicate == null) { - if (other.predicate != null) - return false; - } else if (!predicate.equals(other.predicate)) - return false; if (requiredDatatype == null) { if (other.requiredDatatype != null) return false; diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/scl/AbstractExpressionCompilationRequest.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/scl/AbstractExpressionCompilationRequest.java index 8d364c737..1bcd91877 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/scl/AbstractExpressionCompilationRequest.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/scl/AbstractExpressionCompilationRequest.java @@ -104,7 +104,7 @@ implements Read> { return DEFAULT_EXPECTED_EFFECT; } - private ExpressionEvaluator prepareEvaluator(final ReadGraph graph, final CompilationContext context, Type expectedType) throws DatabaseException { + protected ExpressionEvaluator prepareEvaluator(final ReadGraph graph, final CompilationContext context, Type expectedType) throws DatabaseException { final Variable contextVariable = new Variable("context", getContextVariableType()); LocalEnvironment localEnvironment = new AbstractLocalEnvironment() { THashMap> precalculatedVariables = new THashMap>(); @@ -156,7 +156,7 @@ implements Read> { } @SuppressWarnings("unchecked") - private Function1 eval(ExpressionEvaluator evaluator, ReadGraph graph) throws DatabaseException { + protected Function1 eval(ExpressionEvaluator evaluator, ReadGraph graph) throws DatabaseException { Object oldGraph = SCLContext.getCurrent().put("graph", graph); try { return (Function1)evaluator.eval(); diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/SessionGarbageCollection.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/SessionGarbageCollection.java index c58ced3d8..c168e2286 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/SessionGarbageCollection.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/SessionGarbageCollection.java @@ -75,10 +75,10 @@ public class SessionGarbageCollection { if(_monitor == null) _monitor = new NullProgressMonitor(); QueryControl qc = graph.getService(QueryControl.class); ClusterControl cc = graph.getService(ClusterControl.class); -// _monitor.beginTask("Collect clusters", IProgressMonitor.UNKNOWN); -// cc.gc(graph, clusterTarget); -// _monitor.beginTask("Collect queries", IProgressMonitor.UNKNOWN); -// qc.gc(graph, allowedTimeInMs); + _monitor.beginTask("Collect clusters", IProgressMonitor.UNKNOWN); + cc.gc(graph, clusterTarget); + _monitor.beginTask("Collect queries", IProgressMonitor.UNKNOWN); + qc.gc(graph, allowedTimeInMs); } /** diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardGraphPropertyVariable.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardGraphPropertyVariable.java index 7927614cd..0589f36d2 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardGraphPropertyVariable.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardGraphPropertyVariable.java @@ -37,7 +37,7 @@ import org.slf4j.LoggerFactory; public class StandardGraphPropertyVariable extends AbstractPropertyVariable { private static final Logger LOGGER = LoggerFactory.getLogger(StandardGraphPropertyVariable.class); - protected static final PropertyInfo NO_PROPERTY = new PropertyInfo(null, null, + protected static final PropertyInfo NO_PROPERTY = new PropertyInfo(null, null, true, false, false, Collections. emptySet(), null, null, null, null, null, null, Collections.> emptyMap(), null, false); diff --git a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/SessionImplSocket.java b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/SessionImplSocket.java index 2ca107380..1eb815240 100644 --- a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/SessionImplSocket.java +++ b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/SessionImplSocket.java @@ -3524,7 +3524,7 @@ public abstract class SessionImplSocket implements Session, WriteRequestSchedule public int getAmountOfQueryThreads() { // This must be a power of two - return 4; + return 32; // return Integer.highestOneBit(Runtime.getRuntime().availableProcessors()); } diff --git a/bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLHandlerValueRequest.java b/bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLHandlerValueRequest.java index 8ca55eaa5..e117dd004 100644 --- a/bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLHandlerValueRequest.java +++ b/bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLHandlerValueRequest.java @@ -1,5 +1,6 @@ package org.simantics.document.server.request; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; @@ -9,15 +10,11 @@ import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.common.procedure.adapter.TransientCacheListener; import org.simantics.db.common.request.IndexRoot; -import org.simantics.db.common.request.PossibleTypedParent; import org.simantics.db.common.request.UnaryRead; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.scl.AbstractExpressionCompilationContext; -import org.simantics.db.layer0.scl.AbstractExpressionCompilationRequest; import org.simantics.db.layer0.util.RuntimeEnvironmentRequest2; import org.simantics.db.layer0.variable.Variable; -import org.simantics.document.base.ontology.DocumentationResource; -import org.simantics.document.server.request.ServerSCLHandlerValueRequest.CompilationContext; import org.simantics.layer0.Layer0; import org.simantics.scl.compiler.elaboration.expressions.EApply; import org.simantics.scl.compiler.elaboration.expressions.EConstant; @@ -30,147 +27,156 @@ import org.simantics.scl.compiler.runtime.RuntimeEnvironment; import org.simantics.scl.compiler.types.TCon; import org.simantics.scl.compiler.types.Type; import org.simantics.scl.compiler.types.Types; +import org.simantics.scl.compiler.types.exceptions.MatchException; import org.simantics.scl.compiler.types.kinds.Kinds; +import org.simantics.scl.compiler.types.util.MultiFunction; import org.simantics.scl.runtime.SCLContext; import org.simantics.scl.runtime.function.Function1; +import org.simantics.scl.runtime.function.FunctionImpl1; import org.simantics.structural2.scl.ComponentTypeProperty; import org.simantics.structural2.scl.FindPossibleComponentTypeRequest; import org.simantics.structural2.scl.ReadComponentTypeInterfaceRequest; import org.simantics.utils.datastructures.Pair; -public class ServerSCLHandlerValueRequest extends AbstractExpressionCompilationRequest { - - private final Pair componentTypeAndRoot; - private final Resource literal; - protected String possibleExpectedValueType; - - public static class CompilationContext extends AbstractExpressionCompilationContext { - public final Map propertyMap; - - public CompilationContext(RuntimeEnvironment runtimeEnvironment, - Map propertyMap) { - super(runtimeEnvironment); - this.propertyMap = propertyMap; - } - } - - private ServerSCLHandlerValueRequest(Pair componentTypeAndRoot, Resource literal, String possibleExpectedValueType) { - assert(literal != null); - this.literal = literal; - this.componentTypeAndRoot = componentTypeAndRoot; - this.possibleExpectedValueType = possibleExpectedValueType; - } - - public ServerSCLHandlerValueRequest(ReadGraph graph, Variable context) throws DatabaseException { - this(getComponentTypeAndRoot(graph, context), context.getRepresents(graph), resolveExpectedValueType(graph, context.getPredicateResource(graph))); - } - - public ServerSCLHandlerValueRequest(ReadGraph graph, Resource s, Resource o, Resource p) throws DatabaseException { - this(getComponentTypeAndRoot(graph, s, o), o, resolveExpectedValueType(graph, p)); - } - - private static Pair getComponentTypeAndRoot(ReadGraph graph, Variable property) throws DatabaseException { - Variable parent = property.getParent(graph); - Resource represents = parent.getRepresents(graph); - if(represents != null) { - Resource type = graph.syncRequest(new FindPossibleComponentTypeRequest(represents)); - if(type != null) { - Resource root = graph.syncRequest(new IndexRoot(type)); - return Pair.make(type, root); - } - } - parent = parent.getParent(graph); - Resource root = graph.syncRequest(new IndexRoot(property.getRepresents(graph))); - return Pair.make(parent.getType(graph), root); - } - - private static Pair getComponentTypeAndRoot(ReadGraph graph, Resource component, Resource literal) throws DatabaseException { - if(component != null) { - Resource type = graph.syncRequest(new FindPossibleComponentTypeRequest(component)); - if(type != null) { - Resource root = graph.syncRequest(new IndexRoot(type)); - return Pair.make(type, root); - } else { - Resource doc = graph.syncRequest(new PossibleTypedParent(component, DocumentationResource.getInstance(graph).Document)); - Resource componentType = graph.getSingleType(doc); - Resource root = graph.syncRequest(new IndexRoot(doc)); - return Pair.make(componentType, root); - } - // TODO: For Antti to consider and fix later - // Introduced to handle procedural user components where component == null - } else if (literal != null) { - Resource root = graph.syncRequest(new IndexRoot(literal)); - return Pair.make(null, root); - } else { - throw new DatabaseException("Couldn't resolve component type and root for component == null && literal == null"); - } - //throw new IllegalStateException(); - } +public class ServerSCLHandlerValueRequest extends ServerSCLValueRequestBase { + + private final Pair componentTypeAndRoot; + private final Resource literal; + protected String possibleExpectedValueType; + + public static class CompilationContext extends AbstractExpressionCompilationContext { + public final Map propertyMap; + + public CompilationContext(RuntimeEnvironment runtimeEnvironment, + Map propertyMap) { + super(runtimeEnvironment); + this.propertyMap = propertyMap; + } + } + + private ServerSCLHandlerValueRequest(Pair componentTypeAndRoot, Resource literal, String possibleExpectedValueType) { + assert(literal != null); + this.literal = literal; + this.componentTypeAndRoot = componentTypeAndRoot; + this.possibleExpectedValueType = possibleExpectedValueType; + } + + public ServerSCLHandlerValueRequest(ReadGraph graph, Variable context) throws DatabaseException { + this(getComponentTypeAndRoot(graph, context), context.getRepresents(graph), resolveExpectedValueType(graph, context.getPredicateResource(graph))); + } + + public ServerSCLHandlerValueRequest(ReadGraph graph, Resource s, Resource o, Resource p) throws DatabaseException { + this(getComponentTypeAndRoot(graph, s, o), o, resolveExpectedValueType(graph, p)); + } + + private static Pair getComponentTypeAndRoot(ReadGraph graph, Variable property) throws DatabaseException { + Variable parent = property.getParent(graph); + Resource represents = parent.getRepresents(graph); + if(represents != null) { + Resource type = graph.syncRequest(new FindPossibleComponentTypeRequest(represents)); + if(type != null) { + Resource root = graph.syncRequest(new IndexRoot(type)); + return Pair.make(type, root); + } + } + parent = parent.getParent(graph); + Resource root = graph.syncRequest(new IndexRoot(property.getRepresents(graph))); + return Pair.make(parent.getType(graph), root); + } + public static List getEffects(ReadGraph graph, Variable context) throws DatabaseException { + HandlerFn fn = (HandlerFn)compile(graph, context); + return fn.effects; + } + + public static Object compileAndEvaluate(ReadGraph graph, Variable context) throws DatabaseException { + SCLContext sclContext = SCLContext.getCurrent(); + Object oldGraph = sclContext.get("graph"); try { - ServerSCLHandlerValueRequest req = new ServerSCLHandlerValueRequest(graph, context); - return req.getExpressionEffects(graph); + Function1 exp = graph.syncRequest(new ServerSCLHandlerValueRequest(graph, context), + TransientCacheListener.instance()); + sclContext.put("graph", graph); + return exp.apply(context); } catch (DatabaseException e) { throw (DatabaseException)e; } catch (Throwable t) { throw new DatabaseException(t); + } finally { + sclContext.put("graph", oldGraph); } } - public static Object compileAndEvaluate(ReadGraph graph, Variable context) throws DatabaseException { - SCLContext sclContext = SCLContext.getCurrent(); - Object oldGraph = sclContext.get("graph"); - try { - Function1 exp = graph.syncRequest(new ServerSCLHandlerValueRequest(graph, context), - TransientCacheListener.instance()); - sclContext.put("graph", graph); - return exp.apply(context); - } catch (DatabaseException e) { - throw (DatabaseException)e; - } catch (Throwable t) { - throw new DatabaseException(t); - } finally { - sclContext.put("graph", oldGraph); - } - } - - public static Function1 compile(ReadGraph graph, Variable context) throws DatabaseException { - return graph.syncRequest(new ServerSCLHandlerValueRequest(graph, context), TransientCacheListener.instance()); - } - - public static Function1 compile(ReadGraph graph, Resource s, Resource o, Resource p) throws DatabaseException { - return graph.syncRequest(new ServerSCLHandlerValueRequest(graph, s, o, p), TransientCacheListener.>instance()); - } - - @Override - protected String getExpressionText(ReadGraph graph) - throws DatabaseException { - Layer0 L0 = Layer0.getInstance(graph); - String exp = graph.getRelatedValue(literal, L0.SCLValue_expression, Bindings.STRING); - return "\\context -> " + exp; - } - - protected RuntimeEnvironmentRequest2 getRuntimeEnvironmentRequest(Resource componentType, Resource indexRoot) { - return new RuntimeEnvironmentRequest2(componentType, indexRoot) { - @Override - protected void fillEnvironmentSpecification( - EnvironmentSpecification environmentSpecification) { - } - }; - } - - @Override - protected CompilationContext getCompilationContext(ReadGraph graph) throws DatabaseException { - return graph.syncRequest(new UnaryRead,CompilationContext>(componentTypeAndRoot) { - @Override - public CompilationContext perform(ReadGraph graph) throws DatabaseException { - RuntimeEnvironment runtimeEnvironment = graph.syncRequest(getRuntimeEnvironmentRequest(parameter.first, parameter.second)); + public static Function1 compile(ReadGraph graph, Variable context) throws DatabaseException { + return graph.syncRequest(new ServerSCLHandlerValueRequest(graph, context), TransientCacheListener.instance()); + } + + public static Function1 compile(ReadGraph graph, Resource s, Resource o, Resource p) throws DatabaseException { + return graph.syncRequest(new ServerSCLHandlerValueRequest(graph, s, o, p), TransientCacheListener.instance()); + } + + public static class HandlerFn extends FunctionImpl1 { + + Function1 handler; + ArrayList effects; + + HandlerFn(Function1 handler, Type type) { + try { + this.handler = handler; + this.effects = new ArrayList(); + MultiFunction mfun = Types.matchFunction(type, 1); + mfun.effect.collectConcreteEffects(this.effects); + } catch(MatchException e) { + // Should not happen! + throw new RuntimeException(e); + } + } + + @Override + public Object apply(Object p0) { + return handler.apply(p0); + } + + } + + @Override + public Function1 perform(ReadGraph graph) throws DatabaseException { + + CompilationContext context = getCompilationContext(graph); + Type expectedType = getExpectedType(graph, context); + Function1 handler = eval(prepareEvaluator(graph, context, expectedType), graph); + return new HandlerFn(handler, expectedType); + + } + + @Override + protected String getExpressionText(ReadGraph graph) + throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + String exp = graph.getRelatedValue(literal, L0.SCLValue_expression, Bindings.STRING); + return "\\context -> " + exp; + } + + protected RuntimeEnvironmentRequest2 getRuntimeEnvironmentRequest(Resource componentType, Resource indexRoot) { + return new RuntimeEnvironmentRequest2(componentType, indexRoot) { + @Override + protected void fillEnvironmentSpecification( + EnvironmentSpecification environmentSpecification) { + } + }; + } + + @Override + protected CompilationContext getCompilationContext(ReadGraph graph) throws DatabaseException { + return graph.syncRequest(new UnaryRead,CompilationContext>(componentTypeAndRoot) { + @Override + public CompilationContext perform(ReadGraph graph) throws DatabaseException { + RuntimeEnvironment runtimeEnvironment = graph.syncRequest(getRuntimeEnvironmentRequest(parameter.first, parameter.second)); Map propertyMap; if (parameter.first != null) { propertyMap = - graph.syncRequest(new ReadComponentTypeInterfaceRequest(parameter.first, runtimeEnvironment.getEnvironment()), - TransientCacheListener.>instance()); + graph.syncRequest(new ReadComponentTypeInterfaceRequest(parameter.first, runtimeEnvironment.getEnvironment()), + TransientCacheListener.>instance()); } else { // TODO: Antti to consider // To handle procedural user components @@ -179,47 +185,47 @@ public class ServerSCLHandlerValueRequest extends AbstractExpressionCompilationR // Map propertyMap = // graph.syncRequest(new ReadComponentTypeInterfaceRequest(parameter.first, runtimeEnvironment.getEnvironment()), // TransientCacheListener.>instance()); - return new CompilationContext(runtimeEnvironment, propertyMap); - } - }); - } - - @Override - protected Type getContextVariableType() { - return VARIABLE; - } - - private static Expression accessInputVariable(Environment environment, - org.simantics.scl.compiler.elaboration.expressions.Variable contextVariable) { - SCLValue variableParentFunction = environment.getValue(VARIABLE_PARENT); - return new EApply(new EConstant(variableParentFunction), - new EApply(new EConstant(variableParentFunction), - new EVariable(contextVariable))); - } - - protected static Expression standardGetProperty( - Environment environment, - org.simantics.scl.compiler.elaboration.expressions.Variable contextVariable, - String name, - Type type) { - return getPropertyFlexible(environment, accessInputVariable(environment, contextVariable), name, type); - } - - @Override - protected Expression getVariableAccessExpression( - ReadGraph graph, - CompilationContext context, - org.simantics.scl.compiler.elaboration.expressions.Variable contextVariable, - String name) throws DatabaseException { - ComponentTypeProperty property = context.propertyMap.get(name); - if(property != null) - return standardGetProperty( - context.runtimeEnvironment.getEnvironment(), - contextVariable, - name, - property.type == null ? Types.metaVar(Kinds.STAR) : property.type); - else { - + return new CompilationContext(runtimeEnvironment, propertyMap); + } + }); + } + + @Override + protected Type getContextVariableType() { + return VARIABLE; + } + + private static Expression accessInputVariable(Environment environment, + org.simantics.scl.compiler.elaboration.expressions.Variable contextVariable) { + SCLValue variableParentFunction = environment.getValue(VARIABLE_PARENT); + return new EApply(new EConstant(variableParentFunction), + new EApply(new EConstant(variableParentFunction), + new EVariable(contextVariable))); + } + + protected static Expression standardGetProperty( + Environment environment, + org.simantics.scl.compiler.elaboration.expressions.Variable contextVariable, + String name, + Type type) { + return getPropertyFlexible(environment, accessInputVariable(environment, contextVariable), name, type); + } + + @Override + protected Expression getVariableAccessExpression( + ReadGraph graph, + CompilationContext context, + org.simantics.scl.compiler.elaboration.expressions.Variable contextVariable, + String name) throws DatabaseException { + ComponentTypeProperty property = context.propertyMap.get(name); + if(property != null) + return standardGetProperty( + context.runtimeEnvironment.getEnvironment(), + contextVariable, + name, + property.type == null ? Types.metaVar(Kinds.STAR) : property.type); + else { + // if(context.propertyMap.containsKey(name)) { // // org.simantics.scl.compiler.elaboration.expressions.Variable parametersVariable = new org.simantics.scl.compiler.elaboration.expressions.Variable("context", COMMAND_CONTEXT); @@ -234,45 +240,45 @@ public class ServerSCLHandlerValueRequest extends AbstractExpressionCompilationR // new ELiteral(new StringConstant(name))); // // } - - return getSpecialVariableAccessExpression(graph, context, contextVariable, name); - - } - } - - protected Expression getSpecialVariableAccessExpression(ReadGraph graph, - CompilationContext context, - org.simantics.scl.compiler.elaboration.expressions.Variable contextVariable, - String name) throws DatabaseException { - if(name.equals("input")) { - Environment environment = context.runtimeEnvironment.getEnvironment(); - return accessInputVariable(environment, contextVariable); - } else if(name.equals("self")) - return new EVariable(contextVariable); - else - return null; - } + + return getSpecialVariableAccessExpression(graph, context, contextVariable, name); + + } + } + + protected Expression getSpecialVariableAccessExpression(ReadGraph graph, + CompilationContext context, + org.simantics.scl.compiler.elaboration.expressions.Variable contextVariable, + String name) throws DatabaseException { + if(name.equals("input")) { + Environment environment = context.runtimeEnvironment.getEnvironment(); + return accessInputVariable(environment, contextVariable); + } else if(name.equals("self")) + return new EVariable(contextVariable); + else + return null; + } @Override protected Type getExpectedType(ReadGraph graph, CompilationContext context) throws DatabaseException { return super.getExpectedType(graph, context); } - @Override - public int hashCode() { - return 31*(31*getClass().hashCode() + literal.hashCode()) + componentTypeAndRoot.hashCode(); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - ServerSCLHandlerValueRequest other = (ServerSCLHandlerValueRequest) obj; - return literal.equals(other.literal) && componentTypeAndRoot.equals(other.componentTypeAndRoot); - } + @Override + public int hashCode() { + return 31*(31*getClass().hashCode() + literal.hashCode()) + componentTypeAndRoot.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ServerSCLHandlerValueRequest other = (ServerSCLHandlerValueRequest) obj; + return literal.equals(other.literal) && componentTypeAndRoot.equals(other.componentTypeAndRoot); + } } diff --git a/bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLValueRequest.java b/bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLValueRequest.java index adff8dab5..7f9473861 100644 --- a/bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLValueRequest.java +++ b/bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLValueRequest.java @@ -45,7 +45,7 @@ import org.simantics.utils.datastructures.Pair; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class ServerSCLValueRequest extends AbstractExpressionCompilationRequest { +public class ServerSCLValueRequest extends ServerSCLValueRequestBase { private final Pair componentTypeAndRoot; private final Resource literal; @@ -91,39 +91,9 @@ public class ServerSCLValueRequest extends AbstractExpressionCompilationRequest< return Pair.make(parent.getType(graph), root); } - private static Pair getComponentTypeAndRoot(ReadGraph graph, Resource component, Resource literal) throws DatabaseException { - if(component != null) { - Resource type = graph.syncRequest(new FindPossibleComponentTypeRequest(component)); - if(type != null) { - Resource root = graph.syncRequest(new IndexRoot(type)); - // System.err.println("getComponentTypeAndRoot3 " + graph.getPossibleURI(component) + " => " + graph.getPossibleURI(type) + " " + graph.getPossibleURI(root)); - return Pair.make(type, root); - } else { - Resource doc = graph.syncRequest(new PossibleTypedParent(component, DocumentationResource.getInstance(graph).Document)); - if(doc != null) { - Resource componentType = graph.getSingleType(doc); - Resource root = graph.syncRequest(new IndexRoot(doc)); - return Pair.make(componentType, root); - } else { - //System.err.println("component = " + component); - Resource root = graph.syncRequest(new IndexRoot(component)); -// Resource componentType = graph.getSingleType(doc); - return Pair.make(null, root); - } - } - // TODO: For Antti to consider and fix later - // Introduced to handle procedural user components where component == null - } else if (literal != null) { - Resource root = graph.syncRequest(new IndexRoot(literal)); - return Pair.make(null, root); - } else { - throw new DatabaseException("Couldn't resolve component type and root for component == null && literal == null"); - } - } - public static Object compileAndEvaluate(ReadGraph graph, Variable context) throws DatabaseException { SCLContext sclContext = SCLContext.getCurrent(); - Object oldGraph = sclContext.get("graph"); + Object oldGraph = sclContext.get("graph"); try { Function1 exp = compile(graph, context); sclContext.put("graph", graph); @@ -133,7 +103,7 @@ public class ServerSCLValueRequest extends AbstractExpressionCompilationRequest< } catch (Throwable t) { throw new DatabaseException(t); } finally { - sclContext.put("graph", oldGraph); + sclContext.put("graph", oldGraph); } } diff --git a/bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLValueRequestBase.java b/bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLValueRequestBase.java new file mode 100644 index 000000000..ab23e2ab1 --- /dev/null +++ b/bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLValueRequestBase.java @@ -0,0 +1,43 @@ +package org.simantics.document.server.request; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.IndexRoot; +import org.simantics.db.common.request.PossibleTypedParent; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.scl.AbstractExpressionCompilationContext; +import org.simantics.db.layer0.scl.AbstractExpressionCompilationRequest; +import org.simantics.document.base.ontology.DocumentationResource; +import org.simantics.structural2.scl.FindPossibleComponentTypeRequest; +import org.simantics.utils.datastructures.Pair; + +abstract public class ServerSCLValueRequestBase extends AbstractExpressionCompilationRequest { + + static Pair getComponentTypeAndRoot(ReadGraph graph, Resource component, Resource literal) throws DatabaseException { + if(component != null) { + Resource type = graph.syncRequest(new FindPossibleComponentTypeRequest(component)); + if(type != null) { + Resource root = graph.syncRequest(new IndexRoot(type)); + return Pair.make(type, root); + } else { + Resource doc = graph.syncRequest(new PossibleTypedParent(component, DocumentationResource.getInstance(graph).Document)); + if(doc != null) { + Resource componentType = graph.getSingleType(doc); + Resource root = graph.syncRequest(new IndexRoot(doc)); + return Pair.make(componentType, root); + } else { + Resource root = graph.syncRequest(new IndexRoot(component)); + return Pair.make(null, root); + } + } + // TODO: For Antti to consider and fix later + // Introduced to handle procedural user components where component == null + } else if (literal != null) { + Resource root = graph.syncRequest(new IndexRoot(literal)); + return Pair.make(null, root); + } else { + throw new DatabaseException("Couldn't resolve component type and root for component == null && literal == null"); + } + } + +} diff --git a/bundles/org.simantics.project/src/org/simantics/project/management/PlatformUtil.java b/bundles/org.simantics.project/src/org/simantics/project/management/PlatformUtil.java index af59dbfc1..a783acbad 100644 --- a/bundles/org.simantics.project/src/org/simantics/project/management/PlatformUtil.java +++ b/bundles/org.simantics.project/src/org/simantics/project/management/PlatformUtil.java @@ -478,8 +478,19 @@ public class PlatformUtil { } private static boolean isImmutable(Bundle bundle) { - String immutable = (String) bundle.getHeaders().get("Immutable"); - return immutable != null ? "true".equals(immutable) : true; + String immutable = (String) bundle.getHeaders().get("Immutable"); + if(immutable == null) + return true; + if("false".equals(immutable)) + return false; + if("trueWhenDeployed".equals(immutable)) { + String installHint = System.getProperty("installOntologiesAsDeployed"); + if("true".equals(installHint)) + return true; + else + return false; + } + return true; } public static class TGInfo { diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/repository/ModuleRepository.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/repository/ModuleRepository.java index a6650e9a4..78dfa8f88 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/repository/ModuleRepository.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/repository/ModuleRepository.java @@ -3,7 +3,9 @@ package org.simantics.scl.compiler.module.repository; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.HashSet; import java.util.Map; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import org.simantics.scl.compiler.common.exceptions.InternalCompilerError; @@ -52,6 +54,7 @@ public class ModuleRepository { private final ModuleRepository parentRepository; private final ModuleSourceRepository sourceRepository; private ConcurrentHashMap moduleCache = new ConcurrentHashMap(); + public Set runtimeEnvironments = new HashSet(); private static final ThreadLocal> PENDING_MODULES = new ThreadLocal>(); @@ -395,7 +398,9 @@ public class ModuleRepository { THashMap moduleMap = mapEntriesToModules(entries); Environment environment = createEnvironment(moduleMap, imports); THashMap runtimeModuleMap = mapEntriesToRuntimeModules(entries); - return new RuntimeEnvironmentImpl(environment, parentClassLoader, runtimeModuleMap); + RuntimeEnvironmentImpl result = new RuntimeEnvironmentImpl(environment, parentClassLoader, runtimeModuleMap); + runtimeEnvironments.add(result); + return result; } private static Environment createEnvironment( @@ -530,6 +535,10 @@ public class ModuleRepository { public void setAdvisor(ModuleCompilationOptionsAdvisor advisor) { this.advisor = advisor; } + + public Set getRuntimeEnvironments() { + return runtimeEnvironments; + } } \ No newline at end of file diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/runtime/ExpressionClassLoader.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/runtime/ExpressionClassLoader.java index 45e302720..dbfafe19b 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/runtime/ExpressionClassLoader.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/runtime/ExpressionClassLoader.java @@ -11,7 +11,7 @@ public class ExpressionClassLoader extends ClassLoader implements MutableClassLo public static final boolean TRACE_CLASS_CREATION = false; String basePackageName; - THashMap localClasses = new THashMap(); + public THashMap localClasses = new THashMap(); THashMap runtimeModuleMap; int transientPackageId = 0; THashMap valueCache = new THashMap(); @@ -57,7 +57,11 @@ public class ExpressionClassLoader extends ClassLoader implements MutableClassLo if(bytes == null) throw new ClassNotFoundException(name); - return defineClass(name, bytes, 0, bytes.length); + clazz = defineClass(name, bytes, 0, bytes.length); + resolveClass(clazz); + + return clazz; + } @Override diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/runtime/RuntimeModule.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/runtime/RuntimeModule.java index 2e35427cd..9955c77aa 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/runtime/RuntimeModule.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/runtime/RuntimeModule.java @@ -35,7 +35,7 @@ public class RuntimeModule { private static final Logger LOGGER = LoggerFactory.getLogger(RuntimeModule.class); public static final boolean VALIDATE_CLASS_NAMES = true; - public static final boolean TRACE_CLASS_CREATION = true; + public static final boolean TRACE_CLASS_CREATION = false; Module module; ModuleClassLoader classLoader; @@ -131,7 +131,9 @@ public class RuntimeModule { private Class getClass(String name) throws ClassNotFoundException { - System.out.println(moduleName + ":getClass " + name); + Class clazz = findLoadedClass(name); + if(clazz != null) + return clazz; // If the class is not generated from SCL, use parent class loader if(!name.startsWith(SCL_PACKAGE_PREFIX)) { @@ -388,7 +390,6 @@ public class RuntimeModule { ClassVisitor cv1 = new ClassVisitor(ASM5) {}; ClassVisitor cv = new ClassRemapper(cv1, m); cr.accept(cv, ClassReader.SKIP_DEBUG); - System.err.println(className + " refs: " + referencedClasses); return referencedClasses; } catch (Exception e) { e.printStackTrace(); @@ -396,22 +397,24 @@ public class RuntimeModule { return null; } - public void loadReferences() { - ConcreteModule cm = (ConcreteModule)module; - try { - for(String className : cm.getClasses().keySet()) { - Set refs = classReferences(className); - for(String s : refs) { - String internalName = s.replace('/', '.'); - try { - classLoader.loadClass(internalName); - } catch (Throwable e) { - e.printStackTrace(); + public void loadClasses() { + if(module instanceof ConcreteModule) { + ConcreteModule cm = (ConcreteModule)module; + try { + for(String className : cm.getClasses().keySet()) { + Set refs = classReferences(className); + for(String s : refs) { + String internalName = s.replace('/', '.'); + try { + classLoader.getClass(internalName); + } catch (Throwable e) { + e.printStackTrace(); + } } } + } catch (Throwable e) { + e.printStackTrace(); } - } catch (Throwable e) { - e.printStackTrace(); } } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/top/ExpressionEvaluator.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/top/ExpressionEvaluator.java index f69395c3d..b51b188cd 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/top/ExpressionEvaluator.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/top/ExpressionEvaluator.java @@ -76,7 +76,7 @@ public class ExpressionEvaluator { private Type expectedType; private LocalEnvironment localEnvironment; private LocalStorage localStorage; - private boolean interpretIfPossible = false; + private boolean interpretIfPossible = true; private ExpressionParseMode parseMode = ExpressionParseMode.EXPRESSION; private boolean validateOnly; diff --git a/bundles/org.simantics.scl.osgi/src/org/simantics/scl/osgi/SCLOsgi.java b/bundles/org.simantics.scl.osgi/src/org/simantics/scl/osgi/SCLOsgi.java index 1e0360051..35438747c 100644 --- a/bundles/org.simantics.scl.osgi/src/org/simantics/scl/osgi/SCLOsgi.java +++ b/bundles/org.simantics.scl.osgi/src/org/simantics/scl/osgi/SCLOsgi.java @@ -9,6 +9,8 @@ import org.simantics.scl.compiler.module.Module; import org.simantics.scl.compiler.module.options.ModuleCompilationOptions; import org.simantics.scl.compiler.module.options.ModuleCompilationOptionsAdvisor; import org.simantics.scl.compiler.module.repository.ModuleRepository; +import org.simantics.scl.compiler.runtime.ExpressionClassLoader; +import org.simantics.scl.compiler.runtime.RuntimeEnvironment; import org.simantics.scl.compiler.runtime.RuntimeModule; import org.simantics.scl.compiler.source.repository.ModuleSourceRepository; import org.simantics.scl.compiler.testing.repository.TestRepository; @@ -70,36 +72,16 @@ public class SCLOsgi { return null; } - public static String compileAllModules2() { + public static String primeClassloading() { ArrayList modulesWithErrors = new ArrayList(); SCLOsgi.SOURCE_REPOSITORY.forAllModules(new TObjectProcedure() { @Override public boolean execute(String moduleName) { - System.out.print(moduleName); - System.out.print(" - "); - Failable module = SCLOsgi.MODULE_REPOSITORY.getModule(moduleName); - if(module.didSucceed()) { - System.out.println("succeeded"); - } else if(module == DoesNotExist.INSTANCE) - System.out.println("does not exist"); // should not happen - else { - System.out.println("error"); - modulesWithErrors.add(moduleName); - } - return true; - } - }); - SCLOsgi.SOURCE_REPOSITORY.forAllModules(new TObjectProcedure() { - @Override - public boolean execute(String moduleName) { - System.out.print(moduleName); - System.out.print(" - "); Failable module = SCLOsgi.MODULE_REPOSITORY.getModule(moduleName); if(module.didSucceed()) { Failable frm = SCLOsgi.MODULE_REPOSITORY.getRuntimeModule(moduleName); RuntimeModule rm = frm.getResult(); - rm.loadReferences(); - System.out.println("succeeded"); + rm.loadClasses(); } else if(module == DoesNotExist.INSTANCE) System.out.println("does not exist"); // should not happen else { @@ -109,12 +91,15 @@ public class SCLOsgi { return true; } }); - if(!modulesWithErrors.isEmpty()) { - StringBuilder b = new StringBuilder(); - b.append("Some SCL modules failed to compile:"); - for(String module : modulesWithErrors) - b.append(' ').append(module); - return b.toString(); + for(RuntimeEnvironment env : SCLOsgi.MODULE_REPOSITORY.getRuntimeEnvironments()) { + ExpressionClassLoader ecl = (ExpressionClassLoader)env.getMutableClassLoader(); + for(String name : ecl.localClasses.keySet()) { + try { + ecl.loadClass(name.replace("/", ".")); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + } } return null; } diff --git a/bundles/org.simantics.structural2/src/org/simantics/structural2/scl/procedural/CompileProceduralComponentTypeRequest.java b/bundles/org.simantics.structural2/src/org/simantics/structural2/scl/procedural/CompileProceduralComponentTypeRequest.java index 871dc1975..3a4801078 100644 --- a/bundles/org.simantics.structural2/src/org/simantics/structural2/scl/procedural/CompileProceduralComponentTypeRequest.java +++ b/bundles/org.simantics.structural2/src/org/simantics/structural2/scl/procedural/CompileProceduralComponentTypeRequest.java @@ -58,6 +58,10 @@ public class CompileProceduralComponentTypeRequest extends AbstractExpressionCom } } + public static Function1 compile(ReadGraph graph, Resource componentType) throws DatabaseException { + return graph.syncRequest(new CompileProceduralComponentTypeRequest(componentType), TransientCacheListener.instance()); + } + @Override protected String getExpressionText(ReadGraph graph) throws DatabaseException { -- 2.45.2