platform/upstream/dotnet/runtime.git
4 years ago[runtime] Implement support for SuppressGCTransitionAttribute. (mono/mono#17534)
Zoltan Varga [Mon, 28 Oct 2019 14:59:53 +0000 (10:59 -0400)]
[runtime] Implement support for SuppressGCTransitionAttribute. (mono/mono#17534)

Fixes https://github.com/mono/mono/issues/17367.

Commit migrated from https://github.com/mono/mono/commit/e4cc70f4b5038ec5d6500ba988d0bb67143658bc

4 years agoAdditional and adjusted logging for parallel minor GC. (mono/mono#17522)
Johan Lorensson [Mon, 28 Oct 2019 14:34:42 +0000 (15:34 +0100)]
Additional and adjusted logging for parallel minor GC. (mono/mono#17522)

* Additional and adjusted logging for parallel minor GC.

When running parallel minor GC we currently get incorrect timing
on several loggings and counters due to work being put on thread pool
and accumulated. This commit fix so that the logging is accurate
when running with and without parallelization. In parallel mode a new
logging is also added to show the accumulated split between major and los
remset scan jobs.

The counters time_minor_scan_remsets and time_minor_scan_roots are only
updated when not running parallel GC since they are not correct when
running parallel GC.

* Fix WASM build error.

Commit migrated from https://github.com/mono/mono/commit/c5edcd1ed443ae5b960d8f8972b0850b7999e44a

4 years ago[netcore] Fix offsets generation when cross compiling
Alexander Köplinger [Fri, 25 Oct 2019 18:32:03 +0000 (20:32 +0200)]
[netcore] Fix offsets generation when cross compiling

The offsets-tool.py uses some magic to map `typename` to `<underscore>typename` for looking up runtime types.
This caused issues on netcore because we aliased it to a different name.

To fix this let's keep the `_MonoInternalThread` name instead and just fix the one location where `_MonoThread` is used.

Commit migrated from https://github.com/mono/mono/commit/450d4746849d228c85748d9ab4ef68f90ac0c7f2

4 years ago[netcore] Don't load types in aot-compiler.c that don't exist in corefx
Alexander Köplinger [Fri, 25 Oct 2019 18:27:34 +0000 (20:27 +0200)]
[netcore] Don't load types in aot-compiler.c that don't exist in corefx

Fixes https://github.com/mono/mono/issues/16026

Commit migrated from https://github.com/mono/mono/commit/fb7b075e4930751421a5feb0b9ac095d832df228

4 years ago[merp] Introduce a new 'dump mode' that allows different signal behavior when dumping...
Alexis Christoforides [Sat, 26 Oct 2019 22:48:40 +0000 (18:48 -0400)]
[merp] Introduce a new 'dump mode' that allows different signal behavior when dumping (mono/mono#17537)

* dump_native_stacktrace should always register the sigterm handler.

Cherry picked from the https://github.com/mono/mono/pull/17310

* [merp] Introduce a new 'dump mode' that allows different signal behavior when dumping

The primary reason for this is gaining the ability to interpret SIGTERM properly as a crashing signal when outside of 'dump mode', and as a utility signal during the 'thread summarizer' dumping process.

Commit migrated from https://github.com/mono/mono/commit/db568c6fe0cb5eab71ed729ec5b412365eacf280

4 years ago[runtime] Unbalanced GC Unsafe transitions before shutdown (mono/mono#17566)
Aleksey Kliger (λgeek) [Sat, 26 Oct 2019 22:45:35 +0000 (18:45 -0400)]
[runtime] Unbalanced GC Unsafe transitions before shutdown (mono/mono#17566)

When embedders call mono_runtime_quit or mono_jit_cleanup, we need to do unbalanced transitions to GC Unsafe, because after mini_cleanup runs we don't have GC thread states anymore and MONO_EXIT_GC_UNSAFE will assert.

* [runtime] Do an unbalanced GC Unsafe transition in mono_jit_cleanup

After mini_cleanup, we don't have GC thread states anymore because all that
stuff was cleaned up, so MONO_EXIT_GC_UNSAFE would assert

* [runtime] Mark mono_runtime_quit external only.

Runtime should use mono_runtime_quit_internal.

After we call the quit_function (aka mini_cleanup) we don't have any GC thread
states anymore because all that stuff got cleaned up.  So MONO_EXIT_GC_UNSAFE
can't work.

Commit migrated from https://github.com/mono/mono/commit/0e3caf00df54199be88cfcb53ed847226defebb4

4 years ago[cxx][x86] int/ptr casts (mono/mono#17570)
Jay Krell [Sat, 26 Oct 2019 16:26:15 +0000 (09:26 -0700)]
[cxx][x86] int/ptr casts (mono/mono#17570)

[cxx][x86] int/ptr casts

Commit migrated from https://github.com/mono/mono/commit/5f3446bd12c32727b926eb0d39769af96a6a389c

4 years ago[cxx] Compile mini-llvm.c as C++ if configure -enable-cxx. (mono/mono#17558)
Jay Krell [Fri, 25 Oct 2019 15:46:01 +0000 (08:46 -0700)]
[cxx] Compile mini-llvm.c as C++ if configure -enable-cxx. (mono/mono#17558)

[cxx] Compile mini-llvm.c as C++ if configure -enable-cxx.

This is presently catastrophic, because of `MonoJitICallId` varying between C and C++, and therefore the layout of `MonoCallInst`.

Related to:
https://github.com/mono/mono/pull/17557

https://github.com/mono/mono/pull/17445#issuecomment-546175352

Commit migrated from https://github.com/mono/mono/commit/893486638cae8efc46323d6c2209fc99febcd05d

4 years ago[jit][x86][cxx] int/ptr casts (mono/mono#17382)
Jay Krell [Fri, 25 Oct 2019 15:34:50 +0000 (08:34 -0700)]
[jit][x86][cxx] int/ptr casts (mono/mono#17382)

Commit migrated from https://github.com/mono/mono/commit/84d64d314bdbbd8cee07bbcb9ec8d030abe0156d

4 years ago[runtime] Make mono_thread_manage external only (mono/mono#17554)
Aleksey Kliger (λgeek) [Fri, 25 Oct 2019 15:28:18 +0000 (11:28 -0400)]
[runtime] Make mono_thread_manage external only (mono/mono#17554)

* [runtime] Make mono_thread_manage external only

runtime should use mono_thread_manage_internal

Commit migrated from https://github.com/mono/mono/commit/d6ee245c94a8365c1d418ea82f9b83ce11cc53a3

4 years ago[interp] Optimize stelem (mono/mono#17519)
Vlad Brezae [Fri, 25 Oct 2019 14:25:08 +0000 (17:25 +0300)]
[interp] Optimize stelem (mono/mono#17519)

* [interp] Optimize stelem instructions

* [intepr] Optimize stelem_ref and slowpath casts

mono_object_isinst_checked uses coop handles and is very slow. Attempt to use the straightforward mono_class_is_assignable_from_checked.

Makes stelem_ref 5x faster.

Commit migrated from https://github.com/mono/mono/commit/768fefbad1e3835c3be09828c9c43f2964079f65

4 years ago[llvm] Use -place-safepoints in JIT mode too (mono/mono#17116)
Egor Bogatov [Fri, 25 Oct 2019 14:10:57 +0000 (17:10 +0300)]
[llvm] Use -place-safepoints in JIT mode too (mono/mono#17116)

* always use -place-safepoints pass in JIT mode

* ignore loaded llvm

* remove gc.safepoint_poll after optimizations

* fix typo

* cleanup

* cleanup

* cleanup

* cleanup

* Do not emit safepoints on entry thus simple functions (without calls and loops) won't have them at all

* Undo  -spp-no-entry=true

* fix failing tests

* do not emit sp in Allocators

Commit migrated from https://github.com/mono/mono/commit/dc4a7f5ed7094a586cee28c4f9987c40b4f2cea5

4 years ago[cxx] externC for some icalls, for wasm and ios. (mono/mono#17444)
Jay Krell [Thu, 24 Oct 2019 21:59:11 +0000 (14:59 -0700)]
[cxx] externC for some icalls, for wasm and ios. (mono/mono#17444)

Maybe all JIT icalls?

Commit migrated from https://github.com/mono/mono/commit/4ef7c566af91722821031f11d704cae2061937e3

4 years agoInclude signal.h unconditionally. (mono/mono#17430)
Jay Krell [Thu, 24 Oct 2019 21:44:57 +0000 (14:44 -0700)]
Include signal.h unconditionally. (mono/mono#17430)

Some of the includes already were unconditional, including both on Win32 and Unix.
It is part of ANSI C 89, albeit in a reduced form compared to typical Unix (no sigaction).

Remove configuration of MSG_NOSIGNAL which has no other uses.

Preserve configuration of signal.h temporarily due to other uses of ifdef HAVE_SIGNAL_H.
 i.e. LLVM?

Commit migrated from https://github.com/mono/mono/commit/fc390a5f2493ae908ccf2696c4ca675d82104db6

4 years ago[cxx][x86] int/ptr casts. (mono/mono#17441)
Jay Krell [Thu, 24 Oct 2019 21:37:12 +0000 (14:37 -0700)]
[cxx][x86] int/ptr casts. (mono/mono#17441)

* [cxx][x86] Another int/ptr cast.

* More casts. Notice these are under
`#if defined (MONO_ARCH_USE_SIGACTION) && !defined (MONO_CROSS_COMPILE)`
which would explain them not showing up.

Commit migrated from https://github.com/mono/mono/commit/ec81a868a104ca0c465023ff5d9f90c0f131f725

4 years ago[master] Update dependencies from dotnet/arcade dotnet/core-setup dotnet/corefx ...
dotnet-maestro[bot] [Thu, 24 Oct 2019 19:06:46 +0000 (21:06 +0200)]
[master] Update dependencies from dotnet/arcade dotnet/core-setup dotnet/corefx (mono/mono#17458)

* Update dependencies from https://github.com/dotnet/arcade build 20191018.2

- Microsoft.DotNet.Arcade.Sdk - 5.0.0-beta.19518.2
- Microsoft.DotNet.Helix.Sdk - 5.0.0-beta.19518.2

* Update dependencies from https://github.com/dotnet/core-setup build 20191021.2

- Microsoft.NETCore.App - 5.0.0-alpha1.19521.2

* Update dependencies from https://github.com/dotnet/corefx build 20191020.7

- Microsoft.Private.CoreFx.NETCoreApp - 5.0.0-alpha1.19520.7

* Update dependencies from https://github.com/dotnet/arcade build 20191023.3

- Microsoft.DotNet.Arcade.Sdk - 5.0.0-beta.19523.3
- Microsoft.DotNet.Helix.Sdk - 5.0.0-beta.19523.3

* Update dependencies from https://github.com/dotnet/core-setup build 20191023.10

- Microsoft.NETCore.App - 5.0.0-alpha1.19523.10

* Update dependencies from https://github.com/dotnet/corefx build 20191023.8

- Microsoft.Private.CoreFx.NETCoreApp - 5.0.0-alpha1.19523.8

* Disable a file system watcher test on mac

See https://github.com/mono/mono/issues/17547

* Reenable tests that were fixed

Commit migrated from https://github.com/mono/mono/commit/a7287bdae54c0539a74fdbe87eb73ba268a95ed6

4 years ago[interp] fix code length for JitInfo (mono/mono#17538)
Bernhard Urban-Forster [Thu, 24 Oct 2019 18:13:27 +0000 (20:13 +0200)]
[interp] fix code length for JitInfo (mono/mono#17538)

* [interp] fix code length for JitInfo

* fix c++ build

Commit migrated from https://github.com/mono/mono/commit/25b53a642b4756332e5cdb932ed09521da3418df

4 years ago[netcore] Fix corerun build deps
Marek Safar [Thu, 24 Oct 2019 14:58:20 +0000 (10:58 -0400)]
[netcore] Fix corerun build deps

Commit migrated from https://github.com/mono/mono/commit/81a4a19f0a3282866cb6459da5f56ff67f26b940

4 years agoFix eglib on AIX/PASE (mono/mono#17476)
Calvin Buckley [Thu, 24 Oct 2019 16:04:20 +0000 (13:04 -0300)]
Fix eglib on AIX/PASE (mono/mono#17476)

* fix eglib on AIX/PASE

* Work around access(2) syscall bug on PASE
  On PASE, X_OK will always returns true. This is contrary to
  how AIX behaves (though corresponds to documentation!). This
  is probably because it's an upcall to the ILE version of
  access, and that seemingly always returns true.

* Always export the dummy function in the test suite
  The AIX linker didn't export this properly, without using the
  giant sledgehammer of -bexpall. Write an export file and use
  it. This required some build system changes to expose an
  AIX-only automake conditional.

* Use a file that exists on PASE for tests
  PASE doesn't use Unix-style DNS resolution, so /etc/hosts is
  missing. Use /etc/magic, since that seems to be present.

* Don't use /bin on AIX/PASE for tests
  This is a symlink to /usr/bin, and it seems chdir/getcwd
  follows links. Use /usr instead, that is unlikely to be a
  symlink.

* Make a note what directory we're in if we fail test_cwd

* Change manual executable access check change per Jay

* Change test on POSIXy platforms to always use root directory

Commit migrated from https://github.com/mono/mono/commit/638e2c6a8614d25aad591112d3414e28641b97e0

4 years ago[interp] Add super instructions for field storing (mono/mono#17525)
Vlad Brezae [Thu, 24 Oct 2019 15:05:04 +0000 (18:05 +0300)]
[interp] Add super instructions for field storing (mono/mono#17525)

* [interp] Add also floating versions for stloc.np

* [interp] Add super instructions for stfld

When storing into a field of a local or an argument (ldloc/ldarg -> random instructions that end up pushing one value -> stfld). We add this instruction to the cprop pass because the instructions that are optimized together are not consecutive and we need the stack information to be able to access the instruction that loaded the argument / local and to make sure that the local wasn't dirtied. Alternatively we could make the super instruction pass stack aware, which we should probably do if more super instruction candidates turn out to require stack state information.

* [interp] Enable cprop for methods without locals

We do some optimizations here that don't apply to locals.

* [interp] Fix result stack type of CEE_CONV_OVF_I_UN

Commit migrated from https://github.com/mono/mono/commit/b7ef7363382757c2951a7a84026d5a1baa7f0130

4 years ago[netcore] Add a few more missing SSE intrinsics. (mono/mono#17511)
Zoltan Varga [Thu, 24 Oct 2019 10:57:13 +0000 (06:57 -0400)]
[netcore] Add a few more missing SSE intrinsics. (mono/mono#17511)

* [netcore] Add a few more missing SSE intrinsics.

* Disable some intrinsics for non-llvm.

Commit migrated from https://github.com/mono/mono/commit/951769b2795df22904079d79d8d97d35c44466ba

4 years agoAdjust restart world logging level to match start major/nursery logging. (mono/mono...
Johan Lorensson [Thu, 24 Oct 2019 08:57:56 +0000 (10:57 +0200)]
Adjust restart world logging level to match start major/nursery logging. (mono/mono#17520)

With this change we will get the following logging on level 1:

2019-10-22 15:46:59 Start nursery collection 38898 00000205A0000000-00000205A1000000, size: 16777216
2019-10-22 15:46:59 restarted (pause time: 2728 usec, max: 689233 usec)

showing the pause time and when runtime was restared, before this fix
we will only see the start log message on level 1.

Commit migrated from https://github.com/mono/mono/commit/fe7654f745c9b8ba030c9c4c1671904c6d9bda53

4 years ago[netcore] Managed ThreadPool implementation (mono/mono#17387)
Filip Navara [Thu, 24 Oct 2019 08:56:25 +0000 (10:56 +0200)]
[netcore] Managed ThreadPool implementation (mono/mono#17387)

* Wire up the managed side of the portable thread pool

* Remove old native thread pool code

* Fix non-netcore build

* Fix Thread.IsThreadPoolThread

* Fix MSVC builds

* Code style fix

* Make the locking primitives uninterruptible

* Revert icall changes for non-netcore

* Implement Thread.ResetThreadPoolThread

* Compile out more thread pool code for netcore

* Remove ThreadPoolBoundHandle, it is shared now

* Address PR feedback on code style

Commit migrated from https://github.com/mono/mono/commit/7a15b718735eccfac6ecd7467a09279d2f23e16e

4 years ago[debugger] Changing how debugger handles exception when hybrid suspend is enabled...
Thays Grazia [Wed, 23 Oct 2019 20:56:58 +0000 (17:56 -0300)]
[debugger] Changing how debugger handles exception when hybrid suspend is enabled (mono/mono#17478)

* Removing all fixes to fix mono/mono#15203 and mono/mono#17083, and trying a new approach to fix this mono/mono#17084, together.

The thing is when we are executing on hybrid suspend the caller is executed inside try catch in the runtime_invoke_ method that is generated. And this try catch should be ignored for the debugger exception, otherwise it's the last try catch in main thread, but should always be considered to generate the stack trace.

Fixes mono/mono#17084

* This test check the case that we were missing. On preemptive this test always runs perfectly, on Hybrid, never run well until this PR.

* Changing how call unit test.
Changing variable name.

Commit migrated from https://github.com/mono/mono/commit/8fda1738f728dec900e7a53b78fefdbbbc9e0924

4 years ago[cxx] Put extern "C" in MONO_LLVM_INTERNAL. (mono/mono#17443)
Jay Krell [Wed, 23 Oct 2019 19:36:35 +0000 (12:36 -0700)]
[cxx] Put extern "C" in MONO_LLVM_INTERNAL. (mono/mono#17443)

Commit migrated from https://github.com/mono/mono/commit/4d7adf4d2a0c7c31d8081a4c01d2bb16b4029ea7

4 years agoOptimize LOS for better parallelization. (mono/mono#17173)
Johan Lorensson [Wed, 23 Oct 2019 18:58:04 +0000 (20:58 +0200)]
Optimize LOS for better parallelization. (mono/mono#17173)

Scanning LOS list as part of minor GC didn't parallelize well since
all scan jobs needed to walk the complete LOS list. This led to touching
a lot of memory walking the list, increasing minor GC pause times
when the number of items in the LOS list increased. As an example,
stressing LOS data structure using ~600 MB's of random sized byte arrays
caused minor GC pause times between ~20ms without parallelization and ~19ms
with parallelization. NOTE, the more work each job gets (more memory to scan)
we will get a better parallelization, but still a lot of room for improvement.

Changing from a normal linked list to a SgenArrayList makes it more effective
to parallelize the scan jobs and since the list is using sequential
memory, this will also reduce cache misses for each thread iterating LOS
objects. Tagging objects in SgenArrayList with reference information reduce
cache misses dramatically in cases where objects not including references
exists on the list, since scanning jobs can skip these items without any
need to touch object memory causing cache misses.

Same scenario running with fix gives us minor GC pause times, without
parallelization in ~7ms (down from 20~ms) and with parallelization,
< 5ms (down from 19ms). NOTE, the more work each job gets (more memory to scan)
we will get a better result using parallelization, so the delta will increase
between using and not using parallelization, this scenario primarily stress
the extreme case where most LOS objects doesn't have references.

In total, this optimization reduce minor GC pause time 4x, from ~19ms when
using parallelization down to < 5ms.

Commit migrated from https://github.com/mono/mono/commit/df30c7228c4061573601ea9a71772cc6f00e4b85

4 years ago[wasm] Avoid adding an extra arg to native-to-managed wrappers. (mono/mono#17508)
Zoltan Varga [Wed, 23 Oct 2019 15:06:18 +0000 (11:06 -0400)]
[wasm] Avoid adding an extra arg to native-to-managed wrappers. (mono/mono#17508)

[wasm] Avoid adding an extra arg to native-to-managed wrappers.

Fixes https://github.com/mono/mono/issues/17389.

<!--
Thank you for your Pull Request!

If you are new to contributing to Mono, please try to do your best at conforming to our coding guidelines http://www.mono-project.com/community/contributing/coding-guidelines/ but don't worry if you get something wrong. One of the project members will help you to get things landed.

Does your pull request fix any of the existing issues? Please use the following format: Fixes #issue-number
-->

Commit migrated from https://github.com/mono/mono/commit/31b475e25a4ab5b6d8af731be9bb9e8158da31d9

4 years ago[coop] Fix big endian problem in MonoThradStateMachine and cleanup. (mono/mono#17502)
Jay Krell [Wed, 23 Oct 2019 14:21:54 +0000 (07:21 -0700)]
[coop] Fix big endian problem in MonoThradStateMachine and cleanup. (mono/mono#17502)

Commit migrated from https://github.com/mono/mono/commit/8b8b8b5010140b56bab3130e1b5b5e296dd86752

4 years ago[netcore] Add Unsafe.SkipInit intrinsic
Filip Navara [Wed, 23 Oct 2019 09:53:06 +0000 (11:53 +0200)]
[netcore] Add Unsafe.SkipInit intrinsic

Commit migrated from https://github.com/mono/mono/commit/e29f8e32b77e29ec314c0e509e1d1aef9d286285

4 years ago[interp] Add a new super instructions pass (mono/mono#17489)
Vlad Brezae [Wed, 23 Oct 2019 08:57:07 +0000 (11:57 +0300)]
[interp] Add a new super instructions pass (mono/mono#17489)

Together with a few very simple super instructions. We replace common instruction patterns to avoid indirection via interp stack, instruction dispatch overhead and to allow the compiler to generate better code for the instruction.

Commit migrated from https://github.com/mono/mono/commit/479d2dff365a688cc0045b3c76aa7aba79d4784e

4 years ago[interp] Retry cprop pass if killing stloc (mono/mono#17491)
Vlad Brezae [Wed, 23 Oct 2019 07:39:27 +0000 (10:39 +0300)]
[interp] Retry cprop pass if killing stloc (mono/mono#17491)

When replacing a stloc with a pop, we should retry the pass, since it is very likely that we will be able to kill the instruction that pushed that value on the stack.

Commit migrated from https://github.com/mono/mono/commit/4419dc919f01c6d97ecd1662929adc6e7e642e83

4 years agoSetLastError slightly later, in case last error not preserved, and it is just as...
Jay Krell [Wed, 23 Oct 2019 07:36:15 +0000 (00:36 -0700)]
SetLastError slightly later, in case last error not preserved, and it is just as good. (mono/mono#17483)

SetLastError slightly later, in case last error not preserved, and it is just as good.

Commit migrated from https://github.com/mono/mono/commit/92c08fab4d417d9c3e62dab7f1bac5a710f28916

4 years ago[interp] Optimize ldelem instructions (mono/mono#17494)
Vlad Brezae [Wed, 23 Oct 2019 07:23:49 +0000 (10:23 +0300)]
[interp] Optimize ldelem instructions (mono/mono#17494)

Remove the switch and have each instruction have its own code. Seems to improve speed on a benchmark that heavily uses ldelem by about 10-20%.

Commit migrated from https://github.com/mono/mono/commit/61594078466fd80a4f80a0c3d670adb8301144b0

4 years ago[netcore] Disable debugging code in lookup_intrins (mono/mono#17464)
Filip Navara [Wed, 23 Oct 2019 04:01:51 +0000 (06:01 +0200)]
[netcore] Disable debugging code in lookup_intrins (mono/mono#17464)

Commit migrated from https://github.com/mono/mono/commit/1e60703a191297440d25f1f3a103fb515163869b

4 years ago[reflection] mono_method_get_base_method on a GTD should use canonical ginst (mono...
Aleksey Kliger (λgeek) [Tue, 22 Oct 2019 18:07:44 +0000 (14:07 -0400)]
[reflection] mono_method_get_base_method on a GTD should use canonical ginst (mono/mono#17475)

* [test] GetCustomAttributes on generic type definition

* [reflection] mono_method_get_base_method on a GTD should use canonical ginst

The issue is in how we pass along the generic instantiation.  So there are two
parts here: we start with a method on a GTD which has to decompose into the GTD
and it's instantiation with its own generic parameters, and then we go up to
its parent and grandparent inflating and decomposing the resulting
instantiation. The instantiations keep passing the last parameter as the number
of parameters shrinks so that the gparam index from the original type is now
out of bounds for the parent and grandparent.  If we mess up, we'll get a
BadImageFormatException from the runtime

Fixes https://github.com/mono/mono/issues/17278

Commit migrated from https://github.com/mono/mono/commit/fb5b2c949ddd2ab09fcddb458584a5facd9ec94e

4 years ago[coop] Use bitfields for coop state machine state representation (mono/mono#17298)
Aleksey Kliger (λgeek) [Tue, 22 Oct 2019 16:14:05 +0000 (12:14 -0400)]
[coop] Use bitfields for coop state machine state representation (mono/mono#17298)

* [checked] Mask the thread state in GC thread state assertions

Because we have extra bits (like suspend count and the no_checkpoints bit) on
the thread state, we have to mask it to get the actual thread state enum value

* [coop] Use bitfields to represent coop thread state

Instead of using a 32-bit int, use bitfields and type-punning through a union
type.  We need to type pun because we need to access the entire state as a 32-bit int so that we can do atomic CAS.

* use atomic load of thread state in unwrap_thread_state.

Saw one stack trace on CI on the full coop lane where check_thread_state saw STATE_RUNNING
but with a positive suspend count.  Another thread was starting a GC a
the time.  Seems like we saw the state as runnning, but the suspend
count as if we were already in async_suspend_requested.

Thread 22 (Thread 0x7f43c03ff700 (LWP 39860)):

Commit migrated from https://github.com/mono/mono/commit/ebb5846e0d743a12a359f4b1dbcea9d18ccfe867

4 years ago[System.Private.CoreLib] Remove unused methods
Marek Safar [Tue, 22 Oct 2019 13:49:26 +0000 (09:49 -0400)]
[System.Private.CoreLib] Remove unused methods

Commit migrated from https://github.com/mono/mono/commit/f34fd20fbf009c9ef174c1fabdbccda47c93b9da

4 years agoUpdate Mono for changes in shared CoreLib partition
Filip Navara [Tue, 22 Oct 2019 09:54:15 +0000 (11:54 +0200)]
Update Mono for changes in shared CoreLib partition

Commit migrated from https://github.com/mono/mono/commit/cf1a9e003371495f4fff86c690da0213fff29c85

4 years ago[jit] Avoid running mono_handle_native_crash () on the altstack, it can't produce...
Zoltan Varga [Tue, 22 Oct 2019 10:31:23 +0000 (06:31 -0400)]
[jit] Avoid running mono_handle_native_crash () on the altstack, it can't produce a backtrace. AMD64 only for now. (mono/mono#17466)

* [jit] Avoid running mono_handle_native_crash () on the altstack, it can't produce a backtrace. AMD64 only for now.

* Fix checks so stack overflows work again.

Commit migrated from https://github.com/mono/mono/commit/b96260e603fe0188e54019bfde8ca00bc2b5d78c

4 years ago[interp] Replace loading of static readonly fields with LDC (mono/mono#17420)
Vlad Brezae [Mon, 21 Oct 2019 20:42:24 +0000 (23:42 +0300)]
[interp] Replace loading of static readonly fields with LDC (mono/mono#17420)

LDC is faster and also allows for constant propagation. Cleanup code a little bit.

Commit migrated from https://github.com/mono/mono/commit/c1461e4a2d9c539506b88af786c948ff8a8bad7d

4 years agoNo type_traits on Android.
Jay Krell [Fri, 18 Oct 2019 01:17:24 +0000 (18:17 -0700)]
No type_traits on Android.

In file included from /Users/builder/jenkins/workspace/test-mono-pull-request-amd64-osx-products-sdks-android/mono/metadata/icall.c:42:
/Users/builder/jenkins/workspace/test-mono-pull-request-amd64-osx-products-sdks-android/mono/metadata/icall-internals.h:89:10: fatal error: 'type_traits' file not found

Commit migrated from https://github.com/mono/mono/commit/fd82c6036ec3720d568050c1e538f9729cef984e

4 years ago[cxx][debug-interp] Cast once from void* to non-void*.
Jay Krell [Sat, 19 Oct 2019 01:35:42 +0000 (18:35 -0700)]
[cxx][debug-interp] Cast once from void* to non-void*.

Commit migrated from https://github.com/mono/mono/commit/21d7d41bfe4a8aebed8e73deadd1fb1177360392

4 years ago[Coop] Unconvert Microsoft.Win32.NativeMethods. (mono/mono#16992)
Jay Krell [Mon, 21 Oct 2019 08:29:39 +0000 (01:29 -0700)]
[Coop] Unconvert Microsoft.Win32.NativeMethods. (mono/mono#16992)

* [Coop] Unconvert ves_icall_Microsoft_Win32_NativeMethods_CloseProcess.

* [Coop] Unconvert ves_icall_Microsoft_Win32_NativeMethods_GetCurrentProcess.

* [Coop] Unconvert ves_icall_Microsoft_Win32_NativeMethods_GetCurrentProcessId.

* [Coop] Unconvert ves_icall_Microsoft_Win32_NativeMethods_GetExitCodeProcess.

* [Coop] Unconvert ves_icall_Microsoft_Win32_NativeMethods_GetPriorityClass.

* [Coop] Unconvert ves_icall_Microsoft_Win32_NativeMethods_GetProcessTimes.

* [Coop] Unconvert ves_icall_Microsoft_Win32_NativeMethods_GetProcessWorkingSetSize.

* [Coop] Unconvert ves_icall_Microsoft_Win32_NativeMethods_SetPriorityClass.

* [Coop] Unconvert ves_icall_Microsoft_Win32_NativeMethods_SetProcessWorkingSetSize.

* [Coop] Unconvert ves_icall_Microsoft_Win32_NativeMethods_TerminateProcess.

* [Coop] Unconvert ves_icall_Microsoft_Win32_NativeMethods_WaitForInputIdle.

Commit migrated from https://github.com/mono/mono/commit/9f50bdb2d944793d30ea2d052cdad96feb282003

4 years ago[interp] Small fixes. (mono/mono#17442)
Zoltan Varga [Mon, 21 Oct 2019 03:28:25 +0000 (23:28 -0400)]
[interp] Small fixes. (mono/mono#17442)

* [interp] Really abort in ves_real_abort ().

* [interp] Fix stack usage in TRACE_EXIT.

* [interp] Add a callback to free ThreadContext.

* Fix warnings.

* Remove an empty statement.

* Fix a double free.

Commit migrated from https://github.com/mono/mono/commit/4b9226619c9caef3d45778380198c70a43e3570c

4 years ago[netcore] Implement Array.GetElementSize as intrinsic (mono/mono#17437)
Filip Navara [Sun, 20 Oct 2019 22:39:39 +0000 (00:39 +0200)]
[netcore] Implement Array.GetElementSize as intrinsic (mono/mono#17437)

* [netcore] Implement Array.GetElementSize as intrinsic

* Remove unnecessary icall

* alloc_preg -> alloc_ireg

* Implement Array.GetElementSize as intrinsic in interpreter

* Address PR feedback

Commit migrated from https://github.com/mono/mono/commit/32ab6bcf004dee2009ab98f9381842ff3fc6e6f2

4 years ago[netcore] Remove unused code for Array.Unsafe[Mov/Load/Store] intrinsics
Filip Navara [Sat, 19 Oct 2019 09:58:49 +0000 (11:58 +0200)]
[netcore] Remove unused code for Array.Unsafe[Mov/Load/Store] intrinsics

Commit migrated from https://github.com/mono/mono/commit/67c8d0d812d5045ca084d24ad271233685a6c899

4 years agoUse correct variable in mini_get_cpu_features (mono/mono#17436)
Filip Navara [Sun, 20 Oct 2019 05:26:44 +0000 (07:26 +0200)]
Use correct variable in mini_get_cpu_features (mono/mono#17436)

* Use correct variable in mini_get_cpu_features

* Address PR feedback

Commit migrated from https://github.com/mono/mono/commit/bc678a2c10b98d8624bc55da1e4409be13a265f4

4 years agoRemove dead code left out in mono/mono#17341 (mono/mono#17433)
Filip Navara [Sun, 20 Oct 2019 05:23:05 +0000 (07:23 +0200)]
Remove dead code left out in mono/mono#17341 (mono/mono#17433)

Commit migrated from https://github.com/mono/mono/commit/91f10aeee4ff70696f19fdda9f3d6b67403bc45d

4 years ago[jit][x86][cxx] int/ptr casts in mini-x86.c (mono/mono#17380)
Jay Krell [Sat, 19 Oct 2019 17:20:56 +0000 (10:20 -0700)]
[jit][x86][cxx] int/ptr casts in mini-x86.c (mono/mono#17380)

Commit migrated from https://github.com/mono/mono/commit/91413f78f3242aab3d38d0fb609dd748999265fc

4 years agoReplace ICALL_DECL_EXPORT with ICALL_EXPORT. They are always the same, and it is...
Jay Krell [Sat, 19 Oct 2019 11:25:54 +0000 (04:25 -0700)]
Replace ICALL_DECL_EXPORT with ICALL_EXPORT. They are always the same, and it is only used once. (mono/mono#17429)

Replace ICALL_DECL_EXPORT with ICALL_EXPORT. They are always the same and it is only used once.

Commit migrated from https://github.com/mono/mono/commit/84f4e1dcbf96925105f4d4f54bb9cb9b61067603

4 years ago[bcl] Add null reference checks to Interlocked.Exchange<T> (mono/mono#17400)
Aleksey Kliger (λgeek) [Fri, 18 Oct 2019 23:11:22 +0000 (19:11 -0400)]
[bcl] Add null reference checks to Interlocked.Exchange<T> (mono/mono#17400)

* [bcl] Add null reference checks to Interlocked.Exchange<T>

and Interlocked.CompareExchange<T>

This is to mimic the old behavior in unmanaged when the intrinsic cannot be
used.

The issue was detected via the coreclr acceptance test:
https://github.com/mono/coreclr/blob/mono/tests/src/baseservices/threading/interlocked/exchange/exchangetneg.il

* and netcore

Commit migrated from https://github.com/mono/mono/commit/d8ae32a9ee7763c861bdc31831271d82aa8a4953

4 years ago[cxx] [wasm] int/ptr casts esp. m2n-gen. (mono/mono#17379)
Jay Krell [Fri, 18 Oct 2019 22:03:00 +0000 (15:03 -0700)]
[cxx] [wasm] int/ptr casts esp. m2n-gen. (mono/mono#17379)

Commit migrated from https://github.com/mono/mono/commit/a2992d634b9cfa6ae8572ba597f009cb05104743

4 years agoMerge pull request mono/mono#17279 from imhameed/bug-gh-16935-netcore-equalsall-codegen
imhameed [Fri, 18 Oct 2019 19:47:41 +0000 (12:47 -0700)]
Merge pull request mono/mono#17279 from imhameed/bug-gh-16935-netcore-equalsall-codegen

Generate LLVM IR for OP_XEQUAL that is recognized by LLVM's vector pattern recognizers.

Commit migrated from https://github.com/mono/mono/commit/8836231459121e0144ae03169554c1d0636ec5ba

4 years agoSome updates to make RISC-V buildable again. (mono/mono#17408)
Alex Rønne Petersen [Fri, 18 Oct 2019 18:16:14 +0000 (20:16 +0200)]
Some updates to make RISC-V buildable again. (mono/mono#17408)

Some updates to make RISC-V buildable again.

Also some updates to the toolchain setup documentation.

Commit migrated from https://github.com/mono/mono/commit/d44e0e80d73d59de204b5db881e3d8c6076b4cac

4 years ago[profiler] Fix coverage profiler on macos (mono/mono#17396)
Vlad Brezae [Fri, 18 Oct 2019 14:31:47 +0000 (17:31 +0300)]
[profiler] Fix coverage profiler on macos (mono/mono#17396)

If we have coverage profiling enabled for a method (mono_profiler_coverage_instrumentation_enabled, with coverage_filter callback), then we should be able to allocate a coverage info structure (mono_profiler_coverage_alloc). After https://github.com/mono/mono/commit/mono/mono@52429673dc617fd437518757c04c7448211075e9, coverage_filter was reporting wrapper methods as ok to profile, while mono_profiler_coverage_alloc was refusing to allocate the necessary structure, leading to crashes.

Commit migrated from https://github.com/mono/mono/commit/37f628750af0f81e7550989e83bcfe3d134fb6be

4 years ago[interp][wasm] Remove more varargs to conserve stack. (mono/mono#17388)
Jay Krell [Fri, 18 Oct 2019 07:39:05 +0000 (00:39 -0700)]
[interp][wasm] Remove more varargs to conserve stack. (mono/mono#17388)

Commit migrated from https://github.com/mono/mono/commit/958b9b2658f6d866ba451781cfa2180e2b340f35

4 years agoEnable GSS on Linux and Android (mono/mono#17223)
Egor Bogatov [Thu, 17 Oct 2019 23:01:44 +0000 (02:01 +0300)]
Enable GSS on Linux and Android (mono/mono#17223)

Commit migrated from https://github.com/mono/mono/commit/4908d1f19a615b033ec148b49c8fab83f1e6f0ec

4 years ago[interp] Constant folding for integers (mono/mono#17362)
Vlad Brezae [Thu, 17 Oct 2019 11:23:12 +0000 (14:23 +0300)]
[interp] Constant folding for integers (mono/mono#17362)

* [interp] Move instructions together

For easy check if an instruction is unary or binary operation. We consider conversion instructions to be unary operators and compare instructions to be binary operators.

* [interp] Add stloc.np also for longs

* [interp] Add stats for total number of emitted instructions

Also make the killed_instructions counter actually track the total amount of killed instructions. It was not previously tracking instructions killed as part of addition of stloc.np / movloc.

* [interp] Improve logging during cprop

Make dumping instruction support also InterpInst's not just compacted instructions.

* [interp] Constant folding of common unary operators

* [interp] Constant fold binary operations

* [interp] Remove MINT_CONV_U8_I4 opcode

It is equivalent with MINT_CONV_I8_U4.

Commit migrated from https://github.com/mono/mono/commit/ec653e70bfaba99e9fd88ceb3ff475eda83cb8f1

4 years ago[cxx] Int vs. enum, static for efficiency, cleanup, fix typo. (mono/mono#17377)
Jay Krell [Thu, 17 Oct 2019 10:25:18 +0000 (03:25 -0700)]
[cxx] Int vs. enum, static for efficiency, cleanup, fix typo. (mono/mono#17377)

[cxx] Int vs. enum, static for efficiency, cleanup, fix typo.

Commit migrated from https://github.com/mono/mono/commit/e8b6fcc9451eded4ba370649bcb41fad405f0b2a

4 years ago[cxx][x86] int/ptr casts. (mono/mono#17345)
Jay Krell [Thu, 17 Oct 2019 10:24:46 +0000 (03:24 -0700)]
[cxx][x86] int/ptr casts. (mono/mono#17345)

Commit migrated from https://github.com/mono/mono/commit/e97e1f994d0310b4f988fad343793019cf5e273d

4 years ago[interp] Always intrinsify MemoryBarrier method
Vlad Brezae [Wed, 16 Oct 2019 20:13:10 +0000 (23:13 +0300)]
[interp] Always intrinsify MemoryBarrier method

As we do it on jit.

Commit migrated from https://github.com/mono/mono/commit/ae0fbd366e3125d8da99663a492f6116de4214b9

4 years ago[interp] Avoid using full barriers for volatile operations
Vlad Brezae [Wed, 16 Oct 2019 20:01:54 +0000 (23:01 +0300)]
[interp] Avoid using full barriers for volatile operations

This commit avoid unnecessary memory barriers on x86 and amd64.

Volatile writes have release semantics, volatile reads have acquire semantics. Organize the code a little bit to indicate this. On x86 and amd64 we don't require barrier for acquire and release semantics since they are provided by the arch, so we can skip them. Ideally we should have 3 memory barrier interp instructions for each type, but, currently, they would all seem to call mono_memory_barrier so it is useless at this point.

Commit migrated from https://github.com/mono/mono/commit/0102263645b73422d84dbe7fac3bdee65c7447a7

4 years agoUpgrade build scripts to support VS2019. (mono/mono#17269)
Johan Lorensson [Thu, 17 Oct 2019 06:55:50 +0000 (08:55 +0200)]
Upgrade build scripts to support VS2019. (mono/mono#17269)

Changes will default Windows SDK version as well as Platform Toolset to
the default versions used in the targeted VS version. If the projects are
opened up in VS2015, it should default to Windows SDK 8.1 and v140, but if
the same projects are opened in VS2019, it will default to latest Windows SDK 10
and v142. This way the project files should adapt to used VS version, meaning
that we could still build them using VS2015 (what's currently used on CI) but also
using VS2017 and VS2019. There should not be a need to install any previous versions
of build tools, unless an older version is targeted. It is also possible to set
PlatformToolset when calling msbuild and that should adapt to corresponding default
Windows SDK version for targeted toolset version.

Commit makes many changes and adjustments, aligning all vcxproj files but changes
should not affect build output.

Commit migrated from https://github.com/mono/mono/commit/4f8a82c9fdebd7e9dcc5392a8b3a0fd129789bc0

4 years agoUse functions instead of macros for is_in/is_out. (mono/mono#17350)
Jay Krell [Thu, 17 Oct 2019 04:46:03 +0000 (21:46 -0700)]
Use functions instead of macros for is_in/is_out. (mono/mono#17350)

Use functions instead of macros for is_in/is_out.

Commit migrated from https://github.com/mono/mono/commit/edafa021d3b8e5b5762a297afa38ae58c21997b1

4 years ago[master] Update dependencies from dotnet/core-setup dotnet/corefx (mono/mono#17355)
dotnet-maestro[bot] [Wed, 16 Oct 2019 21:12:15 +0000 (23:12 +0200)]
[master] Update dependencies from dotnet/core-setup dotnet/corefx (mono/mono#17355)

* Update dependencies from https://github.com/dotnet/core-setup build 20191015.17

- Microsoft.NETCore.App - 5.0.0-alpha1.19515.17

* Update dependencies from https://github.com/dotnet/corefx build 20191015.14

- Microsoft.Private.CoreFx.NETCoreApp - 5.0.0-alpha1.19515.14

* Reenable a test that was fixed

Commit migrated from https://github.com/mono/mono/commit/1dbad7cd881f1051fe21e72911bd4ce0228cb954

4 years ago[cxx][x86][amd64] Remove unused STORE_MEM_IMM. (mono/mono#17347)
Jay Krell [Wed, 16 Oct 2019 20:26:02 +0000 (13:26 -0700)]
[cxx][x86][amd64] Remove unused STORE_MEM_IMM. (mono/mono#17347)

[cxx][x86][amd64] Remove unused STORE_MEM_IMM.

And there was an int/ptr cast error within.

Commit migrated from https://github.com/mono/mono/commit/c0d50719eab15fbf7fe8259fd3df065af7eb91f3

4 years ago[bcl][jit] implement Interlocked.Exchange<T> in terms of object (mono/mono#17341)
Aleksey Kliger (λgeek) [Wed, 16 Oct 2019 19:35:49 +0000 (15:35 -0400)]
[bcl][jit] implement Interlocked.Exchange<T> in terms of object (mono/mono#17341)

* [bcl][jit] implement Interlocked.Exchange<T> in terms of object

Exchange<T> is supposed to be picked up as an intrinsic.  But if it isn't,
since T has a class constraint, call the `Exchange (ref object, ref object, ref
object)` overload instead.

This works around a limitation in the JIT:
https://github.com/mono/mono/blob/mono/mono@82a07273c22b996b08fa88ee2e6632d782ac2242/mono/mini/mini-trampolines.c#L704-L713

if we're in the common call trampoline, and the caller is generic method and
the callee is a generic method, if we're using generic sharing for the caller,
but there's no generic jit info for the callee, we will not patch the call
site.

In this case we had Exchange<T> calling Exchange_T<T>
where the callee is an icall (and evidently didn't have generic jit info).

So every time we called Exchange<T>, we would go through the trampoline when
trying to call Exchange_T<T> without patching the call site.

Addresses part of https://github.com/mono/mono/issues/17334

* Bump Mono

* Also drop CompareExchange_T<T>

* Sprinkle some Unsafe magic.

Mark the non-icall methods that we expect the JIT to treet as intrinsics with [Intrinsic]

* aot-runtime doesn't need Volatile.Read<T>/Write<T> code

Both of those methods are implemented as calls to the object overload of Volatile.Read/Write

Commit migrated from https://github.com/mono/mono/commit/f017835ac11371038aec3ea66c513c8234d73187

4 years agoremove GenericVectorTests from rsp (mono/mono#17366)
Egor Bogatov [Wed, 16 Oct 2019 19:24:16 +0000 (22:24 +0300)]
remove GenericVectorTests from rsp (mono/mono#17366)

Commit migrated from https://github.com/mono/mono/commit/58b53299b76c7f788a18116676ea8aa9c00a0b9c

4 years ago[cxx][netcore] Goto around init. (mono/mono#17348)
Jay Krell [Wed, 16 Oct 2019 18:56:09 +0000 (11:56 -0700)]
[cxx][netcore] Goto around init. (mono/mono#17348)

[cxx][netcore] Goto around init.

Commit migrated from https://github.com/mono/mono/commit/de9ccfa63fc373d20759275c5eb5f3706869def3

4 years ago[cxx][x86] ifndef DISABLE_JIT around mono_arch_emit_prolog. (mono/mono#17346)
Jay Krell [Wed, 16 Oct 2019 18:28:24 +0000 (11:28 -0700)]
[cxx][x86] ifndef DISABLE_JIT around mono_arch_emit_prolog. (mono/mono#17346)

Commit migrated from https://github.com/mono/mono/commit/70675241410f886b096ee79decaf6c3da047640a

4 years agofix netcore build with cygwin (mono/mono#17361)
Egor Bogatov [Wed, 16 Oct 2019 18:20:48 +0000 (21:20 +0300)]
fix netcore build with cygwin (mono/mono#17361)

Commit migrated from https://github.com/mono/mono/commit/c13f36bdfe4558277b92fba714385d0ee377bf0b

4 years ago[netcore] Implement System.IO.HasOverriddenBeginEndRead(Write)… (mono/mono#17237)
Egor Bogatov [Wed, 16 Oct 2019 18:16:51 +0000 (21:16 +0300)]
[netcore] Implement System.IO.HasOverriddenBeginEndRead(Write)… (mono/mono#17237)

* Implement HasOverriddenBeginEndRead and HasOverriddenBeginEndWrite

* fix typo

* clean up

* more clean up

* more clean up

* convert into intrinsics

* handle end* methods

* Update intrinsics.c

* make cache_System_IO_Stream_slots static

* fix race condition

* Rollback to icall

* Update icall.c

* Address feedback

* Address feedback

Commit migrated from https://github.com/mono/mono/commit/886cd73784befd68b45c4fa3fa4f6864fe366139

4 years ago[ci] Improve netcore build telemetry by running nupkg and tests through build.sh...
Alexander Köplinger [Wed, 16 Oct 2019 16:52:13 +0000 (18:52 +0200)]
[ci] Improve netcore build telemetry by running nupkg and tests through build.sh (mono/mono#17349)

Follow-up to https://github.com/mono/mono/pull/17331.

We were running nuget pack and tests explicitly in the Azure Pipelines
config so we weren't capturing failure telemetry.

Commit migrated from https://github.com/mono/mono/commit/cd6e574b87b4746afa980165a52e0eb0a95be58e

4 years agoReplace mono_assembly_name_free use with mono_assembly_name_free_internal. (mono...
Jay Krell [Wed, 16 Oct 2019 12:25:55 +0000 (05:25 -0700)]
Replace mono_assembly_name_free use with mono_assembly_name_free_internal. (mono/mono#16982)

Replace mono_assembly_name_free use with mono_assembly_name_free_internal.

Maybe just remove the GC mode change and remove the internal form.
We don't really equate malloc/free with GC/locks/hangs, though arguably we should. Arguably this change is right.

Commit migrated from https://github.com/mono/mono/commit/a03027cab08e9b2caddef8cdd8b62b8d2d6430c8

4 years ago[interp] Add constant propagation of integers (mono/mono#17326)
Vlad Brezae [Wed, 16 Oct 2019 10:56:14 +0000 (13:56 +0300)]
[interp] Add constant propagation of integers (mono/mono#17326)

* [interp] Make StackValue more intuitive

Replace the opcode field with an enum which will represent what type of value is contained (STACK_VALUE_LOCAL, STACK_VALUE_I4 etc)

* [interp] Add the mint type to the local data

Makes the emitting code easier and we no longer compute the mint type for each local access, which is fairly expensive.

* [interp] Handle indirect locals saner during cprop

Instead of checking for the indirect flag when loading from a local, simply never store a StackValue into such a local since we can't use it. We use the same logic when not pushing on the stack values for such locals.

* [interp] Add constant folding for integers

We decode the values from LDC_I4 and LDC_I8 opcodes and track/propagate the values on the stack and in the locals using the existing infrastructure. When loading a local, we try to load using the known constant value instead, so we might get to kill that local.

* [interp] Similar to stloc.np we can optimize pop/push pairs

If the pushing instruction pushes the same value that was popped by the previous instruction, we can kill them both

* [tests] Remove issue that seems to have been fixed for a while

Commit migrated from https://github.com/mono/mono/commit/0aabccef9bf6f17313fa384349a8089e8d8b0642

4 years agoFix C++ WebAssembly build. (mono/mono#17302)
Jay Krell [Wed, 16 Oct 2019 08:12:41 +0000 (01:12 -0700)]
Fix C++ WebAssembly build. (mono/mono#17302)

Commit migrated from https://github.com/mono/mono/commit/7d3fc17e815073e24d1f1506305e6ae0c4753be7

4 years agoFix SafeHandle marshalling in ref/in/out parameters (mono/mono#17330)
Filip Navara [Wed, 16 Oct 2019 05:43:42 +0000 (07:43 +0200)]
Fix SafeHandle marshalling in ref/in/out parameters (mono/mono#17330)

* Fix SafeHandle marshalling in ref/in/out parameters

* Reorder code to make it exception safe, update comments

* Revert the code reordering because it breaks the invariant that new handle returned from native code should always create new SafeHandle on the managed side

* Fix test_0_safehandle_ref test. The test was expecting incorrect behavior, verified on .NET Core 3 and .NET Framework 4.8.

* Address PR feedback

* Fix cut & paste error

* Fix build

* Really fix the test_0_safehandle_ref tests

* Add more tests for SafeHandle marshalling

* Add exclusion for broken CoreFX test

Commit migrated from https://github.com/mono/mono/commit/0c02bb1207af75c176c369e411d9f4407e21030d

4 years ago[jit] Fix is_reference checks for intrinsics with byref parameters. (mono/mono#17338)
Zoltan Varga [Wed, 16 Oct 2019 01:45:04 +0000 (21:45 -0400)]
[jit] Fix is_reference checks for intrinsics with byref parameters. (mono/mono#17338)

Found by https://github.com/mono/mono/issues/17335.

Commit migrated from https://github.com/mono/mono/commit/08e8a7f2c3c43366358901d304bfe2808962577a

4 years ago[loader] Add an explicit define DISABLE_DLLMAP to control dllmap usage (mono/mono...
Ryan Lucia [Tue, 15 Oct 2019 23:40:24 +0000 (19:40 -0400)]
[loader] Add an explicit define DISABLE_DLLMAP to control dllmap usage (mono/mono#17315)

* [loader] Add an explicit define ENABLE_DLLMAP to control dllmap usage

* Update configure.ac

* Update configure.ac

* Add dllmap to enable-minimal

* Change to DISABLE_DLLMAP

* Grab some missing MonoDllMap uses

Commit migrated from https://github.com/mono/mono/commit/3fa5f6c66e5d87e25425f2ced2c21d546aaf3cfe

4 years agoInitial telemetry for netcore builds (mono/mono#17331)
Jo Shields [Tue, 15 Oct 2019 20:21:21 +0000 (16:21 -0400)]
Initial telemetry for netcore builds (mono/mono#17331)

* Load VSTS telemetry helpers into build.sh script

* First cut adding some basic VSTS-compatible telemetry on failures

* Don't make `ci=true` the default, make it a build.sh flag

Commit migrated from https://github.com/mono/mono/commit/dc0eea6fd1c76c1060751d24ba8d0e93b8ea0277

4 years agoUpdate CoreFX.issues.rsp
Filip Navara [Mon, 14 Oct 2019 23:44:42 +0000 (01:44 +0200)]
Update CoreFX.issues.rsp

See https://github.com/mono/mono/pull/17232#issuecomment-541973035.

Commit migrated from https://github.com/mono/mono/commit/ac1d05ad4066456ddeab9748ab28989dd2a70ee2

4 years ago[netcore] Avoid suspending threads in Environment.Exit, it can hang process (mono...
Filip Navara [Mon, 14 Oct 2019 22:35:26 +0000 (00:35 +0200)]
[netcore] Avoid suspending threads in Environment.Exit, it can hang process (mono/mono#17318)

CoreCLR doesn't suspend threads on exit (https://github.com/dotnet/corefx/pull/41450#issuecomment-536755093, https://github.com/dotnet/coreclr/pull/1813).

Fixes mono/mono#17317
Fixes mono/mono#15006
Fixes mono/mono#15010
Fixes mono/mono#15181

Unblocks mono/mono#17232

Commit migrated from https://github.com/mono/mono/commit/a194de4cdf2b3e3567672edf75aee1b5624d199f

4 years agoRemove broken sin/cos optimization for x86
Filip Navara [Sat, 12 Oct 2019 10:29:27 +0000 (12:29 +0200)]
Remove broken sin/cos optimization for x86

Commit migrated from https://github.com/mono/mono/commit/76068d8d6130f837f004bd435b23175886319a02

4 years agoRemove broken sin/cos optimization for x64
Filip Navara [Sat, 12 Oct 2019 10:27:47 +0000 (12:27 +0200)]
Remove broken sin/cos optimization for x64

Commit migrated from https://github.com/mono/mono/commit/05df3970c21fc31d17a1d79e6738fa43d78709fd

4 years agoFix msvc build warning, empty source main-core.c. (mono/mono#17305)
Johan Lorensson [Mon, 14 Oct 2019 16:55:07 +0000 (18:55 +0200)]
Fix msvc build warning, empty source main-core.c. (mono/mono#17305)

Commit migrated from https://github.com/mono/mono/commit/734b77688467defe62010b3f4eeb6d1694a7e596

4 years ago[loader] Locking and coop related cleanup; fix leak
Ryan Lucia [Wed, 9 Oct 2019 17:16:48 +0000 (13:16 -0400)]
[loader] Locking and coop related cleanup; fix leak

Commit migrated from https://github.com/mono/mono/commit/e7b199377c1876c308b8420230b5ea74bf7a2aa9

4 years ago[loader] Move PInvoke and DllMap code into separate source file
Ryan Lucia [Tue, 8 Oct 2019 22:02:05 +0000 (18:02 -0400)]
[loader] Move PInvoke and DllMap code into separate source file

Commit migrated from https://github.com/mono/mono/commit/bf3afd6cad3974706287d0943c3a5d0e823c1e5f

4 years ago[netcore] Remove unused InternalLoadUnmanagedDllFromPath
Ryan Lucia [Wed, 9 Oct 2019 17:37:35 +0000 (13:37 -0400)]
[netcore] Remove unused InternalLoadUnmanagedDllFromPath

As of https://github.com/dotnet/coreclr/pull/27090

Commit migrated from https://github.com/mono/mono/commit/80db55591af3bc85f3f2d0735c316b9b08350a79

4 years ago[netcore] Use a single NativeLibrary.cs for all platforms
Ryan Lucia [Tue, 8 Oct 2019 20:10:03 +0000 (16:10 -0400)]
[netcore] Use a single NativeLibrary.cs for all platforms

Commit migrated from https://github.com/mono/mono/commit/96050effa6e0461b986ac33ab15940b3a9d93353

4 years agoMirror changes from mono/coreclr (mono/mono#17297)
Dotnet-GitSync-Bot [Sat, 12 Oct 2019 06:50:00 +0000 (23:50 -0700)]
Mirror changes from mono/coreclr (mono/mono#17297)

* Enable fast-paths on Mono for Array (dotnet/coreclrmono/mono#27144)

Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
* [CoreLib] Remove String fields moved to shared

* Stub Array Try* methods

Commit migrated from https://github.com/mono/mono/commit/4e81814709b0ebbab4ed6e5bde22370b0fd5e4ac

4 years ago[loader] Fix gnu/lib-names.h define (mono/mono#17294)
Ryan Lucia [Sat, 12 Oct 2019 00:49:24 +0000 (20:49 -0400)]
[loader] Fix gnu/lib-names.h define (mono/mono#17294)

Commit migrated from https://github.com/mono/mono/commit/9832bbb0ac059418c5edeb6388678be89e44f560

4 years ago[runtime] Add portable cached array creation functions and replace gcc-specific impl...
Jay Krell [Fri, 11 Oct 2019 23:47:20 +0000 (16:47 -0700)]
[runtime] Add portable cached array creation functions and replace gcc-specific impl. (mono/mono#16855)

* Remove unused mono_class_get_field_from_name_cached.

* Replace gcc-specific:
  mono_array_class_get_cached
  mono_array_new_cached
  mono_array_new_cached_handle

with portable forms that are easy enough to use and general enough.

Before was "easier" because cache provided for you -- possibly multiple.
Before was more general because rank was a parameter -- and had to be a constant.
It was always 1.

Commit migrated from https://github.com/mono/mono/commit/33d62537d4f7ceeabd8439b26724450a88981d58

4 years agoEnable more hw intrinsics for AOT (mono/mono#17160)
Egor Bogatov [Fri, 11 Oct 2019 19:09:08 +0000 (22:09 +0300)]
Enable more hw intrinsics for AOT (mono/mono#17160)

* Enable more hw intrinsics for AOT

* Address feedback

* does it fix the failure?

* fix loadedllvm

* Address feedback

* fix copy-paste

* forgot MONO_LLVM_INTERNAL

Commit migrated from https://github.com/mono/mono/commit/9cc5ea3862894a10d87a51e302893b0165e4850c

4 years agoUpdate MERP event type to MonoAppCrash (mono/mono#17131)
Kyle White [Fri, 11 Oct 2019 15:15:21 +0000 (11:15 -0400)]
Update MERP event type to MonoAppCrash (mono/mono#17131)

* Update parameters in MERP WerReportMetadata xml

To enable backend analysis, we need to update our parameters to match our back end event type, which is MonoAppCrash.

It doesn't make sense to me that the previous implementation constructed the XML here in Mono, but depended on the user (VSMac in this case) to add the "correct" event type.  The parameters in the XML, must match exactly what is expected for the given EventType, and so we should ensure they are always in-sync by defining them here.  Thus, I removed the usage of `eventType` in `mono_merp_enable` and hard coded the expected eventType.

* [merp] Don't pass eventType from managed

The eventType must me MONO_MERP_EVENT_TYPE_STR ("MonoAppCrash") - the backend
determines the format of the other fields based on the event type, so it
doesn't make sense to pass other values from managed since the runtime controls
the other fields.

For compatability Mono.Runtime.EnableMicrosoftTelemetry will still take a
string parameter (now called "unused" instead of "eventType_str") but it will
not pass it down to the internal call.

* Bump corlib version

* [merp] Revert paramerters in WerReportMetadata.xml

Still need event type to be `MonoAppCrash` but the parameters will be the same as before.

Commit migrated from https://github.com/mono/mono/commit/481b3005c63daa38d163e46ef5bb43288b1403b7

4 years agoGenerate LLVM IR for OP_XEQUAL that is recognized by LLVM's vector pattern recognizers.
Imran Hameed [Thu, 10 Oct 2019 23:05:34 +0000 (16:05 -0700)]
Generate LLVM IR for OP_XEQUAL that is recognized by LLVM's vector pattern recognizers.

Commit migrated from https://github.com/mono/mono/commit/7c7d406fc01e6f867519c8aa3959d5a96a896a3e

4 years ago[interp] Kill more instructions (mono/mono#17226)
Vlad Brezae [Thu, 10 Oct 2019 19:29:19 +0000 (22:29 +0300)]
[interp] Kill more instructions (mono/mono#17226)

* [interp] Replace STLOC to dead local with MINT_POP

* [interp] Optimize MINT_POP

It was only used for 0 and 1 values. The implementation for values larger than 1 was broken anyway.

* [interp] Remove unnecessary usage of MINT_POP1

When storing a static field from a CEE_STFLD instruction.

* [interp] Prevent optimizing away the stack, after a branch

We know the contents of the stack following a branch, so we could have optimized away some instructions preceding the branch. We shouldn't do this because the code we are branching to expects a certain stack size.

* [interp] Clear instructions which push unused values on stack

* [interp] Properly initialize stack when pushing local

Commit migrated from https://github.com/mono/mono/commit/165c114aaa68a52c5aa10ae1df93816f71061840

4 years ago[eglib] Add newline for failure check prints (mono/mono#17262)
Ryan Lucia [Thu, 10 Oct 2019 13:23:16 +0000 (09:23 -0400)]
[eglib] Add newline for failure check prints (mono/mono#17262)

Commit migrated from https://github.com/mono/mono/commit/1b6bbfaf367211bb785467731ae1a111a9487dfd

4 years agoIncorrect constrained virtual call in method using gsharedvt for reference type....
Johan Lorensson [Thu, 10 Oct 2019 13:22:54 +0000 (15:22 +0200)]
Incorrect constrained virtual call in method using gsharedvt for reference type. (mono/mono#17227)

* Incorrect constrained virtual call in method using gsharedvt for reference type.

For generic constrained virtual calls using reference type's, the
virtual call will be dispatched using instance vtable. When the same
virtual call is taking place in a gsharedvt method, mono_gsharedvt_constrained_call
gets called that will assist making the call, the problem is that it will
use the constrained class for reference types meaning that it will not call
the most derived implementation of the method. This difference in the behavior
compared to none gsharedvt versions of methods, gives inconsistent results.

One way this will reproduce is by using Dictionary<Type, EmptyStruct>. For
methods that will take both Type (reference type) and EmptyStruct (value type)
like Add, calling that through IDictionary (hiding details from compiler) will
use the gsharedvt version of the method. Internally that method will call
Type.GetHashCode (), and since Type really is a RuntimeType it overrides
GetHashCode. But since mono_gsharedvt_constrained_call will use the constrained
class instead of the instance class, the called method will be
Object.GetHashCode, that gives a different result. When later ContainsKey
is called using the same Type, it only takes a reference value, so not
using a gsharedvt version of the method, then the most derived version of
GetHashCode will be called, given a different hash, not finding item
in dictionary.

Fix is to make sure behavior in mono_gsharedvt_constrained_call match
behavior for regular constrained virtual calls when having a reference type.
This makes sure we always call the most derived version of the method.

Commit also adds a test for this specific scenario using a dictionary.

* Updated to a more low-level test.

Commit migrated from https://github.com/mono/mono/commit/0db52289a39cf21618ec604f2b0940bbfbfd616b

4 years ago[mini] trace snippet should restore return value (mono/mono#17251)
Bernhard Urban-Forster [Thu, 10 Oct 2019 09:21:23 +0000 (11:21 +0200)]
[mini] trace snippet should restore return value (mono/mono#17251)

* [mini] trace snippet should restore return value

This is a problem on architectures with a floating point stack (x86).

Without this PR and without `--trace` the managed-to-native wrapper for `Math.Ceiling` has a basic block like this at the end:

```
AFTER LOWER-VTYPE-OPTS  4: [IN:  BB6(5) BB3(1), OUT:  BB1(3) ]
 fmove R34 <- R16
 ldaddr R35 <- R10
 load_membase R37 <- [R35 + 0x0]
 store_membase_reg [R36] <- R37
 il_seq_point il: 0x2d
```

`R16` contains the return value. `ldaddr`/`load_membase`/`store_membase_reg` is the sequence for LMF popping.  `mono_spill_global_vars` does this with it:

```
 SPILL BLOCK 4:
 fmove R34 <- R16
         ff  34 16
        0  loadr8_membase R34 <- [%ebp + 0xffffffd4]
        1  nop
 ldaddr R35 <- R10
         ii  35 5
        1  add_imm R35 <- %ebp [-36] clobbers: 1
 load_membase R37 <- [R35 + 0x0]
         ii  37 35
        1  load_membase R37 <- [R35 + 0x0]
 store_membase_reg [R36] <- R37
          ii -1 37
        1  store_membase_reg [%edi] <- R37
 il_seq_point il: 0x2d
             -1
        1  il_seq_point il: 0x2d
```

The local register allocator takes care of the FP stack handling:

```
processing:     0  loadr8_membase %fr0 <- [%ebp + 0xffffffd4]
        [%fr0]
processing:     0  load_membase %eax <- [%ebp + 0xffffffdc]
        [%fr0]
processing:     0  store_membase_reg [%edi] <- %eax
        [%fr0]
processing:     0  il_seq_point il: 0x2d
        [%fr0]
```

At the end of the basic block we have one value left on the FP stack. That's good as we are in the `cfg->bb_exit` basic block, so this is ought to be the return value.

Let's enable `--trace=M:System.Math:Ceiling`. It will insert some code in order to copy arguments/return value to some datastructure that can then be printed by the trace code:

```
processing:     0  loadr8_membase %fr0 <- [%ebp + 0xffffffd4]
        [%fr0]
processing:     0  iconst %eax <- [11116832]
        [%fr0]
processing:     0  iconst %eax <- [52]
        [%fr0]
processing:     0  localloc_imm %eax <-
        [%fr0]
processing:     0  localloc_imm %ecx <-
        [%fr0]
processing:     0  store_membase_reg [%eax + 0x30] <- %ecx
        [%fr0]
processing:     0  x86_lea_membase %edx <- %ebp
        [%fr0]
processing:     0  store_membase_reg [%ecx] <- %edx
        [%fr0]
processing:     0  store_membase_imm [%eax + 0x28] <- [11116832]
        [%fr0]
processing:     0  storer8_membase_reg [%ebp + 0xffffffcc] <- %fr0
        []
processing:     0  x86_lea_membase %ecx <- %ebp
        []
processing:     0  store_membase_reg [%eax + 0x2c] <- %ecx
        []
processing:     0  store_membase_reg [%esp + 0x4] <- %eax
        []
processing:     0  store_membase_imm [%esp] <- [11116832]
        []
processing:     0  voidcall [mono_trace_leave_method] clobbers: c
        []
processing:     0  x86_lea_membase %eax <- %ebp
        []
processing:     0  load_membase %eax <- [%ebp + 0xffffffdc]
        []
processing:     0  store_membase_reg [%edi] <- %eax
        []
processing:     0  il_seq_point il: 0x2d
        []
```

At the very beginning we push some value on the FP stack, same as before. However the code inserted by the tracing code will pop that value. Now, when returning to the, it will pop again something from the FP stack, but alas it's gonna be garbage.

With this PR it looks like this:

```
processing:     0  loadr8_membase %fr0 <- [%ebp + 0xffffffd4]
        [%fr0]
processing:     0  iconst %eax <- [11116832]
        [%fr0]
processing:     0  iconst %eax <- [52]
        [%fr0]
processing:     0  localloc_imm %eax <-
        [%fr0]
processing:     0  localloc_imm %ecx <-
        [%fr0]
processing:     0  store_membase_reg [%eax + 0x30] <- %ecx
        [%fr0]
processing:     0  x86_lea_membase %edx <- %ebp
        [%fr0]
processing:     0  store_membase_reg [%ecx] <- %edx
        [%fr0]
processing:     0  store_membase_imm [%eax + 0x28] <- [11116832]
        [%fr0]
processing:     0  storer8_membase_reg [%ebp + 0xffffffcc] <- %fr0
        []
processing:     0  x86_lea_membase %ecx <- %ebp
        []
processing:     0  store_membase_reg [%eax + 0x2c] <- %ecx
        []
processing:     0  loadr8_membase %fr0 <- [%ebp + 0xffffffcc]
        [%fr0]
processing:     0  store_membase_reg [%esp + 0x4] <- %eax
        [%fr0]
processing:     0  store_membase_imm [%esp] <- [11116832]
        [%fr0]
processing:     0  voidcall [mono_trace_leave_method] clobbers: c
        [%fr0]
processing:     0  x86_lea_membase %eax <- %ebp
        [%fr0]
processing:     0  load_membase %eax <- [%ebp + 0xffffffdc]
        [%fr0]
processing:     0  store_membase_reg [%edi] <- %eax
        [%fr0]
processing:     0  il_seq_point il: 0x2d
        [%fr0]
```

Leaving us the return value on the FP stack before returning.

Fixes https://github.com/mono/mono/issues/16410

Commit migrated from https://github.com/mono/mono/commit/6ebf07f2cd4f71218c6a4a2ed5f855a5ac9ce9e3

4 years agoFix g_assert_not_reached message regression. (mono/mono#17263)
Jay Krell [Thu, 10 Oct 2019 08:26:14 +0000 (01:26 -0700)]
Fix g_assert_not_reached message regression. (mono/mono#17263)

Fix g_assert_not_reached message regression.

Commit migrated from https://github.com/mono/mono/commit/8c5581a6f2190cbfee3c223ef8ccaf84802de041