Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect outdated launcher #10779

Merged
merged 7 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 36 additions & 6 deletions engine/runner/src/main/java/org/enso/runner/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -1278,6 +1278,12 @@ private void launch(String[] args) throws IOException, InterruptedException, URI
var logLevel = setupLogging(line, logMasking);
var props = parseSystemProperties(line);

var loc = Main.class.getProtectionDomain().getCodeSource().getLocation();
var component = new File(loc.toURI().resolve("..")).getAbsoluteFile();
if (!component.getName().equals("component")) {
component = new File(component, "component");
}
assert checkOutdatedLauncher(new File(loc.toURI()), component) || true;
if (line.hasOption(JVM_OPTION)) {
var jvm = line.getOptionValue(JVM_OPTION);
var current = System.getProperty("java.home");
Expand All @@ -1288,7 +1294,6 @@ private void launch(String[] args) throws IOException, InterruptedException, URI
if (!shouldLaunchJvm) {
println(JVM_OPTION + " option has no effect - already running in JVM " + current);
} else {
var loc = Main.class.getProtectionDomain().getCodeSource().getLocation();
var commandAndArgs = new ArrayList<String>();
JVM_FOUND:
if (jvm == null) {
Expand Down Expand Up @@ -1318,18 +1323,18 @@ private void launch(String[] args) throws IOException, InterruptedException, URI
commandAndArgs.add(op);
}
}
var assertsOn = false;
assert assertsOn = true;
if (assertsOn) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This "transfer of assertion mode" is now causing following failure, @Akirathan:

Execution finished with an error: java.lang.AssertionError
         at <java> org.enso.runtime/org.enso.interpreter.runtime.warning.WithWarnings.<init>(WithWarnings.java:82)
         at <java> org.enso.runtime/org.enso.interpreter.runtime.warning.AppendWarningNode.doObjectMultipleWarningsHashMap(AppendWarningNode.java:120)
         at <java> org.enso.runtime/org.enso.interpreter.runtime.warning.AppendWarningNodeGen.executeAndSpecialize(AppendWarningNodeGen.java:318)
         at <java> org.enso.runtime/org.enso.interpreter.runtime.warning.AppendWarningNodeGen.executeAppend(AppendWarningNodeGen.java:193)
         at <java> org.enso.runtime/org.enso.interpreter.runtime.data.atom.InstantiateNode.doExecute(InstantiateNode.java:102)
         at <java> org.enso.runtime/org.enso.interpreter.runtime.data.atom.InstantiateNodeGen.executeAndSpecialize(InstantiateNodeGen.java:95)
         at <java> org.enso.runtime/org.enso.interpreter.runtime.data.atom.InstantiateNodeGen.executeGeneric(InstantiateNodeGen.java:76)
         at <java> org.enso.runtime/org.enso.interpreter.node.callable.function.BlockNode.executeGeneric(BlockNode.java:54)
         at <java> org.enso.runtime/org.enso.interpreter.node.ClosureRootNode.execute(ClosureRootNode.java:85)
         at <enso> Data.Value(Internal)
         at <enso> Data.type.new(src/Decimal_Benchmark.enso:30:9-180)
         at <enso> Decimal_Benchmark.collect_benches.Decimal_Benchmark.collect_benches<arg-1>(src/Decimal_Benchmark.enso:37:29-42)

the 5575d88 change should fix the problem.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alas, that fix leads to this error:

️ Execution finished with an error: java.lang.AssertionError
 ️at <java> org.enso.interpreter.runtime.warning.WithWarnings.<init>(WithWarnings.java:84)
 ️at <java> org.enso.interpreter.runtime.warning.AppendWarningNode.doWithWarnMultipleWarningsHashMap(AppendWarningNode.java:140)
  at <java> org.enso.interpreter.runtime.warning.AppendWarningNodeGen.executeAndSpecialize(AppendWarningNodeGen.java:345)
  at <java> org.enso.interpreter.runtime.warning.AppendWarningNodeGen.executeAppend(AppendWarningNodeGen.java:193)
  at <java> org.enso.interpreter.node.callable.InvokeMethodNode.doWarning(InvokeMethodNode.java:479)
 ️at <java> org.enso.interpreter.node.callable.InvokeMethodNodeGen.executeAndSpecialize(InvokeMethodNodeGen.java:781)
 ️at <java> org.enso.interpreter.node.callable.InvokeMethodNodeGen.execute(InvokeMethodNodeGen.java:533)

let's assume 0b9a49b fixes both - the instantiate and the invoke case.

commandAndArgs.add("-ea");
}
if (props != null) {
for (var e : props.entrySet()) {
commandAndArgs.add("-D" + e.getKey() + "=" + e.getValue());
}
}

commandAndArgs.add("--add-opens=java.base/java.nio=ALL-UNNAMED");
commandAndArgs.add("--module-path");
var component = new File(loc.toURI().resolve("..")).getAbsoluteFile();
if (!component.getName().equals("component")) {
component = new File(component, "component");
}
if (!component.isDirectory()) {
throw new IOException("Cannot find " + component + " directory");
}
Expand Down Expand Up @@ -1443,4 +1448,29 @@ private void launch(CommandLine line, Level logLevel, boolean logMasking) {
protected String getLanguageId() {
return LanguageInfo.ID;
}

/**
* Check if native image based launcher is up-to-date. Prints a warning when it is outdated.
*
* @param base the base file to check
* @param dir directory with other files that should be older than base
* @return
*/
private static boolean checkOutdatedLauncher(File base, File dir) {
var needsCheck = base.canExecute();
if (needsCheck) {
var files = dir.listFiles();
if (files != null) {
var baseTime = base.lastModified();
for (var f : files) {
if (baseTime < f.lastModified()) {
System.err.println(
"File " + base + " is older than " + f + " consider running in --jvm mode");
return false;
}
}
}
}
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.enso.interpreter.runtime.data.Type;
import org.enso.interpreter.runtime.data.hash.EnsoHashMap;
import org.enso.interpreter.runtime.data.hash.HashMapInsertAllNode;
import org.enso.interpreter.runtime.data.hash.HashMapSizeNode;
import org.enso.interpreter.runtime.data.text.Text;
import org.enso.interpreter.runtime.error.DataflowError;
import org.enso.interpreter.runtime.error.PanicException;
Expand Down Expand Up @@ -509,11 +510,11 @@ Object doPolyglot(
@Cached BranchProfile anyWarningsProfile,
@Cached HostMethodCallNode hostMethodCallNode,
@Shared @Cached AppendWarningNode appendWarningNode,
@Cached HashMapSizeNode mapSizeNode,
@Cached HashMapInsertAllNode mapInsertAllNode) {
Object[] args = new Object[argExecutors.length];
boolean anyWarnings = false;
var accumulatedWarnings = EnsoHashMap.empty();
var maxWarnings = EnsoContext.get(this).getWarningsLimit();
for (int i = 0; i < argExecutors.length; i++) {
var r = argExecutors[i].executeThunk(frame, arguments[i + 1], state, TailStatus.NOT_TAIL);
if (r instanceof DataflowError) {
Expand All @@ -524,8 +525,11 @@ Object doPolyglot(
anyWarnings = true;
try {
EnsoHashMap rWarnsMap = warnings.getWarnings(r, false);
var maxWarningsToAdd =
EnsoContext.get(this).getWarningsLimit() - mapSizeNode.execute(accumulatedWarnings);
accumulatedWarnings =
mapInsertAllNode.executeInsertAll(frame, accumulatedWarnings, rWarnsMap, maxWarnings);
mapInsertAllNode.executeInsertAll(
frame, accumulatedWarnings, rWarnsMap, maxWarningsToAdd);
args[i] = warnings.removeWarnings(r);
} catch (UnsupportedMessageException e) {
var ctx = EnsoContext.get(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.enso.interpreter.runtime.EnsoContext;
import org.enso.interpreter.runtime.data.hash.EnsoHashMap;
import org.enso.interpreter.runtime.data.hash.HashMapInsertAllNode;
import org.enso.interpreter.runtime.data.hash.HashMapSizeNode;
import org.enso.interpreter.runtime.type.TypesGen;
import org.enso.interpreter.runtime.warning.AppendWarningNode;
import org.enso.interpreter.runtime.warning.WarningsLibrary;
Expand Down Expand Up @@ -68,11 +69,11 @@ Object doExecute(
VirtualFrame frame,
@Cached(parameters = {"constructor"}) AtomConstructorInstanceNode createInstanceNode,
@Cached AppendWarningNode appendWarningNode,
@Cached HashMapSizeNode mapSizeNode,
@Cached HashMapInsertAllNode mapInsertAllNode) {
Object[] argumentValues = new Object[arguments.length];
boolean anyWarnings = false;
var accumulatedWarnings = EnsoHashMap.empty();
var maxWarnings = EnsoContext.get(this).getWarningsLimit();
for (int i = 0; i < arguments.length; i++) {
CountingConditionProfile profile = profiles[i];
CountingConditionProfile warningProfile = warningProfiles[i];
Expand All @@ -84,9 +85,11 @@ Object doExecute(
anyWarnings = true;
try {
var argumentWarnsMap = warnings.getWarnings(argument, false);
var maxWarningsToAdd =
EnsoContext.get(this).getWarningsLimit() - mapSizeNode.execute(accumulatedWarnings);
accumulatedWarnings =
mapInsertAllNode.executeInsertAll(
frame, accumulatedWarnings, argumentWarnsMap, maxWarnings);
frame, accumulatedWarnings, argumentWarnsMap, maxWarningsToAdd);
argumentValues[i] = warnings.removeWarnings(argument);
} catch (UnsupportedMessageException e) {
throw EnsoContext.get(this).raiseAssertionPanic(this, null, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,19 @@ public static HashMapInsertAllNode getUncached() {
* @param maxItems Maximum number of items to insert into the map from the container.
*/
public abstract EnsoHashMap executeInsertAll(
VirtualFrame frame, EnsoHashMap self, EnsoHashMap container, int maxItems);
VirtualFrame frame, EnsoHashMap self, EnsoHashMap container, long maxItems);

@Specialization
EnsoHashMap doEnsoHashMaps(
VirtualFrame frame,
EnsoHashMap self,
EnsoHashMap other,
int maxItems,
long maxItems,
@Cached HashCodeNode hashCodeNode,
@Cached EqualsNode equalsNode) {
assert maxItems > 0;
if (maxItems <= 0) {
return self;
}
var selfSize = self.getHashSize();
var otherSize = other.getHashSize();
if (otherSize == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,8 @@ WithWarnings doWithWarnMultipleWarningsHashMap(
var maxWarns = withWarnings.maxWarnings;
var warnsMap = withWarnings.warnings;
var curWarnsCnt = (int) mapSizeNode.execute(warnsMap);
warnsMap =
mapInsertAllNode.executeInsertAll(frame, warnsMap, newWarnsMap, maxWarns - curWarnsCnt);
var isLimitReached =
mapSizeNode.execute(withWarnings.warnings) + mapSizeNode.execute(newWarnsMap) >= maxWarns;
warnsMap = mapInsertAllNode.executeInsertAll(frame, warnsMap, newWarnsMap, maxWarns);
var isLimitReached = mapSizeNode.execute(warnsMap) >= maxWarns;
return new WithWarnings(withWarnings.value, withWarnings.maxWarnings, isLimitReached, warnsMap);
}

Expand Down
Loading