本文整理汇总了C#中Heap.GetHeapElement方法的典型用法代码示例。如果您正苦于以下问题:C# Heap.GetHeapElement方法的具体用法?C# Heap.GetHeapElement怎么用?C# Heap.GetHeapElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Heap
的用法示例。
在下文中一共展示了Heap.GetHeapElement方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetArrayTrace
private string GetArrayTrace(StackValue pointer, Heap heap, int langblock, HashSet<int> pointers, bool forPrint)
{
if (!formatParams.ContinueOutputTrace())
return "...";
StringBuilder arrayElements = new StringBuilder();
HeapElement hs = heap.GetHeapElement(pointer);
int halfArraySize = -1;
if (formatParams.MaxArraySize > 0) // If the caller did specify a max value...
{
// And our array is larger than that max value...
if (hs.VisibleSize > formatParams.MaxArraySize)
halfArraySize = (int)Math.Floor(formatParams.MaxArraySize * 0.5);
}
int totalElementCount = hs.VisibleSize + (hs.Dict == null ? 0 : hs.Dict.Count());
for (int n = 0; n < hs.VisibleSize; ++n)
{
// As we try to output the next element in the array, there
// should be a comma if there were previously output element.
if (arrayElements.Length > 0)
if(forPrint)
arrayElements.Append(",");
else
arrayElements.Append(", ");
StackValue sv = hs.Stack[n];
if (sv.IsArray)
{
arrayElements.Append(GetPointerTrace(sv, heap, langblock, pointers, forPrint));
}
else
{
arrayElements.Append(GetStringValue(hs.Stack[n], heap, langblock, forPrint));
}
// If we need to truncate this array (halfArraySize > 0), and we have
// already reached the first half of it, then offset the loop counter
// to the next half of the array.
if (halfArraySize > 0 && (n == halfArraySize - 1))
{
arrayElements.Append(", ...");
n = totalElementCount - halfArraySize - 1;
}
}
if (hs.Dict != null)
{
int startIndex = (halfArraySize > 0) ? hs.Dict.Count - halfArraySize : 0;
int index = -1;
foreach (var keyValuePair in hs.Dict)
{
index++;
if (index < startIndex)
{
continue;
}
if (arrayElements.Length > 0)
{
if (forPrint)
{
arrayElements.Append(",");
}
else
{
arrayElements.Append(", ");
}
}
StackValue key = keyValuePair.Key;
StackValue value = keyValuePair.Value;
if (key.IsArray)
{
arrayElements.Append(GetPointerTrace(key, heap, langblock, pointers, forPrint));
}
else
{
arrayElements.Append(GetStringValue(key, heap, langblock, forPrint));
}
arrayElements.Append("=");
if (value.IsArray)
{
arrayElements.Append(GetPointerTrace(value, heap, langblock, pointers, forPrint));
}
else
{
arrayElements.Append(GetStringValue(value, heap, langblock, forPrint));
}
}
}
formatParams.RestoreOutputTraceDepth();
return arrayElements.ToString();
//.........这里部分代码省略.........
示例2: GetStringTrace
private string GetStringTrace(StackValue strptr, Heap heap)
{
string str = "";
foreach (var sv in heap.GetHeapElement(strptr).VisibleItems)
{
if (!sv.IsChar)
{
break;
}
str += ProtoCore.Utils.EncodingUtils.ConvertInt64ToCharacter(sv.opdata);
}
return str;
}
示例3: GetClassTrace
public string GetClassTrace(StackValue val, Heap heap, int langblock, bool forPrint)
{
if (!formatParams.ContinueOutputTrace())
return "...";
Executable exe = MirrorTarget.exe;
ClassTable classTable = MirrorTarget.Core.ClassTable;
int classtype = val.metaData.type;
if (classtype < 0 || (classtype >= classTable.ClassNodes.Count))
{
formatParams.RestoreOutputTraceDepth();
return string.Empty;
}
ClassNode classnode = classTable.ClassNodes[classtype];
if (classnode.IsImportedClass)
{
var helper = DLLFFIHandler.GetModuleHelper(FFILanguage.CSharp);
var marshaller = helper.GetMarshaller(core);
var strRep = marshaller.GetStringValue(val);
formatParams.RestoreOutputTraceDepth();
return strRep;
}
else
{
HeapElement hs = heap.GetHeapElement(val);
List<string> visibleProperties = null;
if (null != propertyFilter)
{
if (!propertyFilter.TryGetValue(classnode.name, out visibleProperties))
visibleProperties = null;
}
StringBuilder classtrace = new StringBuilder();
if (classnode.symbols != null && classnode.symbols.symbolList.Count > 0)
{
bool firstPropertyDisplayed = false;
for (int n = 0; n < hs.VisibleSize; ++n)
{
SymbolNode symbol = classnode.symbols.symbolList[n];
string propName = symbol.name;
if ((null != visibleProperties) && visibleProperties.Contains(propName) == false)
continue; // This property is not to be displayed.
if (firstPropertyDisplayed)
classtrace.Append(", ");
string propValue = "";
if (symbol.isStatic)
{
var staticSymbol = exe.runtimeSymbols[langblock].symbolList[symbol.symbolTableIndex];
StackValue staticProp = core.Rmem.GetSymbolValue(staticSymbol);
propValue = GetStringValue(staticProp, heap, langblock, forPrint);
}
else
{
propValue = GetStringValue(hs.Stack[symbol.index], heap, langblock, forPrint);
}
classtrace.Append(string.Format("{0} = {1}", propName, propValue));
firstPropertyDisplayed = true;
}
}
else
{
for (int n = 0; n < hs.VisibleSize; ++n)
{
if (0 != n)
classtrace.Append(", ");
classtrace.Append(GetStringValue(hs.Stack[n], heap, langblock, forPrint));
}
}
formatParams.RestoreOutputTraceDepth();
if (classtype >= (int)ProtoCore.PrimitiveType.kMaxPrimitives)
if (forPrint)
return (string.Format("{0}{{{1}}}", classnode.name, classtrace.ToString()));
else
{
string tempstr = (string.Format("{0}({1})", classnode.name, classtrace.ToString()));
return tempstr;
}
return classtrace.ToString();
}
}
示例4: Unpack
//@TODO(Luke): Add in the methods here that correspond to each of the internal datastructures in use by the executive
//@TODO(Jun): if this method stays static, then the Heap needs to be referenced from a parameter
/// <summary>
/// Do the recursive unpacking of the data structure into mirror objects
/// </summary>
/// <param name="val"></param>
/// <returns></returns>
public static Obj Unpack(StackValue val, Heap heap, Core core, int type = (int)PrimitiveType.kTypePointer)
{
switch (val.optype)
{
case AddressType.ArrayPointer:
case AddressType.String:
{
DsasmArray ret = new DsasmArray();
//Pull the item out of the heap
HeapElement hs = heap.GetHeapElement(val);
StackValue[] nodes = hs.Stack;
ret.members = new Obj[hs.VisibleSize];
for (int i = 0; i < ret.members.Length; i++)
{
ret.members[i] = Unpack(nodes[i], heap, core, type);
}
// TODO Jun: ret.members[0] is hardcoded and means we are assuming a homogenous collection
// How to handle mixed-type arrays?
Obj retO = new Obj(val)
{
Payload = ret,
Type = core.TypeSystem.BuildTypeObject(
(ret.members.Length > 0)
? core.TypeSystem.GetType(ret.members[0].Type.Name)
: (int)ProtoCore.PrimitiveType.kTypeVoid, Constants.kArbitraryRank)
};
return retO;
}
case AddressType.Int:
{
Int64 data = val.opdata;
Obj o = new Obj(val)
{
Payload = data,
Type = TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.kTypeInt, 0)
};
return o;
}
case AddressType.Boolean:
{
Int64 data = val.opdata;
Obj o = new Obj(val)
{
Payload = (data != 0),
Type = TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.kTypeBool, 0)
};
return o;
}
case AddressType.Null:
{
Obj o = new Obj(val)
{
Payload = null,
Type = TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.kTypeNull, 0)
};
return o;
}
case AddressType.Char:
{
Int64 data = val.opdata;
Obj o = new Obj(val)
{
Payload = data,
Type = TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.kTypeChar, 0)
};
return o;
}
case AddressType.Double:
{
double data = val.RawDoubleValue;
Obj o = new Obj(val)
{
Payload = data, Type =
TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.kTypeDouble, 0)
};
return o;
}
case AddressType.Pointer:
{
Int64 data = val.opdata;
Obj o = new Obj(val)
{
Payload = data,
Type = core.TypeSystem.BuildTypeObject(type, 0)
};
return o;
//.........这里部分代码省略.........