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

Invoke all Enso benchmarks via JMH #7101

Merged
merged 77 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from 70 commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
188d465
[WIP] Invoke Enso bench via JMH
Akirathan Jun 22, 2023
8836629
Abstract from direct call to Bench.measure
JaroslavTulach Jul 1, 2023
88fd6fb
Builder pattern to collect all benchmarks first and only then execute…
JaroslavTulach Jul 1, 2023
19a439e
Improve type ascriptions of Bench type
Akirathan Jul 7, 2023
f6dd423
[WIP] Add LibBenchRunner
Akirathan Jul 7, 2023
58c1e0d
Making the project compilable (again)
JaroslavTulach Jul 9, 2023
f5a9aae
Executed few suites from Vector/Operations.enso in JMH
JaroslavTulach Jul 9, 2023
3f37a7d
Merge remote-tracking branch 'origin/develop' into wip/akirathan/enso…
JaroslavTulach Jul 10, 2023
7c33b3a
Bench is the type, not Group
JaroslavTulach Jul 10, 2023
f70a6da
sumStatistic benchmark
JaroslavTulach Jul 10, 2023
1584357
Generate double values
JaroslavTulach Jul 10, 2023
0f41777
Add prototype of bench suites discovery
Akirathan Jul 17, 2023
9d9f328
Move LibBenchRunner to a separate project `bench-libs`
Akirathan Jul 17, 2023
0ee38df
Get rid of IRUtils.scala
Akirathan Jul 18, 2023
3ec89ef
Merge branch 'develop' into wip/akirathan/enso-bench-jmh
Akirathan Jul 19, 2023
733338d
Add SpecCollector
Akirathan Jul 20, 2023
5b543ef
LibBenchRunner prints help
Akirathan Jul 20, 2023
1f916e6
Merge branch 'develop' into wip/akirathan/enso-bench-jmh
Akirathan Jul 20, 2023
40a2ad7
LibBenchRunner can list benchmarks
Akirathan Jul 20, 2023
65051a4
Fix Operations.enso to provide specs and not to run them
Akirathan Jul 20, 2023
d5b41f3
Add simple annotation processor
Akirathan Jul 24, 2023
1adad1a
Move bench-libs to std-bits/benchmarks
Akirathan Jul 24, 2023
85c3b96
Integrate annotation processor into bench-libs
Akirathan Jul 24, 2023
5339233
Add truffle and runtime to annotation processor's class path
Akirathan Jul 25, 2023
a9cdd19
BenchProcessor creates JMH sources for all benchmarks
Akirathan Jul 26, 2023
906cc4d
Put generated code into src_managed directory
Akirathan Jul 26, 2023
8f3d761
Remove benchmark discovery code from LibBenchRunner
Akirathan Jul 26, 2023
179949e
Do not use generate package name for generated sources
Akirathan Jul 27, 2023
df82640
Incorporate bench and benchOnly commands in bench-libs project
Akirathan Jul 27, 2023
6ec55f9
Move LibBenchRunner under src/bench from src/main
Akirathan Jul 27, 2023
954e96f
Benchmark/run/javaOptions gets fullClasspath
Akirathan Jul 27, 2023
18e313a
Generate source into Compile/sourceManaged.
Akirathan Jul 27, 2023
4e9afc2
Use fully qualified module names in BenchProcessor
Akirathan Jul 27, 2023
45d1143
Add ability to attach debugger to the annotation processors.
Akirathan Jul 27, 2023
a124a0b
Add the benchmarks documentation
Akirathan Jul 27, 2023
8b6b96d
Discard spurious warnings from javac for generated sources
Akirathan Jul 27, 2023
16d2f56
Remove some temporary logging
Akirathan Jul 27, 2023
ad538e8
Fail annotation processing properly instead of throwing exceptions
Akirathan Jul 27, 2023
dc09d02
Fix SourceVersion warning
Akirathan Jul 27, 2023
60f2372
Catch exception, not throwable
Akirathan Jul 27, 2023
4888e45
cosmetics
Akirathan Jul 27, 2023
82b14c8
Merge branch 'develop' into wip/akirathan/enso-bench-jmh
Akirathan Jul 27, 2023
95e6dea
Easier way to debug the runtime/benchOnly command
JaroslavTulach Jul 28, 2023
df99383
Restrict dependencies scopes
Akirathan Jul 28, 2023
8683d37
Merge branch 'origin/wip/akirathan/enso-bench-jmh' of github.com:enso…
Akirathan Jul 28, 2023
00e6cf3
Restructure debugging docs, reformat.
Akirathan Jul 28, 2023
62f3480
Remove meso benchmark terminology
Akirathan Jul 28, 2023
80564b0
Remove unecessary method from BenchSUiteWrapper
Akirathan Jul 28, 2023
2e57598
Some refactoring.
Akirathan Jul 28, 2023
f6bdc67
Move bench-processor from std-bits to lib/scala/bench-processor
Akirathan Jul 28, 2023
5001012
Add Benchmark runner code to bench-processor
Akirathan Jul 28, 2023
882ae8a
Delete unused benchmark code
Akirathan Jul 28, 2023
53373b7
Distinct.enso benchmark uses the new bench builder API
Akirathan Jul 28, 2023
81353d2
Main module of test/Benchmarks collects all bench specs
Akirathan Jul 28, 2023
1d389d9
Fix jakarta.xml dependency
Akirathan Jul 28, 2023
c19b53c
Add module-discovery parameters to GenerateBenchSources annotation
Akirathan Jul 28, 2023
c5ec01e
Add tests for SpecCollector
Akirathan Aug 1, 2023
9b34546
BenchProcessor supports new module-discovery parameters
Akirathan Aug 1, 2023
8bad812
Some improvements of bench-libs SBT project.
Akirathan Aug 1, 2023
2f409fb
Unify report collecting
Akirathan Aug 1, 2023
30bb9f0
Add Utils class
Akirathan Aug 1, 2023
d3e6a87
Add some tests
Akirathan Aug 1, 2023
7df60c5
No star import in Scala sources in project
Akirathan Aug 2, 2023
6676b8c
--no-limit-modules is not a hardcoded, but a documentted constant in …
Akirathan Aug 2, 2023
60899de
Filter out spurious warning messages from javac
Akirathan Aug 2, 2023
97a0036
Reformat bench-libs project in sbt - group settings by the configurat…
Akirathan Aug 2, 2023
f562284
Generated source does not contain absolute paths
Akirathan Aug 2, 2023
ea5315f
Rename `bench-libs` sbt project to `std-benchmarks`.
Akirathan Aug 2, 2023
ed1909d
In std-benchmarks project, withDebug command works the same as in run…
Akirathan Aug 2, 2023
f5e9715
Add some docs
Akirathan Aug 3, 2023
2664ded
Remove --no-limit-modules
Akirathan Aug 3, 2023
08fa60b
fmt docs
Akirathan Aug 3, 2023
495e6e6
Add some docs
Akirathan Aug 3, 2023
939e8fb
Minor fixes in the docs
Akirathan Aug 3, 2023
701183e
Merge branch 'develop' into wip/akirathan/enso-bench-jmh
Akirathan Aug 4, 2023
11e0a12
Revert "Easier way to debug the runtime/benchOnly command"
Akirathan Aug 7, 2023
7141b08
fmt docs
Akirathan Aug 7, 2023
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
114 changes: 114 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -1769,6 +1769,120 @@ lazy val `distribution-manager` = project
.dependsOn(pkg)
.dependsOn(`logging-utils`)

lazy val `bench-processor` = (project in file("lib/scala/bench-processor"))
.settings(
frgaalJavaCompilerSetting,
libraryDependencies ++= Seq(
"jakarta.xml.bind" % "jakarta.xml.bind-api" % jaxbVersion,
"com.sun.xml.bind" % "jaxb-impl" % jaxbVersion,
"org.openjdk.jmh" % "jmh-core" % jmhVersion % "provided",
"org.openjdk.jmh" % "jmh-generator-annprocess" % jmhVersion % "provided",
"org.netbeans.api" % "org-openide-util-lookup" % netbeansApiVersion % "provided",
"org.graalvm.sdk" % "graal-sdk" % graalMavenPackagesVersion % "provided",
"junit" % "junit" % junitVersion % Test,
"com.github.sbt" % "junit-interface" % junitIfVersion % Test,
"org.graalvm.truffle" % "truffle-api" % graalMavenPackagesVersion % Test
),
Compile / javacOptions := ((Compile / javacOptions).value ++
// Only run ServiceProvider processor and ignore those defined in META-INF, thus
// fixing incremental compilation setup
Seq(
"-processor",
"org.netbeans.modules.openide.util.ServiceProviderProcessor"
)),
commands += WithDebugCommand.withDebug,
(Test / fork) := true,
(Test / parallelExecution) := false,
(Test / javaOptions) ++= {
val runtimeJars =
(LocalProject("runtime") / Compile / fullClasspath).value
val jarsStr = runtimeJars.map(_.data).mkString(File.pathSeparator)
Seq(
s"-Dtruffle.class.path.append=${jarsStr}"
)
}
)
.dependsOn(`polyglot-api`)
.dependsOn(runtime)

lazy val `std-benchmarks` = (project in file("std-bits/benchmarks"))
.settings(
frgaalJavaCompilerSetting,
libraryDependencies ++= jmh ++ Seq(
"org.openjdk.jmh" % "jmh-core" % jmhVersion % Benchmark,
"org.openjdk.jmh" % "jmh-generator-annprocess" % jmhVersion % Benchmark,
"org.graalvm.sdk" % "graal-sdk" % graalMavenPackagesVersion % "provided",
"org.graalvm.truffle" % "truffle-api" % graalMavenPackagesVersion % Benchmark
),
commands += WithDebugCommand.withDebug,
(Compile / logManager) :=
sbt.internal.util.CustomLogManager.excludeMsg(
"Could not determine source for class ",
Level.Warn
)
)
.configs(Benchmark)
.settings(
inConfig(Benchmark)(Defaults.testSettings)
)
.settings(
(Benchmark / parallelExecution) := false,
(Benchmark / run / fork) := true,
(Benchmark / run / connectInput) := true,
// Pass -Dtruffle.class.path.append to javac
(Benchmark / compile / javacOptions) ++= {
val runtimeClasspath =
(LocalProject("runtime") / Compile / fullClasspath).value
val runtimeInstrumentsClasspath =
(LocalProject(
"runtime-with-instruments"
) / Compile / fullClasspath).value
val appendClasspath =
(runtimeClasspath ++ runtimeInstrumentsClasspath)
.map(_.data)
.mkString(File.pathSeparator)
Seq(
FrgaalJavaCompiler.noLimitModulesArg,
s"-J-Dtruffle.class.path.append=$appendClasspath"
)
},
(Benchmark / compile / javacOptions) ++= Seq(
"-s",
(Benchmark / sourceManaged).value.getAbsolutePath,
"-Xlint:unchecked"
),
(Benchmark / run / javaOptions) ++= {
val runtimeClasspath =
(LocalProject("runtime") / Compile / fullClasspath).value
val runtimeInstrumentsClasspath =
(LocalProject(
"runtime-with-instruments"
) / Compile / fullClasspath).value
val appendClasspath =
(runtimeClasspath ++ runtimeInstrumentsClasspath)
.map(_.data)
.mkString(File.pathSeparator)
Seq(
s"-Dtruffle.class.path.append=$appendClasspath"
)
}
)
.settings(
bench := (Benchmark / run).toTask("").tag(Exclusive).value,
benchOnly := Def.inputTaskDyn {
import complete.Parsers.spaceDelimited
val name = spaceDelimited("<name>").parsed match {
case List(name) => name
case _ => throw new IllegalArgumentException("Expected one argument.")
}
Def.task {
(Benchmark / run).toTask(" " + name).value
}
}.evaluated
)
.dependsOn(`bench-processor` % Benchmark)
.dependsOn(runtime % Benchmark)

lazy val editions = project
.in(file("lib/scala/editions"))
.configs(Test)
Expand Down
4 changes: 3 additions & 1 deletion docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ the following flags:
allow for manual analysis and discovery of optimisation failures.
- `--showCompilations`: Prints the truffle compilation trace information.
- `--printAssembly`: Prints the assembly output from the HotSpot JIT tier.
- `--debugger`: Launches the JVM with the remote debugger enabled.

For more information on this sbt command, please see
[WithDebugCommand.scala](../project/WithDebugCommand.scala).
Expand Down Expand Up @@ -756,7 +757,8 @@ interface of the runner prints all server options when you execute it with
Below are options uses by the Language Server:

- `--server`: Runs the Language Server
- `--root-id <uuid>`: Content root id.
- `--root-id <uuid>`: Content root id. The Language Server chooses one randomly,
so can pass any valid UUID.
Akirathan marked this conversation as resolved.
Show resolved Hide resolved
- `--path <path>`: Path to the content root.
- `--interface <interface>`: Interface for processing all incoming connections.
Default value is 127.0.0.1
Expand Down
104 changes: 11 additions & 93 deletions docs/debugger/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,96 +8,14 @@ order: 0

# Enso Debugger

The Enso Debugger allows amongst other things, to execute arbitrary expressions
in a given execution context - this is used to implement a debugging REPL. The
REPL can be launched when triggering a breakpoint in the code.

This folder contains all documentation pertaining to the REPL and the debugger,
which is broken up as follows:

- [**The Enso Debugger Protocol:**](./protocol.md) The protocol for the Debugger

# Chrome Developer Tools Debugger

As a well written citizen of the [GraalVM](http://graalvm.org) project the Enso
language can be used with existing tools available for the overall platform. One
of them is
[Chrome Debugger](https://www.graalvm.org/22.1/tools/chrome-debugger/) and Enso
language is fully integrated with it. Launch the `bin/enso` executable with
additional `--inspect` option and debug your Enso programs in _Chrome Developer
Tools_.

```bash
enso$ ./built-distribution/enso-engine-*/enso-*/bin/enso --inspect --run ./test/Tests/src/Data/Numbers_Spec.enso
Debugger listening on ws://127.0.0.1:9229/Wugyrg9
For help, see: https://www.graalvm.org/tools/chrome-debugger
E.g. in Chrome open: devtools://devtools/bundled/js_app.html?ws=127.0.0.1:9229/Wugyrg9
```

copy the printed URL into chrome browser and you should see:

![Chrome Debugger](https://user-images.githubusercontent.com/26887752/209614265-684f530e-cf7e-45d5-9450-7ea1e4f65986.png)

Step in, step over, set breakpoints, watch values of the variables as well as
evaluate arbitrary expressions in the console. Note that as of December 2022,
with GraalVM 22.3.0, there is a well-known
[bug in Truffle](https://github.com/oracle/graal/issues/5513) that causes
`NullPointerException` when a host object gets into the chrome inspector. There
is a workaround for that, but it may not work in certain situations. Therefore,
if you encounter `NullPointerException` thrown from

```
at org.graalvm.truffle/com.oracle.truffle.polyglot.PolyglotContextImpl.getContext(PolyglotContextImpl.java:685)
```

simply ignore it. It will be handled within the debugger and should not affect
the rest of the environment.

# Debugging Enso and Java Code at Once

Enso libraries are written in a mixture of Enso code and Java libraries.
Debugging both sides (the Java as well as Enso code) is possible with a decent
IDE.

Get [NetBeans](http://netbeans.apache.org) version 13 or newer or
[VS Code with Apache Language Server extension](https://cwiki.apache.org/confluence/display/NETBEANS/Apache+NetBeans+Extension+for+Visual+Studio+Code)
and _start listening on port 5005_ with _Debug/Attach Debugger_ or by specifying
following debug configuration in VSCode:

```json
{
"name": "Listen to 5005",
"type": "java+",
"request": "attach",
"listen": "true",
"hostName": "localhost",
"port": "5005"
}
```

Then it is just about executing following Sbt command which builds CLI version
of the engine, launches it in debug mode and passes all other arguments to the
started process:

```bash
sbt:enso> runEngineDistribution --debug --run ./test/Tests/src/Data/Numbers_Spec.enso
```

Alternatively you can pass in special JVM arguments when launching the
`bin/enso` launcher:

```bash
enso$ JAVA_OPTS=-agentlib:jdwp=transport=dt_socket,server=n,address=5005 ./built-distribution/enso-engine-*/enso-*/bin/enso --run ./test/Tests/src/Data/Numbers_Spec.enso
```

As soon as the debuggee connects and the Enso language starts - choose the
_Toggle Pause in GraalVM Script_ button in the toolbar:

![NetBeans Debugger](https://user-images.githubusercontent.com/26887752/209614191-b0513635-819b-4c64-a6f9-9823b90a1513.png)

and your execution shall stop on the next `.enso` line of code. This mode allows
to debug both - the Enso code as well as Java code. The stack traces shows a
mixture of Java and Enso stack frames by default. Right-clicking on the thread
allows one to switch to plain Java view (with a way more stack frames) and back.
Analyzing low level details as well as Enso developer point of view shall be
simple with such tool.
This folder contains all documentation pertaining to the debugging facilities
used by Enso, broken up as follows:

- [**The Enso Debugger Protocol:**](./protocol.md) The protocol for the REPL
JaroslavTulach marked this conversation as resolved.
Show resolved Hide resolved
Debugger.
- [**Chrome devtools debugger:**](./chrome-devtools.md) A guide how to debug
Enso code using Chrome devtools.
- [**Debugging Enso and Java code at once:**](./mixed-debugging.md) A
step-by-step guide how to debug both Enso and Java code in a single debugger.
- [**Debugging Engine (Runtime) only Java code:**](./runtime-debugging.md) A
guide how to debug the internal Engine Java code.
41 changes: 41 additions & 0 deletions docs/debugger/chrome-devtools.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Chrome Developer Tools Debugger

As a well written citizen of the [GraalVM](http://graalvm.org) project the Enso
language can be used with existing tools available for the overall platform. One
of them is
[Chrome Debugger](https://www.graalvm.org/22.1/tools/chrome-debugger/) and Enso
language is fully integrated with it. Launch the `bin/enso` executable with
additional `--inspect` option and debug your Enso programs in _Chrome Developer
Tools_.

```bash
enso$ ./built-distribution/enso-engine-*/enso-*/bin/enso --inspect --run ./test/Tests/src/Data/Numbers_Spec.enso
Debugger listening on ws://127.0.0.1:9229/Wugyrg9
For help, see: https://www.graalvm.org/tools/chrome-debugger
E.g. in Chrome open: devtools://devtools/bundled/js_app.html?ws=127.0.0.1:9229/Wugyrg9
```

copy the printed URL into chrome browser and you should see:

![Chrome Debugger](https://user-images.githubusercontent.com/26887752/209614265-684f530e-cf7e-45d5-9450-7ea1e4f65986.png)

Step in, step over, set breakpoints, watch values of the variables as well as
evaluate arbitrary expressions in the console. Note that as of December 2022,
with GraalVM 22.3.0, there is a well-known
[bug in Truffle](https://github.com/oracle/graal/issues/5513) that causes
`NullPointerException` when a host object gets into the chrome inspector. There
is a workaround for that, but it may not work in certain situations. Therefore,
if you encounter `NullPointerException` thrown from

```
at org.graalvm.truffle/com.oracle.truffle.polyglot.PolyglotContextImpl.getContext(PolyglotContextImpl.java:685)
```

simply ignore it. It will be handled within the debugger and should not affect
the rest of the environment.

## Tips and tricks

- Use `env JAVA_OPTS=-Dpolyglot.inspect.Path=enso_debug` to set the chrome to
use a fixed URL. In this case the URL is
`devtools://devtools/bundled/js_app.html?ws=127.0.0.1:9229/enso_debug`
Comment on lines +39 to +41
Copy link
Member

Choose a reason for hiding this comment

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

Wow I did not know that, so cool!

48 changes: 48 additions & 0 deletions docs/debugger/mixed-debugging.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Debugging Enso and Java Code at Once

Enso libraries are written in a mixture of Enso code and Java libraries.
Debugging both sides (the Java as well as Enso code) is possible with a decent
IDE.

Get [NetBeans](http://netbeans.apache.org) version 13 or newer or
[VS Code with Apache Language Server extension](https://cwiki.apache.org/confluence/display/NETBEANS/Apache+NetBeans+Extension+for+Visual+Studio+Code)
and _start listening on port 5005_ with _Debug/Attach Debugger_ or by specifying
following debug configuration in VSCode:

```json
{
"name": "Listen to 5005",
"type": "java+",
"request": "attach",
"listen": "true",
"hostName": "localhost",
"port": "5005"
}
```

Then it is just about executing following Sbt command which builds CLI version
of the engine, launches it in debug mode and passes all other arguments to the
started process:

```bash
sbt:enso> runEngineDistribution --debug --run ./test/Tests/src/Data/Numbers_Spec.enso
```

Alternatively you can pass in special JVM arguments when launching the
`bin/enso` launcher:

```bash
enso$ JAVA_OPTS=-agentlib:jdwp=transport=dt_socket,server=n,address=5005 ./built-distribution/enso-engine-*/enso-*/bin/enso --run ./test/Tests/src/Data/Numbers_Spec.enso
```

As soon as the debuggee connects and the Enso language starts - choose the
_Toggle Pause in GraalVM Script_ button in the toolbar:

![NetBeans Debugger](https://user-images.githubusercontent.com/26887752/209614191-b0513635-819b-4c64-a6f9-9823b90a1513.png)

and your execution shall stop on the next `.enso` line of code. This mode allows
to debug both - the Enso code as well as Java code. The stack traces shows a
mixture of Java and Enso stack frames by default. Right-clicking on the thread
allows one to switch to plain Java view (with a way more stack frames) and back.
Analyzing low level details as well as Enso developer point of view shall be
simple with such tool.
Loading
Loading