Imported Upstream version 6.6.0.89

Former-commit-id: b39a328747c2f3414dc52e009fb6f0aa80ca2492
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2019-09-24 08:53:40 +00:00
parent cf815e07e0
commit 95fdb59ea6
2556 changed files with 138145 additions and 47453 deletions

View File

@@ -0,0 +1,20 @@
namespace Mono.Profiler.Aot {
public abstract class ProfileBase {
internal enum RecordType {
NONE = 0,
IMAGE = 1,
TYPE = 2,
GINST = 3,
METHOD = 4
}
internal enum MonoTypeEnum {
MONO_TYPE_CLASS = 0x12,
}
internal const string MAGIC = "AOTPROFILE";
internal const int MAJOR_VERSION = 1;
internal const int MINOR_VERSION = 0;
}
}

View File

@@ -9,26 +9,8 @@ namespace Mono.Profiler.Aot
// Read the contents of a .aotprofile created by the AOT profiler
// See mono-profiler-aot.h for a description of the file format
//
public sealed class ProfileReader
public sealed class ProfileReader : ProfileBase
{
enum RecordType
{
NONE = 0,
IMAGE = 1,
TYPE = 2,
GINST = 3,
METHOD = 4
}
enum MonoTypeEnum
{
MONO_TYPE_CLASS = 0x12,
}
const string MAGIC = "AOTPROFILE";
const int MAJOR_VERSION = 1;
const int MINOR_VERSION = 0;
DataConverter conv;
byte[] data;
int pos;

View File

@@ -0,0 +1,137 @@
using System.IO;
using System.Collections.Generic;
using System.Text;
namespace Mono.Profiler.Aot {
//
// Write the contents of a .aotprofile
// See mono/profiler/aot.h for a description of the file format
//
public sealed class ProfileWriter : ProfileBase {
Stream stream;
ProfileData data;
int id;
readonly Dictionary<TypeRecord, int> typeIds = new Dictionary<TypeRecord, int> ();
readonly Dictionary<ModuleRecord, int> moduleIds = new Dictionary<ModuleRecord, int> ();
unsafe void WriteInt32 (int intValue)
{
byte* b = (byte*)&intValue;
for (int i = 0; i < 4; i++)
stream.WriteByte (b [i]);
}
void WriteString (string str)
{
WriteInt32 (str.Length);
var buf = Encoding.UTF8.GetBytes (str);
stream.Write (buf, 0, buf.Length);
}
int AddModule (ModuleRecord m)
{
int mId;
if (moduleIds.TryGetValue (m, out mId))
return mId;
mId = id++;
moduleIds [m] = mId;
WriteRecord (RecordType.IMAGE, mId);
WriteString (m.Name);
WriteString (m.Mvid);
return mId;
}
int AddType (TypeRecord t)
{
int tId;
if (typeIds.TryGetValue (t, out tId))
return tId;
var moduleId = AddModule (t.Module);
int instId = -1;
if (t.GenericInst != null)
instId = AddGenericInstance (t.GenericInst);
tId = id++;
typeIds [t] = tId;
WriteRecord (RecordType.TYPE, tId);
stream.WriteByte ((byte)MonoTypeEnum.MONO_TYPE_CLASS);
WriteInt32 (moduleId);
WriteInt32 (instId);
WriteString (t.Name);
return tId;
}
int AddGenericInstance (GenericInstRecord gi)
{
// add the types first, before we start writing the GINST record
for (int i = 0; i < gi.Types.Length; i++)
AddType (gi.Types [i]);
var gId = id++;
WriteRecord (RecordType.GINST, gId);
WriteInt32 (gi.Types.Length);
for (int i = 0; i < gi.Types.Length; i++)
WriteInt32 (AddType (gi.Types [i]));
return gId;
}
void WriteMethod (MethodRecord m)
{
var typeId = AddType (m.Type);
int instId = -1;
if (m.GenericInst != null)
instId = AddGenericInstance (m.GenericInst);
WriteRecord (RecordType.METHOD, id++);
WriteInt32 (typeId);
WriteInt32 (instId);
WriteInt32 (m.ParamCount);
WriteString (m.Name);
WriteString (m.Signature);
}
void WriteRecord (RecordType rt, int value)
{
stream.WriteByte ((byte)rt);
WriteInt32 (value);
}
public void WriteAllData (Stream s, ProfileData pd)
{
stream = s;
data = pd;
var buf = Encoding.UTF8.GetBytes (MAGIC);
this.stream.Write (buf, 0, buf.Length);
WriteInt32 ((MAJOR_VERSION << 16) | MINOR_VERSION);
foreach (var m in data.Methods)
WriteMethod (m);
// make sure ew have all the types
// sometime the profile contain type, which is not referenced from the methods
foreach (var t in data.Types)
AddType (t);
// just to be complete, do not miss any module too
foreach (var module in data.Modules)
AddModule (module);
WriteRecord (RecordType.NONE, 0);
}
}
}

View File

@@ -1,3 +1,5 @@
using System.Text;
namespace Mono.Profiler.Aot
{
//
@@ -31,6 +33,11 @@ namespace Mono.Profiler.Aot
public string Mvid {
get; set;
}
public override string ToString ()
{
return Name;
}
}
public class GenericInstRecord : ProfileRecord
@@ -43,6 +50,27 @@ namespace Mono.Profiler.Aot
public TypeRecord[] Types {
get; set;
}
public override string ToString ()
{
if (Types == null || Types.Length <= 0)
return "";
var sb = new StringBuilder ("<");
var first = true;
foreach (var type in Types) {
if (!first)
sb.Append (", ");
else
first = false;
sb.Append (type.ToString ());
}
sb.Append (">");
return sb.ToString ();
}
}
public class TypeRecord : ProfileRecord
@@ -62,9 +90,27 @@ namespace Mono.Profiler.Aot
get; set;
}
public string FullName {
get {
string prefix;
if (Name.Length > 0 && Name [0] == '.')
prefix = Module.ToString ();
else
prefix = "";
return $"{prefix}{Name}{GenericInst}";
}
}
public GenericInstRecord GenericInst {
get; set;
}
public override string ToString ()
{
return FullName;
}
}
public class MethodRecord : ProfileRecord
@@ -97,5 +143,10 @@ namespace Mono.Profiler.Aot
public int ParamCount {
get; set;
}
public override string ToString ()
{
return $"{Signature.Replace ("(", $" {Type}:{Name} (")}";
}
}
}