Compare commits

..
Author SHA1 Message Date
Rodrigo Kumpera c9d9a10ff0 Merge remote-tracking branch 'origin/pr/1908' into HEAD 2015-07-02 14:04:45 -04:00
Alexander Kyte 6ea8bdec15 [runtime] Conversion of a printf to string append for performance 2015-07-01 16:34:20 -04:00
Alexander Kyte 0ab1aa2a78 [runtime] Avoid repeated method hashing in find_aot_module 2015-07-01 16:32:52 -04:00
Alex Rønne Petersen 198235db76 [profiler] Fix missing TYPE_JIT events for alloc/exception/monitor backtraces. 2015-06-05 22:10:07 +02:00
Alexis Christoforides 046a426065 Restore "Fix XAttribute.ToString method (Xamarin-29935)"
The patch is now accepted.
2015-06-05 15:33:58 -04:00
Atsushi Eno 19be22ca00 [xbuild] for resolving assemblies from pkg-config, prefer specified version
... even if SpecificVersion is false. There is no reason to prefer any
mismatching version when SpecificVersion=false.

That behavior caused monodevelop build failures because of incorrectly-
resolved gtk# packages. After this fix, this issue goes away.
https://github.com/mono/monodevelop/blob/2436ad1874694ec811871dacf9a659a79b5fad0d/README.md#known-problems
2015-06-05 14:19:03 -04:00
Miguel de Icaza 02adfce5cf [monop] Band-aid, cope with IKVM's Type.Namespace crashing on generic types
[monop] Add test suite for monop
2015-06-05 14:14:24 -04:00
Rodrigo Kumpera 8019f53849 Bump mono to 4.0.2 2015-06-05 14:14:21 -04:00
Zoltan Varga e967ed4868 [arm64] Increase the size of the thunk area to work around https://bugzilla.xamarin.com/show_bug.cgi?id=28747. 2015-06-05 14:02:47 -04:00
Zoltan Varga 2a0f19e0d2 [jit] Emulate OP_RREM if OP_FREM is emulated. Fixes #30698. 2015-06-03 15:31:48 -04:00
Alexander Kyte ef16e5a45c [runtime] Don't set flag to skip future initialization on half-baked classes 2015-06-03 12:13:20 +02:00
Zoltan Varga c68e6be205 [runtime] Fix the signature of native-func-aot wrappers. AOT the delegate invoke wrapper which is used to invoke it. Fixes #29970. 2015-06-02 19:05:26 -04:00
Sebastien Pouliot fad43d28b9 [corlib] Xamarin.Mac to continue default to the OS default codepage
XM 2.0 was the first version to ship the mobile (w/unified) and it used
the OS default codepage.

The previous, system mono, profile was already using the OS default
codepage so it make sense for XM to be consistent across profiles (
including the 4.5 subset)
2015-06-02 16:53:53 -04:00
Sebastien Pouliot e4510d8546 [corlib] Let XI and XM define their own default encoding [#29928]
605192528d used UTF8Unmarked for MONOTOUCH
and XAMMAC. However it's initialized differently (than the old UTF8) and
caused unit test regressions in System and System.Net.Http unit tests

This new logic moves the default encoding creation into the products
themselves.
2015-06-02 16:53:42 -04:00
Alexis Christoforides a3b2464acb Bump to include xamarin/bockbuild@0669caebbc 2015-06-02 16:02:38 -04:00
Alex Rønne Petersen 0bf88ca938 [profiler] Initialize threads in runtime initialization callback.
For the helper and writer thread to actually work, we need Mono's threading
subsystem to be initialized (so we can use TLS and hazard pointers). We now
wait with starting these threads until Mono gives us the go-ahead.

This means that a bit more data will be buffered up in the thread-local log
buffers during startup, but it shouldn't really matter in practice.
2015-06-02 15:50:15 -04:00
Zoltan Varga 348b0980cd [arm] Fix the handling of callee saved fp registers during unwinding, previously they were saved in an 32 bit array. Fixes #29726. 2015-06-02 15:28:12 -04:00
Zoltan Varga 80c4f56c1c [aot] Avoid duplicate plt symbols for plt entries for synchronized methods. Fixes #28961. 2015-06-02 15:27:14 -04:00
Sebastien Pouliot 955b2d61c9 [linker] Resolve AssemblyName[Reference] when sweeping [#29211]
The exact name (e.g. version) might differ between the original
AssemblyNameReference and the one being used (e.g. PCL).

To make sure we remove unused references we need to resolve
the AssemblyNameReference into AssemblyDefinition and then
continue the sweep based on the _new_ AssemblyNameReference.
2015-06-02 14:58:50 -04:00
Marcos Henrich d64e196394 Merge pull request #1758 from esdrubal/tzdroidfix
[corlib] Fixes DST without AdjustmentRules
2015-05-22 15:52:12 +01:00
Marek Safar ed1d3ec526 [corlib] BinaryReader with Unicode encoding needs to read bytes in a pair. Fixes #30171 2015-05-20 09:55:49 +02:00
Marek Safar 11b58305d0 [runtime] Add more 3.0 fx assemblies to remapping table. Fixes #29459 2015-05-15 15:55:26 -04:00
João Matos ef50e28e6c Merge pull request #1810 from directhex/mono-4.0.0-branch
Add missing Microsoft.Portable.VisualBasic_4.{0,5}.targets to EXTRA_DIST
2015-05-15 13:01:40 +01:00
Jo Shields de778fd998 Add missing Microsoft.Portable.VisualBasic_4.{0,5}.targets to EXTRA_DIST 2015-05-15 12:14:18 +01:00
Alexis Christoforides e308d07968 Bump to include mono/bockbuild@e94f64444d which reverts the nuget bump I mistakenly pushed to the branch. 2015-05-14 15:15:58 -07:00
Rodrigo Kumpera 766c45cacf Merge pull request #1807 from mono/revert-1787-Xamarin-29935
Revert "Fix XAttribute.ToString method (Xamarin-29935)"
2015-05-14 18:08:44 -04:00
Rodrigo Kumpera 00bd897cd6 Revert "Fix XAttribute.ToString method (Xamarin-29935)" 2015-05-14 18:07:21 -04:00
Atsushi Eno bee689faf9 Merge pull request #1787 from ermshiperete/Xamarin-29935
Fix XAttribute.ToString method (Xamarin-29935)
2015-05-15 02:54:40 +08:00
jaredpar 6d5afc17fc Improve Visual Basic build support
This fixes a couple of small issues with the Visual Basic build support:

- The VBC task now respects the $(NoStdLib) MSBuild option.
- The field @(ReferencePath) should be used for References in the VBC
target as it is for the CSC target.
- The CreateVisualBasicManifestResourceNames task is compiled and used
in the same manner as CreateCSharpManifestResourceNames hence it should
be loaded via UsingTask in the same manner as well.
- Include the VisualBasic Portable targets files.
2015-05-14 14:23:27 +02:00
Alan McGovern 888a961d27 Trigger a build 2015-05-14 08:20:25 +01:00
Zoltan Varga d17c251d93 [runtime] Fix the initialization of the pid array in ves_icall_System_Diagnostics_Process_GetProcesses_internal (). 2015-05-14 03:32:38 +02:00
Alexis Christoforides 83c226b78f Bump to include mono/bockbuild@78924fd36e. Fixes 29898 2015-05-13 10:31:23 -07:00
Marek Safar 79dbfbec17 [system.runtime.caching] Remove inappropropriate use of Marshal.SizeOf. Fixes #29667 2015-05-11 20:10:50 +02:00
Eberhard Beilharz 58acbf1239 Fix XAttribute.ToString method (Xamarin-29935)
This fix is more or less copied over from Microsoft's referencesource
implementation.

Change-Id: Icdb5979bd1b274afc5ee3a27f07db5ef64eb94aa
2015-05-11 15:13:04 +02:00
Eberhard Beilharz ec0d27cbc3 Unit test that demonstrates Xamarin-29935
Change-Id: I3510a2ccb897e0a0baf03af3a34bb74d6b700e03
2015-05-11 15:13:01 +02:00
Neale Ferguson d7f9ffaa25 Fix decimal comparison by using signed char comparison of signs; Fix size of jmp instruction sequence 2015-05-08 13:24:08 -04:00
Rolf Bjarne Kvinge f80248053d Add a monotouch_runtime corlib sources. 2015-05-06 17:52:29 -04:00
Zoltan Varga c06ccca9b4 [jit] Correctly disable seq points in wrappers on android. 2015-05-06 15:05:32 -04:00
Zoltan Varga 88674ce963 [sdb] Transition from step over to step into when control leaves managed code. Fixes #28557. 2015-05-06 15:03:37 -04:00
Mark Probst e280710722 [sgen] Check SP on thread suspend correctly. Fixes #29177. 2015-05-05 16:51:49 -04:00
Marcos Henrich f14352027e [corlib] Fixes DST without AdjustmentRules.
Fixes IsDaylightSavingTime returning false when
SupportsDaylightSavingTime was set to false because TimeZoneInfo was
create with no AdjustmentRules.

Now if TimeZoneInfo uses transitions SupportsDaylightSavingTime will be
set to true regardless of AdjustmentRules.
2015-05-04 14:30:50 +01:00
Sebastien Pouliot 5a0b19f1a1 [linker] Mark SecurityDeclarations [#28918]
Security declarations looks very similar to custom attributes - but
they are not (e.g. a different metadata table).

They need to be marked, just like other metadata, by the linker because
they can encode types that won't show up in the type (or assembly)
references.

Ignoring this can create an invalid binary (the kind that even Cecil
can't load back for further processing).
2015-05-01 13:45:09 +02:00
Zoltan Varga ed6b20ecc8 [jit] Increase some trampoline sizes. 2015-04-29 17:24:05 -04:00
Alex Rønne Petersen f5bd8428e3 [utils] Fix yet more visibility issues. 2015-04-29 18:03:55 +02:00
Alex Rønne Petersen 72e497f232 [mini] Fix visibility of mono_aot_get_method (). 2015-04-29 18:03:55 +02:00
Rolf Bjarne Kvinge 77adc2a461 [runtime] Don't call mach_port_deallocate on tasks we don't own.
Fixes random/strange hangs/crashes (many native API starts returning
out-of-memory errors when there is plenty of memory available, other
just hang inexplicably) when profiling.
2015-04-29 16:53:28 +01:00
Ludovic Henry d5acd37572 [runtime] Fix call to task_for_pid in proclib utils
task_for_pid requires special privileges on osx 10.5+ and ios, so it's better to avoid calling it.
2015-04-29 16:53:19 +01:00
João Matos e5678fa983 [aot] Improve error checking when setting up class vtable.
Fixes https://bugzilla.xamarin.com/show_bug.cgi?id=28816.
2015-04-29 16:35:11 +01:00
Zoltan Varga 9476d562d9 [jit] Use the same dwarf<->hw register mapping on x86 for both LLVM and jitted code, the one used by LLVM is the official version.
Cherry-pick of https://github.com/mono/mono/commit/2cab68d28c574320f6927b6677b4e3ea213b2e20.
2015-04-29 16:22:10 +01:00
Alex Rønne Petersen c110da5dc6 [mini] Expose mono_aot_get_method () as an API-unstable function.
This will be used by the profiler.
2015-04-29 16:34:19 +02:00
Alex Rønne Petersen 44ba74f134 [mini] Expose an API-unstable mono_get_jit_info_from_method () function.
This will be used by the profiler.

Conflicts:

	mono/mini/mini-runtime.c
2015-04-29 16:34:04 +02:00
Alex Rønne Petersen 0424c0e425 [profiler] Disable perf events by default.
As it turns out, `perf` support crashes/hangs on a lot of Linux
kernels in the wild, and produces no output on some Android devices.
So, given that using a signal + helper thread is more reliable, use
it by default and make `perf` support optional.

The configure flag is now `--enable-perf-events`.
2015-04-29 10:45:01 +02:00
Alex Rønne Petersen 145bf1a485 [profiler] Avoid a slow path in mono_jit_info_table_find (). 2015-04-29 10:44:56 +02:00
Alex Rønne Petersen 5b658b5c72 [profiler] Really fix looking up JIT info for AOT'd methods.
mono_aot_get_method () will not necessarily put methods into the
MonoDomain::jit_code_hash table. But it does return an IP that we
can use to look up the JIT info with mono_jit_info_table_find ().
2015-04-29 10:44:48 +02:00
Alex Rønne Petersen f81d1dba42 [profiler] Fix finding methods in other domains than the current one.
In certain cross-domain scenarios, the method we're executing
is not necessarily emitted in the current domain. So we need
to scan all domains for it.
2015-04-29 10:44:39 +02:00
Alex Rønne Petersen e01c79dffd [profiler] Redesign buffer flushing and method reporting.
The main goal of this change is to ensure that all methods have a `TYPE_JIT`
event emitted in the stream before they are referenced in other events. Before
this change, `TYPE_JIT` events could arrive out of order or not be emitted at
all because of generic sharing.

We now use a separate thread for writing log buffers to the output file.
Whenever a method is referenced in a TLS log buffer, we add it to a TLS list of
methods. When we ship the TLS log buffer off to the writer thread, we also send
the TLS list of methods. The writer thread first goes over all the methods and,
if some of them haven't had a `TYPE_JIT` event emitted yet, emits them to a
temporary buffer which is flushed just before flushing the main log buffer.

This approach ensures that `TYPE_JIT` events will *always* come before the
events that reference them.

Bookkeeping of which methods have been emitted to the output stream is done in
a global, concurrent hash table. Before a thread adds a method to its TLS list
of methods, it checks if the method is in the hash table. If it is, we know
that the method has already been emitted to the output stream, so it isn't
added to the list. The writer thread is the only thread that updates the hash
table (which happens when it flushes the temporary method buffer). So,
eventually, all TLS method lists will end up being empty because all methods
have been emitted to the output stream.
2015-04-29 10:44:31 +02:00
Zoltan Varga 373d684397 Fix the mobile build. 2015-04-28 15:58:47 -04:00
Zoltan Varga 735f5b3ee8 [runtime] Fix the non-msvc build. 2015-04-27 16:08:47 -04:00
Zoltan Varga feb16e4022 [jit] Disable deadce in the liveness2 pass as well when compiling for sdb. Fixes #28847. 2015-04-27 15:20:01 -04:00
Alex Rønne Petersen 436c5d2e57 [mini] Fix intrinsic signature checks to take into account the 'this' parameter. 2015-04-27 15:11:40 -04:00
Zoltan Varga d0620f1ab5 [runtime] Fix freeing invalid memory in CreateProcess () if the executable was not found. Fixes #28209. 2015-04-27 15:00:45 -04:00
Alexis Christoforides 3a6e855647 [DataContractJsonSerializer] Allow abstract base classes in lists. Fixes #26998
Abstract classes can still have subclasses with KnownType attributes, which are allowed in deserialization.

This used to work as the '__type' hint  was always honored no matter the type, and broke with https://github.com/mono/mono/commit/71e152accc727089faffa6b4fd6bf58cb62636cf which removed that behavior.
2015-04-27 12:17:31 -04:00
Marek Safar 5521f11004 [corlib] First specific culture returned by enumerator was not fully initialized. Fixes #29039 2015-04-27 16:43:41 +02:00
Marek Safar 1513f8f827 Merge pull request #1727 from esdrubal/mono-4.0.0-branch
[System.Xml] Fixed DateTime parsing of Xml strings
2015-04-27 16:35:26 +02:00
Miguel de Icaza 7975f5090d Update version 2015-04-26 09:00:31 -04:00
Marek Safar 1aa57ef746 [corlib] Add DefaultDllImportSearchPathsAttribute 2015-04-25 08:53:19 -04:00
Alexis Christoforides fd35b80bef Bump to bring in xamarin/bockbuild@257a1a8920 2015-04-22 15:20:53 -04:00
Marcos Henrich 71385a445f [System.Xml] Fixed DateTime parsing of Xml strings
System.Xml was failing to parse DateTime serializations such as
"2000-02-29T23:59:59+13:60".
This is caused by using .NET DateTime and still having the old
System.Xml in branch 4.0
This logic is implemented in .NET by XsdDateTime.
Added fallbacks to .NET XsdDateTime (renamed to XsdDateTime2) when our
parser fails.

The fix is specific to mono 4.0. As in mono master we are already using
.NET System.Xml.
2015-04-22 13:27:32 +01:00
Alexis Christoforides c8db1b0fbc Bump to bring in xamarin/bockbuild@42570d260b 2015-04-16 12:52:12 -04:00
65 changed files with 1838 additions and 284 deletions

No files matched your search

+5 -5
View File
@@ -1,7 +1,7 @@
# Process this file with autoconf to produce a configure script.
#AC_PREREQ([2.62])
AC_INIT(mono, [4.0.0],
AC_INIT(mono, [4.0.2],
[http://bugzilla.xamarin.com/enter_bug.cgi?classification=Mono])
AC_CONFIG_SRCDIR([README.md])
@@ -2521,10 +2521,10 @@ fi
AC_ARG_ENABLE(bcl-opt, [ --disable-bcl-opt BCL is compiled with no optimizations (allows accurate BCL debugging)], test_bcl_opt=$enableval, test_bcl_opt=yes)
AC_ARG_ENABLE(perf-events, [ --disable-perf-events Disable using `perf` for profiling on Linux], test_perf_events=$enableval, test_perf_events=yes)
if test "x$test_perf_events" != "xyes"; then
AC_DEFINE(DISABLE_PERF_EVENTS, 1, [Disable using `perf` for profiling on Linux])
AC_SUBST(DISABLE_PERF_EVENTS)
AC_ARG_ENABLE(perf-events, [ --enable-perf-events Enable using `perf` for profiling on Linux], test_perf_events=$enableval, test_perf_events=no)
if test "x$test_perf_events" == "xyes"; then
AC_DEFINE(ENABLE_PERF_EVENTS, 1, [Enable using `perf` for profiling on Linux])
AC_SUBST(ENABLE_PERF_EVENTS)
fi
AC_MSG_CHECKING([if big-arrays are to be enabled])
@@ -256,9 +256,8 @@ namespace Microsoft.Build.Tasks {
{
PackageAssemblyInfo pkg = null;
if (specific_version) {
pkg = PcCache.GetAssemblyLocation (reference.ItemSpec);
} else {
pkg = PcCache.GetAssemblyLocation (reference.ItemSpec);
if (pkg == null && !specific_version) {
// if not specific version, then just match simple name
string name = reference.ItemSpec;
if (name.IndexOf (',') > 0)
@@ -73,6 +73,8 @@ namespace Microsoft.Build.Tasks {
commandLine.AppendSwitchIfNotNull ("/main:", MainEntryPoint);
// NoStandardLib
if (Bag ["NoStandardLib"] != null && NoStandardLib)
commandLine.AppendSwitch ("/nostdlib");
if (NoWarnings)
commandLine.AppendSwitch ("/nowarn");
@@ -11,14 +11,17 @@ namespace System.Runtime.Caching {
*/
internal class SRef {
private Object _sizedRef;
// private Object _sizedRef;
internal SRef (Object target) {
_sizedRef = target;
// _sizedRef = target;
}
internal long ApproximateSize {
get { return (long) Marshal.SizeOf (_sizedRef.GetType ()); }
get {
// TODO: .net uses System.SizedReference which contains approximate size after Gen 2 collection
return 16;
}
}
internal void Dispose() {
@@ -353,8 +353,7 @@ namespace System.Runtime.Serialization.Json
for (reader.MoveToContent (); reader.NodeType != XmlNodeType.EndElement; reader.MoveToContent ()) {
if (!reader.IsStartElement ("item"))
throw SerializationError (String.Format ("Expected element 'item', but found '{0}' in namespace '{1}'", reader.LocalName, reader.NamespaceURI));
Type et = elementType == typeof (object) || elementType.IsAbstract ? null : elementType;
object elem = ReadObject (et ?? typeof (object));
object elem = ReadObject (elementType);
c.Add (elem);
}
#if NET_2_1
@@ -2,6 +2,8 @@ Assembly/AssemblyInfo.cs
../../build/common/Consts.cs
../../build/common/Locale.cs
../../build/common/MonoTODOAttribute.cs
../../../external/referencesource/System.Xml/System/Xml/Bits.cs
System.Xml/XsdDateTime2.cs
Mono.Xml.Schema/XmlSchemaValidatingReader.cs
Mono.Xml.Schema/XsdIdentityPath.cs
Mono.Xml.Schema/XsdIdentityState.cs
+40 -4
View File
@@ -290,7 +290,16 @@ namespace System.Xml {
//return DateTime.Parse(s, d);
DateTimeStyles style = DateTimeStyles.AllowLeadingWhite |
DateTimeStyles.AllowTrailingWhite;
return DateTime.ParseExact (s, format, DateTimeFormatInfo.InvariantInfo, style);
try {
return DateTime.ParseExact (s, format, DateTimeFormatInfo.InvariantInfo, style);
} catch (Exception e) {
try {
var xsdDateTime = new XsdDateTime2 (s, XsdDateTimeFlags.AllXsd);
return (DateTime) xsdDateTime;
} catch {
throw e;
}
}
}
public static DateTime ToDateTime(string s, string[] formats)
@@ -304,6 +313,13 @@ namespace System.Xml {
return DateTime.ParseExact (s, formats, DateTimeFormatInfo.InvariantInfo, style);
} catch (ArgumentOutOfRangeException) {
return DateTime.MinValue;
} catch (Exception e) {
try {
var xsdDateTime = new XsdDateTime2 (s, XsdDateTimeFlags.AllXsd);
return (DateTime) xsdDateTime;
} catch {
throw e;
}
}
}
@@ -781,15 +797,35 @@ namespace System.Xml {
public static DateTimeOffset ToDateTimeOffset (string s, string format)
{
return DateTimeOffset.ParseExact (s, format, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal);
try {
return DateTimeOffset.ParseExact (s, format, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal);
} catch (Exception e) {
try {
var xsdDateTime = new XsdDateTime2 (s, XsdDateTimeFlags.AllXsd);
return (DateTimeOffset) xsdDateTime;
} catch {
throw e;
}
}
}
public static DateTimeOffset ToDateTimeOffset (string s, string [] formats)
{
DateTimeStyles style = DateTimeStyles.AllowLeadingWhite |
try {
DateTimeStyles style = DateTimeStyles.AllowLeadingWhite |
DateTimeStyles.AllowTrailingWhite |
DateTimeStyles.AssumeUniversal;
return DateTimeOffset.ParseExact (s, formats, CultureInfo.InvariantCulture, style);
return DateTimeOffset.ParseExact (s, formats, CultureInfo.InvariantCulture, style);
} catch (Exception e) {
try {
var xsdDateTime = new XsdDateTime2 (s, XsdDateTimeFlags.AllXsd);
return (DateTimeOffset) xsdDateTime;
} catch {
throw e;
}
}
}
public static string ToString (DateTimeOffset value)
@@ -0,0 +1,993 @@
//------------------------------------------------------------------------------
// <copyright file="XsdDuration.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// <owner current="true" primary="true">[....]</owner>
//------------------------------------------------------------------------------
namespace System.Xml.Schema {
using System;
using System.Xml;
using System.Diagnostics;
using System.Text;
/// <summary>
/// This enum specifies what format should be used when converting string to XsdDateTime
/// </summary>
[Flags]
internal enum XsdDateTimeFlags {
DateTime = 0x01,
Time = 0x02,
Date = 0x04,
GYearMonth = 0x08,
GYear = 0x10,
GMonthDay = 0x20,
GDay = 0x40,
GMonth = 0x80,
#if !SILVERLIGHT // XDR is not supported in Silverlight
XdrDateTimeNoTz = 0x100,
XdrDateTime = 0x200,
XdrTimeNoTz = 0x400, //XDRTime with tz is the same as xsd:time
#endif
AllXsd = 0xFF //All still does not include the XDR formats
}
/// <summary>
/// This structure extends System.DateTime to support timeInTicks zone and Gregorian types scomponents of an Xsd Duration. It is used internally to support Xsd durations without loss
/// of fidelity. XsdDuration structures are immutable once they've been created.
/// </summary>
internal struct XsdDateTime2 {
// DateTime is being used as an internal representation only
// Casting XsdDateTime to DateTime might return a different value
private DateTime dt;
// Additional information that DateTime is not preserving
// Information is stored in the following format:
// Bits Info
// 31-24 DateTimeTypeCode
// 23-16 XsdDateTimeKind
// 15-8 Zone Hours
// 7-0 Zone Minutes
private uint extra;
// Subset of XML Schema types XsdDateTime represents
enum DateTimeTypeCode {
DateTime,
Time,
Date,
GYearMonth,
GYear,
GMonthDay,
GDay,
GMonth,
#if !SILVERLIGHT // XDR is not supported in Silverlight
XdrDateTime,
#endif
}
// Internal representation of DateTimeKind
enum XsdDateTimeKind {
Unspecified,
Zulu,
LocalWestOfZulu, // GMT-1..14, N..Y
LocalEastOfZulu // GMT+1..14, A..M
}
// Masks and shifts used for packing and unpacking extra
private const uint TypeMask = 0xFF000000;
private const uint KindMask = 0x00FF0000;
private const uint ZoneHourMask = 0x0000FF00;
private const uint ZoneMinuteMask = 0x000000FF;
private const int TypeShift = 24;
private const int KindShift = 16;
private const int ZoneHourShift = 8;
// Maximum number of fraction digits;
private const short maxFractionDigits = 7;
static readonly int Lzyyyy = "yyyy".Length;
static readonly int Lzyyyy_ = "yyyy-".Length;
static readonly int Lzyyyy_MM = "yyyy-MM".Length;
static readonly int Lzyyyy_MM_ = "yyyy-MM-".Length;
static readonly int Lzyyyy_MM_dd = "yyyy-MM-dd".Length;
static readonly int Lzyyyy_MM_ddT = "yyyy-MM-ddT".Length;
static readonly int LzHH = "HH".Length;
static readonly int LzHH_ = "HH:".Length;
static readonly int LzHH_mm = "HH:mm".Length;
static readonly int LzHH_mm_ = "HH:mm:".Length;
static readonly int LzHH_mm_ss = "HH:mm:ss".Length;
static readonly int Lz_ = "-".Length;
static readonly int Lz_zz = "-zz".Length;
static readonly int Lz_zz_ = "-zz:".Length;
static readonly int Lz_zz_zz = "-zz:zz".Length;
static readonly int Lz__ = "--".Length;
static readonly int Lz__mm = "--MM".Length;
static readonly int Lz__mm_ = "--MM-".Length;
static readonly int Lz__mm__ = "--MM--".Length;
static readonly int Lz__mm_dd = "--MM-dd".Length;
static readonly int Lz___ = "---".Length;
static readonly int Lz___dd = "---dd".Length;
#if !SILVERLIGHT
/// <summary>
/// Constructs an XsdDateTime from a string trying all possible formats.
/// </summary>
public XsdDateTime2(string text) : this(text, XsdDateTimeFlags.AllXsd) {
}
#endif
/// <summary>
/// Constructs an XsdDateTime from a string using specific format.
/// </summary>
public XsdDateTime2(string text, XsdDateTimeFlags kinds) : this() {
Parser parser = new Parser();
if (! parser.Parse(text, kinds)) {
throw new FormatException("Res.GetString(Res.XmlConvert_BadFormat, text, kinds)");
}
InitiateXsdDateTime(parser);
}
#if !SILVERLIGHT
private XsdDateTime2(Parser parser) : this() {
InitiateXsdDateTime(parser);
}
#endif
private void InitiateXsdDateTime(Parser parser) {
dt = new DateTime(parser.year, parser.month, parser.day, parser.hour, parser.minute, parser.second);
if (parser.fraction != 0) {
dt = dt.AddTicks(parser.fraction);
}
extra = (uint)(((int)parser.typeCode << TypeShift) | ((int)parser.kind << KindShift) | (parser.zoneHour << ZoneHourShift) | parser.zoneMinute);
}
#if !SILVERLIGHT
internal static bool TryParse(string text, XsdDateTimeFlags kinds, out XsdDateTime2 result) {
Parser parser = new Parser();
if (! parser.Parse(text, kinds)) {
result = new XsdDateTime2();
return false;
}
result = new XsdDateTime2(parser);
return true;
}
#endif
/// <summary>
/// Constructs an XsdDateTime from a DateTime.
/// </summary>
public XsdDateTime2(DateTime dateTime, XsdDateTimeFlags kinds) {
Debug.Assert(Bits.ExactlyOne((uint)kinds), "Only one DateTime type code can be set.");
dt = dateTime;
DateTimeTypeCode code = (DateTimeTypeCode) (Bits.LeastPosition((uint) kinds) - 1);
int zoneHour = 0;
int zoneMinute = 0;
XsdDateTimeKind kind;
switch (dateTime.Kind) {
case DateTimeKind.Unspecified: kind = XsdDateTimeKind.Unspecified; break;
case DateTimeKind.Utc: kind = XsdDateTimeKind.Zulu; break;
default: {
Debug.Assert(dateTime.Kind == DateTimeKind.Local, "Unknown DateTimeKind: " + dateTime.Kind);
TimeSpan utcOffset = TimeZoneInfo.Local.GetUtcOffset(dateTime);
if (utcOffset.Ticks < 0) {
kind = XsdDateTimeKind.LocalWestOfZulu;
zoneHour = -utcOffset.Hours;
zoneMinute = -utcOffset.Minutes;
}
else {
kind = XsdDateTimeKind.LocalEastOfZulu;
zoneHour = utcOffset.Hours;
zoneMinute = utcOffset.Minutes;
}
break;
}
}
extra = (uint)(((int)code << TypeShift) | ((int)kind << KindShift) | (zoneHour << ZoneHourShift) | zoneMinute);
}
// Constructs an XsdDateTime from a DateTimeOffset
public XsdDateTime2(DateTimeOffset dateTimeOffset) : this(dateTimeOffset, XsdDateTimeFlags.DateTime) {
}
public XsdDateTime2(DateTimeOffset dateTimeOffset, XsdDateTimeFlags kinds) {
Debug.Assert(Bits.ExactlyOne((uint)kinds), "Only one DateTime type code can be set.");
dt = dateTimeOffset.DateTime;
TimeSpan zoneOffset = dateTimeOffset.Offset;
DateTimeTypeCode code = (DateTimeTypeCode) (Bits.LeastPosition((uint) kinds) - 1);
XsdDateTimeKind kind;
if (zoneOffset.TotalMinutes < 0) {
zoneOffset = zoneOffset.Negate();
kind = XsdDateTimeKind.LocalWestOfZulu;
}
else if (zoneOffset.TotalMinutes > 0) {
kind = XsdDateTimeKind.LocalEastOfZulu;
}
else {
kind = XsdDateTimeKind.Zulu;
}
extra = (uint)(((int)code << TypeShift) | ((int)kind << KindShift) | (zoneOffset.Hours << ZoneHourShift) | zoneOffset.Minutes);
}
/// <summary>
/// Returns auxiliary enumeration of XSD date type
/// </summary>
private DateTimeTypeCode InternalTypeCode {
get { return (DateTimeTypeCode)((extra & TypeMask) >> TypeShift); }
}
/// <summary>
/// Returns geographical "position" of the value
/// </summary>
private XsdDateTimeKind InternalKind {
get { return (XsdDateTimeKind)((extra & KindMask) >> KindShift); }
}
#if !SILVERLIGHT
/// <summary>
/// Returns XmlTypeCode of the value being stored
/// </summary>
public XmlTypeCode TypeCode {
get { return typeCodes[(int)InternalTypeCode]; }
}
/// <summary>
/// Returns whether object represent local, UTC or unspecified time
/// </summary>
public DateTimeKind Kind {
get {
switch (InternalKind) {
case XsdDateTimeKind.Unspecified:
return DateTimeKind.Unspecified;
case XsdDateTimeKind.Zulu:
return DateTimeKind.Utc;
default:
// XsdDateTimeKind.LocalEastOfZulu:
// XsdDateTimeKind.LocalWestOfZulu:
return DateTimeKind.Local;
}
}
}
#endif
/// <summary>
/// Returns the year part of XsdDateTime
/// The returned value is integer between 1 and 9999
/// </summary>
public int Year {
get { return dt.Year; }
}
/// <summary>
/// Returns the month part of XsdDateTime
/// The returned value is integer between 1 and 12
/// </summary>
public int Month {
get { return dt.Month; }
}
/// <summary>
/// Returns the day of the month part of XsdDateTime
/// The returned value is integer between 1 and 31
/// </summary>
public int Day {
get { return dt.Day; }
}
/// <summary>
/// Returns the hour part of XsdDateTime
/// The returned value is integer between 0 and 23
/// </summary>
public int Hour {
get { return dt.Hour; }
}
/// <summary>
/// Returns the minute part of XsdDateTime
/// The returned value is integer between 0 and 60
/// </summary>
public int Minute {
get { return dt.Minute; }
}
/// <summary>
/// Returns the second part of XsdDateTime
/// The returned value is integer between 0 and 60
/// </summary>
public int Second {
get { return dt.Second; }
}
/// <summary>
/// Returns number of ticks in the fraction of the second
/// The returned value is integer between 0 and 9999999
/// </summary>
public int Fraction {
get { return (int)(dt.Ticks - new DateTime(dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, dt.Second).Ticks); }
}
/// <summary>
/// Returns the hour part of the time zone
/// The returned value is integer between -13 and 13
/// </summary>
public int ZoneHour {
get {
uint result = (extra & ZoneHourMask) >> ZoneHourShift;
return (int)result;
}
}
/// <summary>
/// Returns the minute part of the time zone
/// The returned value is integer between 0 and 60
/// </summary>
public int ZoneMinute {
get {
uint result = (extra & ZoneMinuteMask);
return (int)result;
}
}
#if !SILVERLIGHT
public DateTime ToZulu() {
switch (InternalKind) {
case XsdDateTimeKind.Zulu:
// set it to UTC
return new DateTime(dt.Ticks, DateTimeKind.Utc);
case XsdDateTimeKind.LocalEastOfZulu:
// Adjust to UTC and then convert to local in the current time zone
return new DateTime(dt.Subtract(new TimeSpan(ZoneHour, ZoneMinute, 0)).Ticks, DateTimeKind.Utc);
case XsdDateTimeKind.LocalWestOfZulu:
// Adjust to UTC and then convert to local in the current time zone
return new DateTime(dt.Add(new TimeSpan(ZoneHour, ZoneMinute, 0)).Ticks, DateTimeKind.Utc);
default:
return dt;
}
}
#endif
/// <summary>
/// Cast to DateTime
/// The following table describes the behaviors of getting the default value
/// when a certain year/month/day values are missing.
///
/// An "X" means that the value exists. And "--" means that value is missing.
///
/// Year Month Day => ResultYear ResultMonth ResultDay Note
///
/// X X X Parsed year Parsed month Parsed day
/// X X -- Parsed Year Parsed month First day If we have year and month, assume the first day of that month.
/// X -- X Parsed year First month Parsed day If the month is missing, assume first month of that year.
/// X -- -- Parsed year First month First day If we have only the year, assume the first day of that year.
///
/// -- X X CurrentYear Parsed month Parsed day If the year is missing, assume the current year.
/// -- X -- CurrentYear Parsed month First day If we have only a month value, assume the current year and current day.
/// -- -- X CurrentYear First month Parsed day If we have only a day value, assume current year and first month.
/// -- -- -- CurrentYear Current month Current day So this means that if the date string only contains time, you will get current date.
/// </summary>
public static implicit operator DateTime(XsdDateTime2 xdt) {
DateTime result;
switch (xdt.InternalTypeCode) {
case DateTimeTypeCode.GMonth:
case DateTimeTypeCode.GDay:
result = new DateTime(DateTime.Now.Year, xdt.Month, xdt.Day);
break;
case DateTimeTypeCode.Time:
//back to DateTime.Now
DateTime currentDateTime = DateTime.Now;
TimeSpan addDiff = new DateTime(currentDateTime.Year, currentDateTime.Month, currentDateTime.Day) - new DateTime(xdt.Year, xdt.Month, xdt.Day);
result = xdt.dt.Add(addDiff);
break;
default:
result = xdt.dt;
break;
}
long ticks;
switch (xdt.InternalKind) {
case XsdDateTimeKind.Zulu:
// set it to UTC
result = new DateTime(result.Ticks, DateTimeKind.Utc);
break;
case XsdDateTimeKind.LocalEastOfZulu:
// Adjust to UTC and then convert to local in the current time zone
ticks = result.Ticks - new TimeSpan(xdt.ZoneHour, xdt.ZoneMinute, 0).Ticks;
if (ticks < DateTime.MinValue.Ticks)
{
// Underflow. Return the DateTime as local time directly
ticks += TimeZoneInfo.Local.GetUtcOffset(result).Ticks;
if (ticks < DateTime.MinValue.Ticks)
ticks = DateTime.MinValue.Ticks;
return new DateTime(ticks, DateTimeKind.Local);
}
result = new DateTime(ticks, DateTimeKind.Utc).ToLocalTime();
break;
case XsdDateTimeKind.LocalWestOfZulu:
// Adjust to UTC and then convert to local in the current time zone
ticks = result.Ticks + new TimeSpan(xdt.ZoneHour, xdt.ZoneMinute, 0).Ticks;
if (ticks > DateTime.MaxValue.Ticks)
{
// Overflow. Return the DateTime as local time directly
ticks += TimeZoneInfo.Local.GetUtcOffset(result).Ticks;
if (ticks > DateTime.MaxValue.Ticks)
ticks = DateTime.MaxValue.Ticks;
return new DateTime(ticks, DateTimeKind.Local);
}
result = new DateTime(ticks, DateTimeKind.Utc).ToLocalTime();
break;
default:
break;
}
return result;
}
public static implicit operator DateTimeOffset(XsdDateTime2 xdt) {
DateTime dt;
switch (xdt.InternalTypeCode) {
case DateTimeTypeCode.GMonth:
case DateTimeTypeCode.GDay:
dt = new DateTime( DateTime.Now.Year, xdt.Month, xdt.Day );
break;
case DateTimeTypeCode.Time:
//back to DateTime.Now
DateTime currentDateTime = DateTime.Now;
TimeSpan addDiff = new DateTime(currentDateTime.Year, currentDateTime.Month, currentDateTime.Day) - new DateTime(xdt.Year, xdt.Month, xdt.Day);
dt = xdt.dt.Add( addDiff );
break;
default:
dt = xdt.dt;
break;
}
DateTimeOffset result;
switch (xdt.InternalKind) {
case XsdDateTimeKind.LocalEastOfZulu:
result = new DateTimeOffset(dt, new TimeSpan(xdt.ZoneHour, xdt.ZoneMinute, 0));
break;
case XsdDateTimeKind.LocalWestOfZulu:
result = new DateTimeOffset(dt, new TimeSpan(-xdt.ZoneHour, -xdt.ZoneMinute, 0));
break;
case XsdDateTimeKind.Zulu:
result = new DateTimeOffset(dt, new TimeSpan( 0 ) );
break;
case XsdDateTimeKind.Unspecified:
default:
result = new DateTimeOffset(dt, TimeZoneInfo.Local.GetUtcOffset(dt));
break;
}
return result;
}
#if !SILVERLIGHT
/// <summary>
/// Compares two DateTime values, returning an integer that indicates
/// their relationship.
/// </summary>
public static int Compare(XsdDateTime2 left, XsdDateTime2 right) {
if (left.extra == right.extra) {
return DateTime.Compare(left.dt, right.dt);
}
else {
// Xsd types should be the same for it to be comparable
if (left.InternalTypeCode != right.InternalTypeCode) {
throw new ArgumentException("Res.GetString(Res.Sch_XsdDateTimeCompare, left.TypeCode, right.TypeCode)");
}
// Convert both to UTC
return DateTime.Compare(left.GetZuluDateTime(), right.GetZuluDateTime());
}
}
// Compares this DateTime to a given object. This method provides an
// implementation of the IComparable interface. The object
// argument must be another DateTime, or otherwise an exception
// occurs. Null is considered less than any instance.
//
// Returns a value less than zero if this object
/// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.CompareTo"]/*' />
public int CompareTo(Object value) {
if (value == null) return 1;
return Compare(this, (XsdDateTime2)value);
}
#endif
/// <summary>
/// Serialization to a string
/// </summary>
public override string ToString() {
StringBuilder sb = new StringBuilder(64);
char[] text;
switch (InternalTypeCode) {
case DateTimeTypeCode.DateTime:
PrintDate(sb);
sb.Append('T');
PrintTime(sb);
break;
case DateTimeTypeCode.Time:
PrintTime(sb);
break;
case DateTimeTypeCode.Date:
PrintDate(sb);
break;
case DateTimeTypeCode.GYearMonth:
text = new char[Lzyyyy_MM];
IntToCharArray(text, 0, Year, 4);
text[Lzyyyy] = '-';
ShortToCharArray(text, Lzyyyy_, Month);
sb.Append(text);
break;
case DateTimeTypeCode.GYear:
text = new char[Lzyyyy];
IntToCharArray(text, 0, Year, 4);
sb.Append(text);
break;
case DateTimeTypeCode.GMonthDay:
text = new char[Lz__mm_dd];
text[0] = '-';
text[Lz_] = '-';
ShortToCharArray(text, Lz__, Month);
text[Lz__mm] = '-';
ShortToCharArray(text, Lz__mm_, Day);
sb.Append(text);
break;
case DateTimeTypeCode.GDay:
text = new char[Lz___dd];
text[0] = '-';
text[Lz_] = '-';
text[Lz__] = '-';
ShortToCharArray(text, Lz___, Day);
sb.Append(text);
break;
case DateTimeTypeCode.GMonth:
text = new char[Lz__mm__];
text[0] = '-';
text[Lz_] = '-';
ShortToCharArray(text, Lz__, Month);
text[Lz__mm] = '-';
text[Lz__mm_] = '-';
sb.Append(text);
break;
}
PrintZone(sb);
return sb.ToString();
}
// Serialize year, month and day
private void PrintDate(StringBuilder sb) {
char[] text = new char[Lzyyyy_MM_dd];
IntToCharArray(text, 0, Year, 4);
text[Lzyyyy] = '-';
ShortToCharArray(text, Lzyyyy_, Month);
text[Lzyyyy_MM] = '-';
ShortToCharArray(text, Lzyyyy_MM_, Day);
sb.Append(text);
}
// Serialize hour, minute, second and fraction
private void PrintTime(StringBuilder sb) {
char[] text = new char[LzHH_mm_ss];
ShortToCharArray(text, 0, Hour);
text[LzHH] = ':';
ShortToCharArray(text, LzHH_, Minute);
text[LzHH_mm] = ':';
ShortToCharArray(text, LzHH_mm_, Second);
sb.Append(text);
int fraction = Fraction;
if (fraction != 0) {
int fractionDigits = maxFractionDigits;
while (fraction % 10 == 0) {
fractionDigits --;
fraction /= 10;
}
text = new char[fractionDigits + 1];
text[0] = '.';
IntToCharArray(text, 1, fraction, fractionDigits);
sb.Append(text);
}
}
// Serialize time zone
private void PrintZone(StringBuilder sb) {
char[] text;
switch (InternalKind) {
case XsdDateTimeKind.Zulu:
sb.Append('Z');
break;
case XsdDateTimeKind.LocalWestOfZulu:
text = new char[Lz_zz_zz];
text[0] = '-';
ShortToCharArray(text, Lz_, ZoneHour);
text[Lz_zz] = ':';
ShortToCharArray(text, Lz_zz_, ZoneMinute);
sb.Append(text);
break;
case XsdDateTimeKind.LocalEastOfZulu:
text = new char[Lz_zz_zz];
text[0] = '+';
ShortToCharArray(text, Lz_, ZoneHour);
text[Lz_zz] = ':';
ShortToCharArray(text, Lz_zz_, ZoneMinute);
sb.Append(text);
break;
default:
// do nothing
break;
}
}
// Serialize integer into character array starting with index [start].
// Number of digits is set by [digits]
private void IntToCharArray(char[] text, int start, int value, int digits) {
while(digits -- != 0) {
text[start + digits] = (char)(value%10 + '0');
value /= 10;
}
}
// Serialize two digit integer into character array starting with index [start].
private void ShortToCharArray(char[] text, int start, int value) {
text[start] = (char)(value/10 + '0');
text[start + 1] = (char)(value%10 + '0');
}
#if !SILVERLIGHT
// Auxiliary for compare.
// Returns UTC DateTime
private DateTime GetZuluDateTime() {
switch (InternalKind) {
case XsdDateTimeKind.Zulu:
return dt;
case XsdDateTimeKind.LocalEastOfZulu:
return dt.Subtract(new TimeSpan(ZoneHour, ZoneMinute, 0));
case XsdDateTimeKind.LocalWestOfZulu:
return dt.Add(new TimeSpan(ZoneHour, ZoneMinute, 0));
default:
return dt.ToUniversalTime();
}
}
#endif
private static readonly XmlTypeCode[] typeCodes = {
XmlTypeCode.DateTime,
XmlTypeCode.Time,
XmlTypeCode.Date,
XmlTypeCode.GYearMonth,
XmlTypeCode.GYear,
XmlTypeCode.GMonthDay,
XmlTypeCode.GDay,
XmlTypeCode.GMonth
};
// Parsing string according to XML schema spec
struct Parser {
private const int leapYear = 1904;
private const int firstMonth = 1;
private const int firstDay = 1;
public DateTimeTypeCode typeCode;
public int year;
public int month;
public int day;
public int hour;
public int minute;
public int second;
public int fraction;
public XsdDateTimeKind kind;
public int zoneHour;
public int zoneMinute;
private string text;
private int length;
public bool Parse(string text, XsdDateTimeFlags kinds) {
this.text = text;
this.length = text.Length;
// Skip leading withitespace
int start = 0;
while(start < length && char.IsWhiteSpace(text[start])) {
start ++;
}
// Choose format starting from the most common and trying not to reparse the same thing too many times
#if !SILVERLIGHT // XDR is not supported in Silverlight
if (Test(kinds, XsdDateTimeFlags.DateTime | XsdDateTimeFlags.Date | XsdDateTimeFlags.XdrDateTime | XsdDateTimeFlags.XdrDateTimeNoTz)) {
#else
if (Test(kinds, XsdDateTimeFlags.DateTime | XsdDateTimeFlags.Date)) {
#endif
if (ParseDate(start)) {
if (Test(kinds, XsdDateTimeFlags.DateTime)) {
if (ParseChar(start + Lzyyyy_MM_dd, 'T') && ParseTimeAndZoneAndWhitespace(start + Lzyyyy_MM_ddT)) {
typeCode = DateTimeTypeCode.DateTime;
return true;
}
}
if (Test(kinds, XsdDateTimeFlags.Date)) {
if (ParseZoneAndWhitespace(start + Lzyyyy_MM_dd)) {
typeCode = DateTimeTypeCode.Date;
return true;
}
}
#if !SILVERLIGHT // XDR is not supported in Silverlight
if (Test(kinds, XsdDateTimeFlags.XdrDateTime)) {
if (ParseZoneAndWhitespace(start + Lzyyyy_MM_dd) || (ParseChar(start + Lzyyyy_MM_dd, 'T') && ParseTimeAndZoneAndWhitespace(start + Lzyyyy_MM_ddT)) ) {
typeCode = DateTimeTypeCode.XdrDateTime;
return true;
}
}
if (Test(kinds, XsdDateTimeFlags.XdrDateTimeNoTz)) {
if (ParseChar(start + Lzyyyy_MM_dd, 'T')) {
if (ParseTimeAndWhitespace(start + Lzyyyy_MM_ddT)) {
typeCode = DateTimeTypeCode.XdrDateTime;
return true;
}
}
else {
typeCode = DateTimeTypeCode.XdrDateTime;
return true;
}
}
#endif
}
}
if (Test(kinds, XsdDateTimeFlags.Time)) {
if (ParseTimeAndZoneAndWhitespace(start)) { //Equivalent to NoCurrentDateDefault on DateTimeStyles while parsing xs:time
year = leapYear;
month = firstMonth;
day = firstDay;
typeCode = DateTimeTypeCode.Time;
return true;
}
}
#if !SILVERLIGHT // XDR is not supported in Silverlight
if (Test(kinds, XsdDateTimeFlags.XdrTimeNoTz)) {
if (ParseTimeAndWhitespace(start)) { //Equivalent to NoCurrentDateDefault on DateTimeStyles while parsing xs:time
year = leapYear;
month = firstMonth;
day = firstDay;
typeCode = DateTimeTypeCode.Time;
return true;
}
}
#endif
if (Test(kinds, XsdDateTimeFlags.GYearMonth | XsdDateTimeFlags.GYear)) {
if (Parse4Dig(start , ref year) && 1 <= year) {
if (Test(kinds, XsdDateTimeFlags.GYearMonth)) {
if (
ParseChar(start + Lzyyyy, '-') &&
Parse2Dig(start + Lzyyyy_, ref month) && 1 <= month && month <= 12 &&
ParseZoneAndWhitespace(start + Lzyyyy_MM)
) {
day = firstDay;
typeCode = DateTimeTypeCode.GYearMonth;
return true;
}
}
if (Test(kinds, XsdDateTimeFlags.GYear)) {
if (ParseZoneAndWhitespace(start + Lzyyyy)) {
month = firstMonth;
day = firstDay;
typeCode = DateTimeTypeCode.GYear;
return true;
}
}
}
}
if (Test(kinds, XsdDateTimeFlags.GMonthDay | XsdDateTimeFlags.GMonth)) {
if (
ParseChar(start , '-') &&
ParseChar(start + Lz_, '-') &&
Parse2Dig(start + Lz__, ref month) && 1 <= month && month <= 12
) {
if (Test(kinds, XsdDateTimeFlags.GMonthDay) && ParseChar(start + Lz__mm, '-')) {
if (
Parse2Dig(start + Lz__mm_, ref day) && 1 <= day && day <= DateTime.DaysInMonth(leapYear, month) &&
ParseZoneAndWhitespace(start + Lz__mm_dd)
) {
year = leapYear;
typeCode = DateTimeTypeCode.GMonthDay;
return true;
}
}
if (Test(kinds, XsdDateTimeFlags.GMonth)) {
if (ParseZoneAndWhitespace(start + Lz__mm) || (ParseChar(start + Lz__mm, '-') && ParseChar(start + Lz__mm_, '-') && ParseZoneAndWhitespace(start + Lz__mm__)) ) {
year = leapYear;
day = firstDay;
typeCode = DateTimeTypeCode.GMonth;
return true;
}
}
}
}
if (Test(kinds, XsdDateTimeFlags.GDay)) {
if (
ParseChar(start , '-') &&
ParseChar(start + Lz_, '-') &&
ParseChar(start + Lz__, '-') &&
Parse2Dig(start + Lz___, ref day) && 1 <= day && day <= DateTime.DaysInMonth(leapYear, firstMonth) &&
ParseZoneAndWhitespace(start + Lz___dd)
) {
year = leapYear;
month = firstMonth;
typeCode = DateTimeTypeCode.GDay;
return true;
}
}
return false;
}
private bool ParseDate(int start) {
return
Parse4Dig(start , ref year) && 1 <= year &&
ParseChar(start + Lzyyyy, '-') &&
Parse2Dig(start + Lzyyyy_, ref month) && 1 <= month && month <= 12 &&
ParseChar(start + Lzyyyy_MM, '-') &&
Parse2Dig(start + Lzyyyy_MM_, ref day) && 1 <= day && day <= DateTime.DaysInMonth(year, month);
}
private bool ParseTimeAndZoneAndWhitespace(int start) {
if (ParseTime(ref start)) {
if (ParseZoneAndWhitespace(start)) {
return true;
}
}
return false;
}
#if !SILVERLIGHT // XDR is not supported in Silverlight
private bool ParseTimeAndWhitespace(int start) {
if (ParseTime(ref start)) {
while(start < length ) {//&& char.IsWhiteSpace(text[start])) {
start ++;
}
return start == length;
}
return false;
}
#endif
static int[] Power10 = new int[maxFractionDigits] {-1, 10, 100, 1000, 10000, 100000, 1000000};
private bool ParseTime(ref int start) {
if (
Parse2Dig(start , ref hour) && hour < 24 &&
ParseChar(start + LzHH, ':') &&
Parse2Dig(start + LzHH_, ref minute) && minute < 60 &&
ParseChar(start + LzHH_mm, ':') &&
Parse2Dig(start + LzHH_mm_, ref second) && second < 60
) {
start += LzHH_mm_ss;
if (ParseChar(start, '.')) {
// Parse factional part of seconds
// We allow any number of digits, but keep only first 7
this.fraction = 0;
int fractionDigits = 0;
int round = 0;
while (++start < length) {
int d = text[start] - '0';
if (9u < (uint) d) { // d < 0 || 9 < d
break;
}
if (fractionDigits < maxFractionDigits) {
this.fraction = (this.fraction * 10) + d;
} else if (fractionDigits == maxFractionDigits) {
if (5 < d) {
round = 1;
} else if (d == 5) {
round = -1;
}
} else if (round < 0 && d != 0) {
round = 1;
}
fractionDigits ++;
}
if (fractionDigits < maxFractionDigits) {
if (fractionDigits == 0) {
return false; // cannot end with .
}
fraction *= Power10[maxFractionDigits - fractionDigits];
} else {
if (round < 0) {
round = fraction & 1;
}
fraction += round;
}
}
return true;
}
// cleanup - conflict with gYear
hour = 0;
return false;
}
private bool ParseZoneAndWhitespace(int start) {
if (start < length) {
char ch = text[start];
if (ch == 'Z' || ch == 'z') {
kind = XsdDateTimeKind.Zulu;
start ++;
}
else if (start + 5 < length) {
if (
Parse2Dig(start + Lz_, ref zoneHour) && zoneHour <= 99 &&
ParseChar(start + Lz_zz, ':') &&
Parse2Dig(start + Lz_zz_, ref zoneMinute) && zoneMinute <= 99
) {
if (ch == '-') {
kind = XsdDateTimeKind.LocalWestOfZulu;
start += Lz_zz_zz;
}
else if (ch == '+') {
kind = XsdDateTimeKind.LocalEastOfZulu;
start += Lz_zz_zz;
}
}
}
}
while(start < length && char.IsWhiteSpace(text[start])) {
start ++;
}
return start == length;
}
private bool Parse4Dig(int start, ref int num) {
if (start + 3 < length) {
int d4 = text[start] - '0';
int d3 = text[start + 1] - '0';
int d2 = text[start + 2] - '0';
int d1 = text[start + 3] - '0';
if (0 <= d4 && d4 < 10 &&
0 <= d3 && d3 < 10 &&
0 <= d2 && d2 < 10 &&
0 <= d1 && d1 < 10
) {
num = ((d4 * 10 + d3) * 10 + d2) * 10 + d1;
return true;
}
}
return false;
}
private bool Parse2Dig(int start, ref int num) {
if (start + 1 < length) {
int d2 = text[start] - '0';
int d1 = text[start + 1] - '0';
if (0 <= d2 && d2 < 10 &&
0 <= d1 && d1 < 10
) {
num = d2 * 10 + d1;
return true;
}
}
return false;
}
private bool ParseChar(int start, char ch) {
return start < length && text[start] == ch;
}
private static bool Test(XsdDateTimeFlags left, XsdDateTimeFlags right) {
return (left & right) != 0;
}
}
}
}
@@ -371,4 +371,6 @@ System.Xml.Serialization/XmlElementEventHandler.cs
System.Xml.Serialization/XmlNodeEventHandler.cs
System.Xml/XQueryConvert.cs
../../../external/referencesource/System.Xml/System/Xml/Bits.cs
System.Xml/XsdDateTime2.cs
@@ -26,6 +26,8 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Text;
using System.Xml;
@@ -334,34 +336,29 @@ namespace System.Xml.Linq
static readonly char [] escapeChars = new char [] {'<', '>', '&', '"', '\r', '\n', '\t'};
private static string GetPrefixOfNamespace (XNamespace ns)
{
string namespaceName = ns.NamespaceName;
if (namespaceName.Length == 0)
return string.Empty;
if (namespaceName == XNamespace.Xml.NamespaceName)
return "xml";
if (namespaceName == XNamespace.Xmlns.NamespaceName)
return "xmlns";
return null;
}
public override string ToString ()
{
StringBuilder sb = new StringBuilder ();
sb.Append (name.ToString ());
sb.Append ("=\"");
int start = 0;
do {
int idx = value.IndexOfAny (escapeChars, start);
if (idx < 0) {
if (start > 0)
sb.Append (value, start, value.Length - start);
else
sb.Append (value);
sb.Append ("\"");
return sb.ToString ();
using (StringWriter sw = new StringWriter (CultureInfo.InvariantCulture)) {
XmlWriterSettings ws = new XmlWriterSettings ();
ws.ConformanceLevel = ConformanceLevel.Fragment;
using (XmlWriter w = XmlWriter.Create (sw, ws)) {
w.WriteAttributeString (GetPrefixOfNamespace (Name.Namespace), Name.LocalName,
Name.NamespaceName, Value);
}
sb.Append (value, start, idx - start);
switch (value [idx]) {
case '&': sb.Append ("&amp;"); break;
case '<': sb.Append ("&lt;"); break;
case '>': sb.Append ("&gt;"); break;
case '"': sb.Append ("&quot;"); break;
case '\r': sb.Append ("&#xD;"); break;
case '\n': sb.Append ("&#xA;"); break;
case '\t': sb.Append ("&#x9;"); break;
}
start = idx + 1;
} while (true);
return sw.ToString ().Trim ();
}
}
}
}
@@ -205,6 +205,14 @@ namespace MonoTests.System.Xml.Linq
Assert.AreEqual ("a=\" &gt;_&lt; \"", a.ToString ());
}
[Test]
public void ToString_Xamarin29935 ()
{
var doc = XDocument.Parse ("<?xml version='1.0' encoding='utf-8'?><lift xmlns:test='http://test.example.com'></lift>");
Assert.AreEqual ("xmlns:test=\"http://test.example.com\"",
doc.Root.Attributes ().Select (s => s.ToString ()).First ());
}
[Test]
public void DateTimeAttribute ()
{
@@ -417,11 +417,12 @@ namespace System.Globalization
// The runtime returns a NULL in the first position of the array when
// 'neutral' is true. We fill it in with a clone of InvariantCulture
// since it must not be read-only
int i = 0;
if (neutral && infos.Length > 0 && infos [0] == null) {
infos [0] = (CultureInfo) InvariantCulture.Clone ();
infos [i++] = (CultureInfo) InvariantCulture.Clone ();
}
for (int i = 1; i < infos.Length; ++i) {
for (; i < infos.Length; ++i) {
var ci = infos [i];
infos [i].m_cultureData = CultureData.GetCultureData (ci.m_name, false, ci.datetime_index, ci.CalendarType, ci.iso2lang);
}
@@ -253,6 +253,13 @@ namespace System.IO {
m_buffer [pos ++] = (byte)read_byte;
bytes_read ++;
if (m_encoding is UnicodeEncoding) {
CheckBuffer (pos + 1);
read_byte = m_stream.ReadByte();
if (read_byte != -1) {
m_buffer [pos++] = (byte)read_byte;
}
}
int n = m_encoding.GetChars (m_buffer, 0, pos, buffer, index + chars_read);
if (n > 0)
@@ -0,0 +1,42 @@
//
// DefaultDllImportSearchPathsAttribute.cs
//
// Authors:
// Marek Safar <[email protected]>
//
// Copyright (C) 2015 Xamarin Inc (http://www.xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace System.Runtime.InteropServices
{
[AttributeUsage (AttributeTargets.Assembly | AttributeTargets.Method, AllowMultiple = false)]
[System.Runtime.InteropServices.ComVisible (false)]
public sealed class DefaultDllImportSearchPathsAttribute : Attribute
{
public DefaultDllImportSearchPathsAttribute(DllImportSearchPath paths)
{
Paths = paths;
}
public DllImportSearchPath Paths { get; private set; }
}
}
@@ -0,0 +1,42 @@
//
// DllImportSearchPath.cs
//
// Authors:
// Marek Safar <[email protected]>
//
// Copyright (C) 2015 Xamarin Inc (http://www.xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace System.Runtime.InteropServices
{
[Flags]
public enum DllImportSearchPath
{
UseDllDirectoryForDependencies = 0x100,
ApplicationDirectory = 0x200,
UserDirectories = 0x400,
System32 = 0x800,
SafeDirectories = 0x1000,
AssemblyDirectory = 0x2,
LegacyBehavior = 0x0
}
}
@@ -7,7 +7,7 @@ using System.Security;
namespace System.Text
{
internal static class EncodingHelper
internal static partial class EncodingHelper
{
//
// Only internal, to be used by the class libraries: Unmarked and non-input-validating
@@ -71,6 +71,7 @@ internal static class EncodingHelper
[MethodImpl (MethodImplOptions.InternalCall)]
extern internal static string InternalCodePage (ref int code_page);
#if !MONOTOUCH
internal static Encoding GetDefaultEncoding ()
{
Encoding enc = null;
@@ -105,6 +106,7 @@ internal static class EncodingHelper
}
return enc;
}
#endif
// Loaded copy of the "I18N" assembly. We need to move
// this into a class in "System.Private" eventually.
+4 -2
View File
@@ -592,7 +592,7 @@ namespace System
public AdjustmentRule [] GetAdjustmentRules ()
{
if (!supportsDaylightSavingTime)
if (!supportsDaylightSavingTime || adjustmentRules == null)
return new AdjustmentRule [0];
else
return (AdjustmentRule []) adjustmentRules.Clone ();
@@ -1254,8 +1254,10 @@ namespace System
tz = CreateCustomTimeZone (id, baseUtcOffset, id, standardDisplayName, daylightDisplayName, ValidateRules (adjustmentRules).ToArray ());
}
if (storeTransition)
if (storeTransition && transitions.Count > 0) {
tz.transitions = transitions;
tz.supportsDaylightSavingTime = true;
}
return tz;
}
@@ -225,6 +225,15 @@ namespace MonoTests.System.Globalization
Assert.Fail ("InvariantCulture not found in the array from GetCultures()");
}
[Test]
public void GetAllCultures_Specific ()
{
CultureInfo [] infos = CultureInfo.GetCultures (CultureTypes.SpecificCultures);
foreach (CultureInfo ci in infos) {
Assert.IsNotNull (ci.DateTimeFormat);
}
}
[Test]
#if !NET_4_0
[ExpectedException (typeof (NotSupportedException))]
@@ -274,6 +274,20 @@ namespace MonoTests.System.IO
}
}
[Test]
public void TestReadUnicode ()
{
char testChar1 = 'H';
using (var stream = new MemoryStream())
using (var writer = new BinaryWriter(stream, Encoding.Unicode, true))
using (var reader = new BinaryReader(stream, Encoding.Unicode))
{
writer.Write(testChar1);
stream.Position = 0;
Assert.AreEqual ('H', reader.ReadChar ());
}
}
//-TODO: (TestRead[Type]*) Verify the ReadBoolean, ReadByte ....
// ReadBoolean, ReadByte, ReadChar, ReadInt32 Done
+2
View File
@@ -607,6 +607,8 @@ System.Runtime.InteropServices/CONNECTDATA.cs
System.Runtime.InteropServices/CriticalHandle.cs
System.Runtime.InteropServices/CurrencyWrapper.cs
System.Runtime.InteropServices/DefaultCharSetAttribute.cs
System.Runtime.InteropServices/DllImportSearchPath.cs
System.Runtime.InteropServices/DefaultDllImportSearchPathsAttribute.cs
System.Runtime.InteropServices/DESCKIND.cs
System.Runtime.InteropServices/DispatchWrapper.cs
System.Runtime.InteropServices/DISPPARAMS.cs
@@ -0,0 +1 @@
#include corlib.dll.sources
+76 -15
View File
@@ -204,18 +204,72 @@ namespace Mono.Linker.Steps {
MarkCustomAttributeFields (ca, type);
}
void MarkCustomAttributeProperties (CustomAttribute ca, TypeDefinition attribute)
protected void MarkSecurityDeclarations (ISecurityDeclarationProvider provider)
{
// most security declarations are removed (if linked) but user code might still have some
// and if the attribtues references types then they need to be marked too
if ((provider == null) || !provider.HasSecurityDeclarations)
return;
foreach (var sd in provider.SecurityDeclarations)
MarkSecurityDeclaration (sd);
}
protected virtual void MarkSecurityDeclaration (SecurityDeclaration sd)
{
if (!sd.HasSecurityAttributes)
return;
foreach (var sa in sd.SecurityAttributes)
MarkSecurityAttribute (sa);
}
protected virtual void MarkSecurityAttribute (SecurityAttribute sa)
{
TypeReference security_type = sa.AttributeType;
TypeDefinition type = security_type.Resolve ();
if (type == null)
throw new ResolutionException (security_type);
MarkType (security_type);
MarkSecurityAttributeProperties (sa, type);
MarkSecurityAttributeFields (sa, type);
}
protected void MarkSecurityAttributeProperties (SecurityAttribute sa, TypeDefinition attribute)
{
if (!sa.HasProperties)
return;
foreach (var named_argument in sa.Properties)
MarkCustomAttributeProperty (named_argument, attribute);
}
protected void MarkSecurityAttributeFields (SecurityAttribute sa, TypeDefinition attribute)
{
if (!sa.HasFields)
return;
foreach (var named_argument in sa.Fields)
MarkCustomAttributeField (named_argument, attribute);
}
protected void MarkCustomAttributeProperties (CustomAttribute ca, TypeDefinition attribute)
{
if (!ca.HasProperties)
return;
foreach (var named_argument in ca.Properties) {
PropertyDefinition property = GetProperty (attribute, named_argument.Name);
if (property != null)
MarkMethod (property.SetMethod);
foreach (var named_argument in ca.Properties)
MarkCustomAttributeProperty (named_argument, attribute);
}
MarkIfType (named_argument.Argument);
}
protected void MarkCustomAttributeProperty (CustomAttributeNamedArgument namedArgument, TypeDefinition attribute)
{
PropertyDefinition property = GetProperty (attribute, namedArgument.Name);
if (property != null)
MarkMethod (property.SetMethod);
MarkIfType (namedArgument.Argument);
}
PropertyDefinition GetProperty (TypeDefinition type, string propertyname)
@@ -231,18 +285,22 @@ namespace Mono.Linker.Steps {
return null;
}
void MarkCustomAttributeFields (CustomAttribute ca, TypeDefinition attribute)
protected void MarkCustomAttributeFields (CustomAttribute ca, TypeDefinition attribute)
{
if (!ca.HasFields)
return;
foreach (var named_argument in ca.Fields) {
FieldDefinition field = GetField (attribute, named_argument.Name);
if (field != null)
MarkField (field);
foreach (var named_argument in ca.Fields)
MarkCustomAttributeField (named_argument, attribute);
}
MarkIfType (named_argument.Argument);
}
protected void MarkCustomAttributeField (CustomAttributeNamedArgument namedArgument, TypeDefinition attribute)
{
FieldDefinition field = GetField (attribute, namedArgument.Name);
if (field != null)
MarkField (field);
MarkIfType (namedArgument.Argument);
}
FieldDefinition GetField (TypeDefinition type, string fieldname)
@@ -306,7 +364,7 @@ namespace Mono.Linker.Steps {
return false;
}
void MarkAssembly (AssemblyDefinition assembly)
protected void MarkAssembly (AssemblyDefinition assembly)
{
if (CheckProcessed (assembly))
return;
@@ -314,6 +372,7 @@ namespace Mono.Linker.Steps {
ProcessModule (assembly);
MarkCustomAttributes (assembly);
MarkSecurityDeclarations (assembly);
foreach (ModuleDefinition module in assembly.Modules)
MarkCustomAttributes (module);
@@ -412,6 +471,7 @@ namespace Mono.Linker.Steps {
MarkType (type.BaseType);
MarkType (type.DeclaringType);
MarkCustomAttributes (type);
MarkSecurityDeclarations (type);
if (IsMulticastDelegate (type)) {
MarkMethodCollection (type.Methods);
@@ -845,6 +905,7 @@ namespace Mono.Linker.Steps {
MarkType (method.DeclaringType);
MarkCustomAttributes (method);
MarkSecurityDeclarations (method);
MarkGenericParameterProvider (method);
@@ -100,7 +100,8 @@ namespace Mono.Linker.Steps {
var references = assembly.MainModule.AssemblyReferences;
for (int i = 0; i < references.Count; i++) {
var reference = references [i];
if (!AreSameReference (reference, target.Name))
var r = Context.Resolver.Resolve (reference);
if (!AreSameReference (r.Name, target.Name))
continue;
references.RemoveAt (i);
+6
View File
@@ -8,3 +8,9 @@ LOCAL_MCS_FLAGS += -d:NO_AUTHENTICODE,STATIC,NO_SYMBOL_WRITER
CLEAN_FILES = monop.exe monop2.exe *.mdb
include ../../build/executable.make
run-test-local : basic-tests
basic-tests:
for type in System.Array System.String 'System.Collections.Generic.List`1'; do \
echo $$type; $(RUNTIME) $(build_lib) $$type >/dev/null || exit 1; done
+7 -6
View File
@@ -301,10 +301,10 @@ class MonoP {
static Options options = new Options ();
static void Main (string [] args)
static int Main (string [] args)
{
if (!options.ProcessArgs (args))
return;
return 1;
if (options.Style == null)
mscorlib = universe.LoadFile (typeof (int).Assembly.Location);
@@ -318,14 +318,14 @@ class MonoP {
if (options.ShowAll){
ShowAll (assembly, options.ShowPrivate, options.FilterObsolete);
return;
return 0;
} else {
if (options.Type == null) {
if (options.PrintRefs)
PrintRefs (assembly);
else
PrintTypes (assembly, options.ShowPrivate, options.FilterObsolete);
return;
return 0;
}
}
}
@@ -348,7 +348,7 @@ class MonoP {
if (count > 1){
Console.WriteLine ("Found " + count + " types that match:");
Console.WriteLine (matches);
return;
return 0;
}
}
@@ -394,7 +394,7 @@ class MonoP {
notfound:
if (t == null) {
Console.WriteLine ("Could not find {0}", tname);
return;
return 1;
}
found:
//
@@ -406,6 +406,7 @@ class MonoP {
if (message != null)
Console.WriteLine (message);
return 0;
}
}
+16 -2
View File
@@ -42,6 +42,19 @@ using System.Reflection;
#endif
namespace Mono.CSharp {
public static class TypeExtensions {
public static string GetNamespace (this Type t)
{
// IKVM crashes here with a null ref sometimes
try {
return t.Namespace;
} catch {
return null;
}
}
}
public class Outline {
bool declared_only;
bool show_private;
@@ -636,7 +649,7 @@ public class Outline {
if (!type.StartsWith ("System.")) {
if (type.IndexOf (".") == -1)
return type;
if (t.Namespace == this.t.Namespace)
if (t.GetNamespace () == this.t.GetNamespace ())
return t.Name;
return type;
}
@@ -745,7 +758,8 @@ public class Outline {
}
if (!recursed) {
string ns = t.Namespace;
string ns;
ns = t.GetNamespace ();
if ((ns != null) && (ns != "")) {
sb.Append (ns);
sb.Append (".");
+4
View File
@@ -58,9 +58,11 @@ install-pcl-targets:
$(MKINSTALLDIRS) $(DESTDIR)$(PORTABLE_TARGETS_DIR)/v4.0
$(INSTALL_DATA) targets/Microsoft.Portable.Common.targets $(DESTDIR)$(PORTABLE_TARGETS_DIR)/v4.0/Microsoft.Portable.Common.targets
$(INSTALL_DATA) targets/Microsoft.Portable.CSharp_4.0.targets $(DESTDIR)$(PORTABLE_TARGETS_DIR)/v4.0/Microsoft.Portable.CSharp.targets
$(INSTALL_DATA) targets/Microsoft.Portable.VisualBasic_4.0.targets $(DESTDIR)$(PORTABLE_TARGETS_DIR)/v4.0/Microsoft.Portable.VisualBasic.targets
$(MKINSTALLDIRS) $(DESTDIR)$(PORTABLE_TARGETS_DIR)/v4.5
$(INSTALL_DATA) targets/Microsoft.Portable.Common.targets $(DESTDIR)$(PORTABLE_TARGETS_DIR)/v4.5/Microsoft.Portable.Common.targets
$(INSTALL_DATA) targets/Microsoft.Portable.CSharp_4.5.targets $(DESTDIR)$(PORTABLE_TARGETS_DIR)/v4.5/Microsoft.Portable.CSharp.targets
$(INSTALL_DATA) targets/Microsoft.Portable.VisualBasic_4.5.targets $(DESTDIR)$(PORTABLE_TARGETS_DIR)/v4.5/Microsoft.Portable.VisualBasic.targets
$(INSTALL_DATA) targets/Microsoft.Portable.Core.targets $(DESTDIR)$(PORTABLE_TARGETS_DIR)/Microsoft.Portable.Core.targets
$(INSTALL_DATA) targets/Microsoft.Portable.Core.props $(DESTDIR)$(PORTABLE_TARGETS_DIR)/Microsoft.Portable.Core.props
@@ -107,5 +109,7 @@ EXTRA_DISTFILES = \
targets/Microsoft.Portable.Core.targets \
targets/Microsoft.Portable.Core.props \
targets/Microsoft.WebApplication.targets \
targets/Microsoft.Portable.VisualBasic_4.0.targets \
targets/Microsoft.Portable.VisualBasic_4.5.targets \
xbuild.make \
xbuild_test.make
@@ -8,6 +8,7 @@
<UsingTask TaskName="Microsoft.Build.Tasks.CombinePath" AssemblyName="Microsoft.Build.Tasks.v12.0, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<UsingTask TaskName="Microsoft.Build.Tasks.Copy" AssemblyName="Microsoft.Build.Tasks.v12.0, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<UsingTask TaskName="Microsoft.Build.Tasks.CreateCSharpManifestResourceName" AssemblyName="Microsoft.Build.Tasks.v12.0, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
<UsingTask TaskName="Microsoft.Build.Tasks.CreateVisualBasicManifestResourceName" AssemblyName="Microsoft.Build.Tasks.v12.0, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
<UsingTask TaskName="Microsoft.Build.Tasks.CreateItem" AssemblyName="Microsoft.Build.Tasks.v12.0, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<UsingTask TaskName="Microsoft.Build.Tasks.CreateProperty" AssemblyName="Microsoft.Build.Tasks.v12.0, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<UsingTask TaskName="Microsoft.Build.Tasks.Csc" AssemblyName="Microsoft.Build.Tasks.v12.0, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
@@ -7,6 +7,7 @@
<UsingTask TaskName="Microsoft.Build.Tasks.CombinePath" AssemblyName="Microsoft.Build.Tasks.Core, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<UsingTask TaskName="Microsoft.Build.Tasks.Copy" AssemblyName="Microsoft.Build.Tasks.Core, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<UsingTask TaskName="Microsoft.Build.Tasks.CreateCSharpManifestResourceName" AssemblyName="Microsoft.Build.Tasks.Core, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
<UsingTask TaskName="Microsoft.Build.Tasks.CreateVisualBasicManifestResourceName" AssemblyName="Microsoft.Build.Tasks.Core, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
<UsingTask TaskName="Microsoft.Build.Tasks.CreateItem" AssemblyName="Microsoft.Build.Tasks.Core, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<UsingTask TaskName="Microsoft.Build.Tasks.CreateProperty" AssemblyName="Microsoft.Build.Tasks.Core, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<UsingTask TaskName="Microsoft.Build.Tasks.Csc" AssemblyName="Microsoft.Build.Tasks.Core, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
@@ -7,6 +7,7 @@
<UsingTask TaskName="Microsoft.Build.Tasks.CombinePath" AssemblyName="Microsoft.Build.Tasks, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<UsingTask TaskName="Microsoft.Build.Tasks.Copy" AssemblyName="Microsoft.Build.Tasks, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<UsingTask TaskName="Microsoft.Build.Tasks.CreateCSharpManifestResourceName" AssemblyName="Microsoft.Build.Tasks, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<UsingTask TaskName="Microsoft.Build.Tasks.CreateVisualBasicManifestResourceName" AssemblyName="Microsoft.Build.Tasks, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
<UsingTask TaskName="Microsoft.Build.Tasks.CreateItem" AssemblyName="Microsoft.Build.Tasks, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<UsingTask TaskName="Microsoft.Build.Tasks.CreateProperty" AssemblyName="Microsoft.Build.Tasks, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<UsingTask TaskName="Microsoft.Build.Tasks.Csc" AssemblyName="Microsoft.Build.Tasks, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
@@ -8,6 +8,7 @@
<UsingTask TaskName="Microsoft.Build.Tasks.CombinePath" AssemblyName="Microsoft.Build.Tasks.v3.5, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<UsingTask TaskName="Microsoft.Build.Tasks.Copy" AssemblyName="Microsoft.Build.Tasks.v3.5, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<UsingTask TaskName="Microsoft.Build.Tasks.CreateCSharpManifestResourceName" AssemblyName="Microsoft.Build.Tasks.v3.5, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<UsingTask TaskName="Microsoft.Build.Tasks.CreateVisualBasicManifestResourceName" AssemblyName="Microsoft.Build.Tasks.v3.5, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
<UsingTask TaskName="Microsoft.Build.Tasks.CreateItem" AssemblyName="Microsoft.Build.Tasks.v3.5, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<UsingTask TaskName="Microsoft.Build.Tasks.CreateProperty" AssemblyName="Microsoft.Build.Tasks.v3.5, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<UsingTask TaskName="Microsoft.Build.Tasks.Csc" AssemblyName="Microsoft.Build.Tasks.v3.5, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
@@ -8,6 +8,7 @@
<UsingTask TaskName="Microsoft.Build.Tasks.CombinePath" AssemblyName="Microsoft.Build.Tasks.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<UsingTask TaskName="Microsoft.Build.Tasks.Copy" AssemblyName="Microsoft.Build.Tasks.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<UsingTask TaskName="Microsoft.Build.Tasks.CreateCSharpManifestResourceName" AssemblyName="Microsoft.Build.Tasks.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
<UsingTask TaskName="Microsoft.Build.Tasks.CreateVisualBasicManifestResourceName" AssemblyName="Microsoft.Build.Tasks.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
<UsingTask TaskName="Microsoft.Build.Tasks.CreateItem" AssemblyName="Microsoft.Build.Tasks.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<UsingTask TaskName="Microsoft.Build.Tasks.CreateProperty" AssemblyName="Microsoft.Build.Tasks.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<UsingTask TaskName="Microsoft.Build.Tasks.Csc" AssemblyName="Microsoft.Build.Tasks.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
@@ -1,5 +1,4 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask TaskName="Microsoft.Build.Tasks.CreateVisualBasicManifestResourceName" AssemblyName="Microsoft.Build.Tasks, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
<PropertyGroup>
<DefaultLanguageSourceExtension>.vb</DefaultLanguageSourceExtension>
<Language>VB</Language>
@@ -67,7 +66,7 @@
OptionStrictType="$(OptionStrictType)"
OutputAssembly="@(IntermediateAssembly)"
Platform="$(PlatformTarget)"
References="@(ResolvedFiles)"
References="@(ReferencePath)"
RemoveIntegerChecks="$(RemoveIntegerChecks)"
Resources="@(ManifestResourceWithNoCulture);@(ManifestNonResxWithNoCultureOnDisk);@(CompiledLicenseFile)"
ResponseFiles="$(CompilerResponseFile)"
@@ -0,0 +1,5 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\Microsoft.Portable.Core.props" />
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
<Import Project="..\Microsoft.Portable.Core.targets" />
</Project>
@@ -0,0 +1,5 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\Microsoft.Portable.Core.props" />
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
<Import Project="..\Microsoft.Portable.Core.targets" />
</Project>
-1
View File
@@ -838,7 +838,6 @@ gboolean CreateProcess (const gunichar2 *appname, const gunichar2 *cmdline,
} else {
if (!is_executable (prog)) {
DEBUG ("%s: Executable permisson not set on %s", __func__, prog);
g_free (prog);
SetLastError (ERROR_ACCESS_DENIED);
goto free_strings;
}
+7
View File
@@ -74,6 +74,9 @@ static char **extra_gac_paths = NULL;
* The integer number is an index in the MonoRuntimeInfo structure, whose
* values can be found in domain.c - supported_runtimes. Look there
* to understand what remapping will be made.
*
* .NET version can be found at https://github.com/dotnet/coreclr/blob/master/src/inc/fxretarget.h#L99
*
*/
static const AssemblyVersionMap framework_assemblies [] = {
{"Accessibility", 0},
@@ -102,6 +105,7 @@ static const AssemblyVersionMap framework_assemblies [] = {
{"Npgsql", 0},
{"PEAPI", 0},
{"System", 0},
{"System.ComponentModel.Composition", 2},
{"System.ComponentModel.DataAnnotations", 2},
{"System.Configuration", 0},
{"System.Configuration.Install", 0},
@@ -117,6 +121,8 @@ static const AssemblyVersionMap framework_assemblies [] = {
{"System.Drawing", 0},
{"System.Drawing.Design", 0},
{"System.EnterpriseServices", 0},
{"System.IdentityModel", 3},
{"System.IdentityModel.Selectors", 3},
{"System.Management", 0},
{"System.Messaging", 0},
{"System.Net", 2},
@@ -124,6 +130,7 @@ static const AssemblyVersionMap framework_assemblies [] = {
{"System.Runtime.Serialization", 3},
{"System.Runtime.Serialization.Formatters.Soap", 0},
{"System.Security", 0},
{"System.ServiceModel", 3},
{"System.ServiceModel.Web", 2},
{"System.ServiceProcess", 0},
{"System.Transactions", 0},
+5 -3
View File
@@ -82,9 +82,11 @@ append_class_name (GString *res, MonoClass *class, gboolean include_namespace)
append_class_name (res, class->nested_in, include_namespace);
g_string_append_c (res, '/');
}
if (include_namespace && *(class->name_space))
g_string_append_printf (res, "%s.", class->name_space);
g_string_append_printf (res, "%s", class->name);
if (include_namespace && *(class->name_space)) {
g_string_append (res, class->name_space);
g_string_append_c (res, '.');
}
g_string_append (res, class->name);
}
static MonoClass*
+2 -2
View File
@@ -2246,9 +2246,9 @@ mono_decimal_compare (MonoDecimal *left, MonoDecimal *right)
}
//
// Signs are different. Used signed byte compares
// Signs are different. Use signed byte comparison
//
if ((char)left_sign > (char)right_sign)
if ((signed char)left_sign > (signed char)right_sign)
return MONO_DECIMAL_CMP_GT;
return MONO_DECIMAL_CMP_LT;
}
+2 -2
View File
@@ -3031,7 +3031,7 @@ free_signature_pointer_pair (SignaturePointerPair *pair)
g_free (pair);
}
static MonoMethod *
MonoMethod *
mono_marshal_get_delegate_invoke_internal (MonoMethod *method, gboolean callvirt, gboolean static_method_with_first_arg_bound, MonoMethod *target_method)
{
MonoMethodSignature *sig, *static_sig, *invoke_sig;
@@ -7474,7 +7474,7 @@ mono_marshal_get_native_func_wrapper_aot (MonoClass *klass)
info->d.managed_to_native.method = invoke;
g_assert (!sig->hasthis);
csig = signature_dup_add_this (image, sig, mono_defaults.int_class);
csig = signature_dup_add_this (image, sig, mono_defaults.object_class);
csig->pinvoke = 0;
res = mono_mb_create_and_cache_full (cache, invoke,
mb, csig, csig->param_count + 16,
+3
View File
@@ -308,6 +308,9 @@ mono_marshal_get_delegate_end_invoke (MonoMethod *method) MONO_INTERNAL;
MonoMethod *
mono_marshal_get_delegate_invoke (MonoMethod *method, MonoDelegate *del) MONO_INTERNAL;
MonoMethod *
mono_marshal_get_delegate_invoke_internal (MonoMethod *method, gboolean callvirt, gboolean static_method_with_first_arg_bound, MonoMethod *target_method) MONO_INTERNAL;
MonoMethod *
mono_marshal_get_runtime_invoke (MonoMethod *method, gboolean is_virtual) MONO_INTERNAL;
+1 -1
View File
@@ -804,7 +804,7 @@ ves_icall_System_Diagnostics_Process_GetProcesses_internal (void)
}
procs = mono_array_new (mono_domain_get (), mono_get_int32_class (), count);
if (sizeof (guint32) == sizeof (gpointer)) {
memcpy (mono_array_addr (procs, guint32, 0), pidarray, count);
memcpy (mono_array_addr (procs, guint32, 0), pidarray, count * sizeof (gint32));
} else {
for (i = 0; i < count; ++i)
*(mono_array_addr (procs, guint32, i)) = GPOINTER_TO_UINT (pidarray [i]);
+1 -1
View File
@@ -75,7 +75,7 @@ sgen_suspend_thread (SgenThreadInfo *info)
info->stack_start = NULL;
stack_start = (char*) mono_mach_arch_get_sp (state) - REDZONE_SIZE;
/* If stack_start is not within the limits, then don't set it in info and we will be restarted. */
if (stack_start >= info->stack_start_limit && info->stack_start <= info->stack_end) {
if (stack_start >= info->stack_start_limit && stack_start <= info->stack_end) {
info->stack_start = stack_start;
#ifdef USE_MONO_CTX
+1 -1
View File
@@ -82,7 +82,7 @@ suspend_thread (SgenThreadInfo *info, void *context)
/* If stack_start is not within the limits, then don't set it
in info and we will be restarted. */
if (stack_start >= info->stack_start_limit && info->stack_start <= info->stack_end) {
if (stack_start >= info->stack_start_limit && stack_start <= info->stack_end) {
info->stack_start = stack_start;
#ifdef USE_MONO_CTX
+24 -2
View File
@@ -3090,6 +3090,8 @@ static MonoPltEntry*
get_plt_entry (MonoAotCompile *acfg, MonoJumpInfo *patch_info)
{
MonoPltEntry *res;
gboolean synchronized = FALSE;
static int synchronized_symbol_idx;
if (!is_plt_patch (patch_info))
return NULL;
@@ -3105,6 +3107,7 @@ get_plt_entry (MonoAotCompile *acfg, MonoJumpInfo *patch_info)
* wrapper.
*/
res = NULL;
synchronized = TRUE;
}
if (!res) {
@@ -3118,6 +3121,13 @@ get_plt_entry (MonoAotCompile *acfg, MonoJumpInfo *patch_info)
res->symbol = get_plt_symbol (acfg, res->plt_offset, patch_info);
if (acfg->aot_opts.write_symbols)
res->debug_sym = get_plt_entry_debug_sym (acfg, res->ji, acfg->plt_entry_debug_sym_cache);
if (synchronized) {
/* Avoid duplicate symbols because we don't cache */
res->symbol = g_strdup_printf ("%s_%d", res->symbol, synchronized_symbol_idx);
if (res->debug_sym)
res->debug_sym = g_strdup_printf ("%s_%d", res->debug_sym, synchronized_symbol_idx);
synchronized_symbol_idx ++;
}
if (res->debug_sym)
res->llvm_symbol = g_strdup_printf ("%s_%s_llvm", res->symbol, res->debug_sym);
else
@@ -3622,8 +3632,18 @@ add_wrappers (MonoAotCompile *acfg)
for (j = 0; j < cattr->num_attrs; ++j)
if (cattr->attrs [j].ctor && (!strcmp (cattr->attrs [j].ctor->klass->name, "MonoNativeFunctionWrapperAttribute") || !strcmp (cattr->attrs [j].ctor->klass->name, "UnmanagedFunctionPointerAttribute")))
break;
if (j < cattr->num_attrs)
add_method (acfg, mono_marshal_get_native_func_wrapper_aot (klass));
if (j < cattr->num_attrs) {
MonoMethod *invoke;
MonoMethod *wrapper;
MonoMethod *del_invoke;
/* Add wrappers needed by mono_ftnptr_to_delegate () */
invoke = mono_get_delegate_invoke (klass);
wrapper = mono_marshal_get_native_func_wrapper_aot (klass);
del_invoke = mono_marshal_get_delegate_invoke_internal (invoke, FALSE, TRUE, wrapper);
add_method (acfg, wrapper);
add_method (acfg, del_invoke);
}
}
} else if ((acfg->opts & MONO_OPT_GSHAREDVT) && klass->generic_container) {
MonoError error;
@@ -5712,6 +5732,8 @@ emit_klass_info (MonoAotCompile *acfg, guint32 token)
g_assert (klass->nested_classes_inited);
mono_class_setup_vtable (klass);
if (klass->exception_type)
g_error ("Error setting up %s class vtable\n", klass->name);
/*
* Emit all the information which is required for creating vtables so
+5 -5
View File
@@ -3739,7 +3739,7 @@ load_method (MonoDomain *domain, MonoAotModule *amodule, MonoImage *image, MonoM
}
static guint32
find_extra_method_in_amodule (MonoAotModule *amodule, MonoMethod *method)
find_aot_method_in_amodule (MonoAotModule *amodule, MonoMethod *method, guint32 hash_full)
{
guint32 table_size, entry_size, hash;
guint32 *table, *entry;
@@ -3750,11 +3750,10 @@ find_extra_method_in_amodule (MonoAotModule *amodule, MonoMethod *method)
return 0xffffff;
table_size = amodule->extra_method_table [0];
hash = hash_full % table_size;
table = amodule->extra_method_table + 1;
entry_size = 3;
hash = mono_aot_method_hash (method) % table_size;
entry = &table [hash * entry_size];
if (entry [0] == 0)
@@ -3835,10 +3834,11 @@ find_extra_method (MonoMethod *method, MonoAotModule **out_amodule)
guint32 index;
GPtrArray *modules;
int i;
guint32 hash = mono_aot_method_hash (method);
/* Try the method's module first */
*out_amodule = method->klass->image->aot_module;
index = find_extra_method_in_amodule (method->klass->image->aot_module, method);
index = find_aot_method_in_amodule (method->klass->image->aot_module, method, hash);
if (index != 0xffffff)
return index;
@@ -3860,7 +3860,7 @@ find_extra_method (MonoMethod *method, MonoAotModule **out_amodule)
MonoAotModule *amodule = g_ptr_array_index (modules, i);
if (amodule != method->klass->image->aot_module)
index = find_extra_method_in_amodule (amodule, method);
index = find_aot_method_in_amodule (amodule, method, hash);
if (index != 0xffffff) {
*out_amodule = amodule;
break;
+6
View File
@@ -704,6 +704,12 @@ class Tests
return (int)(f1 / f2);
}
public static int test_1_frem_r4 () {
float f1 = 7.0f;
float f2 = 2.0f;
return (int)(f1 % f2);
}
public static int test_0_fcmp_eq_r4 () {
float f1 = 1.0f;
float f2 = 1.0f;
+1 -1
View File
@@ -139,7 +139,7 @@ i8const: dest:i len:20
icompare: src1:i src2:i len:4
icompare_imm: src1:i len:18
iconst: dest:i len:40
jmp: len:46
jmp: len:50
label: len:0
lcall: dest:o len:22 clob:c
lcall_membase: dest:o src1:b len:12 clob:c
+12
View File
@@ -5310,6 +5310,18 @@ ss_start (SingleStepReq *ss_req, MonoMethod *method, SeqPoint* sp, MonoSeqPointI
if (ss_req->nframes == 0)
ss_req->nframes = nframes;
if ((ss_req->depth == STEP_DEPTH_OVER) && (!sp && !parent_sp)) {
DEBUG_PRINTF (1, "[dbg] No parent frame for step over, transition to step into.\n");
/*
* This is needed since if we leave managed code, and later return to it, step over
* is not going to stop.
* This approach is a bit ugly, since we change the step depth, but it only affects
* clients who reuse the same step request, and only in this special case.
*/
ss_req->depth = STEP_DEPTH_INTO;
}
if (ss_req->depth == STEP_DEPTH_OVER) {
/* Need to stop in catch clauses as well */
for (i = 0; i < nframes; ++i) {
+3 -3
View File
@@ -401,7 +401,7 @@ mono_arch_find_jit_info (MonoDomain *domain, MonoJitTlsData *jit_tls,
if (ji != NULL) {
int i;
gssize regs [MONO_MAX_IREGS + 1 + 8];
mono_unwind_reg_t regs [MONO_MAX_IREGS + 1 + 8];
guint8 *cfa;
guint32 unwind_info_len;
guint8 *unwind_info;
@@ -420,7 +420,7 @@ mono_arch_find_jit_info (MonoDomain *domain, MonoJitTlsData *jit_tls,
#ifdef TARGET_IOS
/* On IOS, d8..d15 are callee saved. They are mapped to 8..15 in unwind.c */
for (i = 0; i < 8; ++i)
regs [MONO_MAX_IREGS + i] = new_ctx->fregs [8 + i];
regs [MONO_MAX_IREGS + i] = *(guint64*)&(new_ctx->fregs [8 + i]);
#endif
mono_unwind_frame (unwind_info, unwind_info_len, ji->code_start,
@@ -434,7 +434,7 @@ mono_arch_find_jit_info (MonoDomain *domain, MonoJitTlsData *jit_tls,
new_ctx->regs [ARMREG_SP] = (gsize)cfa;
#ifdef TARGET_IOS
for (i = 0; i < 8; ++i)
new_ctx->fregs [8 + i] = regs [MONO_MAX_IREGS + i];
new_ctx->fregs [8 + i] = *(double*)&(regs [MONO_MAX_IREGS + i]);
#endif
/* Clear thumb bit */
+8
View File
@@ -60,6 +60,14 @@ mono_jit_parse_options (int argc, char * argv[]);
MONO_API char* mono_get_runtime_build_info (void);
/* The following APIs are not stable. Avoid if possible. */
MONO_API MonoJitInfo *
mono_get_jit_info_from_method (MonoDomain *domain, MonoMethod *method);
MONO_API void *
mono_aot_get_method (MonoDomain *domain, MonoMethod *method);
MONO_END_DECLS
#endif
+1 -1
View File
@@ -812,7 +812,7 @@ update_liveness2 (MonoCompile *cfg, MonoInst *ins, gboolean set_volatile, int in
}
else {
/* Try dead code elimination */
if ((var != cfg->ret) && !(var->flags & (MONO_INST_VOLATILE|MONO_INST_INDIRECT)) && ((ins->opcode == OP_ICONST) || (ins->opcode == OP_I8CONST) || (ins->opcode == OP_R8CONST)) && !(var->flags & MONO_INST_VOLATILE)) {
if (!cfg->disable_deadce_vars && (var != cfg->ret) && !(var->flags & (MONO_INST_VOLATILE|MONO_INST_INDIRECT)) && ((ins->opcode == OP_ICONST) || (ins->opcode == OP_I8CONST) || (ins->opcode == OP_R8CONST)) && !(var->flags & MONO_INST_VOLATILE)) {
LIVENESS_DEBUG (printf ("\tdead def of R%d, eliminated\n", ins->dreg));
NULLIFY_INS (ins);
return;
+9 -12
View File
@@ -5693,7 +5693,7 @@ mini_emit_inst_for_method (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSign
"System.Runtime.CompilerServices", "RuntimeHelpers");
if (cmethod->klass == mono_defaults.string_class) {
if (strcmp (cmethod->name, "get_Chars") == 0 && fsig->param_count == 2) {
if (strcmp (cmethod->name, "get_Chars") == 0 && fsig->param_count + fsig->hasthis == 2) {
int dreg = alloc_ireg (cfg);
int index_reg = alloc_preg (cfg);
int mult_reg = alloc_preg (cfg);
@@ -5722,7 +5722,7 @@ mini_emit_inst_for_method (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSign
#endif
type_from_op (cfg, ins, NULL, NULL);
return ins;
} else if (strcmp (cmethod->name, "get_Length") == 0 && fsig->param_count == 1) {
} else if (strcmp (cmethod->name, "get_Length") == 0 && fsig->param_count + fsig->hasthis == 1) {
int dreg = alloc_ireg (cfg);
/* Decompose later to allow more optimizations */
EMIT_NEW_UNALU (cfg, ins, OP_STRLEN, dreg, args [0]->dreg);
@@ -5745,7 +5745,7 @@ mini_emit_inst_for_method (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSign
return NULL;
} else if (cmethod->klass == mono_defaults.object_class) {
if (strcmp (cmethod->name, "GetType") == 0 && fsig->param_count == 1) {
if (strcmp (cmethod->name, "GetType") == 0 && fsig->param_count + fsig->hasthis == 1) {
int dreg = alloc_ireg_ref (cfg);
int vt_reg = alloc_preg (cfg);
MONO_EMIT_NEW_LOAD_MEMBASE_FAULT (cfg, vt_reg, args [0]->dreg, MONO_STRUCT_OFFSET (MonoObject, vtable));
@@ -5771,9 +5771,9 @@ mini_emit_inst_for_method (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSign
} else
return NULL;
} else if (cmethod->klass == mono_defaults.array_class) {
if (strcmp (cmethod->name, "GetGenericValueImpl") == 0 && fsig->param_count == 3 && !cfg->gsharedvt)
if (strcmp (cmethod->name, "GetGenericValueImpl") == 0 && fsig->param_count + fsig->hasthis == 3 && !cfg->gsharedvt)
return emit_array_generic_access (cfg, fsig, args, FALSE);
else if (strcmp (cmethod->name, "SetGenericValueImpl") == 0 && fsig->param_count == 3 && !cfg->gsharedvt)
else if (strcmp (cmethod->name, "SetGenericValueImpl") == 0 && fsig->param_count + fsig->hasthis == 3 && !cfg->gsharedvt)
return emit_array_generic_access (cfg, fsig, args, TRUE);
#ifndef MONO_BIG_ARRAYS
@@ -5781,8 +5781,8 @@ mini_emit_inst_for_method (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSign
* This is an inline version of GetLength/GetLowerBound(0) used frequently in
* Array methods.
*/
else if (((strcmp (cmethod->name, "GetLength") == 0 && fsig->param_count == 2) ||
(strcmp (cmethod->name, "GetLowerBound") == 0 && fsig->param_count == 2)) &&
else if (((strcmp (cmethod->name, "GetLength") == 0 && fsig->param_count + fsig->hasthis == 2) ||
(strcmp (cmethod->name, "GetLowerBound") == 0 && fsig->param_count + fsig->hasthis == 2)) &&
args [1]->opcode == OP_ICONST && args [1]->inst_c0 == 0) {
int dreg = alloc_ireg (cfg);
int bounds_reg = alloc_ireg_mp (cfg);
@@ -5823,7 +5823,7 @@ mini_emit_inst_for_method (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSign
if (cmethod->name [0] != 'g')
return NULL;
if (strcmp (cmethod->name, "get_Rank") == 0 && fsig->param_count == 1) {
if (strcmp (cmethod->name, "get_Rank") == 0 && fsig->param_count + fsig->hasthis == 1) {
int dreg = alloc_ireg (cfg);
int vtable_reg = alloc_preg (cfg);
MONO_EMIT_NEW_LOAD_MEMBASE_OP_FAULT (cfg, OP_LOAD_MEMBASE, vtable_reg,
@@ -5833,7 +5833,7 @@ mini_emit_inst_for_method (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSign
type_from_op (cfg, ins, NULL, NULL);
return ins;
} else if (strcmp (cmethod->name, "get_Length") == 0 && fsig->param_count == 1) {
} else if (strcmp (cmethod->name, "get_Length") == 0 && fsig->param_count + fsig->hasthis == 1) {
int dreg = alloc_ireg (cfg);
EMIT_NEW_LOAD_MEMBASE_FAULT (cfg, ins, OP_LOADI4_MEMBASE, dreg,
@@ -7813,9 +7813,6 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b
cfg->stat_cil_code_size += header->code_size;
seq_points = cfg->gen_seq_points && cfg->method == method;
#ifdef PLATFORM_ANDROID
seq_points &= cfg->method->wrapper_type == MONO_WRAPPER_NONE;
#endif
if (method->wrapper_type == MONO_WRAPPER_NATIVE_TO_MANAGED) {
/* We could hit a seq point before attaching to the JIT (#8338) */
+3
View File
@@ -124,6 +124,9 @@
* reproduceable results for benchmarks */
#define MONO_ARCH_CODE_ALIGNMENT 32
/* This needs to hold both a 32 bit int and a 64 bit double */
#define mono_unwind_reg_t guint64
/* Argument marshallings for calls between gsharedvt and normal code */
typedef enum {
GSHAREDVT_ARG_NONE = 0,
+6 -1
View File
@@ -12,6 +12,11 @@
#include "mini.h"
/* This is the same as mgreg_t, except on 32 bit bit platforms with callee saved fp regs */
#ifndef mono_unwind_reg_t
#define mono_unwind_reg_t mgreg_t
#endif
/*
* This is a platform-independent interface for unwinding through stack frames
* based on the Dwarf unwinding interface.
@@ -145,7 +150,7 @@ mono_unwind_ops_encode (GSList *unwind_ops, guint32 *out_len) MONO_INTERNAL;
void
mono_unwind_frame (guint8 *unwind_info, guint32 unwind_info_len,
guint8 *start_ip, guint8 *end_ip, guint8 *ip, guint8 **mark_locations,
mgreg_t *regs, int nregs,
mono_unwind_reg_t *regs, int nregs,
mgreg_t **save_locations, int save_locations_len,
guint8 **out_cfa) MONO_INTERNAL;
+15
View File
@@ -4918,6 +4918,14 @@ mini_method_compile (MonoMethod *method, guint32 opts, MonoDomain *domain, JitFl
cfg->gen_seq_points = debug_options.gen_seq_points_compact_data || debug_options.gen_seq_points_debug_data;
cfg->gen_seq_points_debug_data = debug_options.gen_seq_points_debug_data;
#ifdef PLATFORM_ANDROID
if (cfg->method->wrapper_type != MONO_WRAPPER_NONE) {
/* FIXME: Why is this needed ? */
cfg->gen_seq_points = FALSE;
cfg->gen_seq_points_debug_data = FALSE;
}
#endif
cfg->explicit_null_checks = debug_options.explicit_null_checks;
cfg->soft_breakpoints = debug_options.soft_breakpoints;
cfg->check_pinvoke_callconv = debug_options.check_pinvoke_callconv;
@@ -5766,6 +5774,12 @@ lookup_method (MonoDomain *domain, MonoMethod *method)
return ji;
}
MonoJitInfo *
mono_get_jit_info_from_method (MonoDomain *domain, MonoMethod *method)
{
return lookup_method (domain, method);
}
#if ENABLE_JIT_MAP
static FILE* perf_map_file;
@@ -7586,6 +7600,7 @@ register_icalls (void)
#ifdef MONO_ARCH_EMULATE_FREM
#if defined(__default_codegen__)
register_opcode_emulation (OP_FREM, "__emul_frem", "double double double", fmod, "fmod", FALSE);
register_opcode_emulation (OP_RREM, "__emul_rrem", "float float float", fmodf, "fmodf", FALSE);
#elif defined(__native_client_codegen__)
register_opcode_emulation (OP_FREM, "__emul_frem", "double double double", mono_fmod, "mono_fmod", FALSE);
#endif
+2 -2
View File
@@ -105,7 +105,7 @@
#endif
/* Version number of the AOT file format */
#define MONO_AOT_FILE_VERSION 108
#define MONO_AOT_FILE_VERSION 111
//TODO: This is x86/amd64 specific.
#define mono_simd_shuffle_mask(a,b,c,d) ((a) | ((b) << 2) | ((c) << 4) | ((d) << 6))
@@ -2232,7 +2232,7 @@ jinfo_get_method (MonoJitInfo *ji)
void mono_aot_init (void) MONO_INTERNAL;
void mono_aot_cleanup (void) MONO_INTERNAL;
gpointer mono_aot_get_method (MonoDomain *domain,
MonoMethod *method) MONO_INTERNAL;
MonoMethod *method);
gpointer mono_aot_get_method_from_token (MonoDomain *domain, MonoImage *image, guint32 token) MONO_INTERNAL;
gboolean mono_aot_is_got_entry (guint8 *code, guint8 *addr) MONO_INTERNAL;
guint8* mono_aot_get_plt_entry (guint8 *code) MONO_INTERNAL;
+1 -1
View File
@@ -995,7 +995,7 @@ mono_arch_create_monitor_enter_trampoline (MonoTrampInfo **info, gboolean is_v4,
status_offset = MONO_THREADS_SYNC_MEMBER_OFFSET (status_offset);
nest_offset = MONO_THREADS_SYNC_MEMBER_OFFSET (nest_offset);
tramp_size = 96;
tramp_size = 128;
code = buf = mono_global_codeman_reserve (tramp_size);
+13 -10
View File
@@ -51,11 +51,12 @@ static int map_hw_reg_to_dwarf_reg [] = { 0, 2, 1, 3, 7, 6, 4, 5, 8, 9, 10, 11,
#define DWARF_PC_REG (mono_hw_reg_to_dwarf_reg (AMD64_RIP))
#elif defined(TARGET_ARM)
// http://infocenter.arm.com/help/topic/com.arm.doc.ihi0040a/IHI0040A_aadwarf.pdf
/* Assign d8..d15 to hregs 16..24 */
/* Assign d8..d15 to hregs 16..24 (dwarf regs 264..271) */
static int map_hw_reg_to_dwarf_reg [] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 264, 265, 266, 267, 268, 269, 270, 271 };
#define NUM_REGS 272
#define DWARF_DATA_ALIGN (-4)
#define DWARF_PC_REG (mono_hw_reg_to_dwarf_reg (ARMREG_LR))
#define IS_DOUBLE_REG(dwarf_reg) (((dwarf_reg) >= 264) && ((dwarf_reg) <= 271))
#elif defined(TARGET_ARM64)
#define NUM_REGS 96
#define DWARF_DATA_ALIGN (-8)
@@ -68,16 +69,11 @@ static int map_hw_reg_to_dwarf_reg [] = {
72, 73, 74, 75, 76, 77, 78, 79,
};
#elif defined (TARGET_X86)
#ifdef __APPLE__
/*
* LLVM seems to generate unwind info where esp is encoded as 5, and ebp as 4, ie see this line:
* def ESP : RegisterWithSubRegs<"esp", [SP]>, DwarfRegNum<[-2, 5, 4]>;
* in lib/Target/X86/X86RegisterInfo.td in the llvm sources.
* ebp and esp are swapped:
* http://lists.cs.uiuc.edu/pipermail/lldb-dev/2014-January/003101.html
*/
static int map_hw_reg_to_dwarf_reg [] = { 0, 1, 2, 3, 5, 4, 6, 7, 8 };
#else
static int map_hw_reg_to_dwarf_reg [] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
#endif
/* + 1 is for IP */
#define NUM_REGS X86_NREG + 1
#define DWARF_DATA_ALIGN (-4)
@@ -114,6 +110,10 @@ static int map_hw_reg_to_dwarf_reg [16];
#define DWARF_PC_REG -1
#endif
#ifndef IS_DOUBLE_REG
#define IS_DOUBLE_REG(dwarf_reg) 0
#endif
static gboolean dwarf_reg_to_hw_reg_inited;
static int map_dwarf_reg_to_hw_reg [NUM_REGS];
@@ -485,7 +485,7 @@ typedef struct {
void
mono_unwind_frame (guint8 *unwind_info, guint32 unwind_info_len,
guint8 *start_ip, guint8 *end_ip, guint8 *ip, guint8 **mark_locations,
mgreg_t *regs, int nregs,
mono_unwind_reg_t *regs, int nregs,
mgreg_t **save_locations, int save_locations_len,
guint8 **out_cfa)
{
@@ -607,7 +607,10 @@ mono_unwind_frame (guint8 *unwind_info, guint32 unwind_info_len,
if (reg_saved [i] && locations [i].loc_type == LOC_OFFSET) {
int hreg = mono_dwarf_reg_to_hw_reg (i);
g_assert (hreg < nregs);
regs [hreg] = *(mgreg_t*)(cfa_val + locations [i].offset);
if (IS_DOUBLE_REG (i))
regs [hreg] = *(guint64*)(cfa_val + locations [i].offset);
else
regs [hreg] = *(mgreg_t*)(cfa_val + locations [i].offset);
if (save_locations && hreg < save_locations_len)
save_locations [hreg] = (mgreg_t*)(cfa_val + locations [i].offset);
}
+341 -143
View File
@@ -9,15 +9,19 @@
*/
#include <config.h>
#include "../mini/jit.h"
#include <mono/metadata/profiler.h>
#include <mono/metadata/threads.h>
#include <mono/metadata/mono-gc.h>
#include <mono/metadata/debug-helpers.h>
#include <mono/metadata/mono-perfcounters.h>
#include <mono/metadata/appdomain.h>
#include <mono/utils/atomic.h>
#include <mono/utils/mono-membar.h>
#include <mono/utils/mono-counters.h>
#include <mono/utils/mono-mutex.h>
#include <mono/utils/mono-conc-hashtable.h>
#include <mono/utils/lock-free-queue.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
@@ -74,7 +78,7 @@
#include <sys/syscall.h>
#include "perf_event.h"
#ifndef DISABLE_PERF_EVENTS
#ifdef ENABLE_PERF_EVENTS
#define USE_PERF_EVENTS 1
static int read_perf_mmap (MonoProfiler* prof, int cpu);
@@ -89,7 +93,8 @@ static int use_zip = 0;
static int do_report = 0;
static int do_heap_shot = 0;
static int max_call_depth = 100;
static int runtime_inited = 0;
static volatile int runtime_inited = 0;
static int need_helper_thread = 0;
static int command_port = 0;
static int heapshot_requested = 0;
static int sample_type = 0;
@@ -401,28 +406,49 @@ struct _MonoProfiler {
int pipes [2];
#ifndef HOST_WIN32
pthread_t helper_thread;
pthread_t writer_thread;
#endif
volatile gint32 run_writer_thread;
MonoLockFreeQueue writer_queue;
MonoConcurrentHashTable *method_table;
mono_mutex_t method_table_mutex;
BinaryObject *binary_objects;
};
typedef struct _WriterQueueEntry WriterQueueEntry;
struct _WriterQueueEntry {
MonoLockFreeQueueNode node;
GPtrArray *methods;
LogBuffer *buffer;
};
typedef struct _MethodInfo MethodInfo;
struct _MethodInfo {
MonoMethod *method;
MonoJitInfo *ji;
};
#ifdef HOST_WIN32
#define TLS_SET(x,y) TlsSetValue(x, y)
#define TLS_GET(x) ((LogBuffer *) TlsGetValue(x))
#define TLS_INIT(x) x = TlsAlloc ()
#define TLS_SET(x,y) (TlsSetValue (x, y))
#define TLS_GET(t,x) ((t *) TlsGetValue (x))
#define TLS_INIT(x) (x = TlsAlloc ())
static int tlsbuffer;
static int tlsmethodlist;
#elif HAVE_KW_THREAD
#define TLS_SET(x,y) x = y
#define TLS_GET(x) x
#define TLS_SET(x,y) (x = y)
#define TLS_GET(t,x) (x)
#define TLS_INIT(x)
static __thread LogBuffer* tlsbuffer = NULL;
static __thread GPtrArray* tlsmethodlist = NULL;
#else
#define TLS_SET(x,y) pthread_setspecific(x, y)
#define TLS_GET(x) ((LogBuffer *) pthread_getspecific(x))
#define TLS_INIT(x) pthread_key_create(&x, NULL)
#define TLS_SET(x,y) (pthread_setspecific (x, y))
#define TLS_GET(t,x) ((t *) pthread_getspecific (x))
#define TLS_INIT(x) (pthread_key_create (&x, NULL))
static pthread_key_t tlsbuffer;
static pthread_key_t tlsmethodlist;
#endif
static void safe_dump (MonoProfiler *profiler, LogBuffer *logbuffer);
static void safe_send (MonoProfiler *profiler, LogBuffer *logbuffer);
static char*
pstrdup (const char *s)
@@ -458,28 +484,48 @@ create_buffer (void)
static void
init_thread (void)
{
LogBuffer *logbuffer;
if (TLS_GET (tlsbuffer))
return;
logbuffer = create_buffer ();
TLS_SET (tlsbuffer, logbuffer);
logbuffer->thread_id = thread_id ();
if (!TLS_GET (LogBuffer, tlsbuffer)) {
LogBuffer *logbuffer = create_buffer ();
TLS_SET (tlsbuffer, logbuffer);
logbuffer->thread_id = thread_id ();
}
if (!TLS_GET (GPtrArray, tlsmethodlist)) {
GPtrArray *methodlist = g_ptr_array_new ();
TLS_SET (tlsmethodlist, methodlist);
}
//printf ("thread %p at time %llu\n", (void*)logbuffer->thread_id, logbuffer->time_base);
}
static LogBuffer *
ensure_logbuf_inner (LogBuffer *old, int bytes)
{
if (old && old->data + bytes + 100 < old->data_end)
return old;
LogBuffer *new = create_buffer ();
new->thread_id = thread_id ();
new->next = old;
if (old)
new->call_depth = old->call_depth;
return new;
}
static LogBuffer*
ensure_logbuf (int bytes)
{
LogBuffer *old = TLS_GET (tlsbuffer);
if (old && old->data + bytes + 100 < old->data_end)
return old;
TLS_SET (tlsbuffer, NULL);
LogBuffer *old = TLS_GET (LogBuffer, tlsbuffer);
LogBuffer *new = ensure_logbuf_inner (old, bytes);
if (new == old)
return old; // Still enough space.
TLS_SET (tlsbuffer, new);
init_thread ();
TLS_GET (tlsbuffer)->next = old;
if (old)
TLS_GET (tlsbuffer)->call_depth = old->call_depth;
//printf ("new logbuffer\n");
return TLS_GET (tlsbuffer);
return new;
}
static void
@@ -538,7 +584,7 @@ emit_ptr (LogBuffer *logbuffer, void *ptr)
}
static void
emit_method (LogBuffer *logbuffer, void *method)
emit_method_inner (LogBuffer *logbuffer, void *method)
{
if (!logbuffer->method_base) {
logbuffer->method_base = (intptr_t)method;
@@ -549,6 +595,71 @@ emit_method (LogBuffer *logbuffer, void *method)
assert (logbuffer->data <= logbuffer->data_end);
}
typedef struct {
MonoMethod *method;
MonoJitInfo *found;
} MethodSearch;
static void
find_method (MonoDomain *domain, void *user_data)
{
MethodSearch *search = user_data;
if (search->found)
return;
MonoJitInfo *ji = mono_get_jit_info_from_method (domain, search->method);
// It could be AOT'd, so we need to get it from the AOT runtime's cache.
if (!ji) {
void *ip = mono_aot_get_method (domain, search->method);
// Avoid a slow path in mono_jit_info_table_find ().
if (ip)
ji = mono_jit_info_table_find (domain, ip);
}
if (ji)
search->found = ji;
}
static void
register_method_local (MonoProfiler *prof, MonoMethod *method, MonoJitInfo *ji)
{
if (!mono_conc_hashtable_lookup (prof->method_table, method)) {
if (!ji) {
MethodSearch search = { method, NULL };
mono_domain_foreach (find_method, &search);
ji = search.found;
}
g_assert (ji);
MethodInfo *info = malloc (sizeof (MethodInfo));
info->method = method;
info->ji = ji;
g_ptr_array_add (TLS_GET (GPtrArray, tlsmethodlist), info);
}
}
static void
emit_method (MonoProfiler *prof, LogBuffer *logbuffer, MonoMethod *method)
{
register_method_local (prof, method, NULL);
emit_method_inner (logbuffer, method);
}
static void
emit_method_as_ptr (MonoProfiler *prof, LogBuffer *logbuffer, MonoMethod *method)
{
register_method_local (prof, method, NULL);
emit_ptr (logbuffer, method);
}
static void
emit_obj (LogBuffer *logbuffer, void *ptr)
{
@@ -647,6 +758,16 @@ dump_header (MonoProfiler *profiler)
#endif
}
static void
send_buffer (MonoProfiler *prof, GPtrArray *methods, LogBuffer *buffer)
{
WriterQueueEntry *entry = calloc (1, sizeof (WriterQueueEntry));
mono_lock_free_queue_node_init (&entry->node, FALSE);
entry->methods = methods;
entry->buffer = buffer;
mono_lock_free_queue_enqueue (&prof->writer_queue, &entry->node);
}
static void
dump_buffer (MonoProfiler *profiler, LogBuffer *buf)
{
@@ -686,31 +807,32 @@ process_requests (MonoProfiler *profiler)
static void counters_init (MonoProfiler *profiler);
static void counters_sample (MonoProfiler *profiler, uint64_t timestamp);
static void
runtime_initialized (MonoProfiler *profiler)
{
runtime_inited = 1;
#ifndef DISABLE_HELPER_THREAD
counters_init (profiler);
counters_sample (profiler, 0);
#endif
/* ensure the main thread data and startup are available soon */
safe_dump (profiler, ensure_logbuf (0));
}
/*
* Can be called only at safe callback locations.
*/
static void
safe_dump (MonoProfiler *profiler, LogBuffer *logbuffer)
safe_send (MonoProfiler *profiler, LogBuffer *logbuffer)
{
/* We need the runtime initialized so that we have threads and hazard
* pointers available. Otherwise, the lock free queue will not work and
* there won't be a thread to process the data.
*
* While the runtime isn't initialized, we just accumulate data in the
* thread local buffer list.
*/
if (!InterlockedRead (&runtime_inited))
return;
int cd = logbuffer->call_depth;
take_lock ();
dump_buffer (profiler, TLS_GET (tlsbuffer));
release_lock ();
send_buffer (profiler, TLS_GET (GPtrArray, tlsmethodlist), TLS_GET (LogBuffer, tlsbuffer));
TLS_SET (tlsbuffer, NULL);
TLS_SET (tlsmethodlist, NULL);
init_thread ();
TLS_GET (tlsbuffer)->call_depth = cd;
TLS_GET (LogBuffer, tlsbuffer)->call_depth = cd;
}
static int
@@ -796,7 +918,7 @@ gc_event (MonoProfiler *profiler, MonoGCEvent ev, int generation) {
heap_walk (profiler);
EXIT_LOG (logbuffer);
if (ev == MONO_GC_EVENT_POST_START_WORLD)
safe_dump (profiler, logbuffer);
safe_send (profiler, logbuffer);
//printf ("gc event %d for generation %d\n", ev, generation);
}
@@ -848,7 +970,7 @@ collect_bt (FrameData *data)
}
static void
emit_bt (LogBuffer *logbuffer, FrameData *data)
emit_bt (MonoProfiler *prof, LogBuffer *logbuffer, FrameData *data)
{
/* FIXME: this is actually tons of data and we should
* just output it the first time and use an id the next
@@ -860,7 +982,7 @@ emit_bt (LogBuffer *logbuffer, FrameData *data)
//if (*p != data.count) {
// printf ("bad num frames enc at %d: %d -> %d\n", count, data.count, *p); printf ("frames end: %p->%p\n", p, logbuffer->data); exit(0);}
while (data->count) {
emit_ptr (logbuffer, data->methods [--data->count]);
emit_method_as_ptr (prof, logbuffer, data->methods [--data->count]);
}
}
@@ -869,7 +991,7 @@ gc_alloc (MonoProfiler *prof, MonoObject *obj, MonoClass *klass)
{
uint64_t now;
uintptr_t len;
int do_bt = (nocalls && runtime_inited && !notraces)? TYPE_ALLOC_BT: 0;
int do_bt = (nocalls && InterlockedRead (&runtime_inited) && !notraces)? TYPE_ALLOC_BT: 0;
FrameData data;
LogBuffer *logbuffer;
len = mono_object_get_size (obj);
@@ -887,10 +1009,10 @@ gc_alloc (MonoProfiler *prof, MonoObject *obj, MonoClass *klass)
emit_obj (logbuffer, obj);
emit_value (logbuffer, len);
if (do_bt)
emit_bt (logbuffer, &data);
emit_bt (prof, logbuffer, &data);
EXIT_LOG (logbuffer);
if (logbuffer->next)
safe_dump (prof, logbuffer);
safe_send (prof, logbuffer);
process_requests (prof);
//printf ("gc alloc %s at %p\n", mono_class_get_name (klass), obj);
}
@@ -1011,7 +1133,7 @@ image_loaded (MonoProfiler *prof, MonoImage *image, int result)
//printf ("loaded image %p (%s)\n", image, name);
EXIT_LOG (logbuffer);
if (logbuffer->next)
safe_dump (prof, logbuffer);
safe_send (prof, logbuffer);
process_requests (prof);
}
@@ -1025,7 +1147,7 @@ class_loaded (MonoProfiler *prof, MonoClass *klass, int result)
LogBuffer *logbuffer;
if (result != MONO_PROFILE_OK)
return;
if (runtime_inited)
if (InterlockedRead (&runtime_inited))
name = mono_type_get_name (mono_class_get_type (klass));
else
name = type_name (klass);
@@ -1049,7 +1171,7 @@ class_loaded (MonoProfiler *prof, MonoClass *klass, int result)
free (name);
EXIT_LOG (logbuffer);
if (logbuffer->next)
safe_dump (prof, logbuffer);
safe_send (prof, logbuffer);
process_requests (prof);
}
@@ -1064,7 +1186,7 @@ method_enter (MonoProfiler *prof, MonoMethod *method)
ENTER_LOG (logbuffer, "enter");
emit_byte (logbuffer, TYPE_ENTER | TYPE_METHOD);
emit_time (logbuffer, now);
emit_method (logbuffer, method);
emit_method (prof, logbuffer, method);
EXIT_LOG (logbuffer);
process_requests (prof);
}
@@ -1080,10 +1202,10 @@ method_leave (MonoProfiler *prof, MonoMethod *method)
ENTER_LOG (logbuffer, "leave");
emit_byte (logbuffer, TYPE_LEAVE | TYPE_METHOD);
emit_time (logbuffer, now);
emit_method (logbuffer, method);
emit_method (prof, logbuffer, method);
EXIT_LOG (logbuffer);
if (logbuffer->next)
safe_dump (prof, logbuffer);
safe_send (prof, logbuffer);
process_requests (prof);
}
@@ -1101,37 +1223,18 @@ method_exc_leave (MonoProfiler *prof, MonoMethod *method)
ENTER_LOG (logbuffer, "eleave");
emit_byte (logbuffer, TYPE_EXC_LEAVE | TYPE_METHOD);
emit_time (logbuffer, now);
emit_method (logbuffer, method);
emit_method (prof, logbuffer, method);
EXIT_LOG (logbuffer);
process_requests (prof);
}
static void
method_jitted (MonoProfiler *prof, MonoMethod *method, MonoJitInfo* jinfo, int result)
method_jitted (MonoProfiler *prof, MonoMethod *method, MonoJitInfo *ji, int result)
{
uint64_t now;
char *name;
int nlen;
LogBuffer *logbuffer;
if (result != MONO_PROFILE_OK)
return;
name = mono_method_full_name (method, 1);
nlen = strlen (name) + 1;
logbuffer = ensure_logbuf (32 + nlen);
now = current_time ();
ENTER_LOG (logbuffer, "jit");
emit_byte (logbuffer, TYPE_JIT | TYPE_METHOD);
emit_time (logbuffer, now);
emit_method (logbuffer, method);
emit_ptr (logbuffer, mono_jit_info_get_code_start (jinfo));
emit_value (logbuffer, mono_jit_info_get_code_size (jinfo));
memcpy (logbuffer->data, name, nlen);
logbuffer->data += nlen;
mono_free (name);
EXIT_LOG (logbuffer);
if (logbuffer->next)
safe_dump (prof, logbuffer);
process_requests (prof);
register_method_local (prof, method, ji);
}
static void
@@ -1167,7 +1270,7 @@ code_buffer_new (MonoProfiler *prof, void *buffer, int size, MonoProfilerCodeBuf
static void
throw_exc (MonoProfiler *prof, MonoObject *object)
{
int do_bt = (nocalls && runtime_inited && !notraces)? TYPE_EXCEPTION_BT: 0;
int do_bt = (nocalls && InterlockedRead (&runtime_inited) && !notraces)? TYPE_EXCEPTION_BT: 0;
uint64_t now;
FrameData data;
LogBuffer *logbuffer;
@@ -1180,7 +1283,7 @@ throw_exc (MonoProfiler *prof, MonoObject *object)
emit_time (logbuffer, now);
emit_obj (logbuffer, object);
if (do_bt)
emit_bt (logbuffer, &data);
emit_bt (prof, logbuffer, &data);
EXIT_LOG (logbuffer);
process_requests (prof);
}
@@ -1196,14 +1299,14 @@ clause_exc (MonoProfiler *prof, MonoMethod *method, int clause_type, int clause_
emit_time (logbuffer, now);
emit_value (logbuffer, clause_type);
emit_value (logbuffer, clause_num);
emit_method (logbuffer, method);
emit_method (prof, logbuffer, method);
EXIT_LOG (logbuffer);
}
static void
monitor_event (MonoProfiler *profiler, MonoObject *object, MonoProfilerMonitorEvent event)
{
int do_bt = (nocalls && runtime_inited && !notraces && event == MONO_PROFILER_MONITOR_CONTENTION)? TYPE_MONITOR_BT: 0;
int do_bt = (nocalls && InterlockedRead (&runtime_inited) && !notraces && event == MONO_PROFILER_MONITOR_CONTENTION)? TYPE_MONITOR_BT: 0;
uint64_t now;
FrameData data;
LogBuffer *logbuffer;
@@ -1216,7 +1319,7 @@ monitor_event (MonoProfiler *profiler, MonoObject *object, MonoProfilerMonitorEv
emit_time (logbuffer, now);
emit_obj (logbuffer, object);
if (do_bt)
emit_bt (logbuffer, &data);
emit_bt (profiler, logbuffer, &data);
EXIT_LOG (logbuffer);
process_requests (profiler);
}
@@ -1231,11 +1334,11 @@ thread_start (MonoProfiler *prof, uintptr_t tid)
static void
thread_end (MonoProfiler *prof, uintptr_t tid)
{
take_lock ();
if (TLS_GET (tlsbuffer))
dump_buffer (prof, TLS_GET (tlsbuffer));
release_lock ();
if (TLS_GET (LogBuffer, tlsbuffer))
send_buffer (prof, TLS_GET (GPtrArray, tlsmethodlist), TLS_GET (LogBuffer, tlsbuffer));
TLS_SET (tlsbuffer, NULL);
TLS_SET (tlsmethodlist, NULL);
}
static void
@@ -1681,36 +1784,14 @@ dump_unmanaged_coderefs (MonoProfiler *prof)
}
static void
dump_sample_hits_inner (MonoProfiler *prof, StatBuffer *sbuf, int recurse, GPtrArray **array);
static void
dump_sample_hits (MonoProfiler *prof, StatBuffer *sbuf, int recurse)
{
GPtrArray *array = NULL;
dump_sample_hits_inner (prof, sbuf, recurse, &array);
if (array) {
int i;
g_ptr_array_sort (array, g_direct_equal);
for (i = 0; i < array->len; ++i) {
MonoJitInfo *cur = array->pdata [i];
//Ignore duplicates
if (i > 0 && array->pdata [i - 1] == cur)
continue;
method_jitted (prof, mono_jit_info_get_method (cur), cur, MONO_PROFILE_OK);
}
}
}
static void
dump_sample_hits_inner (MonoProfiler *prof, StatBuffer *sbuf, int recurse, GPtrArray **array)
dump_sample_hits (MonoProfiler *prof, StatBuffer *sbuf)
{
uintptr_t *sample;
LogBuffer *logbuffer;
if (!sbuf)
return;
if (recurse && sbuf->next) {
dump_sample_hits_inner (prof, sbuf->next, 1, array);
if (sbuf->next) {
dump_sample_hits (prof, sbuf->next);
free_buffer (sbuf->next, sbuf->next->size);
sbuf->next = NULL;
}
@@ -1731,12 +1812,9 @@ dump_sample_hits_inner (MonoProfiler *prof, StatBuffer *sbuf, int recurse, GPtrA
if (!method) {
MonoJitInfo *ji = mono_jit_info_table_find (domain, address);
if (ji) {
if (ji)
managed_sample_base [i * 4 + 0] = (uintptr_t)mono_jit_info_get_method (ji);
if (!*array)
*array = g_ptr_array_new ();
g_ptr_array_add (*array, ji);
}
}
}
logbuffer = ensure_logbuf (20 + count * 8);
@@ -1753,9 +1831,12 @@ dump_sample_hits_inner (MonoProfiler *prof, StatBuffer *sbuf, int recurse, GPtrA
/* new in data version 6 */
emit_uvalue (logbuffer, mbt_count);
for (i = 0; i < mbt_count; ++i) {
emit_method (logbuffer, (void*)sample [i * 4]); /* method */
MonoMethod *method = (MonoMethod *) sample [i * 4 + 0];
uintptr_t native_offset = sample [i * 4 + 3];
emit_method (prof, logbuffer, method);
emit_svalue (logbuffer, 0); /* il offset will always be 0 from now on */
emit_svalue (logbuffer, sample [i * 4 + 3]); /* native offset */
emit_svalue (logbuffer, native_offset);
}
sample += 4 * mbt_count;
}
@@ -2135,7 +2216,7 @@ counters_emit (MonoProfiler *profiler)
}
EXIT_LOG (logbuffer);
safe_dump (profiler, ensure_logbuf (0));
safe_send (profiler, ensure_logbuf (0));
mono_mutex_unlock (&counters_mutex);
}
@@ -2253,7 +2334,7 @@ counters_sample (MonoProfiler *profiler, uint64_t timestamp)
emit_value (logbuffer, 0);
EXIT_LOG (logbuffer);
safe_dump (profiler, ensure_logbuf (0));
safe_send (profiler, ensure_logbuf (0));
mono_mutex_unlock (&counters_mutex);
}
@@ -2312,7 +2393,7 @@ perfcounters_emit (MonoProfiler *profiler)
}
EXIT_LOG (logbuffer);
safe_dump (profiler, ensure_logbuf (0));
safe_send (profiler, ensure_logbuf (0));
}
static gboolean
@@ -2394,7 +2475,7 @@ perfcounters_sample (MonoProfiler *profiler, uint64_t timestamp)
emit_value (logbuffer, 0);
EXIT_LOG (logbuffer);
safe_dump (profiler, ensure_logbuf (0));
safe_send (profiler, ensure_logbuf (0));
mono_mutex_unlock (&counters_mutex);
}
@@ -2418,13 +2499,14 @@ counters_and_perfcounters_sample (MonoProfiler *prof)
static void
log_shutdown (MonoProfiler *prof)
{
void *res;
in_shutdown = 1;
#ifndef DISABLE_HELPER_THREAD
counters_and_perfcounters_sample (prof);
if (prof->command_port) {
char c = 1;
void *res;
ign_res (write (prof->pipes [1], &c, 1));
pthread_join (prof->helper_thread, &res);
}
@@ -2436,12 +2518,17 @@ log_shutdown (MonoProfiler *prof)
read_perf_mmap (prof, i);
}
#endif
dump_sample_hits (prof, prof->stat_buffers, 1);
take_lock ();
if (TLS_GET (tlsbuffer))
dump_buffer (prof, TLS_GET (tlsbuffer));
dump_sample_hits (prof, prof->stat_buffers);
if (TLS_GET (LogBuffer, tlsbuffer))
send_buffer (prof, TLS_GET (GPtrArray, tlsmethodlist), TLS_GET (LogBuffer, tlsbuffer));
TLS_SET (tlsbuffer, NULL);
release_lock ();
TLS_SET (tlsmethodlist, NULL);
InterlockedWrite (&prof->run_writer_thread, 0);
pthread_join (prof->writer_thread, &res);
#if defined (HAVE_SYS_ZLIB)
if (prof->gzfile)
gzclose (prof->gzfile);
@@ -2450,6 +2537,10 @@ log_shutdown (MonoProfiler *prof)
pclose (prof->file);
else
fclose (prof->file);
mono_conc_hashtable_destroy (prof->method_table);
mono_mutex_destroy (&prof->method_table_mutex);
free (prof);
}
@@ -2584,9 +2675,9 @@ helper_thread (void* arg)
if (do_debug)
fprintf (stderr, "stat buffer dump\n");
if (sbuf) {
dump_sample_hits (prof, sbuf, 1);
dump_sample_hits (prof, sbuf);
free_buffer (sbuf, sbuf->size);
safe_dump (prof, ensure_logbuf (0));
safe_send (prof, ensure_logbuf (0));
}
continue;
}
@@ -2606,7 +2697,7 @@ helper_thread (void* arg)
}
}
#endif
safe_dump (prof, ensure_logbuf (0));
safe_send (prof, ensure_logbuf (0));
return NULL;
}
#if USE_PERF_EVENTS
@@ -2617,7 +2708,7 @@ helper_thread (void* arg)
continue;
if (FD_ISSET (perf_data [i].perf_fd, &rfds)) {
read_perf_mmap (prof, i);
safe_dump (prof, ensure_logbuf (0));
safe_send (prof, ensure_logbuf (0));
}
}
}
@@ -2635,7 +2726,7 @@ helper_thread (void* arg)
if (strcmp (buf, "heapshot\n") == 0) {
heapshot_requested = 1;
//fprintf (stderr, "perform heapshot\n");
if (runtime_inited && !thread) {
if (InterlockedRead (&runtime_inited) && !thread) {
thread = mono_thread_attach (mono_get_root_domain ());
/*fprintf (stderr, "attached\n");*/
}
@@ -2702,13 +2793,120 @@ start_helper_thread (MonoProfiler* prof)
}
#endif
static void *
writer_thread (void *arg)
{
MonoProfiler *prof = arg;
mono_threads_attach_tools_thread ();
dump_header (prof);
while (InterlockedRead (&prof->run_writer_thread)) {
WriterQueueEntry *entry;
while ((entry = (WriterQueueEntry *) mono_lock_free_queue_dequeue (&prof->writer_queue))) {
LogBuffer *method_buffer = NULL;
gboolean new_methods = FALSE;
if (entry->methods->len)
method_buffer = create_buffer ();
/*
* Encode the method events in a temporary log buffer that we
* flush to disk before the main buffer, ensuring that all
* methods have metadata emitted before they're referenced.
*/
for (guint i = 0; i < entry->methods->len; i++) {
MethodInfo *info = g_ptr_array_index (entry->methods, i);
if (mono_conc_hashtable_lookup (prof->method_table, info->method))
continue;
new_methods = TRUE;
/*
* Other threads use this hash table to get a general
* idea of whether a method has already been emitted to
* the stream. Due to the way we add to this table, it
* can easily happen that multiple threads queue up the
* same methods, but that's OK since eventually all
* methods will be in this table and the thread-local
* method lists will just be empty for the rest of the
* app's lifetime.
*/
mono_conc_hashtable_insert (prof->method_table, info->method, info->method);
char *name = mono_method_full_name (info->method, 1);
int nlen = strlen (name) + 1;
uint64_t now = current_time ();
method_buffer = ensure_logbuf_inner (method_buffer, 32 + nlen);
emit_byte (method_buffer, TYPE_JIT | TYPE_METHOD);
emit_time (method_buffer, now);
emit_method_inner (method_buffer, info->method);
emit_ptr (method_buffer, mono_jit_info_get_code_start (info->ji));
emit_value (method_buffer, mono_jit_info_get_code_size (info->ji));
memcpy (method_buffer->data, name, nlen);
method_buffer->data += nlen;
mono_free (name);
free (info);
}
g_ptr_array_free (entry->methods, TRUE);
if (new_methods)
dump_buffer (prof, method_buffer);
else if (method_buffer)
free_buffer (method_buffer, method_buffer->size);
dump_buffer (prof, entry->buffer);
free (entry);
}
}
return NULL;
}
static int
start_writer_thread (MonoProfiler* prof)
{
InterlockedWrite (&prof->run_writer_thread, 1);
return !pthread_create (&prof->writer_thread, NULL, writer_thread, prof);
}
static void
runtime_initialized (MonoProfiler *profiler)
{
#ifndef DISABLE_HELPER_THREAD
if (hs_mode_ondemand || need_helper_thread) {
if (!start_helper_thread (profiler))
profiler->command_port = 0;
}
#endif
start_writer_thread (profiler);
InterlockedWrite (&runtime_inited, 1);
#ifndef DISABLE_HELPER_THREAD
counters_init (profiler);
counters_sample (profiler, 0);
#endif
/* ensure the main thread data and startup are available soon */
safe_send (profiler, ensure_logbuf (0));
}
static MonoProfiler*
create_profiler (const char *filename)
{
MonoProfiler *prof;
char *nf;
int force_delete = 0;
int need_helper_thread = 0;
prof = calloc (1, sizeof (MonoProfiler));
prof->command_port = command_port;
@@ -2767,17 +2965,16 @@ create_profiler (const char *filename)
if (do_counters && !need_helper_thread) {
need_helper_thread = 1;
}
#ifndef DISABLE_HELPER_THREAD
if (hs_mode_ondemand || need_helper_thread) {
if (!start_helper_thread (prof))
prof->command_port = 0;
}
#else
#ifdef DISABLE_HELPER_THREAD
if (hs_mode_ondemand)
fprintf (stderr, "Ondemand heapshot unavailable on this arch.\n");
#endif
mono_lock_free_queue_init (&prof->writer_queue);
mono_mutex_init (&prof->method_table_mutex);
prof->method_table = mono_conc_hashtable_new (&prof->method_table_mutex, NULL, NULL);
prof->startup_time = current_time ();
dump_header (prof);
return prof;
}
@@ -3127,5 +3324,6 @@ mono_profiler_startup (const char *desc)
mono_profiler_set_events (events);
TLS_INIT (tlsbuffer);
TLS_INIT (tlsmethodlist);
}
+6 -5
View File
@@ -28,6 +28,7 @@
#ifndef __MONO_LOCKFREEQUEUE_H__
#define __MONO_LOCKFREEQUEUE_H__
#include <mono/utils/mono-publib.h>
#include <glib.h>
//#define QUEUE_DEBUG 1
@@ -55,13 +56,13 @@ typedef struct {
volatile gint32 has_dummy;
} MonoLockFreeQueue;
void mono_lock_free_queue_init (MonoLockFreeQueue *q) MONO_INTERNAL;
MONO_API void mono_lock_free_queue_init (MonoLockFreeQueue *q);
void mono_lock_free_queue_node_init (MonoLockFreeQueueNode *node, gboolean to_be_freed) MONO_INTERNAL;
void mono_lock_free_queue_node_free (MonoLockFreeQueueNode *node) MONO_INTERNAL;
MONO_API void mono_lock_free_queue_node_init (MonoLockFreeQueueNode *node, gboolean to_be_freed);
MONO_API void mono_lock_free_queue_node_free (MonoLockFreeQueueNode *node);
void mono_lock_free_queue_enqueue (MonoLockFreeQueue *q, MonoLockFreeQueueNode *node) MONO_INTERNAL;
MONO_API void mono_lock_free_queue_enqueue (MonoLockFreeQueue *q, MonoLockFreeQueueNode *node);
MonoLockFreeQueueNode* mono_lock_free_queue_dequeue (MonoLockFreeQueue *q) MONO_INTERNAL;
MONO_API MonoLockFreeQueueNode* mono_lock_free_queue_dequeue (MonoLockFreeQueue *q);
#endif
+1 -1
View File
@@ -492,7 +492,7 @@ mono_code_manager_foreach (MonoCodeManager *cman, MonoCodeManagerFunc func, void
#define BIND_ROOM 8
#endif
#if defined(TARGET_ARM64)
#define BIND_ROOM 8
#define BIND_ROOM 4
#endif
static CodeChunk*
+1 -1
View File
@@ -278,7 +278,7 @@ typedef SSIZE_T ssize_t;
#ifdef __GNUC__
#define MONO_COLD __attribute__((cold))
#else
#define MONO_COLD __attribute__((cold))
#define MONO_COLD
#endif
#endif /* __UTILS_MONO_COMPILER_H__*/
+7 -6
View File
@@ -10,18 +10,19 @@
#ifndef __MONO_CONCURRENT_HASHTABLE_H__
#define __MONO_CONCURRENT_HASHTABLE_H__
#include <mono/utils/mono-publib.h>
#include <mono/utils/mono-compiler.h>
#include <mono/utils/mono-mutex.h>
#include <glib.h>
typedef struct _MonoConcurrentHashTable MonoConcurrentHashTable;
MonoConcurrentHashTable* mono_conc_hashtable_new (mono_mutex_t *mutex, GHashFunc hash_func, GEqualFunc key_equal_func) MONO_INTERNAL;
MonoConcurrentHashTable* mono_conc_hashtable_new_full (mono_mutex_t *mutex, GHashFunc hash_func, GEqualFunc key_equal_func, GDestroyNotify key_destroy_func, GDestroyNotify value_destroy_func) MONO_INTERNAL;
void mono_conc_hashtable_destroy (MonoConcurrentHashTable *hash_table) MONO_INTERNAL;
gpointer mono_conc_hashtable_lookup (MonoConcurrentHashTable *hash_table, gpointer key) MONO_INTERNAL;
gpointer mono_conc_hashtable_insert (MonoConcurrentHashTable *hash_table, gpointer key, gpointer value) MONO_INTERNAL;
gpointer mono_conc_hashtable_remove (MonoConcurrentHashTable *hash_table, gpointer key) MONO_INTERNAL;
MONO_API MonoConcurrentHashTable* mono_conc_hashtable_new (mono_mutex_t *mutex, GHashFunc hash_func, GEqualFunc key_equal_func);
MONO_API MonoConcurrentHashTable* mono_conc_hashtable_new_full (mono_mutex_t *mutex, GHashFunc hash_func, GEqualFunc key_equal_func, GDestroyNotify key_destroy_func, GDestroyNotify value_destroy_func);
MONO_API void mono_conc_hashtable_destroy (MonoConcurrentHashTable *hash_table);
MONO_API gpointer mono_conc_hashtable_lookup (MonoConcurrentHashTable *hash_table, gpointer key);
MONO_API gpointer mono_conc_hashtable_insert (MonoConcurrentHashTable *hash_table, gpointer key, gpointer value);
MONO_API gpointer mono_conc_hashtable_remove (MonoConcurrentHashTable *hash_table, gpointer key);
#endif
+14 -6
View File
@@ -299,16 +299,23 @@ get_process_stat_item (int pid, int pos, int sum, MonoProcessError *error)
thread_array_t th_array;
size_t i;
if (task_for_pid(mach_task_self(), pid, &task) != KERN_SUCCESS)
RET_ERROR (MONO_PROCESS_ERROR_NOT_FOUND);
if (pid == getpid ()) {
/* task_for_pid () doesn't work on ios, even for the current process */
task = mach_task_self ();
} else {
if (task_for_pid (mach_task_self (), pid, &task) != KERN_SUCCESS)
RET_ERROR (MONO_PROCESS_ERROR_NOT_FOUND);
}
if (task_info(task, TASK_BASIC_INFO, (task_info_t)&t_info, &t_info_count) != KERN_SUCCESS) {
mach_port_deallocate (mach_task_self (), task);
if (task_info (task, TASK_BASIC_INFO, (task_info_t)&t_info, &t_info_count) != KERN_SUCCESS) {
if (pid != getpid ())
mach_port_deallocate (mach_task_self (), task);
RET_ERROR (MONO_PROCESS_ERROR_OTHER);
}
if (task_threads(task, &th_array, &th_count) != KERN_SUCCESS) {
mach_port_deallocate (mach_task_self (), task);
if (pid != getpid ())
mach_port_deallocate (mach_task_self (), task);
RET_ERROR (MONO_PROCESS_ERROR_OTHER);
}
@@ -331,7 +338,8 @@ get_process_stat_item (int pid, int pos, int sum, MonoProcessError *error)
for (i = 0; i < th_count; i++)
mach_port_deallocate(task, th_array[i]);
mach_port_deallocate (mach_task_self (), task);
if (pid != getpid ())
mach_port_deallocate (mach_task_self (), task);
process_user_time += t_info.user_time.seconds + t_info.user_time.microseconds / 1e6;
process_system_time += t_info.system_time.seconds + t_info.system_time.microseconds / 1e6;