Added support for inlining subroutines (jsr/ret) to allow the verifier and compiler to be simplified and to hopefully pave the way for future codegen optimizations.

This commit is contained in:
jfrijters 2009-04-16 05:34:20 +00:00
Родитель e3f95b0bcd
Коммит 937d2e6568
8 изменённых файлов: 2106 добавлений и 4 удалений

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

@ -29,7 +29,7 @@ using System.Reflection;
[assembly: AssemblyCopyright("Copyright (C) 2002-2009 Jeroen Frijters")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("0.39.3363.0")]
[assembly: AssemblyVersion("0.41.3393.0")]
#if SIGNCODE
#pragma warning disable 1699

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

@ -113,6 +113,7 @@
<Compile Include="runtime\JavaException.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="runtime\JsrInliner.cs" />
<Compile Include="runtime\MemberWrapper.cs">
<SubType>Code</SubType>
</Compile>

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

@ -27,6 +27,7 @@
<include name="../runtime/DynamicClassLoader.cs" />
<include name="../runtime/intrinsics.cs" />
<include name="../runtime/JavaException.cs" />
<include name="../runtime/JsrInliner.cs" />
<include name="../runtime/MemberWrapper.cs" />
<include name="../runtime/profiler.cs" />
<include name="../runtime/ReflectUtil.cs" />

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

@ -2458,6 +2458,10 @@ namespace IKVM.Internal
{
return code.instructions;
}
set
{
code.instructions = value;
}
}
internal ExceptionTableEntry[] ExceptionTable
@ -2466,6 +2470,10 @@ namespace IKVM.Internal
{
return code.exception_table;
}
set
{
code.exception_table = value;
}
}
internal LineNumberTableEntry[] LineNumberTableAttribute
@ -2484,8 +2492,17 @@ namespace IKVM.Internal
}
}
internal bool HasJsr
{
get
{
return code.hasJsr;
}
}
private struct Code
{
internal bool hasJsr;
internal string verifyError;
internal ushort max_stack;
internal ushort max_locals;
@ -2512,7 +2529,9 @@ namespace IKVM.Internal
BigEndianBinaryReader rdr = br.Section(code_length);
while(!rdr.IsAtEnd)
{
instructions[instructionIndex++].Read((ushort)(rdr.Position - basePosition), rdr);
instructions[instructionIndex].Read((ushort)(rdr.Position - basePosition), rdr);
hasJsr |= instructions[instructionIndex].NormalizedOpCode == NormalizedByteCode.__jsr;
instructionIndex++;
}
// we add an additional nop instruction to make it easier for consumers of the code array
instructions[instructionIndex++].SetTermNop((ushort)(rdr.Position - basePosition));
@ -2561,7 +2580,7 @@ namespace IKVM.Internal
break;
case NormalizedByteCode.__tableswitch:
case NormalizedByteCode.__lookupswitch:
this.instructions[i].SetSwitchTargets(pcIndexMap);
this.instructions[i].MapSwitchTargets(pcIndexMap);
break;
}
}
@ -2780,6 +2799,11 @@ namespace IKVM.Internal
this.arg1 = arg1;
}
internal void SetPC(int pc)
{
this.pc = (ushort)pc;
}
internal void SetTargetIndex(int targetIndex)
{
this.arg1 = targetIndex;
@ -2792,7 +2816,7 @@ namespace IKVM.Internal
this.normopcode = NormalizedByteCode.__nop;
}
internal void SetSwitchTargets(int[] pcIndexMap)
internal void MapSwitchTargets(int[] pcIndexMap)
{
arg1 = pcIndexMap[arg1 + pc];
for (int i = 0; i < switch_entries.Length; i++)
@ -2943,6 +2967,10 @@ namespace IKVM.Internal
{
return arg1;
}
set
{
arg1 = value;
}
}
internal int Arg2
@ -2967,6 +2995,10 @@ namespace IKVM.Internal
{
return arg1;
}
set
{
arg1 = value;
}
}
internal int SwitchEntryCount
@ -2986,6 +3018,16 @@ namespace IKVM.Internal
{
return switch_entries[i].target;
}
internal void SetSwitchTargets(int[] targets)
{
SwitchEntry[] newEntries = (SwitchEntry[])switch_entries.Clone();
for (int i = 0; i < newEntries.Length; i++)
{
newEntries[i].target = targets[i];
}
switch_entries = newEntries;
}
}
internal struct LineNumberTableEntry

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

@ -121,6 +121,7 @@
<Compile Include="JavaException.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="JsrInliner.cs" />
<Compile Include="MemberWrapper.cs">
<SubType>Code</SubType>
</Compile>

2052
runtime/JsrInliner.cs Normal file

Разница между файлами не показана из-за своего большого размера Загрузить разницу

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

@ -288,6 +288,10 @@ class Compiler
Profiler.Enter("MethodAnalyzer");
try
{
if(m.HasJsr)
{
JsrInliner.InlineJsrs(classLoader, mw, classFile, m);
}
ma = new MethodAnalyzer(clazz, mw, classFile, m, classLoader);
}
finally

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

@ -75,6 +75,7 @@
<include name="ExceptionHelper.cs" />
<include name="intrinsics.cs" />
<include name="JavaException.cs" />
<include name="JsrInliner.cs" />
<include name="MemberWrapper.cs" />
<include name="openjdk.cs" />
<include name="PassiveWeakDictionary.cs" />