Made ExceptionTableEntry mostly immutable (ordinal will be next).

This commit is contained in:
jfrijters 2010-06-07 10:05:28 +00:00
Родитель 7dfb0107c4
Коммит 03361a778a
3 изменённых файлов: 39 добавлений и 61 удалений

Просмотреть файл

@ -2460,24 +2460,24 @@ namespace IKVM.Internal
{
throw new ClassFormatError("Illegal exception table: {0}.{1}{2}", classFile.Name, method.Name, method.Signature);
}
exception_table[i] = new ExceptionTableEntry();
exception_table[i].catch_type = catch_type;
exception_table[i].ordinal = i;
// if start_pc, end_pc or handler_pc is invalid (i.e. doesn't point to the start of an instruction),
// the index will be -1 and this will be handled by the verifier
exception_table[i].startIndex = pcIndexMap[start_pc];
int startIndex = pcIndexMap[start_pc];
int endIndex;
if (end_pc == code_length)
{
// it is legal for end_pc to point to just after the last instruction,
// but since there isn't an entry in our pcIndexMap for that, we have
// a special case for this
exception_table[i].endIndex = instructionIndex - 1;
endIndex = instructionIndex - 1;
}
else
{
exception_table[i].endIndex = pcIndexMap[end_pc];
endIndex = pcIndexMap[end_pc];
}
exception_table[i].handlerIndex = pcIndexMap[handler_pc];
int handlerIndex = pcIndexMap[handler_pc];
exception_table[i] = new ExceptionTableEntry(startIndex, endIndex, handlerIndex, catch_type);
exception_table[i].ordinal = i;
}
ushort attributes_count = br.ReadUInt16();
for(int i = 0; i < attributes_count; i++)
@ -2588,11 +2588,19 @@ namespace IKVM.Internal
internal sealed class ExceptionTableEntry
{
internal int startIndex;
internal int endIndex;
internal int handlerIndex;
internal ushort catch_type;
internal readonly int startIndex;
internal readonly int endIndex;
internal readonly int handlerIndex;
internal readonly ushort catch_type;
internal int ordinal;
internal ExceptionTableEntry(int startIndex, int endIndex, int handlerIndex, ushort catch_type)
{
this.startIndex = startIndex;
this.endIndex = endIndex;
this.handlerIndex = handlerIndex;
this.catch_type = catch_type;
}
}
[Flags]

Просмотреть файл

@ -266,11 +266,7 @@ namespace IKVM.Internal
int end = MapExceptionStartEnd(entry.endIndex);
if (start != end)
{
ClassFile.Method.ExceptionTableEntry newEntry = new ClassFile.Method.ExceptionTableEntry();
newEntry.startIndex = start;
newEntry.endIndex = end;
newEntry.catch_type = entry.catch_type;
newEntry.handlerIndex = branchMap[entry.handlerIndex];
ClassFile.Method.ExceptionTableEntry newEntry = new ClassFile.Method.ExceptionTableEntry(start, end, branchMap[entry.handlerIndex], entry.catch_type);
newEntry.ordinal = newExceptions.Count;
newExceptions.Add(newEntry);
}

Просмотреть файл

@ -2670,10 +2670,6 @@ class MethodAnalyzer
internal static ExceptionTableEntry[] UntangleExceptionBlocks(ClassFile classFile, ClassFile.Method.Instruction[] instructions, InstructionFlags[] flags, ExceptionTableEntry[] exceptionTable)
{
// NOTE we're going to be messing with ExceptionTableEntrys that are owned by the Method, this is very bad practice,
// this code should probably be changed to use our own ETE class (which should also contain the ordinal, instead
// of the one in ClassFile.cs)
List<ExceptionTableEntry> ar = new List<ExceptionTableEntry>(exceptionTable);
// This optimization removes the recursive exception handlers that Java compiler place around
@ -2730,18 +2726,12 @@ class MethodAnalyzer
// 0006/test.j
if (ej.endIndex > ei.endIndex)
{
ExceptionTableEntry emi = new ExceptionTableEntry();
emi.startIndex = ej.startIndex;
emi.endIndex = ei.endIndex;
emi.catch_type = ei.catch_type;
emi.handlerIndex = ei.handlerIndex;
ExceptionTableEntry emj = new ExceptionTableEntry();
emj.startIndex = ej.startIndex;
emj.endIndex = ei.endIndex;
emj.catch_type = ej.catch_type;
emj.handlerIndex = ej.handlerIndex;
ei.endIndex = emi.startIndex;
ej.startIndex = emj.endIndex;
ExceptionTableEntry emi = new ExceptionTableEntry(ej.startIndex, ei.endIndex, ei.handlerIndex, ei.catch_type);
ExceptionTableEntry emj = new ExceptionTableEntry(ej.startIndex, ei.endIndex, ej.handlerIndex, ej.catch_type);
ei = new ExceptionTableEntry(ei.startIndex, emi.startIndex, ei.handlerIndex, ei.catch_type);
ej = new ExceptionTableEntry(emj.endIndex, ej.endIndex, ej.handlerIndex, ej.catch_type);
ar[i] = ei;
ar[j] = ej;
ar.Insert(j, emj);
ar.Insert(i + 1, emi);
goto restart;
@ -2749,17 +2739,10 @@ class MethodAnalyzer
// 0007/test.j
else if (j > i && ej.endIndex < ei.endIndex)
{
ExceptionTableEntry emi = new ExceptionTableEntry();
emi.startIndex = ej.startIndex;
emi.endIndex = ej.endIndex;
emi.catch_type = ei.catch_type;
emi.handlerIndex = ei.handlerIndex;
ExceptionTableEntry eei = new ExceptionTableEntry();
eei.startIndex = ej.endIndex;
eei.endIndex = ei.endIndex;
eei.catch_type = ei.catch_type;
eei.handlerIndex = ei.handlerIndex;
ei.endIndex = emi.startIndex;
ExceptionTableEntry emi = new ExceptionTableEntry(ej.startIndex, ej.endIndex, ei.handlerIndex, ei.catch_type);
ExceptionTableEntry eei = new ExceptionTableEntry(ej.endIndex, ei.endIndex, ei.handlerIndex, ei.catch_type);
ei = new ExceptionTableEntry(ei.startIndex, emi.startIndex, ei.handlerIndex, ei.catch_type);
ar[i] = ei;
ar.Insert(i + 1, eei);
ar.Insert(i + 1, emi);
goto restart;
@ -2788,12 +2771,9 @@ class MethodAnalyzer
int targetIndex = (k == -1 ? instructions[j].DefaultTarget : instructions[j].GetSwitchTargetIndex(k));
if (ei.startIndex < targetIndex && targetIndex < ei.endIndex)
{
ExceptionTableEntry en = new ExceptionTableEntry();
en.catch_type = ei.catch_type;
en.handlerIndex = ei.handlerIndex;
en.startIndex = targetIndex;
en.endIndex = ei.endIndex;
ei.endIndex = targetIndex;
ExceptionTableEntry en = new ExceptionTableEntry(targetIndex, ei.endIndex, ei.handlerIndex, ei.catch_type);
ei = new ExceptionTableEntry(ei.startIndex, targetIndex, ei.handlerIndex, ei.catch_type);
ar[i] = ei;
ar.Insert(i + 1, en);
goto restart_split;
}
@ -2820,12 +2800,9 @@ class MethodAnalyzer
int targetIndex = instructions[j].Arg1;
if (ei.startIndex < targetIndex && targetIndex < ei.endIndex)
{
ExceptionTableEntry en = new ExceptionTableEntry();
en.catch_type = ei.catch_type;
en.handlerIndex = ei.handlerIndex;
en.startIndex = targetIndex;
en.endIndex = ei.endIndex;
ei.endIndex = targetIndex;
ExceptionTableEntry en = new ExceptionTableEntry(targetIndex, ei.endIndex, ei.handlerIndex, ei.catch_type);
ei = new ExceptionTableEntry(ei.startIndex, targetIndex, ei.handlerIndex, ei.catch_type);
ar[i] = ei;
ar.Insert(i + 1, en);
goto restart_split;
}
@ -2844,12 +2821,9 @@ class MethodAnalyzer
ExceptionTableEntry ej = ar[j];
if (ei.startIndex < ej.handlerIndex && ej.handlerIndex < ei.endIndex)
{
ExceptionTableEntry en = new ExceptionTableEntry();
en.catch_type = ei.catch_type;
en.handlerIndex = ei.handlerIndex;
en.startIndex = ej.handlerIndex;
en.endIndex = ei.endIndex;
ei.endIndex = ej.handlerIndex;
ExceptionTableEntry en = new ExceptionTableEntry(ej.handlerIndex, ei.endIndex, ei.handlerIndex, ei.catch_type);
ei = new ExceptionTableEntry(ei.startIndex, ej.handlerIndex, ei.handlerIndex, ei.catch_type);
ar[i] = ei;
ar.Insert(i + 1, en);
goto restart_split;
}