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

Feature: Runtime Internals #1034

Merged
merged 88 commits into from
Jun 18, 2024
Merged

Feature: Runtime Internals #1034

merged 88 commits into from
Jun 18, 2024

Conversation

sgammon
Copy link
Member

@sgammon sgammon commented Jun 18, 2024

Draft Powered by Pull Request Badge

Summary

Adds support for a concept of "internal" symbols, which are only exposed to internal sources (things within __runtime__/* and facade code). In general, fixes a bunch of other bugs, and adds smaller features on the way to 1.0.0-alpha10.

  • Add support for runtime internals (primordials object)
  • Add support for dropping internals before guest code execution
  • Eagerly evaluate built-in Node and Elide modules
  • Fix Truffle enterprise dependencies
  • Improvements to auximage

sgammon added 30 commits June 17, 2024 17:47
- chore: build js `facade.js` and `js.modules.tar.gz`
- chore: makefile cleanup/improvements
- chore: align and fixup cflags

Signed-off-by: Sam Gammon <sam@elide.ventures>
Signed-off-by: Sam Gammon <sam@elide.ventures>
Signed-off-by: Sam Gammon <sam@elide.ventures>
Signed-off-by: Sam Gammon <sam@elide.ventures>
Signed-off-by: Sam Gammon <sam@elide.ventures>
Signed-off-by: Sam Gammon <sam@elide.ventures>
- feat(graalvm): ability to mark symbols as internal or public
- feat(graalvm): mangle internal names consistently
- feat(graalvm): ability to filter internal/public symbols on resolve
- chore: updates to `runtime` to defer intrinsic access
- chore: mark common allowlisted public symbols
- chore: cleanup/rewrite all internal symbols not to carry prefix

Signed-off-by: Sam Gammon <sam@elide.ventures>
Signed-off-by: Sam Gammon <sam@elide.ventures>
Signed-off-by: Sam Gammon <sam@elide.ventures>
Signed-off-by: Sam Gammon <sam@elide.ventures>
- feat(graalvm): parse and load built-in modules at ctx finalization
- fix(graalvm): protect module patches from race condition
- fix(runtime): apply change for vfs listener dispatch
- chore: missing kotlin function proxy entry

Signed-off-by: Sam Gammon <sam@elide.ventures>
Signed-off-by: Sam Gammon <sam@elide.ventures>
Signed-off-by: Sam Gammon <sam@elide.ventures>
Signed-off-by: Sam Gammon <sam@elide.ventures>
Signed-off-by: Sam Gammon <sam@elide.ventures>
Signed-off-by: Sam Gammon <sam@elide.ventures>
Signed-off-by: Sam Gammon <sam@elide.ventures>
Signed-off-by: Sam Gammon <sam@elide.ventures>
Signed-off-by: Sam Gammon <sam@elide.ventures>
Signed-off-by: Sam Gammon <sam@elide.ventures>
Signed-off-by: Sam Gammon <sam@elide.ventures>
Signed-off-by: Sam Gammon <sam@elide.ventures>
Signed-off-by: Sam Gammon <sam@elide.ventures>
Signed-off-by: Sam Gammon <sam@elide.ventures>
Signed-off-by: Sam Gammon <sam@elide.ventures>
Signed-off-by: Sam Gammon <sam@elide.ventures>
Signed-off-by: Sam Gammon <sam@elide.ventures>
Signed-off-by: Sam Gammon <sam@elide.ventures>
- feat: ability to withdraw access to runtime internals
- feat: rewrite runtime internals to `primordials`
- test: amend bindings to support runtime internals

Signed-off-by: Sam Gammon <sam@elide.ventures>
Signed-off-by: Sam Gammon <sam@elide.ventures>
Signed-off-by: Sam Gammon <sam@elide.ventures>
@sgammon sgammon force-pushed the feat/runtime-internals branch from 7b4d900 to a456c63 Compare June 18, 2024 07:36
sgammon added 2 commits June 18, 2024 00:36
Signed-off-by: Sam Gammon <sam@elide.ventures>
Signed-off-by: Sam Gammon <sam@elide.ventures>
@sgammon sgammon marked this pull request as ready for review June 18, 2024 18:38
@sgammon sgammon requested a review from a team June 18, 2024 18:39
.gitmodules Show resolved Hide resolved
@@ -159,7 +159,7 @@ java {
dependencies {
// Kover: Coverage Reporting
kover(projects.packages.base)
kover(projects.packages.cli)
// kover(projects.packages.cli)
Copy link
Member Author

Choose a reason for hiding this comment

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

i am dropping this project until runtime replaces it

Comment on lines +65 to +76
val internals = HashMap<String, Any>()

intrinsicBindings.forEach { entry ->
// @TODO: don't unconditionally mount all members
val isInternal = entry.key.startsWith("__Elide")
if (!EXPERIMENTAL_SECURE_INTERNALS || !isInternal) {
putMember(entry.key, entry.value)
}
if (isInternal) {
internals[entry.key.removePrefix("__Elide_").removeSuffix("__")] = entry.value
}
}
Copy link
Member Author

Choose a reason for hiding this comment

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

hacky rn i know

Copy link
Member

Choose a reason for hiding this comment

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

this is fine for now, support for this will be clean in v5, already implemented and tested

Comment on lines +277 to +280
option(
"engine.CompilerThreads",
min(max(Runtime.getRuntime().availableProcessors() / 4, 8), 2).toString(),
)
Copy link
Member Author

Choose a reason for hiding this comment

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

maxes at 8, mins at 2, 12 produces 3, 16 produces 4

Copy link
Member

Choose a reason for hiding this comment

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

could be written as (Runtime.getRuntime().availableProcessors() / 4).coerceIn(2, 8).toString() for readability

Comment on lines +849 to +850
"java.util.concurrent.ForkJoinPool.common.parallelism" to "4",
"java.util.concurrent.ForkJoinPool.common.maximumSpares" to "128",
Copy link
Member Author

Choose a reason for hiding this comment

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

fixes the default ForkJoinPool settings for concurrency

Comment on lines +905 to +910
"elide.tool.engine.JsEngineTest",
"elide.tool.engine.JsEngineTest${'$'}Definition",
"elide.tool.engine.PythonEngineTest",
"elide.tool.engine.PythonEngineTest${'$'}Definition",
"elide.tool.engine.RubyEngineTest",
"elide.tool.engine.RubyEngineTest${'$'}Definition",
Copy link
Member Author

Choose a reason for hiding this comment

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

was causing language init even for langs that were not requested at cli

Comment on lines +1262 to +1266
classpath = files(
tasks.optimizedNativeJar,
configurations.nativeImageClasspath,
configurations.runtimeClasspath,
)
Copy link
Member Author

Choose a reason for hiding this comment

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

fixes missing dependencies at native image compile time

Comment on lines +571 to +572
use {
enter()
Copy link
Member Author

Choose a reason for hiding this comment

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

subtle: use { here will close the engine after all use. we need this for features like PGO and engine caching, which need to write at the end of the VM's lifecycle, and so demand that the VM is closed cleanly.

Comment on lines +322 to +326
if (ENABLE_TYPESCRIPT && (typescript || (alias != null && tsAliases.contains(alias)))) add(TYPESCRIPT)
if (ENABLE_PYTHON && (python || (alias != null && pyAliases.contains(alias)))) add(PYTHON)
if (ENABLE_RUBY && (ruby || (alias != null && rbAliases.contains(alias)))) add(RUBY)
if (ENABLE_JVM && (jvm || kotlin || (alias != null && jvmAliases.contains(alias)))) add(JVM)
if (ENABLE_JVM && (kotlin || (alias != null && ktAliases.contains(alias)))) add(KOTLIN)
Copy link
Member Author

Choose a reason for hiding this comment

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

Languages are now "activated" (and then initialized) iff:

(1) The language is supported
(2) The language is active by default (JS, WASM), or is requested by the user (all others)

sgammon added 4 commits June 18, 2024 12:05
Signed-off-by: Sam Gammon <sam@elide.ventures>
Signed-off-by: Sam Gammon <sam@elide.ventures>
Signed-off-by: Sam Gammon <sam@elide.ventures>
Copy link

codecov bot commented Jun 18, 2024

Codecov Report

Attention: Patch coverage is 54.02299% with 200 lines in your changes missing coverage. Please review.

Project coverage is 54.39%. Comparing base (820e910) to head (71d0e8e).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1034      +/-   ##
==========================================
- Coverage   55.10%   54.39%   -0.71%     
==========================================
  Files         323      322       -1     
  Lines       10263    10263              
  Branches     1801     1689     -112     
==========================================
- Hits         5655     5583      -72     
- Misses       4042     4111      +69     
- Partials      566      569       +3     
Flag Coverage Δ
gradle 54.39% <54.02%> (-0.71%) ⬇️
jvm 54.39% <54.02%> (-0.71%) ⬇️
lib 54.39% <54.02%> (-0.71%) ⬇️
plugin 54.39% <54.02%> (-0.71%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
...c/main/kotlin/elide/runtime/core/PolyglotEngine.kt 0.00% <ø> (ø)
...de/runtime/lang/typescript/TypeScriptLanguage.java 90.90% <100.00%> (ø)
...e/runtime/core/internals/graalvm/GraalVMRuntime.kt 68.57% <100.00%> (-1.13%) ⬇️
.../internals/intrinsics/BuiltinIntrinsicsResolver.kt 100.00% <100.00%> (ø)
...internals/intrinsics/CompoundIntrinsicsResolver.kt 100.00% <100.00%> (ø)
.../internals/intrinsics/ServiceIntrinsicsResolver.kt 80.00% <100.00%> (-3.34%) ⬇️
.../internals/intrinsics/js/base64/Base64Intrinsic.kt 62.50% <100.00%> (-1.50%) ⬇️
...nternals/intrinsics/js/console/ConsoleIntrinsic.kt 48.27% <100.00%> (+0.90%) ⬆️
...ternals/intrinsics/js/crypto/WebCryptoIntrinsic.kt 78.57% <100.00%> (ø)
...me/gvm/internals/intrinsics/js/url/URLIntrinsic.kt 90.83% <100.00%> (ø)
... and 64 more

... and 24 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 820e910...71d0e8e. Read the comment docs.

sgammon added 2 commits June 18, 2024 14:01
Signed-off-by: Sam Gammon <sam@elide.ventures>
Signed-off-by: Sam Gammon <sam@elide.ventures>
Comment on lines +64 to +73
private val filesystem: AtomicReference<GuestVFS> = AtomicReference()

private val executor: ExecutorService by lazy {
MoreExecutors.newDirectExecutorService()
override fun onVfsCreated(fileSystem: GuestVFS) {
filesystem.set(fileSystem)
}

private val std: FilesystemAPI by lazy {
NodeFilesystem.createStd(executor, filesystem)
override fun get(): GuestVFS {
return filesystem.get() ?: error("VFS not yet initialized")
}
}
Copy link
Member

Choose a reason for hiding this comment

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

I like this a lot, good call

Copy link
Member Author

Choose a reason for hiding this comment

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

🙇

@@ -107,7 +107,23 @@ import elide.testing.annotations.TestCase
"""
}

@Test fun `isUtf8() compliance`() = conforms {
@Ignore @Test fun `isAscii() compliance (invalid)`() = conforms {
Copy link
Member

Choose a reason for hiding this comment

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

If this was broken, it was probably related to the missing Buffer symbol

Copy link
Member Author

Choose a reason for hiding this comment

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

i thought so too, but alas, it's still broken for some reason

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 one did fix, so did valid (for isAscii)

sgammon added 6 commits June 18, 2024 14:18
Signed-off-by: Sam Gammon <sam@elide.ventures>
Signed-off-by: Sam Gammon <sam@elide.ventures>
Signed-off-by: Sam Gammon <sam@elide.ventures>
Signed-off-by: Sam Gammon <sam@elide.ventures>
Signed-off-by: Sam Gammon <sam@elide.ventures>
Signed-off-by: Sam Gammon <sam@elide.ventures>
@sgammon sgammon mentioned this pull request Jun 18, 2024
@@ -1,3 +1,3 @@
(function(){var u=this||self,a=globalThis;function i(o,r){var e=o.split("."),t=u;e[0]in t||typeof t.b=="undefined"||t.b("var "+e[0]);for(var n;e.length&&(n=e.shift());)e.length||r===void 0?t[n]&&t[n]!==Object.prototype[n]?t=t[n]:t=t[n]={}:t[n]=r;a[o]=r}var h=class extends Error{constructor(o){super(o);this.a=!0,this.message=o||"`ValueError` was thrown"}static[Symbol.hasInstance](o){return o&&o.a===!0||!1}};i("ValueError",h);class g{typeError(r,e){{var t=TypeError;let n;if(typeof r=="string"?n=r:n=r.message,r=new t(n),e?.c==0)e=r;else throw r}return e}valueError(r,e){let t;if(typeof r=="string"?t=r:t=r.message,r=new h(t),e?.c===!1)return r;throw r}}i("__errBridge",new g),i("btoa",function(o){return a.Base64.encode(o)}),i("atob",function(o){return a.Base64.decode(o)});function s(){return Error("Method not supported")}class b{trace(...r){l("debug",r)}log(...r){l("debug",r)}debug(...r){l("debug",r)}info(...r){l("info",r)}warn(...r){l("warn",r)}error(...r){l("error",r)}assert(){throw Error("Method not implemented.")}clear(){}count(){throw s()}countReset(){throw s()}dir(){throw s()}dirxml(){throw s()}group(){throw s()}groupCollapsed(){throw s()}groupEnd(){throw s()}table(){throw s()}time(){throw s()}timeEnd(){throw s()}timeLog(){throw s()}}function l(o,r){let e=a.Console;switch(o){case"trace":e.log(r);break;case"debug":e.log(r);break;case"info":e.info(r);break;case"warn":e.warn(r);break;case"error":e.error(r)}}i("console",new class extends b{});let w=globalThis.__Elide_version__,p=globalThis.__Elide_node_process__;globalThis.window=void 0,globalThis.gc=null;let c={};globalThis.global=c,globalThis.self=c;let d={process:p,version:w,context:{build:!1,runtime:!0}};globalThis.Elide=d,globalThis.process=d.d}).call({});
(function(){var b=this||self;function t(l,r){l=l.split(".");var s=b;l[0]in s||typeof s.b=="undefined"||s.b("var "+l[0]);for(var o;l.length&&(o=l.shift());)l.length||r===void 0?s[o]&&s[o]!==Object.prototype[o]?s=s[o]:s=s[o]={}:s[o]=r}var i=globalThis;let c=primordials.c,u=primordials.d;class d extends u{constructor(r){super(r||"`ValueError` was thrown");this.a=!0}static[Symbol.hasInstance](r){return r&&r.a===!0||!1}}class g extends c{constructor(r){super(r||"`ValueError` was thrown");this.a=!0}static[Symbol.hasInstance](r){return r&&r.a===!0||!1}}var a=d;t("ValueError",a),i.ValueError=a;var e=g;t("TypeError",e),i.TypeError=e;let p=globalThis[primordials.f],T=globalThis[primordials.e];globalThis.window=void 0,globalThis.gc=null;let n={};globalThis.global=n,globalThis.self=n;let h=globalThis.Elide||{};Object.assign(h,{process:T,version:p,context:{build:!1,runtime:!0}}),globalThis.Elide=h}).call({});

Check notice

Code scanning / CodeQL

Semicolon insertion Note

Avoid automated semicolon insertion (92% of all statements in
the enclosing function
have an explicit semicolon).
@sgammon sgammon removed ✋ embargoed PRs and issues that can't proceed because of some non-code condition 🚧 WIP Works-in-progress. Blocks merge labels Jun 18, 2024
@sgammon sgammon merged commit 765e35f into main Jun 18, 2024
21 checks passed
@sgammon sgammon deleted the feat/runtime-internals branch June 18, 2024 22:05
@sgammon sgammon mentioned this pull request Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🧪 labs Experimental work module:graalvm Modules, changes, and issues relating to GraalVM
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants