Skip to content

Conversation

@jonpryor
Copy link
Contributor

tests/invocation-overhead partially bitrot since it was last
touched in 8602581: it insta-crashes:

% make run
mono64 --debug=casts test-overheads.exe
2021-02-11 17:33:49.479 mono64[90565:6542595] CheckForInstalledJavaRuntimes: Please visit http://www.java.com for information on installing java.
make: *** [run] Error 97

The primary "cause" is d1cce19: it was never a good idea to P/Invoke
into jvm.dll, as:

  • The name for jvm.dll differs between platforms! It's jvm
    some places, jre others, and jli in still others!
    If we want (eventual) .NET Framework/.NET Core support, this
    is a non-starter.

  • The actual on-disk path is also highly variable.

The solution to this conundrum was to update the java-interop
native library to have a new java_interop_jvm_load() export, and
use that to load the JVM. (Actual determination of which file
to load is left "elsewhere"; once the JVM to load is found, then
we can sanely P/Invoke into java_interop_jvm_load().)

This change never made it to tests/invocation-overhead.

Rework tests/invocation-overhead so that it's less "stand-alone":
it now uses JreRuntime from Java.Runtime.Environment.dll to
create an in-process JVM, using the $JI_JVM_PATH environment variable
to determine which JVM to load. (This is how tests/TestJVM works.)
This change requires "re-structuring" how certain types such as
JniObjectReference work, as it means we must now reference
Java.Interop.dll, which also defines JniObjectReference/etc.
Square this circle by moving various types into the appropriate
sub-namespaces, e.g. Java.Interop.SafeHandles has its own special
JniObjectReference declaration.

"While we're at it", what's .NET Core's JNI invocation performance
look like?

Update invocation-overhead to multitarget net472 and netcoreapp3.1.
Update src/java-interop so that the java-interop native library
can be built as a netcoreapp3.1 library. (This involves removing
all mention of Mono.)

Update Java.Runtime.Environment so that MonoRuntimeValueManager
disposes the GC Bridge, not JreRuntime. This avoids an
EntryPointNotFoundException, as the java-interop native lib
doesn't provide java_interop_gc_bridge_get_current().

Add a new msbuild /t:Run target which runs invocation-overhead
under both the desktop $(Runtime) & .NET Core

make prepare
make all

make -C tests/invocation-overhead run
# Runs tests under mono & .NET Core

.NET Core is faster than Mono for this particular benchmark:

  • SafeTiming timing:

    Mono:       9.3850449 sec
    .NET Core:  5.1734443 sec
    
  • XAIntPtrTiming timing:

    Mono:       4.4930288 sec
    .NET Core:  3.1048897 sec
    
  • JIIntPtrTiming timing:

    Mono:       4.5563368 sec
    .NET Core:  3.4353958 sec
    
  • JIPinvokeTiming timing:

    Mono:       3.4710383 sec
    .NET Core:  2.7470934 sec
    

@jonpryor jonpryor requested a review from jpobst February 12, 2021 01:54
@jonpryor jonpryor force-pushed the jonp-fix-invocation-overhead branch from 06f5435 to 34ba1da Compare February 12, 2021 02:59
`tests/invocation-overhead` partially bitrot since it was last
touched in 8602581: it insta-crashes:

	% make run
	mono64 --debug=casts test-overheads.exe
	2021-02-11 17:33:49.479 mono64[90565:6542595] CheckForInstalledJavaRuntimes: Please visit http://www.java.com for information on installing java.
	make: *** [run] Error 97

The primary "cause" is d1cce19: it was never a good idea to P/Invoke
into `jvm.dll`, as:

  * The name for `jvm.dll` differs between platforms!  It's `jvm`
    some places, `jre` others, and `jli` in still others!
    If we want (eventual) .NET Framework/.NET Core support, this
    is a non-starter.

  * The actual on-disk path is also highly variable.

The solution to this conundrum was to update the `java-interop`
native library to have a new `java_interop_jvm_load()` export, and
use *that* to load the JVM.  (Actual determination of which file
to load is left "elsewhere"; once the JVM to load is *found*, then
we can sanely P/Invoke into `java_interop_jvm_load()`.)

This change never made it to `tests/invocation-overhead`.

Rework `tests/invocation-overhead` so that it's *less* "stand-alone":
it now uses `JreRuntime` from `Java.Runtime.Environment.dll` to
create an in-process JVM, using the `$JI_JVM_PATH` environment variable
to determine *which* JVM to load.  (This is how `tests/TestJVM` works.)
This change requires "re-structuring" how certain types such as
`JniObjectReference` work, as it means we must now reference
`Java.Interop.dll`, which *also* defines `JniObjectReference`/etc.
Square this circle by moving various types into the appropriate
sub-namespaces, e.g. `Java.Interop.SafeHandles` has its own special
`JniObjectReference` declaration.

"While we're at it", what's .NET Core's JNI invocation performance
look like?

Update `invocation-overhead` to multitarget net472 and netcoreapp3.1.
Update `src/java-interop` so that the `java-interop` native library
can be built as a netcoreapp3.1 library.  (This involves removing
all mention of Mono.)

Update `Java.Runtime.Environment` so that `MonoRuntimeValueManager`
disposes the GC Bridge, not `JreRuntime`.  This avoids an
`EntryPointNotFoundException`, as the `java-interop` native lib
doesn't provide `java_interop_gc_bridge_get_current()`.

Add a new `msbuild /t:Run` target which runs `invocation-overhead`
under both the desktop `$(Runtime)` & .NET Core

	make prepare
	make all

	make -C tests/invocation-overhead run
	# Runs tests under mono & .NET Core

.NET Core is faster than Mono for this particular benchmark:

  * `SafeTiming` timing:

        Mono:       9.3850449 sec
        .NET Core:  5.1734443 sec

  * `XAIntPtrTiming` timing:

        Mono:       4.4930288 sec
        .NET Core:  3.1048897 sec

  * `JIIntPtrTiming` timing:

        Mono:       4.5563368 sec
        .NET Core:  3.4353958 sec

  * `JIPinvokeTiming` timing:

        Mono:       3.4710383 sec
        .NET Core:  2.7470934 sec
@jonpryor jonpryor force-pushed the jonp-fix-invocation-overhead branch from 34ba1da to 048158d Compare February 12, 2021 15:28
@jonpryor jonpryor merged commit 2a299eb into dotnet:main Feb 12, 2021
@jpobst jpobst added this to the 11.3 (16.10 / 8.10) milestone Mar 1, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Apr 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants