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

Package libraries Java code as Java Modules #10714

Draft
wants to merge 97 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
9c149b9
Must specify --repl to enable debug server
JaroslavTulach Jul 29, 2024
76070ba
Use --repl to enable REPL changelog note
JaroslavTulach Jul 29, 2024
873c418
Towards a ClassPath per Package
JaroslavTulach Jul 30, 2024
3b1bc98
One ClassLoader per each Package
JaroslavTulach Jul 30, 2024
45f62cf
Define ModuleLayer for each Package
JaroslavTulach Jul 30, 2024
8700cc8
Load classes via ModuleLayer
JaroslavTulach Jul 30, 2024
74f8111
Turning std-base and std-aws into Java modules
JaroslavTulach Jul 30, 2024
7e865ce
Turn common-polyglot-core-utils into JPMS module
Akirathan Jul 30, 2024
3a6c335
Add depedencies to org.enso.std.base JPMS module
Akirathan Jul 30, 2024
b23be3d
Turn std-database into JPMS module
Akirathan Jul 30, 2024
f0dd3f7
Add depedencies to org.enso.std.aws JPMS module
Akirathan Jul 30, 2024
c4c1842
Using module-info to register SPI services
JaroslavTulach Jul 31, 2024
149dc7e
Removing another no longer needed dependency on NetBeans Lookup API
JaroslavTulach Jul 31, 2024
48b29c7
Removing add to class path concept
JaroslavTulach Jul 31, 2024
dd5723e
Turn std-table into JPMS module
Akirathan Jul 31, 2024
74fa9e1
Move tests that need internal access to Standard.Base into test/Base_…
JaroslavTulach Jul 31, 2024
1e48979
Resolving merge conficts
JaroslavTulach Jul 31, 2024
bbe754c
No more of Polyglot.Java
JaroslavTulach Aug 1, 2024
1514ad2
Nicer formatting with var
JaroslavTulach Aug 1, 2024
09c6946
Allow Standard.Table to depend on modules from Standard.Base
JaroslavTulach Aug 1, 2024
3148976
language-server/test compiles again
JaroslavTulach Aug 1, 2024
ae64b8a
Host Files values group_builder
JaroslavTulach Aug 5, 2024
c5e41ab
Merging in develop branch
JaroslavTulach Aug 5, 2024
6fdd11c
Merge with most recent develop branch that includes many JPMS
JaroslavTulach Sep 26, 2024
cfdda7b
Using moduleDependencies and internalModuleDependencies for standard …
JaroslavTulach Sep 26, 2024
d50f006
There can be Enso sources without associated package
JaroslavTulach Sep 26, 2024
202b1d8
Merging with develop
JaroslavTulach Oct 1, 2024
b04ce5c
Avoid duplicated modules. Use the one from boot layer.
JaroslavTulach Oct 1, 2024
d94a44d
Load all library Java modules with a single class loader
JaroslavTulach Oct 1, 2024
c71183c
Opening std-table.jar for reflection from Enso code
JaroslavTulach Oct 1, 2024
9bc7a3a
Visualization_Tests run and yield just nine errors
JaroslavTulach Oct 1, 2024
16b82c3
Standard.Test loads classes from Standard.Base
JaroslavTulach Oct 1, 2024
405e88d
Always prefer modules from parent layers
JaroslavTulach Oct 1, 2024
57e64e0
AWS requires access to Standard.Base and Standard.Database JARs
JaroslavTulach Oct 1, 2024
efda30f
Opening up std-table JAR, so Enso can access all Java classes
JaroslavTulach Oct 1, 2024
e9a0456
Less functional boilerplate
JaroslavTulach Oct 2, 2024
c0359e2
Merge remote-tracking branch 'origin/develop' into wip/jtulach/ClassP…
JaroslavTulach Oct 2, 2024
5b14f89
Special Lookup class and registration via a property to allow searchi…
JaroslavTulach Oct 2, 2024
841de5f
Turning Standard.Image into Java module
JaroslavTulach Oct 2, 2024
e6e5c09
Making test/Image_Tests pass OK
JaroslavTulach Oct 2, 2024
3194f6d
Avoid DriverManager. Directly talk to Driver instances.
JaroslavTulach Oct 2, 2024
cbe625f
Register SQLServerConnectionDetailsSPI in std-bits/microsoft/*/module…
JaroslavTulach Oct 3, 2024
c72ab8e
No polyglot symbol for org.enso.base.encoding.NewlineDetector in Tabl…
JaroslavTulach Oct 3, 2024
062b26e
No polyglot symbol for org.enso.table.data.table.Table in Table_Tests
JaroslavTulach Oct 3, 2024
e4cc4b4
No polyglot symbol for org.enso.table.data.table.join.between.SortedL…
JaroslavTulach Oct 3, 2024
9c86f7a
Using for loop
JaroslavTulach Oct 3, 2024
6992103
Make enso-test-java-helpers available to Table_Tests
JaroslavTulach Oct 3, 2024
98eeb64
No need to generate .bindings index to run benchmarks
JaroslavTulach Oct 3, 2024
60b4277
BenchProcessor puts runtime.jar into own layer. Use that one as bootL…
JaroslavTulach Oct 3, 2024
f482b72
test/Benchmarks need access to org.enso.table.data.index.OrderedMulti…
JaroslavTulach Oct 4, 2024
3112158
Introducing AWS wrapper module
JaroslavTulach Oct 7, 2024
e51eb3e
Placeholders for exported packages
JaroslavTulach Oct 7, 2024
a263449
Remove placeholders
Akirathan Oct 7, 2024
d161f9e
Remove aws-wrapper/Compile/moduleDependencies.
Akirathan Oct 7, 2024
c03825c
javaModuleName is the first setting
Akirathan Oct 7, 2024
3ec8ed0
Fix typo in cbor library dependency
Akirathan Oct 7, 2024
41fd4c1
Typo in module name.
Akirathan Oct 7, 2024
4bec7d9
Fix compilation of aws-wrapper
Akirathan Oct 7, 2024
88aaa76
Remove empty settings from std-aws
Akirathan Oct 7, 2024
be66f1b
Fix typo in module name
Akirathan Oct 7, 2024
c97ec77
aws-wrapper-assembly.jar gets into component directory.
Akirathan Oct 7, 2024
4a6e55c
Remove signature from aws-wrapper-assembly jar
Akirathan Oct 7, 2024
011494e
aws-wrapper dependency of std-aws is "provided".
Akirathan Oct 7, 2024
92bc7b4
Ensure aws-wrapper-assembly.jar gets into AWS/polyglot/java directory
Akirathan Oct 7, 2024
06ca5ce
Fix NoSuchElementException in JPMSUtils
Akirathan Oct 7, 2024
34dda82
Revert "aws-wrapper-assembly.jar gets into component directory."
Akirathan Oct 7, 2024
e788644
org.enso.std.aws exports org.enso.aws package
Akirathan Oct 7, 2024
644357d
slf4j is module dependency of aws-wrapper
Akirathan Oct 7, 2024
6c33fef
aws-wrapper depends on org.reactivestreams
Akirathan Oct 7, 2024
4c98a58
aws-wrapper uses its own service.
Akirathan Oct 7, 2024
e81e27c
Add some dependencies to aws-wrapper
Akirathan Oct 7, 2024
686f24d
Add necessary exports
Akirathan Oct 7, 2024
c5b1959
fmt
Akirathan Oct 7, 2024
2bd96d4
FileSystemSPI uses Lookup instead of ServiceLoader
Akirathan Oct 7, 2024
cf605cd
org.enso.std.aws provides DataLinkSPI.
Akirathan Oct 7, 2024
12ebe80
Better error message on duplicated service providers
Akirathan Oct 7, 2024
a31fb9c
Duplicate provider is just a warning
Akirathan Oct 7, 2024
77dc8de
List is easier to == than Array
JaroslavTulach Oct 8, 2024
6388881
runtime-integration-tests are loading classes with empty EnsoClassPath
JaroslavTulach Oct 8, 2024
00b47b4
Java.lookup_class has been removed
JaroslavTulach Oct 8, 2024
4173822
Using List() at the right places
JaroslavTulach Oct 8, 2024
f0c2ae4
std.table module isn't present in NI enso build
JaroslavTulach Oct 8, 2024
f11a26a
Use Lookup to lookup DatabaseConnectionDetailsSPI
JaroslavTulach Oct 8, 2024
b7f6542
An unexpected panic was thrown: (No_Such_Method.Error org.enso.base.n…
JaroslavTulach Oct 8, 2024
baeff36
Initialize ModuleLayer for a library sooner than a class is loaded fr…
JaroslavTulach Oct 8, 2024
a9bc32f
There is no runtime-fat-jar anymore
JaroslavTulach Oct 8, 2024
ec03e10
Add JDK_MODULES to small JDK of engine-runner native image
Akirathan Oct 8, 2024
1d4b172
Catch also ResolutionException
JaroslavTulach Oct 8, 2024
2bf4df1
Always add at least boot layer as parent
JaroslavTulach Oct 9, 2024
e8c220b
Make Tableau_Tests pass
JaroslavTulach Oct 9, 2024
bad898c
Bringing up-to-date with most recent develop
JaroslavTulach Oct 18, 2024
ee79b07
SQLServerDataLinkSPI is registered in module-info
JaroslavTulach Oct 18, 2024
6b1d504
Merge remote-tracking branch 'origin/develop' into wip/jtulach/ClassP…
JaroslavTulach Oct 21, 2024
4c46657
Backing out ec03e1080fbe19f7b7363206e876e72298bbc0f2
JaroslavTulach Oct 21, 2024
208d05d
Include chrome and DAP debugging tools in the enso executable
JaroslavTulach Oct 21, 2024
6d80539
Merge remote-tracking branch 'origin/develop' into wip/jtulach/ClassP…
JaroslavTulach Nov 22, 2024
986fb62
uses/provides instead of @ServiceProvider
JaroslavTulach Nov 22, 2024
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
228 changes: 200 additions & 28 deletions build.sbt

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions distribution/lib/Standard/AWS/0.0.0-dev/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ authors:
maintainers:
- name: Enso Team
email: [email protected]
requires:
- Standard.Base
JaroslavTulach marked this conversation as resolved.
Show resolved Hide resolved
- Standard.Database
JaroslavTulach marked this conversation as resolved.
Show resolved Hide resolved
1 change: 0 additions & 1 deletion distribution/lib/Standard/Base/0.0.0-dev/src/Main.enso
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ export project.Nothing.Nothing

export project.Panic.Panic

export project.Polyglot.Java
export project.Polyglot.Polyglot

export project.Random.Random
Expand Down
3 changes: 1 addition & 2 deletions distribution/lib/Standard/Base/0.0.0-dev/src/Meta.enso
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import project.Error.Error as Base_Error
import project.Errors.Common.Not_Found
import project.Function.Function
import project.Nothing.Nothing
import project.Polyglot.Java
from project.Data.Boolean import Boolean, False, True
from project.Runtime.Managed_Resource import Managed_Resource

Expand Down Expand Up @@ -445,7 +444,7 @@ is_a value typ = @Builtin_Method "Meta.is_a"
java_instance_check value typ =
val_java = get_polyglot_language value == "java"
typ_java = get_polyglot_language typ == "java"
val_java && typ_java && Java.is_instance value typ
val_java && typ_java && typ.class.isInstance value

## PRIVATE
ADVANCED
Expand Down
47 changes: 0 additions & 47 deletions distribution/lib/Standard/Base/0.0.0-dev/src/Polyglot.enso
Original file line number Diff line number Diff line change
Expand Up @@ -132,50 +132,3 @@ type Polyglot
Returns the executable name of a polyglot object.
get_executable_name : Any -> Text
get_executable_name value = @Builtin_Method "Polyglot.get_executable_name"

## Utilities for working with Java polyglot objects.
type Java
## PRIVATE
ADVANCED
Adds the provided entry to the host class path.

Arguments:
- path: The java classpath entry to add.

Use of the actual polyglot imports system should be preferred to use of
this method.

> Example
Adding Random to the classpath.

Java.add_to_class_path "java.util.Random"
add_to_class_path : Text -> Nothing
add_to_class_path path = @Builtin_Method "Java.add_to_class_path"

## PRIVATE
ADVANCED
Looks up a java symbol on the classpath by name.

Arguments:
- name: The name of the java symbol to look up.

Use of the actual polyglot imports system should be preferred to use of
this method.

> Example
Look up java's Random class.

Java.lookup_class "java.util.Random"
lookup_class : Text -> Any
lookup_class name = @Builtin_Method "Java.lookup_class"

## PRIVATE
Checks whether an object is an instance of a given class.

Arguments:
- object: The object to check for class membership.
- class: The java class to check for membership in.
is_instance : Any -> Any -> Boolean
is_instance object class =
class_object = class.class
class_object.isInstance object
3 changes: 3 additions & 0 deletions distribution/lib/Standard/Database/0.0.0-dev/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ authors:
maintainers:
- name: Enso Team
email: [email protected]
requires:
- Standard.Base
- Standard.Table
2 changes: 2 additions & 0 deletions distribution/lib/Standard/Image/0.0.0-dev/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ authors:
maintainers:
- name: Enso Team
email: [email protected]
requires:
- Standard.Base
3 changes: 3 additions & 0 deletions distribution/lib/Standard/Microsoft/0.0.0-dev/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ authors:
maintainers:
- name: Enso Team
email: [email protected]
requires:
- Standard.Base
- Standard.Database
2 changes: 2 additions & 0 deletions distribution/lib/Standard/Table/0.0.0-dev/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ authors:
maintainers:
- name: Enso Team
email: [email protected]
requires:
- Standard.Base
JaroslavTulach marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 2 additions & 0 deletions distribution/lib/Standard/Tableau/0.0.0-dev/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ authors:
maintainers:
- name: Enso Team
email: [email protected]
requires:
- Standard.Table
2 changes: 2 additions & 0 deletions distribution/lib/Standard/Test/0.0.0-dev/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ authors:
maintainers:
- name: Enso Team
email: [email protected]
requires:
- Standard.Base
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ object ComponentGroupsResolverSpec {
license = "",
authors = Nil,
maintainers = Nil,
requires = List(),
edition = None,
preferLocalLibraries = true,
componentGroups = Some(componentGroups)
Expand All @@ -296,6 +297,7 @@ object ComponentGroupsResolverSpec {
license = "",
authors = Nil,
maintainers = Nil,
requires = List(),
edition = None,
preferLocalLibraries = true,
componentGroups = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ object ComponentGroupsValidatorSpec {
authors = Nil,
maintainers = Nil,
edition = None,
requires = List(),
preferLocalLibraries = true,
componentGroups = Some(
ComponentGroups(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ class PolyglotTest extends InterpreterTest {
val code =
"""from Standard.Base import all
|import Standard.Base.Data.Array.Array
|polyglot java import org.enso.example.TestClass
|
|main =
| class = Java.lookup_class "org.enso.example.TestClass"
| class = TestClass
| method = Polyglot.get_member class "add"
| Polyglot.execute method ([1, 2].to_array)
|""".stripMargin
Expand Down Expand Up @@ -60,9 +61,10 @@ class PolyglotTest extends InterpreterTest {
"allow instantiating objects and calling methods on them" in {
val code =
"""from Standard.Base import all
|polyglot java import org.enso.example.TestClass
|
|main =
| class = Java.lookup_class "org.enso.example.TestClass"
| class = TestClass
| instance = Polyglot.new class [x -> x * 2]
| Polyglot.invoke instance "callFunctionAndIncrement" [10]
|""".stripMargin
Expand All @@ -72,9 +74,10 @@ class PolyglotTest extends InterpreterTest {
"allow listing available members of an object" in {
val code =
"""from Standard.Base import all
|polyglot java import org.enso.example.TestClass
|
|main =
| class = Java.lookup_class "org.enso.example.TestClass"
| class = TestClass
| instance = Polyglot.new class []
| members = Polyglot.get_members instance
| IO.println members.length
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
package org.enso.interpreter.runtime;

import com.oracle.truffle.api.TruffleLogger;
import java.lang.module.Configuration;
import java.lang.module.FindException;
import java.lang.module.ModuleFinder;
import java.lang.module.ResolutionException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.logging.Level;

/** Representation of an Enso library class path. */
public final class EnsoClassPath {
static final EnsoClassPath EMPTY = new EnsoClassPath("empty", null, null, null);
private final Object id;
private final ModuleLayer.Controller cntrl;
private final ModuleLayer layer;
final ClassLoader loader;

private EnsoClassPath(
Object id, ModuleLayer.Controller cntrl, ModuleLayer layer, ClassLoader loader) {
this.id = id;
if (cntrl != null) {
// cannot be null
layer.getClass();
}
this.cntrl = cntrl;
this.layer = layer;
this.loader = loader;
}

private static ModuleLayer bootLayer() {
var myLayer = EnsoClassPath.class.getModule().getLayer();
if (myLayer != null) {
return myLayer;
} else {
return ModuleLayer.boot();
}
}

static EnsoClassPath create(Path file, List<EnsoClassPath> parents, TruffleLogger log) {
try {
return createImpl(file, parents);
} catch (FindException | ResolutionException e) {
var sb = new StringBuilder();
sb.append("Cannot instantiate modules at ").append(file);
log.log(Level.FINE, sb.toString(), e);
for (var cp : parents) {
sb.append("\n with parent ").append(cp);
}
e.setStackTrace(
Arrays.asList(e.getStackTrace()).stream().limit(10).toArray(StackTraceElement[]::new));
log.log(Level.SEVERE, sb.toString(), e);
return EnsoClassPath.EMPTY;
}
}

private static EnsoClassPath createImpl(Path file, List<EnsoClassPath> parents) {
var locations = new ArrayList<Path>();
var moduleNames = new ArrayList<String>();
MODULE_LOOP:
for (var mod : ModuleFinder.of(file).findAll()) {
if (bootLayer().findModule(mod.descriptor().name()).isPresent()) {
continue;
}
for (var p : parents) {
if (p.layer != null && p.layer.findModule(mod.descriptor().name()).isPresent()) {
continue MODULE_LOOP;
}
}
moduleNames.add(mod.descriptor().name());
var uri = mod.location().get();
locations.add(Path.of(uri));
}
if (moduleNames.isEmpty() && parents.isEmpty()) {
return EMPTY;
} else {
var finder = ModuleFinder.of(locations.toArray(new Path[0]));
ModuleLayer.Controller cntrl;
if (parents.isEmpty()) {
var parent = bootLayer();
var parentLoader = parent.findLoader("java.base");
var parentCfgs = Collections.singletonList(parent.configuration());
var parentModules = Collections.singletonList(parent);
var cfg =
Configuration.resolveAndBind(finder, parentCfgs, ModuleFinder.ofSystem(), moduleNames);
cntrl = ModuleLayer.defineModulesWithOneLoader(cfg, parentModules, parentLoader);
} else {
var parentCfgs = new ArrayList<Configuration>();
var parentLayers = new ArrayList<ModuleLayer>();
for (var cp : parents) {
if (cp.layer == null) {
continue;
}
parentLayers.add(cp.layer);
parentCfgs.add(cp.layer.configuration());
}
if (parentLayers.isEmpty()) {
parentLayers.add(ModuleLayer.boot());
parentCfgs.add(ModuleLayer.boot().configuration());
}
var parentLoader = bootLayer().findLoader("java.base");
var cfg =
Configuration.resolveAndBind(finder, parentCfgs, ModuleFinder.ofSystem(), moduleNames);
cntrl = ModuleLayer.defineModulesWithOneLoader(cfg, parentLayers, parentLoader);
}
var layer = cntrl.layer();
var loader =
!moduleNames.isEmpty() ? layer.findLoader(moduleNames.get(0)) : parents.get(0).loader;

registerLayer(layer);
return new EnsoClassPath(file, cntrl, layer, loader);
}
}

@SuppressWarnings("unchecked")
private static void registerLayer(ModuleLayer moduleLayer) {
var props = System.getProperties();
Collection<ModuleLayer> layers;
if (props.get("enso.class.path") instanceof Collection registeredLayers) {
layers = registeredLayers;
} else {
layers = new LinkedHashSet<>();
props.put("enso.class.path", layers);
}
layers.add(moduleLayer);
}

@Override
public String toString() {
return "EnsoClassPath[id=" + id + "]";
}
}
Loading
Loading